// JavaScript Document
function delOrder(id){
	Submit(0);
	createXMLHttpRequest();
	xmlHttp.open("GET", "ajax/order.delete.php?id="+id,true);
	xmlHttp.onreadystatechange = function (){ 
		if(xmlHttp.readyState==4&&xmlHttp.status==200){ 
			document.getElementById("p_order"+id).style.display="none";
			calTotal();
		}
	}
	xmlHttp.send(null);
}
function updateQty(id,sz,ii){
	Submit(0);
	qty=document.getElementById("ct_quantity"+id+"-"+ii).value;

	createXMLHttpRequest();
	xmlHttp.open("GET", "ajax/order.qty.php?id="+id+"&sz="+sz+"&qty="+qty,true);
	xmlHttp.onreadystatechange = function (){ 
		if(xmlHttp.readyState!=4){
			document.getElementById("p_price"+id+"-"+ii).innerHTML="waiting...";
			document.getElementById("subtotal").innerHTML="waiting...";
			document.getElementById("discount").innerHTML="waiting...";
			document.getElementById("shipping").innerHTML="waiting...";
			document.getElementById("total").innerHTML="waiting...";			
		}else if(xmlHttp.readyState==4&&xmlHttp.status==200){ 
			document.getElementById("p_price"+id+"-"+ii).innerHTML=xmlHttp.responseText;
			calTotal();
		}
	}
	xmlHttp.send(null);
}
function calTotal(){
	
	createXMLHttpRequest();
	xmlHttp.open("GET", "ajax/order.total.php",true);
	xmlHttp.onreadystatechange = function (){ 
	 	if(xmlHttp.readyState!=4){
			document.getElementById("subtotal").innerHTML="waiting...";
			document.getElementById("discount").innerHTML="waiting...";
			document.getElementById("shipping").innerHTML="waiting...";
			document.getElementById("total").innerHTML="waiting...";			
		}else if(xmlHttp.readyState==4&&xmlHttp.status==200){ 
			var txt=xmlHttp.responseText;
			var save=txt.split(",") ;
			document.getElementById("subtotal").innerHTML=save[0];
			document.getElementById("discount").innerHTML=save[1];
			document.getElementById("shipping").innerHTML=save[2];
			document.getElementById("total").innerHTML=save[3];
			if(save[4]==0)Submit(0);
			else Submit(1);
		}
	}
	xmlHttp.send(null);
}
function Submit(i){
	document.getElementById("submit_check").innerHTML=(i==1)?"<input type=\"image\" src=\"images/check_out.jpg\">":"<img src=\"images/check_out_hide.jpg\">";
}
/* Login */
/* New */


// =============================================================================================================
// Http Request
// =============================================================================================================
// create XML Http Request
function createXMLHttpRequest(){
	try{
		xmlHttp=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		alert('There was a problem creating the XMLHttpRequest object'); 
	}
}
// display data
function displayinfo(tag){
	document.getElementById(tag).innerHTML=xmlHttp.responseText;
}
var xmlHttp;