function ftoc(fahrenheit){
  fahrenheit.Celsius.value = Math.round((fahrenheit.tempf.value - 32) * .556) + " C";
}

function ctof(celsius){
  celsius.Fahrenheit.value = 1.80 * celsius.tempc.value + 32.0 + " F";
}
// ####################################  Windchill #####################################
function windchill1(Windchill){
   if (Windchill.intemp.value > 45){
     alert("Anything above 45 degrees doesn't really matter. Try something a little colder.");
  }
 else{
 var wc = 0.0817*(3.71*Math.sqrt(Windchill.mph.value)+5.81 - 0.25 * Windchill.mph.value)*(Windchill.intemp.value-91.4) + 91.4;
 Windchill.windchill.value = Math.round(wc) + " F" + " / " + (Math.round((wc - 32) * .556) + " C");
}
}

function RH(humidity){
  var tc = (humidity.airtemp.value - 32) * .556;
  var tdc = (humidity.dewpointtemp.value -32)* .556;
    if (tc < tdc){
      alert("Your dew point temperature cannot be higher than the air temperature.  Click on reset and try again!");
    }
    else{
     humidity.relativeh.value = Math.round(100.0*(Math.pow((112-(0.1*tc)+tdc)/(112+(0.9*tc)),8))) + "%";
         humidity.answer3.value = Math.round(tc) + " C";
         humidity.answer4.value = Math.round(tdc) + " C";
    }
}

