function writeValueFromInput(id, from)
{
	if(from == 0)
	{
		document.getElementById('p-'+id).value = document.getElementById('t-'+id).value;
	}
	
	else if(from == 1)
	{
		if(!isNaN(document.getElementById('p-'+id).value))
			document.getElementById('t-'+id).value = document.getElementById('p-'+id).value;
	}
}

function check_box(chkID)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	var xx = document.getElementById("t-"+chkID).value;
	
	var action = "";
	
	if (document.getElementById("c-"+chkID).checked == true) 
	{
		action = "check";
		document.getElementById("t-"+chkID).disabled = false;
	}
	else
	{
		action = "uncheck";
	}

	var url="http://"+window.location.host+"/pages/check_box.php"
	url=url+"?id="+chkID
	url=url+"&action="+action
	url=url+"&quantity="+xx
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 	
		<!--document.getElementById("test").innerHTML=xmlHttp.responseText -->
	} 
}

function update_quantity(id, from)
{
	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	if(from == 0)
	{
		//Inputted from body of page
		var xx = document.getElementById("t-"+id).value;
	}
	else if(from == 1)
	{
		//Inputted from milkbox popup
		var xx = document.getElementById("p-"+id).value;
	}
	
	//alert(xx);
	
	if(isNaN(xx))
	{
		alert('Please enter the quantity you would like to order. Only numbers are allowed.');
		if(from == 0)
			document.getElementById('t-'+id).value = '';
		else if (from == 1)
			document.getElementById('p-'+id).value = '';
	}
	else
	{
		var action = 'update_quantity';
		
		var url="http://"+window.location.host+"/pages/check_box.php"
		url=url+"?id="+id
		url=url+"&action="+action
		url=url+"&quantity="+xx
		url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=stateChanged
		xmlHttp.open("GET",url,true)
		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;
}
