function roundit(temp_val) {
  temp_val = Math.round(temp_val * 100) / 100;
  temp_val = (temp_val + 0.001) + '';
  temp_val = temp_val.substring(0, temp_val.indexOf('.') + 3);
  return temp_val;
  }
function NeuKnoten(){
  with(document.wind){
   ms.value="";
   knoten.value=Math.round(knoten.value);
   beaufort.value="";
   kmh.value="";
   mph.value="";
  }
 }

 function NeuMph(){
  with(document.wind){
   ms.value="";
   knoten.value="";
   beaufort.value="";
   kmh.value="";
   mph.value=Math.round(mph.value);
  }
 }

 function NeuKmh(){
  with(document.wind){
   ms.value="";
   knoten.value="";
   beaufort.value="";
   kmh.value=Math.round(kmh.value);
   mph.value="";
  }
 }

 function NeuMs(){
  with(document.wind){
   ms.value=Math.round(ms.value);
   knoten.value="";
   beaufort.value="";
   kmh.value="";
   mph.value="";
  }
 }

 function NeuBeaufort(){
  with(document.wind){
   ms.value="";
   knoten.value="";
   kmh.value="";
   mph.value="";
  }
 }


function CheckZahl(Eingabe){
  var nur_das ="0123456789";
  for (var i = 0; i < Eingabe.length; i++)
   if (nur_das.indexOf(Eingabe.charAt(i))<0 ) return false;
  return true;
 }

 function pruef_ms(ms){
   if(ms<0)
     ms=0;
   if(!CheckZahl(ms))
     ms=0;

   return ms;
 }

 function pruef_kmh(kmh){
   if(kmh<0)
     kmh=0;
   if(!CheckZahl(kmh))
     kmh=0;

   return kmh;
 }

 function pruef_mph(mph){
   if(mph<0)
     mph=0;
   if(!CheckZahl(mph))
     mph=0;

   return mph;
 }


 function pruef_knoten(knoten){
   if(knoten<0)
     knoten=0;
   if(!CheckZahl(knoten))
     knoten=0;

   return knoten;
 }

 function pruef_beaufort(beaufort){
   if(beaufort<0)
     beaufort=0;
   if(beaufort>12)
     beaufort=0;

   if(!CheckZahl(beaufort))
     beaufort=0;

   return beaufort;
 }



 function kmh2ms(kmh){
   ms=0;
   ms=kmh/3.6;

   return ms;
 }

 function kmh2mph(kmh){
   mph=0;
   mph=0.6215*kmh;

   return mph;
 }

 function ms2knoten(ms){
   var knoten=0;
   knoten=1.9438*ms;
   return knoten;
 }

 function kmh2knoten(kmh){
   var knoten=0;
   var ms=kmh2ms(kmh);
   knoten=ms2knoten(ms);
   return knoten;
 }


 function knoten2beaufort(knoten){

   if (knoten==0)
    return 0;
   if (knoten<=3)
    return 1;
   if (knoten<=6)
    return 2;
   if (knoten<=10)
    return 3;
   if (knoten<=15)
    return 4;
   if (knoten<=21)
    return 5;
   if (knoten<=27)
    return 6;
   if (knoten<=33)
    return 7;
   if (knoten<=40)
    return 8;
   if (knoten<=47)
    return 9;
   if (knoten<=55)
    return 10;
   if (knoten<=63)
    return 11;
   else
    return 12;
 }


 function ms2kmh(ms){
   var kmh=0;
   kmh=ms*3.6;
   return kmh;
 }

 function ms2mph(ms){
   var mph=0;
   var kmh=0;
   kmh=ms2kmh(ms);
   mph=kmh2mph(kmh);
   return mph;
 }

 function mph2kmh(mph){
   var kmh=0;
   kmh=1.609*mph;
   return kmh;
 }

 function mph2ms(mph){
   var ms=0;
   var kmh=0;

   kmh=mph2kmh(mph);
   ms=kmh2ms(kmh);
   return ms;
 }

 function mph2knoten(mph){
  var knoten=0;
  var ms=0;
  ms=mph2ms(mph);
  knoten=ms2knoten(ms);
  return knoten;

 }

 function mph2beaufort(mph){
   var beaufort=0;
   var knoten=0;
   knoten=mph2knoten(mph);
   beaufort=knoten2beaufort(knoten);
   return beaufort;

 }



 function ms2beaufort(ms){
   var knoten=0;
   var beaufort=0;
   knoten=ms2knoten(ms);
   beaufort=knoten2beaufort(knoten);
   return beaufort;
 }

 function kmh2beaufort(kmh){
   beaufort=0;
   ms=0;
   ms=kmh2ms(kmh);
   beaufort=ms2beaufort(ms);
   return beaufort;
 }

 function knoten2ms(knoten){
   var ms=0;
   ms = 0.51444*knoten
   return ms;
 }

 function knoten2mph(knoten){
   var mph=0;
   ms=0;
   ms=knoten2ms(knoten);
   mph=ms2mph(ms);
   return mph;
 }

 function knoten2kmh(knoten){
   var ms=0;
   var kmh=0;
   ms=knoten2ms(knoten);
   kmh=ms2kmh(ms);
   return kmh;
 }


 function beaufort2knoten(beaufort){
   var knoten="0";


   if(beaufort==1)
     knoten="1-3"
   if(beaufort==2)
     knoten="4-6"
   if(beaufort==3)
     knoten="7-10"
   if(beaufort==4)
     knoten="11-15"
   if(beaufort==5)
     knoten="16-21"
   if(beaufort==6)
     knoten="22-27"
   if(beaufort==7)
     knoten="28-33"
   if(beaufort==8)
     knoten="34-40"
   if(beaufort==9)
     knoten="41-47"
   if(beaufort==10)
     knoten="48-55"
   if(beaufort==11)
     knoten="56-63"
   if(beaufort==12)
     knoten=">64"

   return knoten;
 }

 function beaufort2ms(beaufort){
    var ms=0;

   if(beaufort==1)
     ms="0.3-1.5"
   if(beaufort==2)
     ms="1.6-3.3"
   if(beaufort==3)
     ms="3.4-5.4"
   if(beaufort==4)
     ms="5.5-7.9"
   if(beaufort==5)
     ms="8.0-10.7"
   if(beaufort==6)
     ms="10.8-13.8"
   if(beaufort==7)
     ms="13.9-17.1"
   if(beaufort==8)
     ms="17.2-20.7"
   if(beaufort==9)
     ms="20.8-24.4"
   if(beaufort==10)
     ms="24.5-28.4"
   if(beaufort==11)
     ms="28.5-32.6"
   if(beaufort==12)
     ms=">32.6"

    return ms;
 }


 function beaufort2kmh(beaufort){
   var kmh=0;

   if(beaufort==1)
     kmh="1.1-5.4"
   if(beaufort==2)
     kmh="5.5-11.9"
   if(beaufort==3)
     kmh="12.0-19.4"
   if(beaufort==4)
     kmh="19.5-28.4"
   if(beaufort==5)
     kmh="28.5-38.5"
   if(beaufort==6)
     kmh="38.6-49.7"
   if(beaufort==7)
     kmh="49.8-61.5"
   if(beaufort==8)
     kmh="61.6-74.5"
   if(beaufort==9)
     kmh="74.6-87.8"
   if(beaufort==10)
     kmh="87.9-102.2"
   if(beaufort==11)
     kmh="102.3-117.3"
   if(beaufort==12)
     kmh=">117.4"

   return kmh;

 }

 function beaufort2mph(beaufort){
   var mph=0;

   if(beaufort==1)
     mph="0.7-3.5"
   if(beaufort==2)
     mph="3.6-7.5"
   if(beaufort==3)
     mph="7.6-12.2"
   if(beaufort==4)
     mph="12.3-17.8"
   if(beaufort==5)
     mph="17.9-24.0"
   if(beaufort==6)
     mph="24.1-31.0"
   if(beaufort==7)
     mph="31.1-38.3"
   if(beaufort==8)
     mph="38.4-46.4"
   if(beaufort==9)
     mph="46.5-54.7"
   if(beaufort==10)
     mph="54.8-63.6"
   if(beaufort==11)
     mph="63.7-73.0"
   if(beaufort==12)
     mph=">73"


   return mph;
 }



 function WBerechnen(){
   var ms=document.wind.ms.value;
   var knoten=document.wind.knoten.value;
   var beaufort=document.wind.beaufort.value;
   var kmh=document.wind.kmh.value;
   var mph=document.wind.mph.value;
   if (document.wind.ms.value != ""){
     ms=pruef_ms(ms);
     knoten=ms2knoten(ms);
     beaufort=ms2beaufort(ms);
     kmh=ms2kmh(ms);
     mph=ms2mph(ms);
     document.wind.knoten.value=Math.round(knoten);
     document.wind.beaufort.value=Math.round(beaufort);
     document.wind.ms.value=Math.round(ms);
     document.wind.kmh.value=Math.round(kmh);
     document.wind.mph.value=Math.round(mph);
     return;
   }
   if (document.wind.knoten.value != ""){
     knoten=pruef_knoten(knoten);
     ms=knoten2ms(knoten);
     beaufort=knoten2beaufort(knoten);
     kmh=knoten2kmh(knoten);
     mph=knoten2mph(knoten);
     document.wind.ms.value=Math.round(ms);
     document.wind.beaufort.value=Math.round(beaufort);
     document.wind.knoten.value=Math.round(knoten);
     document.wind.kmh.value=Math.round(kmh);
     document.wind.mph.value=Math.round(mph);
     return;
   }
   if (document.wind.beaufort.value != ""){
     beaufort=pruef_beaufort(beaufort);
     ms=beaufort2ms(beaufort);
     knoten=beaufort2knoten(beaufort);
     kmh=beaufort2kmh(beaufort);
     mph=beaufort2mph(beaufort);
     document.wind.ms.value=ms;
     document.wind.knoten.value=knoten;
     document.wind.beaufort.value=beaufort;
     document.wind.kmh.value=kmh;
     document.wind.mph.value=mph;
     return;
   }
   if (document.wind.kmh.value != ""){
     kmh=pruef_kmh(kmh);
     ms=kmh2ms(kmh);
     knoten=kmh2knoten(kmh);
     beaufort=kmh2beaufort(kmh);
     mph=kmh2mph(kmh);
     document.wind.ms.value=Math.round(ms);
     document.wind.knoten.value=Math.round(knoten);
     document.wind.beaufort.value=Math.round(beaufort);
     document.wind.kmh.value=Math.round(kmh);
     document.wind.mph.value=Math.round(mph);
     return;
   }
   if (document.wind.mph.value != ""){
     mph=pruef_mph(mph);
     ms=mph2ms(mph);
     knoten=mph2knoten(mph);
     beaufort=mph2beaufort(mph);
     kmh=mph2kmh(mph);
     document.wind.ms.value=Math.round(ms);
     document.wind.knoten.value=Math.round(knoten);
     document.wind.beaufort.value=Math.round(beaufort);
     document.wind.kmh.value=Math.round(kmh);
     document.wind.mph.value=Math.round(mph);
     return;
   }


 }


 function WLoeschen(){
   with(document.wind){
     ms.value="";
     knoten.value="";
     beaufort.value="";
     kmh.value="";
     mph.value="";
   }
 }

 function neu_knoten(){
   with(document.wind){
     knoten.value=Math.round(knoten.value);
     ms.value="";
     beaufort.value="";
     kmh.value="";
     mph.value="";
   }
 }

