﻿
/*
100 erro,back page!
101 no record found，back to page!
102 Selected item added to you cart!
103 the item have been in your cart!
*/
/*
var cart__1=0;
var cart__2=0;
*/
/*
说明：AJAX创建要考虑到不同的浏览器问题，我这里列了IE和非IE的创建方式。
创建好了就打开实例--发送--接收（一般是一个函数）并显示处理页面返回的信息（根据不同的状态显示不同的信息）。
*/
function createAjax(){
    var http;
         if (window.ActiveXObject){
             http=new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Microsoft.XMLHTTP") : new ActiveXObject("Msxml2.XMLHTTP");
              }
        else if(window.XMLHttpRequest){
            http=new XMLHttpRequest();
              }


     return http;
}






    var ajax=createAjax();
function show(Kx,pr_,qu_){//ajax乱码是因为在传递中文的时候没有进行编码，escape（）是进行编码。
    

    var nowurl=window.location;
       //window.alert(nowurl+Kx);
    var url2="/putcart.asp?pid=" + Kx + "&price=" + escape(pr_) + "&qu=" +qu_+ "&returl="+escape(nowurl)+ "&randomnum=" + Math.random()
       //window.alert(url2);
    cart__1=1;
    cart__2=pr_;
    ajax.open("GET",url2,true);
    ajax.send(null);
    ajax.onreadystatechange=getmessage;
    //window.alert(ajax.responseText);
}

function show2(Kx,pr_,qu_){//ajax乱码是因为在传递中文的时候没有进行编码，escape（）是进行编码。
    
    var myKx,mypr_,myqu_
    myKx=document.dvddetailform.pid.value;
    mypr_=document.dvddetailform.price.value;
    myqu_=document.dvddetailform.quantity.value;
    cart__1=myqu_;
    cart__2=Number(mypr_)*Number(myqu_);

       //window.alert(myKx+"===="+mypr_+"===="+myqu_+"|||||||");
    var nowurl=window.location;
       //window.alert(nowurl+Kx);
    var url2="/putcart.asp?pid=" + myKx + "&price=" + escape(mypr_) + "&qu=" +myqu_+ "&returl="+escape(nowurl)+ "&randomnum=" + Math.random()
       //window.alert(url2);
    ajax.open("GET",url2,true);
    ajax.send(null);
    ajax.onreadystatechange=getmessage;
    //window.alert(ajax.responseText);
}


function getmessage(){
    var html;
     if (ajax.readyState==4){
            if (ajax.status==200){
                 html=ajax.responseText;
                 //document.getElementById("massage_content").innerHTML=html;
                 //alert(html+"|||"+cart_1+"|||"+cart_2);
                 //通过html返回值为判断
                 //add to cart
                   if (html=="102"){
                       cart_1+=Number(cart__1);
                       cart_2+=Number(cart__2);
                       document.getElementById("cart1").innerHTML=cart_1;
                       document.getElementById("cart2").innerHTML="$&nbsp;"+cart_2;
                         }
                  //alert(html);
                   switch (html){
                    case "100":
                           alert('erro,back page!');
                           break;
                    case "101":
                           alert('no record found，back to page!');
                           break;
                    case "102":
                           alert('Selected item added to you cart!');
                           break;
                    case "103":
                           alert('the item have been in your cart!');
                           break;
                    default:
                           alert('system erro!');
                           break;
                      }

                 //location.reload();
            }
            else{
                 alert('status is:'+ajax.status);
            }

     }else{
          //document.getElementById("massage_content").innerHTML="<center><br/><br/><br/><br/><img src='/images/loading.gif' /><br/>数据提交中...</center>";
          //alert('get page,please waitting');
     }

}

/*从购物车中删除*/
function cdel___(x,y){
 var x;
 var y;
 var url="Delcart.asp?pid=" +x + "&Sid="+y;
 if (confirm("do you really cancel the items?")){
     window.location=url;
     }
}


//