var sTmpVarList;
				
function fnOpenLargeImage(sFullImage, strAlt)
{
	var objPopWin=window.open("previewimage.asp?image="+escape(sFullImage)+"&type=image&ImgAlt="+escape(strAlt),'ImagePreview','height=500,width=600,top=25,left=100,help=0,resizable=yes,toolbar=0,location=0,status=0,menubar=0,scrollbars=yes');
	objPopWin.focus();
}
				
function checkQuantity(value1, StockQty,txtbox, frm, sItemMFGName, strPersFieldName, blnHideProducts, bHasVariants)
{

	//pfrm = document.PersonalizationForm
	//Modified
	pfrm = frm;
	strTemp = ''
	var strPerField='';
	if (pfrm.PersonalizationQuestionCounter.value != 0)
	{
		for (i=1; i <= pfrm.PersonalizationQuestionCounter.value; i++)
		{
			if (pfrm.elements["PersonalizationRequired" + i].value == "true" && trim(pfrm.elements["PersonalizationAnswer" + i].value) == "")
			{
				alert("Please answer all required personalization questions!");
				pfrm.elements["PersonalizationAnswer" + i].focus();
				return false;
			}
			if (strTemp != '')
			{
				strTemp = strTemp + '##*-#'
			}
			if (pfrm.elements["PersonalizationAnswer" + i].value!='')
			{			
				strTemp = strTemp + pfrm.elements["PersonalizationQuestion" + i].value + ': ' + pfrm.elements["PersonalizationAnswer" + i].value
			}		
		}
			
		frm.elements[strPersFieldName].value = strTemp		
	}					
					
	value2 = txtbox.value


	if (isNaN(value2))
		{
		 	alert("Please enter a valid quantity")
		 	if (txtbox.type != 'hidden')
		 		txtbox.focus();
		 	return false
		}

	//if (!validate_DOUBLE(txtbox,"quantity")) return false;	
	if (parseFloat(value2) != parseInt(parseFloat(value2)))
		{
			alert("The quantity for this product should be a whole number")
		 	if (txtbox.type != 'hidden')
		 		txtbox.focus();
			return false
		}
	if (value1 > value2)
		{
			alert("The minimum quantity for this product is " + value1)
			txtbox.value = value1
		 	if (txtbox.type != 'hidden')
		 		txtbox.focus();
			return false;
		}
	if(blnHideProducts == "1")
	{
		sTmpVarList = '';
		if (bHasVariants) 
			StockQty = GetMaxStockQty(StockQty)
		if (value2 > StockQty && StockQty != -1)
			{
				if(StockQty != 0) {
					alert('The available quantity in stock for "' + sItemMFGName + '" is ' + StockQty + '. Please reduce the order quantity in order to proceed');
				} else {
					alert(sItemMFGName +' is not in stock at this time. Please check back later.');
				}
				txtbox.value = value2
			 	if (txtbox.type != 'hidden')
			 		txtbox.focus();
				return false;
			}
	}		

		return true;
}
				
function GetMaxStockQty(defQty)
{
	var tmpMaxValue
	var finalMaxValue
	frm = document.form0
	finalMaxValue = defQty;
	sTmpVarList = '';
	for (i = 1; i <= frm.GroupCounter.value; i++)
	{
		ind = frm.elements["VariantGroup" + i].selectedIndex
		tmpMaxValue = eval('varMaxStock' + i + '[' + ind + ']');
		if (tmpMaxValue<finalMaxValue && tmpMaxValue!=-1) 
			finalMaxValue = tmpMaxValue;

		//for getting the variant options string
		if (sTmpVarList != '')
			sTmpVarList = sTmpVarList + ' - '
		sTmpVarList = sTmpVarList + (frm.elements["VariantGroup" + i].options[ind].text);
	}
	return finalMaxValue;
}

function checkQuantitySetPrice(value1,StockQty, txtbox, frm_next, ItemMFGDesc, strProdVarIDDesc, strProdPrice, blnHideProductsinStk, strPersFieldName)
{
	if (checkQuantity(value1, StockQty, txtbox, frm_next, ItemMFGDesc, strPersFieldName, blnHideProductsinStk, true))
	{
		frm = document.form0
		description_text = ""
		total_price = 0
		for (i = 1; i <= frm.GroupCounter.value; i++)
		{
			ind = frm.elements["VariantGroup" + i].selectedIndex
																					
			description_text += frm.elements["VariantGroup" + i][ind].value + ";"
			total_price += parseFloat(frm.elements["variant" + i + "_" + (ind + 1)].value)
		}
		frm.elements[strProdVarIDDesc].value = description_text			
		frm.elements[strProdPrice].value = parseFloat(frm.elements[strProdPrice].value) + total_price
		return true
	}
	else
		return false
}

	function returnObjById( id ) 
	{ 
	    if (document.getElementById) 
	        var returnVar = document.getElementById(id); 
	    else if (document.all) 
	        var returnVar = document.all[id]; 
	    else if (document.layers) 
	        var returnVar = document.layers[id]; 
	    return returnVar; 
	} 
	function toogleOLD(a, b)
	{
		//var temp = "";
		var imga = null;
		var imgb = null;
		imga = returnObjById(a);
		imgb = returnObjById(b);
		//temp = imga.src;

		imga.src = imgb.src;
		//imga.alt = imgb.alt;
	}
	function setHiddenForLargeImg(h1, h2, newLargeSrc, newLargeAlt)
	{
		//alert('newLargeSrc='+ newLargeSrc);
		//alert('newLargeAlt='+ newLargeAlt);

		var hid1 = null;
		var hid2 = null;
		hid1 = returnObjById(h1);
		hid2 = returnObjById(h2);
		hid1.value = newLargeSrc;
		hid2.value =newLargeAlt;
		//alert(hid1.value); 
		//alert(hid2.value); 
	}
	function changeImg(a, newSrc, newAlt, newLargeSrc, newLargeAlt)
	{
		//alert('newLargeSrc='+ newLargeSrc);
		//alert('newLargeAlt='+ newLargeAlt);

		imgSetSrc(a, newSrc);
		imgSetAlt(a, newAlt);
		
		setHiddenForLargeImg('main_img_SRC', 'main_img_ALT', newLargeSrc, newLargeAlt);
	}
	function imgCopySrc(a, b)
	{
		//var temp = "";
		var imga = null;
		var imgb = null;
		imga = returnObjById(a);
		imgb = returnObjById(b);

		imga.src = imgb.src;
	}

	function imgSetAlt(a, newAlt)
	{
		var imga = null;
		imga = returnObjById(a);

		imga.alt = newAlt;
	}

	function imgSetSrc(a, newSrc)
	{
		var imga = null;
		imga = returnObjById(a);

		imga.src = newSrc;
	}
	//
	function fnOpenLargeImageEU()
	{
		var main_img_SRC = null;
		var main_img_ALT = null;

		main_img_SRC = returnObjById('main_img_SRC');
		main_img_ALT = returnObjById('main_img_ALT');
		//alert(main_img_SRC.value);
		fnOpenLargeImage(main_img_SRC.value, main_img_ALT.value);		
	}
	function fnOpenPopupPage(theLocation, theWidth, theHeight) {
		var w = theWidth;
		var h = theHeight;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;	
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl
		myWin = window.open(theLocation, 'picker', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,'+winprops);
		myWin.focus();
	}