// Temperature berechnen
 function NeuCelsius(){
  with(document.temperature){
   celsius.value=Math.round(celsius.value);
   fahrenheit.value="";
   kelvin.value="";
   reaumur.value="";
  }
 }

 function NeuFahrenheit(){
  with(document.temperature){
   fahrenheit.value=Math.round(fahrenheit.value);
   celsius.value="";
   kelvin.value="";
   reaumur.value="";
  }
 }

 function NeuKelvin(){
  with(document.temperature){
   kelvin.value=Math.round(kelvin.value);
   celsius.value="";
   fahrenheit.value="";
   reaumur.value="";
  }
 }

 function NeuReaumur(){
  with(document.temperature){
   reaumur.value=Math.round(reaumur.value);
   celsius.value="";
   fahrenheit.value="";
   kelvin.value="";
  }
 }

 function TBerechnen(){
   var celsius=document.temperature.celsius.value;
   var fahrenheit=document.temperature.fahrenheit.value;
   var kelvin=document.temperature.kelvin.value;
   var reaumur=document.temperature.reaumur.value;
   if (document.temperature.celsius.value != ""){
     celsius=pruef_celsius(celsius);
     fahrenheit=celsius2fahrenheit(celsius);
     kelvin=celsius2kelvin(celsius);
     reaumur=celsius2reaumur(celsius);
     document.temperature.celsius.value=Math.round(celsius);
     document.temperature.fahrenheit.value=Math.round(fahrenheit);
     document.temperature.kelvin.value=Math.round(kelvin);
     document.temperature.reaumur.value=Math.round(reaumur);
     return;
   }
   if (document.temperature.fahrenheit.value != ""){
     fahrenheit=pruef_fahrenheit(fahrenheit);
     celsius=fahrenheit2celsius(fahrenheit);
     kelvin=fahrenheit2kelvin(celsius);
     reaumur=fahrenheit2reaumur(celsius);
     document.temperature.fahrenheit.value=Math.round(fahrenheit);
     document.temperature.celsius.value=Math.round(celsius);
     document.temperature.kelvin.value=Math.round(kelvin);
     document.temperature.reaumur.value=Math.round(reaumur);
     return;
   }
   if (document.temperature.kelvin.value != ""){
     kelvin=pruef_kelvin(kelvin);
     celsius=kelvin2celsius(kelvin);
     fahrenheit=kelvin2fahrenheit(kelvin);
     reaumur=kelvin2reaumur(kelvin);
     document.temperature.fahrenheit.value=Math.round(fahrenheit);
     document.temperature.celsius.value=Math.round(celsius);
     document.temperature.kelvin.value=Math.round(kelvin);
     document.temperature.reaumur.value=Math.round(reaumur);
     return;
   }
    if (document.temperature.reaumur.value != ""){
      reaumur=pruef_reaumur(reaumur);
      celsius=reaumur2celsius(reaumur);
      fahrenheit=reaumur2fahrenheit(reaumur);
      kelvin=reaumur2kelvin(reaumur);
      document.temperature.fahrenheit.value=Math.round(fahrenheit);
      document.temperature.celsius.value=Math.round(celsius);
      document.temperature.kelvin.value=Math.round(kelvin);
      document.temperature.reaumur.value=Math.round(reaumur);
      return;
   }
 }


 function fahrenheit2celsius(fahrenheit){
   var celsius = 0;
   celsius = ( (10*fahrenheit/10) -32 )*5/9;
   return celsius;
 }

 function fahrenheit2kelvin(fahrenheit){
   var kelvin = 0;
  // kelvin = (( fahrenheit -32 )*5/9) + 273.15;
   kelvin = (9*fahrenheit/5) + 273.15;
   return kelvin;
 }

 function fahrenheit2reaumur(fahrenheit){
   var reaumur = 0;
   // reaumur = 4*((10*fahrenheit/10 -32 )*5/9)/5;
   reaumur = 4*(9*fahrenheit/5)/5;
   return reaumur;
 }

 function celsius2fahrenheit(celsius){
   var fahrenheit = 0;
   fahrenheit = (9*celsius/5) + 32;
   return fahrenheit;
 }

 function celsius2kelvin(celsius){
    var kelvin = 0;
    kelvin = 10*celsius/10 + 273.15;
    return kelvin;
 }

 function celsius2reaumur(celsius){
   var reaumur = 0;
   reaumur = 4*celsius/5;
   return reaumur;
 }

 function kelvin2fahrenheit(kelvin){
   var fahrenheit = 0;
   fahrenheit = (9*( (10*kelvin/10) -273.15)/5) + 32;
   return fahrenheit;
 }

 function kelvin2celsius(kelvin){
    var celsius = 0;
    celsius = 10*kelvin/10 - 273.15;
    return celsius;
 }

 function kelvin2reaumur(kelvin){
   var reaumur = 0;
   reaumur = 4*( (10*kelvin/10) -273.15)/5;
   return reaumur;
 }

 function reaumur2fahrenheit(reaumur){
   var fahrenheit = 0;
   fahrenheit = (9*(5*reaumur/4)/5) + 32;
   return fahrenheit;
 }

 function reaumur2celsius(reaumur){
    var celsius = 0;
    clesius = 5*reaumur/4;
    return clesius;
 }

 function reaumur2kelvin(reaumur){
   var kelvin = 0;
   kelvin = (5*reaumur/4) + 273.15;
   return kelvin;
 }

  function pruef_celsius(celsius){
    return celsius;
  }

  function pruef_fahrenheit(fahrenheit){
    return fahrenheit;
 }

  function pruef_kelvin(kelvin){
    if(!CheckZahl(kelvin))
     kelvin=0;
    return kelvin;
 }

   function pruef_reaumur(reaumur){;
     return reaumur;
 }

  function TLoeschen(){
    with(document.temperature){
      celsius.value="";
      fahrenheit.value="";
      kelvin.value="";
      reaumur.value="";
    }
 }

