try
{
 var req;
 var DivIDValue;
 var fieldTextvalue;
 var fieldIDvalue;
 var obj;
 var hidobj;
 var customapp; 
 var code;
 var stateobj;
var postcodeobj;
var statehid;
var countryobj;
var postcodehid;
var countryhid;
var temppos;
var freq = 0; 
var referval;

 
function Initialize()
{   
   try
    {	
		
        req=new ActiveXObject("Msxml2.XMLHTTP");
 
    }
    catch(e)
    {
        try
        {
			
            req=new ActiveXObject("Microsoft.XMLHTTP");
 
        }
        catch(oc)
        {
            req=null;
        }
    }
	
    if(!req&&typeof XMLHttpRequest!="undefined")
    {
        req=new XMLHttpRequest();
    }

}

function SendQuery(key,customapplication,divID, fieldText,fieldID) {

DivIDValue = divID;
fieldTextvalue = fieldText;
fieldIDvalue = fieldID;

	var escp = window.event;
	
	if (escp.keyCode == 27)
		{
		document.getElementById(fieldTextvalue).value = "";
		document.getElementById(fieldIDvalue).value = "";
		       while ( document.getElementById(DivIDValue).hasChildNodes() )
				document.getElementById(DivIDValue).removeChild(document.getElementById(DivIDValue).firstChild);
		HideDiv(DivIDValue);
		return;
		}
	
	document.getElementById(fieldTextvalue).className="AutoCompleteRESULTSNOTOK";
	document.getElementById(fieldIDvalue).value = "";



    Initialize();
   // var url="../../../../../../Panorama/common/autocompleteAction.aspx?Key="+key+"&Application="+customapplication;
    //var url="../../../../Panorama/common/AutoCompleteAction.aspx?RandomKey="+ Math.random() * Date.parse(new Date()) + "&Key="+key+"&Application="+customapplication  
	var url= window.location.protocol + "//" + window.location.host + "/Panorama/common/AutoCompleteAction.aspx?RandomKey="+ Math.random() * Date.parse(new Date()) + "&Key="+key+"&Application="+customapplication  
   
          
    if(req!=null)
    {
		alert(url);
         req.onreadystatechange = Process;
         req.open("GET", url, true);
         req.send(null);
   
    }

}

function Process() {
   
    if (req.readyState == 4)  {
             // only if "OK"
            if (req.status == 200)
            {
               
                  
                if(req.responseText=="") {
                    HideDiv(DivIDValue);
                //    alert("test1");
                 }
                else
                {
                //      alert("test2");
                    ShowDiv(DivIDValue);
                    
                   while ( document.getElementById(DivIDValue).hasChildNodes() )
							document.getElementById(DivIDValue).removeChild(document.getElementById(DivIDValue).firstChild);
			
		
                  var aStr = new Array();
                  var tempstr;
                  tempstr = req.responseText;
                  aStr = tempstr.split(':');                 
                    
                
                              
                               
                	var i, n = aStr.length;
					for ( i = 0; i < n; i++ )
					{
						var linkelement = document.createElement("div");
						strid = aStr[i]
						strid = strid.split('|');
						linkelement.ID = strid[1];
						linkelement.innerHTML = strid[0];						
						document.getElementById(DivIDValue).appendChild(linkelement);
						linkelement.onmouseover = function() { onDivMouseOver(this); }
						linkelement.onmousedown  = function() { onDivMouseDown(this,DivIDValue); }
						linkelement.onmouseout = function() { onDivMouseOut(this); }
					}
                   //**document.getElementById("autocomplete").innerHTML = req.responseText;   
                }
            }
            else
            {
                document.getElementById(DivIDValue).innerHTML= "There was a problem retrieving data:<br>" + req.statusText;
            }
        }
}



//** Process 2 - Incorporate type ahead functionality after postback 
function Process2() {
  
   
    if (req.readyState == 4)  {
             // only if "OK"
            if (req.status == 200)
            {
                             
               if(req.responseText!="")
              {
                  var aStr = new Array() ;
                  aStr=null;
                  var tempstr=null;
     	          tempstr = req.responseText;
                  tempstr = tempstr.substring(0,tempstr.indexOf("<"));
                  aStr = tempstr.split(':');                 
                          
          
              //** Call Type Ahead function and passed in the array created 
               var obj2 = new window.setTimeout(actb(obj,hidobj,aStr),50); 
          //     var obj2 = new actb(obj,hidobj,aStr); 
            
            }
            
            
            
            }
        }
        
           
           
}


function onDivMouseDown(str, divID)
{	
	
	
	document.getElementById(fieldTextvalue).value = str.innerHTML;
	document.getElementById(fieldIDvalue).value = str.ID;
	document.getElementById(fieldTextvalue).className="";
	while ( document.getElementById(divID).hasChildNodes() )
	document.getElementById(divID).removeChild(document.getElementById(divID).firstChild);
	document.getElementById(divID).style.visibility="hidden"
}

function onDivMouseOver(str)
{
	//str.className = "AutoCompleteControlHighlight2";
	str.style.backgroundColor = "#888888";
	str.style.color = "#000000";
   	
}

function onDivMouseOut(str)
{
//	str.className = "AutoCompleteControl2";
	str.style.backgroundColor = "#888888";
   str.style.color = "#FFFFFF";
}


function ShowDiv(divid)
{
   if (document.layers) document.layers[divid].visibility="show";
   else document.getElementById(divid).style.visibility="visible";
}

function HideDiv(divid)
{
   if (document.layers) document.layers[divid].visibility="hide";
   else document.getElementById(divid).style.visibility="hidden";
}

function BodyLoad()
{
    
    document.forms[0].keyword.focus();

}





	//***** This section below is the script for testing new autocomplete functions


//function tb2_AutoCompletePopulate(field,defaultfield,strString) {
//function tb2_AutoCompletePopulate(key,customapplication,field,hidfield) {
function tb2_AutoCompletePopulate(key,customapplication,field,hidfield,SearchFieldLength,refvalue,postback,statefield,statehid0,postcodefield,postcodehid0,countryfield,countryhid0) {
//try 
//  {  

//** Handle IE error . Make it user friendly rather than prompt out details of script error
//window.onerror = errorHandler;



function errorHandler(msg,url,lno)
{
  var alertmsg = "There has been an internal error because of invalid textbox value."; 
  alertmsg += "\n\nPlease clear the textbox and try again.\n\n";
  alert (alertmsg);
  return (true);
}
 
  
//	if (!e) var e = window.event;
//	if (e.keyCode) code = e.keyCode;


customapp = customapplication;
obj = document.getElementById(field); 
hidobj = document.getElementById(hidfield);
fieldTextvalue = field;
fieldIDvalue = hidfield; 

//obj.focus();
//obj.select();

//always set the readonly attribute to false 
//we will set the readonly=true later in the property if we want to
obj.removeAttribute("readOnly");


if (obj.value == '') {
hidobj.value = '';
}


if (refvalue != null) { 
referval = document.getElementById(refvalue); 
}

if (customapplication == 'newsuburbsearch' || customapplication == 'newsuburbsearchdeliveryareapostcode') {

if (statefield != null) { 
stateobj = document.getElementById(statefield);
statehid = document.getElementById(statehid0);

if (obj.value == '') {
stateobj.value = '';
statehid.value = '';
}

}

if (postcodefield != null) { 
postcodeobj = document.getElementById(postcodefield);
postcodehid=document.getElementById(postcodehid0);

if (obj.value == '') {
postcodeobj.value = '';
postcodehid.value = '';
}
}

if (countryfield != null) { 
countryobj = document.getElementById(countryfield);
countryhid = document.getElementById(countryhid0);

if (obj.value == '') {
countryobj.value = '';
countryhid.value = '';
}
}

} 

 //** Do a xmlhttprequest to get data from database . Function actb(type ahead) below will be called from Process2 function.      
 //** Url will have randomkey parameter included so that the XMLHTTPREQUEST will always return the latest value and not those that were already in cache 


//if (key.length > 2) {

//  Initialize();
//    var url="../../../../Panorama/common/AutoCompleteAction.aspx?RandomKey="+ Math.random() * Date.parse(new Date()) + "&Key="+key+"&Application="+customapplication
 
             
//    if(req!=null)
//     {
      
 //        req.onreadystatechange = Process2;
 //        req.open("GET", url, true);
 //        req.send(null);
    
 //  }   

 //  }
    
    
    
   //**** First time focus we will call this function which will attach all the 
   //**** key event to the autocomplete object 
         var obj3 = actb(obj,hidobj,customapplication,SearchFieldLength-1,postback); 
 
  }



//function actb(obj,hidobj,ca){
function actb(obj,hidobj,customapplication,SearchFieldLength,postbackval){
 

/* ---- Public Variables ---- */
    
try { 
    
    
   IsTextArea = 1;
   
	this.actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	this.actb_lim = 15;    // Number of elements autocomplete can show (-1: no limit)
	this.actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
	this.actb_mouse = true; // Enable Mouse Support
	this.actb_delimiter = new Array(';',',');  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	//this.actb_delimiter = new Array();
	this.actb_startcheck = SearchFieldLength; // Show widget only after this number of characters is typed in.
	/* ---- Public Variables ---- */

	/* --- Styles --- */
  	this.actb_bgColor = '#888888';
	this.actb_textColor = '#FFFFFF';
	this.actb_hColor = '#000000';
   	this.actb_fFamily = 'Verdana';
	this.actb_fSize = '12px';
	this.actb_hStyle = 'text-decoration:underline;font-weight="bold"';

	/* --- Styles --- */

	/* ---- Private Variables ---- */
	var actb_delimwords = new Array();
	var actb_cdelimword = 0;
	var actb_delimchar = new Array();
	var actb_display = false;
	var actb_pos = 0;
	var actb_total = 0;
	var actb_curr = null;
	var actb_hid = null;
	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = 1;
	var actb_kwcount = 0;
	var actb_caretmove = false;
    var generatecompleted;	
    
	//this.actb_keywords = null;
	this.actb_keywords = new Array();
	/* ---- Private Variables---- */
        
   //this.actb_keywords = ca;
   
    
     
	actb_curr = obj;
	actb_hid = hidobj;

  var actb_self = this; 
 

//** To cater for address control
  var actb_statecurr=null;
  var actb_postcodecurr=null;
  var actb_countrycurr=null;
  var actb_statehid=null;
  var actb_postcodehid=null;
  var actb_countryhid=null;
  
 if (customapp=='newsuburbsearch' || customapp=='newsuburbsearchdeliveryareapostcode') { 
 actb_statecurr = stateobj; 
 actb_countrycurr = countryobj; 
 actb_postcodecurr = postcodeobj; 
 actb_statehid = statehid;
 actb_postcodehid = postcodehid;
 actb_countryhid = countryhid; 

}

	

 //    var ovj =  actb_checkkey2("keyup");
//**** Attach onkeyup event to the object  
 actb_curr.onkeyup = function() { 
 if (!e) var e = window.event;
 if (e.keyCode) code = e.keyCode;

   
if (actb_curr.value.length > SearchFieldLength) { 	

  if (code == 38 || code == 40 || code == 13|| code == 9) return;
//  alert("test");

  actb_keyup();
//  setTimeout(function(){actb_keyup();},100);
//  var obj4 = actb_checkkey2("keyup");

} 

if (actb_curr.value.length < SearchFieldLength) { 
 
if (trim2(actb_curr.value) == ''){
		   
		    actb_mouse_on_list = 0;
			actb_removedisp();
           
           actb_curr.value = '';
		   actb_hid.value = '';
		   		 
	  if (customapp=='newsuburbsearch' || customapp=='newsuburbsearchdeliveryareapostcode') { 
		  
		   actb_statecurr.value = ''; 
           actb_countrycurr.value = ''; 
           actb_postcodecurr.value = ''; 
           actb_statehid.value = '';
           actb_postcodehid.value = '';
           actb_countryhid.value = ''; 
          }
			
			return;
		}
		
	

}

}


       
// 	addEvent(actb_curr,"focus",actb_setup);
//	function actb_setup(){
     	addEvent(actb_curr,"keydown",actb_checkkey);
 //       addEvent(document,"keyup",actb_checkkey);
		addEvent(actb_curr,"blur",actb_clear);
		addEvent(document,"keypress",actb_keypress);
//		addEvent(document,"keyup",actb_keyup);
//	}



	function actb_clear(evt){
	 	if (!evt) evt = event;
		removeEvent(actb_curr,"keydown",actb_checkkey);
		removeEvent(actb_curr,"blur",actb_clear);
		removeEvent(document,"keypress",actb_keypress);
//		removeEvent(document,"keyup",actb_checkkey2);
		
	//	actb_curr.value = actb_curr.value.trim();	
	
	    actb_penter();
			
    	actb_removedisp();
	}
	function actb_parse(n){
		if (actb_self.actb_delimiter.length > 0){
		 	var t = actb_delimwords[actb_cdelimword].trim().addslashes();
			var plen = actb_delimwords[actb_cdelimword].trim().length;
		}else{
		 	var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var tobuild = '';
		var i;

		if (actb_self.actb_firstText){
		   var re = new RegExp("^" + t, "i");
		}else{
		   
			var re = new RegExp(t, "i");
		}
		var p = n.search(re);
				
		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<font style='"+(actb_self.actb_hStyle)+"'>"
		for (i=p;i<plen+p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</font>";
			for (i=plen+p;i<n.length;i++){
			tobuild += n.substr(i,1);
		}
		
		return tobuild;
	}
	
	function actb_generate(){
			

			
		if (document.getElementById('tat_table')){ 
        actb_display = false;document.body.removeChild(document.getElementById('tat_table')); } 
       
      //Remove Iframe
       if (document.getElementById('__shim')){    
         document.body.removeChild(document.getElementById('__shim'));
       }
       				
		if (actb_kwcount == 0){	
		  obj.style.color="DarkRed";
		   	actb_display = false;
		   	return;
		}
		else { obj.style.color="Black";   }
		
	   	a = document.createElement('table');	
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.zIndex = '999';			
	   	a.style.position='absolute';
	   	a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		
		
		a.id = 'tat_table';
		
		document.body.appendChild(a);
		
		//Create iframe to solve the dropdownlist overlapping problem
		 var shim = document.createElement("<iframe src='../../../../../Panorama/blank.html' scrolling='no' frameborder='0'"+
                                      "style='position:absolute; top:0px;"+
                                      "left:0px; display:none'></iframe>"); 
        shim.name = "__shim";
        shim.id = "__shim";

		document.body.appendChild(shim);
		
	
    shim.style.width = '0px';
    shim.style.height = '0px';
    shim.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
    shim.style.left = curLeft(actb_curr) + "px";
    shim.style.zIndex = '900';
    shim.style.position = "absolute";
    shim.style.display = "block";

 
		
		var i;
		var first = true;
		var j = 1;
		if (actb_self.actb_mouse){
		 		 
			a.onmouseout = actb_table_unfocus;
			a.onmouseover = actb_table_focus;
		}
		var counter = 0;
		var strText='';
		
				
		for (i=0;i<actb_self.actb_keywords.length;i++){
			
		// if (customapp=='newsuburbsearch') { 
	     if(actb_self.actb_keywords[i].indexOf("*") > 0){ 
	      strText = actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("~")+1,actb_self.actb_keywords[i].indexOf("*"));
	    	     }
	     else { 
	        strText = actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("~")+1,actb_self.actb_keywords[i].length);
          }
          
		//  strText = actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("-")+1,actb_self.actb_keywords[i].length);
   	  
   	    
   
   	        	          
			if (actb_bool[i]){
				counter++;
				r = a.insertRow(-1);
				if (first && !actb_tomake){
				  	r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_pos = counter;
			    }else if(actb_pre == i){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_pos = counter;
					
				}else{
				   r.style.backgroundColor = actb_self.actb_bgColor;
				}
				r.id = 'tat_tr'+(j);
				
				c = r.insertCell(-1);
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
			//	c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
			 //  c.innerHTML = actb_parse(actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("-")+1,actb_self.actb_keywords.length));
			    c.innerHTML = actb_parse(strText);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				
								
				
				if (actb_self.actb_mouse){
				    
				   	c.style.cursor = 'pointer';
					c.onclick=actb_mouseclick;					
					c.onmouseover = actb_table_highlight;
				 
				   
				}
				j++;
			}
			if (j - 1 == actb_self.actb_lim && j < actb_total){
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_self.actb_bgColor;
				c = r.insertCell(-1);
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = 'arial narrow';
				c.style.fontSize = actb_self.actb_fSize;
				c.align='center';
			
			//	replaceHTML(c,'\\/');
			
				image_display=document.createElement('img');
				image_display.src='../../../../Panorama/Images/downarrow.gif';
				    
		       replaceHTML2(c,image_display);
				if (actb_self.actb_mouse){
							                                  				    
					c.style.cursor = 'pointer';
					//c.onclick = actb_mouse_down;
					c.onmouseover = actb_mouse_down;
				}
				break;
			}
		
	   
		
		}
	
		
      
   //     return false;
  //   }
   
	// alert(document.getElementById("tat_table").innerText);
	
	   	//then set the iframe width accordingly
	    shim.style.width = document.getElementById("tat_table").offsetWidth + 'px';
	    shim.style.height = document.getElementById("tat_table").offsetHeight + 'px';
	
			  				
		actb_rangeu = 1;
		actb_ranged = j-1;
		actb_display = true;
		
	//	alert(actb_total);
		
	if (actb_curr.value.toUpperCase() == document.getElementById("tat_table").innerText) {
	//	 if (actb_total == 1) {
	       actb_pos = 1; 
			  				       					
			actb_penter();
		    actb_display = false;
        //	}	
		}
	
		
		if (actb_pos <= 0) actb_pos = 1; 
	
 
   
	 	
		
	}
	
	
	function actb_remake(){
		document.body.removeChild(document.getElementById('tat_table'));
	 
	  //Remove Iframe 
	  if (document.getElementById('__shim')){    
         document.body.removeChild(document.getElementById('__shim'));
       }
		
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.zIndex = '999';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		
			
		a.id = 'tat_table';
		if (actb_self.actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		document.body.appendChild(a);
		
		
		//Create iframe to overlay any dropdownlist
		 var shim = document.createElement("<iframe scrolling='no' frameborder='0'"+
                                      "style='position:absolute; top:0px;"+
                                      "left:0px; display:none'></iframe>"); 
        shim.name = "__shim";
        shim.id = "__shim";

		document.body.appendChild(shim);
		
   	shim.style.width = '0px';
    shim.style.height = '0px';
    shim.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
    shim.style.left = curLeft(actb_curr) + "px";
    shim.style.zIndex = '900';
    shim.style.position = "absolute";
    shim.style.display = "block";

		
		
		var i;
		var first = true;
		var j = 1;
		if (actb_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
	 		c = r.insertCell(-1);
			c.style.color = actb_self.actb_textColor;
		//	c.style.fontFamily = 'arial narrow';
		//	c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
	  //		replaceHTML(c,'/\\');
	        
	        image_display2=document.createElement('img');
		    image_display2.src='../../../../Panorama/Images/uparrow.gif';   
	        replaceHTML2(c,image_display2);  
	          
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
			//	c.onclick = actb_mouse_up;
				c.onmouseover = actb_mouse_up;
			}
		}
		for (i=0;i<actb_self.actb_keywords.length;i++){
		// var strText2 = actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("-")+1,actb_self.actb_keywords[i].length);
		// if (customapp=='newsuburbsearch') { 
		 if(actb_self.actb_keywords[i].indexOf("*") > 0){ 
		   var strText2 = actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("~")+1,actb_self.actb_keywords[i].indexOf("*"));
	     } 
	     else { 
	      var strText2 = actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("~")+1,actb_self.actb_keywords[i].length);
	     }
	     	if (actb_bool[i]){
				if (j >= actb_rangeu && j <= actb_ranged){
					r = a.insertRow(-1);
					r.style.backgroundColor = actb_self.actb_bgColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
			 		c.style.color = actb_self.actb_textColor;
					c.style.fontFamily = actb_self.actb_fFamily;
					c.style.fontSize = actb_self.actb_fSize;
				//	c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
			       c.innerHTML = actb_parse(strText2);
			       //c.innerHTML = actb_parse(actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("-")+1,actb_self.actb_keywords.length));  
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					
												
					if (actb_self.actb_mouse){
						c.style.cursor = 'pointer';
						c.onclick=actb_mouseclick;
						c.onmouseover = actb_table_highlight;
												
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actb_ranged) break;
		}
		if (j-1 < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_self.actb_textColor;
	//		c.style.fontFamily = 'arial narrow';
		//	c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
		//	replaceHTML(c,'\\/');
		
		    image_display3=document.createElement('img');
		    image_display3.src='../../../../Panorama/Images/downarrow.gif';   
	      replaceHTML2(c,image_display3);  
		
			if (actb_self.actb_mouse){
			 				    
				c.style.cursor = 'pointer';
			//	c.onclick = actb_mouse_down;
				c.onmouseover = actb_mouse_down;
				
			
				
			}
		}
		
	
		
		//then set the iframe width and height accordingly
	    shim.style.width = document.getElementById("tat_table").offsetWidth + 'px';
	    shim.style.height = document.getElementById("tat_table").offsetHeight + 'px';
		 		
	}
	
	
	
	  
	function actb_goup(){
   try { 
        
     
      	if (!actb_display) return;
		if (actb_pos == 1) return;         						
 	    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;				
		actb_pos--;
		if (actb_pos < actb_rangeu) actb_moveup(); 
		  	   document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;     
   	          	
    //  	actb_curr.focus();					
	    
		
		   
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);

    
      }
   catch(e) { 
    
             return false;
          
           }
  
	}
	
	
	function actb_godown(){
	try { 
	//	alert(actb_ranged);
	
		if (!actb_display) return;
		if (actb_pos == actb_total) ret1urn;

     //  document.getElementById('tat_table').style.backgroundColor=actb_self.actb_bgColor;						
      
     
     	document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
	    actb_pos++;  
		
    	if (actb_pos > actb_ranged) actb_movedown(); 
    	
    	document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor; 
	    
	    
	//	actb_curr.focus();
	   
	   		
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);

	
	} 
	 catch(e) { 
	          return false;
           }
	
		
	}
	
	function actb_movedown(){
	   
		actb_rangeu++;
		actb_ranged++;
		actb_remake();
		
	}
	function actb_moveup(){
     	actb_rangeu--;
		actb_ranged--;
 		actb_remake();
	}

	/* Mouse */
	function actb_mouse_down(){
	try {
	    	     
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
	//	actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	catch(e){}
	
	}
	function actb_mouse_up(evt){
	try{
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
	//	actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
    }
   catch(e){}

	}
	function actb_mouseclick(evt){

		if (!evt) evt = event;
		if (!actb_display) return;
		actb_mouse_on_list = 0;
      	actb_pos = this.getAttribute('pos');
		actb_penter();
		
	//**** Here if the raisepostbackevent property is set to true
	//**** then it will do the submit 			    		    
	     if (referval != null) { 			       
	      if (postbackval == 'True') {		       
	         referval.value = 'AutoComplete'; 
	        document.forms[0].submit();
	       }
	     }
		
		
	}
	function actb_table_focus(){
		actb_mouse_on_list = 1;
	}
	function actb_table_unfocus(){
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_table_highlight(){
	try 
	   {
		actb_mouse_on_list = 1;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
	 if (actb_pos != null) { 
		actb_pos = this.getAttribute('pos');
	  }
		while (actb_pos < actb_rangeu) actb_moveup();
		while (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	 
	 } 
	 catch(e) { 
	          return false;
           }
	
	
	}
	/* ---- */

	function actb_insertword(a,b){
	
		if (actb_self.actb_delimiter.length > 0){
		
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actb_delimwords[i].length;++j){
						if (actb_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actb_delimwords[i].length-1;j>=0;--j){
						if (actb_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
		 
		 if (trim2(str) != '') {
		   actb_curr.value = trim2(str);
		   actb_hid.value = b;
		}	
		//  actb_curr.value = str.replace('/^\s*(\S*(\s+\S+)*)\s*$/',"");
	    	
			setCaret(actb_curr,l);
		}else{
		  
			actb_curr.value = a; 
			actb_hid.value = b;
		}
		actb_mouse_on_list = 0;
		actb_removedisp();
	  
	
		
	}
	
	
	//** insertword2 
	function actb_insertword2(a,b,c,d,e,f,g,h){
	
		if (actb_self.actb_delimiter.length > 0){
		
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actb_delimwords[i].length;++j){
						if (actb_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actb_delimwords[i].length-1;j>=0;--j){
						if (actb_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
		 
		 if (trim2(str) != '') {
		   actb_curr.value = trim2(str);
		   actb_hid.value = b;
		  
				  		 		   
				     
		}	
		//  actb_curr.value = str.replace('/^\s*(\S*(\s+\S+)*)\s*$/',"");
	    	
			setCaret(actb_curr,l);
		}else{
		  
			actb_curr.value = a; 
			actb_hid.value = b;
				   		 			
		}
		 
	

	     if (customapp=='newsuburbsearch' || customapp=='newsuburbsearchdeliveryareapostcode') { 
		   actb_statecurr.value = g; 
           actb_countrycurr.value = e; 
           actb_postcodecurr.value = c; 
           actb_statehid.value = h;
           actb_postcodehid.value = d;
           actb_countryhid.value = f; 
           }
		
		actb_mouse_on_list = 0;
		actb_removedisp();
		
	    return;
	}
	
	
	

 function actb_penter(){
  try { 
 //    alert(actb_self.actb_keywords);
      
    if (actb_self.actb_keywords == null) return false;
      
      
   	    if (!actb_display) return;	
	   	actb_display = false;
		var wordval = '';
		var word = '';
		var HidIDVal = '';
		var postcval = '';
		var postchid = '';
		var countryval = '';
		var countryhid = '';
		var stateval = '';
		var stateid = '';
		var c = 0;
		var b;

					
		for (var i=0;i<=actb_self.actb_keywords.length;i++){
		  
			if (actb_bool[i]) c++;			
			if (c == actb_pos){           
           
		   //	word = actb_self.actb_keywords[i];
			  wordval = actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("~")+1,actb_self.actb_keywords[i].length);
			  HidIDVal = actb_self.actb_keywords[i].substring(0,actb_self.actb_keywords[i].indexOf("~"));
	    	     	
	    	   break;
	    	}   
	    	   
			}
			
	//		alert(wordval + '~' + HidIDVal);		
			
		if (wordval.length == 1 || wordval.length < 1) {  
		 actb_curr.style.color="DarkRed";
		return; 
		}
			
		if (wordval.indexOf("*") > 0) { 
	  	  word = wordval.substring(0,wordval.indexOf("-"));
		  postcval = wordval.substring(wordval.indexOf("+")+1,wordval.length);  
		  postchid = wordval.substring(wordval.indexOf("!")+1,wordval.indexOf("+"));   
		  countryval = wordval.substring(wordval.indexOf("%")+1,wordval.indexOf("!"));    
		  countrychid = wordval.substring(wordval.indexOf("&")+1,wordval.indexOf("%"));   
		  stateval = wordval.substring(wordval.indexOf("#")+1,wordval.indexOf("&"));
		  stateid = wordval.substring(wordval.indexOf("*")+1,wordval.indexOf("#"));  
		 
	
	       actb_insertword2(word, HidIDVal,postcval,postchid,countryval,countrychid,stateval,stateid);	
	    	   
		
		} 
		  else 
		{  
		  			  
	
	  	  var charcount = 0; 
	 	 
	 //** loop through the string and check for how many "-" exist
	 	    for (b=0;b<wordval.length;b++) {
	      	   if (wordval.charAt(b) == '-' ) {
	      	     charcount = charcount+1;
	      	   }    
	      	      
	        }
	    
	    
	     
	   //   if (charcount > 1) {  	      	
	     //** if there are more than one "-" then we get all characters till the last "-"(because all those beginning "-" probably are part of the displayed value    
	   // 	       word = wordval.substring(0,wordval.lastIndexOf("-"));  
	  
	//	    }
		    
		    
		//    if (charcount == 1) { 
		//** here we only get the beginning portion of string until the first "-" (because one "-" mostly use to separate the value from the code..so don't have to display the code when enter)
			//   word = wordval.substring(0,wordval.indexOf("-"));       
		//       word = wordval;   
		//     }
		     
		  
		//     if (charcount == 0) { 
		//** if no "-" found then we just display the whole string
		       word = wordval;
		//     } 
				  
		  actb_insertword(word, HidIDVal);
		
		
		}
		
	
		
		
//		actb_insertword(word, HidIDVal);
		l = getCaretStart(actb_curr);
	
	} 
	 catch(e) 
	    { 
	    
	      actb_removedisp();
	      return;
	      
	    }
	
	}
	

	function actb_removedisp(){
	
		if (actb_mouse_on_list==0){
	       actb_display = 0;	     
		//	if (document.getElementById('tat_table')){ document.body.removeChild(document.getElementById('tat_table')); }
		if (document.getElementById('tat_table')){document.body.removeChild(document.getElementById('tat_table')); document.body.removeChild(document.getElementById('__shim'));}
		if (actb_toid) clearTimeout(actb_toid);
		}
	}
	function actb_keypress(e){
      	 
		if (actb_caretmove) stopEvent(e); 
		return !actb_caretmove;
	
	
	}
	
function actb_keyup(){
  var aStr = new Array() ;	 
  var key = actb_curr.value ; 
  actb_pos = 0;
  

				//ADDED 29/11/2006 - By Brett
				//remove & symbol from key!	>>>>>>>>>>>>>>>>>>>>>>>>>>
                  var keysubstring;
                  keysubstring = key.substring(0,key.indexOf("&"));
                  if (keysubstring=='') {
                  //do nothing
                  }
                  else
                  {
                  var aStr;   
                  aStr='';                                
                  aStr = key.split('&');
                  key = '';      
                          
                  for (var i=0;i<aStr.length-1;i++){
						//this is SQL to match a single character
						key = key + aStr[i] + '_';
					}
					//do this so we do not add an extra _ to the end
					key = key + aStr[aStr.length-1];
					
                  //alert(key);
                  }
				//remove & symbol from key!	>>>>>>>>>>>>>>>>>>>>>>>>>>

 
   //** Do a xmlhttprequest to get from database     
   Initialize();   
   
   
        
   //  var url="../../../../Panorama/common/autocompleteAction.aspx?Key="+key+"&Application="+customapplication;
     var url="../../../../Panorama/common/AutoCompleteAction.aspx?RandomKey="+ Math.random() * Date.parse(new Date()) + "&Key="+key+"&Application="+customapplication   
   
          
    if(req!=null)
     { 
       
         req.onreadystatechange = function() { 
            if (req.readyState == 4)  {
             // only if "OK"
            if (req.status == 200)
            {
                             
               if(req.responseText!="")
              {
                  
                  aStr=null;
                  var tempstr=null;
     	          tempstr = req.responseText;
                  tempstr = tempstr.substring(0,tempstr.indexOf("<"));
                  aStr = tempstr.split(':');                 
                          
   
            this.actb_keywords =aStr;    
     //       actb_self.actb_keywords = aStr;
        //        actb_tocomplete(code);
            
              setTimeout(function(){actb_tocomplete(code)},200);
             
            }
            
            
            
            }
        }
         
         
      }
         
         
         req.open("GET", url, true);
         req.send(null);
    
   }   
      
  
  
	}
	
	function actb_checkkey(evt){
 
     
     	if (!evt) evt = event;
	  	a = evt.keyCode;

	// 	    a = code ;
	
	
		   
       var charCode = String.fromCharCode(evt.keyCode);
		caret_pos_start = getCaretStart(actb_curr);
		actb_caretmove = 0;
		switch (a){
			case 38:
		  //  	setTimeout(function(){actb_goup();},70);
		   if (actb_pos <= 0) actb_pos = 1; 
		  	actb_goup();
				actb_caretmove = 1;
				return false;
				break;
			case 40:
			   
		  //    setTimeout(function(){actb_godown();},150);
		      if (actb_pos <= 0) actb_pos = 1; 
		      	actb_godown();
		 
		       	actb_caretmove = 1;
		      
				return false;
				break;
			case 13: case 9:
			 
			    if (actb_display){
				   actb_caretmove = 1;
				   		
					  				    
				    if (actb_pos <= 0) actb_pos = 1; 
				  				       					
					actb_penter();
				
					
				  	actb_mouse_on_list = 0;
			        actb_removedisp();
			     
			     //**** Here if the raisepostbackevent property is set to true
			     //**** then it will do the submit 		
			     if (referval != null) { 			       
			      if (postbackval == 'True') {		       
			        referval.value = 'AutoComplete';
			        document.forms[0].submit();
			           
			   //     referval.value ='';
			       }
			      }
			       			    			   	                      	                  
				   return false;
				}else{
				
				if (actb_curr.value != '' && actb_hid.value =='') {
				  return false;
			
				  } 
				  
				 if (actb_curr.value == '' && actb_hid.value =='') {
				    return true;
				  }
				  
				  if (actb_curr.value != '' && actb_hid.value !='') {
				    return true;
				  }
				  
				  
				}
				break;
							
//			default:
//			    actb_keyup();
//				setTimeout(function(){actb_tocomplete(a)},50);
//				break;
		}
		

		
	}
	
	
	
 function actb_checkkey2(evt){

	if (!evt) evt = event;
//		a = evt.keyCode;
      a=code;		
      
  	setTimeout(function(){actb_tocomplete(a)},180);
// setTimeout(function(){actb_tocomplete(a)},0);
 //    actb_tocomplete(a);
         				
}

	function actb_tocomplete(kc){
   	
    if (kc == 38 || kc == 40 || kc == 13|| kc == 9) return;
		var i;
		
	
//    alert(actb_self.actb_keywords)   
//   	actb_self.actb_keywords = ca;	  
     // actb_pos = 0;
      	//	   	  	 alert(actb_mouse_on_list);   
    		   	   
	   actb_hid.value = '';
	  actb_curr.value = actb_curr.value;
		
		if (actb_display){
				
			var word = 0;
			var c = 0;
			for (var i=0;i<=actb_self.actb_keywords.length;i++){
			 	if (actb_bool[i]) c++;
							
				if (c == actb_pos){	
						 				
				  	word = i;
					break;
				}
			}
			actb_pre = word;
		}else{actb_pre = -1};
		
		if (trim2(actb_curr.value) == ''){
		   
		    actb_mouse_on_list = 0;
			actb_removedisp();
		 
		 if (customapp=='newsuburbsearch' || customapp=='newsuburbsearchdeliveryareapostcode') { 
		   actb_curr.value = '';
		   actb_hid.value = '';
		   actb_statecurr.value = ''; 
           actb_countrycurr.value = ''; 
           actb_postcodecurr.value = ''; 
           actb_statehid.value = '';
           actb_postcodehid.value = '';
           actb_countryhid.value = ''; 
          }
			
			return;
		}
		
		
		
		
  		
				
		if (actb_self.actb_delimiter.length > 0){
		   
		 
			caret_pos_start = getCaretStart(actb_curr);
			caret_pos_end = getCaretEnd(actb_curr);
		    
		  		    	
			delim_split = '';
			for (i=0;i<actb_self.actb_delimiter.length;i++){
				delim_split += actb_self.actb_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actb_delimwords = new Array();
			actb_delimwords[0] = '';
			for (i=0,j=actb_curr.value.length;i<actb_curr.value.length;i++,j--){
				if (actb_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actb_curr.value.substr(i,j).match(delim_split_rx);
					actb_delimchar[c] = ma[1];
					c++;
					actb_delimwords[c] = '';
				}else{
					actb_delimwords[c] += actb_curr.value.charAt(i);
				}
			}

			var l = 0;
			actb_cdelimword = -1;
			for (i=0;i<actb_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length){
					actb_cdelimword = i;
				}
				l+=actb_delimwords[i].length + 1;
			}
			var ot = actb_delimwords[actb_cdelimword].trim(); 
			var t = actb_delimwords[actb_cdelimword].addslashes().trim();
		}else{		
		    		    		 	
			var ot = actb_curr.value;
			var t = actb_curr.value.addslashes();
		}
		if (ot.length == 0){
			actb_mouse_on_list = 0;
			actb_removedisp();
		}
		
		
		if (ot.length < actb_self.actb_startcheck) return this;
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

		actb_total = 0;
		actb_tomake = false;
	    actb_kwcount = 0;
		var countitem = 0;
		
		var kwordslength;
		
	
	 
	
						
		for (i=0;i<actb_self.actb_keywords.length;i++){
	 	// alert(actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("-")+1,actb_self.actb_keywords[i].length));
			    
	
	  if (actb_self.actb_keywords[i].indexOf("*") > 0){
	     kwordslength = actb_self.actb_keywords[i].indexOf("*");
	     
	     }
	     else { 
	     
	       kwordslength = actb_self.actb_keywords[i].length;
	     
	     }
				
			actb_bool[i] = false;
		
	//	 	if (re.test(actb_self.actb_keywords[i])){
	//	  if(re.test(actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("-")+1,actb_self.actb_keywords[i].length))){
   	
	 	if(re.test(actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("~")+1,kwordslength))){
	 	    
	 //     alert(actb_self.actb_keywords[i].substring(actb_self.actb_keywords[i].indexOf("-")+1,kwordslength)); 	
	        	actb_total++;
				actb_bool[i] = true;
				actb_kwcount++;
		    
				if (actb_pre == i) actb_tomake = true;
		         
		         
	   
		     						
				
			}
		}

  	     
  		if (actb_toid) clearTimeout(actb_toid);
	 	if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
		 setTimeout(function(){actb_generate();},400);		 
	 // 	 actb_generate(); 
	
	
    
	   
	        //** if only one value in list , fill into textbox automatically
     //   if (kc != 8 && kc != "[object]") {
	 //     if (actb_total == 1) {
	      
	 //       actb_penter();  
	    
	 	    
	 //       }
	       
     //  }
  	     
	

 //  	if (actb_total == 1) { 
//		actb_mouse_on_list = 0;
//			actb_removedisp();
//			return;
		 
//		 }
            			
	}
             		
	return this;


}

catch(e) { 
    
             return false;
           } 


} 

// End of actb function 


// Add an event to the obj given
// event_name refers to the event trigger, without the "on", like click or mouseover
// func_name refers to the function callback when event is triggered
function addEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}

// Removes an event from the object
function removeEvent(obj,event_name,func_name){
	if (obj.detachEvent){
		obj.detachEvent("on"+event_name,func_name);
	}else if(obj.removeEventListener){
		obj.removeEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = null;
	}
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt){
	evt || window.event;
	if (evt.stopPropagation){
		evt.stopPropagation();
		evt.preventDefault();
	}else if(typeof evt.cancelBubble != "undefined"){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	return false;
}

// Get the obj that starts the event
function getElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.currentTarget;
	}
}
// Get the obj that triggers off the event
function getTargetElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.target;
	}
}
// For IE only, stops the obj from being selected
function stopSelect(obj){
	if (typeof obj.onselectstart != 'undefined'){
		addEvent(obj,"selectstart",function(){ return false;});
	}
}

