﻿function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address");
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address");
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address");
		    return false;
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address");
		    return false;
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address");
		    return false;
		 }
 		 return true;					
	}
	
	
function formValidation(FormName){

	var emailID = document.getElementById("email");

	if (document.forms[FormName].location!=null)
	if(document.forms[FormName].location.value == ""){
		alert('Please enter your location.');
		document.forms[FormName].location.focus();
		return false;
	}
	
	if(document.forms[FormName].house2!=null){
	if(document.forms[FormName].house2.checked){
		document.getElementById("house").value = "House";
	}
	else{
		document.getElementById("house").value = "";
	}
	}
	
	if(document.forms[FormName].condo2!=null){
	if(document.forms[FormName].condo2.checked){
		document.getElementById("condo").value = "Condo";
	}
	else{
		document.getElementById("condo").value = "";
	}
	}
	
	if(document.forms[FormName].apartment2!=null){
	if(document.forms[FormName].apartment2.checked){
		document.getElementById("apartment").value = "Apartment";
	}
	else{
		document.getElementById("apartment").value = "";
	}
	}
	
	if(document.forms[FormName].townhome2!=null){
	if(document.forms[FormName].townhome2.checked){
		document.getElementById("townhome").value = "Townhome";
	}
	else{
		document.getElementById("townhome").value = "";
	}
	}
	
	if(document.forms[FormName].house2!=null && document.forms[FormName].condo2!=null && document.forms[FormName].apartment2!=null && document.forms[FormName].townhome2!=null)
	if(!(document.forms[FormName].house2.checked || document.forms[FormName].condo2.checked || document.forms[FormName].apartment2.checked || document.forms[FormName].townhome2.checked)){
		alert('Please select a property type .\n');					
		return false;
	}

	if(document.forms[FormName].firstName!=null)
	if(document.forms[FormName].firstName.value == ""){
		alert('Please enter your first name.');
		document.forms[FormName].firstName.focus();
		return false;
	}
	
	if(document.forms[FormName].lastName!=null)
	if(document.forms[FormName].lastName.value == ""){
		alert('Please enter your last name.');
		document.forms[FormName].lastName.focus();
		return false;
	}
	
	if(document.forms[FormName].phone!=null)
	if(document.forms[FormName].phone.value == "" ){
		alert('Please enter your phone.');
		document.forms[FormName].phone.focus();
		return false;
	}
	if (echeck(document.forms[FormName].email.value)==false){
		document.forms[FormName].email.focus();
		return false;
	}
/*-------------------------------------------------------------------------------*/	
	/*career-apply today*/	
/*-------------------------------------------------------------------------------*/
    if(document.forms[FormName].address!=null)
	if(document.forms[FormName].address.value == ""){
		alert('Please enter your address.');
		document.forms[FormName].address.focus();
		return false;
	}
	
	if(document.forms[FormName].city!=null)
    if(document.forms[FormName].city.value == ""){
		alert('Please enter your city.');
		document.forms[FormName].city.focus();
		return false;
	}
	
	if(document.forms[FormName].province!=null)
	if(document.forms[FormName].province.value == ""){
		alert('Please enter province.');
		document.forms[FormName].province.focus();
		return false;
	}
	
	if(document.forms[FormName].postalCode!=null)
	if(document.forms[FormName].postalCode.value == ""){
		alert('Please enter your postal code.');
		document.forms[FormName].postalCode.focus();
		return false;
	}
	
	if(document.forms[FormName].daytimePhone!=null)
	if(document.forms[FormName].daytimePhone.value == ""){
		alert('Please enter your daytime phone.');
		document.forms[FormName].daytimePhone.focus();
		return false;
	}
	
	if(document.forms[FormName].status!=null)
	if(document.forms[FormName].status.value == "Select One"){
		alert('Please select your current status.');
		document.forms[FormName].status.focus();
		return false;
	}
	
	if(document.forms[FormName].officeLocation!=null)
	if(document.forms[FormName].officeLocation.value == "Select One"){
		alert('Please select Macdonald Realty office you are interested in.');
		document.forms[FormName].officeLocation.focus();
		return false;
	}
	
	if(document.forms[FormName].heardSource!=null)
	if(document.forms[FormName].heardSource.value == "Select One"){
		alert('Please select How you heard of Macdonald Realty.');
		document.forms[FormName].heardSource.focus();
		return false;
	}
	
	if(document.forms[FormName].subscribe2!=null){
	if(document.forms[FormName].subscribe2.checked){
		document.getElementById("subscribe").value = " I'd like to subscribe Macdonald Realty career information";
	}
	else{
		document.getElementById("subscribe").value = " ";
	}
	}
	
	if(document.forms[FormName].supportsHTML2!=null){
	if(document.forms[FormName].supportsHTML2.checked){
		document.getElementById("supportsHTML").value = "My email program supports HTML";
	}
	else{
		document.getElementById("supportsHTML").value = " ";
	}
	}
	
	return true;
	
}	