// calc Relat. feuchte
// Temperature berechnen
 function NeuTemp(){
  with(document.humidity){
   temp.value=Math.round(temp.value);
  }
 }

 function NeuDewp(){
  with(document.humidity){
   dewp.value=Math.round(dewp.value);
  }
 }

 function NeuRelf(){
  with(document.humidity){
   relf.value=Math.round(relf.value);
  }
 }


 function FBerechnen(){
   var temp=document.humidity.temp.value;
   var dewp=document.humidity.dewp.value;
   var relf=document.humidity.relf.value;
   if (document.humidity.temp.value != "" && document.humidity.dewp.value != ""){
     temp=pruef_temp(temp);
     dewp=pruef_dewp(dewp);
     relf=calc_from_temp_dewp(temp,dewp);
     document.humidity.temp.value=Math.round(temp);
     document.humidity.dewp.value=Math.round(dewp);
     document.humidity.relf.value=Math.round(relf);
     return;
   }

   if (document.humidity.temp.value != "" && document.humidity.relf.value != ""){
     temp=pruef_temp(temp);
     relf=pruef_relf(relf);
     dewp=calc_from_temp_relf(temp,relf);
     document.humidity.temp.value=Math.round(temp);
     document.humidity.dewp.value=Math.round(dewp);
     document.humidity.relf.value=Math.round(relf);
     return;
   }

 }

 function calc_from_temp_dewp(temp,dewp){
   var relf = 0;
   // relf = Math.round(100.0 * (Math.pow((112 - (0.1 * (temp-0)) + (dewp-0))/(112 + (0.9 * (dewp-0))),10)));
   relf = 100.0 * 6.09 * Math.pow(10, 7.5*dewp/(237.3 +Math.round(dewp) )) / (6.09 * Math.pow(10, 7.5*temp/(237.3+Math.round(temp) )) );
   return relf;
 }

 function calc_from_temp_relf(temp,relf){
   var dewp = 0;
   var f = parseInt(relf)/100;
   temp = parseInt(temp);
   dewp = 237.3/(1/(Math.log(f)/17.27+temp/(temp+237.3))-1);
   return dewp;
 }

