/* Hi there.  See you're looking at the code.  Well all I ask is that you at least give -->
 the author some credit for his work.  Best way, just leave this text intact.  You do not
 have to place the author's name on your page.  But if you want to, that's ok.  Thanks for
 using this script.

 Script is by Ron Murphy. Updated 08.18.2001 for new Windchill calculation.
*/
// ##################  Temperature conversions #####
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("Temperature is above 45 degrees F, it really doesn't matter.  Click on reset and try again!");
  } else {
    if (Windchill.mph.value < 5) {
    alert("The wind speed is below 5 mph, temperature and windchill are the same!  Click on reset and try again!");
    } else {
     // old formula Wind Chill ( F) = 35.74 + 0.6215T - 35.75(V<sup>0.16<\/sup>) + 0.4275T(V<sup>0.16<\/sup>)
//        var wc = 35.74 + (0.6215*Windchill.intemp.value) - (35.75*Math.pow(Windchill.mph.value,0.16)) + (0.4275*Windchill.intemp.value*Math.pow(Windchill.mph.value,0.16));
      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 WC2(Windchill_C){
  if (Windchill_C.intemp_C.value > 7){
    alert("Temperature is above 7 degrees C, it really doesn't matter.  Click on reset and try again!");
  } else {
    if (Windchill_C.mph_C.value < 5) {
    alert("The wind speed is below 5 mph, temperature and windchill are the same!  Click on reset and try again!");
    } else {
        var intemp_to_F = 1.80 * Windchill_C.intemp_C.value + 32.0;
//        var wc_F = 35.74 + (0.6215*intemp_to_F) - (35.75*Math.pow(Windchill_C.mph_C.value,0.16)) + (0.4275*intemp_to_F*Math.pow(Windchill_C.mph_C.value,0.16));
      var wc_F = 0.0817*(3.71*Math.sqrt(Windchill_C.mph_C.value)+5.81 - 0.25 * Windchill_C.mph_C.value)*(intemp_to_F-91.4) + 91.4;
//      var wc_C = 33 + (Windchill_C.intemp_C.value - 33) * (.474 + .454 * Math.sqrt(Windchill_C.mph_C.value * .447) - .0454 * (Windchill_C.mph_C.value * .447));
        Windchill_C.wcvalue_in_c.value=Math.round((wc_F - 32) * .556) + " C" + " / " + Math.round(wc_F) + " F";
//      Windchill_C.wcvalue_in_c.value=Math.round(wc_C) + " C" + "/" + (Math.round(1.80 * wc_C + 32.0)) + " F";
    }
  }
}

// ################### Relative Humidity #####

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("The Heat Index doesn't really matter at this point. The Dew Point only will be calculated.");
  }
  //
  else if (HI1_C.RHumidity.value <= 40) {
     alert("The Heat Index doesn't really matter at this point. The Dew Point only will be calculated.");
  }
  //
  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){
    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)));

    if(heatdew_c.tempair3.value <= 27){
      alert("The Heat Index really doesn't matter at this point. Only the Humidity will be calculated.");
    }
    //
    else if (heatdew_c.dewpoint_c.value <= 12){
      alert("The Heat Index really doesn't matter at this point. Only the Humidity will be calculated.");
    }
    //
    else{
         if (heatdew_c.tempair3.value < heatdew_c.dewpoint_c.value){
         	alert("Your dew point temperature cannot be higher than the air temperature.  Click on reset and try again!");
     	 }
 	 else{
    		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("The Heat Index doesn't really matter at this point. The Dew Point only will be calculated.");
  }
  //
  else if (HeatIndex.RHumidity.value <= 40) {
      alert("The Heat Index doesn't really matter at this point. The Dew Point only will be calculated.");
  }
 //
  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){
    var tc2 = (parseFloat(heatdew.tempair2.value) - 32) * .556;
    var tdc2 = (parseFloat(heatdew.dewpoint.value) -32)* .556;
    var stuff2 = (112-(0.1*tc2)+tdc2)/(112+(0.9*tc2));
    var RHumidity2 = Math.round(100.0*(Math.pow(stuff2,8)));

    if(heatdew.tempair2.value <= 80){
      alert("The Heat Index really doesn't matter at this point. Only the Humidity will be calculated.");
    }
    //
    else if (heatdew.dewpoint.value <= 65) {
      alert("The Heat Index really doesn't matter at this point. Only the Humidity will be calculated.");
    }
    //
    else{
         if (tc2 < tdc2){
         alert("Your dew point temperature cannot be higher than the air temperature.  Click on reset and try again!");
         }
         else{
    		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 + "%";
}

// ###################### Form clearing #####

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="";
}
<!-- done hiding from old browsers -->


