function getXMLHttpRequest() {
		var xmlHttp;
		try
		   {
		 
		     // try to create XMLHttpRequest object
		     xmlHttp = new XMLHttpRequest();
		
		   }
		   catch(e)
		   {
		   var prefixes = ["MSXML2.XmlHttp","Microsoft.XmlHttp","MSXML3.XmlHttp", "MSXML.XmlHttp"];
		     // assume IE6 or older
		   	for (var i = 0; i < prefixes.length; i++) {
				try{xmlHttp = new ActiveXObject(prefixes[i]);}catch(ex){};
			}
		       
		   }
		   // return the created object or display an error message
		   if (!xmlHttp)
		     alert("Error creating the XMLHttpRequest object.");
		   else
		     return xmlHttp;
  }

function addToCart(productId,currentNum) { 
	var num =Number(currentNum);
	if(num<20){
		var xmlHttp=getXMLHttpRequest();
		var url="/myorder/cart.jsf?productId="+productId+"&num="+(num+1);
	 //	var url="/myorder/cart.jsf?productId="+productId;
	 	xmlHttp.open("post",url, true);
		xmlHttp.onreadystatechange = function () {	
			if(xmlHttp.readyState==4){
				 if (xmlHttp.status == 200){
				 	window.location.reload();
	             }
			} 
		}
	
		xmlHttp.send(null);		
	}else{
		alert("单个产品订购最高上限为20盒，您的数量已经达到最大值！");
	} 			
}

function jianToCart(productId,currentNum) {
	var num =Number(currentNum);
	if(num>1){
		var xmlHttp=getXMLHttpRequest();
	 	var url="/myorder/cart.jsf?productId="+productId+"&num="+(num-1);
	 	xmlHttp.open("post",url, true);
		xmlHttp.onreadystatechange = function () {	
			if(xmlHttp.readyState==4){
				 if (xmlHttp.status == 200){
				    window.location.reload();
	             }
			} 
		}
		xmlHttp.send(null);		
	}else{
		alert("您的数量为1，不能在减少！");
	} 
}

function changeValue(productId,currentNum) {
	var num =Number(currentNum);
	if(num>=1&&num<=20){
		var xmlHttp=getXMLHttpRequest();
	 	var url="/myorder/cart.jsf?productId="+productId+"&num="+num;
	 	xmlHttp.open("post",url, true);
		xmlHttp.onreadystatechange = function () {	
			if(xmlHttp.readyState==4){
				 if (xmlHttp.status == 200){
				    window.location.reload();
	             }
			} 
		}
	
		xmlHttp.send(null);		
	}else{
		alert("您的数量为调整需要在1—20之间调整！");
	} 	
}
function delProduct(productId) {
	if(confirm('您确定要删除么？')){
		var xmlHttp=getXMLHttpRequest();
	 	var url="/myorder/cart.jsf?productId="+productId+"&del=-1";
	 	xmlHttp.open("post",url, true);
		xmlHttp.onreadystatechange = function () {	
			if(xmlHttp.readyState==4){
				 if (xmlHttp.status == 200){
				    window.location.reload();
	             }
			} 
		}
		xmlHttp.send(null);
	}		
}
