﻿var xmlHttp
var b = "";
function checkEnter(e){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}
if(characterCode == 13){ //if character code is equal to ascii 13 (if enter key)
mystring = document.getElementById("Text1").value;
showResult(mystring);
return false //return false to the event handler
}
else{
return true //return true to the event handler
}
}

function clearAll()
{
 document.getElementById("liveSearch").innerHTML="";
 document.getElementById('liveSearch').style.display="none";
 return	
}
function showResult(str)
{
if (str.length<=2)
{
clearAll();
return
}
xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 

var url = "search.php"
url=url+"?searchTerm="+str
//url=url+"?q="+str+"&b="+b
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  document.getElementById('liveSearch').innerHTML=xmlHttp.responseText;
  document.getElementById('liveSearch').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;
}
function fillCity(strcity)
{
//alert(document.getElementById("tbxcity") + " and " + document.getElementById("TextBoxCity"));
if(document.getElementById("tbxcity") != null){
document.getElementById("tbxcity").value=strcity;
}
if(document.getElementById("TextBoxCity") != null){
document.getElementById("TextBoxCity").value=strcity;
}
clearAll();
}