// function calc_from_dewp_relf(dewp,relf){
//   var dewp = 0;
//   dewp = (relf/100)*temp;
//   return temp;
// }

  function pruef_temp(temp){
    return temp;
  }

  function pruef_dewp(dewp){
    return dewp;
 }

  function pruef_relf(relf){
   // if(!CheckZahl(relf))
   //  relf=0;
    return relf;
 }


  function FLoeschen(){
    with(document.humidity){
      temp.value="";
      dewp.value="";
      relf.value="";
    }
 }

// calc windchill
 function NeuWCHTemp(){
  with(document.windchill){
   temp.value=Math.round(temp.value);
  }
 }

 function NeuDWCHkmh(){
  with(document.windchill){
   kmh.value=Math.round(kmh.value);
  }
 }


 function WCHBerechnen(){
   var temp=document.windchill.temp.value;
   var kmh=document.windchill.kmh.value;
   var windchill=document.windchill.windchill.value;
   var windchill01=document.windchill.windchill01.value;
   if (document.windchill.temp.value != "" && document.windchill.kmh.value != ""){
     temp=pruef_temp(temp);
     kmh=pruef_kmh(kmh);
     windchill=calc_windchill(temp,kmh);
     windchill01=calc_windchill01(temp,kmh);
     document.windchill.temp.value=Math.round(temp);
     document.windchill.kmh.value=Math.round(kmh);
     document.windchill.windchill.value=Math.round(windchill);
     document.windchill.windchill01.value=Math.round(windchill01);
     return;
   }


 }

 function calc_windchill(temp,kmh){
   var windchill = 0;
   windchill = 0.045*( 5.27 * Math.pow(kmh, 0.5) + 10.45 - 0.28*kmh)*(Math.round(temp) - 33) + 33;
   return windchill;
 }

 function calc_windchill01(temp,kmh){
   var windchill01 = 0;
   var wind =0;
   temp = celsius2fahrenheit(temp);
   wind = kmh2mph(kmh);
   // windchill01 = 0.045*( 5.27 * Math.pow(kmh, 0.5) + 10.45 - 0.28*kmh)*(Math.round(temp) - 33) + 33;
   windchill01 = (35.74+0.6215*temp-35.75*Math.pow(wind,0.16)+0.4275*temp*Math.pow(wind,0.16));
   windchill01 = fahrenheit2celsius(windchill01);
   return windchill01;
 }

  function pruef_kmh(kmh){
   if(!CheckZahl(kmh))
   kmh=0;
    return kmh;
  }


  function WCHLoeschen(){
    with(document.windchill){
      temp.value="";
      kmh.value="";
      windchill.value="";
      windchill01.value="";
    }
 }

