/* Copyright (c) 1995-2008 Choice Hotels International, Inc. All Rights Reserved. */
var MetricConverterLang={NOT_NUMBER:"Valid numbers",UNIT_CATEGORY:"Unit Category",SOURCE_UNIT:"Unit to Convert From",DEST_UNIT:"Unit to Convert To",BASE_VALUE:"Base Value",ENTER_INFO:"Please enter/select a:"};function convert(form_flds){var error_msg;var field_name="";var error="";var unitCategory="";var srcUnitFactor="";var destUnitFactor="";var resultMeasureUnit="";var baseValue="";for(var i=0;i<form_flds.length;i++){var e=form_flds.elements[i];if(e.name=='unitCategory'){unitCategory=e.options[e.selectedIndex].value;field_name=MetricConverterLang.UNIT_CATEGORY;if(unitCategory==""){error+="\n"+field_name}}switch(unitCategory){case 'length':;if(e.name=='srcUnitLength'){srcUnitFactor=e.options[e.selectedIndex].value;field_name=MetricConverterLang.SOURCE_UNIT;if(srcUnitFactor==""){error+="\n"+field_name}}if(e.name=='destUnitLength'){destUnitFactor=e.options[e.selectedIndex].value;resultMeasureUnit=e.options[e.selectedIndex].text;field_name=MetricConverterLang.DEST_UNIT;if(destUnitFactor==""){error+="\n"+field_name}}break;case 'area':;if(e.name=='srcUnitArea'){srcUnitFactor=e.options[e.selectedIndex].value;field_name=MetricConverterLang.SOURCE_UNIT;if(srcUnitFactor==""){error+="\n"+field_name}}if(e.name=='destUnitArea'){destUnitFactor=e.options[e.selectedIndex].value;resultMeasureUnit=e.options[e.selectedIndex].text;field_name=MetricConverterLang.DEST_UNIT;if(destUnitFactor==""){error+="\n"+field_name}}break;default: ;srcUnitFactor=1;destUnitFactor=1;break}if(e.name=='baseValue'){baseValue=e.value;field_name=MetricConverterLang.BASE_VALUE;if(baseValue==""){error+="\n"+field_name}}}if(error){error_msg=MetricConverterLang.ENTER_INFO+"\n"+error+"\n";alert(error_msg);return false}clearResultArea('result');var resultValue=doConvert(unitCategory,srcUnitFactor,destUnitFactor,baseValue);displayResult(resultValue,resultMeasureUnit);return false};function doConvert(unitCategory,srcUnitFactor,destUnitFactor,baseValue){var result=baseValue*(srcUnitFactor/destUnitFactor);result=(Math.round(result*1000.0))/1000.0;return result};function displayResult(resultValue,resultMeasureUnit){var formattedValueNode;var formattedUnitNode;unhideElement("resultLabel");formattedValueNode=document.createElement("b");formattedValueNode.setAttribute("id","formattedValueNode");formattedValueNode.style.fontSize="18px";formattedValueNode.appendChild(document.createTextNode(resultValue+' '));document.getElementById("resValue").appendChild(formattedValueNode);formattedUnitNode=document.createElement("b");formattedUnitNode.setAttribute("id","formattedUnitNode");formattedUnitNode.style.fontSize="14px";formattedUnitNode.appendChild(document.createTextNode(resultMeasureUnit));document.getElementById("resMeasureUnit").appendChild(formattedUnitNode);document.getElementById("resValue").style.display="inline";document.getElementById("resMeasureUnit").style.display="inline"};function enableDropDown(category){var categories=new Array("length","area");for(var i=0;i<categories.length;i++){if(categories[i]==category){document.getElementById("src"+category).style.display="inline";document.getElementById("src"+category).removeAttribute("disabled");document.getElementById("dest"+category).style.display="inline";document.getElementById("dest"+category).removeAttribute("disabled")}else {document.getElementById("src"+categories[i]).style.display="none";document.getElementById("src"+categories[i]).setAttribute("disabled","true");document.getElementById("dest"+categories[i]).style.display="none";document.getElementById("dest"+categories[i]).setAttribute("disabled","true")}}};function clearTxt(txtNode1,txtNode2){var parentNode=null;var node1=document.getElementById(txtNode1);var node2=document.getElementById(txtNode2);if(node1!=null&&node2!=null){var parentNode=node1.parentNode;parentNode.removeChild(node1);parentNode.removeChild(node2)}return parentNode};function addEmptyNode(parentNode){if(parentNode!=null){var span=document.createElement("span");span.setAttribute("id","resValue");span.setAttribute("style","display:none;padding-right:10px;");span.setAttribute("class","emph");var blankTxtNode=document.createTextNode("");span.appendChild(blankTxtNode);var span2=document.createElement("span");span2.setAttribute("id","resMeasureUnit");span2.setAttribute("style","display:none;");span2.setAttribute("class","emph");var blankTxtNode=document.createTextNode("");span.appendChild(blankTxtNode);span2.appendChild(blankTxtNode);var referenceNode=document.getElementById("result");referenceNode.appendChild(span);referenceNode.appendChild(span2)}};function clearResultArea(id){if(document.getElementById("resultLabel")!=null){hideElement("resultLabel")}addEmptyNode(clearTxt("resValue","resMeasureUnit"))};function unhideElement(id){document.getElementById(id).style.display='inline'};function hideElement(id){if(id!=null||id!=''||id!='undefined')document.getElementById(id).style.display='none'};
