function getXMLHTTPRequest() {
	var req=false;
	try {
		req = new XMLHttpRequest();
	} 	catch(err1) {
	  	try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
			}	catch(err2) {
				try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
				}	catch(err3) {
					req = false;
					alert("failed");
				}
			}
	}
	return req;
}

function generalsearch() {
	srch = document.getElementById("searchentrybox").value;
	if (srch!="" && srch.length>2) {
		window.location="http://www.apex-sports.co.uk/search/gs/"+srch;}
	else {
		alert ("Please enter at least 3 letters");
	}
}

function addtocart(listboxid, prodID) {
	var http = getXMLHTTPRequest();
	if (document.getElementById('c'+listboxid)!=null) {
		if(document.getElementById('c'+listboxid).options[document.getElementById('c'+listboxid).selectedIndex].text=="size.."){
			alert("Please choose the size you would like to order");
			return;
		}
	}
	//send new product details via xmlHTTP then got the cart with window.location to avoid parameters in the URL
	if (document.getElementById('c'+listboxid)===null) {
		modurl = "http://www.apex-sports.co.uk/ajaxbasket.php?p="+prodID+"&a=add&s=n/a&rnd="+Math.random();}
	else {
		modurl = "http://www.apex-sports.co.uk/ajaxbasket.php?p="+prodID+"&a=add&s="+encodeURIComponent(document.getElementById('c'+listboxid).options[document.getElementById('c'+listboxid).selectedIndex].text)+"&rnd="+Math.random();
	}
	document.getElementById("a"+listboxid).style.backgroundPosition="-449px -357px";
	
	http.open("GET", modurl, true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if(http.status == 200) {
				window.location="http://www.apex-sports.co.uk/shoppingcart.php";
			}
		}
	}
	http.send(null);
}
