var loaded = 0;
function PreLoad() {

if (document.images != null) {

clickme1 = new Image();
clickme1.src = "images/spacer.gif";
clickme1o = new Image();
clickme1o.src = "images/arw.gif";

}
	loaded = 1;
}

function hiLite(imgDocID,imgObjName) {
if (document.images !=null) {
  if (loaded)
   document.images[imgDocID].src = eval(imgObjName + ".src")
  }
}


function init() {				//  alert ("Running Init");

if (document.layers) {				//  alert ("Running Netscape 4");

 layerRef="document.layers";
 styleSwitch="";
 visibleVar="show";
 agent ="ns4";

} else if (document.all) {			//  alert ("Running IE");

 layerRef="document.all";
 styleSwitch=".style";
 visibleVar="visible";
 agent ="ie";

} else if (document.getElementById) {		//  alert ("Running Netscape 6");

 layerRef="document.getElementByID";
 styleSwitch=".style";
 visibleVar="visible";
 agent="moz";

} else {					//  alert("Older than 4.0 browser.");

 agent="none";
 newbrowser = false;

}
						//  window.status='status bar text to go here';
check = true;
}

// Turn layers on and off

function showLayer(layerName) {

if (check) {
 if (agent=="none") {
  return;
 } else if (agent=="moz") {
  document.getElementById(layerName).style.visibility="visible";
 } else if (agent=="ie") {
  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
 } else {
  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
 }
} else {					// alert ("Please wait for the page to finish loading.");
 return;
}
}


var defaultEmptyOK = false
var decimalPointDelimiter = "."

// Pop up instruction window
function popMe() { myWindow=window.open("instructions.html","","toolbar=no,menubar,scrollbars=yes,location=no,directories=no,status=no,resizable,width=600,height=300");
} 

  /* minimum mortgage length: .083 years
     maximum mortgage length: 25 years
     minimum interest rate: 2%
     maximum interest = 25%
     minimum principle = $1000.00
     see bottom of document for formula information
  */

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


function datatype (v,i,n)
{
 	this.v = v;
 	this.i = i;
 	this.n = n;
}

function CalcPmt(calcform) 
{
	// create new object with Princple data
   		month = new datatype(calcform.p.value, calcform.i.value, calcform.n.value);
   		calcform.payment.value = "";
   		calcform.r2.value = "";

 	calctype = "mnth"; 
 	if(checkvals (calctype, month)) {

 		with (month) 
		{
  			effrate = Math.pow(1 + i/200, 1/6);
			calcform.payment.value = v * (effrate - 1)/(1 - Math.pow(effrate, -12*n));
			calcform.payment.value = (Math.round(calcform.payment.value * 100)) / 100;
			calcform.r2.value = prettyPrint(calcform.payment.value.toString());
  		}
	calcform.payment.value = "";
	} 
}

function CalcPrinciple(calcform) 
{
		prncple = new datatype(calcform.payment.value, calcform.i.value, calcform.n.value);
   		calcform.p.value = "";
   		calcform.r2.value = "";	// set other values to nothing

 	calctype = "prn";
 	if(checkvals(calctype, prncple))
	{

 		with (prncple)
		{
  			effrate = Math.pow(1 + i/200, 1/6);
  			calcform.p.value = v * (1 - Math.pow(effrate, -12*n))/(effrate - 1);
  			calcform.p.value = (Math.round(calcform.p.value * 100)) / 100;
			document.calculator.r2.value = prettyPrint(calcform.p.value.toString());
		}
	calcform.p.value = "";
	} 
}


function checkvals(calctype, obj)
{
 	if (!isFloat(obj.i))
	{
  		alert ("You have entered an invalid number in the INTEREST RATE field.  Please make sure all entries are valid numbers.");
  		document.calculator.i.focus();
		return false;
	}
 	else if (!isFloat(obj.n))
	{	
  		alert ("You have entered an invalid number in the AMORTIZATION  field. Please make sure all entries are valid numbers.");
  		document.calculator.n.focus();
		return false;
	}
	else if (calctype == "mnth")
	{

 		if (!isFloat(obj.v)) 
		{
  			alert ("You have entered an invalid number in the PRINCIPAL field.  Please make sure all entries are valid numbers.");
  			document.calculator.p.focus();
			return false;
 		}
 	}
	else if (calctype == "prn") {

  		if (!isFloat(obj.v))
		{
  			alert ("You have entered an invalid number in the PAYMENT feild.  Please make sure all entries are valid numbers.");
  			document.calculator.payment.focus();
			return false;
		} 
 	}
	
	obj.n = parseFloat(obj.n);
 	obj.v = parseFloat(obj.v);
 	obj.i = parseFloat(obj.i); 

	if (obj.i <= 0)
	{
   		alert ("Your interest rate must be greater than 0.");
   		document.calculator.i.focus();
		return false;
 	}
 	else if (obj.n < 1)
	{
   		alert ("minimum amortization period is 1 year.");
   		document.calculator.n.focus();
		return false;
 	}
 	else if (obj.n > 30)
	{
  		alert("Maximum mortgage period is 30 years.");
  		document.calculator.n.focus();
		return false;
 	}


	return (obj)
}

function prettyPrint(val)
{

   	var decpos = val.indexOf (".");
  	var endpos = val.length;
  	if (decpos == -1) 
	{
    		val = val + ".00";
		return (val);
  	}
  	if (endpos-decpos == 2)
	{
    		val = val + "0";
		return (val);
  	}
  	if (endpos-decpos == 3)
	{
    		return (val);
  	} else {
   		alert ("there was an error Printing the request. Sorry");
   		return (val);
  	}
}

