﻿function CloseDiv(id)
{
    div = document.getElementById(id);
    div.style.display = "none";
} 
function OpenDiv(id)
{
    div = document.getElementById(id);
    div.style.display = "";
    if (Shadowbox)
        Shadowbox.close();
} 
function SetMenuColor(id)
{
    if($('#allMenu'+id).html()=="true")
        $('#MenuAllDiv'+id).attr('class','normal');
    else
        {
            $('#MenuAllDiv'+id).attr('class','topactive');
            $('#MenuAllDiv'+id).css('width','30px');                            
            $('#MenuAllDivBot'+id).css('width','40px');                            
            $("#MenuAllDiv"+id).css("backgroundColor", $("#SpanColor").html());
            $("#MenuAllDiv"+id).corner("3px");
            $('#MenuAllDivA'+id).attr('href','#');
            }
}
 function SetMenuSpan(id)
 {
$('#allMenu'+id).html("true");
}
function SetColorAll()
{
   $("div.topactive").css("backgroundColor", document.getElementById("SpanColor").innerHTML);
   $(".top-trans").css("backgroundColor", document.getElementById("SpanColor").innerHTML);
   $(".lefttrans").css("backgroundColor", document.getElementById("SpanColor").innerHTML);
   $(".leftactive").css("backgroundColor", document.getElementById("SpanColor").innerHTML);  
   $(".white").css("backgroundColor", document.getElementById("SpanColor").innerHTML); 
   $("div#cart-list div.round").corner("8px");
}

