// JavaScript Document

var nInsArray = 4
var aInsArray = new Array(nInsArray);
var aInsAmtArray = new Array(nInsArray);

var aTagArray = new Array();
var aOrigTagArray = new Array();

var lDonationRecalc = false;
var aDonationArray = new Array();
var aDonationAmtArray = new Array();

var aTitleCoArray = new Array();
var aTitleCoItemArray = new Array();
var aTitleCoAmtArray = new Array();
var aTitleCoProductArray = new Array();
var aTitleCoPayDateArray = new Array();

var aStateArray = new Array();
var aStateCountryArray = new Array();

var aCardArray = new Array();
var aCardAmtArray = new Array();


/*-------------------------------------------------------------------------------------------------
*
*	Real and Tangible Property Installments
*
-------------------------------------------------------------------------------------------------*/
/**********************************************\
* Function:	InitInsArray()
* Author: 	Evie Platt
* Created:	24 Jan 2003
* Description: 
*	Initialize arrays for installments
\**********************************************/
function InitInsArray()
{
	var i;
	
	for (i = 0; i <= nInsArray - 1; i++)
	{
		aInsArray[i] = null;
		aInsAmtArray[i] = 0.00;
	}
}

/**********************************************\
* Function:	UpdateInsTotals()
* Author: 	Evie Platt
* Created:	24 Jan 2003
* Description: 
*	Initialize arrays for installments
\**********************************************/
function UpdateInsTotals(tyAmount)
{
	document.taxinstall.elements['DispAmount'].value = FormatCurrency(tyAmount);
	document.taxinstall.elements['amount'].value = tyAmount;
}

/**********************************************\
* Function:	SetInsArray()
* Author: 	Evie Platt
* Created:	24 Jan 2003
* Description: 
*	Set values in installment arrays
\**********************************************/
function SetInsArray(tnInsNo, tcValue, tyAmount)
{
	// Set the value of the checkbox in the array
	// Array elements are zero based
	aInsArray[tnInsNo - 1] = tcValue;
	aInsAmtArray[tnInsNo - 1] = tyAmount;
}

/**********************************************\
* Function:	SumInsArray()
* Author: 	Evie Platt
* Created:	24 Jan 2003
* Description: 
*	Sum amounts in installment amount array
\**********************************************/
function SumInsArray()
{
	var i;
	var lySum = 0.00;

	for (i=0; i <= nInsArray - 1; i++)
	{
		if (aInsArray[i] == true)
		{
			lySum = lySum + aInsAmtArray[i];
		}
	}
		
	return lySum;
}

/**********************************************\
* Function:	InstallClick()
* Author: 	Evie Platt
* Created:	24 Jan 2003
* Description: 
*	Check if selection is valid and update
*	totals when checkbox is clicked.
\**********************************************/
function InstallClick (tnInsNo, tcValue, tyAmount)
{
	var i;
	var lyTotal = 0.00;
	var lcPrevValue = null, lcNextValue = null;
	var llReturn = true;
	
	SetInsArray(tnInsNo, tcValue, tyAmount);
	
	// Look at the other values in the array
	lcPrevValue = aInsArray[tnInsNo - 2];
	lcNextValue = aInsArray[tnInsNo];
	if ((tcValue == false) && (lcNextValue == true)) 
	{
		alert("Installment payments must be paid in order.");
		return false;
	}

	if ((tcValue == true) && (lcPrevValue == false))
	{
		// Check all previous unpaid 
		for (i=0; i <= tnInsNo - 1; i++)
		{
			if (aInsArray[i] == false)
			{
				aInsArray[i] = true;
				document.taxinstall.elements['chkInstall'][i].checked = true
			}
		}
	}		

	// Set value of textbox to total	
	lyTotal = SumInsArray()
	document.taxinstall.elements['DispAmount'].value = FormatCurrency(lyTotal);
	document.taxinstall.elements['amount'].value = lyTotal;
	return true;
}

/*-------------------------------------------------------------------------------------------------
*
*	Personalized Plate renewals
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	InitTagArray()
* Author: 	Evie Platt
* Created:	16 Jul 2003
* Description: 
*	Initialize arrays for tag number
\**********************************************/
function InitTagArray(nLength)
{
	var i;
	aTagArray.length = nLength;
	aOrigTagArray.length = nLength;
	for (i = 0; i <= aTagArray.length - 1; i++)
	{
		aTagArray[i] = " ";
		aOrigTagArray[i] = " ";
	}
}

/**********************************************\
* Function:	SetOrigTagArray()
* Author: 	Evie Platt
* Created:	18 Aug 2003
* Description: 
*	Set values in installment arrays
*   Stores off the original values
\**********************************************/
function SetOrigTagArray(tnPosNo, tcValue)
{
	// Set the value of the checkbox in the array
	// Array elements are zero based
	SetTagArray(tnPosNo, tcValue);
	aOrigTagArray[tnPosNo] = tcValue;
}

/**********************************************\
* Function:	SetTagArray()
* Author: 	Evie Platt
* Created:	16 Jul 2003
* Description: 
*	Set values in tag arrays
\**********************************************/
function SetTagArray(tnPosNo, tcValue)
{
	// Set the value of the checkbox in the array
	// Array elements are zero based
	aTagArray[tnPosNo] = tcValue;

}
			
