function getCats(ref,e)
{

  if (ref.length > 0)
  {

    if(window.event)
      KeyID = window.event.keyCode;     //IE
    else
      KeyID = e.which;     //firefox

    
          
    if (KeyID == '13')
    {
      if (document.getElementById('selected_id') && document.getElementById('selected_name'))
	      setCat(document.getElementById('selected_id').value,document.getElementById('selected_name').value);
    }
    else
    {
      var sel;
      if (document.getElementById('selected_index'))
        sel = document.getElementById('selected_index').value
      else
        sel = 0
      
      document.getElementById('intCat').value = '';
      xmlHttp=GetXmlHttpObject();
  		if (xmlHttp==null)
  		{
  		  alert ("Your browser does not support AJAX!");
  		  //If this is the case, suply a standard drop down in place of the text box
  		  return;
  		}
      var url="/ajax/get_cats.asp";
  		url+="?ref=" + ref;
  		url+="&key=" + KeyID;
  		url+="&sel="+ sel;
  		xmlHttp.onreadystatechange=stateChangedCats;
  		xmlHttp.open("GET",url,true);
  		xmlHttp.send(null);
  	}
  }
  else
  {
    cancelCats();
  }
}

function stateChangedCats() 
{ 	 
	if (xmlHttp.readyState==4)
	{ 
		  var ss = document.getElementById('spnCats')
			ss.innerHTML = '';
			var str = xmlHttp.responseText;
			xmlHttp.abort();
			ss.innerHTML += str;		
	}
}

function cancelCats()
{  
  if (document.getElementById('spnCats'))
    document.getElementById('spnCats').innerHTML = '';
}

function setOnFocus()
{
  var el = document.getElementsByTagName('*');
  for(var i=0;i<el.length;i++)
  {
    if (el[i].id != 'spnCats')
      el[i].onfocus = function(){cancelCats()};
      
  } 
}

function setCat(val1,val2)
{
  document.getElementById('strCat').value = val2;
  document.getElementById('intCat').value = val1;
  spnCats.innerHTML = '';
}

