var NS4DOM = (document.layers) ? true:false;            // Netscape 4.xx browser
var IEDOM = (document.all) ? true:false;                // Internet Explorer browser
var W3CDOM = (document.getElementById) ? true:false;    // Netscape browser

var license = '<div align="justify"><font face="Arial, Helvetica, sans-serif" size="1">' +
  'This calculator is only to be used as a tool for exploring options concerning financing. Accuracy of the results is not guaranteed. The use of this calculator and the results of this calculator in no way signifies that you will be approved for a loan.' +
  '</font></div>';

js_version = 1.1;

function displayDec(val, decs){
    var factr = 1;
    for (var i = 0; i < decs; i++){
        factr *= 10;
    }
    var outputStr = Math.round(factr * val) + '';
    while (outputStr.length - decs < 1){
        outputStr = '0' + outputStr;
    }
    var pos = outputStr.length - decs;
    return outputStr.substring(0, pos) + '.' + outputStr.substring(pos);
}

function Calc(form) {
    var sTemp = "blah";
    var iPrinciple = Number(form.principle.value);
    var iRate = Number(form.rate.value);
    var iTime = Number(form.time.value);
    var iDays;
    var iTimestyle;
    var iResult;

    if (iPrinciple <= 0) {
        form.result.value = 0;
        return true    }

    if (form.calc.selectedIndex == 0) { iDays = 365 }  // compound in days
    if (form.calc.selectedIndex == 1) { iDays = 52 }
    if (form.calc.selectedIndex == 2) { iDays = 26 }
    if (form.calc.selectedIndex == 3) { iDays = 12 }
    if (form.calc.selectedIndex == 4) { iDays = 4 }
    if (form.calc.selectedIndex == 5) { iDays = 1 }

    if (form.timestyle[0].checked) { iTimestyle = 365 }  // the time in days (1 week = 7, 1 year = 365)
    if (form.timestyle[1].checked) { iTimestyle = 7 }
    if (form.timestyle[2].checked) { iTimestyle = 1 }

    iResult = iPrinciple * (Math.pow((1 + (iRate / 100 / iDays)), iTime * iDays / iTimestyle));
    iResult = Math.round(iResult * 100) / 100;


//  for (int i = 0; i < length; i++) {
//      if (Character.isUpperCase(myName.charAt(i))) {
//      myInitials.append(myName.charAt(i));    }}

    var theAnswer = "$"+displayDec(iResult, 2)
    form.result.value = theAnswer;

    return true
}