/**********************************************\
* Function:	SetTagOption()
* Author: 	Evie Platt
* Created:	22 Jul 2003
* Description: 
*	Populates the comboboxes for the tag items
\**********************************************/
function SetTagOptions (tnPosNo)
{
	var nArrayLength = aTagArray.length;
	var nLength;
	var i, j;
	var cDropDown = "";
	
	var loForm = document.getElementById('dmvpersonalized');
	
	var loTagNum = loForm.tagnum[tnPosNo];

	// Reset the array to only contain a space
	loTagNum.options.length = 1;
	loTagNum.options[0].text = ' ';
	loTagNum.options[0].value = ' ';
	for (i = 0; i <= nArrayLength - 1; i++)
	{
		// if the value is already in the combobox, then don't add
		// Need to do this each time because items are being added to the select
		nLength = loTagNum.options.length
		cDropDown = "";
		for (j = 0; j <= nLength - 1; j++)
		{
			cDropDown += loTagNum.options[j].text;
		}

		if ((cDropDown.indexOf(aTagArray[i]) == -1) && (aTagArray[i] != ' ' ))
		{	
			nLength = loTagNum.options.length++;
			loTagNum.options[nLength].text = aTagArray[i];
			loTagNum.options[nLength].value = aTagArray[i];
			if (loTagNum.options[nLength].text == aTagArray[tnPosNo])				
			{
				loTagNum.options[nLength].selected = true
			}
		}
	}
}


/**********************************************\
* Function:	TagAssemble()
* Author: 	Evie Platt
* Created:	22 Jul 2003
* Description: 
*	Puts the tag back into a string
\**********************************************/
function TagAssemble (tnPosNo, tcValue)
{
	SetTagArray(tnPosNo, tcValue);
	document.dmvpersonalized.elements['repl_tag_num'].value = aTagArray.join("");
}

/**********************************************\
* Function:	TagVerify()
* Author: 	Evie Platt
* Created:	22 Jul 2003
* Description: 
*	Verify that the wording of the tag 
*	hasn't changed
\**********************************************/
function TagVerify (tcOldTagNum, tcNewTagNum)
{
	var lcMsg = "";
	var re;
	
	re = / /g;
	tcOldTagNum = tcOldTagNum.replace(re, "");
	tcNewTagNum = tcNewTagNum.replace(re, "");

	if (tcOldTagNum != tcNewTagNum)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The new configuration must have the same lettering in the  \n";
		lcMsg += "same order as the current plate.  Only the spacing can be  \n";
		lcMsg += "changed. Please check the new configuration and try again.\n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg);

		return false;
	}
	return true;	
}

/**********************************************\
* Function:	SetTagOption()
* Author: 	Evie Platt
* Created:	18 Aug 2003
* Description: 
*	Reset the values of the combo boxes to the
*	original values
\**********************************************/
function TagReset()
{
	var nArrayLength = aOrigTagArray.length;
	var i;

	for (i = 0; i <= nArrayLength - 1; i++)
	{
		document.dmvpersonalized.elements['tagnum'][i].text = aOrigTagArray[i];
		document.dmvpersonalized.elements['tagnum'][i].value = aOrigTagArray[i];
		TagAssemble(i, aOrigTagArray[i]);
	}
}

/*-------------------------------------------------------------------------------------------------
*
*	LBT Decals
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	CalcAddlLBTDecals
* Author: 	Evie Platt
* Created:	30 Jan 2009
* Description: 
*	Calculates the amount due for the addl decals
\**********************************************/
function CalcAddlDecals()
{
	
	var loAddlCount = document.getElementById('AddlDecals');
	var loAddlAmount = document.getElementById('AddlDecalsAmt');
	var loDecalFee = document.getElementById('AddlFee');
	
	if (ValidateInteger(loAddlCount.value) == false)
	{
		loAddlAmount.value = "0.00";
	}
	else
	{
		var lnTotal = parseFloat(loAddlCount.value) * parseFloat(loDecalFee.value);
		loAddlAmount.value = lnTotal.toFixed(2);
	}
	CalcTotalDecals();
}

/**********************************************\
* Function:	CalcReplDecals
* Author: 	Evie Platt
* Created:	30 Jan 2009
* Description: 
*	Calculates the amount due for the repl decals
\**********************************************/
function CalcReplDecals()
{
	var loReplCount = document.getElementById('ReplDecals');
	var loReplAmount = document.getElementById('ReplDecalsAmt');
	var loDecalFee = document.getElementById('ReplFee');
	
	if (ValidateInteger(loReplCount.value) == false)
	{
		loAddlAmount.value = "0.00";
	}
	else
	{
		var lnTotal = parseFloat(loReplCount.value) * parseFloat(loDecalFee.value);
		loReplAmount.value = lnTotal.toFixed(2);
	}
	CalcTotalDecals();
}

