/*
File: Main.js
Purpose: Template contains various popular javascript functions that can be used from any view step.
Created by: capeterson@jamestower.com 04/01/03
Application: PPE
Revision History:
--- 04/01/03 - CAP - Created
--- 09/25/03 - ndvaneps - Added a bunch of common, static javascript calls.
--- 11/25/03 - CAP - Added openLayoutValidation function to open a new window from which to validate
										 layout rules.
--- 12/04/03 - CAP - Removed openLayoutValidation function as I need to call it before this template is included.
--- 01/22/04 - CAP - Updated yoGoToStepDm so it uses the "intStep" value passed in, so it doesn't error anymore.
--- 02/02/04 - CAP - Added the CalculatePrice() function.
--- 07/24/04 - ndvaneps - Added "blnDoNotRespondMessage" argument to "yoSendPreview*" functions.
--- 07/28/04 - ndvaneps - Added "blnDoNotRespondMessage" argument to "yoGenPreview" function.
--- 09/08/04 - CAP - Added intCatId to yoBuyIt() function to trick search results for VCs so it doesn't try to
										 find the display information for the product instance that belongs to the SEARCH category since none will!
--- 09/24/04 - CAP - Added "" around the undefined keyword in the yoBuyIt() function to get around the MAC/IE 'undefined' is undefined error
--- 09/28/04 - jataddei - Generating preview in a floating frame instead of a pop up window.
--- 10/21/04 - CAP - Added code to make sure form loaded before allowing BuyIt() function to be called.
--- 03/09/05 - jataddei - Updating to work with Global Tools...done updating as of 03/16/05.
--- 05/13/05 - ecpotter - Updated CalculatePrice() to enforce pricing by quantity increments
--- 07/01/05 - ecpotter - Updated CalculatePrice() to ensure quantity entered was numeric
--- 10/04/05 - ecpotter - Added the CalculateOptionPrice() function.
--- 10/12/05 - ecpotter - Updated CalculatePrice() and CalculateOptionPrice() to accept a new currency symbol
--- 10/18/05 - ecpotter - Updated CalculatePrice() and CalculateOptionPrice() to return the final price as a number
--- 11/14/05 - ndvaneps - Added a debug argument to the send preview functions.
--- 12/09/05 - mmzubairi - Added TrimString()
--- 12/09/05 - mmzubairi - Added isInteger() so that it returns a boolean value
--- 05/18/06 - ecpotter - Added findInList() function.  Returns position in list.
--- 08/04/06 - mjehlen - Added a new price function CalculatePriceNoMultiple, for office depot who has no multiple parameter
--- 10/31/06 - mjehlen - Added the new function tryRequirePhoto(), it looks in viewer for certain RequirePhoto() function if it exists then peform the function
--- 01/30/07 - ecpotter - Updated CalculatePriceNoMultiple to call CalculatePrice so I only have to update one of them.
						Updated CalculatePrice to check for zero-length price inputs.
--- 02/09/07 - mjjoachim - Added forcedigits(obj, strString,strName)
--- 04/02/07 - kbcampeau - Added CalculatePriceNovatus() & ValidateQuantityNovatus();
--- 08/06/07 - mjjoachim - Removed "new Number()" from "intQty = new Number(objQtyField.value)" in ValidateQuantityNovatus because the value may not be a number
--- 08/07/07 - mjjoachim - Use parseFloat rather than parseInt in ValidateQuantityNovatus so that we are validating against exactly what the user enters.
--- 10/10/07 - ecpotter - Forcing some variables in CalculatePrice() to be function scope as IE was having issues sometimes
*/

blnFormLoaded = 0;
blnOkToSubmit = 1;
strEval = "";
blnExitOne = false;
blnExitTwo = false;
arrFakeModalWin = new Array();

function yoExitCheckAsync()
{
	if (blnExitOne && blnExitTwo)
	{
		for (i = 0; i < arrFakeModalWin.length; i++)
		{
			if (arrFakeModalWin[i] != null)
			{
				return(false);
			}
		}
		eval(strEval);
		return(true);
	}
	return(false);
}