function SetCommonRating(rating) {
    $("div.rating div[class^='rstarsbig']").attr("class", "rstarsbig" + rating);
}
function OnGetDataComplete(result, userContext, methodName) // получили асинхронный ответ
{
    if (methodName == 'AjaxAddForCatalog') {
        var results = result.toString().split('|');
        var modalText = $('.addtocart');
        if (modalText.length == 0) {
            $('body').append(results[1]);
        }
        else {
            modalText.replaceWith(results[1]);
        }
        $('#SpanAllSummHead').text($('#Hs-Price').text());
        return hs.htmlExpand(userContext, { contentId: results[0], height: 190, width: 400, objectType: 'rounded-white' });
    }
    if (methodName == 'MyAjaxEditCommFunction') {
        var results = result.toString().split('|');
        $("#AddIntoComm").slideUp('500');
        $("#IdComMyEdit").html(results[0]);
        $("#IdComMyReyt").attr('class', 'rstars' + results[1]);
        SetTextStrComInto(results[1])
        $("#ShowResultLinkIntoComm").show();
        $("#PostSpan").html($("#PostSpan").html() - (-1));
        $("#BackA").attr('href', "javascript:history.go(-" + $("#PostSpan").html() + ")");
        SetCommonRating(results[2]);
    }
    if (methodName == 'MyAjaxDeleteFunction') {
        $('#IdThisMyComment').slideUp('500');
        $('#SpanColAll').html($('#SpanColAll').html() - 1);
        $("#PostSpan").html($("#PostSpan").html() - (-1));
        $("#BackA").attr('href', "javascript:history.go(-" + $("#PostSpan").html() + ")");
        if ($('#SpanColAll').html() == 0) {
            $('#ComH').hide();
        }
        $('#ShowResultLink').show();
        SetCommonRating(result);
    }
    if (methodName == 'MyAjaxFunctionCab') {
        $("#contentAjax" + userContext).html(result.toString().split('|')[0]);
        $("#divRstars" + userContext).attr('class', 'rstars' + result.toString().split('|')[1]);
        SetTextStrComIntoCab(result.toString().split('|')[1], userContext);
        $('#DivEdit' + userContext).slideUp('500');
    }
    if (methodName == 'MyAjaxDeleteFunctionCab') {
        $("#table" + result).slideUp('500');
        $('#SpanColAll').html($('#SpanColAll').html() - 1);
        if ($('#SpanColAll').html() == 0) {
            $('#NoComment').html("<br /><br />Пока Вы не оставляли ни одного отзыва.");
        }
    }
    if (methodName == 'MyAjaxEditFunctionCart') {
        $("#SpanTotal" + userContext).html(result.toString().split('|')[0]);
        $("#ItogSpan").html(result.toString().split('|')[1]);
        $("#SpanAllSummHead").html(result.toString().split('|')[1]);
        if (result.toString().split('|')[1] == 0) {
            $("#Book").hide();
            $("#ButOrder").hide();
        }
        else if ($("#Book").css("display") == "none")
            $("#ButOrder").show();
        ShowHideFreeDelivery(result.toString().split('|')[1]);
        LoockMas[userContext] = false;
    }
    if (methodName == 'MyAjaxDeleteFunctionCart') {
        $("#DivPoz" + userContext).slideUp('500');
        $("#ItogSpan").html(result);
        $("#SpanAllSummHead").html(result);
        if (result == 0) {
            $(".round-table").hide();
            $(".order-itog").hide();
            $("#Book").hide();
            $("#ButOrder").hide();
            $("#NoProductText").show();
        }
        else if ($("#Book").css("display") == "none")
            $("#ButOrder").show();
        ShowHideFreeDelivery(result);
    }

}
function IsInt(c){
    return !isNaN(parseInt(c));
}
function ShowHideFreeDelivery(sum)
{
    var freeprice = $("#freeprice").html();
    if (IsInt(freeprice) && IsInt(sum))
    {
        $("#freedelivery").html(sum >= freeprice ? 'Для Вас доставка будет бесплатной.' : '');
    }
}
function SetTextStrComInto(val) {
    if (val == 1)
        $(".ClassComMyReyt").html("Ужасно");
    else if (val == 2)
        $(".ClassComMyReyt").html("Плохо");
    else if (val == 3)
        $(".ClassComMyReyt").html("Нормально");
    else if (val == 4)
        $(".ClassComMyReyt").html("Хорошо");
    else if (val == 5)
        $(".ClassComMyReyt").html("Отлично");
}
function SetTextStrComIntoCab(val, id) {
    if (val == 1)
        $("#GolosReytStr" + id).html("Ужасно");
    else if (val == 2)
        $("#GolosReytStr" + id).html("Плохо");
    else if (val == 3)
        $("#GolosReytStr" + id).html("Нормально");
    else if (val == 4)
        $("#GolosReytStr" + id).html("Хорошо");
    else if (val == 5)
        $("#GolosReytStr" + id).html("Отлично");
}    
function HideError(id)
{
    $('#'+id).hide();
}
function HideErrorCab(id)
{
    $('#errorDiv'+id).hide();
}        
function OnGetDataError(error, userContext, methodName) // получили сообщение об ошибке асинхронного запроса
{
    if (error != null) {
        alert(error.get_message());
    }
}

function AddMyCartFromCatalog(Myguid, context) {
    PageMethods.AjaxAddForCatalog(Myguid, OnGetDataComplete, OnGetDataError, context)
    return false;
 } 