/**********************************************\
* Function:	CalcTotalDecals
* Author: 	Evie Platt
* Created:	30 Jan 2009
* Description: 
*	Adds up to total due for decals
\**********************************************/
function CalcTotalDecals()
{
	var loAddlAmount = document.getElementById('AddlDecalsAmt');
	var loReplAmount = document.getElementById('ReplDecalsAmt');
	var loTotalAmount = document.getElementById('TotalDecalsAmt');

	var lnTotal = parseFloat(loAddlAmount.value) + parseFloat(loReplAmount.value);
	loTotalAmount.value = lnTotal.toFixed(2);
}

/**********************************************\
* Function:	VerifyLBTDecalPage
* Author: 	Evie Platt
* Created:	30 Jan 2009
* Description: 
*	Verify the input for the decals
\**********************************************/
function VerifyLBTDecalPage()
{
	var loCurrentDecals = document.getElementById('Decals');
	var loAddlCount = document.getElementById('AddlDecals');
	var loReplCount = document.getElementById('ReplDecals');
	var loTotalAmount = document.getElementById('TotalDecalsAmt');
	var loLBTAmount = document.getElementById('amount');
	
	var lyCurrentDecals = parseFloat(loCurrentDecals.value);
	var lyAddlCount = parseFloat(loAddlCount.value);
	var lyReplCount = parseFloat(loReplCount.value);
	var lyTotalAmount = parseFloat(loTotalAmount.value);
	var lyLBTAmount = parseFloat(loLBTAmount.value);

	
	if (lyReplCount > lyCurrentDecals)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The number of replacement decals needs to be less than \n";
		lcMsg += "the current number of decals.  Please try again.\n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg); 
		loReplCount.focus();
		return false;
	}
	
	if (lyTotalAmount + lyLBTAmount == 0)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The amount of additional and replacement decals \n";
		lcMsg += "cannot be zero.  Please try again.\n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg); 
		loAddlCount.focus();
		return false;
	}
	return true;
}

/*-------------------------------------------------------------------------------------------------
*
*	Mask Account and Credit Card Numbers
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	VerifyAccount()
* Author: 	Evie Platt
* Created:	24 Sep 2003
* Description: 
*		Verify the Hold Account and the
*		Retype Account are the same
\**********************************************/
function VerifyAccount()
{
	var loAccountNo = document.getElementById('AccountNo');
	var loMaskAccountNo = document.getElementById('MaskAccountNo');
	var loRetypeAccountNo = document.getElementById('RetypeAccountNo');
	var loMaskRetypeAccountNo = document.getElementById('MaskRetypeAccountNo');
	
	var lcAccountNo = loAccountNo.value;
	var lcRetypeAccountNo = loRetypeAccountNo.value;
	var re;

	re = /[ ;\-\:]/g;
	lcAccountNo = lcAccountNo.replace(re, "");
	lcRetypeAccountNo = lcRetypeAccountNo.replace(re, "");
	
	if (loRetypeAccountNo.length == 0 && lcAccountNo.length == 0) 
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The account number cannot be blank.  Please try again.	 \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg); 
		if (lcAccountNo.length == 0)
		{
			loMaskAccountNo.focus();
		} else if (lcRetypeAccountNo.length == 0)
		{
			loMaskRetypeAccountNo.focus();
		}
		return false;
	}

	if (lcAccountNo.length > 0 && 
		lcRetypeAccountNo.length > 0 && 
		lcAccountNo != lcRetypeAccountNo)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The account number and the retyped account number do \n";
		lcMsg += "not match.  Please verify these numbers and try again.  \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg);
		loMaskRetypeAccountNo.focus()
		return false;
	}
	else
	{
		// If user entered the field, but didn't make any changes
		// check to see if there are asteriks in the card.  If not, mask.
		re = /\*/g;
		if (lcAccountNo.search(re) < 0)
		{
			MaskAccount(lcAccountNo, 'MaskAccountNo');
		}
		if (lcRetypeAccountNo.search(re) < 0)
		{
			MaskAccount(lcRetypeAccountNo, 'MaskRetypeAccountNo');
		}
		return true;
	}
}

/**********************************************\
* Function:	MaskAccount()
* Author: 	Evie Platt
* Created:	15 Mar 2005
* Description: 
*		Mask the Card Number and
*		replace all the characters with an '*'		
\**********************************************/
function MaskAccount(tcAccountNo, tcAccountName)
{
	var liCnt;
	var laAccountNo = tcAccountNo.split("");

	if (tcAccountNo.length > 0)
	{

		// Save off value to hidden field
		if (tcAccountName.substr(0, 4) == 'Mask')
		{
			document.checkout.elements[tcAccountName.substr(4)].value = tcAccountNo;
		}
		
		// Replace with *
		for (liCnt=0; liCnt < laAccountNo.length - 4; liCnt++)
		{
			laAccountNo[liCnt] = '*';
		}
		lcAccountNo = laAccountNo.join("");
	
		// Display masked number
		if (tcAccountName.substr(0, 4) == 'Mask')
		{
			document.checkout.elements[tcAccountName].value = lcAccountNo;
		}
		else
		{
			document.checkout.elements['Mask' + tcAccountName].value = lcAccountNo;
		}
	}

}

