		// Functions
		var CheckIE4 = false;
		if(navigator.appName.indexOf("Microsoft") != -1  &&  parseInt(navigator.appVersion) >= 4)
			CheckIE4 = true;

		var cache = '';
		var globalMntlyPay = '';
		var theIndid;
		
		var answer= '';

		// Validate the Fields
		
		function readIndid(pcform)
		{
			theIndid =   getQueryVariable("indid");
			setdefaults(document.FormPaymentCalc);
		}
		
		function setdefaults(pcform)
		{
			switch (theIndid)
			{
				case '1':
				//calc_term_values = '60,84,120,144,180,240';
				//calc_term_text = '5 Years,7 Years,10 Years,12 Years,15 Years,20 Years';
				document.FormPaymentCalc.TxtBoxMonth.value = '120';
				document.FormPaymentCalc.TxtBoxYear.value = '10';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '9.00';
				break;

				case '2':
				//calc_term_values = '12,24,36,48,60,72,84';
				//calc_term_text = '12 Months,24 Months,36 Months,48 Months,60 Months,72 Months,84 Months';
				document.FormPaymentCalc.TxtBoxMonth.value = '36'; 
				document.FormPaymentCalc.TxtBoxYear.value = '3';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '13.9';
				break;

				case '3':
				//calc_term_values = '12,24,36,48,60,72,84';
				//calc_term_text = '12 Months,24 Months,36 Months,48 Months,60 Months,72 Months,84 Months';
				document.FormPaymentCalc.TxtBoxMonth.value = '84';
				document.FormPaymentCalc.TxtBoxYear.value = '7';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '13.9';
				break; 

				case '4':
				//calc_term_values = '12,24,36,48,60,72,84';
				//calc_term_text = '12 Months,24 Months,36 Months,48 Months,60 Months,72 Months,84 Months';
				document.FormPaymentCalc.TxtBoxMonth.value = '24';
				document.FormPaymentCalc.TxtBoxYear.value = '2';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '8.00';
				break;

				case '5': 
				//calc_term_values = '12,24,36,48,60,72,84';
				//calc_term_text = '12 Months,24 Months,36 Months,48 Months,60 Months,72 Months,84 Months';
				document.FormPaymentCalc.TxtBoxMonth.value = '24';
				document.FormPaymentCalc.TxtBoxYear.value = '2';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '8.00';
				break;

				case '6': 
				//calc_term_values = '12,24,36,48,60,72,84';
				//calc_term_text = '12 Months,24 Months,36 Months,48 Months,60 Months,72 Months,84 Months';
				document.FormPaymentCalc.TxtBoxMonth.value = '36';
				document.FormPaymentCalc.TxtBoxYear.value = '3';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '8.00';
				break;

				case '7': 
				//calc_term_values = '12,24,36,48,60,72,84';
				//calc_term_text = '12 Months,24 Months,36 Months,48 Months,60 Months,72 Months,84 Months';
				document.FormPaymentCalc.TxtBoxMonth.value = '36';
				document.FormPaymentCalc.TxtBoxYear.value = '3';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '8.00';
				break;
				
				default:
				document.FormPaymentCalc.TxtBoxMonth.value = '120';
				document.FormPaymentCalc.TxtBoxYear.value = '10';
				document.FormPaymentCalc.TxtBoxAnnlIntRate.value = '9.00';
				break;

			} 

		}
		
		function OnPriceChange(objSrc)
		{
			if(FieldValidate(objSrc.form)) 
			{ 
				if(DollarValuesRead(objSrc.value) < DollarValuesRead(document.all('TxtBoxDownPayment').value)) 
				{ 
					document.all('TxtBoxDownPayment').value = objSrc.value;
					pcDownPayPercentage(objSrc.form);
				} 
				else 
				{
					pcDownPaymentAmt(objSrc.form); 
					pcMonthlyPayment(objSrc.form);
					
				}
			} 
			else 
			{
				objSrc.value=cache;
			}
			
		}

		function OnDownPaymentAmtChange(objSrc)
		{
			if (objSrc != null)
			{
				if(objSrc.value != "" && FieldValidate(objSrc.form)) 
				{ 
					pcDownPayPercentage(objSrc.form); 
					pcMonthlyPayment(objSrc.form); 
				} 
				else 
				{
					objSrc.value=cache;
				}
			}
		}

		function OnDownPaymentPtgeChange(objSrc)
		{
			if(FieldValidate(objSrc.form))
			{ 
				pcDownPaymentAmt(objSrc.form); 
				pcMonthlyPayment(objSrc.form); 
			} 
			else 
			{
				objSrc.value=cache;
			}
		}

		function OnLoanTermMnChange(objSrc)
		{
			if(FieldValidate(objSrc.form))
			{
				pcYears(objSrc.form);
				pcMonthlyPayment(objSrc.form);
			} 
			else 
			{
				objSrc.value=cache;
			}
		}

		function OnLoanTermYrChange(objSrc)
		{
			if(FieldValidate(objSrc.form)) 
			{
				pcMonths(objSrc.form);
				pcMonthlyPayment(objSrc.form);
			} 
			else
			{
				objSrc.value=cache;
			}
		}

		function OnAirChange(objSrc)
		{
			if(FieldValidate(objSrc.form)) 
			{
				pcMonthlyPayment(objSrc.form);
			} 
			else 
			{
				objSrc.value=cache;
			}
		}
		
		function FieldValidate(pcForm) 
		{
			var ErrMsg = '';
			if(!DollarValuesCheck(document.all('TxtBoxPrice').value))
				ErrMsg += ' Valid Price \n';
			if(!DollarValuesCheck(document.all('TxtBoxDownPayment').value))
				ErrMsg += ' Valid Down Payment in Dollars \n';
			if(!FloatValuesCheck(document.all('TxtBoxDnPayPctage').value))
				ErrMsg += ' Valid Down Payment in Percent \n';
			if(!IntValuesCheck(document.all('TxtBoxMonth').value))
				ErrMsg += ' Valid Loan Term in Months \n';
			if(!FloatValuesCheck(document.all('TxtBoxYear').value))
				ErrMsg += ' Valid Loan Term in Years \n';
			if(!FloatValuesCheck(document.all('TxtBoxAnnlIntRate').value))
			{
				document.all('TxtBoxAnnlIntRate').value="9.0";
				ErrMsg += ' Valid Annual Interest Rate \n';
				document.all('TxtBoxAnnlIntRate').value="9.0";
			}
			if(ErrMsg == '')
			{
				return true;
			}
			else 
			{
				alert(' Please enter: \n' + ErrMsg);
				return false;
			}
		}
		
		function MonthlyPaymentValidate(pcForm)
		{
			var ErrMsg = '';
			if(document.all('TxtBoxDownPayment').value == "" || document.all('TxtBoxDownPayment').value == null)
			{
				pcDownPaymentAmt();
			}
			if(FieldValidate())
			{
				if(document.all('TxtBoxPayVal').value != '' && !DollarValuesCheck(document.all('TxtBoxPayVal').value))
				{	
					ErrMsg += ' Valid Monthly Payment Amount \n';
					document.all('TxtBoxPayVal').value="";
				}
				if(ErrMsg == '')
					return true;
				else 
				{
					alert(' Please enter: \n' + ErrMsg);
					return false;
				}
			}
		}

		// Check Float Values
		function FloatValuesCheck(field)
		{
			var intval = field;
			if(intval >= 0)
			{
				if(intval.indexOf(".") != -1) 
				{
					while(intval.charAt(intval.length-1) == "0")
						intval = intval.substring(0,intval.length-1);
					if(intval.charAt(intval.length-1) == ".")
						intval = intval.substring(0,intval.length-1);
				}

				if("" + parseFloat(intval) != intval)
					return false;
				else
					return true;
			}
			else
			{
				return false;
			}
		}

		//Check Integer Values
		function IntValuesCheck(field) 
		{
			var intval = field;

			if(intval >= 0)
			{
				if(isNaN(intval))
					return false;
				else 
				{
					field.value = '' + parseInt(intval)
					return true;
				}
			}
			else
			{
				return false;
			}
		}

		// Check Dollar Values
		function DollarValuesCheck(field) 
		{
			var floatval = DollarValuesRead(field);
			if(isNaN(floatval))
				return false;
			else 
			{
				str = ConvertFloatToDollar(floatval);
				field.value = str;
				return true;
			}
		}

		// Read Dollar Values
		function DollarValuesRead(field) 
		{
			var str = field;
			if (field == "")
			{
				return 0;
			}
			else
			{
				if(str.charAt(0) == "$")
					str = str.substring(1, str.length);
				
				var pos = str.lastIndexOf(",");
				while(pos != -1) 
				{
					str = str.substring(0,pos) + str.substring(pos+1, str.length);
					pos = str.lastIndexOf(",", pos);
				}
				return parseFloat(str);
			}
		}

		// Convert Float to Dollar
		function ConvertFloatToDollar(floatval) 
		{
			var str = "" + Math.round(floatval)

			pos = str.length; 
			pos -= 4;
			while(pos >= 0) 
			{
				str = str.substring(0,pos+1) + "," + str.substring(pos+1, str.length);
				pos -= 3;
			}

			return str;
		}

		// Term Months
		function pcMonths(frm) 
		{
			var tYr = parseFloat(document.all('TxtBoxYear').value);
			var tMon = Math.round(tYr * 12.0);
			tYr = parseFloat(tMon) / 12.0;
			document.all('TxtBoxYear').value = "" + tYr;
			document.all('TxtBoxMonth').value = "" + tMon;

		}

		// Term Years
		function pcYears(frm) 
		{
			var tMon = parseInt(document.all('TxtBoxMonth').value);
			var tYr = parseFloat(tMon) / 12.0;
			document.all('TxtBoxYear').value = "" + tYr;
			document.all('TxtBoxMonth').value = "" + tMon;

		}
		
		// Price or Montly Payment Call
		function pcCalcCall(frm)
		{
			var MntlyPay = document.all('TxtBoxPayVal').value;
			
			if (MntlyPay == globalMntlyPay)
			{
				if(document.all('TxtBoxPrice').value != "")
				{	
					pcMonthlyPayment(document.FormPaymentCalc);
				}
				else
				{
					alert('Please Enter Amount For Price');
				}
			}
			
			else
			{
				if(document.all('TxtBoxMonth').value !="")
				{
					pcCalcPrice(document.FormPaymentCalc);
				}
				else
				{
					alert('Please Enter Amount For Monthly Payment');
				}
			}
		}
		
		// Calc Price based on Monthly Payment
		function pcCalcPrice(frm)
		{
			if(document.all('TxtBoxPayVal').value != answer)
			{
				var AnnualInt  = parseFloat(document.all('TxtBoxAnnlIntRate').value);
				var MonthlyInt = AnnualInt / (12.0 * 100.0);
				var LenMonths  = parseInt(document.all('TxtBoxMonth').value);
				var MonthlyPay = document.all('TxtBoxPayVal').value;
			
				if(MonthlyInt == 0)
					var Principle = MonthlyPay / LenMonths;
				else
					var Principle = MonthlyPay / ( MonthlyInt / ( 1 - Math.pow((1 + MonthlyInt), -LenMonths) ) );
					Principle = Math.round(Principle * 100) / 100;
					priceVal = ConvertFloatToDollar(Principle);
					if(priceVal != "NaN")
					{
						document.all('TxtBoxPrice').value = priceVal;
					}
			}
			else
			{
			}
		}
		

		// Calc Monthly Payments
		function pcMonthlyPayment(frm) 
		{
			var Principle  = DollarValuesRead(document.all('TxtBoxPrice').value) - DollarValuesRead(document.all('TxtBoxDownPayment').value);
			var AnnualInt  = parseFloat(document.all('TxtBoxAnnlIntRate').value);
			var MonthlyInt = AnnualInt / (12.0 * 100.0);
			var LenMonths  = parseInt(document.all('TxtBoxMonth').value);
			if(MonthlyInt == 0)
				var MonthlyPay = Principle / LenMonths;
			else
				var MonthlyPay = Principle * ( MonthlyInt / ( 1 - Math.pow((1 + MonthlyInt), -LenMonths) ) );
			MonthlyPay = Math.round(MonthlyPay * 100) / 100;

			globalMntlyPay = MonthlyPay;
			monthlyVal = ConvertFloatToDollar(MonthlyPay);
			answer = monthlyVal;
			document.all('TxtBoxPayVal').value = monthlyVal;
		}

		// Calc Down Payment
		function pcDownPayment(frm) 
		{
			var AnnualInt  = parseFloat(document.all('TxtBoxAnnlIntRate').value);
			var MonthlyInt = AnnualInt / (12.0 * 100.0);
			var LenMonths  = parseInt(document.all('TxtBoxMonth').value);
			var MonthlyPay = DollarValuesRead(document.all('TxtBoxPayVal').value);
			var Principle  = DollarValuesRead(document.all('TxtBoxPrice').value) - DollarValuesRead(document.all('TxtBoxDownPayment').value);
			var OldDownPay = DollarValuesRead(document.all('TxtBoxDownPayment').value);
			var EffPrinciple;

			if(MonthlyInt == 0)
				EffPrinciple = MonthlyPay * LenMonths;
			else
				EffPrinciple = MonthlyPay * ((1 - Math.pow((1 + MonthlyInt), -LenMonths)) / MonthlyInt);

			var NewDownPay = OldDownPay + (Principle - EffPrinciple);
			document.all('TxtBoxDownPayment').value = "" + NewDownPay;
			DollarValuesCheck(document.all('TxtBoxDownPayment').value);
			pcDownPayPercentage(frm);
			pcMonthlyPayment(frm);
		}

		// Calc Down Payment %
		function pcDownPayPercentage(frm) 
		{
			var HomePrice  = DollarValuesRead(document.all('TxtBoxPrice').value);
			var DownPay = DollarValuesRead(document.all('TxtBoxDownPayment').value);
			var DownPayPerc = 100 * DownPay / HomePrice;

			if(DownPayPerc >= 0  &&  DownPayPerc <= 100) 
			{
				var DownPayPercStr = "" + DownPayPerc;

				var pos = DownPayPercStr.indexOf(".");
				if(DownPayPercStr.length > pos + 4)
					DownPayPercStr = DownPayPercStr.substring(0,pos+4);
				
				document.all('TxtBoxDnPayPctage').value = DownPayPercStr;
			}
			else if(DownPayPerc < 0) 
			{
				document.all('TxtBoxDnPayPctage').value = "0";
				pcDownPaymentAmt(frm);
			}
			//else 
			//{
			//	document.all('TxtBoxDnPayPctage').value = "10";
			//	pcDownPaymentAmt(frm);
			//}

		}

		// Calc Down Payment Amount
		function pcDownPaymentAmt(frm) 
		{
			var HomePrice  = DollarValuesRead(document.all('TxtBoxPrice').value);
			var DownPayPerc = parseFloat(document.all('TxtBoxDnPayPctage').value);
			if(DownPayPerc < 0) 
			{
				document.all('TxtBoxDnPayPctage').value = "0";
				pcDownPaymentAmt(frm);
			}
			else if(DownPayPerc > 100) 
			{
				document.all('TxtBoxDnPayPctage').value = "100";
				pcDownPaymentAmt(frm);
			}
			else 
			{
				var DownPay = HomePrice * DownPayPerc / 100;
				DownPay = ConvertFloatToDollar(DownPay);
				document.all('TxtBoxDownPayment').value = "" + DownPay;
			}
		}

		function pcSave() 
		{
			var frm = document.FormPaymentCalc;
			var CookieValAir="";
			var CookieValDPAmt = "";
			var CookieValDPPtage = "";
			var AlertMsg="";
			var expires
			
			if(document.all('CkBoxAIR').checked) 
			{
				CookieValAir+= document.all('TxtBoxAnnlIntRate').value;
				AlertMsg += "Annual Interest Rate: " + document.all('TxtBoxAnnlIntRate').value + "%\n";
			}
			if(document.all('CkBoxDP').checked) 
			{
				if(document.getElementById('RdBtnDPds').checked) 
				{
					CookieValDPAmt += DollarValuesRead(document.all('TxtBoxDownPayment').value);
					AlertMsg += "Down payment amount: $" + document.all('TxtBoxDownPayment').value + "\n";
				}

				if(document.getElementById('RdBtnDPptge').checked) 
				{
					CookieValDPPtage += document.all('TxtBoxDnPayPctage').value;
					AlertMsg += "Down payment percentage: " + document.all('TxtBoxDnPayPctage').value + "%\n";
				}
			}
			
			if((CookieValAir != "") || (CookieValDPAmt != "") || (CookieValDPPtage != ""))
			{
				expires = new Date();
				expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000));  
				document.cookie = 'AIR=' + CookieValAir + '; path=/; expires=' + expires.toGMTString();
				document.cookie = 'DPA=' + CookieValDPAmt + '; path=/; expires=' + expires.toGMTString();
				document.cookie = 'DPP=' + CookieValDPPtage + '; path=/; expires=' + expires.toGMTString();
				alert("Saved:\n" + AlertMsg);
			}
			else
				alert('Select either "Annual Interest Rate" and/or "Down Payment".');
		}

		// End of Functions