var license = '<DIV ALIGN="left"><font face="Arial, Helvetica, sans-serif" size="1">' +
        '' +
        ' ' +
        ' ' +
        '' +
        '' +
        '' +
        '' +
        '' +
        '' +
        '' +
        '';

js_version = 1.1;

// The following is something that could cause problems. But I haven't yet found a solution.
// The amortizationTable instance name is used both here and in calculator_l.html; and if 
// the same name is not used everywhere things won't work.  But it would be all too easy to  
// innocently change this name in one place and not all others...  Here we're able to assign 
// the name to a variable and use that variable everywhere. But that is not so easily done 
// in calculator_l.html...

var selector_start_date = 1985;

function clearPayment(){
    document.mtgCalcFrmV.monthlyPayment.value = "     ===>";
}

var monthNames = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

function getFourDigitYear(date_obj){
    var thisyear = date_obj.getYear();
    // Following Y2k fix should work till 3799 :-), by which time getYear() should be fully repalced by getFullYear()...
    if (thisyear < 1900){
        thisyear += 1900;
    }
    return thisyear;
}

function setFourDigitYear(date_obj, thisyear){
    // Y2k fix
    if (navigator.appName == "Microsoft Internet Explorer" && thisyear < 2000){
        thisyear = thisyear - 1900;
    }
    date_obj.setYear(thisyear);
}

function dateSelector(selectorName){
    var returnString = '<SELECT NAME="' + selectorName + 'Month">\n';
    var today = new Date();
    var thisYear = getFourDigitYear(today);
    var maxYear  = thisYear + 10;
    for (var i = 0; i < 12; i++){
        returnString += '\t\t\t\t<OPTION VALUE="' + i + '"';
        if (i == today.getMonth()) returnString += ' SELECTED';
        returnString += '>' + monthNames[i] + '</OPTION>\n';
    }
    returnString += '\t\t\t</SELECT>\n';
    if (selectorName == 'yearlyAdditional')return returnString;
    if (selectorName == 'oneAdditional'){
        maxYear = thisYear + 30;
    }else{
        returnString += '\t\t\t<SELECT NAME="' + selectorName + 'Day">\n';
        for (var i = 1; i < 32; i++){
            returnString += '\t\t\t\t<OPTION VALUE="' + i + '"';
            if (i == today.getDate()) returnString += ' SELECTED';
            returnString += '>' + i + '</OPTION>\n';
        }
        returnString += '\t\t\t</SELECT>,\n';
    }
    /*
    The following if statement was added 3/30/2005 to give the startYear SELECT object a new onChange handler.
    This was done so that the oneAdditionalYear SELECT object could be restricted to the loan term.
    */
    if (selectorName == 'start')
    {
    	returnString += '\t\t\t&nbsp;<SELECT NAME="' + selectorName + 'Year">\n';
    }
    else
    {
    	returnString += '\t\t\t&nbsp;<SELECT NAME="' + selectorName + 'Year">\n';
    }
    for (var i = selector_start_date; i <= maxYear; i++){
    /*
    The following if statement was added 3/30/2005.
    This was done so that the oneAdditionalYear SELECT object could be restricted to the loan term.
    */
    		if (selectorName == 'oneAdditional')
    		{
    			if (i >= getFourDigitYear(today))
    				{
        				returnString += '\t\t\t\t<OPTION VALUE="' + i + '"';
        				if (i == getFourDigitYear(today)) returnString += ' SELECTED';
        				returnString += '>' + i + '</OPTION>\n';
    				}
    		}
    		else
    		{
        		returnString += '\t\t\t\t<OPTION VALUE="' + i + '"';
        		if (i == getFourDigitYear(today)) returnString += ' SELECTED';
        		returnString += '>' + i + '</OPTION>\n';
    		}
    }
    returnString += '\t\t\t</SELECT>\n';
    return returnString;
}


////////////////////////////////////////////////////////////////////////////////

function isNumeric(sText){
		var ValidChars = "0123456789.";
		var IsNumber = true;
		var Char;
		
		for (i = 0; i < sText.length && IsNumber == true; i++){ 
			Char = sText.charAt(i); 
			if(ValidChars.indexOf(Char) == -1){
				IsNumber = false;
			}
		}
		return IsNumber;
	}
function validateMtgCalcVals(){
var loanamount = document.mtgCalcFrmV.loanAmount.value;
var years = document.mtgCalcFrmV.nrOfYears.value;
var rate = document.mtgCalcFrmV.interestRate.value;

   if (loanamount == "") {

		alert("Enter your \"Mortgage amount\".");
		return false;
	} else if (years == ""){
		
		alert("Enter your \"Loan term (yrs)\".");
		return false;	
	}else if (rate == ""){
		
		alert("Enter your \"Interest rate (%)\".");
		return false;	
	} 
	if (loanamount < 0){
		alert("Error: \"Mortgage amount\" must be a positive number.");
		return false;
	}
	if (years < 0){
		alert("Error: \"Loan term (yrs)\" must be a positive number.");
		return false;
	}
	if (rate < 0){
		alert("Error: \"Interest rate (%)\" must be a positive number.");
		return false;
	}
	
	if (!isNumeric(loanamount) || !isNumeric(years) || !isNumeric(rate) ){
		alert("Please make sure that all values are numeric.");
		return false;
	}
		
	
	return true;

}