function RHC(RH2){
    var rhtcc = (RH2.rh_tcc.value-0);
        var rhtdcc = (RH2.rh_tdcc.value-0);
    if (rhtcc < rhtdcc){
      alert("Your dew point temperature cannot be higher than the air temperature.  Click on reset and try again!");
    }
    else{
     RH2.TheRHinPercent.value = Math.round(100.0 * (Math.pow((112 - (0.1 * rhtcc) + rhtdcc)/(112 + (0.9 * rhtcc)),8))) + "%";
     RH2.answer1.value = Math.round(1.80 * rhtcc + 32) + " F";
     RH2.answer2.value = Math.round(1.80 * rhtdcc + 32) + " F";
    }
}
//  ###################################  HEAT INDEX ######################################
function heat1_c(HI1_C){
  if(parseFloat(HI1_C.tempair.value) < 27){
     alert("Try a temperature a little more reasonable.");
  }
  //
  else if (HI1_C.RHumidity.value < 40) {
     alert("Anything less than 40 percent doesn't really matter. Try something a little higher.");
  }
  //  
  else {
     var tempair_in_fahrenheit = 1.80 * HI1_C.tempair.value + 32.0;
     var hi1_c = -42.379 + 2.04901523 * tempair_in_fahrenheit + 10.14333127 * HI1_C.RHumidity.value - 0.22475541 * tempair_in_fahrenheit * HI1_C.RHumidity.value - 6.83783 * (Math.pow(10, -3)) * (Math.pow(tempair_in_fahrenheit, 2)) - 5.481717 * (Math.pow(10, -2)) * (Math.pow(HI1_C.RHumidity.value, 2)) + 1.22874 * (Math.pow(10, -3)) * (Math.pow(tempair_in_fahrenheit, 2)) * HI1_C.RHumidity.value + 8.5282 * (Math.pow(10, -4)) * tempair_in_fahrenheit * (Math.pow(HI1_C.RHumidity.value, 2)) - 1.99 * (Math.pow(10, -6)) * (Math.pow(tempair_in_fahrenheit, 2)) * (Math.pow(HI1_C.RHumidity.value,2));
     HI1_C.heatindex.value = Math.round(hi1_c) + " F"  + " / " + Math.round((hi1_c - 32) * .556) + " C";
     var rh3 = 1 - HI1_C.RHumidity.value/100;
     var tdpc3 = HI1_C.tempair.value - (((14.55 + .114*HI1_C.tempair.value)*rh3) + (Math.pow(((2.5 + .007*HI1_C.tempair.value)*rh3), 3)) + ((15.9 + .117*HI1_C.tempair.value))*(Math.pow(rh3, 14)));
    HI1_C.dewpt2.value = Math.round(1.80 * tdpc3 + 32.0) + " F" + " / " + Math.round(tdpc3) + " C";
   }
}
// Heat index computed using air temperature and dew point temperature.  Degrees C
function HIDEW_c(heatdew_c){
    if(heatdew_c.tempair3.value < 27){
      alert("Anything below 27 degrees really doesn't matter.  Try something higher.");
    }
        //
        else if (heatdew_c.dewpoint_c.value < 12){
      alert("Try a dewpoint higher than 12 degrees.");
        }
        //
    else{
         if (heatdew_c.tempair3.value < heatdew_c.dewpoint_c.value){
         alert("Your dew point temperature cannot be higher than the air temperature. Try again!");
     }
    else{
    tac = parseFloat(heatdew_c.tempair3.value);
    tdac = parseFloat(heatdew_c.dewpoint_c.value);
    var stuff3 = (112 - (0.1 * tac) + tdac) / (112 + (0.9 * tac));
    var RHumidity3 = Math.round(100.0 * (Math.pow(stuff3,8)));
    var airtemp_in_fahrenheit = 1.80 * heatdew_c.tempair3.value + 32.0;

    var hi3 = -42.379 + 2.04901523 * airtemp_in_fahrenheit + 10.14333127 * RHumidity3 - 0.22475541 * airtemp_in_fahrenheit * RHumidity3 - 6.83783 * (Math.pow(10, -3)) * (Math.pow(airtemp_in_fahrenheit, 2)) - 5.481717 * (Math.pow(10, -2)) * (Math.pow(RHumidity3, 2)) + 1.22874 * (Math.pow(10, -3)) * (Math.pow(airtemp_in_fahrenheit, 2)) * RHumidity3 + 8.5282 * (Math.pow(10, -4)) * airtemp_in_fahrenheit * (Math.pow(RHumidity3, 2)) - 1.99 * (Math.pow(10, -6)) * (Math.pow(airtemp_in_fahrenheit, 2)) * (Math.pow(RHumidity3,2));
    heatdew_c.answer.value = Math.round(hi3) + " F" +  " / " + Math.round((hi3 - 32) * .556) + " C";
    heatdew_c.RH3.value = RHumidity3 + "%";
    }
  }
}
// Heat index computed using air temperature F and RH%
function heat1(HeatIndex){
  if(HeatIndex.tempair.value < 80){
      alert("Any temperature below 80 degrees doesn't have a significant heat index. Try something a little higher.");
  }
  //
  else if (HeatIndex.RHumidity.value < 40) {
      alert("Your relative humidity value is too low. Try something greater than 40 percent.");
  }
 //    
  else {
   var hi = -42.379+2.04901523*HeatIndex.tempair.value+10.14333127*HeatIndex.RHumidity.value-0.22475541*HeatIndex.tempair.value*HeatIndex.RHumidity.value-6.83783*(Math.pow(10, -3))*(Math.pow(HeatIndex.tempair.value, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(HeatIndex.RHumidity.value, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(HeatIndex.tempair.value, 2))*HeatIndex.RHumidity.value+8.5282*(Math.pow(10, -4))*HeatIndex.tempair.value*(Math.pow(HeatIndex.RHumidity.value, 2))-1.99*(Math.pow(10, -6))*(Math.pow(HeatIndex.tempair.value, 2))*(Math.pow(HeatIndex.RHumidity.value,2));
   HeatIndex.heatindex.value = Math.round(hi) + " F" +  " / " + Math.round((hi - 32) * .556) + " C";
   var tempc2 = (HeatIndex.tempair.value - 32) * .556;
   var rh2 = 1 - HeatIndex.RHumidity.value/100;
   var tdpc2 = tempc2 - (((14.55 + .114*tempc2)*rh2) + (Math.pow(((2.5 + .007*tempc2)*rh2), 3)) + ((15.9 + .117*tempc2))*(Math.pow(rh2, 14)));
   HeatIndex.dewpt2.value = Math.round(1.80 * tdpc2 + 32.0) + " F" + " / " + Math.round(tdpc2) + " C";
}
}
// Heat index computed using air temperature and dew point temperature. Degrees F
function HIDEW(heatdew){
    if(heatdew.tempair2.value < 80){
      alert("Click on reset and try a temperature above 80 degrees.");
    }
        //
        else if (heatdew.dewpoint.value < 53) {
      alert("Click on reset and try a dewpoing above 53 degrees.");
        }
        // 
    else{
       var tc2 = (parseFloat(heatdew.tempair2.value) - 32) * .556;
       var tdc2 = (parseFloat(heatdew.dewpoint.value) -32)* .556;
         if (tc2 < tdc2){
         alert("Your dew point temperature cannot be higher than the air temperature.  Click on reset and try again.");
         }
    else{
    var stuff2 = (112-(0.1*tc2)+tdc2)/(112+(0.9*tc2));
    var RHumidity2 = Math.round(100.0*(Math.pow(stuff2,8)));
    var hi2 = -42.379+2.04901523*heatdew.tempair2.value+10.14333127*RHumidity2-0.22475541*heatdew.tempair2.value*RHumidity2-6.83783*(Math.pow(10, -3))*(Math.pow(heatdew.tempair2.value, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(RHumidity2, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(heatdew.tempair2.value, 2))*RHumidity2+8.5282*(Math.pow(10, -4))*heatdew.tempair2.value*(Math.pow(RHumidity2, 2))-1.99*(Math.pow(10, -6))*(Math.pow(heatdew.tempair2.value, 2))*(Math.pow(RHumidity2,2));
    heatdew.answer.value = Math.round(hi2) + " F" +  " / " + Math.round((hi2 - 32) * .556) + " C";
    heatdew.RHumidity2.value = RHumidity2 + "%";
    }
  }
}
function clearF(form){
form.Celsius.value="";
form.tempf.value = "";
}
function clearC(form){
form.Fahrenheit.value = "";
form.tempc.value = "";
}
function clearwindchill(form){
form.windchill.value = "";
form.mph.value = "";
form.intemp.value = "";
}
function clearwindchill_C(form){
form.wcvalue_in_c.value = "";
form.mph_C.value = "";
form.intemp_C.value = "";
}
function clearhumidity(form){
form.relativeh.value = "";
form.airtemp.value = "";
form.dewpointtemp.value = "";
form.answer3.value = "";
form.answer4.value = "";
}
function clearhumidity2(form){
form.TheRHinPercent.value = "";
form.rh_tcc.value = "";
form.rh_tdcc.value = "";
form.answer1.value = "";
form.answer2.value = "";
}
function clearHI(form){
form.tempair.value = "";
form.RHumidity.value = "";
form.heatindex.value = "";
}
function clearHIDEW(form){
form.tempair2.value = "";
form.RHumidity2.value = "";
form.answer.value = "";
}
function clearHI(form){
form.tempair.value = "";
form.RHumidity.value = "";
form.heatindex.value = "";
}
function clearHIDEW(form){
form.tempair2.value = "";
form.RHumidity2.value = "";
form.answer.value = "";
}
function clearHI1_C(form){
form.tempair.value = "";
form.RHumidity.value = "";
form.heatindex.value = "";
form.dewpt2.value = "";
}
function clearHIDEW_c(form){
form.tempair3.value = "";
form.RH3.value = "";
form.answer.value = "";
form.dewpoint_c.value="";
}


