// JavaScript Document
var xmlhttp
var btn1;


 function pause(numberMillis)
{
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true)
	{
	now = new Date();
	if (now.getTime() > exitTime)
		return;
	}
} 

function loadXMLDoc(btn)

{
	btncntrl = document.getElementById("btn" + btn);
	btn1 = btncntrl;
	btncntrl.src="images/mozilla_blu.gif";
	//alert("hello");
	xmlhttp=null;
	
	// code for Mozilla, etc.
	
	if (window.XMLHttpRequest)
	
	{
	
		xmlhttp=new XMLHttpRequest();
	
	}
	
	// code for IE
	
	else if (window.ActiveXObject)
	
	{
	
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	
	}
	
	if (xmlhttp!=null)
	
	{
	
		xmlhttp.onreadystatechange=state_Change;
		url = "cart_insert.php?manufacturer=" + document.getElementById("manufacturer" + btn).value + "&part_no=" + escape(document.getElementById("part_no" + btn).value) + "&qty=" + document.getElementById("qty" + btn).value;
		
		xmlhttp.open("GET",url,true);
		 
		xmlhttp.send(null);
	
	}

	else

	{

		alert("Your browser does not support XMLHTTP.");

	}

}

function state_Change()

{

	// if xmlhttp shows "loaded"
	//pause(1000);
	
	if (xmlhttp.readyState==4)

	{

		// if "OK"
		
		if (xmlhttp.status==200)

		{

			
			txt = xmlhttp.responseText;
			//alert("hello");
			
			if  (txt != "saved") {
				alert("To add items to your cart, please log in!");
				
			} else {
			
			//var obj = document.getElementById("infobox");
			
			//obj.innerHTML = xmlhttp.responseText;
			
			//obj.style.display='block';
				
				alert("Item saved to cart");
			}
			btn1.src="images/addtocart.gif";
			
		}

		else

		{

			alert("Problem retrieving XML data")

		}

	}

}

function showInfoBox(e,url) {

	document.getElementById("infobox").style.left=e.x + "px";
	
	document.getElementById("infobox").style.top=e.y + "px";
	
	loadXMLDoc(url);

}

function hideInfoBox() {

	document.getElementById("infobox").style.display='none';
	
	return false;

}