// Called when an asynchronously loaded javascript window is unloaded.
// These windows always exit sucessfully.
function yoExitWindowUnloadAsync(objWin)
{
	for (i = 0; i < arrFakeModalWin.length; i++)
	{
		if (arrFakeModalWin[i] == objWin)
		{
			arrFakeModalWin[i] = null;
			break;
		}
	}
	yoExitCheckAsync();
}

// Called to close an asynchronously loaded javascript window.
function yoExitWindowScriptAsync(objWin, blnExit)
{
	if (!blnExit)
		blnExitOne = blnExit;
	objWin.close();
	for (i = 0; i < arrFakeModalWin.length; i++)
	{
		if (arrFakeModalWin[i] == objWin)
		{
			arrFakeModalWin[i] = null;
			break;
		}
	}
	yoExitCheckAsync();
}

function yoGoToStepDm(strMainFile, intStep)
{
	if (blnFormLoaded == 1)
	{
		if (document.ProdInfo.iProdId != undefined)
			alert("iProdId: " + document.ProdInfo.iProdId.value);
		if (document.ProdInfo.iProdID != undefined)
			alert("iProdId: " + document.ProdInfo.iProdID.value);
		alert(document.applets[0].test());
	}
	return(false);
}

function yoGoToStep(strExitUrl, intStep)
{
	if (blnFormLoaded == 1)
	{
		if (document.ProdInfo.intNextStep != undefined)
		{
			yoExitCheck("document.ProdInfo.intNextStep.value = " + intStep +
				"; document.ProdInfo.action = \"" + strExitUrl +
				"\"; document.ProdInfo.target = \"_self\"; document.ProdInfo.submit();");
		}
		if (document.ProdInfo.NextStep != undefined)
		{
			yoExitCheck("document.ProdInfo.NextStep.value = " + intStep +
				"; document.ProdInfo.action = \"" + strExitUrl +
				"\"; document.ProdInfo.target = \"_self\"; document.ProdInfo.submit();");
		}
	}
	return(false);
}

function yoAddToBasket()
{
	if (blnFormLoaded == 1 && blnOkToSubmit == 1)
	{
		yoExitCheck("if (document.frmCartAdd != null && document.ProdInfo != null) { if (document.frmCartAdd.strPersonalDescription != null && document.ProdInfo.strPersonalDescription != null) { document.frmCartAdd.strPersonalDescription.value = document.ProdInfo.strPersonalDescription.value; } } document.frmCartAdd.submit(); blnOkToSubmit = 0;");
	}
	return(false);
}

function yoGoToNext(strExitUrl)
{
	if (blnFormLoaded == 1)
	{
		yoExitCheck("document.ProdInfo.action = \"" + strExitUrl + "\"; document.ProdInfo.target = \"_self\"; document.ProdInfo.submit();");
	}
	return(false);
}

function yoCancel(strDomainUrl, intCatalogCodeId)
{
	intWidth = 490;
	intHeight = 70;
	startX = (screen.width - intWidth) / 2;
	if (startX < 0) startX = 0;
	startY = (screen.height - intHeight) / 2;
	if (startY < 0) startY = 0;
	window.open(strDomainUrl + "ViewSteps/_CcCancel.cfm?iCatalogCodeId=" +
		intCatalogCodeId, "LogoDialog",
		"screenX=" + startX + ",screenY=" + startY + ",width=" + intWidth + "px,height=" +
		intHeight + "px,scrollbars=no,status=yes");
	return(false);
}

// pops a window up that generates previews
function yoGenPreview(strDomainUrl, intCatalogCodeId, strSessionCookie, strSessionId,
	blnLogoTab, blnEnsemble, blnDispPrevIn, blnDoNotRespondMessage)
{
	strActionUrl = strDomainUrl + "WebPreview.cfm?iCatalogCodeId=" +
		intCatalogCodeId + "&" + strSessionCookie + "=" + strSessionId + "&blnLogoTab=" + blnLogoTab +
		"&blnEnsemble=" + blnEnsemble + "&blnDoNotRespondMessage=" + blnDoNotRespondMessage +
		"&blnDisplayPreviewInPopUp=" + blnDispPrevIn;

	strPopUpName = "frmPreview";
	showFloat(strPopUpName);
	document.ProdInfo.action = strActionUrl;
	document.ProdInfo.target = "frmPreviewBottom";
	checkFrame();
	return false;
}

