// -------------------------------------------------------------------------------
// Changeunits javascript functions.  (c) 2008 All rights reserved.
// -------------------------------------------------------------------------------


// Global variables


//---------------------------------------------------------------------------------
// Help menu
//---------------------------------------------------------------------------------

function onHelp() {
	helpType = document.getElementById("help_menu");
	switch (helpType.selectedIndex) {	
		case 0:
			helpType.selectedIndex = 0;
			break;
		case 1:
		case 2:
			myRef = window.open("help/unitsAlpha.html",'mywin', 'width=500,height=500,toolbar=0,resizable=1,scrollbars=1');
			helpType.selectedIndex = 0;
			break;
		case 3:
			myRef = window.open("help/unitsCat.html",'mywin', 'width=500,height=500,toolbar=0,resizable=1,scrollbars=1');
			helpType.selectedIndex = 0;
			break;		
		case 4:
			myRef = window.open("help/about.html",'mywin', 'width=500,height=500,toolbar=0,resizable=1,scrollbars=1');
			helpType.selectedIndex = 0;
			break;
		default:
			helpType.selectedIndex = 0;
			break;
	}
}


//---------------------------------------------------------------------------------
// Ajax interface
//---------------------------------------------------------------------------------

//--------------------
// Ajax routine
//--------------------

function ajaxFunction()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
   xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.convertForm.ansText.value=xmlHttp.responseText;
        }
      }
      document.convertForm.ansText.value="converting..."
      var inString = escape(document.fromTextForm.fromText.value)
      var toString = escape(document.toTextForm.toUnits.value)
      var url="http://www.changeunits.com/cgi-bin/convert.cgi";
      url=url+"?fromText="+inString;
      url=url+"&toUnits="+toString;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
  }
  
  
  
//---------------------------------------------------------------------------------
// Input functions
//---------------------------------------------------------------------------------

//--------------------
// checkEnter function
//--------------------
  
function checkEnter(e){
var characterCode
	 if(e && e.which){
	 e = e
	 characterCode = e.which
	 }
	 else{
	 e = event
	 characterCode = e.keyCode
	 }	 
	 if(characterCode == 13){
	 	ajaxFunction() 
 	 	return false
	 }
return true
}  
