<!--
function IsAlpha(sChar)
{
        //This function returns true if the character passed is a letter of our alphabet
        if(sChar.length != 1)
        {
                return false;
        }
        var sChar1, sChar2;
        sChar1 = sChar.toLowerCase();
        sChar2 = sChar.toUpperCase();
        
        if (sChar1 == sChar2)
        {
                return false;
        }
        else
        {
                return true;
        }
}
function IsNumer(sChar)
{
        //This function returns true if the character passed is a single digit number
        if(sChar.length != 1)
        {
                return false;
        }
        sNumbers = '0123456789';
        
        for(i=0; i<10; i++)
        {
                if(sNumbers.substr(i,1) == sChar)
                {
                        return true;
                }
        }       
        
        return false;   
}       
function numFormat(elem, lead, sep)
{
        if (elem.value == '') 
        {
                elem.value = format('0', lead, sep);
                return true;
        }
        
        var value = parseInt(cleanNumber(elem.value), 10);
        
        if (lead == '') 
        {
                if (0 > value)
                {
                        alert('You have exceeded the range for the interior size. Please check your information and try again.');
                        value = 0;
                }
                
                if (value > 99999) 
                {
                        alert('You have exceeded the range for the interior size. Please check your information and try again.');
                        value = 99999;
                }
        }
        
        if (lead == '$')
        {
                if (0 > value)
                {
                        alert('You have exceeded the range for the price. Please check your information and try again.');
                        value = 0;
                }
                if (value > 100000000) 
                {
                        alert('You have exceeded the range for the price. Please check your information and try again.');
                        value = 100000000;
                }
        }
        
        if (isNaN(value)) {
                alert('You have entered an incorrect character on this field.  Please check your information and try again.');
                elem.value = format('0', lead, sep);
                elem.focus();
                return false;
        }
        elem.value = format(value, lead, sep);
        return true;
}
function format(value, lead, sep)
{
        var strValue = new String(value);
        var len = strValue.length;
        var n;
        var strRet = '';
        var ctChar = 3 - (len%3);
        if (ctChar == 3) ctChar =0;
        for (n=0; len > n; n++) {
                if (ctChar == 3) {
                        strRet += sep;
                        ctChar = 0;
                }
                ctChar++;
                strRet += strValue.substring(n,n+1)             
        }
        if (lead == '%') {
                return strRet + lead;
        }
        else {
                return lead + strRet;
        }
}
function percentrate(elem, lead)
{
        if (elem.value == '') return true;
        
        var strRet = '';
        var value = parseFloat(cleanNumber(elem.value));
        if (0 > value) value = 0;
        if (value > 100) value = 99.999;
        if (isNaN(value)) {
                alert('You may have entered an incorrect character or exceeded the range for some information on this tab.  Please check your information and try again.');
                elem.value = '';
                elem.focus();
                return false;
        }
        var strvalue = new String(value);
        if (value > 9.9999)
        {
                if(strvalue.length > 6)
                {
                        strRet = strvalue.substr(0, 6);
                }
                else
                {
                        if(strvalue.length == 5)
                        {
                                strRet = strvalue + '0';
                        }
                        else
                        {
                                if(strvalue.length == 4)
                                {
                                        strRet = strvalue + '00';
                                }
                                else
                                {
                                        if (strvalue.length == 2)
                                        {
                                                strRet = strvalue + '.000';
                                        }
                                        else
                                        {
                                                strRet = strvalue;
                                        }
                                }
                        }
                }
        }
        else
        {
                if(strvalue.length > 5)
                {
                        strRet = strvalue.substr(0, 5);
                }
                else
                {
                        if(strvalue.length == 4)
                        {
                                strRet = strvalue + '0';
                        }
                        else
                        {
                                if(strvalue.length == 3)
                                {
                                        strRet = strvalue + '00';
                                }
                                else
                                {
                                        if (strvalue.length == 1)
                                        {
                                                strRet = strvalue + '.000';
                                        }
                                        else
                                        {
                                                strRet = strvalue;
                                        }
                                }
                        }
                }
        }
        elem.value = strRet + lead;
        return true;
}
                