function checkFrame()
{
	if (typeof(frmPreview.frmPreviewBottom) == 'undefined')
	{
		setTimeout('checkFrame()', 100);
	}
	else
	{
		document.ProdInfo.submit();
	}
}

// used on the prodsummary page to launch the sendpreview window
function yoSendPreview(strDomainUrl, intCatalogCodeId,
		strSessionCookie, strSessionId, lstImageIndex,
		blnDoNotRespondMessage, strDebugMsg)
{
	lstPfImageUrl = "";
	arrImageIndex = lstImageIndex.split(",");
	for (i = 0; i < arrImageIndex.length; i++)
	{
		var str = "imgPreview" + arrImageIndex[i];
		for (j = 0; j < document.images.length; j++)
		{
			var image = document.images[j];
			if (image.name == str)
			{
				lstPfImageUrl += image.src + ",";
				break;
			}
		}
	}
	lstPfImageUrl = lstPfImageUrl.substring(0, lstPfImageUrl.length - 1);
	// check to see if printfusion has returned a URL yet if so let them open the window
	// todo adapt this to multiple preview images
	if (lstPfImageUrl.substring(0, 4) == "http")
	{
		window.open(strDomainUrl + "SendPreview.cfm?iCatalogCodeId=" + intCatalogCodeId +
			"&" + strSessionCookie + "=" + strSessionId +
			"&lstPfImageUrl=" + escape(lstPfImageUrl) +
			"&blnDoNotRespondMessage=" + blnDoNotRespondMessage +
			"&strDebugMsg=" + strDebugMsg, "SendPreview");
	}
	else if (lstPfImageUrl.substring(lstPfImageUrl.length - 9, 9) == "Error.gif")
	{
		alert("There was an error processing your preview. Please try again later.");
	}
	else
	{
		alert("Your preview is still being created. Please wait.");
	}
	return(false);
}

// used on the prodsummary page to launch the sendpreview window
function yoSendPreviewCc(strDomainUrl, intCatalogCodeId,
		strSessionCookie, strSessionId, lstPfImageUrl,
		blnDoNotRespondMessage, strDebugMsg)
{
	intWidth = 750;
	intHeight = 650;
	intX = (screen.width - intWidth) / 2;
	intY = (screen.height - intHeight) / 2;
	window.open(strDomainUrl + "SendPreview.cfm?iCatalogCodeId=" + intCatalogCodeId +
		"&" + strSessionCookie + "=" + strSessionId + "&lstPfImageUrl=" + escape(lstPfImageUrl) +
		"&blnDoNotRespondMessage=" + blnDoNotRespondMessage + "&strDebugMsg=" + strDebugMsg,
		"SendPreview", "top=" + intY + ",left=" + intX + ",height=" + intHeight + ",width=" +
		intWidth + ",location=no,resizable=YES,scrollbars=YES,status=no,toolbar=no");
	return(false);
}

intCatalogCodeId = "";

function yoOpenLargeGraphic(strDomainUrl, intCatId, strImagePath)
{
	objImage = new Image();
	objImage.onload = new Function("yoOpenLargeGraphicAsync('"+strDomainUrl+"')");
	intCatalogCodeId = intCatId;
	objImage.src = strImagePath;
}

function yoOpenLargeGraphicAsync(strDomainUrl)
{
	intWidth = objImage.width + 30;
	intHeight = objImage.height + 60;
	intX = (screen.width - intWidth) / 2;
	intY = (screen.height - intHeight) / 2;
	window.open(strDomainUrl + "_LargeGraphicPopup.cfm?iCatalogCodeId=" +
		intCatalogCodeId + "&strImagePath=" + escape(objImage.src),
		"LargeGraphic", "width=" + intWidth + ",height=" + intHeight + ",top=" + intY + ",left=" + intX +
		",toolbar=no,directories=no,status=no,scrollbars=no,resizable=yes,menubar=no,titlebar=no,dependent=yes");
}

