function unitconverterMain(mode){this.version='0.6';w=450;h=180;props=[];units=[];currentPropIdx=0;sliderMax=0;unitsFromParams=null;unitsToParams=null;valFrom=0;valTo=0;loadUnits();var s='';s+='
';document.write(s);document.getElementById('props').selectedIndex=8;onPropsChange();}
function swapUnits(){var f=document.getElementById('units-from'),t=document.getElementById('units-to');var tmp=t.selectedIndex;t.selectedIndex=f.selectedIndex;f.selectedIndex=tmp;onFromUnitsChange();onToUnitsChange();resetSlider();}
function onPropsChange(){currentPropIdx=document.getElementById('props').selectedIndex;var unitNames=[];var unitNamesOrdered=[];for(var i in units[currentPropIdx]){unitNames.push(units[currentPropIdx][i][0]);}
var order=props[currentPropIdx][1];for(var i in order){if(unitNames[order[i]])
unitNamesOrdered.push(unitNames[order[i]]);}
unitNames=null;var s=getConvertFieldHTML('value-from','onFromValueChange','units-from','onFromUnitsChange','units-from-desc',unitNamesOrdered)+
getConvertFieldHTML('value-to','onToValueChange','units-to','onToUnitsChange','units-to-desc',unitNamesOrdered);document.getElementById('unit-selection').innerHTML=s;document.getElementById('units-to').selectedIndex=1;onFromUnitsChange();onFromValueChange();onToUnitsChange();onToValueChange();document.getElementById('value-from').value=1;onFromValueChange();resetSlider();}
function onFromValueChange(){var e=document.getElementById('value-from');valFrom=e.value||0;if(!unitsToParams||!unitsFromParams)return;document.getElementById('value-to').value=fmt(convert(valFrom,unitsFromParams,unitsToParams),15);resetSlider();}
function onToValueChange(){var e=document.getElementById('value-to');valTo=e.value||0;if(!unitsToParams||!unitsFromParams)return;document.getElementById('value-from').value=fmt(convert(valTo,unitsToParams,unitsFromParams),15);resetSlider();}
function getConversionParams(unitName){var propUnits=units[currentPropIdx];for(var i in propUnits){if(propUnits[i][0]==unitName){return propUnits[i];}}
console.log("Unit "+unitName+" does not exist");return null;}
function onFromUnitsChange(e){var e=document.getElementById('units-from');var n=e.value;unitsFromParams=getConversionParams(n);document.getElementById("units-from-desc").innerHTML=unitsFromParams[1];onFromValueChange();}
function onToUnitsChange(e){var e=document.getElementById('units-to');var n=e.value;unitsToParams=getConversionParams(n);document.getElementById("units-to-desc").innerHTML=unitsToParams[1];onFromValueChange();}
function celsiusToFahrenheit(c){return c*9/5+32;}
function fahrenheitToCelsius(f){return(f-32)*5/9;}
function convert(fromVal,fromParams,toParams){if((fromParams[0]=="Degrees Celsius")&&(toParams[0]=="Degrees Fahrenheit")){return celsiusToFahrenheit(fromVal);}
else if((toParams[0]=="Degrees Celsius")&&(fromParams[0]=="Degrees Fahrenheit")){return fahrenheitToCelsius(fromVal);}
var v=Number(fromVal);var m=Number(fromParams[2])/Number(toParams[2]);if(isNaN(v))return "...........................";return v*m;}
function getPropList(props){var s='';s+='';return s;}
function getDropdownHTML(opts,funcName,id){var s='';s+='';return s;}
function resetSlider(){var el=document.getElementById('slider');el.value=.5;sliderMax=document.getElementById('value-from').value*2;onSliderChange();}
function onSliderChange(){var el=document.getElementById('slider');var aVal=sliderMax*el.value;var bVal=convert(aVal,unitsFromParams,unitsToParams);document.getElementById('slidefull').innerHTML=fmt(aVal,15)+' '+unitsFromParams[1]+' = '+fmt(bVal,15)+' '+unitsToParams[1];}
function getSliderHTML(){var s='
'+
'
'+
''+
'
';return s;}
function getConvertFieldHTML(inputId,inputFunc,dropdownId,dropdownFunc,postFixId,opts){var s='