/**********************************************\
* Function:	RestoreAccount()
* Author: 	Evie Platt
* Created:	16 Mar 2005
* Description: 
*		Replace masked account with original 
*		number when user enters on the field		
\**********************************************/
function RestoreAccount(tcAccountName)
{
	if (tcAccountName != null)
	{	
		document.checkout.elements[tcAccountName].value = document.checkout.elements[tcAccountName.substr(4)].value 
	}
}

/**********************************************\
* Function:	VerifyRouting()
* Author: 	Evie Platt
* Created:	07 Oct 2008
* Description: 
*		Verify the Hold Routing and the
*		Retype Routing are the same
\**********************************************/
function VerifyRouting()
{
	var loRoutingNo = document.getElementById('RoutingNo');
	var loMaskRoutingNo = document.getElementById('MaskRoutingNo');
	var loRetypeRoutingNo = document.getElementById('RetypeRoutingNo');
	var loMaskRetypeRoutingNo = document.getElementById('MaskRetypeRoutingNo');
	
	var lcRoutingNo = loRoutingNo.value;
	var lcRetypeRoutingNo = loRetypeRoutingNo.value;
	var re;

	re = /[ ;\-\:]/g;
	lcRoutingNo = lcRoutingNo.replace(re, "");
	lcRetypeRoutingNo = lcRetypeRoutingNo.replace(re, "");
	
	if (loRetypeRoutingNo.length == 0 && lcRoutingNo.length == 0) 
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The routing number cannot be blank.  Please try again.	 \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg); 
		if (lcRoutingNo.length == 0)
		{
			loMaskRoutingNo.focus();
		} else if (lcRetypeRoutingNo.length == 0)
		{
			loMaskRetypeRoutingNo.focus();
		}
		return false;
	}

	if (lcRoutingNo.length > 0 && 
		lcRetypeRoutingNo.length > 0 && 
		lcRoutingNo != lcRetypeRoutingNo)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The routing number and the retyped routing number do \n";
		lcMsg += "not match.  Please verify these numbers and try again.  \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg);
		loMaskRetypeRoutingNo.focus()
		return false;
	}
	else
	{
		// If user entered the field, but didn't make any changes
		// check to see if there are asteriks in the card.  If not, mask.
		re = /\*/g;
		if (lcRoutingNo.search(re) < 0)
		{
			MaskRouting(lcRoutingNo, 'MaskRoutingNo');
		}
		if (lcRetypeAccountNo.search(re) < 0)
		{
			MaskRouting(lcRetypeRoutingNo, 'MaskRetypeRoutingNo');
		}
		return true;
	}
}


/**********************************************\
* Function:	VerifyCard()
* Author: 	Evie Platt
* Created:	24 Sep 2003
* Description: 
*		Verify the Hold Card and the
*		Retype Card are the same
\**********************************************/
function VerifyCard(tnCardEntered)
{
	var loCreditCardNo = document.getElementById('CreditCardNo');
	var loMaskCreditCardNo = document.getElementById('MaskCreditCardNo');
	var loRetypeCardNo = document.getElementById('RetypeCardNo');
	var loMaskRetypeCardNo = document.getElementById('MaskRetypeCardNo');

	var lcCreditCardNo = loCreditCardNo.value;
	var lcRetypeCardNo = loRetypeCardNo.value;
	var re;
	
	re = /[ ;\-\:]/g;
	lcCreditCardNo = lcCreditCardNo.replace(re, "");
	lcRetypeCardNo = lcRetypeCardNo.replace(re, "");

	if (lcRetypeCardNo.length == 0 || lcCreditCardNo.length == 0) 
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The credit card number cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg); 
		if (lcCreditCardNo.length == 0)
		{
			loMaskCreditCardNo.focus()
		}
		else if (lcRetypeCardNo.length == 0)
		{
			loMaskRetypeCardNo.focus()
		}
		
		return false;
	}
	
	if (lcCreditCardNo.length > 0 &&
		lcRetypeCardNo.length > 0 &&
		lcCreditCardNo != lcRetypeCardNo)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The credit card number and the retyped credit card number \n";
		lcMsg += "do not match.  Please verify your selection and try again.  \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg);
		loMaskRetypeCardNo.focus()
		return false;
	}
	else
	{
		// If user entered the field, but didn't make any changes
		// check to see if there are asteriks in the card.  If not, mask.
		re = /\*/g;
		if (lcCreditCardNo.search(re) < 0)
		{
			MaskAccount(lcCreditCardNo, 'MaskCreditCardNo');
		}
		if (lcRetypeCardNo.search(re) < 0)
		{
			MaskAccount(lcRetypeCardNo, 'MaskRetypeCardNo');
		}
		return true;
	}
}

/*-------------------------------------------------------------------------------------------------
*
*	DMV Donations
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	InitDonationArray()
* Author: 	Evie Platt
* Created:	06 Oct 03
* Description: 
*	Initialize arrays for dmv donations
\**********************************************/
function InitDonationArray(nLength)
{
	var i;
	aDonationArray.length = nLength; 
	aDonationAmtArray.length = nLength;
	for (i = 0; i <= aDonationArray.length - 1; i++)
	{
		aDonationArray[i] = null;
		aDonationAmtArray[i] = 0.00;
	}
}

