  
  function ieTrick(sep) 
{ 
  d = new Date(); 
  trick = d.getYear() + "ie" + d.getMonth() + "t" + d.getDate() + "r" + d.getHours() + "i" + d.getMinutes() + "c" + d.getSeconds() + "k" + d.getMilliseconds(); 
    
  if (sep != "?") 
  { 
    sep = "&"; 
  } 
    
  return sep + "ietrick=" + trick; 
}
  
window.onload=initall;

  var xhr=false;
  
  var statesarray=new Array();
  function initall(){
 //alert(1);

  	if(document.getElementById("searchfield")){
  	document.getElementById("searchfield").onkeyup=searchsuggest;
  	}
  	if(window.XMLHttpRequest){
  		xhr=new XMLHttpRequest();
  	}
  	else{
  	if(window.ActiveXObject){
  		try{
  			xhr=new ActiveXObject("Microsoft.XMLHTTP");
  		}
  		catch(e){
  			try{
  			xhr=new ActiveXObject('Msxml2.XMLHTTP');
  		}catch(e){}
  		}
  	}
  }
  if(xhr){

  	xhr.open("GET","aide_saisie_xml.php?" + ieTrick("?"),"true");
  	xhr.onreadystatechange=setstatesarray;
  	//xhr.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")marche bien aussi(cache)
  	xhr.send(null);
  }
  else{
  	alert("sorry cant create xmlhttprequest");
  }
  }
  function setstatesarray(){
  	if(xhr.readyState==4){
  		
  		if(xhr.status==200){
  	if(xhr.responseXML){
  		
  				var allstates=xhr.responseXML.getElementsByTagName("item");
  				
  				for(var i=0;i<allstates.length;i++){
  			 statesarray[i]=allstates[i].getElementsByTagName("label")[0].firstChild;
  					
  				}
  		
  				
  			}
  		}
  
  	else{
  		//alert("problem");
  	}
}
  }
  function searchsuggest(){
 
  	var str=document.getElementById("searchfield").value;
  	document.getElementById("searchfield").className="";
  
  	if(str != ""){
  		document.getElementById("popups").innerHTML="";		
  		for(var i=0;i<statesarray.length;i++){
  			var thisstate=statesarray[i].nodeValue;		 		
  			if(thisstate.toLowerCase().indexOf(str.toLowerCase())==0){			
  			var tempdiv=document.createElement("div");			
  			tempdiv.innerHTML=thisstate;
  			tempdiv.onclick=makechoice;
  			tempdiv.className="suggestions";
  			document.getElementById("popups").appendChild(tempdiv);
  			/*iE hover*/
  			tempdiv.onmouseover=function(){this.style.backgroundColor="#F0F8FF";this.style.cursor="default";}
  			tempdiv.onmouseout=function(){this.style.backgroundColor="#FFF";}
  			/*fin ie hover*/
  		
  			
  				
  			}		
  		}
  		var foundct=document.getElementById("popups").childNodes.length;
  		if(foundct==0){
  			document.getElementById("searchfield").className="error";
  			}
  		if(foundct==1){
  			document.getElementById("searchfield").value=document.getElementById("popups").firstchild.innerHTML;
  			document.getElementById("popups").innerHTML="";
  			
  		}
  	}
  }
  function makechoice(evt){
  	var thisdiv=(evt)?evt.target:window.event.srcElement;
  		
  	document.getElementById("searchfield").value=this.innerHTML;

//var inner=this.innerHTML;
//inner.toString();
//inner.split(" (");
  	//document.getElementById("searchfieldget").value=inner[0];
  	document.getElementById("popups").innerHTML="";
 }
  
  	