function ChangeAttributeValue(strHdnAttributes, strHdnControls)
{
	var hdnAttributes = document.getElementById(strHdnAttributes);
	var hdnControls = document.getElementById(strHdnControls);
	var aControls = hdnControls.value.split('|');
	
	SetProductDynProperties(hdnAttributes.value, aControls[0], aControls[1], aControls[2], aControls[3], aControls[4], aControls[5], aControls[6], aControls[7], aControls[8], aControls[9], aControls[10]);
}

function InitAttributes(strHdnList)
{
	var aHdn = strHdnList.split('|');
	
	for (var i=0; i < aHdn.length/2; i++)
	{
		ChangeAttributeValue(aHdn[i*2], aHdn[i*2 + 1]);
	}
}

function SetProductDynProperties(strValues, cssStyles, objOrder, ddl1, ddl2, spnPrice, spnAltPrice, spnAN, image, hlProd, spnStockStatus, strHdnObj)
{
	var dropdown1 = document.getElementById(ddl1);
	var dropdown2 = document.getElementById(ddl2);
	
	var price;
	var altPrice;
	var an;
	var imgProduct;
	var status;
	var order;
	var hlProduct;
	
	if (spnPrice != null)
	{
		price = document.getElementById(spnPrice);
	}
	else
	{
		price = null;
	}
	if (spnAltPrice != null)
	{
		altPrice = document.getElementById(spnAltPrice);
	}
	else
	{
		altPrice = null;
	}
	if (spnAN != null)
	{
		an = document.getElementById(spnAN);
	}
	else
	{
		an = null;
	}
	
	if (image != null)
	{
		imgProduct = document.getElementById(image);
	}
	else
	{
		imgProduct = null;
	}
	
	if (hlProd != null)
	{
		hlProduct = document.getElementById(hlProd);
	}
	else
	{
		hlProduct = null;
	}
	
	if (spnStockStatus != null)
	{
		status = document.getElementById(spnStockStatus);
	}
	else
	{
		status = null;
	}
	
	if (objOrder != null)
	{
		order = document.getElementById(objOrder);
	}
	else
	{
		order = null;
	}
	
	var dynStyles;
	var dynProperties, dynPrices, dynAltPrices, dynAN, dynImages, dynStatuses, dynOrder;
	var selIdx1 = dropdown1.selectedIndex;
	var items1 = dropdown1.options.length;
	var selIdx2;
	var items2;
	if (dropdown2 != null)
	{
		items2 = dropdown2.options.length;
		selIdx2 = dropdown2.selectedIndex;
	}
	else
	{
		items2 = 0;
		selIdx2 = -1;
	}
	dynStyles = cssStyles.split(';');
	dynAN = new Array();
	dynProperties = strValues.split('|');
	if (dynProperties[0].length > 0)
	{
		dynPrices = dynProperties[0].split(';');
	}
	dynAltPrices = -1;
	if (dynProperties[1].length > 0)
	{
		dynAltPrices = dynProperties[1].split(';');
	}
	if (dynProperties[2].length > 0)
	{
		dynAN = dynProperties[2].split(';');
	}
	if (dynProperties[3].length > 0)
	{
		dynImages = dynProperties[3].split(';');
	}
	if (dynProperties[4].length > 0)
	{
		dynStatuses = dynProperties[4].split(';');
	}
	if (dynProperties[5].length > 0)
	{
		dynOrder = dynProperties[5].split(';');
	}
	
	var selValue = dropdown1.options[dropdown1.selectedIndex].text;
	
	if (dropdown2 != null)
	{
		if (price != null)
		{
			SetInnerText(price, dynPrices[selIdx1*items2 + selIdx2]);
			SetCssClass(price, dynStyles[0]);

			//price.innerText = dynPrices[selIdx1*items2 + selIdx2];
		}
		if (altPrice != null)
		{
			var altText;
			
			if(dynAltPrices != -1)
			{
				altText = dynAltPrices[selIdx1*items2 + selIdx2];
				SetInnerText(altPrice, altText);
			}	 
			
			if (altText != "" && altText != null)
			{
				SetCssClass(price, dynStyles[2]);
				SetCssClass(altPrice, dynStyles[1]);
			}
			//altPrice.innerText = dynAltPrices[selIdx1*items2 + selIdx2];
		}
		if (an != null)
		{
			SetInnerText(an, dynAN[selIdx1*items2 + selIdx2]);
			//an.innerText = dynAN[selIdx1*items2+selIdx2];
		}
		if (imgProduct != null && dynImages != null)
		{
			ChangeImage(image, hlProd, dynImages[selIdx1*items2 + selIdx2], strHdnObj);	
			//SetImage(imgProduct, dynImages[selIdx1*items2 + selIdx2]);
		}
		if (status != null)
		{
			SetInnerText(status, dynStatuses[selIdx1*items2 + selIdx2]);
		}
		if (order != null)
		{
			SetOrderStatus(order, dynOrder[selIdx1*items2 + selIdx2]);
		}
	}
	else
	{
		if (price != null)
		{
			SetInnerText(price, dynPrices[selIdx1]);
			SetCssClass(price, dynStyles[0]);
			//price.innerText = dynPrices[selIdx1];
		}
		if (altPrice != null)
		{
			var altText;
			
			if(dynAltPrices != -1)
			{
				altText = dynAltPrices[selIdx1];
				SetInnerText(altPrice, altText);
			}	
			if (altText != "" && altText != null)
			{
				SetCssClass(price, dynStyles[2]);
				SetCssClass(altPrice, dynStyles[1]);
			}
			
			//altPrice.innerText = dynAltPrices[selIdx1];
		}
		if (an != null)
		{
			SetInnerText(an, dynAN[selIdx1]);
			//an.innerText = dynAN[selIdx1];
		}
		if (imgProduct != null && dynImages != null)
		{
			ChangeImage(image, hlProd, dynImages[selIdx1], strHdnObj);
			//SetImage(imgProduct, dynImages[selIdx1]);
		}
		if (status != null)
		{
			SetInnerText(status, dynStatuses[selIdx1]);
		}
		if (order != null)
		{
			SetOrderStatus(order, dynOrder[selIdx1]);
		}
	}
}