/**********************************************\
* Function:	SetDonationArray()
* Author: 	Evie Platt
* Created:	06 Oct 2003
* Description: 
*	Set values in donation arrays
\**********************************************/
function SetDonationArray(tnSeqNo, tcValue, tyAmount)
{
	// Make sure this is a number
	lyAmount = new Number(tyAmount);
	
	if (lyAmount != aDonationAmtArray[tnSeqNo])
	{
		lDonationRecalc = true;
	}
	aDonationArray[tnSeqNo] = tcValue;
	aDonationAmtArray[tnSeqNo] = lyAmount;
	
	return true;

}

/**********************************************\
* Function:	VerifyDonation()
* Author: 	Evie Platt
* Created:	08 Oct 2003
* Description: 
*	Set values in donation arrays
\**********************************************/
function VerifyDonation(tnSeqNo, tcValue, tyAmount, tyMinAmount, tyMaxAmount)
{
	var re = /^\d{0,3}.\d{2}$/;
	if (tyAmount.search(re) == -1)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The amount must be a dollar value. \n";
		lcMsg += "Please verify the amount and try again.  \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg);
		document.dmvdonation.elements['DonateAmt'][tnSeqNo].focus()
		return false;
	}
	
	// Make sure this is a number
	lyAmount = new Number(tyAmount);
	
	if (((lyAmount < tyMinAmount) || (lyAmount > tyMaxAmount)) && lyAmount != 0)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "The amount entered must be between " + FormatCurrency(tyMinAmount) + " and " + FormatCurrency(tyMaxAmount) + ". \n";
		lcMsg += "Please verify the amount and try again.  \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg);
		document.dmvdonation.elements['DonateAmt'][tnSeqNo].focus()
		return false;
	}
	else
	{
		return true;
	}

}

/**********************************************\
* Function:	UpdateDonationTotals()
* Author: 	Evie Platt
* Created:	07 Oct 2003
* Description: 
*	Updates Donation Totals
\**********************************************/
function UpdateDonationTotals(tyAmount)
{
	document.dmvdonation.elements['TotalAmt'].value = tyAmount.toFixed(2);
	document.dmvdonation.elements['amount'].value = tyAmount;
}

/**********************************************\
* Function:	SumDonationArray()
* Author: 	Evie Platt
* Created:	07 Oct 2003
* Description: 
*	Sum amounts in installment amount array
\**********************************************/
function SumDonationArray()
{
	var i;
	var lcDonation = '';
	var lySum = 0.00;
	var lnDonateArray = aDonationAmtArray.length;

	for (i=0; i <= lnDonateArray - 1; i++)
	{

		lySum = lySum + aDonationAmtArray[i];
		lcDonation = lcDonation + aDonationArray[i] + '=' + aDonationAmtArray[i] + ';';
		
	}
	document.dmvdonation.elements['Donation'].value = lcDonation
	lDonationRecalc = false;
	UpdateDonationTotals(lySum);	
}

/**********************************************\
* Function:	DonationCheckRecalc()
* Author: 	Evie Platt
* Created:	08 Oct 2003
* Description: 
*		Verify the Hold Card and the
*		Retype Card are the same
\**********************************************/
function DonationCheckRecalc()
{
	if (lDonationRecalc == true)
	{
		lcMsg = "_____________________________________________________________\n\n";
		lcMsg += "You entered donation amounts, but did not recalculate   \n";
		lcMsg += "the total.  Please verify the amounts, click recalculate  \n";
		lcMsg += "and try again.  \n";
		lcMsg += "_____________________________________________________________\n\n";
		alert(lcMsg);
		document.dmvdonation.elements['recalc'].focus()
		return false;
	}
	else
	{
		return true;
	}
}

/*-------------------------------------------------------------------------------------------------
*
*	Title Companies
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	InitTitleCoArray()
* Author: 	Evie Platt
* Created:	21 Oct 04
* Description: 
*	Initialize arrays for Title Company Payments
\**********************************************/
function InitTitleCoArray(nLength)
{
	var i;
	aTitleCoArray.length = nLength; 
	aTitleCoAmtArray.length = nLength;
	aTitleCoItemArray.length = nLength;
	aTitleCoProductArray.length = nLength;
	aTitleCoPayDateArray.length = nLength;
	
	for (i = 0; i <= aTitleCoArray.length - 1; i++)
	{
		aTitleCoArray[i] = null;
		aTitleCoItemArray[i] = null;
		aTitleCoAmtArray[i] = 0.00;
		aTitleCoProductArray[i] = null;
		aTitleCoPayDateArray[i] = null;
	}
}

/**********************************************\
* Function:	SetTitleCoArray()
* Author: 	Evie Platt
* Created:	21 Oct 2004
* Description: 
*	Set values in Title Company arrays
\**********************************************/
function SetTitleCoArray(tnSeqNo, tcProduct, tcItem, tcValue, tyAmount, tcPayDate)
{
	aTitleCoArray[tnSeqNo] = tcValue;
	aTitleCoItemArray[tnSeqNo] = tcItem;
	aTitleCoAmtArray[tnSeqNo] = tyAmount;
	aTitleCoProductArray[tnSeqNo] = tcProduct;
	aTitleCoPayDateArray[tnSeqNo] = tcPayDate;
	TitleCoPayMarked();	
	return true;
}

