var xhrc = false;
var xhrfc = false;


// 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 editBothCarts(stockID,qty,action) {

	makeRequestCart("/~jackyglass/EMS_new/lib/scripts/ajax.side_cart.php?stockID="+stockID+"&qty="+qty+"&action="+action);
	makeRequestFullCart("/~jackyglass/EMS_new/lib/scripts/ajax.cart.php?stockID="+stockID+"&qty="+qty+"&action="+action);
	
	return false;
	
}



// generic function - no need to alter

function makeRequestCart(url) {

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

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



// generic function - no need to alter

function refreshSideCart() {

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


// generic function - no need to alter

function makeRequestFullCart(url) {

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

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



// generic function - no need to alter

function refreshCart() {

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