function peErrorDisplay(){
	jQuery('#purchaseTable>div').css('display','none');
	//$('purchaseLinks').style.display = "none";
	//$('purchaseLinks1').style.display = "block";	  
	
	jQuery('#leaseTable>div').css('display','none');
	//$('leaseLinks').style.display = "none";
	//$('leaseLinks1').style.display = "block";

}

// ###	Creates structured data for a lease item. An array of these instances is
//		passed into EstimatorDataClass function as leaseDataArray
function LeaseDataClass (acquisitionFeeNum, mileageCdeVal, moneyFactorFloat, residualPctFloat, termNum, standardOrSpecialLease) {
	this.acquisitionFeeAmt = acquisitionFeeNum;
	this.mileageCde = mileageCdeVal;
	this.moneyFactor = moneyFactorFloat;
	this.residualPct = residualPctFloat;
	this.term = termNum;
	this.standardOrSpecialLease = standardOrSpecialLease;	
}

function PurchaseDataClass (termNum, apr, standardOrSpecialApr) {
	this.term = termNum;
	this.apr = apr;
	this.standardOrSpecialApr = standardOrSpecialApr;
}


// ###	Core Data class for the payment estimator
function EstimatorDataClass (yearNum, baseMsrpNum, destFeeNum, leaseDataArray, purchaseDataArray, leaseMileagePE,purchaseTermPE,leaseTermPE) {
//function EstimatorDataClass (yearNum, baseMsrpNum, destFeeNum, leaseDataArray) {
//	### PRIVATE ###
	var modelYear = yearNum;
	var baseMSRP = baseMsrpNum;
	var destinationFee = destFeeNum;
	var leaseDataList = leaseDataArray;
	var purchaseDataList = purchaseDataArray;
	//var apr = apr;
	var hasLeaseData = checkHasLeaseData(leaseDataList);
	var hasPurchaseData = checkHasPurchaseData(purchaseDataList);
	//remove dh = use of pop equip msrp
	//var loanData = new LoanDataClass ( (baseMSRP+destinationFee), 60, 3000, 0, '6.0'); //These values are the page defaults
	
	var apr = getAprForTerm(purchaseDataList, purchaseTermPE,'apr');
	/*if(apr == null)
	{
		apr = "1.0";
	}*/
	//apr = apr+1.0;
	//alert("apr:"+apr);
	//alert("apr value:"+apr);
	var loanData = new LoanDataClass ( (baseMSRP), purchaseTermPE, costofaccess, downpayment, tradein, owedontrade, apr); //These values are the page defaults
	
	
	//var loanData = new LoanDataClass ( (baseMSRP), 60, 0, 0, 0, '6.0'); //These values are the page defaults
	
	//change the lease term = 36 and use of pop equip msrp = remove dh
	//var leaseData = new LeaseDataClass ( (baseMSRP+destinationFee), 24, 3000, 0, 'L'); //These values are the page defaults
		var leaseData = new LeaseDataClass ( (baseMSRP), leaseTermPE, costofaccess, downpayment, tradein, owedontrade, leaseMileagePE); //These values are the page defaults
	
	
	// Data for the lease part of the app is stored in this instace. Holds and
	// drives all lease specific data and functions
	function LeaseDataClass (estSellingPriceNum, termNum, costOfAccessories, downPaymentNum, tradeInNum, owedTradeIn, mileageCodeValue) {
		var estimatedSellingPrice = estSellingPriceNum;
		var term = termNum;
		var downPayment = downPaymentNum;
		var tradeIn = tradeInNum;
		var mileageCode = mileageCodeValue;
		var owedTradeIn = owedTradeIn;
		
		this.getEstimatedSellingPrice = function (formatFlag) { if (formatFlag) return convertToDollar(estimatedSellingPrice); else return estimatedSellingPrice; }
		this.setEstimatedSellingPrice = function (value) { estimatedSellingPrice = value; }
		
		this.getTerm = function () { return term; };
		this.setTerm = function (value) { term = value; };
		
		this.getCostOfAccessories = function () { return costOfAccessories; };
		this.setCostOfAccessories = function (value) { costOfAccessories = value; };

		this.getDownPayment = function () { return downPayment; };
		this.setDownPayment = function (value) { downPayment = value; };
		
		this.getTradeIn = function () { return tradeIn; };
		this.setTradeIn = function (value) { tradeIn = value; };
		
		this.getOwedTradeIn = function () { return owedTradeIn; };
		this.setOwedTradeIn = function (value) { owedTradeIn = value; };

		this.getMileageCode = function () { return mileageCode; };
		this.setMileageCode = function (value) { mileageCode = value; };
		
		//dh remove= use of pop equip msrp
		//this.getMonthlyLeasePaymentObj = function () { return calculateLease(estimatedSellingPrice,(baseMSRP+destinationFee),downPayment,tradeIn,mileageCode,term); }
		
		this.getMonthlyLeasePaymentObj = function () { return calculateLease(estimatedSellingPrice,(baseMSRP), costOfAccessories, downPayment,tradeIn, owedTradeIn, mileageCode,term); }
	}
	
	// Data for the loan (aka purchase) part of the app is stored in this instace.
	// Holds and drives all loan specific data and functions
	function LoanDataClass (estSellingPriceNum, termNum, costOfAccess, downPaymentNum, tradeInNum, owedTradeIn, aprValue) {
		var estimatedSellingPrice = estSellingPriceNum;
		var term = termNum;
		var costOfAccessories = costOfAccess;
		var downPayment = downPaymentNum;
		var tradeIn = tradeInNum;
		var owedTradeIn = owedTradeIn;
		var apr = aprValue;
		var SAprFlag=0;
		
		this.getEstimatedSellingPrice = function (formatFlag) { if (formatFlag) return convertToDollar(estimatedSellingPrice); else return estimatedSellingPrice; }
		this.setEstimatedSellingPrice = function (value) { estimatedSellingPrice = value; }
		
		this.getTerm = function () { return term; };
		this.setTerm = function (value) { term = value; };
		
		this.getCostOfAccessories = function () { return costOfAccessories; };
		this.setCostOfAccessories = function (value) { costOfAccessories = value; };

		this.getDownPayment = function () { return downPayment; };
		this.setDownPayment = function (value) { downPayment = value; };
		
		this.getTradeIn = function () { return tradeIn; };
		this.setTradeIn = function (value) { tradeIn = value; };
		
		this.getOwedTradeIn = function () { return owedTradeIn; };
		this.setOwedTradeIn = function (value) { owedTradeIn = value; };

		this.getApr = function () { return apr; };
		this.setApr = function (value) { apr = value; };
		this.getSAprFlag = function() { 
		
		var standardAPRType='0';

		if(getAprForTerm(purchaseDataList, term, 'standardOrSpecialApr') ==standardAPRType)
			return true; 
		else 
			return false;
		
		};
		
		this.getMonthlyLoanPaymentObj = function () { return calculateLoan( estimatedSellingPrice, costOfAccessories, downPayment, tradeIn, owedTradeIn, apr, term ); }
	}
	
	// Validates and calculates lease data.
	// Note: this is primarily legacy code with minor modifications
	function calculateLease(fLeasePrice,fActualMSRP,fcostOfAccessories,fDownPay,fTradeIn, fOwedTradeIn, fLeaseType,fTerm) {
		var estLeasePrice = fLeasePrice * 1;
		var actualMSRP = fActualMSRP * 1;
		var costOfAccess = fcostOfAccessories * 1;
		var downPay = fDownPay * 1;
		var tradeIn = fTradeIn * 1;
		var owedTradeIn  = fOwedTradeIn * 1;
		var amtFinanced;

		var errorMsg;
		var errorCheck = false; // false = no error; true = error
		var errorType = "lease";
		
		// set all values from the array
		var moneyFactor = getLeaseDataForTypeAndTerm(fLeaseType,fTerm,'moneyFactor');//leaseDataArray[fLeaseType][fTerm].moneyfactor  * 1;
		/*if(moneyFactor == null)
		{
			moneyFactor = 0.00035;
		}*/
		//moneyFactor = moneyFactor+0.00035;
		//moneyFactor = moneyFactor+0.00125; // MY Updated
		
		var residualPct = getLeaseDataForTypeAndTerm(fLeaseType,fTerm,'residualPct');//leaseDataArray[fLeaseType][fTerm].residual  * 1;
		
                //hardcoded 3/28/07
		 //var acquisitionFee = getLeaseDataForTypeAndTerm(fLeaseType,fTerm,'acquisitionFeeAmt');//leaseDataArray[fLeaseType][fTerm].destination  * 1;
            //Checking  moneyFactor and residualPCT are  null or not
			if(moneyFactor == null || residualPct==null)
			{
				errorMsg = "Lease data is currently unavailable.  Please see your NISSAN dealer for Purchase offers.<br /><br />";
				errorCheck = true;
			}
           	else if(moneyFactor == "NONE" || residualPct=="NONE"){
				if(isEspanol){
					errorMsg = "Sentimos la incoveniencia. Basado en tus selecciones, actualmente no tenemos ninguna oferta que satisfaga tu solicitud. Por favor cambia el t&#233;rmino o las millas que se encuentran debajo para la mejor oferta disponible, o contacta tu concesionario Nissan.<br /><br />";
				}
				else{
		     		errorMsg = "We're sorry for the inconvenience. Based on your selections, we do not currently have any offers that meet your criteria. Please try changing the Term or Mileage below for the best offers available, or contact your Nissan Dealer.<br /><br />";
				}
				jQuery('#leaseTable>div').css('display','none');
				$('leaseLinks').style.display = "none";
				$('leaseLinks1').style.display = "block";
			    $('leaseTermDiv').style.display = "block";
				$('leaseMileageDiv').style.display = "block";
				errorCheck = true;
		 }
		 
		var acquisitionFee = 595;
		var incentives = 0; // no incentives as of now
	
		// calculate monthly Lease Payments
		var residualValue = (actualMSRP + costOfAccess) * (residualPct);
		
		
		
		var totalGrossCapCost = estLeasePrice + incentives + acquisitionFee + costOfAccess;
		var capCostReduction = downPay + tradeIn - owedTradeIn;
		var adjustedCapCost = totalGrossCapCost - capCostReduction;
		var depreciationPay = (adjustedCapCost - residualValue) / fTerm;
		var monthlyRentCharge = (adjustedCapCost + residualValue) * moneyFactor;
		var monthlyLeasePay = monthlyRentCharge + depreciationPay;
		
		
		
		
		amtFinanced = (actualMSRP + costOfAccess) - capCostReduction;
		

		
		// SA500 Changes - Start
		var acquisition_Fee = acquisitionFee;
		var cap_Cost_Reduction = capCostReduction;
		var adjusted_Cap_Cost = adjustedCapCost;
		var security_dep = roundValTo50(monthlyLeasePay);	
		var first_Inst = parseFloat(monthlyLeasePay);
                
                //removed acquisitionfee 4/2/07 already calculated at totalGrossCapCost value
		//var total_Due = acquisitionFee + security_dep + first_Inst + cap_Cost_Reduction;	
		
		var total_Due =  security_dep + first_Inst + cap_Cost_Reduction;	
		// SA500 Changes - End
	
		// BEGIN ERROR CHECK
		if (estLeasePrice < (actualMSRP * 0.70)){
			errorMsg = "Est. purchase price must be greater than or equal to $" + roundValue(actualMSRP * 0.70) + ". Please re-enter the est. purchase price.<br /><br />";
			peErrorDisplay();
			errorCheck = true;		
		} 
		else if (estLeasePrice > (actualMSRP * 1.25)) {
			errorMsg = "Est. purchase price must be less than or equal to $" + roundValue(actualMSRP * 1.25) + ". Please re-enter the est. purchase price.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		//Addedd as a part of PE_Enhancements
		else if(costOfAccess < 0) {
			errorMsg = "Cost Of Accessories must be greater than $0. <br> Please re-enter the cost of accessories amount.<br /><br />";
			errorCheck = true;
		}
		//End
		else if (downPay < 0) {
			errorMsg = "Down payment must be greater than or equal to $0. Please re-enter the down payment amount.<br /><br />";
			errorCheck = true;
		}
		//Added as a part of PE_Enhancements
		else if (owedTradeIn < 0) {
			errorMsg = "Owed TradeIn must be greater than or equal to $0. Please re-enter the down payment amount.<br /><br />";
			errorCheck = true;
		}
		//end of the changes
		//Added as a part of PE_Enhancements
		else if(costOfAccess > estLeasePrice) {
			errorMsg = "Cost Of Accessories must be less than est. purchase price.<br>  Please reduce Cost Of Accessories amount.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		//end of the changes
		else if (downPay > estLeasePrice) {
			errorMsg = "Down payment must be less than lease price. Please adjust the fields to the left to recalculate.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		else if (tradeIn < 0) {
			errorMsg = "Net trade-in value must be greater than or equal to $0. Please re-enter the net trade-in value.<br /><br />";
			errorCheck = true;
		}
		else if (tradeIn > estLeasePrice) {
			errorMsg = "Net trade-in value must be less than or equal to est. purchase price. Please re-enter the net trade-in value.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		else if (capCostReduction > (estLeasePrice * 0.29)) {
			errorMsg = "The sum of net trade-in value and down payment must be less than or equal to $" + roundValue(estLeasePrice * 0.29) + ". Please reduce down payment and/or trade-in amount.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}

		else if (adjustedCapCost < residualValue + 100) {
			errorMsg = "The est. purchase price minus the net trade-in value and down payment must be greater than $" + roundValue(residualValue + 100) + ". Please reduce down payment and/or trade-in amount.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		// END ERROR CHECK
	
		if (errorCheck) { monthlyLeasePay = -1; }

		return new MonthlyLeasePaymentClass(errorCheck, errorMsg, parseFloat(monthlyLeasePay), adjusted_Cap_Cost, security_dep, first_Inst, acquisition_Fee, cap_Cost_Reduction, total_Due, parseFloat(amtFinanced)) ;
	}
	
	// Creates structured data for the return value of calculateLease function.
	// It bundles error messaging and lease specific values
	function MonthlyLeasePaymentClass (isErrorBool, errorMsgValue, leasePaymentFloat, adjustedCapCostNumber, securityDepNumber, firstPaymentFloat, acquisitionFeeNumber, capCostReductionNumber, totalDueFloat , amtFinancedFloat) {
		var isError = isErrorBool;
		var errorMsg = errorMsgValue;
		var paymentValue = Math.ceil(leasePaymentFloat);
		var adjustedCapCost = adjustedCapCostNumber;
		var securityDeposite = securityDepNumber;
		var firstPayment = firstPaymentFloat;
		var acquisitionFee = Math.ceil(acquisitionFeeNumber);
		var capCostReduction = capCostReductionNumber;
		var totalDue = Math.ceil(totalDueFloat);
		var amtFinanced = Math.ceil(amtFinancedFloat);
		
		this.getIsError = function () { return isError }
		this.getErrorMsg = function () { return errorMsg }
		this.getPaymentValue = function (formatFlag){ if (formatFlag) return convertToDollar(paymentValue); else return paymentValue; }
		this.getAdjustedCapCost = function (formatFlag){ if (formatFlag) return convertToDollar(adjustedCapCost); else return adjustedCapCost; }
		this.getSecurityDeposite = function (formatFlag){ if (formatFlag) return convertToDollar(securityDeposite); else return securityDeposite; }
		this.getFirstPayment = function (formatFlag){ if (formatFlag) return convertToDollar(firstPayment); else return firstPayment; }
		this.getAcquisitionFee = function (formatFlag){ if (formatFlag) return convertToDollar(acquisitionFee); else return acquisitionFee; }
		this.getCapCostReduction = function (formatFlag){ if (formatFlag) return convertToDollar(capCostReduction); else return capCostReduction; }
		this.getTotalDue = function (formatFlag){ if (formatFlag) return convertToDollar(totalDue); else return totalDue; }		
		this.getAmtFinanced = function (formatFlag){ if (formatFlag) return convertToDollar(amtFinanced); else return amtFinanced; }		
	}
	

	// Validates and calculates loan data.
	// Note: this is primarily legacy code with minor modifications
	function calculateLoan(fLoanPrice,fcostOfAccessories,fDownPay,fTradeIn,fOwedTradeIn,fRate,intTerm) {
		var cost = fLoanPrice * 1;
		var costOfAccess = fcostOfAccessories * 1;
		var downPay = fDownPay * 1;
		var tradeIn = fTradeIn * 1;
		var owedTradeIn = fOwedTradeIn * 1;
		var loanRate;
		var standardAPRType='0';
		var specialAPRType='1';
		var standardOrSpecialAprType = getAprForTerm(purchaseDataList, intTerm,'standardOrSpecialApr');	
		var apr=fRate;
		var term = intTerm;


		
		if(currentOffers == true)
		{
			//loanRate = ((apr)/100)*1;
			
			if(standardOrSpecialAprType == standardAPRType)
			{				
			
			//loanRate = ((apr+2.00)/100)*1; //MY Updated
			loanRate = ((parseFloat(apr) +1.00)/100)*1; //MY Updated		
			}
			else{
			loanRate = ((apr)/100)*1; 
			}			
		}
		else
		{						
			if(standardOrSpecialAprType == standardAPRType)
			{		
		
			//loanRate = ((apr+2.00)/100)*1; //MY Updated				
			loanRate = ((parseFloat(apr) +1.00)/100)*1; //MY Updated			
			}
			else{
			loanRate = ((apr)/100)*1; 
			}
		}
		//var loanRate = fRate * 1;
		var term = intTerm * 1;
		var loanPayment;
		var amtFinanced;
	
		var errorMsg;
		var errorCheck = false; // false = no error; true = error
		var errorType = "loan";
	
		//var apr = getAprForTerm(intTerm,'apr');


		// BEGIN ERROR CHECKING
		if(apr==null)
		{
			errorMsg = "Purchase data is currently unavailable.  Please see your NISSAN dealer for Purchase offers.<br /><br />";
			errorCheck = true;
		}
		else if(apr == "NONE"){
				if(isEspanol){
					errorMsg = "Sentimos la incoveniencia. Basado en tus selecciones, actualmente no tenemos ninguna oferta que satisfaga tu solicitud. Por favor cambia el t&#233;rmino que se encuentra debajo para la mejor oferta disponible, o contacta tu concesionario Nissan.<br /><br />";			
				}
				else{
					errorMsg = "We're sorry for the inconvenience. Based on your selections, we do not currently have any offers that meet your criteria. Please try changing the Term below for the best offers available, or contact your Nissan Dealer.<br /><br />";			
				}
				jQuery('#purchaseTable>div').css('display','none');
				$('purchaseLinks').style.display = "none";
			    $('purchaseLinks1').style.display = "block";	  
				$('purchaseTermDiv').style.display = "block";
				$('purchaseTermDiv').style.paddingTop = "5px";
				$('purchaseLinks1').style.position = "relative";
				$('purchaseLinks1').style.top = "20px";
	     		errorCheck = true;
		 }  		
		else if (cost <= 0) {
			errorMsg = "Est. purchase price must be greater than $0. <br>Please re-enter the est. purchase price.<br /><br />";
			errorCheck = true;
		}
		//Addedd as a part of PE_Enhancements
		else if(costOfAccess < 0) {
			errorMsg = "Cost Of Accessories must be greater than $0. <br> Please re-enter the cost of accessories amount.<br /><br />";
			errorCheck = true;
		}
		//End
		else if (downPay < 0) {
			errorMsg = "Down payment must be greater than $0. <br> Please re-enter the down payment amount.<br /><br />";
			errorCheck = true;
		}
		//Added as a part of PE_Enhancements
		else if (owedTradeIn < 0) {
			errorMsg = "Owed TradeIn must be greater than or equal to $0. Please re-enter the down payment amount.<br /><br />";
			errorCheck = true;
		}
		//end of the changes
		//Added as a part of PE_Enhancements
		else if(costOfAccess > cost) {
			errorMsg = "Cost Of Accessories must be less than est. purchase price.<br>  Please reduce Cost Of Accessories amount.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		//end of the changes
		else if (downPay > cost) {
			errorMsg = "Down payment must be less than purchase price. Please adjust the fields to the left to recalculate.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		else if (tradeIn < 0) {
			errorMsg = "Net trade-in value must be greater than or equal to $0. <br>Please re-enter the trade-in amount.<br /><br />";
			errorCheck = true;
		}
		else if (tradeIn > cost) {
			errorMsg = "Net trade-in value must be less than est. purchase price. <br> Please reduce net trade-in value amount.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		else if (loanRate < 0) {
			errorMsg = "Interest rate must be greater than or equal to 0.<br>  Please re-enter the Interest Rate.<br /><br />";
			errorCheck = true;
		}
		else if ((tradeIn + downPay) > cost) {
			errorMsg = "Net trade-in value plus down payment must be less than est. purchase price. <br> Please reduce down payment and/or trade-in amount.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		else if ((cost - tradeIn - downPay) < 4000) {
			errorMsg = "Your total finance amount must be greater than $4,000.<br /><br />";
			peErrorDisplay();
			errorCheck = true;
		}
		// END ERROR CHECKING
	
		// if no errors found, then calculate payment
		if (!errorCheck) {
			amtFinanced = cost + costOfAccess - tradeIn - downPay + owedTradeIn;
			if (loanRate == 0) {
				loanPayment = amtFinanced / term;
			} else {
				// calculate monthly loan payment
				var a = 1 / (1 + (loanRate/12));			
				var b = a - Math.pow(a,(term + 1));
				loanPayment = amtFinanced * (1 - a) / b;
				
			}
		} else { loanPayment = -1; }
		return new MonthlyLoanPaymentClass(errorCheck, errorMsg, parseFloat(loanPayment), parseFloat(amtFinanced));
	}
	
	// Creates structured data for the return value of calculateLoan function.
	// It bundles error messaging and loan specific values
	function MonthlyLoanPaymentClass (isErrorBool, errorMsgValue, loanPaymentFloat, amtFinancedFloat) {
		var isError = isErrorBool;
		var errorMsg = errorMsgValue;
		var paymentValue = Math.ceil(loanPaymentFloat);
		var amtFinanced = amtFinancedFloat;
		
		this.getIsError = function () { return isError }
		this.getErrorMsg = function () { return errorMsg }
		this.getPaymentValue = function (formatFlag){ if (formatFlag) return convertToDollar(paymentValue); else return paymentValue; }
		this.getAmtFinanced =  function (formatFlag){ if (formatFlag) return convertToDollar(amtFinanced); else return amtFinanced; }
	}
	
	
	// LEGACY: Rounds values to 2 decimal places and adds a zero to ensure well rounded cents (ex: $34.80 instead of $34.8)
	function roundValue(number){
	    number = Math.round(number*100)/100;
		return (number == Math.floor(number)) ? number + '.00' : ((number*10 == Math.floor(number*10)) ? number + '0' : number);
	}
	
	// LEGACY: Converts any number ie. 999999 to a dollar value of $999,999 or 999.00 to a dollar value of $999.00.
	function convertToDollar(numValue){
		var signValue = "";
		var intNumberValue = parseFloat(numValue);
		if(intNumberValue < 0) signValue = "-";
		//var strNumberValue = roundValue(Math.abs(intNumberValue)) + ' ';
		var strNumberValue = Math.abs(intNumberValue)+ ' ';
		strNumberValue = strNumberValue.substring(0,strNumberValue.length - 1)
		var numLength = strNumberValue.length;
		/*if (strNumberValue.length > 6)
			strNumberValue = "$" + strNumberValue.slice(0,numLength-6) + "," + strNumberValue.slice(numLength-6,numLength)*/
		if (strNumberValue.length > 3)
			strNumberValue = "$" + strNumberValue.slice(0,numLength-3) + "," + strNumberValue.slice(numLength-3,numLength)
		else
			strNumberValue = "$" + strNumberValue.slice(0,numLength)
		return (signValue + strNumberValue);
	}
	
	// LEGACY: Function added for SA500 - rounds the value to next 50
	function roundValTo50(origNumber)
	{
			var ceilNumber = (Math.ceil(origNumber/100))*100;
			var diff = ceilNumber-origNumber;
			diff = ((diff < 50) ? 0 : (50));
			var updatedNumber = ceilNumber - diff;
			return updatedNumber;
	}
	
	// A helper function that returns a requested property value from a
	// LeaseDataClass object in the leaseDataList array based on the given lease 
	// type and lease term
	function getLeaseDataForTypeAndTerm (leaseTypeValue, leaseTermNumber, propFlag) {
		if ( !hasLeaseData ) return null;
		var foundLeaseItem = null;
		for (var idx in leaseDataList) {
			leaseItem = leaseDataList[idx];
			if (leaseItem.mileageCde == leaseTypeValue && leaseItem.term == leaseTermNumber) {
				foundLeaseItem = leaseItem;
				break;
			}
		}
		
		if(foundLeaseItem == null){
		foundLeaseItem= new Array();
		foundLeaseItem.moneyFactor="NONE";			
		foundLeaseItem.residualPct="NONE";	
		foundLeaseItem.acquisitionFeeAmt="NONE";			
		}		
		
		switch (propFlag){
			case 'moneyFactor':
				return foundLeaseItem.moneyFactor;
			case 'residualPct':
				return foundLeaseItem.residualPct;
			case 'acquisitionFeeAmt':
				return foundLeaseItem.acquisitionFeeAmt;
			default: 
				return foundLeaseItem;
		}
	}
	

		//For APR
	function getAprForTerm(purchaseDataList, purchaseTermNumber, propFlag)
	{
		if ( !hasPurchaseData ) return null;
		//alert("purcahseDataList in APR func: "+purchaseDataList.length+"term: "+purchaseTermNumber);
		var foundPurchaseItem = null;
		for (var idx in purchaseDataList) {
			purchaseItem = purchaseDataList[idx];
			//alert("term in for loop: "+purchaseItem.term);
			if (purchaseItem.term == purchaseTermNumber) {
				foundPurchaseItem = purchaseItem;
				break;
			}
		}
		switch (propFlag){
			case 'apr':	
				if(foundPurchaseItem == null){
				return "NONE";
				}
				else{
				return foundPurchaseItem.apr;
				}
			case 'standardOrSpecialApr':	
				if(foundPurchaseItem == null){
				return "NONE";
				}
				else{
				return foundPurchaseItem.standardOrSpecialApr;				
				}
			default: 
				return foundPurchaseItem;
		}
	}

	// Helper function to determin if lease data was passed is
	function checkHasPurchaseData( purchaseDataList ) {
		if ( typeof(purchaseDataList) == 'undefined' || !purchaseDataList || purchaseDataList.length <= 0 )
			return false;
		return true;
	}


	// Helper function to determin if lease data was passed is
	function checkHasLeaseData( leaseDataList ) {
		if ( typeof(leaseDataList) == 'undefined' || !leaseDataList || leaseDataList.length <= 0 )
			return false;
		return true;
	}



//	### PUBLIC ###
	this.getModelYear = function () { return modelYear }
	this.setModelYear = function (value) { modelYear = value; }
	
	this.getBaseMSRP = function (formatFlag) { if (formatFlag) return convertToDollar(baseMSRP); else return baseMSRP; }
	this.setBaseMSRP = function (value) { baseMSRP = value; }
	
	this.getDestinationFee = function (formatFlag){ if (formatFlag) return convertToDollar(destinationFee); else return destinationFee; }
	this.setDestinationFee = function (value) { destinationFee = value; }
	
	//removed dh = use of pop equip msrp
	//this.getEstimatedSellingPrice = function (formatFlag) { if (formatFlag) return convertToDollar(baseMSRP+destinationFee); else return (baseMSRP+destinationFee); }

	this.getEstimatedSellingPrice = function (formatFlag) { if (formatFlag) return convertToDollar(baseMSRP); else return (baseMSRP); }
	
	this.getLeaseDataList = function (){ return leaseDataList; }
	
	this.getLoanDataObj = function () { return loanData; }
	
	this.getLeaseDataObj = function () { return leaseData; }
	
	this.getHasLeaseData = function () { return hasLeaseData; }

	this.getHasPurchaseData = function () { return hasPurchaseData; }
}

// this.getErrorMsg = function () { return errorMsg }

// versa 1.6 trim removal
function disableTrim(){
	
	var selectedVehicleIndex = document.paymentEstimatorForm.vehicle.selectedIndex;
	var CheckVehicleIndex = 16; // 16 = versa

	if (selectedVehicleIndex == CheckVehicleIndex){
		 	var elSel = document.getElementById('drpTrim');
  			var i;
 
  			for (i = elSel.length - 1; i>=0; i--) {
		
				//alert(elSel.options[i].value);
				if(elSel.options[i].value == 'Versa Sedan 1.6' || elSel.options[i].value == 'Versa Sedan 1.6 Base MT' || elSel.options[i].value == 'Versa Sedan 1.6 MT')
				{

      	 			elSel.remove(i);

  				}
 			}

	}			
}