/**********************************************\
* Function:	UpdateTitleCoTotals()
* Author: 	Evie Platt
* Created:	21 Oct 2004
* Description: 
*	Update Totals for Title Co Payments
\**********************************************/
function UpdateTitleCoTotals(tyAmount)
{
	document.titlecopay.elements['DispAmount'].value = FormatCurrency(tyAmount);
}

/**********************************************\
* Function:	SumTitleCoArray()
* Author: 	Evie Platt
* Created:	21 Oct 2004
* Description: 
*	Sum amounts in title company amount array
\**********************************************/
function SumTitleCoArray()
{
	var i;
	var lySum = 0.00;
	var nTitleCoArray = aTitleCoAmtArray.length;

	for (i=0; i <= nTitleCoArray - 1; i++)
	{
		if (aTitleCoArray[i] == true)
		{
			lySum = lySum + aTitleCoAmtArray[i];
		}
	}
	
	return lySum;
}

/**********************************************\
* Function:	TitleCoClick()
* Author: 	Evie Platt
* Created:	21 Oct 2004
* Description: 
*	Check if selection is valid and update
*	totals when checkbox is clicked.
\**********************************************/
function TitleCoClick (tnSeqNo, tcProduct, tcItem, tcValue, tyAmount, tcPayDate)
{
	var lyTotal = 0.00;

	SetTitleCoArray(tnSeqNo, tcProduct, tcItem, tcValue, tyAmount, tcPayDate);

	// Set value of textbox to total	
	lyTotal = SumTitleCoArray();

	document.titlecopay.elements['DispAmount'].value = FormatCurrency(lyTotal);

	return true;
	
}

/**********************************************\
* Function:	TitleCoMarkAll()
* Author: 	Evie Platt
* Created:	21 Oct 2004
* Description: 
*	Select or clear all items
\**********************************************/
function TitleCoMarkAll(tlMark)
{
	var i;
	var nTitleCoArray = aTitleCoAmtArray.length;
	var lyTotal;
	
	for (i=0; i <= nTitleCoArray - 1; i++)
	{
		if (document.titlecopay.elements['chkTitleCoPay'][i].disabled == false)
		{
			aTitleCoArray[i] = tlMark;
	
			document.titlecopay.elements['chkTitleCoPay'][i].checked = tlMark;
		}
	}
	TitleCoPayMarked();
	lyTotal = SumTitleCoArray()
	document.titlecopay.elements['DispAmount'].value = FormatCurrency(lyTotal);
		
}

/**********************************************\
* Function:	TitleCoPayMarked()
* Author: 	Evie Platt
* Created:	27 Oct 2004
* Description: 
*	Concats selected items together
\**********************************************/
function TitleCoPayMarked()
{
	var i;
	var nTitleCoArray = aTitleCoAmtArray.length;
	var cProduct = '';
	var cItem = '';
	var cAmount = '';
	var cPayDate = '';
	
	for (i=0; i <= nTitleCoArray - 1; i++)
	{
		if (aTitleCoArray[i] == true)
		{
			cProduct = cProduct + aTitleCoProductArray[i] + ';';
			cItem = cItem + aTitleCoItemArray[i] + ';';
			cAmount = cAmount + aTitleCoAmtArray[i] + ';';
			cPayDate = cPayDate + aTitleCoPayDateArray[i] + ';';
		}
	}

	document.titlecopay.elements['product_id'].value = cProduct;
	document.titlecopay.elements['amount'].value = cAmount;
	document.titlecopay.elements['item_id'].value = cItem;
	document.titlecopay.elements['pay_date'].value = cPayDate;
}

/**********************************************\
* Function:	TitleCoCheckTotal()
* Author: 	Evie Platt
* Created:	27 Oct 2004
* Description: 
*		Verify that taxes were selected to pay
*	
\**********************************************/
function TitleCoCheckTotal()
{

	if (document.titlecopay.elements['DispAmount'].value == "$0.00")
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "You did not select any taxes to pay.  Please verify   \n";
		lcMsg += "your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		document.titlecopay.elements['submit'].focus()
		return false;
	}
	else
	{
		return true;
	}
}

/*-------------------------------------------------------------------------------------------------
*
*	Contact and Billing Information
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	SameAsContact()
* Author: 	Evie Platt
* Created:	23 Sep 2003
* Description: 
*	Looks up the contact information if the
*	user says the billing information is the 
*	same.	
*
\**********************************************/
function SameAsContact()
{
	var loName = document.getElementById('Name');
	var loAddress1 = document.getElementById('Address1');
	var loAddress2 = document.getElementById('Address2');
	var loCity = document.getElementById('City');
	var loState = document.getElementById('State');
	var loCountry = document.getElementById('Country');
	var loZip = document.getElementById('Zip');	

	var loContactName = document.getElementById('ContactName');
	var loContactAddress1 = document.getElementById('ContactAddress1');
	var loContactAddress2 = document.getElementById('ContactAddress2');
	var loContactCity = document.getElementById('ContactCity');
	var loContactState = document.getElementById('ContactState');
	var loContactZip = document.getElementById('ContactZip');
	var loContactCountry = document.getElementById('ContactCountry');
	
	document.checkout.elements['Name'].value = loContactName.value;
	document.checkout.elements['Address1'].value = loContactAddress1.value;
	document.checkout.elements['Address2'].value = loContactAddress2.value;
	document.checkout.elements['City'].value = loContactCity.value;

	if (loContactState.value.length == 0)
	{
		loState.value = "";
	}
	else
	{
		loState.value = loContactState.value;
	}
	
	loCountry.value = loContactCountry.value;
	loZip.value = loContactZip.value;
}