// calc heat index
// Temperature berechnen
 function NeuHeatTemp(){
  with(document.heatindex){
   temp.value=Math.round(temp.value);
  }
 }

 function NeuHeatRelf(){
  with(document.heatindex){
   relf.value=Math.round(relf.value);
  }
 }


 function WHeatBerechnen(){
   var temp=document.heatindex.temp.value;
   var relf=document.heatindex.relf.value;
   var heatindex=document.heatindex.heatindex.value;
   var heatindex_text=document.heatindex.heatindex_text.value;
   if (document.heatindex.temp.value != "" && document.heatindex.relf.value != ""){
     temp=pruef_temp(temp);
     relf=pruef_relf(relf);
     heatindex=calc_heatindex(temp,relf);
     if(heatindex ==-99)
     	{
     	heatindex = "";
     	heatindex_text = "KEINE GEFAHR";
     	}
     else {
	     heatindex_text=calc_heatindex_text(heatindex);
	     }
     document.heatindex.temp.value=Math.round(temp);
     document.heatindex.relf.value=Math.round(relf);
     document.heatindex.heatindex.value=Math.round(heatindex);
     document.heatindex.heatindex_text.value=heatindex_text;
     return;
   }


 }

 function calc_heatindex(temp,relf){
   var heatindex = 0;
   var t = Math.round(temp)*(9/5) +32;        // convert to fahrenheit
   var r = Math.round(relf)
   var t2=Math.pow(t, 2);
   var rh2=Math.pow(relf, 2);

   var index=-42.379 + 2.04901523*t + 10.14333127*r - 0.22475541*t*r - 6.83783e-03*t2 - 5.481717e-02*rh2 + 1.22874e-03*t2*r + 8.5282e-04*t*rh2 - 1.99e-06*t2*rh2;
   var heatindex = 5/9*(index-32);//convert to celsius
   if(t < 75){heatindex = -99}
   return heatindex;
 }

function calc_heatindex_text(heatindex){
   if (heatindex<26.67)
      var heatindex_text = "KEINE GEFAHR";

   else if  (heatindex<32.22)
      var heatindex_text = "VORSICHT: Bewegung ermüdender als üblich";

   else if  (heatindex<40.56)
      var heatindex_text ="GROSSE VORSICHT: Hitzekrämpfe, Erschöpfung möglich";

   else if  (heatindex<54.44)
      var heatindex_text ="GEFAHR: Erschöpfung wahrscheinlich";

   else
      var heatindex_text = "GROSSE GEFAHR: Gefahr von Hitzeschlag";

        return heatindex_text;
        }


  function WHeatLoeschen(){
    with(document.heatindex){
      temp.value="";
      relf.value="";
      heatindex.value="";
      heatindex_text.value="";
    }
 }