function SetInnerText(obj, value)
{
	var new_txt = document.createTextNode(value);
	if (obj.childNodes.length > 0)
	{
		obj.replaceChild(new_txt, obj.childNodes[0]);
	}
	else
	{
		obj.appendChild(new_txt);
	}
}

function SetImage(obj, obj2, value)
{
	//debugger
	if (value == "" || value == null)
	{
		if (obj != null)
		{
			obj.style.visibility = "hidden";
		}
		if (obj2 != null)
		{
			obj2.style.visibility = "hidden";
		}
	}
	else
	{
		if (obj != null)
		{
			obj.style.visibility = "";
		}
		if (obj2 != null)
		{
			obj2.style.visibility = "";
		}
		
		var imageNameIdx = obj.src.lastIndexOf('/');
	
		var newSrc = obj.src.substring(0, imageNameIdx + 1) + value;
		obj.src = newSrc;
	}
}

function SetOrderStatus(obj, value)
{
	if (value == "true")
	{
		if (obj != null)
		{
			obj.style.visibility = "";
		}
	}
	else
	{
		if (obj != null)
		{
			obj.style.visibility = "hidden";
		}
	}
}

function SetCssClass(obj, cssClass)
{
	obj.className = cssClass;
}

function ChangeImage(strObjName, strObj2Name, strFileName, strHdnName)
{
	var imgProduct = document.getElementById(strObjName);
	var hlProduct = document.getElementById(strObj2Name);
	var hdnProduct = document.getElementById(strHdnName);
	
	if (imgProduct != null)
	{
		SetImage(imgProduct, hlProduct, strFileName);
		if (hdnProduct != null)
		{
			hdnProduct.value = strFileName;
		}
	}
}

function ChangeLargeImage(strObjHdn)
{
	var hdnFilename = document.getElementById(strObjHdn);
	
	if (hdnFilename != null)
	{
		ShowLargeImage(hdnFilename.value);
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
			break;
		obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
			break;
		obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function DisplaySendTipBox(strBoxObj, strObjLink)
{
	try
	{
		// Get link position
		var linkElement = document.getElementById(strObjLink);
		var xPos = findPosX(linkElement);
		var xOffset = 0;
		var yPos = findPosY(linkElement);
		var yOffset = 20;
		
		// Get box elements
		var baseElement = document.getElementById(strBoxObj);
		var element1 = baseElement.childNodes[0];
		var element2 = baseElement.childNodes[1];
				
			
		element1.style.left = (xPos + xOffset) + "px";
		element2.style.left = (xPos + xOffset) + "px";
		
		element1.style.top = (yPos + yOffset) + "px";
		element2.style.top = (yPos + yOffset) + "px";
		
		baseElement.style.display='block';
	}
	catch (e)
	{
	}
}