/**********************************************\
* Function:	InitStateArray()
* Author: 	Evie Platt
* Created:	15 Sep 2005
* Description: 
*	Initialize arrays for states
\**********************************************/
function InitStateArray(nLength)
{
	var i;
	aStateArray.length = nLength;
	aStateCountryArray.length = nLength;
	for (i = 0; i <= aStateArray.length - 1; i++)
	{
		aStateArray[i] = " ";
		aStateCountryArray[i] = " ";
	}
}

/**********************************************\
* Function:	SetStateArray()
* Author: 	Evie Platt
* Created:	15 Sep 2005
* Description: 
*	Set values in state arrays
\**********************************************/
function SetStateArray(tnSeqNo, tcState, tcCountry)
{
	// Array elements are zero based
	aStateArray[tnSeqNo] = tcState;
	aStateCountryArray[tnSeqNo] = tcCountry;

}

/**********************************************\
* Function:	SetFromState()
* Author: 	Evie Platt
* Created:	14 Sep 05
* Description: 
*		Set values based on what state was chosen
\**********************************************/
function SetFromState (tcValue)
{
	var loCountry = document.getElementById('Country');
	var lnCnt = 0;

	if (tcValue.length > 0)
	{
	
		while (lnCnt <= aStateArray.length && tcValue != aStateArray[lnCnt])
		{
			lnCnt++;
		}
		if (lnCnt == aStateArray.length)
		{
			//This should never happen
			loCountry.value = 'US';	
		}
		else
		{
			loCountry.value = aStateCountryArray[lnCnt];
		}
	}
	else
	{
		loCountry.value = "";
	}
}

/**********************************************\
* Function:	SetFromCountry()
* Author: 	Evie Platt
* Created:	14 Sep 05
* Description: 
*		Set values based on what country was chosen
\**********************************************/
function SetFromCountry (tcValue)
{
	var loState = document.getElementById('State');
	var lnCnt = 0;

	if (!(tcValue == 'US' || tcValue =="UM" || tcValue == "CA"))
	{
		loState.value = "";
	}
	else if (tcValue == 'US')
	{
		loState.value = "FL";		
	}
	else
	{
		while (lnCnt <= aStateCountryArray.length && tcValue != aStateCountryArray[lnCnt])
		{
			lnCnt++;
		}
		if (lnCnt == aStateArray.length)
		{
			//This should never happen
			loState.value = "FL";
		}
		else
		{
			loState.value = aStateArray[lnCnt];
		}
	}
}

/**********************************************\
* Function:	VerifyZip()
* Author: 	Evie Platt
* Created:	14 Sep 05
* Description: 
*		Verify Zip code
\**********************************************/
function VerifyZip (tcValue)
{
	var loCountry = document.getElementById('Country');
	var loZip = document.getElementById('Zip');
	var llResult = false;
	var lcMsg;
	var re;

	if (loCountry.value == "US" || loCountry.value == "UM")
	{
		re = /^[0-9]{5}$|^[0-9]{5}-[0-9]{4}$/;
		if (re.test(tcValue))
		{
			llResult = true;
		}
	}
	else if  (loCountry.value == "CA")
	{

		re = /^[A-Za-z]{1}[0-9]{1}[A-Za-z]{1}\s{1}[0-9]{1}[A-Za-z]{1}[0-9]{1}$/;
		if (re.test(tcValue))
		{
			llResult = true;
		}
	}
	else
	{
		llResult = true;
	}
	if (llResult == false)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Zip/Postal Code is not formatted correctly.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loZip.focus();
	}
	
	return llResult;
}

/*-------------------------------------------------------------------------------------------------
*
*	Verify the Credit Card Page
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	VerifyCardPage()
* Author: 	Evie Platt
* Created:	21 Sep 05
* Description: 
*		Verify Credit Card Show Page
\**********************************************/
function VerifyCardPage()
{
	var loCardType = document.getElementById('CardType');
	var loCardNo = document.getElementById('CreditCardNo');
	var loExpMonth = document.getElementById('ExpMonth');
	var loExpYear = document.getElementById('ExpYear');
	var loCountry = document.getElementById('Country');
	var loZip = document.getElementById('Zip');
	
	if (RTrim(loCardType.value).length == 0)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Card Type cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loCardType.focus();
		return false;
	}

	if (RTrim(loExpMonth.value).length == 0)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Expiration Month cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loExpMonth.focus();
		return false;
	}

	if (RTrim(loExpYear.value).length == 0)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Expiration Year cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loExpYear.focus();
		return false;
	}

	if (RTrim(loCountry.value).length == 0)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Country cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loCountry.focus();
		return false;
	}
	
	if (VerifyZip (RTrim(loZip.value)) == false)
	{
		return false;
	}

	if (VerifyCard() == false)
	{
		return false;
	}
	return true;	
}