// calc Druck
 function NeuHpa(){
  with(document.druck){
   hpa.value=Math.round(hpa.value);
   mbar.value="";
   mmhg.value="";
   torr.value="";
   bar.value="";
   atm.value="";
  }
 }

 function NeuMbar(){
  with(document.druck){
   mbar.value=Math.round(mbar.value);
   hpa.value="";
   mmhg.value="";
   torr.value="";
   bar.value="";
   atm.value="";
  }
 }

 function NeuMmhg(){
  with(document.druck){
   mmhg.value=Math.round(mmhg.value);
   mbar.value="";
   hpa.value="";
   torr.value="";
   bar.value="";
   atm.value="";
  }
 }

 function NeuTorr(){
  with(document.druck){
   torr.value=Math.round(torr.value);
   mbar.value="";
   mmhg.value="";
   hpa.value="";
   bar.value="";
   atm.value="";
  }
 }

 function NeuBar(){
  with(document.druck){
   bar.value=Math.round(bar.value);
   mbar.value="";
   mmhg.value="";
   torr.value="";
   hpa.value="";
   atm.value="";
  }
 }

 function NeuAtm(){
  with(document.druck){
   atm.value=Math.round(atm.value);
   mbar.value="";
   mmhg.value="";
   torr.value="";
   bar.value="";
   hpa.value="";
  }
 }

 function DBerechnen(){

   if (document.druck.mbar.value != ""){
     document.druck.hpa.value=document.druck.mbar.value;
   }

   var hpa=document.druck.hpa.value;
   var mbar=document.druck.mbar.value;
   var mmhg=document.druck.mmhg.value;
   var torr=document.druck.torr.value;
   var bar=document.druck.bar.value;
   var atm=document.druck.atm.value;

   if (document.druck.hpa.value != ""){
     hpa=pruef_hpa(hpa);
     mmhg=hpa2mmhg(hpa);
     torr=hpa2torr(hpa);
     bar=hpa2bar(hpa);
     atm=hpa2atm(hpa);
     document.druck.hpa.value=roundit(hpa);
     document.druck.mbar.value=roundit(hpa);
     document.druck.mmhg.value=roundit(mmhg);
     document.druck.torr.value=roundit(torr);
     document.druck.bar.value=roundit(bar);
     document.druck.atm.value=roundit(atm);
     return;
   }

   if (document.druck.mmhg.value != ""){
     mmhg=pruef_mmhg(mmhg);
     hpa=mmhg2hpa(mmhg);
     torr=mmhg2torr(mmhg);
     bar=mmhg2bar(mmhg);
     atm=mmhg2atm(mmhg);
     document.druck.hpa.value=roundit(hpa);
     document.druck.mbar.value=roundit(hpa);
     document.druck.mmhg.value=roundit(mmhg);
     document.druck.torr.value=roundit(torr);
     document.druck.bar.value=roundit(bar);
     document.druck.atm.value=roundit(atm);
     return;
   }

    if (document.druck.torr.value != ""){
      torr=pruef_torr(torr);
      mmhg=torr2mmhg(torr);
      hpa=torr2hpa(torr);
      bar=torr2bar(torr);
      atm=torr2atm(torr);
      document.druck.hpa.value=roundit(hpa);
      document.druck.mbar.value=roundit(hpa);
      document.druck.mmhg.value=roundit(mmhg);
      document.druck.torr.value=roundit(torr);
      document.druck.bar.value=roundit(bar);
      document.druck.atm.value=roundit(atm);
      return;
   }

    if (document.druck.bar.value != ""){
      bar=pruef_bar(bar);
      mmhg=bar2mmhg(bar);
      torr=bar2torr(bar);
      hpa=bar2hpa(bar);
      atm=bar2atm(bar);
      document.druck.hpa.value=roundit(hpa);
      document.druck.mbar.value=roundit(hpa);
      document.druck.mmhg.value=roundit(mmhg);
      document.druck.torr.value=roundit(torr);
      document.druck.bar.value=roundit(bar);
      document.druck.atm.value=roundit(atm);
      return;
   }

    if (document.druck.atm.value != ""){
      atm=pruef_hpa(atm);
      mmhg=atm2mmhg(atm);
      torr=atm2torr(atm);
      bar=atm2bar(atm);
      hpa=atm2hpa(atm);
      document.druck.hpa.value=Math.round(hpa);
      document.druck.mbar.value=Math.round(hpa);
      document.druck.mmhg.value=Math.round(mmhg);
      document.druck.torr.value=Math.round(torr);
      document.druck.bar.value=Math.round(bar);
      document.druck.atm.value=Math.round(atm);
      return;
   }

 }

 function calc_windchill(temp,kmh){
   var windchill = 0;
   windchill = 0.045*( 5.27 * Math.pow(kmh, 0.5) + 10.45 - 0.28*kmh)*(Math.round(temp) - 33) + 33;
   return windchill;
 }

 function hpa2mmhg(hpa) {
   var mmhg = 0;
   mmhg = hpa/1.33;
   return mmhg;
   }

 function hpa2torr(hpa) {
   var torr = 0;
   torr = hpa/1.33;;
   return torr;
   }

 function hpa2bar(hpa) {
   var bar = 0;
   bar = hpa/1000;
   return bar;
   }

 function hpa2atm(hpa) {
   var atm = 0;
   atm = hpa/1013.25 ;
   return atm;
   }

 function mmhg2hpa(mmhg) {
   var hpa = 0;
   hpa = mmhg*1.33;
   return hpa;
   }

 function mmhg2torr(mmhg) {
   var torr = 0;
   torr = mmhg;
   return torr;
   }

 function mmhg2bar(mmhg) {
   var bar = 0;
   bar = mmhg*1.33/1000;
   return bar;
   }

 function mmhg2atm(mmhg) {
   var atm = 0;
   atm = mmhg/760;
   return atm;
   }

 function torr2mmhg(torr) {
   var mmhg = 0;
   mmhg = torr;
   return mmhg;
   }

 function torr2hpa(torr) {
   var hpa = 0;
   hpa = torr*1.33;
   return hpa;
   }

 function torr2bar(torr) {
   var bar = 0;
   bar = torr*1.33/1000;
   return bar;
   }

 function torr2atm(torr) {
   var atm = 0;
   atm = torr/760;
   return atm;
   }

 function bar2mmhg(bar) {
   var mmhg = 0;
   mmhg = bar*1000/1.33322;
   return mmhg;
   }

 function bar2torr(bar) {
   var torr = 0;
   torr = bar*1000/1.333322;
   return torr;
   }

 function bar2hpa(bar) {
   var hpa = 0;
   hpa = bar*1000;
   return hpa;
   }

 function bar2atm(bar) {
   var atm = 0;
   atm = bar*1013.25/1000;
   return atm;
   }

 function atm2mmhg(atm) {
   var mmhg = 0;
   mmhg = atm*760;
   return mmhg;
   }

 function atm2torr(atm) {
   var torr = 0;
   torr = atm*760;
   return torr;
   }

 function atm2bar(atm) {
   var bar = 0;
   bar = atm*1000/1013.25;
   return bar;
   }

 function atm2hpa(atm) {
   var hpa = 0;
   hpa = atm*1013.25;
   return hpa;
   }