function popwindow(exweb){
    if (exweb=="luxuryportfolio")
        window.open('http://www.luxuryportfolio.com','popwin','height=700,width=950,toolbar=no,resizable=yes,scrollbars=yes');
	if (exweb=="luxuryrealestate")
	    window.open('http://www.luxuryrealestate.com','popwin','height=700,width=975,toolbar=no,resizable=yes,scrollbars=yes');
	if (exweb=="bccancerfoundation")
	    window.open('http://www.bccancerfoundation.com/cms/','popwin','height=780,width=790,toolbar=no,resizable=yes,scrollbars=yes');
	if (exweb=="mortgagePage")
	    window.open('http://www.origingroup.ca/deal_app.php?adv=40','popwin','height=2000,width=950,toolbar=no,resizable=yes,scrollbars=yes');
	if (exweb=="commercial")
	    window.open('http://www.macdonaldcommercial.com/','popwin','height=780,width=790,toolbar=no,resizable=yes,scrollbars=yes');
	if (exweb=="rental")
	    window.open('http://www.macdonaldrental.com','popwin','height=780,width=790,toolbar=no,resizable=yes,scrollbars=yes');
}


/*-------------------------------------------------------------------------------*/
/* Calculater---amo.js */
/*-------------------------------------------------------------------------------*/
function compAmort(LIST,INRATE,PAYMENTt,FREQ){



	var form = document.paycalc;

	var MTG = form.list.value;

	var DOWN = form.down.value;

	LIST = (MTG - DOWN);

	var AMORT = form.amortperiod.value;

	var INRATE = form.intrate.value/100;

	var RATE = form.intrate.value;

	var COMPOUND = 2;

	if(FREQ == 2){

		var returnpay = PAYMENTt * 2.0;

	}

	if(FREQ == 3){

		var returnpay = PAYMENTt * 2.0;

	}

	if(FREQ == 4){

		var returnpay = PAYMENTt * 4.0;

	}

	var wholecom = findAmort(1,1,LIST,INRATE,COMPOUND,returnpay,FREQ);

	var solvecom = findAmort(wholecom,.001,LIST,INRATE,COMPOUND,returnpay,FREQ);

	if(FREQ == 2){

		form.semiMonth.value= round_up(solvecom,2);

		return form.semiMonth.value;

	}

	if(FREQ == 3){

		form.AccelBi.value= round_up(solvecom,2);

		return form.AccelBi.value;

	}

	if(FREQ == 4){

		form.AccelWeek.value= round_up(solvecom,2);

		return form.AccelWeek.value;

	}



}



function findAmort(q,n,LIST,RATE,COMPOUND,PAYMENTAG,FREQ){



	var compound = COMPOUND / 12;

	var yrRate = RATE / COMPOUND;

	var rdefine = Math.pow((1.0 + yrRate),compound) - 1.0;

	var newpay = 1000000000;

	if (FREQ == 2) {

		var p = 12;

	}

	if (FREQ == 3) {

		var p = 13;

	}

	if (FREQ == 4) {

		var p = 13;

	}

	for(i = q; newpay >= PAYMENTAG; i = i + n){

		var monTime = i * p;

		var comfact = Math.pow((1.0 + rdefine),monTime);

		var newpay = (LIST * rdefine * comfact) / (comfact - 1.0);

	}

	return (i - n - n);

}



function compPay(){

	var form = document.paycalc;

	var MTG = form.list.value;

	var DOWN = form.down.value;

	var LIST = MTG - DOWN;

	var AMORT = form.amortperiod.value;

	var INRATE = form.intrate.value / 100;

	if (form.list.value != "" && form.intrate.value != "" && form.amortperiod.value != "") {

		var compound = 2 / 12;

		var monTime = AMORT * 12;

		var yrRate = INRATE / 2;

		var rdefine = Math.pow((1.0 + yrRate),compound) - 1.0;

		var comfact = Math.pow((1.0 + rdefine),monTime);

		var PAYMNT = (LIST * rdefine * comfact)/  (comfact - 1.0);

		var rPAYMENT = PAYMNT;

		var rPAYMENT2 = PAYMNT / 2.0;

		var rPAYMENT3 = PAYMNT / 4.0;

		form.payMonth.value = round_up(rPAYMENT,2);

		form.paysemiMonth.value = round_up(rPAYMENT2,2);

		form.payAccelBi.value = round_up(rPAYMENT2,2);

		form.payAccelWeek.value = round_up(rPAYMENT3,2);

		form.Month.value = form.amortperiod.value * 1.0;                                                                                                                                                                          

		form.semiMonth.value = compAmort(LIST,INRATE,rPAYMENT2,2);

		form.AccelBi.value = compAmort(LIST,INRATE,rPAYMENT2,3);

		form.AccelWeek.value = compAmort(LIST,INRATE,rPAYMENT3,4);

	}

}



function check(a){

   	var pest = 0;

   	var b = "";

	for(i = 0;i <= a.length;i++){

		var u = a.charAt(i);

      	if((u >= "0" && u <= "9") || u == "."){

        	if(u == "."){

        		var pest = pest + 1;

        		if(pest == 2){

					break;

				}

			}

			var b = b + u;

		}

	}

	return b;

}



function add_up(a){ 

	a.value = check(a.value);

}



function round_up(n,num){

	if(n > 0){

		var nums = num * 1.0;

		if(num == 2){

			pennies = n * 100;

		}

		if(num == 3){

			pennies = n * 1000;

		}

		pennies = Math.round(pennies);

		strPennies = "" + pennies;

		len = strPennies.length;

		return strPennies.substring(0, len - nums) + "." + strPennies.substring(len - nums, len);

	} else{

		return 0;

	}

}