/*-------------------------------------------------------------------------------------------------
*
*	Verify the EFT Page
*
-------------------------------------------------------------------------------------------------*/
/**********************************************\
* Function:	VerifyEFTPage()
* Author: 	Evie Platt
* Created:	21 Sep 05
* Description: 
*		Verify EFT Show Page
\**********************************************/
function VerifyEFTPage()
{
	var loAccountType = document.getElementById('AccountType');
	var loRoutingNo = document.getElementById('RoutingNo');
	var loAccountNo = document.getElementById('AccountNo');
	var loCountry = document.getElementById('Country');
	var loZip = document.getElementById('Zip');
	
	if (RTrim(loAccountType.value).length == 0)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Account Type cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loCardType.focus();
		return false;
	}

	if (RTrim(loCountry.value).length == 0)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Country cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loCountry.focus();
		return false;
	}
	
	if (VerifyZip (RTrim(loZip.value)) == false)
	{
		return false;
	}
	
	if (VerifyRouting() == false)
	{
		return false;
	}
	
	if (VerifyAccount() == false)
	{
		return false;
	}
	return true;	
}

/*-------------------------------------------------------------------------------------------------
*
*	Credit Card Fees
*
-------------------------------------------------------------------------------------------------*/

/**********************************************\
* Function:	InitCardArray()
* Author: 	Evie Platt
* Created:	04 Nov 2009
* Description: 
*	Initialize arrays for credit cards
\**********************************************/
function InitCardTypeArray(nLength)
{
	var i;
	aCardArray.length = nLength
	for (i = 0; i <= aCardArray.length - 1; i++)
	{
		aCardArray[i] = null;
		aCardAmtArray[i] = 0.00;
	}
}

/**********************************************\
* Function:	SetCardTypeArray()
* Author: 	Evie Platt
* Created:	04 Nov 2009
* Description: 
*	Set values in card type arrays
\**********************************************/
function SetCardTypeArray(tnCardTypeNo, tcValue, tyAmount)
{
	// Set the value of the checkbox in the array
	// Array elements are zero based
	aCardArray[tnCardTypeNo] = tcValue;
	aCardAmtArray[tnCardTypeNo] = tyAmount;
}

/**********************************************\
* Function:	CreditCardOnChange()
* Author: 	Evie Platt
* Created:	04 Nov 2009
* Description: 
*	Find amount to go with card type value
\**********************************************/
function CreditCardOnChange(tcValue)
{
	var i=0;
	document.checkout.elements['FeeMessage'].value = '';
	for (i = 0; i <= aCardArray.length - 1; i++)
	{
		if (aCardArray[i] == tcValue)
		{
			document.checkout.elements['FeeMessage'].value = 'Attention: A convenience fee of $' + 
				aCardAmtArray[i] + 
				' will be added to the total of your transaction.';
			break;
		}
	}
}

/*-------------------------------------------------------------------------------------------------
*
*	Verify the Contact Page
*
-------------------------------------------------------------------------------------------------*/
/**********************************************\
* Function:	VerifyContactPage()
* Author: 	Evie Platt
* Created:	21 Sep 05
* Description: 
*		Verify Contact Show Page
\**********************************************/
function VerifyContactPage()
{
	var loCountry = document.getElementById('Country');
	var loZip = document.getElementById('Zip');
	
	if (RTrim(loCountry.value).length == 0)
	{
		lcMsg = "_________________________________________\n\n";
		lcMsg += "The Country cannot be blank.   \n";
		lcMsg += "Please verify your selection and try again.  \n";
		lcMsg += "_________________________________________\n\n";
		alert(lcMsg);
		loCountry.focus();
		return false;
	}
	
	if (VerifyZip (RTrim(loZip.value)) == false)
	{
		return false;
	}
}

/*-------------------------------------------------------------------------------------------------
*
*	Other
*
-------------------------------------------------------------------------------------------------*/
/**********************************************\
* Function:	ClickConfirmPayment()
* Author: 	Evie Platt
* Created:	12 Nov 2003
* Description: 
*		Set value that the payment was confirmed
\**********************************************/
function ClickConfirmPayment(tcAction)
{
	var loConfirm = document.getElementById('confirm');
	var loConfirmCart = document.getElementById('confirmcart');
	
	loConfirm.value = tcAction;
	loConfirmCart.submit();
}

/**********************************************\
* Function:	ClickDeclinedPayment()
* Author: 	Evie Platt
* Created:	12 Nov 2003
* Description: 
*		Set value that the payment was confirmed
\**********************************************/
function ClickDeclinedPayment(tcAction)
{
	var loMethod = document.getElementById('method');
	var loDeclinedPayment = document.getElementById('declinedpayment');
	
	loMethod.value = tcAction;
	loDeclinedPayment.submit();
}

/**********************************************\
* Function:	ClickEpayment()
* Author: 	Evie Platt
* Created:	12 Nov 04
* Description: 
*		Redirect for ePayment Cart String
\**********************************************/
function ClickEpayment(tcLink)
{
	location.href = tcLink;
}






