/*********************************************************************************
Variations
*********************************************************************************/

var variationSetupArray = new Array();
var variationSelectBoxNames = new Array();
var selectedIndexes = new Array();

function initVariations()
{
	var selectBox;
	for (var i = 0; i < variationSelectBoxNames.length; i++)
	{
		selectedIndexes[i] = 0;
		
		if (i > 0)
		{
			selectBox = document.getElementById(variationSelectBoxNames[i]);
			if (selectBox)
			{
				removeOptions(selectBox, 1);
			}
		}
	}
}

function populateDropdown(boxIndex, selectedIndex)
{
	selectedIndexes[boxIndex] = selectedIndex;
	for (var i = boxIndex + 1; i < selectedIndexes.length; i++)
	{
      selectedIndexes[i] = 0;	
	}
	for (var k = boxIndex + 1; k < variationSelectBoxNames.length; k++)
	{
		var sBox = document.getElementById(variationSelectBoxNames[k]);
		if (sBox)
		{
			removeOptions(sBox, 1);
		}
	}
    if (variationSelectBoxNames[boxIndex + 1])
    {
	  var boxKey = "0";
	  for (var j = 0; j <= boxIndex; j++)
	  {
	    boxKey = boxKey + "_" + selectedIndexes[j];
	  }
	  
	  if (variationSetupArray[boxKey]) 
	  {
	  	selectBox = document.getElementById(variationSelectBoxNames[boxIndex + 1]);
	  	if (selectBox) 
	  	{
	  		var counter = 1;
	  		var hasMoreElements = true;
	  		var dataKey;
	  		while (hasMoreElements)
	  		{
	  			dataKey = boxKey + "_" + counter++;
	  			if (variationSetupArray[dataKey])
	  			{
	  				addOption(selectBox, variationSetupArray[dataKey], variationSetupArray[dataKey]);
				} else {
					hasMoreElements = false;
				}
	  		}
	  	}
	  }
	}
}

function addOption(selectBox, text, value)
{
	var option = document.createElement("OPTION");
	option.text = text;
	option.value = value;
	selectBox.options.add(option);
}

function removeOptions(selectBox, startIndex)
{
	var i;
	for(i = selectBox.options.length-1; i >= startIndex; i--)
	{
		selectBox.remove(i);
	}
}


/*********************************************************************************
End Variations
*********************************************************************************/

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode == 37 || charCode == 39)) {
        return false;
    }
    return true;
}

function swapImage(id,imgSrc,imgWidth,imgHeight, popUpSrc){ 
	document.getElementById(id).setAttribute('src',imgSrc);
	document.getElementById(id).setAttribute('width',imgWidth);
	document.getElementById(id).setAttribute('height',imgHeight);
	popUpImgSrc = popUpSrc;
}
var popUpImgSrc;
function zoom(imgSrc){
	if(!popUpImgSrc)
		popUpImgSrc = popUpImageUrl;
	if(imgSrc)
		popUpImgSrc = imgSrc;
	window.open(popUpImgSrc,'zoom','toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=400,height=400');
}