function isInt(elm) 
{
	var elmstr = elm.value + ""; 
    	if (elmstr == "") 
		return false;
    	for (var i = 0; i < elmstr.length; i++)
	{
        	if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9")
		{
        		return false;
        	}
    	}
	return true;
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isFloat(s)
{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    return true;
}




var defaultEmptyOK = false
var decimalPointDelimiter = "."

// Pop up instruction window
function popMe() { myWindow=window.open("instructions.html","","toolbar=no,menubar,scrollbars=yes,location=no,directories=no,status=no,resizable,width=600,height=300");
} 

  /* minimum mortgage length: .083 years
     maximum mortgage length: 25 years
     minimum interest rate: 2%
     maximum interest = 25%
     minimum principle = $1000.00
     see bottom of document for formula information
  */

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


function datatype (v,i,n)
{
 	this.v = v;
 	this.i = i;
 	this.n = n;
}

function CalcPmt(calcform) 
{
	// create new object with Princple data
   		month = new datatype(calcform.p.value, calcform.i.value, calcform.n.value);
   		calcform.payment.value = "";
   		calcform.r2.value = "";

 	calctype = "mnth"; 
 	if(checkvals (calctype, month)) {

 		with (month) 
		{
  			effrate = Math.pow(1 + i/200, 1/6);
			calcform.payment.value = v * (effrate - 1)/(1 - Math.pow(effrate, -12*n));
			calcform.payment.value = (Math.round(calcform.payment.value * 100)) / 100;
			calcform.r2.value = prettyPrint(calcform.payment.value.toString());
  		}
	calcform.payment.value = "";
	} 
}

function CalcPrinciple(calcform) 
{
		prncple = new datatype(calcform.payment.value, calcform.i.value, calcform.n.value);
   		calcform.p.value = "";
   		calcform.r2.value = "";	// set other values to nothing

 	calctype = "prn";
 	if(checkvals(calctype, prncple))
	{

 		with (prncple)
		{
  			effrate = Math.pow(1 + i/200, 1/6);
  			calcform.p.value = v * (1 - Math.pow(effrate, -12*n))/(effrate - 1);
  			calcform.p.value = (Math.round(calcform.p.value * 100)) / 100;
			document.calculator.r2.value = prettyPrint(calcform.p.value.toString());
		}
	calcform.p.value = "";
	} 
}


function checkvals(calctype, obj)
{
 	if (!isFloat(obj.i))
	{
  		alert ("You have entered an invalid number in the INTEREST RATE field.  Please make sure all entries are valid numbers.");
  		document.calculator.i.focus();
		return false;
	}
 	else if (!isFloat(obj.n))
	{	
  		alert ("You have entered an invalid number in the AMORTIZATION  field. Please make sure all entries are valid numbers.");
  		document.calculator.n.focus();
		return false;
	}
	else if (calctype == "mnth")
	{

 		if (!isFloat(obj.v)) 
		{
  			alert ("You have entered an invalid number in the PRINCIPAL field.  Please make sure all entries are valid numbers.");
  			document.calculator.p.focus();
			return false;
 		}
 	}
	else if (calctype == "prn") {

  		if (!isFloat(obj.v))
		{
  			alert ("You have entered an invalid number in the PAYMENT feild.  Please make sure all entries are valid numbers.");
  			document.calculator.payment.focus();
			return false;
		} 
 	}
	
	obj.n = parseFloat(obj.n);
 	obj.v = parseFloat(obj.v);
 	obj.i = parseFloat(obj.i); 

	if (obj.i <= 0)
	{
   		alert ("Your interest rate must be greater than 0.");
   		document.calculator.i.focus();
		return false;
 	}
 	else if (obj.n < 1)
	{
   		alert ("minimum amortization period is 1 year.");
   		document.calculator.n.focus();
		return false;
 	}
 	else if (obj.n > 30)
	{
  		alert("Maximum mortgage period is 30 years.");
  		document.calculator.n.focus();
		return false;
 	}


	return (obj)
}

function prettyPrint(val)
{

   	var decpos = val.indexOf (".");
  	var endpos = val.length;
  	if (decpos == -1) 
	{
    		val = val + ".00";
		return (val);
  	}
  	if (endpos-decpos == 2)
	{
    		val = val + "0";
		return (val);
  	}
  	if (endpos-decpos == 3)
	{
    		return (val);
  	} else {
   		alert ("there was an error Printing the request. Sorry");
   		return (val);
  	}
}

function isInt(elm) 
{
	var elmstr = elm.value + ""; 
    	if (elmstr == "") 
		return false;
    	for (var i = 0; i < elmstr.length; i++)
	{
        	if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9")
		{
        		return false;
        	}
    	}
	return true;
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isFloat(s)
{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    return true;
}

 function popup1(status,url,adWidth,adHeight) {
 
  if (screen) {
   var bottom = screen.availHeight;
   var right = screen.availWidth;
   var pos_x = parseInt((right- adWidth)/2) ;
   var pos_y = parseInt((bottom - adHeight)/2);
   } else {
   pos_x = 30;
   pos_y = 50;
  }
 
 if(status != 0) {
 if(popup != null) popup.focus(); 
 else { 
 var popup = open(url, "popup", "HEIGHT=" + adHeight + ",WIDTH=" + adWidth + ",left=" + pos_y + ",top=" + pos_y + ",status=1,scrollbars=no,toolbar=no,directories=no,menubar=no,location=no");
 popup_window = popup;
 }
 } else {
 if(popup_window != null) popup_window.close();
 }
 }