﻿var wsUrl="/ws/sellbody.asmx/";
var cart=
{
        c:"cart",//cart name
        d:"d_cart",//show cart
        s:"s_c",//small cart
        r:"rent",// rent
        addtocart:function(cvalue,ctype)
        {   var t=this;
            var now=new Date(); var rshopid=now.getHours()+"_"+now.getMinutes()+"_"+now.getSeconds()+"_"+now.getMilliseconds();
            var objvalue=rshopid+"|"+cvalue+"|"+ctype;
            var cookievalue=Cookies.getCookie(t.c)!=null?Cookies.getCookie(t.c):'';
            if(cookievalue!=''){cookievalue+="~"+objvalue;}else{cookievalue=objvalue;}
            Cookies.delCookie(t.c);Cookies.addCookie(t.c,cookievalue,0);
            cc.f3(800,'s_c');
            t. getscart();
            location.href="#now";
            
        },
        getcartInfo:function(ctype)
        {   var t=this;
            if(Cookies.getCookie(t.c)==null||Cookies.getCookie(t.c)==''){$(t.d).innerHTML="Sorry,Your cart is empty!"}
            else{var nValue=Cookies.getCookie(t.c); var url=wsUrl+"GetcartInfo";var rentId=Cookies.getCookie(t.r);
            var params="body="+nValue+"&rentId="+rentId+"&ctype="+ctype;
            Ajax.open('POST',url,params,'TEXT',function(o){$(t.d).innerHTML=o;});}
        },
        getscart:function()
        {   var t=this;
            var m="Your cart is empty.";
            if(Cookies.getCookie(t.c)!=null&&Cookies.getCookie(t.c)!='')
            {var nValue=Cookies.getCookie(t.c);var o=nValue.split('~');var num=o.length;m="There is  <font class='pC'>"+num+"</font>  goods in cart."}
            $(t.s).innerHTML=m;
        },
        delcart:function(nId)
       {   var t=this;
           var nValue=Cookies.getCookie(t.c);
           Cookies.delCookie(t.c);
           var o=nValue.split('~');
           var newValue='';
          for(i=0;i<o.length;i++)
          {
            var v=o[i];var ov=v.split('|');
            if(ov[0]!=nId){if(newValue.charAt(newValue-1)!='~'&&newValue!=''){newValue+="~";} newValue+=o[i]; } 
          }
         Cookies.addCookie(t.c,newValue,0)
         t.getcartInfo('edit');
         cc.f3(600,'s_c');
         t. getscart();
        
        },
    ck:function()
    {
        var t=this;
        if(Cookies.getCookie(t.c)!=null&&Cookies.getCookie(t.c)!=''){location.href='/checkout';}
        else{alert('Your cart is empty!');}
    }
}
var shop=
{
    gId:6,
    sId:0,
    add:function(nId,stype)
    {
        var t=this;
        var cvalue=t.gId+"^"+t.sId+"^"+nId+"^"+1;
        cart.addtocart(cvalue,stype);
    },
    addpl:function(skillId,s,e,stype)
    {
        var t=this;
        var n=skillId+"*"+s+"*"+e;
        t.add(n,stype); 
    }
}