// This script builds the content of the Include Expenses box, using a PHP file, and populates the page content box

var xmlHttp;

function addToBasket(itemid, itemtype, itemprice) {
	
	var id = itemid;
	var type = itemtype;
	var price = itemprice;
	var qty = document.getElementById('quantity'+id).value;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var url="/addtobasket.php";
	url=url+"?item="+id+"&type="+type+"&price="+price+"&quantity="+qty;
	
	// Add a timestamp random string to prevent caching in IE
	var date = new Date();
	var timestamp = date.getTime();
	url=url+"&rand="+timestamp;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	document.getElementById('notification').style.display='block';
	setTimeout(function(){ if(window.mytimeout) window.clearTimeout(window.mytimeout); window.mytimeout = window.setTimeout('$("#notification").fadeOut(1500)', 3000); return true; });
}


function addToBasketHot(itemid, itemtype, itemprice) {
	
	var id = itemid;
	var type = itemtype;
	var price = itemprice;
	var qty = document.getElementById('quantity'+id+'hot').value;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var url="/addtobasket.php";
	url=url+"?item="+id+"&type="+type+"&price="+price+"&quantity="+qty;
	
	// Add a timestamp random string to prevent caching in IE
	var date = new Date();
	var timestamp = date.getTime();
	url=url+"&rand="+timestamp;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	document.getElementById('notification').style.display='block';
	setTimeout(function(){ if(window.mytimeout) window.clearTimeout(window.mytimeout); window.mytimeout = window.setTimeout('$("#notification").fadeOut(1500)', 3000); return true; });
}




function buildBasket() {
		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="/buildbasket.php";
	
	// Add a timestamp random string to prevent caching in IE
	var date = new Date();
	var timestamp = date.getTime();
	url=url+"?rand="+timestamp;
	
	xmlHttp.onreadystatechange=updateBasket;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updateBasket() 
{ 
	if (xmlHttp.readyState==4)
	{
		document.getElementById('basket').innerHTML = xmlHttp.responseText;
	}
}





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;
}