
var area=new Array("Acre","Hectares","Square Centimeter","Square Meter","Square Feet","Square Inches","Square Kilometer","Square Miles","Square Milimeters","Square Yards")
var area1=new Array("acre","hectare","sqcentimeter","sqmeter","sqfeet","sqinch","sqkilometer","sqmile","sqmilimeter","sqyard")

var lengths=new Array("Centimeter","Feet","inch","Kilometer","Meter","Mile","Yard")
var length1=new Array("cm","feet","inch","kilometer","meter","umile","yard")

var mass=new Array("Gram ","Kilogram","Ounce","Pounds","Tons")
var mass1=new Array("gram","kilogram","ounce","pound","ton")

var temperature=new Array("Celsius","Farenheit","Kelvin")
var temperature1=new Array("celsius","farenheit","kelvin")

var speed=new Array("Centimeter/hour","Centimeter/minute","Centimeter/second","Feet/hour","Feet/minute","Feet/second","Kilometer/hour","Kilometer/minute","Kilometer/second","Meter/hour","Meter/minute","Meter/second","Miles/hour","Miles/minute","Miles/second")
var speed1=new Array("cmph","cmpm","cmps","feetph","feetpm","feetps","kmph","kmpm","kmps","meterph","meterpm","meterps","milesph","milespm","milesps")

var volume=new Array("Barrels ","Centi Liter","Cubic Centimeter","Cubic Decimeter","Cubic Milimeter","Cubic Yards","Cubic Meter","Cubic Feet","Cubic Inch","Gallons(Liquid)","Liters(l or L)")
var volume1=new Array("barrel","centiliter","cubiccm","cubicdecimeter","cubicmm","cubicyard","cubicmeter","cubicfeet","cubicinch","gallon","liter")
 

function add_option(selectname)
 { 
  var val=selectname
  if(document.getElementById('selectname').value=="area")
    {
	 //alert(document.getElementById('selectname').value)
	 document.forms["weight"].elements["from_convert"].options.length=0;
	 document.forms["weight"].elements["to_convert"].options.length=0;
	 for(var i=0;i<area.length;i++)
	    {
	     var opt = document.createElement("option");
		 var opt1 = document.createElement("option");
		 opt.setAttribute('value',area1[i]);
		 opt1.setAttribute('value',area1[i]);
		 opt.innerHTML = area[i]
		 opt1.innerHTML = area[i]
		 document.forms["weight"].elements["from_convert"].appendChild(opt);
		 document.forms["weight"].elements["to_convert"].appendChild(opt1);
	    }
     }
 if(document.getElementById('selectname').value=="length")
    {
	 //alert(document.getElementById('selectname').value)
  	 document.forms["weight"].elements["from_convert"].options.length=0;
	 document.forms["weight"].elements["to_convert"].options.length=0;
	 for(var i=0;i<lengths.length;i++)
	  {
	    var opt = document.createElement("option");
		var opt1 = document.createElement("option");
		opt.setAttribute('value',length1[i]);
		opt1.setAttribute('value',length1[i]);
		opt.innerHTML = lengths[i];
		opt1.innerHTML = lengths[i];
		document.forms["weight"].elements["from_convert"].appendChild(opt);
		document.forms["weight"].elements["to_convert"].appendChild(opt1);		
		
	  }
  }
if(document.getElementById('selectname').value=="mass")
    {
	 //alert(document.getElementById('selectname').value)
     document.forms["weight"].elements["from_convert"].options.length=0;
	 document.forms["weight"].elements["to_convert"].options.length=0;
	for(var i=0;i<mass.length;i++)
	  {
	    var opt = document.createElement("option");
		var opt1 = document.createElement("option");
		opt.setAttribute('value',mass1[i]);
		opt1.setAttribute('value',mass1[i]);
		opt.innerHTML = mass[i];
		opt1.innerHTML = mass[i];
		document.forms["weight"].elements["from_convert"].appendChild(opt);
		document.forms["weight"].elements["to_convert"].appendChild(opt1);			
	  }
    }
if(document.getElementById('selectname').value=="temperature")
    {
     document.forms["weight"].elements["from_convert"].options.length=0;
	 document.forms["weight"].elements["to_convert"].options.length=0;	
	for(var i=0;i<temperature.length;i++)
	  {
	    var opt = document.createElement("option");
		var opt1 = document.createElement("option");
		opt.setAttribute('value',temperature1[i]);
		opt1.setAttribute('value',temperature1[i]);
		 opt.innerHTML = temperature[i];
		 opt1.innerHTML = temperature[i];
		 document.forms["weight"].elements["from_convert"].appendChild(opt);
		 document.forms["weight"].elements["to_convert"].appendChild(opt1);			
	  }
    }	
if(document.getElementById('selectname').value=="velocity")
    {
     document.forms["weight"].elements["from_convert"].options.length=0;
	 document.forms["weight"].elements["to_convert"].options.length=0;	
	for(var i=0;i<speed.length;i++)
	   {
	     var opt = document.createElement("option");
		 var opt1 = document.createElement("option");
	     opt.setAttribute('value',speed1[i]);
		 opt1.setAttribute('value',speed1[i]);
		 opt.innerHTML = speed[i];
		 opt1.innerHTML = speed[i];
		 document.forms["weight"].elements["from_convert"].appendChild(opt);
		 document.forms["weight"].elements["to_convert"].appendChild(opt1);				
	   }
    }
if(document.getElementById('selectname').value=="volume")
    {
     document.forms["weight"].elements["from_convert"].options.length=0;
	 document.forms["weight"].elements["to_convert"].options.length=0;
	 for(var i=0;i<volume.length;i++)
	  {
	    var opt = document.createElement("option");
		var opt1 = document.createElement("option");
	    opt.setAttribute('value',volume1[i]);
		opt1.setAttribute('value',volume1[i]);
		opt.innerHTML = volume[i];
		opt1.innerHTML = volume[i];
		
		document.forms["weight"].elements["from_convert"].appendChild(opt);
		document.forms["weight"].elements["to_convert"].appendChild(opt1);				
	  }
    }
	
 }

