var xmlHttp;
var hintdiv;

//----------------------------------------------------------------------------------------
function showHint(srchstr, boxname, divhint)
{
  if (srchstr.length == 0)
  { 
    divhint.innerHTML = '';
    return;
  }

  xmlHttp = GetXmlHttpObject();
  hintdiv = divhint;
  
  if (xmlHttp==null)
  {
    alert ('Your browser does not support AJAX!');
    return;
  } 

//  obj = document.getElementById(boxname);

  left = GetPosition_Left(boxname);
  left = left + 'px';
  
  temp = GetPosition_Top(boxname);
  temp = temp + 20;
  temp = temp + 'px';

  if (divhint.style.left != left) divhint.style.left = left;
  if (divhint.style.top != temp) divhint.style.top = temp;

  
  var url = '/ajax_postcode_lookup.asp';  
  url = url + '?q=' + srchstr + '&boxname=' + boxname;
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open('GET', url, true);
  xmlHttp.send(null);
} 

//----------------------------------------------------------------------------------------
function stateChanged()
{ 
  if (xmlHttp.readyState==4)
  { 
    var temp = xmlHttp.responseText;  
    var flds = temp.split('|');
  
    temp = '';  //'<b>Please select below...</b>';

    for (i=0; i<flds.length; i++)
    {
      temp = temp + '<div>' + flds[i] + '</div>';
    }

    if (hintdiv)
    {
      hintdiv.innerHTML = temp;
      hintdiv.style.visibility = 'visible';
      hintdiv.style.display = '';
     }
  }
}

//----------------------------------------------------------------------------------------
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;
}

//this function allows for Clickable suggestions
//----------------------------------------------------------------------------------------
function setTextBox(text1, box1)
{
  obj = document.getElementById(box1);
  obj.value = text1;
  hideHint(hintdiv);
}

function hideHint(divhint)
{
  divhint.style.visibility = 'hidden';
  divhint.style.display = 'none';
}
