var xmlhttp;
var current_query;
var current;

function hide_hints_locations(id)
{
clear_selections_locations();
document.getElementById(id).style.display = 'none';
}


function showHint_locations(str,t,type)
{
var id = 'input-'+type;
var suggest_id = 'suggest-'+type;

	if (str.length==0)
	{
	clear_search(id);
	clear_selections_locations();
	document.getElementById(suggest_id).style.display = 'none';
	document.getElementById(suggest_id).innerHTML="";
	return;
	} else {
	show_clear(id);
	}
  
xmlhttp=GetXmlHttpObject_locations();

	if (xmlhttp==null)
	{
	//  alert ("Your browser does not support XMLHTTP!");
	return;
	}
  
	if(str !== current_query)
	{
	clear_selections_locations();
	current_query = str;
	var url="/postcode/femalefriendly/find_matches.php";
	url=url+"?q="+str;
	url=url+"&t="+t;


	//url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged_locations;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	}
	
}

function stateChanged_locations()
{
if (xmlhttp.readyState==4)
  {
  	if(xmlhttp.responseText !== 'No suggestions.')
  	{
	document.getElementById("suggest-in").style.display = 'block';
	document.getElementById("suggest-in").innerHTML=xmlhttp.responseText;
	} else {
	document.getElementById("suggest-in").style.display = 'none';
	document.getElementById("suggest-in").innerHTML="";
	}
  }
}

function GetXmlHttpObject_locations()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}







function choose_suggestion_locations(suggestion)
	{
	var data = explode(';', suggestion);
		
	document.getElementById("postcode").value = data[1];

	document.getElementById("suggest-in").style.display = 'none';
	document.getElementById("suggest-in").innerHTML="";
	document.getElementById('input-in').value = data[0];
	}
	
	
	
	
	
var selected_location = 0;
	
function checkArrows_locations (field, evt) 
	{
	var keyCode = 
    document.layers ? evt.which :
    document.all ? event.keyCode :
    document.getElementById ? evt.keyCode : 0;

  
	  	if((keyCode == 40) || (keyCode == 38))
	  	{
	  	
			if(document.getElementById('suburbs-suggestions'))
			{
		  	
			var parent = document.getElementById('suburbs-suggestions');
			var childCount = parent.getElementsByTagName('li').length;
		  
				if (keyCode == 40) //down
				{
				n = selected_location + 1;
			    } else if (keyCode == 38) { //up
				n = selected_location - 1;
				}
				
				if(n < 1)
				{
				n = childCount;
				} else if(n > childCount) {
				n = 1;
				}
				
			highlight_selection_locations(n);
			}
			
		}
	
	}

function clear_selections_locations()
	{
	selected_location = 0;
	
		if(document.getElementById('suburbs-suggestions'))
		{
		var parent = document.getElementById('suburbs-suggestions');
		var childCount = parent.getElementsByTagName('li').length;
		var n = 1;
		
			while (n <= childCount)
			{
			document.getElementById('suburbs-suggestion'+n).style.backgroundPosition = '0 0';
			n++;
			}

		
		}
	
	}


function highlight_selection_locations(n)
	{
	clear_selections_locations();

	selected_location = n;
	document.getElementById('suburbs-suggestion'+n).style.backgroundPosition = '-165px 0';
	}