//object detection to return the correct object depending upon broswer type.
function getNewHttpObject() {
    var objType = false;
    try {
        objType = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
        try {
            objType = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
            objType = new XMLHttpRequest();
        }
    }
    return objType;
}

//Function used to update page content with new xhtml fragments by using a javascript object, the dom, and http.
function getAXAH(url,elementContainer){
	document.getElementById(elementContainer).innerHTML = '<div id="loader">Laddar Sida...</div>';
	var theHttpRequest = getNewHttpObject();
	theHttpRequest.onreadystatechange = function() {processAXAH(elementContainer);};
	theHttpRequest.open("GET", url);
	theHttpRequest.send(false);

		function processAXAH(elementContainer){
		   if (theHttpRequest.readyState == 4) {
			   if (theHttpRequest.status == 200) {
				   document.getElementById(elementContainer).innerHTML = theHttpRequest.responseText;
			   } else {
				   document.getElementById(elementContainer).innerHTML="error";
			   }
		   }
		}

}

function addItem(id)
{
	var theHttpRequest = getNewHttpObject();
	
	document.getElementById("status" + id).innerHTML = "<img src='loading.gif' alt='loading' />";
	
	var url = "addItemToCart.php?itemId=" + id + "&itemQuantity=" + document.forms['items'].elements['item' + id].value;
	theHttpRequest.onreadystatechange = function() {processAXAH("item" + id);};
	theHttpRequest.open("GET", url);
	theHttpRequest.send(false);
		
		function processAXAH(elementContainer){
		   if (theHttpRequest.readyState == 4) {
			   if (theHttpRequest.status == 200) {
				   //Det lyckades!
				   document.getElementById("status" + id).innerHTML="";
			   } else {
				   alert("Something went wrong!");
			   }
		   }
		}

}