function check_num(quest,input, min, max, msg){

    var str = input.value;

    for (var i = 0; i < str.length; i++) {

        var ch = str.substring(i, i + 1)

        if ((ch < "0" || "9" < ch) && ch != '.') {

            alert(msg);

            return false;

        }

    }

    if(input.value != ""){

    	var num = 0 + str

    	if (num < min || max < num) {

    		var sendn = msg;

    		var sendq = "You have entered " + input.value + ". Please enter a number between " + min + " and " + max + ".";

			alert(sendn + "\n" + sendq);

        	return false;

    	}

    	input.value = str;

    	return true;

    }

}



function THEcompute(quest,input,min,max,msage){

    add_up(input);

	check_num(quest,input,min,max,msage);

} 



function compu(form){

	var testNum = 0;

	if((document.paycalc.list.value == null || document.paycalc.list.value.length == 0) || (document.paycalc.list.value * 1.0 < 10000 || document.paycalc.list.value * 1.0 > 1000000)){

		alert('List price:' + '\n' + 'Please enter a number between 10,000 and 1,000,000.');

		testNum = 1;

	}

	if((document.paycalc.intrate.value == null || document.paycalc.intrate.value.length == 0)|| (document.paycalc.intrate.value * 1.0 < 2 || document.paycalc.intrate.value * 1.0 > 25)){

		alert('Rate:' + '\n' + 'Please enter a number between 2.0 and 25.0.');

		testNum = 1;

	}

	if((document.paycalc.amortperiod.value == null|| document.paycalc.amortperiod.value.length == 0)|| (document.paycalc.amortperiod.value * 1.0 < 1|| document.paycalc.amortperiod.value * 1.0 > 40)){

		alert('Amort. period:' + '\n' + 'Please enter a number between 1 and 40.');

		testNum = 1;

	}

	if(testNum == 0){

		compPay();

	}

}



function computeForm(){

	if(navigator.appVersion.substring(0,3) == 2.0 &&  navigator.appName.substring(0,8) == "Netscape" && navigator.appVersion.indexOf("Macintosh") >= 0){

        setTimeout("compute(document.forms['paycalculator'])",200);

	}else{

		compute(document.forms['paycalculator']);

	}

}

/*-------------------------------------------------------------------------------*/
/* Calculater-aff.js */
/*-------------------------------------------------------------------------------*/
function add_up(a){ 
   	a.value = THEcheck(a.value);
}

function THEcheck(a){
	var pest = 0;
   	var b = "";
   	for(i = 0;i <= a.length; i++){
   		var u = a.charAt(i);
      	if((u >= "0" && u <= "9") || u == "."){
        	if(u == "."){
        		var pest = pest + 1;
        		if(pest == 2){
					break;
				}
			}
			var b = b + u;          
		}
	}
	return b;
}

function test_num(question_num,input, min, max, msg){
    var str = input.value;
    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
            alert(msg);
            return false;
        }
    }
    if(input.value != ""){
    	var num = 0 + str;
    	if (num < min || max < num) {
 			var sendn = msg;
    		var sendq = "You have entered " + input.value + ". Please enter a number between " + min + " and " + max + ".";
  			alert(sendn + "\n" + sendq);
			return false;
    	}
    	input.value = str;
    	return true;
	} 
}

function THEcomputeField(question_num,input,min,max,msage){
	add_up(input); 
	test_num(question_num,input,min,max,msage);     
}        

function round_up(n){
	if(n > 0){
		pennies = n*100;
		pennies = Math.round(pennies);
		strPennies = "" + pennies;
		len = strPennies.length;
		return strPennies.substring(0, len - 2) + "." + strPennies.substring(len -2, len);
	}else return 0;
}

function THEcalcMax(){
	var RATE = document.maxcalc.rate.value / 100;
	var income = document.maxcalc.totinc.value;
	var tax = document.maxcalc.protax.value;
	var heat = document.maxcalc.proheat.value * 12;
	var debt = document.maxcalc.debt.value * 12;
	var fees = document.maxcalc.fees.value * 12;
	var compound = 2 / 12;
	var monTime = 25 * 12;
	var yrRate = RATE / 2;
	var rdefine = Math.pow((1.0 + yrRate),compound) - 1.0;
	var purchcompound = Math.pow((1.0 + rdefine),monTime);
	var maxgdsr = .32;
	var maxtdsr = .42;
	var GDSPAY = (maxgdsr * income) - tax - heat - fees;
	var TDSPAY = (maxtdsr * income) - tax - heat - fees - debt;
	var PAYMENT = (GDSPAY < TDSPAY) ? GDSPAY / 12 : TDSPAY / 12;
	var MORTGAGE = (0 + ((PAYMENT * (purchcompound - 1.0)) / rdefine)) / purchcompound;
	document.maxcalc.amt.value = round_up(MORTGAGE);
	document.maxcalc.pay.value = round_up(PAYMENT);
	return;
}

function StringArray(n){
	this.length = n;
	for (var i = 1; i <= n; i++)
	this[i] = '' 
	return this
}

maxtitle = new StringArray(6);
maxtitle['A'] = 'Annual income';
maxtitle['B'] = 'Annual property taxes';
maxtitle['C'] = 'Monthly heating cost';
maxtitle['D'] = 'Other monthly debt pymnts';
maxtitle['E'] = 'Mortgage interest rate';
maxtitle['F'] = 'Monthly condo fees';