/*   
function addOption(selectbox,text,value)
  {
   var optn = document.createElement("OPTION");
   optn.text = text;
   optn.value = value;
   selectbox.options.add(optn);
  }

function removeAllOptions(selectbox)
  {
      var i;
   for(i=selectbox.options.length-1;i>=0;i--)
	 {
		selectbox.remove(i);
	 }
  }
  
  
 
function add_option()
 {
   if(document.getElementById('selectname').value=="area")
    {
	 //document.weight.selectname.value
	  removeAllOptions(document.weight.from_convert);
	  removeAllOptions(document.weight.to_convert);
	  //document.getElementById('dd').src="img/mass.gif"
	  for(var i=0;i<area.length;i++)
	    {
	     addOption(document.weight.from_convert,area[i],area1[i]);
		 addOption(document.weight.to_convert,area[i],area1[i]);	
	    }
     }
 if(document.getElementById('selectname').value=="length")
    {
  	 removeAllOptions(document.weight.from_convert);
	 removeAllOptions(document.weight.to_convert);
	 for(var i=0;i<length.length;i++)
	  {
	    addOption(document.weight.from_convert,length[i],length1[i]);	
	    addOption(document.weight.to_convert,length[i],length1[i]);	
	  }
  }
if(document.getElementById('selectname').value=="mass")
    {
  	removeAllOptions(document.weight.from_convert);
	removeAllOptions(document.weight.to_convert);
	for(var i=0;i<mass.length;i++)
	  {
		addOption(document.weight.from_convert,mass[i],mass1[i]);	
		addOption(document.weight.to_convert,mass[i],mass1[i]);	
	  }
    }
if(document.getElementById('selectname').value=="temperature")
    {
  	removeAllOptions(document.weight.from_convert);
	removeAllOptions(document.weight.to_convert);
	for(var i=0;i<temperature.length;i++)
	  {
		addOption(document.weight.from_convert,temperature[i],temperature1[i]);	
  		addOption(document.weight.to_convert,temperature[i],temperature1[i]);	
	  }
    }	
if(document.getElementById('selectname').value=="velocity")
    {
  	removeAllOptions(document.weight.from_convert);
   	removeAllOptions(document.weight.to_convert);
	for(var i=0;i<speed.length;i++)
	   {
	     addOption(document.weight.from_convert,speed[i],speed1[i]);
	     addOption(document.weight.to_convert,speed[i],speed1[i]);	
	   }
    }
if(document.getElementById('selectname').value=="volume")
    {
  	removeAllOptions(document.weight.from_convert);
	removeAllOptions(document.weight.to_convert);
	for(var i=0;i<volume.length;i++)
	  {
	    addOption(document.weight.from_convert,volume[i],volume1[i]);
	    addOption(document.weight.to_convert,volume[i],volume1[i]);		  	
	  }
    }			
 }
*/

var xmlhttp
function GetXmlHttpObject()
 {
  var xmlHttp=null;
 try
  {
  //Firefox, Opera 8.0+, Safari
   xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  //Internet Explorer
   try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}
function convert(combo1,combo2,combo3,number)
 {
   var uri="conversion/"+combo1
   var input=number
   var from_convert=combo2
   var to_convert=combo3
   var url=uri+'.jsp?amount='+input+'&from_convert='+from_convert+'&to_convert='+to_convert;
   //+'from_area='+dd1
   //+'from_area='+document.weight.from_area.value+'to_area='+document.weight.to_area.value
   xmlhttp=GetXmlHttpObject();

   if(xmlhttp!=null)
    {
	  
	       xmlhttp.onreadystatechange=state_change
	       xmlhttp.open("GET",url,true);
  	       xmlhttp.send(null);
	  
	}
   else
     {
	      alert("Sorry Your Browser is Not Supporting");
      }
 }

function state_change()
 {
   if(xmlhttp.readyState==4)
    {
       document.getElementById('output').innerHTML=xmlhttp.responseText;
    }
 
  }

function setvalue()
 {
   document.weight.amount.value="1"
}
 
function ourvalues()
  {
    var combo1=document.weight.selectname.value
    var combo2=document.weight.from_convert.value
    var combo3=document.weight.to_convert.value
    var number=document.weight.amount.value

    if(number=="")
     {
        //alert("hai")
       document.weight.output.value="Enter your digit"
        //return hai
     }
    else
     {
       convert(combo1,combo2,combo3,number)
     } 
  
  }

  function loadimage()
   {
     if(document.weight.selectname.value=="area")
	  {
       document.getElementById('dd').src="img/area.gif"
	  } 
	 if(document.weight.selectname.value=="mass")
	  {
	   
       document.getElementById('dd').src="img/mass.gif"
	  } 
	 if(document.weight.selectname.value=="length")
	  {
	   
       document.getElementById('dd').src="img/length.gif"
	  }   
	  if(document.weight.selectname.value=="temperature")
	  {
	   
       document.getElementById('dd').src="img/temperature.gif"
	  } 
	  if(document.weight.selectname.value=="velocity")
	  {
	   
       document.getElementById('dd').src="img/speed.gif"
	  } 
	  if(document.weight.selectname.value=="volume")
	  {
	   
       document.getElementById('dd').src="img/volume.gif"
	  }      
   } 
