function Converter(args){this._initialize(args);};Converter.prototype={ERROR_MESSAGE_BEAUFORT:"Please use only numbers between 1 and 12",ERROR_MESSAGE_STANDARD:"No negative values and characters",_form:null,_error:null,_knotsField:null,_msField:null,_beaufortField:null,_kmhField:null,_mphField:null,_clear:function(aElem){aElem.value="";},clearAll:function(){this._clear(this._knotsField);this._clear(this._msField);this._clear(this._beaufortField);this._clear(this._kmhField);this._clear(this._mphField);},calculate:function(){var value=null;var from=this._detectActiveField();switch(from){case"knots":value=this._checkStandard(this._knotsField.value);if(value){var result=this._convertKnots(value);this._assign(result);}
else{this._reportError(this.ERROR_MESSAGE_STANDARD);}
break;case"ms":value=this._checkMs(this._msField.value);if(value){var result=this._convertMs(value);this._assign(result);}
else{this._reportError(this.ERROR_MESSAGE_STANDARD);}
break;case"beaufort":value=this._checkBeaufort(this._beaufortField.value);this._beaufortField.value=value;if(value){var result=this._convertBeaufort(value);this._assign(result);}
else{this._reportError(this.ERROR_MESSAGE_BEAUFORT);}
break;case"kmh":value=this._checkStandard(this._kmhField.value);if(value){var result=this._convertKmh(value);this._assign(result);}
else{this._reportError(this.ERROR_MESSAGE_STANDARD);}
break;case"mph":value=this._checkStandard(this._mphField.value);if(value){var result=this._convertMph(value);this._assign(result);}
else{this._reportError(this.ERROR_MESSAGE_STANDARD);}
break;default:break;}},prepare:function(field){this._clearErrors();switch(field){case"knots":this._clear(this._msField);this._clear(this._beaufortField);this._clear(this._kmhField);this._clear(this._mphField);break;case"ms":this._clear(this._knotsField);this._clear(this._beaufortField);this._clear(this._kmhField);this._clear(this._mphField);break;case"beaufort":this._clear(this._knotsField);this._clear(this._msField);this._clear(this._kmhField);this._clear(this._mphField);break;case"kmh":this._clear(this._knotsField);this._clear(this._msField);this._clear(this._beaufortField);this._clear(this._mphField);break;case"mph":this._clear(this._knotsField);this._clear(this._msField);this._clear(this._beaufortField);this._clear(this._kmhField);break;default:break;}},_initialize:function(formNames){this._form=eval("document."+formNames["form"]);this._knotsField=eval("document."+formNames["form"]+"."+formNames["knots"]);this._msField=eval("document."+formNames["form"]+"."+formNames["ms"]);this._beaufortField=eval("document."+formNames["form"]+"."+formNames["beaufort"]);this._kmhField=eval("document."+formNames["form"]+"."+formNames["kmh"]);this._mphField=eval("document."+formNames["form"]+"."+formNames["mph"]);if(document.getElementById(formNames["error"]))
this._error=document.getElementById(formNames["error"]);},_reportError:function(message){if(this._error!=null)
{this._error.innerHTML=message;}},_clearErrors:function(){if(this._error!=null){this._error.innerHTML="";}},_checkBeaufort:function(value){if(value!="")
{if(value.substring(0,1)=="0")
{value=value.substring(1,value.length-1)}
var result=parseInt(value);if((result>=1)&&(result<=12)){return result;}
else{return false;}}
return false;},_checkMs:function(value){if(value!="")
{value=value.replace(/(\d),(\d)/g,'$1.$2');if(parseFloat(value)>0)
{return parseFloat(value);}
else{return false;}}
return false;},_checkStandard:function(value){if(value!="")
{if(value.substring(0,1)=="0")
{value=value.substring(1,value.length-1)}
if(parseFloat(value)>0)
{return parseFloat(value);}
else{return false;}}
return false;},_convertKnots:function(knots){var result=new Array();result["ms"]=this._convertWindspeed(knots,"kts","m/s");result["beaufort"]=this._convertWindspeed(knots,"kts","bft");result["kmh"]=this._convertWindspeed(knots,"kts","kmh");result["mph"]=this._convertWindspeed(knots,"kts","mph");return result;},_convertMs:function(ms){var result=new Array();result["knots"]=this._convertWindspeed(ms,"m/s","kts");result["beaufort"]=this._convertWindspeed(ms,"m/s","bft");result["kmh"]=this._convertWindspeed(ms,"m/s","kmh");result["mph"]=this._convertWindspeed(ms,"m/s","mph");return result;},_convertBeaufort:function(beaufort){var result=new Array();result["knots"]=this._convertWindspeed(beaufort,"bft","kts");result["ms"]=this._convertWindspeed(beaufort,"bft","m/s");result["kmh"]=this._convertWindspeed(beaufort,"bft","kmh");result["mph"]=this._convertWindspeed(beaufort,"bft","mph");return result;},_convertKmh:function(kmh){var result=new Array();result["knots"]=this._convertWindspeed(kmh,"kmh","kts");result["ms"]=this._convertWindspeed(kmh,"kmh","m/s");result["beaufort"]=this._convertWindspeed(kmh,"kmh","bft");result["mph"]=this._convertWindspeed(kmh,"kmh","mph");return result;},_convertMph:function(mph){var result=new Array();result["knots"]=this._convertWindspeed(mph,"mph","kts");result["ms"]=this._convertWindspeed(mph,"mph","m/s");result["beaufort"]=this._convertWindspeed(mph,"mph","bft");result["kmh"]=this._convertWindspeed(mph,"mph","kmh");return result;},_bft2knots:function(bft){var knots=0;if(bft>=12)knots=63;else if(bft==11)knots=56;else if(bft==10)knots=48;else if(bft==9)knots=41;else if(bft==8)knots=34;else if(bft==7)knots=28;else if(bft==6)knots=22;else if(bft==5)knots=16;else if(bft==4)knots=11;else if(bft==3)knots=7;else if(bft==2)knots=4;else if(bft==1)knots=1;else knots=0;return knots;},_knots2bft:function(knots){var bft=0;if(knots>=63)bft=12;if(knots<63.55)bft=11;if(knots<55.38)bft=10;if(knots<47.61)bft=9;if(knots<40.42)bft=8;if(knots<33.42)bft=7;if(knots<27.01)bft=6;if(knots<20.99)bft=5;if(knots<15.5503)bft=4;if(knots<10.6008)bft=3;if(knots<6.60890)bft=2;if(knots<3.11008)bft=1;if(knots<0.38876)bft=0;return bft;},_convertWindspeed:function(windspeed,unit_in,unit_out){var tmp=999;var result=999;if(unit_in==unit_out)return windspeed;if(windspeed!=999&&windspeed!=""){if(unit_in=='kts'){tmp=windspeed;}
else if(unit_in=='bft'){tmp=this._bft2knots(windspeed);}
else if(unit_in=='m/s'){tmp=windspeed*1.9438;}
else if(unit_in=='kmh'){tmp=windspeed/1.852;}
else if(unit_in=='mph'){tmp=windspeed*0.868;}
if(unit_out=='kts'){result=Math.floor(tmp+0.5)}
else if(unit_out=='bft'){result=this._knots2bft(tmp);}
else if(unit_out=='m/s'){result=Math.floor(tmp*0.5144+0.5);}
else if(unit_out=='kmh'){result=Math.floor(tmp*1.852+0.5);}
else if(unit_out=='mph'){result=Math.floor(tmp*1.15+0.5);}}
return result;},_assign:function(result){if(result["knots"]!=null)
this._knotsField.value=result["knots"];if(result["ms"]!=null)
this._msField.value=result["ms"];if(result["beaufort"]!=null)
this._beaufortField.value=result["beaufort"];if(result["kmh"]!=null)
this._kmhField.value=result["kmh"];if(result["mph"]!=null)
this._mphField.value=result["mph"];},_detectActiveField:function(){if(this._knotsField.value!="")
return"knots";else if(this._msField.value!="")
return"ms";else if(this._beaufortField.value!="")
return"beaufort";else if(this._kmhField.value!="")
return"kmh";else if(this._mphField.value!="")
return"mph";}};

