﻿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 OnGetDataComplete(result, userContext, methodName) // получили асинхронный ответ
    {
        if (methodName=='MyAjaxAddFunction') 
        {
        $("#Hs-Col").html(result.toString().split('|')[0]);
        $("#Hs-ColAll").html(result.toString().split('|')[2]);
        $("#Hs-Price").html(result.toString().split('|')[1]); 
        $("#SpanAllSummHead").html(result.toString().split('|')[1]);            
        $("#Hs_But").click();
        $("#PostSpan").html($("#PostSpan").html()-(-1));
        $("#BackA").attr('href',"javascript:history.go(-"+$("#PostSpan").html()+")");
    }
    if (methodName == 'AjaxAddForCatalog') {
        $(userContext).after(result.toString());
        userContext.focus();
        $('a#Hs_But').click();
    }
    if (methodName == 'MyAjaxEditCommFunction') {
            $("#AddIntoComm").slideUp('500');
            $("#IdComMyEdit").html(result.toString().split('|')[0]);
            $("#IdComMyReyt").attr('class','rstars'+result.toString().split('|')[1]);
            SetTextStrComInto(result.toString().split('|')[1])
            $("#ShowResultLinkIntoComm").show();
            $("#PostSpan").html($("#PostSpan").html()-(-1));
            $("#BackA").attr('href',"javascript:history.go(-"+$("#PostSpan").html()+")");
        }
        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();
                            
        }
        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();
         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();          
        }                     

    }
    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 AddMyCart1(Myguid)
    {
         PageMethods.MyAjaxAddFunction(Myguid,OnGetDataComplete, OnGetDataError)
     }
     function AddMyCartFromCatalog(Myguid, context) {
         $('#Hs_But, .addtocart').remove();
         PageMethods.AjaxAddForCatalog(Myguid, OnGetDataComplete, OnGetDataError, context)
     } 
    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("Уверены, что хотите удалить?")==true)
        {
        PageMethods.MyAjaxDeleteFunctionCab(idThis,idCom, OnGetDataComplete, OnGetDataError)
        }        
    } 
    function Book()
    {
        $('#Book').slideDown('500');
        $('#ButOrder').hide();
    }       
    function empty()
    { }  
    function DeleteCommentCart(idThis,idCom)
    {
        if (confirm("Уверены, что хотите удалить?")==true)
        {
         PageMethods.MyAjaxDeleteFunctionCart(idCom, OnGetDataComplete, OnGetDataError,idThis)
        }        
    } 
    function ChangeSum(idThis, idCart)
    {
        //$("#SpanTotal"+id).html($("#SpanPrice"+id).html()*document.getElementById('InCol'+id).value);         
        if(!LoockMas[idThis])
        {
            PageMethods.MyAjaxEditFunctionCart(document.getElementById('InCol'+idThis).value,idCart,OnGetDataComplete, OnGetDataError,idThis);
            LoockMas[idThis]=true;
        }
    }