function pruef_hpa(hpa){
   if(!CheckZahl(hpa))
   hpa=0;
    return hpa;
  }

function pruef_mmhg(mmhg){
   if(!CheckZahl(mmhg))
   mmhg=0;
    return mmhg;
  }

function pruef_torr(torr){
   if(!CheckZahl(torr))
   torr=0;
    return torr;
  }

function pruef_bar(bar){
   if(!CheckZahl(bar))
   bar=0;
    return bar;
  }

function pruef_atm(atm){
   if(!CheckZahl(atm))
   atm=0;
    return atm;
  }


  function DLoeschen(){
    with(document.druck){
      hpa.value="";
      mbar.value="";
      mmhg.value="";
      torr.value="";
      bar.value="";
      atm.value="";
    }
 }

 // calc Schneefallgrenze
  function NeuSchneeTemp(){
   with(document.schneefallgrenze){
    temp.value=Math.round(temp.value);
   }
  }

  function NeuSchneeGeopot(){
   with(document.schneefallgrenze){
    geopot.value=Math.round(geopot.value);
   }
  }


  function SchneeBerechnen(){
    var temp=document.schneefallgrenze.temp.value;
    var geopot=document.schneefallgrenze.geopot.value;
    var schneefallgrenze=document.schneefallgrenze.schneefallgrenze.value;
    if (document.schneefallgrenze.temp.value != "" && document.schneefallgrenze.geopot.value != ""){
      temp=pruef_temp(temp);
      geopot=pruef_geopot(geopot);
      schneefallgrenze=calc_schneefallgrenze(temp,geopot);
      document.schneefallgrenze.temp.value=Math.round(temp);
      document.schneefallgrenze.geopot.value=Math.round(geopot);
      document.schneefallgrenze.schneefallgrenze.value=Math.round(schneefallgrenze);
      return;
    }


  }

  function calc_schneefallgrenze(temp,geopot){
    var schneefallgrenze = 0;
    schneefallgrenze = 153.0*Math.round(temp) + 0.9985*Math.round(geopot) - 304.26;;
    return schneefallgrenze;
  }

   function pruef_geopot(geopot){
    if(!CheckZahl(geopot))
    geopot=0;
     return geopot;
   }


   function SchneeLoeschen(){
     with(document.schneefallgrenze){
       temp.value="";
       geopot.value="";
       schneefallgrenze.value="";
     }
  }