function yoUpdateGraphicEns(strGrfxUrl, intEnsKey)
{
	eval("document.imgPreview" + intEnsKey + ".src = strGrfxUrl;");
}

function yoUpdateGraphic(strGrfxUrl)
{
	document.imgPreview.src = strGrfxUrl;
}

function yoBuyIt(intProdId, intDisplayId, intCatId)
{
	if (blnFormLoaded == 1)
	{
		if (document.frmCatalog.iProdId != undefined)
		{
			document.frmCatalog.iProdId.value = intProdId;
			document.frmCatalog.iDisplayId.value = intDisplayId;
			if (!isNaN(intCatId)) document.frmCatalog.iCatId.value = intCatId;
			document.frmCatalog.submit();
		}
		if (document.frmCatalog.iProdID != undefined)
		{
			document.frmCatalog.iProdID.value = intProdId;
			document.frmCatalog.iDisplayID.value = intDisplayId;
			if (!isNaN(intCatId)) document.frmCatalog.iCatID.value = intCatId;
			document.frmCatalog.submit();
		}
	}
	return(false);
}

function isNumeric(strValue, oObject, strDesc)
{
	var strChar = "";
	var blnNumeric = true;
	var intPeriods = 0;
	for (intIndex = 0; intIndex < strValue.length; intIndex++)
	{
		strChar = strValue.charAt(intIndex);
		if (isNaN(parseInt(strChar)) && strChar != ".")
		{
			blnNumeric = false;
		}
		else if (strChar == ".")
		{
			intPeriods = intPeriods + 1;
		}
	}
	if (blnNumeric && intPeriods > 1 || strValue.length < 1)
	{
		blnNumeric = false;
	}
	if (!blnNumeric)
	{
		alert(strDesc + " must be a numeric value.");
	}
}

function isCurrency(strValue, oObject, strDesc)
{
	var strChar = "";
	var blnCurrency = true;
	var intPeriods = 0;
	var strCurrency = strValue.replace('$', "")
	for (intIndex = 0; intIndex < strCurrency.length; intIndex++)
	{
		strChar = strCurrency.charAt(intIndex);
		if (isNaN(parseInt(strChar)) && strChar != ".")
		{
			blnCurrency = false;
		}
		else if(strChar == ".")
		{
			intPeriods = intPeriods + 1;
		}
	}
	if (blnCurrency && intPeriods > 1 || strCurrency.length < 1)
	{
		blnCurrency = false;
	}
	if (!blnCurrency)
	{
		alert(strDesc + " must be a valid currency value.");
	}
}

function isInteger(strValue, oObject, strDesc)
{
	var strChar = "";
	var blnInteger = true;
	for (intIndex = 0; intIndex < strValue.length; intIndex++)
	{
		strChar = strValue.charAt(intIndex);
		if (isNaN(parseInt(strChar)))
		{
			blnInteger = false;
		}
	}
	if (strValue.length < 1)
	{
		blnInteger = false;
	}
	if (!blnInteger)
	{
		alert(strDesc + " must be an integer value.");
	}
}

function isDate(sDate, oObject, strDesc)
{
	blnDate = true;
	iFirstSlash = sDate.indexOf("/");
	iSecondSlash = sDate.indexOf("/", iFirstSlash + 1);
	if (iFirstSlash == -1 || iSecondSlash == -1 || iFirstSlash == iSecondSlash)
	{
		blnDate = false;
	}
	iMonth = sDate.substring(0, iFirstSlash);
	iDay = sDate.substring(iFirstSlash + 1, iSecondSlash);
	iYear = sDate.substring(iSecondSlash + 1);
	if (iDay.length == 2 && iDay.charAt(0) == "0")
	{
		iDay = iDay.charAt(1);
	}
	if (iMonth.length == 2 && iMonth.charAt(0) == "0")
	{
		iMonth = iMonth.charAt(1);
	}
	if ((iMonth.length != 1 && iMonth.length != 2) ||
			iMonth != parseInt(iMonth) || iMonth < 1 || iMonth > 12)
	{
		blnDate = false;
	}
	if ((iYear.length != 2 && iYear.length != 4) || iYear != parseInt(iYear))
	{
		blnDate = false;
	}
	if (iMonth == 2)
	{
		if (iYear % 4 > 0 || (iYear % 100 == 0 && iYear % 400 > 0))
		{
			iMaxDays = 28;
		}
		else
		{
			iMaxDays = 29;
		}
	}
	else if (iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11)
	{
		iMaxDays = 30;
	}
	else
	{
		iMaxDays = 31;
	}
	if ((iDay.length != 1 && iDay.length != 2) || iDay != parseInt(iDay) || iDay < 1 || iDay > iMaxDays)
	{
		blnDate = false;
	}
	if (!blnDate)
	{
		alert(strDesc + " must be a valid date.");
	}
}

