	
	
	
	function SetFocusOn(){
		document.calc.txtLoanAmount.focus()
    }


    function ResetCboMonthYear(){
		CalcTermMonthYr();
		if (document.calc.cboMonthYear.value != "zero") {
			if (document.calc.txtLoanAmount.value != "" || document.calc.txtInterestRate.value != "" || document.calc.txtLoanTerm.value != "") {
			}
		}
    }
    
	function CalcTermMonthYr() {
		var amount = document.calc.txtLoanAmount.value
		var rate = document.calc.txtInterestRate.value
		var term = document.calc.txtLoanTerm.value
		var monthYr = document.calc.cboMonthYear[document.calc.cboMonthYear.selectedIndex].value
		var flg = true
		var total
		
		// make sure the numbers are rounded
		amount = amount * 1;
		rate = rate * 1;
		term = term * 1;
																
		if (isNaN(amount)) {
             alert("Please enter a numeric value for the Loan Amount.")
             //document.calc.txtLoanAmount.value = ""
             document.calc.txtLoanAmount.focus()
             flg = false
             if (document.calc.txtInterestRate.value != "") {
				if (isNaN(rate)) {
				   document.calc.txtInterestRate.value = ""
				}
			 }
			 if (document.calc.txtLoanTerm.value != "") {
				if (isNaN(term)) {
				       document.calc.txtLoanTerm.value = ""              
				}
			 }
          }
            else {
                if (isNaN(rate)) {
                    alert("Please enter a numeric value for the Interest Rate.")
                    //document.calc.txtInterestRate.value = ""
                    document.calc.txtInterestRate.focus()
                    flg = false
                    if (document.calc.txtLoanTerm.value != "") {
						if (isNaN(term)) {
						       document.calc.txtLoanTerm.value = ""               
						}
					}
                }
                 else {
					if (isNaN(term)) {
                        alert("Please enter a numeric value for the Term.")
                        //document.calc.txtLoanTerm.value = ""
                        document.calc.txtLoanTerm.focus()
                        flg = false
                    }
                 }
             }
        
        //-- Actual Calculation     
		if (document.calc.txtLoanAmount.value != "" && document.calc.txtInterestRate.value != "" && document.calc.txtLoanTerm.value != "") {
		  if (document.calc.txtLoanTerm.value != 0 && document.calc.txtInterestRate.value != 0) {
				rate = rate /1200;
				if (monthYr == 12) {
					term = term * 12;
				}
				total = Math.pow(1 + rate,term);
				document.calc.txtPayment.value = (amount*total*rate) / (total-1);				
				document.calc.txtPayment.value = dollarFormat(document.calc.txtPayment.value);				
		  } else {
			if(document.calc.txtLoanTerm.value != 0 && document.calc.txtInterestRate.value == 0){
				if(monthYr == 12){
					term = term * 12;
				}
				document.calc.txtPayment.value = amount/term;
				document.calc.txtPayment.value = dollarFormat(document.calc.txtPayment.value);
			}else{
				document.calc.txtPayment.value = ""
			}
		  }
		} else {
			document.calc.txtPayment.value = ""
		}
    }	
    
    //-- Format dollar
		function dollarFormat(valueIn) {	      
		var formatStr = ""
		var OutDollars = ""
		var deciPos = valueIn.indexOf(".")
				
		if (deciPos == -1) 
			deciPos = valueIn.length
			var dollars = valueIn.substring(0,deciPos)
			var dollen = dollars.length
			if (dollen > 3) {
				while(dollen > 0) {
					totalDollar = dollars.substring(dollen - 3, dollen)
					if (totalDollar.length == 3) {
						OutDollars = "," + totalDollar + OutDollars
						dollen = dollen - 3
					} else {
						OutDollars = totalDollar + OutDollars
						dollen = 0
					  }					
			}
			
		if (OutDollars.substring(0,1) == ",") 
			dollars = OutDollars.substring(1,OutDollars.length)
		else
			dollars = OutDollars
					
		}
		var cents = valueIn.substring(deciPos+1,deciPos+3)
		if (cents == "")
			cents = "00"		
			var formatStr = "$"+dollars+"."+cents
		return formatStr		
		}   
         
    //-- Round number
        function round(x) {
          return Math.round(x*100)/100;        
        }
