// Windspeed Converter
 
<!--
 function NewKnots(){
   with(document.wind){     
     ms.value="";
     knots.value=Math.round(knots.value);
     beaufort.value="";
     kmh.value="";
     mph.value="";
   }
 }

 function NewMph(){
   with(document.wind){     
     ms.value="";
     knots.value="";
     beaufort.value="";
     kmh.value="";
     mph.value=Math.round(mph.value);
   }
 }

 function NewKmh(){
   with(document.wind){     
     ms.value="";
     knots.value="";
     beaufort.value="";
     kmh.value=Math.round(kmh.value);
     mph.value="";
   }
 }

 function NewMs(){
   with(document.wind){     
     ms.value=Math.round(ms.value);
     knots.value="";
     beaufort.value="";
     kmh.value="";
     mph.value="";
   }
 }

 function NewBeaufort(){
   with(document.wind){     
     ms.value="";
     knots.value="";
     kmh.value="";
     mph.value="";
   }
 }
 
function CheckNumber(Input){
  var nur_das ="0123456789";
  for (var i = 0; i < Input.length; i++)
   if (nur_das.indexOf(Input.charAt(i))<0 ) return false;
  return true;
 }

 function examine_ms(ms){
   if(ms<0)
     ms=0;
   if(!CheckNumber(ms))
     ms=0;

   return ms;
 }

 function examine_kmh(kmh){
   if(kmh<0)
     kmh=0;
   if(!CheckNumber(kmh))
     kmh=0;

   return kmh;
 }

 function examine_mph(mph){
   if(mph<0)
     mph=0;
   if(!CheckNumber(mph))
     mph=0;

   return mph;
 }


 function examine_knots(knots){
   if(knots<0)
     knots=0;
   if(!CheckNumber(knots))
     knots=0;

   return knots;
 }

 function examine_beaufort(beaufort){
   if(beaufort<0)
     beaufort=0;
   if(beaufort>12)
     beaufort=0;

   if(!CheckNumber(beaufort))
     beaufort=0;

   return beaufort;
 }

 function kmh2ms(kmh){
   ms=0;
   ms=kmh/3.6;

   //return Math.round(ms);
   return ms;
 }

 function kmh2mph(kmh){
   mph=0;
   mph=0.6215*kmh;

   //return Math.round(mph);
   return mph;
 }

 function ms2knots(ms){
   var knots=0;
   knots=1.9438*ms;
   //return Math.round(knots);
   return knots;
 }

 function kmh2knots(kmh){
   knots=0;
   ms=0;
   ms=kmh2ms(kmh);
   knots=ms2knots(ms);

   return knots;
 }


 function knots2beaufort(knots){
 
   if (knots==0)
    return 0;
   if (knots<=3)
    return 1;
   if (knots<=6)
    return 2;
   if (knots<=10)
    return 3;
   if (knots<=15)
    return 4;
   if (knots<=21)
    return 5;
   if (knots<=27)
    return 6;
   if (knots<=33)
    return 7;
   if (knots<=40)
    return 8;
   if (knots<=47)
    return 9;
   if (knots<=55)
    return 10;
   if (knots<=63)
    return 11;
   else
    return 12;   
 }


 function ms2kmh(ms){
   var kmh=0;
   kmh=ms*3.6;
   //return Math.round(kmh);
   return kmh;
 }

 function ms2mph(ms){
   var mph=0;
   var kmh=0;
   kmh=ms2kmh(ms);
   mph=kmh2mph(kmh);
   
   //return Math.round(mph); 
   return mph;
 }

 function mph2kmh(mph){
   var kmh=0;
   kmh=1.609*mph;

   //return Math.round(kmh);
   return kmh;
 }

 function mph2ms(mph){
   var ms=0;
   var kmh=0;

   kmh=mph2kmh(mph);
   ms=kmh2ms(kmh);

   //return Math.round(ms);
   return ms;
 }

 function mph2knots(mph){
  var knots=0;
  var ms=0;

  ms=mph2ms(mph);
  knots=ms2knots(ms);

  //return Math.round(knots);
  return knots;

 }

 function mph2beaufort(mph){
   var beaufort=0;
   var knots=0;

   knots=mph2knots(mph);
   beaufort=knots2beaufort(knots);

   return beaufort;

 }

 function ms2beaufort(ms){
   var knots=0;
   var beaufort=0;
   knots=ms2knots(ms);
   beaufort=knots2beaufort(knots);

   return beaufort;   
 }

 function kmh2beaufort(kmh){
   beaufort=0;
   ms=0;
   ms=kmh2ms(kmh);
   beaufort=ms2beaufort(ms);

   return beaufort;
 }

 function knots2ms(knots){
   var ms=0;
   ms = 0.51444*knots
   //return Math.round(ms);
   return ms;
 }

 function knots2mph(knots){
   var mph=0;
   ms=0;
   ms=knots2ms(knots);
   mph=ms2mph(ms);

   return mph;
 }

 function knots2kmh(knots){
   var ms=0;
   var kmh=0;
   ms=knots2ms(knots);
   kmh=ms2kmh(ms);

   return kmh;
 }


 function beaufort2knots(beaufort){
   var knots="0";


   if(beaufort==1)
     knots="1-3"
   if(beaufort==2)
     knots="4-6"
   if(beaufort==3)
     knots="7-10"
   if(beaufort==4)
     knots="11-15"
   if(beaufort==5)
     knots="16-21"
   if(beaufort==6)
     knots="22-27"
   if(beaufort==7)
     knots="28-33"
   if(beaufort==8)
     knots="34-40"
   if(beaufort==9)
     knots="41-47"
   if(beaufort==10)
     knots="48-55"
   if(beaufort==11)
     knots="56-63"
   if(beaufort==12)
     knots=">64"
   
   return knots;   
 }

 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 Calculate(){
   var ms=document.wind.ms.value;
   var knots=document.wind.knots.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=examine_ms(ms);
     knots=ms2knots(ms);
     beaufort=ms2beaufort(ms);
     kmh=ms2kmh(ms);
     mph=ms2mph(ms);
     document.wind.knots.value=Math.round(knots);
     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.knots.value != ""){
     knots=examine_knots(knots);
     ms=knots2ms(knots);
     beaufort=knots2beaufort(knots);
     kmh=knots2kmh(knots);
     mph=knots2mph(knots);
     document.wind.ms.value=Math.round(ms);
     document.wind.beaufort.value=Math.round(beaufort);     
     document.wind.knots.value=Math.round(knots);
     document.wind.kmh.value=Math.round(kmh);
     document.wind.mph.value=Math.round(mph);
     return;
   }
   if (document.wind.beaufort.value != ""){
     beaufort=examine_beaufort(beaufort);
     ms=beaufort2ms(beaufort);
     knots=beaufort2knots(beaufort);
     kmh=beaufort2kmh(beaufort);
     mph=beaufort2mph(beaufort);
     document.wind.ms.value=ms;
     document.wind.knots.value=knots;     
     document.wind.beaufort.value=beaufort;
     document.wind.kmh.value=kmh;
     document.wind.mph.value=mph;
     return;
   }
   if (document.wind.kmh.value != ""){
     kmh=examine_kmh(kmh);
     ms=kmh2ms(kmh);
     knots=kmh2knots(kmh);
     beaufort=kmh2beaufort(kmh);
     mph=kmh2mph(kmh);
     document.wind.ms.value=Math.round(ms);
     document.wind.knots.value=Math.round(knots);     
     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=examine_mph(mph);
     ms=mph2ms(mph);
     knots=mph2knots(mph);
     beaufort=mph2beaufort(mph);
     kmh=mph2kmh(mph);
     document.wind.ms.value=Math.round(ms);
     document.wind.knots.value=Math.round(knots);     
     document.wind.beaufort.value=Math.round(beaufort);
     document.wind.kmh.value=Math.round(kmh);
     document.wind.mph.value=Math.round(mph);
     return;
   }


 }


 function Delete(){
   with(document.wind){
     ms.value="";
     knots.value="";
     beaufort.value="";
     kmh.value="";
     mph.value="";
   }
 }

 function new_knots(){
   with(document.wind){
     knots.value=Math.round(knots.value);
     ms.value="";
     beaufort.value="";
     kmh.value="";
     mph.value="";
   }
 }


