// JavaScript Document
function getReqXMLHTTPObj()
{
	var a = null;
	try{a = new ActiveXObject("Msxml2.XMLHTTP")}
	catch(b)
	{
		try{a = new ActiveXObject("Microsoft.XMLHTTP")}
		catch(c){a=null;}
	}
	if(!a && typeof XMLHttpRequest!="undefined")
	{
		a = new XMLHttpRequest();
	} 
	return a;
}

var req;
function AjaxCall(url, onCallback) 
{
	
	req = getReqXMLHTTPObj();
    req.onreadystatechange = onCallback;
    var rnd = Math.floor(Math.random()*100000)
    url = url + "&rnd=" + rnd;
    req.open("GET", url, true);
    req.send(null);
}
function incProcess()
{
	var discode=document.getElementById('txtDIscountCode').value;
	AjaxCall('check-discount.php?discode='+discode,increament_processs);
}
function increament_processs()
{
	if (req.readyState == 4) 
	{
		text=req.responseText;
		if(text=='Available')
		{
			var val='<font color="#00FF00">'+text+'</font>';
		}
		else
		{
			var val='<font color="#FF0000">'+text+'</font>';
		}
		document.getElementById('discountid').innerHTML=val;
	}
}
function displayPrice(pprice,mprice,lprice,cprice,tprice)
{
	AjaxCall('show-price.php?pprice='+pprice+'&mprice='+mprice+'&lprice='+lprice+'&cprice='+cprice+'&tprice='+tprice,display_price);
}
function display_price()
{
	if (req.readyState == 4) 
	{
		text=req.responseText;
		//alert(text);
		document.getElementById('idpprice').innerHTML="$"+text;
	}
}
function checkDiscount()
{
	var discode=document.getElementById('txtDIscountCode').value;
	AjaxCall('check-discount.php?discode='+discode,check_discount);
}
function check_discount()
{
	if (req.readyState == 4) 
	{
		text=req.responseText;
		if(text=='Available')
		{
			var val='<font color="#00FF00">'+text+'</font>';
		}
		else
		{
			var val='<font color="#FF0000">'+text+'</font>';
		}
		document.getElementById('discountid').innerHTML=val;
	}
}
function showOrder(ostatus)
{
	if(ostatus=='P')
	{
		document.getElementById('idprocess').style.display='none';
		document.getElementById('idactiveprocess').style.display='inline';
	}
	else
	{
		document.getElementById('idprocess').style.display='inline';
		document.getElementById('idactiveprocess').style.display='none';
	}
	if(ostatus=='D')
	{
		document.getElementById('iddelevered').style.display='none';
		document.getElementById('idactivedelevered').style.display='inline';
	}
	else
	{
		document.getElementById('iddelevered').style.display='inline';
		document.getElementById('idactivedelevered').style.display='none';
	}
	if(ostatus=='A')
	{
		document.getElementById('idacknowledge').style.display='none';
		document.getElementById('idactiveacknowledge').style.display='inline';
	}
	else
	{
		document.getElementById('idacknowledge').style.display='inline';
		document.getElementById('idactiveacknowledge').style.display='none';
	}
	
	if(ostatus=='C')
	{
		document.getElementById('idcan').style.display='none';
		document.getElementById('idactividcan').style.display='inline';
	}
	else
	{
		document.getElementById('idcan').style.display='inline';
		document.getElementById('idactividcan').style.display='none';
	}
	
	AjaxCall('order-listing.php?ResetPager=1&ostatus='+ostatus,show_order);
}
function show_order()
{
	if (req.readyState == 4) 
	{
		text=req.responseText;
		document.getElementById('idorder').innerHTML=text;
	}
}
