var xmlHttp;

function updateReserve(prodid,price,sitename,prodname){
	qtyid = 'product_qty'+prodid;
	qty = document.getElementById(qtyid).value;
	xmlHttp=GetXmlHttpObject();
	totprice = parseInt(qty)*parseInt(price);
	url = "scripts/updateReserve.php?qty="+qty+"&prodid="+prodid+"&sitename="+sitename+"&totprice="+totprice+"&price="+price;
	xmlHttp.open("POST", url ,true);
	xmlHttp.onreadystatechange=
	function(){
		if (xmlHttp.readyState==4){
			response=xmlHttp.responseText;
/*			alert(response);
			alert(document.getElementById('totprice'+prodid).innerHTML);*/
			responsedata = response.split("|");
			document.getElementById('totprice'+prodid).innerHTML = responsedata[0];
			document.getElementById('grandtotprice').innerHTML = responsedata[1];
			alert(prodname+"'s quantity was updated to "+qty);
		}
	};
	xmlHttp.send(null);
}

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;
}

function addSeparatorsNF(nStr, inD, outD, sep)
{
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return nStr + nStrEnd;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