function replace(szBuf, szFind, szReplace, lStart)
{
        var lFind = 0;
        if (!lStart) lStart = 0;
        
        while (lFind != -1) {
                lFind = szBuf.indexOf(szFind, lStart);
                if (lFind != -1) {
                        szBuf = szBuf.substring(0,lFind) + szReplace + szBuf.substring(lFind + szFind.length);
                        lStart = lFind + szReplace.length;
                }
        }
        return szBuf;
}
function cleanNumber(strNum)
{
        if (!strNum) return strNum;
        strNum = replace(strNum, '$', '', 0);
        strNum = replace(strNum, ',', '', 0);
        strNum = replace(strNum, '%', '', 0);   
        return strNum;
}
//-->
//<!--
function pmt(rate, nper, pv, fv)
{
        var rVal;
        if (rate==0)
                rVal=-(fv + pv)/nper;
        else {
                ir=Math.pow(1 + rate,nper);
                rVal=-((rate * (fv + ir * pv))/(ir-1));
        }
        return rVal;
}
function getRate(rate)
{
        //calculate the interest rate
        var vRate;
        vRate = (parseFloat(rate.substring(rate.lastIndexOf("..")+2,rate.length))/100)/12;
        return vRate;
}
function getTerm(term)
{
        //calculate the term of the interest interest
        var vTerm;
        vTerm = parseInt(term.substring(0,term.indexOf(".")))*12;
        return vTerm;
}
function reformat (expr,decplaces)
{
        var str = "" + Math.round(eval(expr)*Math.pow(10,decplaces));
        while (str.length <=decplaces)
        {
                str="0" + str;
        }
        var decpoint = str.length - decplaces;
        var strUnit= str.substring(0,decpoint);
        var strTemp;
        var strUnitDisp="";
        var strPoint = str.substring(decpoint,str.length);
        while (strUnit.length>3)
        {
                strUnitDisp = "," + strUnit.substring(strUnit.length - 3,strUnit.length)+strUnitDisp;
                strUnit = strUnit.substring(0,strUnit.length - 3);              
        }       
        if (strUnit.length>0)
                strUnitDisp = strUnit + strUnitDisp;
        else
                strUnitDisp = strUnitDisp.substring(1,strUnit.length);
        
        return strUnitDisp;
}
function initLoan(loan)
{
	return "$" + reformat(loan,0);
}
function initDown(down)
{
	return "$" + reformat(down,0);
}
function initPayment()
{       
        // this is to calculate the monthly payment
        var lrate,lterm,pay,down;
	lrate=parseFloat(rate);
	lterm=parseFloat(term);
        if (!(document.lf.ap.value=="") && !(document.lf.ap.value==null))       
	{
		pay=getCleanNumber(document.lf.ap.value);
		down=getCleanNumber(document.lf.dp.value);
		if(pay - down <0)
                {
                        alert("To calculate a payment, you must enter a down payment that is less than the asking price.");
                        return "bad1";
                }
	        return "$" + reformat(-pmtCalc(rate,term,pay-down,0),0);
	}
	return "bad2";
}       
function calcPayment(vthis)
{       
        // this is to calculate the monthly payment
        var lrate,lterm;
        if (vthis.name!="ir")
        {
                if (!(vthis.value=="") && !(vthis.value == null))
                        numFormat(vthis,'$',',');
                        
                lrate=parseFloat(rate);
                lterm=parseFloat(term);
        }
        else
        {
                lrate = parseFloat(getRate(document.forms.lf.ir[document.lf.ir.selectedIndex].value));
                lterm = parseFloat(getTerm(document.forms.lf.ir[document.lf.ir.selectedIndex].value));
                
                rate = lrate;
                term = lterm;
        }
        if (!(document.lf.ap.value=="") && !(document.lf.ap.value==null))       
        {
                if(getCleanNumber(document.lf.ap.value)-getCleanNumber(document.lf.dp.value) <0)
                {
                        alert("To calculate a payment, you must enter a down payment that is less than the asking price.");
                        vthis.value = '';
                        vthis.focus();
                        return false;
                }
                document.lf.ep.value = "$" + reformat(-pmtCalc(rate,term,getCleanNumber(document.lf.ap.value)-getCleanNumber(document.lf.dp.value),0),0);
        }
        else
                return false;
}       
function getCleanNumber(nVal)
{
        //convert field value to numeric value
        if(nVal != "")
        {
                nVal = nVal.replace(/\$/,"");
		nVal = nVal.replace(/,/gi,"");
                if(isNaN(parseFloat(nVal)))
                        nVal = "0";
        }
        else
        {
                nVal = "0";
        }
                
        return parseFloat(nVal);
}
function pmtCalc(rate, nper, pv, fv)
{       
        //calculate payment (called by payment calculation subrouting)
        var rVal;
        if (isNaN(rate) || isNaN(nper))
                return ""
        
        if (rate==0)
        {
                rVal=-(fv + pv)/nper;
        }
        else
        {
                var ir;
                ir = Math.pow(1+rate,nper);
                rVal=-((rate * (fv + ir * pv))/(ir-1));
        }
                
        return rVal;
}
//-->

//<!-- 
var rate,term;
rate = getRate('30.FRM..6.75');
term = getTerm('30.FRM..6.75');
//-->