function CalculatePrice(intQtyIn, lstQtys, lstPrices, lstIndPrices, strPrefixText,
	strQtyField, strPriceIdField, intMultiple, strCurrencyChar)
{
	if (strCurrencyChar == undefined)
		strCurrencyChar = "$";
	arrQty = lstQtys.split(',');
	arrPrice = lstPrices.split(',');
	arrIndPrice = lstIndPrices.split(',');

	intQty = new Number(intQtyIn);
	tmpQty = new Number(arrQty[0]);

	// If field is blank, enter a number
	if (intQtyIn.length < 1)
	{
		//set the quantity field to the minimum quantity allowed.
		eval(strQtyField + '.value=' + tmpQty + ';');
		//Set the quantity used for the pricing calculation to the minimum.
		intQty = tmpQty;
		alert('Quantity can not be left blank');
	}
	if (isNaN(intQty))
	{
		//set the quantity field to the minimum quantity allowed.
		eval(strQtyField + '.value=' + tmpQty + ';');
		//Set the quantity used for the pricing calculation to the minimum.
		intQty = tmpQty;
		alert('Quantity must be numeric');
	}
	//if the quantity selected is lower than the minimum quantity offered
	if (intQty < tmpQty)
	{
		//set the quantity field to the minimum quantity allowed.
		eval(strQtyField + '.value=' + tmpQty + ';');
		//Set the quantity used for the pricing calculation to the minimum.
		intQty = tmpQty;
		alert('The Minimum orderable quantity for this product is ' + tmpQty + '. \nPlease enter a higher quantity.');
	}
	//if the quantity selected isn't a multiple of the requested multiple restriction
	if (intQty % intMultiple != 0)
	{
		//set the quantity field to the next higher quantity allowed
		tmpQty = intQty + (intMultiple - (intQty % intMultiple));
		eval(strQtyField + '.value=' + tmpQty + ';');
		//Set the quantity used for the pricing calculation to the next higher quantity.
		intQty = tmpQty;
		alert('This product must be ordered in multiples of ' + intMultiple + '.');
	}

	iListPos = 0;
	//loop over the quantities in the list and see which price break we should use.
	for (var x = 0; x < arrQty.length; x++)
	{
		curQty = new Number(arrQty[x]);
		if (curQty > intQty)
		{
			break;
		}
		else
		{
			iListPos = x;
		}
	}
	var cPrice = new Number(arrPrice[iListPos]);
	var cIndPrice = new Number(arrIndPrice[iListPos]);
	cPrice = intQty * cIndPrice + cPrice;
	//round the total value
	cPrice = Math.floor(cPrice * 100 + 0.50000000001);
	fltPrice = new Number(cPrice);
	//determine the cents
	cents = cPrice % 100;
	//calculate the final value not including cents
	cPrice = Math.floor(cPrice/100).toString();
	//if there are less than 10 cents then pad cents with a 0 to make it two digits.
	if (cents < 10)
	{
		cents = "0" + cents;
	}
	//Loop from 0 to the number of total digits of the total price not including the cents divided by 3
	//in order to determine how many commas we need to add to the number
	for (i=0; i< Math.floor((cPrice.length - (1 + i)) / 3); i++)
	{
		cPrice = cPrice.substring(0, cPrice.length - (4 * i + 3)) + ',' + cPrice.substring(cPrice.length - (4 * i + 3));
	}
	//create the string to display on the page.
	strPrice = strPrefixText + strCurrencyChar + cPrice + '.' + cents;
	//set the value of the table cell to display the final price.
	eval('document.getElementById("' + strPriceIdField + '").innerHTML = strPrice');
	return fltPrice/100;
}

