// BEGIN VARIABLES



   // General variables

   var version = 0;



   // Weerrekenaar Popup specific variables

   var windowOpener = parent.opener;



   // END VARIABLES



   // BEGIN CODE



   // General code

   if (navigator.userAgent.indexOf("Mozilla/3.0") != -1) version = 3;

   else if (navigator.userAgent.indexOf("Mozilla/4.0") !=-1) version = 3;

   else if (navigator.userAgent.indexOf("Mozilla/2.0") != -1) version = 2;

   else if (navigator.userAgent.indexOf("MSIE") != -1) version = 2;

   else version = 0;

   if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Mac") != -1) version = 1;

   

   // Weerrekenaar conversion functions

   function replaceComma (str) {

      nstr = "";

      for (i=0; i<str.length; i++) {

         if (str.charAt(i)==',') {

            nstr += '.';

         } else {

            nstr += str.charAt(i);

         }

      }

      return nstr;

   }

   

   function ISnAn (str) {

      nstr = "" + str;

      if (nstr=="") {

         return true;

      }

      for (i=0; i<nstr.length; i++) {

         if (nstr.charAt(i)!='.' && nstr.charAt(i)!='-' && nstr.charAt(i)!='+') {

            if (nstr.charAt(i)<'0' || nstr.charAt(i)>'9') {

               return true;

            }

         }

      }

      return false;

   }





   function afronden(number,len) {

      //meer chop dan afronden

      var str = ""+number; // viezigheid vanwege MSIE

      if (ISnAn(len)) {

         len = 1;

      }

      if (str.indexOf(".")==-1) {

         return str;

      } else {

         if (len==0) {

            return str.substring(0,str.indexOf(".")+len);

         } else {

            return str.substring(0,str.indexOf(".")+len+1);

         }

      }

   }



   function c2f(t) {

      var temp = parseFloat(t);

      celsius    = temp;

      fahrenheit = (temp*9/5) + 32;

      return afronden(fahrenheit,1);

   }



   function f2c(t) {

      var temp    = parseFloat(t);

      celsius     = 5/9 * (temp - 32);

      fahrenheit  = temp;

      return afronden(celsius,1);

   }



   var tempOK = false;



   function processTemp(f) {

      if (f.textTemp.value!="") {

         f.textTemp.value = replaceComma(f.textTemp.value);

      }

      if (ISnAn(f.textTemp.value) || f.textTemp.value=="") {

         f.tempOut.value = "Vul een waarde in";

         tempOK = false;

      } else {

         if (f.tempUnit.options[f.tempUnit.options.selectedIndex].value=="c") {

            var t = c2f(f.textTemp.value);

            f.tempOut.value = t + " Fahrenheit";

         } else {

            var t = f2c(f.textTemp.value);

            f.tempOut.value = t + " Celsius";

         }

         tempOK = true;

      }

   }



   var windOK = false;

   beauf     = new Array;

   beauf[0]  = 0.2;

   beauf[1]  = 1.5;

   beauf[2]  = 3.3;

   beauf[3]  = 5.4;

   beauf[4]  = 7.9;

   beauf[5]  = 10.7;

   beauf[6]  = 13.8;

   beauf[7]  = 17.1;

   beauf[8]  = 20.7;

   beauf[9]  = 24.4;

   beauf[10] = 28.4;

   beauf[11] = 32.6;





   function b2ms(wk) {

      if (wk==0) {

         ms  = beauf[wk]/2;

         ms1 = 0;

         ms2 = beauf[wk];

      }

      if (wk>0 && wk<12) {

         ms  = (beauf[wk-1] + beauf[wk]) / 2;

         ms1 = beauf[wk-1];

         ms2 = beauf[wk];

      }

      if (wk==12) {

         ms  = beauf[11];

         ms1 = beauf[11];

         ms2 = "-1";

      }

   }



   function ms2b(wk) {

      for (var i=12; i>0; i--) {

         if (wk>beauf[i-1]) {

            beaufort = i;

            return i;

         }

      }

      beaufort = 0;

      return "0";

   }



   function processWind(f) {

      if (f.textWind.value!="") {

         f.textWind.value = replaceComma(f.textWind.value);

      }

      if (ISnAn(f.textWind.value) || f.textWind.value=="" || parseFloat(f.textWind.value)<0 || (parseInt(f.textWind.value)>12 && f.wkUnitIn.options[f.wkUnitIn.options.selectedIndex].value=="b")) {

         f.windOut.value = "Vul een waarde in";

         windOK = false;

      } else {

         var wk = parseFloat(f.textWind.value);

         if (f.wkUnitIn.options[f.wkUnitIn.options.selectedIndex].value=="b") {

            beaufort = afronden(f.textWind.value,0);

            f.textWind.value = beaufort;

            wk = beaufort;

            b2ms(wk);

            if (ms2!="-1") {

               kmu      = "> " + afronden((ms1/1000*3600),1) + " en < " + afronden((ms2/1000*3600),1);

               knopen   = "> " + afronden(ms1*1.94254,1)     + " en < " + afronden(ms2*1.94254,1);

               ms       = "> " + ms1 + " en < " + ms2;

            } else {

               kmu      = "> " + afronden((ms1/1000*3600),1);

               knopen   = "> " + afronden(ms1*1.94254,1);

               ms       = "> " + ms1;

            }

         }

         if (f.wkUnitIn.options[f.wkUnitIn.options.selectedIndex].value=="ms") {

            beaufort = ms2b(wk);

            ms       = f.textWind.value;

            kmu      = afronden((wk/1000)*3600,1);

            knopen   = afronden(wk*1.94254,1);

         }

         if (f.wkUnitIn.options[f.wkUnitIn.options.selectedIndex].value=="kmu") {

            ms       = (wk/3600)*1000;

            beaufort = ms2b(ms);

            kmu      = f.textWind.value;

            knopen   = afronden(ms*1.94254,1);

            ms       = afronden(ms,1);

         }

         if (f.wkUnitIn.options[f.wkUnitIn.options.selectedIndex].value=="knopen") {

            ms       = wk/1.94254;

            beaufort = ms2b(ms);

            kmu      = afronden((ms/1000)*3600,1);

            knopen   = f.textWind.value;

            ms       = afronden(ms,1);

         }

         if (f.wkUnitOut.options[f.wkUnitOut.options.selectedIndex].value=="b") {

            f.windOut.value = beaufort;

         }

         if (f.wkUnitOut.options[f.wkUnitOut.options.selectedIndex].value=="ms") {

            f.windOut.value = ms;

         }

         if (f.wkUnitOut.options[f.wkUnitOut.options.selectedIndex].value=="kmu") {

            f.windOut.value = kmu;

         }

         if (f.wkUnitOut.options[f.wkUnitOut.options.selectedIndex].value=="knopen") {

            f.windOut.value = knopen;

         }

         windOK = true;

      }

   }



   function windchill(t,wk) {

      b2ms(wk);

      var mph;

      mph = ms / 0.44704;

      var windchill = 0.0817 * (3.71*Math.pow(mph,0.5) + 5.81 - 0.25*mph) * ((t*9/5) + 32 - 91.4) + 91.4;

      windchill = 5/9 * (windchill - 32);

      return afronden(windchill,1);

   }



   function processChill(f) {

      ok = true;

      var wk = parseInt(f.selectChillW.options[f.selectChillW.options.selectedIndex].value);

      if (ISnAn(f.textChillT.value)) {

         ok = false;

      } else {

         var t = parseFloat(replaceComma(f.textChillT.value));

      }

      if (!ok || wk<0 || wk>12) {

         f.chillOutC.value = "Vul een waarde in";

      } else {

         f.chillOutC.value = windchill(t,wk);

      }

   }



   // Weerrekenaar Popup specific code

   function setClosed () {

      if (version != 3) {

         if (windowOpener) windowOpener.weerrekenaarPopupWindow = null;

      }

      if (version == 1) {

         if (windowOpener != null) {

            windowOpener.setWeerrekenaarPopupWindowClosed ();

         }

      }

   }



   // END CODE
