var getPriceReq = getXmlHttpRequestObject();

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	randomString = randomstring;
}

function checkPrice(product_id, product_colour_id, login, disc)
{	
	if (login == "y")
	{
	if (getPriceReq.readyState == 4 || getPriceReq.readyState == 0) 
	{	
	
		var product_size_id = document.getElementById("size" + product_colour_id + product_id).value;
		getPriceReq.open("GET", 'http://www.fit-equip-home.com/ajax/get-price.asp?forcerefresh='+randomString()+'&loggedin=y&disc='+disc+'&product_size_id='+ product_size_id, true);				
		getPriceReq.onreadystatechange = function() {checkPriceResponse()};
		getPriceReq.send(null);
		
	}
	}
	else
	{
	if (getPriceReq.readyState == 4 || getPriceReq.readyState == 0) 
	{	
		var product_size_id = document.getElementById("size" + product_colour_id + product_id).value;
		getPriceReq.open("GET", 'http://www.fit-equip-home.com/ajax/get-price.asp?forcerefresh='+randomString()+'&product_size_id='+ product_size_id, true);				
		getPriceReq.onreadystatechange = function() {checkPriceResponse()};
		getPriceReq.send(null);
		
	}
	}
}

function checkPriceResponse()
{
	if (getPriceReq.readyState==4)
	{
		var alternate_price = getPriceReq.responseText;
		document.getElementById("prod_price").innerHTML = alternate_price;
		//document.getElementById("prod_price_vat").innerHTML = formatCurrency(priceWithVat(alternate_price)) + " including VAT @ 17.5%";
		
	}
}

function changeSize(prodID)
{
	
	var colID = document.getElementById("colour").value;
	if (document.getElementById("hiddenID").value != "")
	{	
		var temp = document.getElementById("hiddenID").value;
		document.getElementById("size" + temp + prodID).style.visibility = "hidden";
		document.getElementById("size" + temp + prodID).style.display = "none";
		document.getElementById("hideme").style.visibility = "visible";
	document.getElementById("hideme").style.display = "";// was block
	}
	if (colID != 0)
	{
	
	
	document.getElementById("hiddenID").value = colID;
	document.getElementById("size" + colID + prodID).style.visibility = "visible";
	document.getElementById("size" + colID + prodID).style.display = "";// was block
	document.getElementById("hideme").style.visibility = "hidden";
	document.getElementById("hideme").style.display = "none";
	}
	
	

}

function validate(prodID)
{
	var numeric = /^[0-9\,\.]+$/;
	if(document.getElementById("qty" + prodID).value == "")
	{
		alert("Please specify a quantity to add to you basket");
	}
	else
	{
		if(!numeric.test(document.getElementById("qty" + prodID).value))
		{
			alert("Please enter a numeric value");
		}
		else
		{
			document.getElementById('addBask').submit();
		}
	}
}