// Update the quantity field with a valid quantity if the current qty is invalid.
// It does not update any prices!!
function ValidateQuantityNovatus(objQtyField, lstQtys, lstBaseQtys, lstAdlQtys)
{
	arrQty = lstQtys.split(',');
	arrBaseQty = lstBaseQtys.split(',');
	arrAdlQty = lstAdlQtys.split(',');
	
	if (arrBaseQty[0] == 0) arrBaseQty[0] = arrQty[0];
	tmpQty = new Number(arrBaseQty[0]);
	
	if (objQtyField.type == 'select-one')
		intQty = objQtyField[objQtyField.selectedIndex].value;
	else
		intQty = objQtyField.value;
	
	// If field is blank, enter a number
	if (intQty.length < 1)
	{
		//set the quantity field to the minimum quantity allowed.
		objQtyField.value = tmpQty;
		//Set the quantity used for the pricing calculation to the minimum.
		intQty = tmpQty;
		alert('Quantity can not be left blank');
	}
	if (isNaN(intQty))
	{
		//set the quantity field to the minimum quantity allowed.
		objQtyField.value = tmpQty;
		//Set the quantity used for the pricing calculation to the minimum.
		intQty = tmpQty;
		alert('Quantity must be numeric');
	}
	
	// convert the number to a float
	intQty = parseFloat(intQty);
	
	//if the quantity selected is lower than the minimum quantity offered
	if (intQty < tmpQty)
	{
		//set the quantity field to the minimum quantity allowed.
		objQtyField.value = tmpQty;
		//Set the quantity used for the pricing calculation to the minimum.
		intQty = tmpQty;
		alert('The Minimum orderable quantity for this product is ' + tmpQty + '. \nPlease enter a higher quantity.');
	}
	
	for (x=0; x<arrQty.length; x++)
	{
		if (intQty <= Number(arrQty[x]) || x == arrQty.length-1)
		{
			if (Number(arrBaseQty[x]) == 0) arrBaseQty[x] = Number(arrQty[x]);
			
			if (intQty < Number(arrBaseQty[x]))
			{
				intQty = Number(arrBaseQty[x]);
				objQtyField.value = intQty;
				alert('An invalid quantity was entered.');
			}
			else if (intQty != Number(arrBaseQty[x]))
			{
				// if an additional quantity multiplier is specified, loop through the additional quantities
				if (Number(arrAdlQty[x]) > 0)
				{
					if (eval(intQty-Number(arrBaseQty[x])) % Number(arrAdlQty[x]) != 0)
					{
						//set the quantity field to the next higher quantity allowed
						intQty = (intQty + Number(arrAdlQty[x])) - (intQty-Number(arrBaseQty[x])) % Number(arrAdlQty[x]);
						objQtyField.value = intQty;
						alert('An invalid quantity was entered.');
					}
				}
				// else use the base quantity
				else
				{
					intQty = arrBaseQty[x];
					objQtyField.value = intQty;
					alert('An invalid quantity was entered.');
				}
			}
			break;
		}
	}
	
	return intQty;
}