//*    Caret Functions     */

// Get the end position of the caret in the object. Note that the obj needs to be in focus first
function getCaretEnd(obj){
if (window.onerror) return false;

	if(typeof obj.selectionEnd != "undefined"){
		return obj.selectionEnd;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToEnd",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}

// Get the start position of the caret in the object
function getCaretStart(obj){
if (window.onerror) return false;

	if(typeof obj.selectionStart != "undefined"){
		return obj.selectionStart;
		
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToStart",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}


// sets the caret position to l in the object
function setCaret(obj,l){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(l,l);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',l);
		m.collapse();
		m.select();
	}
}

// sets the caret selection from s to e in the object
function setSelection(obj,s,e){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(s,e);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',s);
		m.moveEnd('character',e);
		m.select();
	}
}



/* --- Escape --- */

/* Offset position from top of the screen */
function curTop(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return toreturn;
}

function curLeft(obj){
	toreturn = 0;
	
	while(obj){
		toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
		//try{toreturn -= obj.scrollLeft;}catch(echi){}
	}
	
	return toreturn;
}

/* ------ End of Offset function ------- */


/*    Escape function   */
String.prototype.addslashes = function(){

var str = this;
str = str.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)\s])/g, '\\$1');

//str = str.replace( /\\/g,'\\$1');
//str = str.replace( /\[/g,'\\$1');
//str = str.replace( /\]/g,'\\$1');
//str = str.replace( /\(/g,'\\$1');
//str = str.replace( /\)/g,'\\$1');
//str = str.replace( /\*/g,'\\$1');

return str;

 //	return this.replace('/(["\\\.\|\[\]\^\*\+\?\$\(\)\s])/g', '\\$1');
//    return encodeURIComponent(this.replace('/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g', '\\$1'));

}

String.prototype.trim = function () {

    

     return this.replace('/^\s*(\S*(\s+\S+)*)\s*$/', "$1");
   
  //   return encodeURIComponent(this.replace('/^\s*(\S*(\s+\S+)*)\s*$/', "$1"));    
     
  };



// is a given input a number?
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function trim2(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}


function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;

}

function replaceHTML(obj,text){
	while(el = obj.childNodes[0]){
		obj.removeChild(el);
	};
	obj.appendChild(document.createTextNode(text));
}	 


function replaceHTML2(obj,text){
	while(el = obj.childNodes[0]){
		obj.removeChild(el);
	};
	obj.appendChild(text);
}	 
}

catch (e)
{		

	JavascriptHandler(e.message + " in AutoComplete.js", "AutoComplete.js", -1)	
}
