function ResetButton() {
  document.form7a2.reset();
  if (navigator.appName=="Netscape") {
     document.result.document.write("");
     document.result.document.close();
  }
  else {
     result.innerHTML="";
  }
}


function c_period() {
  var index = document.form7a2.period.selectedIndex;
  var curYear = document.form7a2.period.options[index].value;
    if (curYear == "1")
       document.form7a2.rate.value = "5.000000";
    else if (curYear == "2")
       document.form7a2.rate.value = "5.125000";
    else if (curYear == "3")
       document.form7a2.rate.value = "5.250000";
}


function compute() {
   var a, r, p, ans;
   var n1;  //year
   var n2;  //month

   a = parseFloat(document.form7a2.saving.value);
   r = parseFloat(document.form7a2.rate.value);
        
   for (var m = 0; m <  document.form7a2.period.options.length; m++) {
      if (document.form7a2.period.options[m].selected) {
         n1 = parseFloat(document.form7a2.period.options[m].value);
         n2 = n1 % 1;
         n1 = n1 - (n1 % 1);
         n2 = n2 * 12;
         break;
      }
   }
   r = r / 100;
   p = 100 * a / (((24+13*r)*(Math.pow(1+r, n1)-1)*(12+r*n2) + r * n2 * (24+r*(n2+1))) / (24 * r));
   ans = Math.round(p) / 100;
   ans = format(ans.toString());
   if (navigator.appName=="Netscape") {
      document.result.document.write(ans);
      document.result.document.close();
   }
   else {
      result.innerHTML = ans;
   }
}



function Checking(tag) {
   if (document.form7a2.saving.value <= 0) {
      if (!tag)
         alert ("計劃到期本息數不能少於或等於零！");
      else
         alert ("Planned Principal Plus Accrued Interest cannot be less than or equal to zero!");
      return false;
   }
   if (isNaN(document.form7a2.saving.value)) {
      if (!tag)
         alert("計劃到期本息數輸入錯誤！");
      else
         alert("Invalid input on Planned Principal Plus Accrued Interest field!");
      return false;
   }
   if (document.form7a2.rate.value == "") {
      c_period();
   }
   if (document.form7a2.rate.value <= 0) {
      if (!tag)
         alert ("年利率不能少於或等於零！");
      else
         alert ("Interest Rate cannot be less than or equal to zero!");
      return false;
   }
   if (isNaN(document.form7a2.rate.value)) {
      if (!tag)
         alert("年利率輸入錯誤 ！");
      else
         alert("Invalid input on Interest Rate field!");
      return false;
   }
   return true;
}