var xmlHttpColor;

var loadstatustext="<FONT style=BACKGROUND-COLOR: #990033 color=#ff0033><STRONG><FONT color=#123B69>&nbsp;Loading....</FONT></STRONG></FONT>";
var productImagePath
function showColorVariants(productId, productColourId, path, productVariantId)
{
	//alert(productId+"="+productColourId+"="+path+"="+productVariantId);
	//alert(document.getElementById("colourId"+productVariantId));
	if(productColourId=='')
	{
		productColourId	= document.getElementById("colourId_"+productVariantId).value;
	}
	if (productColourId.length==0)
	{ 
		return
	}
	productImagePath = path;
	xmlHttpColor=getHTTPObject();
	if (xmlHttpColor==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
//	var productId = document.getElementById("productId").value;
	var url="products/showColorVariants.php"
	url=url+"?productId="+productId+"&productColourId="+productColourId
	url=url+"&stid="+Math.random()
	xmlHttpColor.onreadystatechange=getColorDetails 
	xmlHttpColor.open("GET",url,true)
	xmlHttpColor.send(null)

} 

/*function showColorVariants(productId, productColourId, path, productVariantId)
{
	//alert(productId+"="+productColourId+"="+path);
	if(productColourId=='')
	{
		productColourId	= document.getElementById("colourId"+productVariantId).value;
	}
	if (productColourId.length==0)
	{ 
		return
	}
	productImagePath = path;
	xmlHttpColor=getHTTPObject();
	if (xmlHttpColor==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
//	var productId = document.getElementById("productId").value;
	var url="products/showColorVariants.php"
	url=url+"?productId="+productId+"&productColourId="+productColourId
	url=url+"&stid="+Math.random()
	xmlHttpColor.onreadystatechange=getColorDetails 
	xmlHttpColor.open("GET",url,true)
	xmlHttpColor.send(null)

} */

function getColorDetails() 
{ 
	if (xmlHttpColor.readyState==4 || xmlHttpColor.readyState=="complete")
	{
		//alert(xmlHttpColor.responseText);
		if(xmlHttpColor.responseText!="") {
			var result =  xmlHttpColor.responseText;
			result	= result.split("|");
			
			//Change the image
			//alert(result[0]);
			//document.getElementById("imgHolder").innerHTML = "";
			//document.getElementById("imgHolder").innerHTML =  result[0];
			var img;
			if(result[0]=="\n" || result[0]=="")
				img="no-image-big.jpg";
			else
				img=result[0];
			var imag="./includes/resize.php?image=../uploaded/products/fabric/"+ img+"&new_width=330&new_height=460";
			
			document.getElementById("mainProductImage").src = imag;
			//document.getElementById("colourId").value = result[1];
			//alert(result[1]);
			
			//Updates the Image URL of <A>
			
			//alert(productImagePath + result[0]);
			
			document.getElementById("mainProductImageLink1").setAttribute('href', productImagePath + result[0] );
			document.getElementById("mainProductImageLink11").setAttribute('href', productImagePath + result[0] );
			
			//document.getElementById("mainProductImageLink2").setAttribute('href', productImagePath + result[0] );
			
			
		}
	} 
}