// Calculates and returns price.
// If strPriceFieldId is passed it will update the price display.
function CalculatePriceNovatus(intQty, lstQtys, lstBaseQtys, lstPrices, lstAdlQtys, lstAdlPrices, strPriceFieldId, strCurrencyChar) {
	if (strCurrencyChar == undefined)
		strCurrencyChar = "$";
	arrQty = lstQtys.split(',');
	arrBaseQty = lstBaseQtys.split(',');
	arrPrice = lstPrices.split(',');
	arrAdlQty = lstAdlQtys.split(',');
	arrAdlPrice = lstAdlPrices.split(',');
	
	if (arrBaseQty[0] == 0) arrBaseQty[0] = arrQty[0];
	
	cPrice = 0;
	
	for (x=0; x<arrQty.length; x++)
	{
		if (intQty <= Number(arrQty[x]) || x == arrQty.length-1)
		{
			if (Number(arrBaseQty[x]) == 0) arrBaseQty[x] = Number(arrQty[x]);
			if (intQty == Number(arrBaseQty[x]))
			{
				cPrice = Number(arrPrice[x]);
			}
			else
			{
				cPrice = Number(arrPrice[x]) + (((intQty - Number(arrBaseQty[x])) / Number(arrAdlQty[x])) * Number(arrAdlPrice[x]));
			}
			break;
		}
	}
	
	//round the total value
	cPrice = Math.floor(cPrice * 100 + 0.50000000001);
	fltPrice = new Number(cPrice);
	// if a price field was passed in, update it
	if (strPriceFieldId)
	{
		//determine the cents
		cents = cPrice % 100;
		//calculate the final value not including cents
		cPrice = Math.floor(cPrice/100);
		//if there are less than 10 cents then pad cents with a 0 to make it two digits.
		if (cents < 10)
		{
			cents = "0" + cents;
		}
		//Loop from 0 to the number of total digits of the total price not including the cents divided by 3
		//in order to determine how many commas we need to add to the number
		for (i=0; i< Math.floor((cPrice.length - (1 + i)) / 3); i++)
		{
			cPrice = cPrice.substring(0, cPrice.length - (4 * i + 3)) + ',' + cPrice.substring(cPrice.length - (4 * i + 3));
		}
		//create the string to display on the page.
		strPrice = strCurrencyChar + cPrice + '.' + cents;
		//set the value of the table cell to display the final price.
		try
		{
			eval('document.getElementById("' + strPriceFieldId + '").innerHTML = strPrice');
		}
		catch(e)
		{}
	}
	return fltPrice/100;
}

function CalculatePriceNoMultiple(intQty, lstQtys, lstPrices, lstIndPrices, strPrefixText,
	strQtyField, strPriceIdField, strCurrencyChar)
{
	return CalculatePrice(intQty, lstQtys, lstPrices, lstIndPrices, strPrefixText,
		strQtyField, strPriceIdField, 1, strCurrencyChar);

	/*if (strCurrencyChar == undefined)
		strCurrencyChar = "$";
	arrQty = lstQtys.split(',');
	arrPrice = lstPrices.split(',');
	arrIndPrice = lstIndPrices.split(',');

	intQty = new Number(intQty);
	tmpQty = new Number(arrQty[0]);

	if (isNaN(intQty)) {
		//set the quantity field to the minimum quantity allowed.
		eval(strQtyField + '.value=' + tmpQty + ';');
		//Set the quantity used for the pricing calculation to the minimum.
		intQty = tmpQty;
		alert('Quantity must be numeric');
	}

	iListPos = 0;
	//loop over the quantities in the list and see which price break we should use.
	for (var x = 0; x < arrQty.length; x++) {
		curQty = new Number(arrQty[x]);
		if (curQty > intQty) {
			break;
		}
		else {
			iListPos = x;
		}
	}

	iListIndPos = 0;
	if (intQty >= arrIndPrice.length) {
		iListIndPos = (arrIndPrice.length - 1);
	}
	else {
		if (intQty != 0)
			iListIndPos = (intQty - 1);
		else
			iListIndPos = 0;
	}

	cPrice = new Number(arrPrice[iListPos]);
	cIndPrice = new Number(arrIndPrice[iListIndPos]);
	cPrice = intQty * cIndPrice + cPrice;
	//round the total value
	cPrice = Math.floor(cPrice * 100 + 0.50000000001);
	fltPrice = new Number(cPrice);
	//determine the cents
	cents = cPrice % 100;
	//calculate the final value not including cents
	cPrice = Math.floor(cPrice/100).toString();
	//if there are less than 10 cents then pad cents with a 0 to make it two digits.
	if (cents < 10)
	{
		cents = "0" + cents;
	}
	//Loop from 0 to the number of total digits of the total price not including the cents divided by 3
	//in order to determine how many commas we need to add to the number
	for (i=0; i< Math.floor((cPrice.length - (1 + i)) / 3); i++)
	{
		cPrice = cPrice.substring(0, cPrice.length - (4 * i + 3)) + ',' + cPrice.substring(cPrice.length - (4 * i + 3));
	}
	//create the string to display on the page.
	strPrice = strPrefixText + strCurrencyChar + cPrice + '.' + cents;
	//set the value of the table cell to display the final price.
	eval('document.getElementById("' + strPriceIdField + '").innerHTML = strPrice');
	return fltPrice/100;*/
}