/*-------------------------------------------------------------------------------*/
/*calculator-rvb1.js */
/*-------------------------------------------------------------------------------*/
rb = 'rentbuydata';
numDays = 60;  /* days until cookie expires (eg. 183 days = 6 months) */

function doSum(a){ 
	a.value = check(a.value);
}

function check(a) {
	var b = "";
   	for(i = 0; i <= a.length; i++){
		var u = a.charAt(i);
      	if((u >= "0" && u <= "9") || u == "." ){ 
   			var b = b + u;
		}
   	}
	return b;
}

function checkNumber(quest,input, min, max, msg){
    var str = input.value;
    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
            alert(msg);
            return false;
        }
    }
    if(input.value != "") {
    	var num = 0 + str
    	if (num < min || max < num) {
    		var sendn = msg + ":";
    		var sendq = "You have entered " + input.value + ". Please enter a number between " + min + " and " + max + ".";
  			fixpro(sendn,sendq);
        	return false;
    	}
    	input.value = str;
    	return true;
    }
}

function computeField(quest,input,min,max,msage){
// calls upon the function which calculates the results of the entered data.  
// For example - Mortgage Payment, GDS and TDS ratios, and Loan to 
// Value. This function is executed everytime a value is changed in a field.
	doSum(input);
	if (input.value != null && input.value.length != 0)
	input.value = "" + eval(input.value);
	checkNumber(quest,input,min,max,msage); 
}        

function roundPen(n){
	if(n > 0){
		pennies = n * 100;
		pennies = Math.round(pennies);
		strPennies = "" + pennies;
		len = strPennies.length;
		return strPennies.substring(0, len - 2) + "." + strPennies.substring(len -2, len);
	} else { 
		return 0;
	}
}

function calcMax(){
	var error = 0;
	if((document.rentcalc.monpay.value == null || document.rentcalc.monpay.value.length == 0) || (document.rentcalc.monpay.value < 200 || document.rentcalc.monpay.value > 10000)){
		error = 1;
		fixpro('Monthly Payment:','Please enter a number between 200 and 10000.');
	}
	if (error == 0) {
		if ((document.rentcalc.downp.value == null || document.rentcalc.downp.value.length == 0) || (document.rentcalc.downp.value < 2000 || document.rentcalc.downp.value > 1000000)){
			error = 1;
			fixpro('Downpayment:','Please enter a number between 2000 and 1000000.');
		}
	}
	if (error == 0) {
		if ((document.rentcalc.protax.value == null || document.rentcalc.protax.value.length == 0) || (document.rentcalc.protax.value < 300 || document.rentcalc.protax.value > 10000)){
			var error = 1;
			fixpro('Property Taxes:','Please enter a number between 300 and 10000.');
		}
	}
	if (error == 0) {
		if ((document.rentcalc.rate.value == null || document.rentcalc.rate.value.length == 0) || (document.rentcalc.rate.value < 2  || document.rentcalc.rate.value > 25)){
			var error = 1;
			fixpro('Interest Rate:','Please enter a number between 2 and 25.');
		}
	}
	if (error == 0) {
		if(document.rentcalc.incr.selectedIndex == 0){
			var error = 1;
			fixpro('Home Value Increase:','You have not answered this question, click on the \'Select\' button to choose your option.');
		}
	}
	if (error == 0) {
		if ((document.rentcalc.rent.value < 0  || document.rentcalc.rent.value.length == 0) || (document.rentcalc.rent.value < 0  || document.rentcalc.rent.value > 5000)){
			var error = 1;
			fixpro('Monthly Rent:','Please enter a number between 0 and 5000.');
		}
	}
	if (error == 0) {
		if(document.rentcalc.compare.selectedIndex == 0){
			var error = 1;
			fixpro('Years of Comparison:','You have not answered this question, click on the \'Select\' button to choose your option.');
		}
	}
	if (error == 0) {     
		var RATE = document.rentcalc.rate.value / 100;
		var downp = document.rentcalc.downp.value * 1.0;
		var tax = document.rentcalc.protax.value;
		var incr = document.rentcalc.incr[document.rentcalc.incr.selectedIndex].value;
		var monpay = document.rentcalc.monpay.value;
		var rent = document.rentcalc.rent.value;
		var compare = document.rentcalc.compare[document.rentcalc.compare.selectedIndex].value;
		var expire = new Date ();
		expire.setTime (expire.getTime() + (numDays * 24 * 3600000));/* 2 months */
		var rbData = " ";
		var rbData = rbData + '`' + RATE + '`' + downp + '`' + tax + '`' + incr + '`' + monpay + '`' + rent + '`' + compare;
		document.cookie = rb + "=" + escape(rbData) +"; expires=" + expire.toGMTString()+"; path=/" ;
		if(versTest() == true || nineTest() == true){       
        	sumW = window.open('rentvsbuy_summary.html','Results','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=550,height=300');
        	if(navigator.appName.substring(0,8) == "Netscape"){
                sumW.focus();
        	}
		} else{
			location.href='rentvsbuy_summary.html';
		}
	}
}

function winopen(name){
	var linkit = "help/" + name;
	if(versTest() == true || nineTest() == true){       
		qc = window.open(linkit,'helpscreen','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=250,height=180');
		if(navigator.appName.substring(0,8) == "Netscape"){
			qc.focus();
		}
	} else {
		location.href = linkit;
	}
}
 
