sAgent = navigator.userAgent;
bIsMac = sAgent.indexOf("Mac") > -1;
bIsIE = sAgent.indexOf("MSIE") > -1;
bIsIE3 = sAgent.indexOf("IE 3") > -1;
bIsIE4 = sAgent.indexOf("IE 4") > -1;
bIsIE5 = sAgent.indexOf("IE 5")  > -1;
bIsNav = sAgent.indexOf("Mozilla") > -1 && !bIsIE;
bDoesAll = (bIsIE4 || bIsIE5) && !bIsMac;

function mycalc() {
   Pv = vValue();
   i = vInt();
   n = vYears();
   
   if ( (Pv == -1) || (i == -1) || (n == -1) ) {
      document.data.pmt.value = "ERROR";
   } else {
      Pmt = i * Pv / (1-Math.pow(1+i,-n));
       document.data.pmt.value = Math.round(Pmt*100)/100;     
   }

   if(bDoesAll){
     window.event.returnValue=false;}
   else{
   document.data.action='javascript::void()';
   return false;}
   
}

function vValue() {
   num = parseFloat(document.data.pV.value);
   if(isNaN(num)) {
      if(document.data.pV.value != "ERROR") {
         document.data.pV.value = "ERROR";
         alert("Loan amount must be a number");
      }
      return -1;
   } else if(num <= 0) {
      if(document.data.pV.value != "ERROR") {
         document.data.pV.value = "ERROR";
         alert("Loan amount must be number greater than 0.");
      }
      
      return -1;
   } else {
      document.data.pV.value = num;
      return num;  
   } 
}

function vInt() {
   num = parseFloat(document.data.iY.value);
   if(isNaN(num)) {
      if(document.data.iY.value != "ERROR") {
         document.data.iY.value = "ERROR";
         alert("Interest rate must be a number");
      }
      return -1;
   } else if(num <= 0) {
      if(document.data.iY.value != "ERROR") {
         document.data.iY.value = "ERROR";
         alert("Interest rate must be number greater than 0.");
      }
      //document.data.iY.value = num;
      return -1;
   }
   document.data.iY.value = num;
   return num/1200;  
}

function vYears() {
   num = parseFloat(document.data.tY.value);
   if(isNaN(num)) {
      if(document.data.tY.value != "ERROR") {
         document.data.tY.value = "ERROR";
         alert("Number of years must be a number");
      }
      return -1;
   } else if(num <= 0) {
      if(document.data.tY.value != "ERROR") {
         document.data.tY.value = "ERROR";
         alert("Number of years must be number greater than 0.");
      }
      //document.data.tY.value = num;
      return -1;
   }
   document.data.tY.value = num;
   return num*12;  
}

function resetValues() {
    var purprice = 0;
    document.data.pV.value = purprice;
    document.data.pmt.value = "";
}