function ShowHide(id)
{
if ($('#'+id).css("display")=="none")
    $('#'+id).slideDown('500');
else
    $('#'+id).slideUp('500');        
}
function ImgSmallClick(id)
{
img = document.getElementById("imgsmall" + id);
imgBig = document.getElementById("imgbig");
imgBig.src = img.src;
}
function show_results(){
    $('#ShowResultLink').css("display", "none");        
    $('#BizFormDiv').slideDown('500');
}
function show_resultsInComm()
{
    $('#ShowResultLinkIntoComm').css("display", "none");        
    $('#AddIntoComm').slideDown('500');
}
function set_star_Into(i)
{
    $('.currentSet').css('width','');
    $('.currentSet').attr('class','');                            
    $('#liIn'+i).attr('class','currentSet');
    $('#liIn'+i).css("width", i*15 +"px"); 
    document.getElementById("starRSpan").innerHTML=i;
} 
function GetStrReyt(ColEl)
{
    for(var i=0; i<ColEl;i++ )
    {
        if ($('#ReytSpanCol'+i).html()==1)
            $('#GolosReytStr'+i).html("Ужасно")
        else if($('#ReytSpanCol'+i).html()==2)
            $('#GolosReytStr'+i).html("Плохо")
        else if($('#ReytSpanCol'+i).html()==3)
            $('#GolosReytStr'+i).html("Нормально")
        else if($('#ReytSpanCol'+i).html()==4)
            $('#GolosReytStr'+i).html("Хорошо")
        else if($('#ReytSpanCol'+i).html()==5 )
            $('#GolosReytStr'+i).html("Отлично")                                
    }
    
}  
function HideTD(count)
{
for(var i=0;i<count;i++)
    {
        if (i>0 && ($('#td'+i).html()==$('#td'+(i-1)).html()))
            {
            $('#td'+i).html("");
            $('#2td'+i).html("");
            }
        $('#StatusTd'+i).html(GetStatus($('#StatusTd'+i).html()));
        $('#StatDivThis'+i).html(GetStatus($('#StatusTd'+i).html()));
    }
} 
function GetStatus(status)
{
    if(status==2)
        return "Заказ обрабатывается менеджером";
    else if(status==3)
        return "Заказ в работе";
    else if(status==4)
        return "Заказ выехал со склада ";
    else if(status==5)
        return "Заказ аннулирован";
    else if(status==6)
        return "Заказ доставлен";
    else
        return "Заказ принят";
}  
function set_star(i,j)
{
    $('.currentSet').attr('class','');
    $('#'+j+'li'+i).attr('class','currentSet');
    $('#'+j+'li'+i).css("width", i*15 +"px"); 
    document.getElementById("starRSpan"+j).innerHTML=i;
}  
function NewTel(number)
{
    $("#addB"+number).hide();
    $('#TRTel'+(number+1)).css("display","");
} 
function SetNewEdit(idThis, idCom)
{ 
    if( document.getElementById("starRSpan"+idThis).innerHTML=="0")
     $('#errorDiv'+idThis).show();
    else if (document.getElementById('TextEdit'+idThis).value=="")
    $('#errorDivEdit'+idThis).show();
    else      
    PageMethods.MyAjaxFunctionCab(document.getElementById("starRSpan"+idThis).innerHTML,idCom,document.getElementById('TextEdit'+idThis).value, OnGetDataComplete, OnGetDataError,idThis);
}
function DeleteComment(idThis,idCom)
{
    if (confirm("Уверены, что хотите удалить?"))
    {
    PageMethods.MyAjaxDeleteFunctionCab(idThis,idCom, OnGetDataComplete, OnGetDataError)
    }        
} 
function Book()
{
    $('#Book').slideDown('500');
    $('#ButOrder').hide();
}       
function empty()
{ }  
function DeleteCommentCart(idThis,idCom)
{
    if (confirm("Уверены, что хотите удалить?"))
    {
     PageMethods.MyAjaxDeleteFunctionCart(idCom, OnGetDataComplete, OnGetDataError,idThis)
    }        
} 
function ChangeSum(idThis, idCart)
{
    if(!LoockMas[idThis])
    {
        PageMethods.MyAjaxEditFunctionCart(document.getElementById('InCol'+idThis).value,idCart,OnGetDataComplete, OnGetDataError,idThis);
        LoockMas[idThis]=true;
    }
}
/*newsblock animation start ->*/
function InitInterChange(divid)
{
    index = divid;
    intervalID = window.setInterval(AutoSetNewsBlockContent, 15000);
    $("#newsblock0").hover( function () { HoldAnimation(); }, function () { RestartAnimation(); } );
}
function AutoSetNewsBlockContent()
{
    var newindex = index + 1;
    index = ($("#pnewsblock" + newindex).length == 0) ? 1 : newindex;
    $("#pnewsblock0").fadeOut(400, function() {
        $("#pnewsblock0").hide();
        $("#pnewsblock0").html($("#pnewsblock" + index).html());
        $("#h3newsblock0").html($("#h3newsblock" + index).html());
        $("#anewsblock0").attr("href", $("#anewsblock" + index).attr("href"));
        $("#pnewsblock0").fadeIn(400);
    });
}
function HoldAnimation()
{
    clearInterval(intervalID);
}
function RestartAnimation()
{
    intervalID = window.setInterval(AutoSetNewsBlockContent, 15000);
}
/*<- end newsblock animation*/
