	function autoTextCompletion(NameTextField,IDTextField,ListDivTextField,serviceName,max_return)
	{	
		var XMLHttpRequestObject; 
		var length=0; //
		var listString = "";
		var name=document.getElementById(NameTextField).value;
		var queryString="";
		
		if(serviceName.indexOf("search_taxon.php")==0){
			clearTaxonFieldsOnce();
		}
		if(serviceName.indexOf("search_geopol.php")==0){
			clearCountryProvinceFieldsOnce();
		}
		
		if(name.length==0){
			listString = "";
			document.getElementById(ListDivTextField).innerHTML=listString;
		}

		document.getElementById(IDTextField).value="";
		document.getElementById(ListDivTextField).style.height="100%";
	
		if(document.getElementById(NameTextField).value ==''){
			document.getElementById(NameTextField).style.border = '1px solid #e8a225'; //yellow
		}
		else{
			document.getElementById(NameTextField).style.border = '1px solid #990000'; //red
		}
	
		try{
			// Opera 8.0+, Firefox, Safari
			XMLHttpRequestObject = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		
		// This function will receive data sent from the server
		XMLHttpRequestObject.onreadystatechange = function(){
			if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status== 200){
				
				document.getElementById(ListDivTextField).style.visibility = 'visible';
				
				if(XMLHttpRequestObject.responseText =='[{"HITS":null}]'){ 
				
					document.getElementById(IDTextField).value='';
					document.getElementById(NameTextField).value='';
					document.getElementById(ListDivTextField).innerHTML=listString;
				}
				myArray = eval("(" + XMLHttpRequestObject.responseText + ")");
				
				listString +="<table style=\"z-index:1; background-color: #F5F5F2; color: #EBEAE8; border: 1px solid #757573; padding: 0.25em; width:210\" >";
				
				var myArray_length=myArray.length-1;
				
				if(myArray[myArray_length].HITS != null){ 
					for (var i = 0 ; i < (myArray.length-1) ; i++) {
						var escapeSingleQuoteinName=myArray[i].NAME.replace("'","*");
						length++;
						listString += "<tr><td  width=\"180px\" class=\"menuoff\"  onmouseover=\"className='menuon';\" onmouseout=\"className='menuoff';\"><a href='Javascript:SelectAutoTextCompletion(\""+NameTextField+"\",\""+escapeSingleQuoteinName+"\",\""+myArray[i].ID+"\",\""+IDTextField+"\",\""+ListDivTextField+"\",\""+serviceName+"\");'>" +  myArray[i].NAME + "</a><br></td></tr>";
					}
				
					if(myArray[myArray_length].HITS == 0){
						listString += "<tr><td><span class=\'listString\'>No Matches Were Found: </span></td></tr>";
					}
					
					if(myArray[myArray_length].HITS > max_return){
						var more_names=myArray[myArray_length].HITS - max_return;
						listString += "<tr><td><span class=\'listString\'>" + more_names + " Other Matches </span></td></tr>";
					}
					
					if(myArray[myArray_length].HITS < max_return){
						listString += "";
					}
					listString +="</table>";
					document.getElementById(ListDivTextField).innerHTML=listString;
					}
					else{}
				}
			}//onreadystatechange
			
			if(name.length!=0){
				if(name!=null || name!=''){
					if(serviceName.indexOf("?")>0){
						queryString += "&name=" + name;
					}
					
					else{
						queryString += "?name=" + name;
					}
					
					if(max_return!=null || max_return!=''){
						queryString += "&max_return=" + max_return;
					}
						XMLHttpRequestObject.open("GET", "../../services/"+serviceName+ queryString, true);
						XMLHttpRequestObject.send(null); 
				
				}
			}
	}

	function SelectAutoTextCompletion(NameTextField,NameValue,IDValue,IDTextField,ListDivTextField,serviceName)
	{
		var NameValue=NameValue.replace("*","'");
		//display the ID value from database in IDTextfield
		document.getElementById(IDTextField).value=IDValue;
		
		//display the NAME value from database in NameTextfield
		document.getElementById(NameTextField).value=NameValue;
		
		document.getElementById(NameTextField).style.borderColor ='#006600'; //green
		document.getElementById(NameTextField).style.border = '1px solid #006600';
		document.getElementById(NameTextField).style.color = '#000000';
		
		document.getElementById(ListDivTextField).style.visibility = 'hidden';
		document.getElementById(ListDivTextField).style.height='10px';
		
		if(serviceName.indexOf("search_taxon.php")==0){
			getTaxonInfo();
		}
		if(serviceName.indexOf("search_geopol.php")==0){
			getLocationInfo();
		}
    }
	
	function clearTaxonFieldsOnce(){
		if((document.getElementById("class").options.length>1) || (document.getElementById("order").options.length>1) || (document.getElementById("family").options.length>1) || (document.getElementById("subfamily").options.length>1) || (document.getElementById("genus").options.length>1) || (document.getElementById("species").options.length>1)){
			clearTaxonFields();
		}
	}
	
	function clearCountryProvinceFieldsOnce(){
		if((document.getElementById("province").options.length>1) || (document.getElementById("country").options.length>1)){
			clearCountryProvinceFields();
		}
	}
