var xhr = false;
var updateElement = "stock_availability";


// this function is changed per different ajax functionality, 
// there can be multiple instances of this function all using 2 functions below
// the script referenced takes the parameters and outputs the dynamic content
// the 2 functions below then are generic - they perform the request and output the response
// @param: updateElement is the id of span or div to update with ajax content

function checkStock(size,color,updateElement,itemID) {

	makeRequestSelect("/~jackyglass/EMS_new/lib/scripts/ajax.stock_check.php?size="+size+"&color="+color+"&itemID="+itemID);
	
	return false;
	
}



// generic function - no need to alter

function makeRequestSelect(url) {

	if (window.XMLHttpRequest) {
	
		xhr = new XMLHttpRequest();
		
	}else{
	
		if (window.ActiveXObject) {
		
			try {
			
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
				
			}
			
			catch (e) { }
		}
		
	}

	if (xhr) {
	
		xhr.onreadystatechange = showContent;
		xhr.open("GET", url, true);
		xhr.send(null);
		
	}else{
	
		document.getElementById(updateElement).innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
		
	}
	
}



// generic function - no need to alter

function showContent() {

	if (xhr.readyState == 4) {
	
		if (xhr.status == 200) {
		
			var outMsg = (xhr.responseXML && xhr.responseXML.contentType=="text/xml") ? xhr.responseXML.getElementsByTagName("choices")[0].textContent : xhr.responseText;
			
		}else{
		
			var outMsg = "There was a problem with the request " + xhr.status;
			
		}
		
		document.getElementById(updateElement).innerHTML = outMsg;
		
	}
	
}