function StringArray(n){
	this.length = n;
	for (var i = 1; i <= n; i++)
	this[i] = '' 
	return this
}

function versTest(){
	var one = '';
	var two = '';
	if((navigator.appName.substring(0,8) == "Netscape" && (navigator.appVersion.substring(0,3) == "3.0" ||  navigator.appVersion.substring(0,3) == "4.0"))){
		var one = 'true';
	}
	if((navigator.appName.substring(0,9) == "Microsoft" && navigator.appVersion.substring(0,3) == "3.0" && navigator.appVersion.indexOf("Macintosh") >= 0)){
		var two = 'true';
	}
	if(one == 'true' || two == 'true' || (navigator.appName.substring(0,9) == "Microsoft" && navigator.appVersion.indexOf("MSIE 3.0") >= 0 && navigator.appVersion.indexOf("Windows 3.1") >= 0)){
		return true;
	} else {
		return false;
	}
}

/* tests if version is msie 3.0 for mac */

function msTest(){
	if(navigator.appName.substring(0,9) == "Microsoft" && (navigator.appVersion.substring(0,3) == "3.0" && navigator.appVersion.indexOf("Macintosh")>=0)){
		return true;
	} else {
		return false;
	}
}

function nineTest(){
	if(navigator.appName.substring(0,9) == "Microsoft" && (navigator.appVersion.substring(0,3) == "3.0" || navigator.appVersion.indexOf("MSIE 3.0") >= 0) && (navigator.appVersion.indexOf("Macintosh") == -1 || navigator.appVersion.indexOf("Windows 3.1") == -1)) {
		return true;
	} else {
		return false;
	}
}

function StringArray(n){
	this.length = n;
	for (var i = 1; i <= n; i++)
	this[i] = '' 
	return this
}

function browTest(){
	if((navigator.appVersion.substring(0,3) == 3.0 || navigator.appVersion.substring(0,3) == 4.0)&& navigator.appName.substring(0,8)=="Netscape"){
        return true;
	} else{
		return false;
	}
}

function fixpro(n,q){
	if(versTest() == true){
		if(msTest() == true){
			var winNam = '';
		} else{
			var slash = location.href.lastIndexOf("/")+1;
			var filNam = location.href.substring(0,slash);
			var winNam = filNam + 'empty.asp';
		}
		fix = window.open(winNam,'FIX','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=300,height=100');
		if(navigator.appName.substring(0,8) == "Netscape"){
			fix.focus();
		}
		fix.document.write('<html>\n<head>\n<title>Calculators</title>');
		fix.document.write('</head>\n<body bgcolor="#ffffff"><form name="fixer">');
		fix.document.write('' + n + '<p>' + q + '<p>');
		fix.document.write('<center><input type="button" value="OK" onclick="self.close()">');
		fix.document.write('</center></form>\n</body>\n</html>');
		fix.document.close();
	} else{
		alert(n + '\n' + q)
	}
}


/*-------------------------------------------------------------------------------*/
/* calculator-pmf1.js */
/*--------------------------------------------------------------------------------*/
pd = 'paydata'; /* saving calculator data */
numDays = 60;  /* days until cookie expires (eg. 183 days = 6 months) */

/* function that adds commas to the currency value (i.e. $1000000.00 -> $1,000,000.00) */

function addCommas(currencyValue){
	currencyValue = "" + currencyValue;
	var dollars = 0;
	var cents = "";
	if (currencyValue.indexOf(",") != -1){
		return currencyValue;
	} else if (currencyValue.indexOf(".") != -1 ){
		dollars = currencyValue.substring(0,currencyValue.indexOf("."));
		cents = currencyValue.substring(currencyValue.indexOf("."),currencyValue.length);
	} else if (currencyValue > 0){
		dollars = currencyValue;
	} else {
		return currencyValue;
	}
	var returnValue = "";
	for (var i=1;i<=dollars.length;i++){
		if (i % 3 == 1 && i != 1){
			returnValue = "," + returnValue;
		}
		returnValue = dollars.charAt(dollars.length - i) + returnValue;
	}
	returnValue += cents;
	return returnValue;
}

/*  the following two functions check that all numeric values are real number 
and remove double decimals */

function check(a){
   	var pest = 0;
   	var b = "";
   	for(i = 0; i <= a.length; i++){
   		var u = a.charAt(i);
      	if((u >= "0" && u <= "9") || u == "."){
        	if(u == "."){
        		var pest = pest + 1;
        		if(pest == 2){
					break;
				}
			}
			var b = b + u;
		}
	}
	return b;
}

function doSum(a){
	a.value = check(a.value);
}

/* tests versions for which will support pop up windows */
function versTest(){
	var one = '';
	var two = '';
	if((navigator.appName.substring(0,8)=="Netscape" && (navigator.appVersion.substring(0,3) == "3.0" ||  navigator.appVersion.substring(0,3) =="4.0"))){
		var one='true';
	}
	if((navigator.appName.substring(0,9) == "Microsoft" && navigator.appVersion.substring(0,3) == "3.0" && navigator.appVersion.indexOf("Macintosh")>=0)){
		var two='true';
	}
	if(one=='true' || two=='true' || (navigator.appName.substring(0,9) == "Microsoft" && navigator.appVersion.indexOf("MSIE 3.0")>=0 && navigator.appVersion.indexOf("Windows 3.1")>=0)){
		return true;
	}else{
		return false;
	}
}

