// JavaScript Document

var xmlHttp
var date_now=new Date()

/*function showHint(str)
{ 
	if (str.length > 0)
	{ 
		var url="sample1.asp?q=" + str
		xmlHttp=GetXmlHttpObject(stateChanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	} 
	else
	{ 
		k=document.frm.txtHint.options.length;
		for(m=1;m<=parseInt(k);m++)
		{
			document.frm.txtHint.options[1]=null
		}
	} 
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		k=document.frm.txtHint.options.length;
		for(m=1;m<=parseInt(k);m++)
		{
			document.frm.txtHint.options[1]=null
		}
		
		newstr=xmlHttp.responseText;
		newstr1=newstr.split(",");
		for (i=0;i<newstr1.length;i++)
		{
			document.frm.txtHint.options[i+1]=new Option();
			document.frm.txtHint[i+1].value=newstr1[i];
			document.frm.txtHint[i+1].text=newstr1[i];
		}
	} 
} */

function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera") 
		return 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
} 


function LoadMiniCart()
{
		var date_now=new Date()
		var url="LoarminiCart.asp?Doact=InitCart&timestamp="+date_now
		//alert(url)
		xmlHttp=GetXmlHttpObject(bodychanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
}
function AddToMiniCart(PID)
{
		var date_now=new Date()
		var url="LoarminiCart.asp?Doact=Addcart&timestamp="+date_now+"&prodid="+PID
		//alert(url)
		xmlHttp=GetXmlHttpObject(newchanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
		
}
function MakeCartEmpty()
{
		var date_now=new Date()
		var url="LoarminiCart.asp?Doact=Delcart&timestamp="+date_now
		//alert(url)
		xmlHttp=GetXmlHttpObject(newchanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
		document.getElementById("cartcount").innerHTML="";
		alert("Your cart is empty")
}
function GoToCheckOut()
{
		var date_now=new Date()
		var url="LoarminiCart.asp?Doact=Chkout&timestamp="+date_now
		//alert(url)
		xmlHttp=GetXmlHttpObject(newchanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
	
}
function newchanged() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//alert(xmlHttp.responseText)
		if (xmlHttp.responseText=="E")
		{
			alert("Cart is Empty")
		}
		else if (xmlHttp.responseText=="L")
		{
			document.frm.doaction.value="ChekOut"
			document.frm.action="../account/login.asp";
			document.frm.submit();
		}
		else if (xmlHttp.responseText=="C")
		{
			document.frm.action="../shopping/dd_shoppingdetail.asp";
			document.frm.submit();
		}
		else
		{
			var output=xmlHttp.responseText
			splitoutput=output.split("!#!")
			document.getElementById("result").innerHTML=splitoutput[0];
			//alert(splitoutput[1])
			if (splitoutput[1] > 0)
			{
				document.getElementById("cartcount").innerHTML="(" + splitoutput[1] + " Items)";
				while (document.getElementById("cartcount").innerHTML == "")
				{
					
				}
				alert("Item added in your cart successfully")
					
			}
		}
	} 
} 

function bodychanged() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//alert(xmlHttp.responseText)
		if (xmlHttp.responseText=="E")
		{
			alert("Cart is Empty")
		}
		else if (xmlHttp.responseText=="L")
		{
			document.frm.doaction.value="ChekOut"
			document.frm.action="../account/login.asp";
			document.frm.submit();
		}
		else if (xmlHttp.responseText=="C")
		{
			document.frm.action="../shopping/dd_shoppingdetail.asp";
			document.frm.submit();
		}
		else
		{
			var output=xmlHttp.responseText
			splitoutput=output.split("!#!")
			document.getElementById("result").innerHTML=splitoutput[0];
			//alert(splitoutput[1])
			if (splitoutput[1] > 0)
			{
				document.getElementById("cartcount").innerHTML="(" + splitoutput[1] + " Items)";
					
			}
		}
	} 
} 
function cartchanged() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//alert(xmlHttp.responseText)
		if (xmlHttp.responseText=="E")
		{
			alert("Cart is Empty")
		}
		else if (xmlHttp.responseText=="L")
		{
			document.frm.doaction.value="ChekOut"
			document.frm.action="../account/login.asp";
			document.frm.submit();
		}
		else if (xmlHttp.responseText=="C")
		{
			document.frm.action="../shopping/dd_shoppingdetail.asp";
			document.frm.submit();
		}
		else
		{
			var output=xmlHttp.responseText
			splitoutput=output.split("!#!")
			document.getElementById("result").innerHTML=splitoutput[0];
			//alert(splitoutput[1])
			if (splitoutput[1] > 0)
			{
				document.getElementById("cartcount").innerHTML="(" + splitoutput[1] + " Items)";
			}
		}
	} 
} 