﻿var xmlHttp;
  function updateNum()
	{
		
		var proNum=document.getElementsByName('ProductNum');
		var numValue="";
		for(var i=0; i<proNum.length; i++)
        {
           numValue+=proNum[i].value+','+proNum[i].id+'|';
        }        
        xmlHttp = GetXmlHttp();        
		xmlHttp.onreadystatechange=AddCallBackForCart;		
		xmlHttp.open("GET","AjaxPostBack.aspx?Action=UpdateCart&ChangeValue="+ numValue,true);		
		xmlHttp.send("");
		
	}
	function AddCallBackForCart()
	{
		if(xmlHttp.readyState == 4   ) 
		{
		    
             if(xmlHttp.status==200)
	         {		 	  		      
				    alert("更新成功！");	
			        window.location="Cart.aspx";
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}		
   }
   function delcart()
	{		
        xmlHttp = GetXmlHttp();        
		xmlHttp.onreadystatechange=AddCallDelForCart;		
		xmlHttp.open("GET","AjaxPostBack.aspx?Action=DelCart",true);		
		xmlHttp.send("");
		
	}
	function AddCallDelForCart()
	{
		if(xmlHttp.readyState == 4   ) 
		{
		    
             if(xmlHttp.status==200)
	         {		 	  		      
				    alert("清除成功！");
				    window.location="Cart.aspx";	
			   
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}		
   } 
   
    function submitCart()
	{		
		var data=checkSubmitCart();
		if(data=="")
		{
		return false;	
		}
        xmlHttp = GetXmlHttp();        
		xmlHttp.onreadystatechange=AddCallSubForCart;	
			
		xmlHttp.open("GET","AjaxPostBack.aspx?Action=SubCart" + data,true);		
		xmlHttp.send("");
		
	}
	function checkSubmitCart()
	{
	   var name=document.getElementById("Name").value;
	   if(name=="")
	   {
	     alert("请输入联系人");
	     return "";
	   }
	   var phone=document.getElementById("Phone").value;
	   if(phone=="")
	   {
	     alert("请输入电话号码");
	     return "";
	   }	
	   var email=document.getElementById("Email").value;
	   if(email=="")
	   {
	     alert("请输入邮箱地址");
	     return "";
	   }
	   var addr=document.getElementById("Addr");
	   var content=document.getElementById("Content");
	   if(addr ||content)
	   {
	   
	   }	   
	   return "&Name=" + name +"&Phone=" + phone + "&Email=" + email + "&Addr="  + document.getElementById("Addr").value + "&Content=" + document.getElementById("Content").value;; 		
	}
	function AddCallSubForCart()
	{
		if(xmlHttp.readyState == 4   ) 
		{
		    
             if(xmlHttp.status==200)
	         {		
	                var s=xmlHttp.responseText;
	                if(s=="1")
	                {	  		      
				      alert("提交成功！");
				       window.location="Index.html";
				    }
				    else if (s=="0")
				    {
				      alert("请先登录!");
				    }
				    else
				    {
				       alert("提交错误!");
				       alert(s);
				    }
				    //window.close();	
			   
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}		
   } 