/* tests if version is msie 3.0 for mac */
function msTest(){
	if(navigator.appName.substring(0,9) == "Microsoft" && (navigator.appVersion.substring(0,3) == "3.0" && navigator.appVersion.indexOf("Macintosh")>=0)){
		return true;
	}else{
		return false;
	}
}

function nineTest(){
	if(navigator.appName.substring(0,9) == "Microsoft" && (navigator.appVersion.substring(0,3)=="3.0" || navigator.appVersion.indexOf("MSIE 3.0")>=0) && (navigator.appVersion.indexOf("Macintosh")==-1 || navigator.appVersion.indexOf("Windows 3.1")== -1)){
		return true;
	}else{
		return false;
	}
}

/* opens pop up window to display validation messages in netscape 3.0 and 4.0 */

function fixpro(n,q){
	if(versTest() == true){
		if(msTest() == true){
			var winNam = '';
		}else{
			var slash = location.href.lastIndexOf("/")+1;
			var filNam = location.href.substring(0,slash);
			var winNam = filNam+'empty.asp';
		}
		fix = window.open(winNam,'FIX','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=300,height=100');
		if(navigator.appName.substring(0,8) == "Netscape"){
			fix.focus();
      	}
		fix.document.write('<html>\n<head><title>Pay Your Mortgage Off Faster</title>');
		fix.document.write('</head>\n<body bgcolor="#ffffff"><form name="fixer">');
		fix.document.write(n + '<p>' + q + '<p>');
		fix.document.write('<center><input type=button value="OK" onclick="self.close()">');
		fix.document.write('</center></form>\n</body>\n</html>');
		fix.document.close();
	}else{
		alert(n+'\n'+q)
	}
}

/* function confirms that the value entered into a field falls within 
the pre-determined minimum and maximum values, and displays an error 
message with the allowable numeric range for the field data in a pop 
up validation window */

function checkNumber(quest,input, min, max, msg){
	var str = input.value;
    for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
  			alert(msg);
            return false;
        }
    }
    if(input.value != ""){
    	var num = 0 + str;
    	if (num < min || max < num){
    		var sendn = msg + ":";
    		var sendq = "You have entered " + input.value + ". Please enter a number between " + min + " and " + max + ".";
  			fixpro(sendn,sendq);
        	return false;
    	}
    	input.value = str;
    	return true;
    }
}

/* calls upon the functions to determine if the numbers entered are valid 
and to calculate the results of the entered data for example - mortgage 
payment, gds and tds ratios, and loan to value. this function is executed 
everytime a value is changed in a field */

function computeField(quest,input,min,max,msage){
	doSum(input);
	return (checkNumber(quest,input,min,max,msage));
}

/* returns the selected index value of select lists in the calculator to be 
used in calculations */

function getIndex(n){
	return n.selectedIndex;
}

function calcRdefine(intrate,compound, freq){
	return Math.pow((1.0 + ((intrate / 100) / compound)),(compound/freq)) - 1.0;
}

function calcBal(mortgage,intrate,compound,freq,payment,term){
	rdefine = calcRdefine(intrate,compound, freq);
	return (mortgage * (Math.pow((1.0 + rdefine),(term)))) -  ((payment * ((Math.pow((1.0 + rdefine),(term))) - 1.0))/rdefine);
}

/* rounds off monetary numbers to two decimals (pennies) */

function roundPen(n){
	if(n > 0){
		pennies = n * 100;
		pennies = Math.round(pennies);
		strPennies = "" + pennies;
		len = strPennies.length;
		return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
	}else{ 
		return 0;
	}
}

/* this function calculates the loan to value ratio */

function LTVcalc(MORTGAGE, MORTGAGE2, APPRAISE){
	return (MORTGAGE/APPRAISE) + (MORTGAGE2/APPRAISE);
}

function Ratios(PAY1, PAY2, HEAT, TAX, DEBT, INCOME){
	return (PAY1/INCOME)+(PAY2/INCOME)+(HEAT/INCOME)+(TAX/INCOME)+(DEBT/INCOME);
}

/* this function calculates the monthly mortgage payment based on the user's input */

function calcPay(MORTGAGE, AMORTYEARS, INRATE, COMPOUND, FREQ){
	var compound = COMPOUND / 12;
	var monTime = (AMORTYEARS * 12);
	var RATE = (INRATE * 1.0) / 100;
	var yrRate = RATE / COMPOUND;
	var rdefine = Math.pow((1.0 + yrRate),compound) - 1.0;
	var PAYMENT = (MORTGAGE * rdefine * (Math.pow((1.0 + rdefine),monTime))) / ((Math.pow((1.0 + rdefine),monTime)) - 1.0);
	if(FREQ == 12){
        return PAYMENT;
	}
	if(FREQ == 26){
        return PAYMENT / 2.0;
	}
	if(FREQ == 52){
        return PAYMENT / 4.0;
	}
	if(FREQ == 24){
        var compound2 = COMPOUND/FREQ;
        var monTime2 = (AMORTYEARS * FREQ);
        var rdefine2 = Math.pow((1.0 + yrRate),compound2) - 1.0;
		var PAYMENT2 = (MORTGAGE * rdefine2 * (Math.pow((1.0 + rdefine2),monTime2))) / ((Math.pow((1.0 + rdefine2),monTime2)) - 1.0);
		return PAYMENT2;
	}
}

