// This is just a function that returns a handle for the AJAX ojbect
function GetXmlHttpObject(){
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}


// Call THIS function when you need to test the state of the basket
function checkBasketIsValid(basketId){
	var date = new Date();
	var timestamp = date.getTime();
	xmlHttp=GetXmlHttpObject()
	var url="../check_basket_is_still_valid.php?time="+timestamp+"&basket="+basketId
	xmlHttp.onreadystatechange=basketCheckResult
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


// This function displays the results of the check
// You can write the results back to the HTML with document.getElementById or set a global var and test before rendering the submit button
function basketCheckResult(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		if(xmlHttp.responseText=='yes'){
			alert('Basket already Checked Out. Please close all your browser windows and try again')
			document.getElementById("ProceedButton").disabled=true
		}
	}

}
