// JavaScript Document

/*---------------------------------------------------------

----------------------------------------------------------*/
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 // Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
	return xmlHttp;
}
/*---------------------------------------------------------
update(pid, qtyId):
----------------------------------------------------------*/
function update(pid, qtyId){
	qty = document.getElementById(qtyId).value;
	//alert("Pid: "+pid+" - Qty: "+qty);
	ajaxRequest = GetXmlHttpObject(); 
	if (ajaxRequest==null){
		alert ("Browser does not support HTTP Request")
		return
	} 

	// Add parameter 'q' to URL
	var url = '../assets/ajaxPages/updateQty.php?pid='+pid+"&qty="+qty;	
	// Adds a random number to prevent the server from using a cached file
	url=url+"&sid="+Math.random();	
   
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			response = ajaxRequest.responseText;
			//document.getElementById('test').innerHTML="Pid: "+pid+" - Qty: "+qty;
			//document.getElementById('test').innerHTML=response;
		}
	}
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null);
}
/*---------------------------------------------------------
delete(pid):
----------------------------------------------------------*/
function deleteInventory(pid){
	qty = 0; //document.getElementById(qtyId).value;
	//alert("Pid: "+pid+" - Qty: "+qty);
	ajaxRequest = GetXmlHttpObject(); 
	if (ajaxRequest==null){
		alert ("Browser does not support HTTP Request")
		return
	} 

	// Add parameter 'q' to URL
	var url = '../assets/ajaxPages/updateQty.php?pid='+pid+"&qty="+qty;	
	// Adds a random number to prevent the server from using a cached file
	url=url+"&sid="+Math.random();	
   
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			response = ajaxRequest.responseText;
			//document.getElementById('test').innerHTML="Pid: "+pid+" - Qty: "+qty;
			document.getElementById('test').innerHTML=response;
		}
	}
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null);
}
