// JavaScript Document
/* Javascript-Date-Code Reference: http://www.w3schools.com/jsref/jsref_obj_date.asp
 * <script language="Javascript" type="text/javascript"> document.write(thedate.getFullYear()); </script>
 */
var stampdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var stampmonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var thedate = new Date();
// Start of Preload Images
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/soundwave/soundwave1.png"
    images[2]="images/soundwave/soundwave2.png"
    images[3]="images/soundwave/soundwave3.png"
    images[4]="images/soundwave/soundwave4.png"
    images[5]="images/soundwave/soundwave5.png"
    images[6]="images/soundwave/soundwave6.png"
    images[7]="images/soundwave/soundwave7.png"
    images[8]="images/soundwave/soundwave8.png"
    images[9]="images/soundwave/soundwave9.png"
	 
    // start preloading
    for(i=0; i<=3; i++) {
        imageObj.src=images[i];
    }
}
// End Image Preloader */
// 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';
}
function showonlyone(thechosenone) {
    var newboxes = document.getElementsByTagName("div");
    for(var x=0; x<newboxes.length; x++) {
        name = newboxes[x].getAttribute("name");
        if (name == 'newboxes') {
            if (newboxes[x].id == thechosenone) {
                newboxes[x].style.display = 'block';
            }
            else {
                newboxes[x].style.display = 'none';
            }
        }
    }
}
//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 */


