// JavaScript Document
function preloader(){
		// counter
		var i = 0;
		 
		// create object
		imageObj = new Image();
		
		// set image list
     images = new Array();
     images[0]="images/logo.png"
     images[1]="images/header.png"
		 
		 // start preloading
     for(i=0; i<=3; i++) {
          imageObj.src=images[i];
     }
	}
// Mortgage Calculator
function checkForZero(field) {
			if (field.value == 0 || field.value.length == 0) {
					alert ("This field can't be 0!");
					field.focus(); }
			else
					calculatePayment(field.form);
}//end function
	
function cmdCalc_Click(form) {
			if (form.price.value == 0 || form.price.value.length == 0) {
					alert ("The Price field can't be 0!");
					form.price.focus(); }
			else if (form.ir.value == 0 || form.ir.value.length == 0) {
					alert ("The Interest Rate field can't be 0!");
					form.ir.focus(); }
			else if (form.term.value == 0 || form.term.value.length == 0) {
					alert ("The Term field can not be 0!");
					form.term.focus(); }
			else
					calculatePayment(form);
}//end function
	
	function calculatePayment(form) {
			princ = form.price.value - form.dp.value;
			intRate = (form.ir.value/100) / 12;
			months = form.term.value * 12;
			//form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
			monthly_pt  = Math.floor ( (form.pt.value/12)*100)/100;
			monthly_ins = Math.floor( (form.ins.value/12)*100)/100;
			monthly_extra = (monthly_pt + monthly_ins);
			//alert(monthly_pt);
			//alert(monthly_ins);
			//alert(monthly_extra);
			principle_interest = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
      
			form.pmt.value = (principle_interest + monthly_extra);
			form.principle.value = princ;
			form.payments.value = months;
}//end function
//end Mortgage Calculator

// Show-Hide-Divs
function toggleLayer(whichLayer) {
  var elem, vis;
  if(document.getElementById) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
//end Show-Hide-Divs

// Set Active Class
function scriptInit() {
if (!document.getElementById) {
	return;
	}
}
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
	elm.addEventListener(evType, fn, useCapture);
	return true;
	} else if (elm.attachEvent) {
	var r = elm.attachEvent('on' + evType, fn);
	return r;
	} else {
	elm['on' + evType] = fn;
	}
}
function checkActive() {
	var a = document.getElementsByTagName("a");
	if (window.location.href.substr(location.href.length - 1, 1) == '/') {
		var loc = window.location.href + 'index.html'; 
	}
	else {
		var loc = window.location.href;
	}
	for(var i=0; i < a.length; i++) {
		if (a[i].href == loc) {
			a[i].setAttribute("class", "active");
			a[i].setAttribute("className", "active");
		}
	}
}
addEvent(window, 'load', checkActive, false);
// End Set Active Class

function move_box(an, box) {
  var cleft = -40;
  var ctop = -22;
  var obj = an;
  while (obj.offsetParent) {
    cleft += obj.offsetLeft;
    ctop += obj.offsetTop;
    obj = obj.offsetParent;
  }//end while
  box.style.left = cleft + 'px';
  ctop += an.offsetHeight + 8;
  if (document.body.currentStyle && document.body.currentStyle['marginTop']) {
    ctop += parseInt(document.body.currentStyle['marginTop']);
  }//end if
  box.style.top = ctop + 'px';
}// end function

function show_hide_box(an, width, height, borderStyle) {
  var href = an.href;
  var boxdiv = document.getElementById(href);
  if (boxdiv != null) {
    if (boxdiv.style.display=='none') {
      move_box(an, boxdiv);
      boxdiv.style.display='block';
    } else
      boxdiv.style.display='none';
    return false;
  }//end if

  boxdiv = document.createElement('div');
  boxdiv.setAttribute('id', href);
  boxdiv.style.display = 'block';
  boxdiv.style.position = 'absolute';
  boxdiv.style.width = width + 'px';
  boxdiv.style.height = height + 'px';
  boxdiv.style.border = borderStyle;
  boxdiv.style.backgroundColor = 'transparent';
  boxdiv.style.backgroundColor = '#FFFFFF';
  var close_button = '<a href="#" onClick="document.getElementById(\''+href+'\').style.display=\'none\'; return false;" style="background-color:#c0c0c0; border:solid black 1px; font-size:14px; font-weight:bold; position:absolute; right:1; top:1; text-decoration:none; font-family:arial; padding:1px 3px 1px 3px; z-index:5;">X</a>';
  boxdiv.innerHTML = close_button;

  var contents = document.createElement('iframe');
  contents.scrolling = 'no';
  contents.frameBorder = '0';
  contents.style.width = width + 'px';
  contents.style.height = height + 'px';
  contents.src = href;

  boxdiv.appendChild(contents);
  document.body.appendChild(boxdiv);
  move_box(an, boxdiv);
  return false;
}//end function

