// Tools JS v.1.01

function isANumeric(sText, sMessage)
{
   var ValidChars = "0123456789.";
   var isANumber=true;
   var Char;
   for (i = 0; i < sText.length && isANumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         isANumber = false;
		 alert("Please use only numbers and the '.' as decimal for the " + sMessage + " field");
         }
      }
   return isANumber;
   
   }

function calc_mort() { //v.0.1
  var d=document; 
if (d.mortcalc.amount.value == '' || d.mortcalc.interest.value == '' || d.mortcalc.years.value == ''){
		alert("Please to make an estimation of your mortgage fill the Total Amoun, Rate and Time");
		return false;
}else if (d.mortcalc.amount.value == '0' || d.mortcalc.interest.value == '0' || d.mortcalc.years.value == '0'){
		alert("Please don't use the zero value for the calculation");
		return false;
} else if (isANumeric(d.mortcalc.amount.value,"Amount") && isANumeric(d.mortcalc.interest.value,"Interest") && isANumeric(d.mortcalc.years.value,"Time in Years")){
		 var pv= Number(d.mortcalc.amount.value);
		 var rate = Number((d.mortcalc.interest.value/12)/100);
		 var nper = Number(d.mortcalc.years.value*12);	
	    var valoraux = 1/(Math.pow((1+rate),nper));
		 var valor = Math.round(pv*100*rate/(1-valoraux))/100;
		 d.mortcalc.valorcalc.value = "For the specific amount you will pay " + valor + " €/month";			
} else {return false;}
}

function calculaarea() { //v.0.1
  var d=document; 
if (d.form1.areacal.value == ''){
		alert("Please fill the Field to proceed with the calculation of the area");
		return false;
} else if (isANumeric(d.form1.areacal.value,"Area")){
		 var i = d.form1.uniar1.selectedIndex;
		 var j = d.form1.uniar2.selectedIndex;
		 d.form1.areacalculada.value = d.form1.areacal.value + " " + d.form1.uniar1.options[i].text + " >>> " + (Math.round((Number(d.form1.areacal.value)*Number(d.form1.uniar2.options[j].value)/Number(d.form1.uniar1.options[i].value))*100))/100 + " " + d.form1.uniar2.options[j].text;			
} else {return false;}
}

function calculadist() { //v.0.1
  var d=document; 
if (d.form2.distcal.value == ''){
		alert("Please fill the Field to proceed with the calculation of the area");
		return false;
} else if (isANumeric(d.form2.distcal.value,"Area")){
		 var i = d.form2.unidist1.selectedIndex;
		 var j = d.form2.unidist2.selectedIndex;
		 d.form2.distcalculada.value = d.form2.distcal.value + " " + d.form2.unidist1.options[i].text + " >>> " + (Math.round((Number(d.form2.distcal.value)*Number(d.form2.unidist2.options[j].value)/Number(d.form2.unidist1.options[i].value))*100))/100 + " " + d.form2.unidist2.options[j].text;			
} else {return false;}
}