function retTerm(n){
	if(n == 0){
		return 0;
	}
	if(n == 1){
		return 6;
	}
	if(n == 2){
		return 12;
	}
	if(n == 3){
		return 24;
	}
	if(n == 4){
		return 36;
	}
	if(n == 5){
		return 60;
	}
	if(n == 6){
		return 84;
	}
	if(n == 7){
		return 120;
	}
	if(n == 8){
		return 300;
	}
}

function retFreq(n){
	if(n == 0){
		return 0;
	}
	if(n == 1){
		return 12;
	}
	if(n == 2){
		return 24;
	}
	if(n == 3){
		return 26;
	}
	if(n == 4){
		return 52;
	}
}

function calcTotal(MORTGAGE, LTV){
	if(LTV > .75 && LTV <= .80){
		return MORTGAGE * 1.0125;
	}
	if(LTV > .80 && LTV <= .85){
		return MORTGAGE * 1.02;
	}
	if(LTV > .80){
		return MORTGAGE * 1.025;
	}
	if(LTV <= .75){
		return MORTGAGE
	}
}

/* saves cookie containing data to be used in amortization schedule */

function quickCook(MTGAMT,AMORTYEARS,RATE,TERM,FREQ,WHATYEAR){
	if (WHATYEAR && WHATYEAR == -1 ){
		var timeKindA = 0;
	}else{
        WHATYEAR = 0;
        var timeKindA = 1;
	}
	var AMORTPMT = calcPay(MTGAMT, AMORTYEARS, RATE, 2, FREQ);
	var intrate = RATE / 100;
	var INTFACTOR = Math.pow((1 + intrate / 2),(2 / FREQ)) - 1;
	var expire = new Date ();
	expire.setTime (expire.getTime() + (numDays * 24 * 3600000)); /* 2 months */
	var pdData = " " ;
	pdData = pdData + '`' + MTGAMT + '`' + AMORTPMT + '`' + INTFACTOR + '`' + FREQ + '`' + (AMORTYEARS * FREQ) + '`' + 0 + '`' + 0 + '`' + (TERM / 12) + '`' + timeKindA + '`' + RATE * 1.0 / 100 + '`' + 0 + '`' + WHATYEAR + '`' + 0 + '`' + 0 + '`' + 0 + '`' + 0 + '`' + 0;
	document.cookie = pd + "=" + escape(pdData) +"; expires=" + expire.toGMTString()+"; path=/" ;
}

/* validates all the fields and calculates values to be entered into 
the text boxes at the bottom of the page when the user clicks on compute 
or compute amortization */

function compute(form,year){

	if(document.paycalculator.desterm.selectedIndex == 0){
		fixpro('Mortgage Term:','You have not answered this question, click on the PLEASE CHOOSE button to select your option.');
		return false;
	}
	if(document.paycalculator.pfreq.selectedIndex == 0){
		fixpro('Payment Frequency:','You have not answered this question, click on the PLEASE CHOOSE button to select your option.');
		return false;
	}
	if((document.paycalculator.namortyears.value < 0 || document.paycalculator.namortyears.value > 40)){
		fixpro('Amortization Period - Years:','Please enter a number between 0 and 40.');
		return false;
	}
	if((document.paycalculator.mortamt.value == null|| document.paycalculator.mortamt.value.length == 0)|| (document.paycalculator.mortamt.value <10000|| document.paycalculator.mortamt.value > 1000000) ){
		fixpro('Mortgage Amount:','Please enter a number between 10000 and 1000000.');
		return false;
	}
	if((document.paycalculator.rate.value == null || document.paycalculator.rate.value.length == 0)||(document.paycalculator.rate.value < 2 || document.paycalculator.rate.value > 25)){
		fixpro('Interest Rate:','Please enter a number between 2.0 and 25.0.');
		return false;
	}																						  // + document.paycalculator.namortmonths.value
	if(retTerm(document.paycalculator.desterm.selectedIndex) > (document.paycalculator.namortyears.value*12)){
		fixpro('Mortgage Term:','The selected mortgage term is greater than the amortization period entered.  Increase the amortization period or choose a shorter mortgage term.');
		return false;
	}

	term = retTerm(document.paycalculator.desterm.selectedIndex);
	freq = retFreq(document.paycalculator.pfreq.selectedIndex);
	amortyears = document.paycalculator.namortyears.value;
	mortgageA = document.paycalculator.mortamt.value;
	intrate = document.paycalculator.rate.value;
	var payment = calcPay(mortgageA, amortyears, intrate, 2, freq);
	var intFact = Math.pow((1 + (intrate / 100) / 2),(2 / freq)) - 1;
	// need to determin the number of payments so we can correctly determin the Amortization period
	// and the remaing balance
	var principalBal = mortgageA;
	var aYear = 0;
	var annualCount = 1;
	var year1 = 0;
	var year2 = 0;
	var year3 = 0;
	var year5 = 0;
	var year10 = 0;
	var year25 = 0;

	for(payAdd = 1; principalBal > 0; payAdd++){
        var checkLump = 0;
        var printPayments = Math.ceil(1 / freq);// expressed in Years    
        var printYear = printPayments * freq;// expressed in Payments
        // set flag if this payment is an anniversary
		if((payAdd - 1) / Math.floor(freq) == annualCount){
      		var aYear = 1;
		}
        // interest and principal payment
        var interestPayment = roundPen(principalBal * intFact) * 1.0;
        var principalPayment =  roundPen(payment - interestPayment) * 1.0;
        var checkBal = (principalPayment > principalBal) ? principalBal : principalPayment;
        var principalBal =  roundPen(principalBal - checkBal) * 1.0;
        // lumpsum payment if requested
        if(aYear == 1 && 0 >= annualCount){
        	var checkLump = (lumpAmt > principalBal) ? principalBal : lumpAmt;
       		var principalBal = roundPen(principalBal - checkLump) * 1.0;
		}
        // eliminates balance (adds it to principal paid) if less than half
        if(principalBal < ((interestPayment+principalPayment) / 2)){
          	var checkBal = checkBal + principalBal;
       		var principalBal = 0;
		}
        // resets the anniversary
        if(aYear == 1){
         	var annualCount = annualCount + 1;
          	var aYear = 0;
		}

        if((payAdd / freq) == 1){
  			year1 = principalBal;
        } else if((payAdd / freq) == 2){
         	year2 = principalBal;
        } else if((payAdd / freq) == 3){
          	year3 = principalBal;
        } else if((payAdd / freq) == 5){
          	year5 = principalBal;
        } else if((payAdd / freq) == 10){
           	year10 = principalBal;
        } else if((payAdd / freq) == 25){
           	year25 = principalBal;
        }
	}

	var totalYears = (payAdd - 1) / freq;
	form.newamortyears.value = Math.floor(totalYears);;
	form.mainpay.value = '$' + addCommas(roundPen(payment));
	form.mainyr1.value = '$' + addCommas(roundPen(year1));
	form.mainyr2.value = '$' + addCommas(roundPen(year2));
	form.mainyr3.value = '$' + addCommas(roundPen(year3));
	form.mainyr5.value = '$' + addCommas(roundPen(year5));
	form.mainyr10.value = '$' + addCommas(roundPen(year10));
	form.mainyr25.value = '$' + addCommas(roundPen(year25));
	quickCook(mortgageA,amortyears,intrate,term,freq,year);
	return true;
}

