/*AJAX*/

var xmlHttp

// AJAX HTTP OBJECT
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;
}

// ADD TO CART
function addToCart(action, proid,catid)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="ajax-cart.php"
	url=url+"?action="+action
	url=url+"&id="+proid
	url=url+"&catid="+catid
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedCart 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChangedCart() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("basketid").innerHTML=xmlHttp.responseText 
		document.getElementById("basketid").style.display='block';
		document.getElementById("cartid").style.display='none'; 
	} 
}

function updateCart(action,item,itemname)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="ajax-cart.php"
	url=url+"?action="+action
	url=url+"&item="+item
	url=url+"&itemname="+itemname
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateUpdateCart 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateUpdateCart() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("basketid").innerHTML=xmlHttp.responseText 
		document.getElementById("basketid").style.display='block';
		document.getElementById("cartid").style.display='none'; 
	} 
}

//MY CART
function addToMyCart(action, proid)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="ajax-mycart.php"
	url=url+"?action="+action
	url=url+"&id="+proid
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedMyCart 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChangedMyCart() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("mybasketid").innerHTML=xmlHttp.responseText 
		document.getElementById("mybasketid").style.display='block';
		document.getElementById("mycartid").style.display='none'; 
	} 
}
//UPDATE MY CART
function updateMyCart(action,item,itemname)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="ajax-mycart.php"
	url=url+"?action="+action
	url=url+"&item="+item
	url=url+"&itemname="+itemname
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateUpdateMyCart 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateUpdateMyCart() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("mybasketid").innerHTML=xmlHttp.responseText 
		document.getElementById("mybasketid").style.display='block';
		document.getElementById("mycartid").style.display='none'; 
	} 
}

//PROMO CODE ---> MY CART
function checkPromo(promo)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request")
	 	return
	}
	var url="ajax-promo.php"
	url=url+"?promo="+promo
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=statePromo 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function statePromo() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("mybasketid").innerHTML=xmlHttp.responseText 
		document.getElementById("mybasketid").style.display='block';
		document.getElementById("mycartid").style.display='none'; 
	} 
}

