// JavaScript Document
	var weight={g:[1,'g (grams)'],oz:[28.35," oz (ounces)"],lb:[453.592,"lb,lbs (pounds)"],smcup:[200,"metric cup sugar"],suscup:[190,"US cup sugar"],mfcup:[150,"metric cup flour"],fuscup:[140,"US cup flour"]};
	var temp={c:[1,"Celsius (C)"],f:[0,"Fahrenheit (F)"]};
	var length={cm:[1,'cm (centimeter)'],inch:[2.54,"\" (inch)"]};
	var volume={ml:[1,"ml (mililiters)"],ifloz:[28.413,"imperial fl oz"],usfloz:[29.574,"US fl oz"],uscup:[236.588,"US cup"],mcup:[250,"metric cup"],tsp:[5,'tsp'],tbsp:[15,"Tbsp"]};
	
	function cvDefaultFormula()
	{
		
	}
	
	cvDefaultFormula.prototype.q=0;
	cvDefaultFormula.prototype.s1=0;
	cvDefaultFormula.prototype.s2=0;
	cvDefaultFormula.prototype.convert=function()
	{
	 return this.q * this.s1/this.s2;
	}
	
function cvTempFormula() {}
	cvTempFormula.prototype= new cvDefaultFormula();
	cvTempFormula.prototype.convert=function()
	{
		if (this.s1>0)
		{
			return (this.q*1.8)+32;
		}	
		
		return (this.q-32)/1.8;
	}
	
	function cv$(t)
	{
	 return document.getElementById(t);
	}

var cvIsTemp=false;
	
    function cvConvert()
    {
	
	 var q=document.getElementById("q").value;
      if (isNaN(q))
      {
        alert("Please, specify the quantity as a number!");
        return false;
      }
      if (q==0) 
	  {
		  cv$("result").value=0;	
		  return;
	  }
	  var s1=cv$("s1").value;
  	  var s2=cv$("s2").value;
	  if (s1==s2)
	  {
	  	  cv$("result").value=q;	
		  return;
	  }
	
	var f=null;
	 if (cvIsTemp)
	 {
	 	f= new cvTempFormula();
		
		
	 }
	 else
	 {
	  f= new cvDefaultFormula();
	  f.s2=s2;
	 }
	 
	 f.q=q;
	 f.s1=s1;
	  var rez=Math.round(f.convert()*1000)/1000;
      cv$("result").value=rez;
    }
   
   function cvChangeType(c)
   {
	cvIsTemp=(c=="temp");
	
  	var c=eval(c);
	var s1=cv$("s1");
	while (s1.length> 0) {
    s1.remove(0);
	} 
	
	var s2=cv$("s2");
	while (s2.length> 0) {
    s2.remove(0);
	}
	j=0;
	for(i in c)
	{
		s1.options[j]=new Option(c[i][1],c[i][0]);  
		s2.options[j]=new Option(c[i][1],c[i][0]);
		j++;
	}   
   }
		
	document.write('<form action="" method="get" id="converter"><div style="margin-top:0.5em;"><div><label> Type </label></div><select id="type" onchange="cvChangeType(this.value)"><option value="weight">Weight</option><option value="volume">Volume</option><option value="length">Length</option><option value="temp">Temperature</option></select></div><div style="margin-top:0.5em;"><div><label for="q"> Quantity </label></div><input type="text" id="q" size="8" maxlength="10" value="0" /></div><div style="margin-top:0.5em;"><div><label for="s1"> From </label></div><select id="s1" onchange="cv$(\'result\').value=\'\'"></select></div><div style="margin-top:0.5em;"><div><label for="s2"> To </label></div><select id="s2" onchange="cv$(\'result\').value=\'\';"></select></div><div style="margin-top:0.5em;"><div>Result</label></div><input name="text" type="text" id="result" size="10" readonly="readonly" /></div><div style="margin-top:0.5em;"><button type="button" onclick="cvConvert()">Convert</button></div><a href="http://www.mariasmenu.com/help/free-online-cooking-converter" style="display:block;text-align:right;font-size:90%;margin-top:1em;margin-bottom:0.5em;font-weight:bold;color:#c14900;">Add To Your Blog! Powered By MariasMenu.com</a></form>');

cv$("type").selectedIndex=0;
cvChangeType("weight");