/* loads the amortization schedule file once it is certain that all values 
entered into the form are correct. */

function amortLink(whatyear){
	if(navigator.appVersion.substring(0,3) == 2.0 &&  navigator.appName.substring(0,8)=="Netscape" && (navigator.appVersion.indexOf("Macintosh")>=0||navigator.appVersion.indexOf("PowerPC")>=0)){
		var timere = compute(document.forms['paycalculator'],whatyear);
		if(timere == true){
			setTimeout("document.form2.submit()",100);
		}
	}else{
		if(compute(document.forms['paycalculator'],whatyear) == true){
			document.form2.submit();
		}
	}
}

function amortonLink(){
	if(compute(document.forms['paycalculator'])==true){
		document.form2.submit();
		return false;
	}else{
		return false;
	}
}

function payBal(){
	if(navigator.appVersion.substring(0,3) == 2.0 &&  navigator.appName.substring(0,8)=="Netscape" && navigator.appVersion.indexOf("Macintosh")>=0){
		setTimeout("compute(document.forms['paycalculator'])",200);
	}else{
		compute(document.forms['paycalculator']);
	}
}

/*-------------------------------------------------------------------------------*/
/* Calculator-rvb2.js */
/*-------------------------------------------------------------------------------*/

rb = 'rentbuydata';

/* get the cookie required from a list of possible cookies */
function GetCookie (CookieName){
	var cname = CookieName + "=";
	var i = 0;
	while (i < document.cookie.length) {
		var j = i + cname.length;
		if (document.cookie.substring(i, j) == cname){
			var leng = document.cookie.indexOf (";", j);
			if (leng == -1) leng = document.cookie.length;
			return unescape(document.cookie.substring(j, leng));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
		break;
	}
	return " ";
}

/* parses the cookie required returning the requested value - the value 
which is at the requested position within the specified cookie */

function parseCookie(cookieValue, citem){
	var indx = 0, citemlen =0;
	if (cookieValue == null) 
	return " "/* data has expired or never entered. */
	if (cookieValue == " ") 
	return " "/* data has expired or never entered. */
	for(var i=0; i < citem; i++) {
		indx = ( citem==0 )?0:cookieValue.indexOf("`", indx + 1)+1;
	}
	citemlen=(cookieValue.indexOf("`",indx)>0)?cookieValue.indexOf("`", indx+1):cookieValue.length;
	return cookieValue.substring(indx, citemlen);
}

function roundPen(n){
	if(n > 0){
	pennies = n*100;
	pennies = Math.round(pennies);
	strPennies = "" + pennies;
	len = strPennies.length;
	return strPennies.substring(0, len - 2) + "." + strPennies.substring(len -2, len);
	}else{ 
		return 0;
	}
}

rbuyData = GetCookie(rb);

function browTest(){
	if((navigator.appVersion.substring(0,3) == 3.0 || navigator.appVersion.substring(0,3) == 4.0)&& navigator.appName.substring(0,8)=="Netscape"){
		return true;
	}else{
		return false;
	}
}

function MailStopWarning (email)
{
	alert('Our email system is cureently having technical issue, please send your information to '+email+ '\n Sorry for the inconvenience');
}