// calc Stationsdruck
 function NeuSDTemp(){
  with(document.stationsdruck){
   temp.value=roundit(temp.value);
  }
 }

 function NeuSDHoehe(){
  with(document.stationsdruck){
   hoehe.value=roundit(hoehe.value);
  }
 }


 function NeuSDStationsdruck(){
  with(document.stationsdruck){
   stationsdruck.value=roundit(stationsdruck.value);
  }
 }

 function NeuSDNndruck(){
  with(document.stationsdruck){
   nndruck.value=roundit(nndruck.value);
  }
 }


 function SDBerechnen(){
   var temp=document.stationsdruck.temp.value;
   var stationsdruck=document.stationsdruck.stationsdruck.value;
   var nndruck=document.stationsdruck.nndruck.value;
   var hoehe=document.stationsdruck.hoehe.value;
   if (document.stationsdruck.temp.value != "" && document.stationsdruck.stationsdruck.value != "" && document.stationsdruck.hoehe.value != ""){
     temp=pruef_temp(temp);
     // stationsdruck=pruef_stationsdruck(stationsdruck);
     hoehe=pruef_hoehe(hoehe);
     nndruck=calc_nndruck(temp,stationsdruck,hoehe);
     document.stationsdruck.temp.value=roundit(temp);
     document.stationsdruck.stationsdruck.value=roundit(stationsdruck);
     document.stationsdruck.nndruck.value=roundit(nndruck);
     return;
   }

   if (document.stationsdruck.temp.value != "" && document.stationsdruck.nndruck.value != "" && document.stationsdruck.hoehe.value != ""){
     temp=pruef_temp(temp);
     // stationsdruck=pruef_stationsdruck(stationsdruck);
     hoehe=pruef_hoehe(hoehe);
     stationsdruck=calc_stationsdruck(temp,nndruck,hoehe);
     document.stationsdruck.temp.value=roundit(temp);
     document.stationsdruck.stationsdruck.value=roundit(stationsdruck);
     document.stationsdruck.nndruck.value=roundit(nndruck);
     return;
   }


 }

 function calc_nndruck(temp,stationsdruck,hoehe){
   temp = 10*temp/10;
   stationsdruck = 10*stationsdruck/10;
   hoehe = 10*hoehe/10;
   var nndruck = 0;
   var g = 9.81;
   var R = 287.0;
   var tmean = temp + 0.003*hoehe +273.15;
    nndruck = stationsdruck/Math.exp(-g*hoehe/(tmean*R) );
   return nndruck;
 }

 function calc_stationsdruck(temp,nndruck,hoehe){
   temp = 10*temp/10;
   nndruck = 10*nndruck/10;
   hoehe = 10*hoehe/10;
   var stationsdruck = 0;
   var g = 9.81;
   var R = 287.0;
   var tmean = temp + 0.003*hoehe +273.15;
    stationsdruck = nndruck*Math.exp(-g*hoehe/(tmean*R) );
   return stationsdruck;
 }

  function pruef_hoehe(hoehe){
  // if(!CheckZahl(hoehe))
  //  hoehe=0;
    return hoehe;
  }

  function pruef_stationsdruck(stationsdruck){
   if(!CheckZahl(stationsdruck))
   stationsdruck=0;
    return stationsdruck;
  }

  function SDLoeschen(){
    with(document.stationsdruck){
      temp.value="";
      hoehe.value="";
      nndruck.value="";
      stationsdruck.value="";
    }
 }

 // calc Wolkenbasis
  function NeuCloudbaseTemp(){
   with(document.cloudbase){
    temp.value=Math.round(temp.value);
   }
  }

  function NeuCloudbaseDewp(){
   with(document.cloudbase){
    dewp.value=Math.round(dewp.value);
   }
  }


  function CloudbaseBerechnen(){
    var temp=document.cloudbase.temp.value;
    var dewp=document.cloudbase.dewp.value;
    var cloudbase=document.cloudbase.cloudbase.value;
    if (document.cloudbase.temp.value != "" && document.cloudbase.dewp.value != ""){
      temp=pruef_temp(temp);
      dewp=pruef_dewp(dewp);
      cloudbase=calc_cloudbase(temp,dewp);
      cloudtemp=calc_cloudtemp(temp,cloudbase);
      document.cloudbase.temp.value=Math.round(temp);
      document.cloudbase.dewp.value=Math.round(dewp);
      document.cloudbase.cloudbase.value=Math.round(cloudbase);
      document.cloudbase.cloudtemp.value=Math.round(cloudtemp);
      return;
    }


  }

  function calc_cloudbase(temp,dewp){
    var cloudbase = 0;
    cloudbase = (parseFloat(temp) - parseFloat(dewp)) / 0.00802;
    return cloudbase;
  }

  function calc_cloudtemp(temp,cloudbase){
    var cloudtemp = 0;
    cloudtemp = -0.00984*(parseFloat(cloudbase) ) + parseFloat(temp);
    return cloudtemp;
  }

   function CloudbaseLoeschen(){
     with(document.cloudbase){
       temp.value="";
       dewp.value="";
       cloudbase.value="";
       cloudtemp.value="";
     }
  }