function CalculateOptionPrice(intQty, intListPos, lstMinPrices, lstPrices,
	lstIndPrices, strPrefixText, strPriceIdField, strCurrencyChar)
{
	if (strCurrencyChar == undefined)
		strCurrencyChar = "$";
	arrPrice = lstPrices.split('~');
	arrIndPrice = lstIndPrices.split('~');
	arrMinPrice = lstMinPrices.split('~');
	cPrice = new Number(arrPrice[intListPos]);
	cIndPrice = new Number(arrIndPrice[intListPos]);
	cMinPrice = new Number(arrMinPrice[intListPos]);
	cPrice = intQty * cIndPrice + cPrice;
	if (cPrice < cMinPrice)
		cPrice = cMinPrice;
	// don't apply charge if quantity is 0
	if (intQty == 0)
		cPrice = 0;
	//round the total value
	cPrice = Math.floor(cPrice * 100 + 0.50000000001);
	fltPrice = cPrice;
	//determine the cents
	cents = cPrice % 100;
	//calculate the final value not including cents
	cPrice = Math.floor(cPrice/100).toString();
	//if there are less than 10 cents then pad cents with a 0 to make it two digits.
	if (cents < 10)
	{
		cents = "0" + cents;
	}
	//Loop from 0 to the number of total digits of the total price not including the cents divided by 3
	//in order to determine how many commas we need to add to the number
	for (i=0; i< Math.floor((cPrice.length - (1 + i)) / 3); i++) {
		cPrice = cPrice.substring(0, cPrice.length - (4 * i + 3)) + ',' + cPrice.substring(cPrice.length - (4 * i + 3));
	}
	//create the string to display on the page.
	strPrice = strPrefixText + strCurrencyChar + cPrice + '.' + cents;
	//set the value of the table cell to display the final price.
	eval('document.getElementById("' + strPriceIdField + '").innerHTML = strPrice');
	return fltPrice/100;
}

// performs trim function
function TrimString(sInString) {
	if(sInString.length > 0)
	{
		sInString = sInString.replace( /^\s+/g, "" );// strip leading
		return sInString.replace( /\s+$/g, "" );// strip trailing
	}
	else
		return sInString;
}

// checks if the input is an integer value (no floating points or decimals)
function isInteger(pintString) {
	//var regEx = /[123456789]*/
	//var regEx = /^\d{5}$/
	var regEx = /^\d*$/
	return pintString.search(regEx) > -1;
	//if(pintString.search(regEx) != -1) return true; else return false;
}

// finds position in list, similar to ListFind() function in ColdFusion
function findInList(list, value, delimiters) {
	arrValues = list.split(delimiters);
	for (x=0; x<arrValues.length; x++)
	{
		if (arrValues[x] == value)
		{
			return x;
		}
	}
	return -1;
}

// Does before the page is submitted to see if there is the requirePhoto function, if there is
// then run that function and see if there is a photo specified to be included, if not then don't let the
// page be submitted.
function tryRequirePhoto() {
	if ('function' == typeof window.requirePhoto) {
		if (requirePhoto())
			blnFormLoaded = 1;
		else
			blnFormLoaded = 0;
	}
	else {
		blnFormLoaded = 1;
	}
}

function forcedigits(obj, strString,strName)
{
	<!--- list of valid numbers --->
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	<!--- test strString consists of valid characters listed above --->
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			obj.select();
			obj.focus();
			alert('The "' + strName + '" field must be all digits.');
			blnResult = false;
		}
	}
	return blnResult;
}

function forcedigits(obj, strString,strName)
{
	// list of valid numbers
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			obj.select();
			obj.focus();
			alert('The "' + strName + '" field must be all digits.');
			blnResult = false;
		}
	}
	return blnResult;
}

blnFormLoaded = 1;
