function suggest_left(e)
{
	var intKey = 0;
	e = (window.event)? event : e;
	intKey = (e.keyCode)? e.keyCode: e.charCode;

	if (intKey == 40) //down
	{
		
		//SWITCH THEM OFF
		if (this.pos>0 && this.pos<=num_rows)
		{
			
			div_id = "s"+this.pos;
		
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("industry_nameleft").value = '';
		}
		
		//SWITCH THEM ON
		if (this.pos+1<=num_rows)
		{			
			this.pos = this.pos+1;
			div_id = "s"+this.pos;
			document.getElementById(div_id).style.background = '#ffffff';
			document.getElementById("industry_nameLeft").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if(this.pos+1 == num_rows+1)
		{
			this.pos = this.pos +1;			
		}
	}
	else if (intKey == 38) //up
	{
		//SWITCH THEM OFF
		if (this.pos>0 && this.pos<=num_rows)
		{
			div_id = "s"+this.pos;
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("industry_nameleft").value = '';
		}
		
		//SWITCH THEM ON
		if (this.pos-1>0)
		{
			this.pos = this.pos-1;
			div_id = "s"+this.pos;
			document.getElementById(div_id).style.background = '#ffffff';
			input_text = 
			document.getElementById("industry_nameleft").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if (this.pos-1==0)
		{
			this.pos = this.pos-1;
		}
	}
	else 
	{
		this.pos=0;
		getSuggestions_left();
	}
}

function getSuggestions_left()
{
	xmlHttp=GetXmlHttpObject2();

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}


	var url="/suggest_left.php?str="+document.getElementById("industry_nameleft").value +"&city_name=" + document.getElementById('city_nameleft').value ;
	
	xmlHttp.onreadystatechange=displaySuggestions_left;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function displaySuggestions_left() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		trimmed = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
		
		delim = trimmed.indexOf(":==:");
		
		num_rows = parseInt(trimmed.substr(0,delim));
		
		remaining = trimmed.substr(trimmed.indexOf(":==:")+4);
		
		trimmed = remaining;
		
		if (remaining!='')
		{
			document.getElementById("suggestBox_left").style.visibility = 'visible';
		
			document.getElementById("suggestBox_left").innerHTML=remaining;
		}
		else
		{
			document.getElementById("suggestBox_left").style.visibility = 'hidden';
			this.pos = 0;
		}
	} 	
}



function changePosition_left(id)
{
	if (this.pos > 0 && this.pos <= num_rows)
	{
		div_id = "s"+this.pos;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("industry_nameleft").value = '';
	}
		
	this.pos = id;
	div_id = "s"+this.pos;
	document.getElementById(div_id).style.background = '#ffffff';
}

function updateSearch_left(id)
{
	if (this.pos > 0 && this.pos <= num_rows)
	{
		div_id = "s"+this.pos;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("industry_nameleft").value = '';
	}
		
	this.pos = id;
	div_id = "s"+this.pos;
	document.getElementById(div_id).style.background = '#ffffff';
	document.getElementById("industry_nameleft").value = document.getElementById(div_id +"_value").value.replace(/&amp;/gi, '&');
	
	document.getElementById("suggestBox_left").style.visibility = 'hidden';
	document.getElementById("industry_nameleft").focus();
	document.getElementById("industry_nameleft").value = document.getElementById("industry_nameleft").value;
	this.pos = 0;
}

function clickedon_left(id)
{
	//alert('yip' + document.getElementById('industry_name_left').value);
	
	if(document.getElementById('industry_nameleft').value=='')
	{
		document.getElementById('industry_nameleft').value='Find a Service ...';
	}else if( document.getElementById('industry_nameleft').value=='Find a Service ...')
	{
		document.getElementById('industry_nameleft').value='';
	}
	
	document.getElementById('suggestBox_left').style.visibility='hidden';
}


function GetXmlHttpObject2()
{
	var xmlHttp;
	try
	{    // Firefox, Opera 8.0+, Safari
	    xmlHttp=new XMLHttpRequest();    
	}
	catch (e)
	{    // Internet Explorer    
		try
		{      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e)
		{     
			try
			{       
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e)
			{        
				alert("Your browser does not support AJAX!");        
				return false;        
			}      
		}    
	}
	return xmlHttp;
}

function suggest_left2(e)
{
	var intKey = 0;
	e = (window.event)? event : e;
	intKey = (e.keyCode)? e.keyCode: e.charCode;

	if (intKey == 40) //down
	{
		
		//SWITCH THEM OFF
		if (this.pos>0 && this.pos<=num_rows)
		{
			
			div_id = "s"+this.pos;
		
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("industry_nameleft2").value = '';
		}
		
		//SWITCH THEM ON
		if (this.pos+1<=num_rows)
		{			
			this.pos = this.pos+1;
			div_id = "s"+this.pos;
			document.getElementById(div_id).style.background = '#ffffff';
			document.getElementById("industry_nameLeft2").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if(this.pos+1 == num_rows+1)
		{
			this.pos = this.pos +1;			
		}
	}
	else if (intKey == 38) //up
	{
		//SWITCH THEM OFF
		if (this.pos>0 && this.pos<=num_rows)
		{
			div_id = "s"+this.pos;
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("industry_nameleft2").value = '';
		}
		
		//SWITCH THEM ON
		if (this.pos-1>0)
		{
			this.pos = this.pos-1;
			div_id = "s"+this.pos;
			document.getElementById(div_id).style.background = '#ffffff';
			input_text = 
			document.getElementById("industry_nameleft2").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if (this.pos-1==0)
		{
			this.pos = this.pos-1;
		}
	}
	else 
	{
		this.pos=0;
		getSuggestions_left2();
	}
}

function getSuggestions_left2()
{
	xmlHttp=GetXmlHttpObject2();

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}


	var url="/suggest_left.php?str="+document.getElementById("industry_nameleft2").value +"&city_name=" + document.getElementById('city_nameleft2').value ;
	
	xmlHttp.onreadystatechange=displaySuggestions_left2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function displaySuggestions_left2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		trimmed = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
		
		delim = trimmed.indexOf(":==:");
		
		num_rows = parseInt(trimmed.substr(0,delim));
		
		remaining = trimmed.substr(trimmed.indexOf(":==:")+4);
		
		trimmed = remaining;
		
		if (remaining!='')
		{
			document.getElementById("suggestBox_left2").style.visibility = 'visible';
		
			document.getElementById("suggestBox_left2").innerHTML=remaining;
		}
		else
		{
			document.getElementById("suggestBox_left2").style.visibility = 'hidden';
			this.pos = 0;
		}
	} 	
}



function changePosition_left2(id)
{
	if (this.pos > 0 && this.pos <= num_rows)
	{
		div_id = "s"+this.pos;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("industry_nameleft2").value = '';
	}
		
	this.pos = id;
	div_id = "s"+this.pos;
	document.getElementById(div_id).style.background = '#ffffff';
}

function updateSearch_left2(id)
{
	if (this.pos > 0 && this.pos <= num_rows)
	{
		div_id = "s"+this.pos;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("industry_nameleft2").value = '';
	}
		
	this.pos = id;
	div_id = "s"+this.pos;
	document.getElementById(div_id).style.background = '#ffffff';
	document.getElementById("industry_nameleft2").value = document.getElementById(div_id +"_value").value.replace(/&amp;/gi, '&');
	
	document.getElementById("suggestBox_left2").style.visibility = 'hidden';
	document.getElementById("industry_nameleft2").focus();
	document.getElementById("industry_nameleft2").value = document.getElementById("industry_nameleft2").value;
	this.pos = 0;
}

function clickedon_left2(id)
{
	//alert('yip' + document.getElementById('industry_name_left2').value);
	
	if(document.getElementById('industry_nameleft2').value=='')
	{
		document.getElementById('industry_nameleft2').value='Find a Service ...';
	}else if( document.getElementById('industry_nameleft2').value=='Find a Service ...')
	{
		document.getElementById('industry_nameleft2').value='';
	}
	
	document.getElementById('suggestBox_left2').style.visibility='hidden';
}


var posb=0;
var num_rowsb;

function changePosition_b(id)
{
	if (this.posb > 0 && this.posb <= num_rowsb)
	{
		div_id = "sb"+this.posb;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("search").value = '';
	}
		
	this.posb = id;
	div_id = "sb"+this.posb;
	document.getElementById(div_id).style.background = '#ffffff';
}

function updateSearch_b(id)
{
	if (this.posb > 0 && this.posb <= num_rowsb)
	{
		div_id = "sb"+this.posb;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("search").value = '';
	}
		
	this.posb = id;
	div_id = "sb"+this.posb;
	document.getElementById(div_id).style.background = '#ffffff';
	document.getElementById("search").value = document.getElementById(div_id +"_value").value.replace(/&amp;/gi, '&');
	
	document.getElementById("suggestBoxb").style.visibility = 'hidden';
	document.getElementById("search").focus();
	document.getElementById("search").value = document.getElementById("search").value;
	this.posb = 0;
}

function suggest_b(e)
{
	var intKey = 0;
	e = (window.event)? event : e;
	intKey = (e.keyCode)? e.keyCode: e.charCode;
	
	if (intKey == 40) //down
	{
		
		
		//SWITCH THEM OFF
		if (this.posb>0 && this.posb<=num_rowsb)
		{
			
			div_id = "sb"+this.posc;
		
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("search").value = '';
		}
		
		//SWITCH THEM ON
		if (this.posb+1<=num_rowsb)
		{			
			//alert('city_down on');
			this.posb = this.posb+1;
			div_id = "sb"+this.posb;
			document.getElementById(div_id).style.background = '#ffffff';
			document.getElementById("search").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if(this.posb+1 == num_rowsb+1)
		{
			this.posb = this.posb +1;			
		}
	}
	else if (intKey == 38) //up
	{
		//SWITCH THEM OFF
		if (this.posb>0 && this.posb<=num_rows)
		{
			div_id = "sb"+this.posb;
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("search").value = '';
		}
		
		//SWITCH THEM ON
		if (this.posb-1>0)
		{
			this.posb = this.posb-1;
			div_id = "sb"+this.posb;
			document.getElementById(div_id).style.background = '#ffffff';
			input_text = 
			document.getElementById("search").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if (this.posb-1==0)
		{
			this.posb = this.posb-1;
		}
	}
	else 
	{
		this.posb=0;
		getSuggestions_b();
	}
}

function getSuggestions_b()
{
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url="/suggest_bus.php?str="+document.getElementById("search").value +"&city_name=" + document.getElementById("city_nameleft").value +"&industry_name=" +document.getElementById("industry_nameleft").value +"&sid="+Math.random();
	xmlHttp.onreadystatechange=displaySuggestions_b;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

 
function displaySuggestions_b() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		trimmed = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
		
		delim = trimmed.indexOf(":==:");
		
		num_rowsb = parseInt(trimmed.substr(0,delim));
		//alert(num_rowsc);
		remaining = trimmed.substr(trimmed.indexOf(":==:")+4);
		
		trimmed = remaining;
		
		if (remaining!='')
		{
			document.getElementById("suggestBoxb").style.visibility = 'visible';
		
			document.getElementById("suggestBoxb").innerHTML=remaining;
		}
		else
		{
			document.getElementById("suggestBoxb").style.visibility = 'hidden';
			this.posb = 0;
		}
	} 	
}

function GetXmlHttpObject()
{
	var xmlHttp;
	try
	{    // Firefox, Opera 8.0+, Safari
	    xmlHttp=new XMLHttpRequest();    
	}
	catch (e)
	{    // Internet Explorer    
		try
		{      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e)
		{     
			try
			{       
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e)
			{        
				alert("Your browser does not support AJAX!");        
				return false;        
			}      
		}    
	}
	return xmlHttp;
}


var pocs=0;
var num_rowsc;

function changePosition_c(id)
{
	if (this.posc > 0 && this.posc <= num_rowsc)
	{
		div_id = "sc"+this.posc;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("city_nameleft").value = '';
	}
		
	this.posc = id;
	div_id = "sc"+this.posc;
	document.getElementById(div_id).style.background = '#ffffff';
}

function updateSearch_c(id)
{
	if (this.posc > 0 && this.posc <= num_rowsc)
	{
		div_id = "sc"+this.posc;
		document.getElementById(div_id).style.background = '#F1F8FF';
		document.getElementById("city_nameleft").value = '';
	}
		
	this.posc = id;
	div_id = "sc"+this.posc;
	document.getElementById(div_id).style.background = '#ffffff';
	document.getElementById("city_nameleft").value = document.getElementById(div_id +"_value").value.replace(/&amp;/gi, '&');
	
	document.getElementById("suggestBoxc").style.visibility = 'hidden';
	document.getElementById("city_nameleft").focus();
	document.getElementById("city_nameleft").value = document.getElementById("city_nameleft").value;
	this.pos = 0;
}

function suggest_c(e)
{
	var intKey = 0;
	e = (window.event)? event : e;
	intKey = (e.keyCode)? e.keyCode: e.charCode;
	
	if (intKey == 40) //down
	{
		
		
		//SWITCH THEM OFF
		if (this.posc>0 && this.posc<=num_rowsc)
		{
			
			div_id = "sc"+this.posc;
		
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("city_nameleft").value = '';
		}
		
		//SWITCH THEM ON
		if (this.posc+1<=num_rowsc)
		{			
			//alert('city_down on');
			this.posc = this.posc+1;
			div_id = "sc"+this.posc;
			document.getElementById(div_id).style.background = '#ffffff';
			document.getElementById("city_nameleft").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if(this.posc+1 == num_rowsc+1)
		{
			this.posc = this.posc +1;			
		}
	}
	else if (intKey == 38) //up
	{
		//SWITCH THEM OFF
		if (this.posc>0 && this.posc<=num_rows)
		{
			div_id = "sc"+this.pos;
			document.getElementById(div_id).style.background = '#F1F8FF';
			document.getElementById("city_nameleft").value = '';
		}
		
		//SWITCH THEM ON
		if (this.posc-1>0)
		{
			this.posc = this.posc-1;
			div_id = "sc"+this.posc;
			document.getElementById(div_id).style.background = '#ffffff';
			input_text = 
			document.getElementById("city_nameleft").value = document.getElementById(div_id + "_value").value.replace(/&amp;/gi, '&');
		}
		else if (this.posc-1==0)
		{
			this.posc = this.posc-1;
		}
	}
	else 
	{
		this.posc=0;
		getSuggestions_c();
	}
}

function getSuggestions_c()
{
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url="/suggest_city.php?str="+document.getElementById("city_nameleft").value+"&sid="+Math.random();
	xmlHttp.onreadystatechange=displaySuggestions_c;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function displaySuggestions_c() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		trimmed = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
		
		delim = trimmed.indexOf(":==:");
		
		num_rowsc = parseInt(trimmed.substr(0,delim));
		//alert(num_rowsc);
		remaining = trimmed.substr(trimmed.indexOf(":==:")+4);
		
		trimmed = remaining;
		
		if (remaining!='')
		{
			document.getElementById("suggestBoxc").style.visibility = 'visible';
		
			document.getElementById("suggestBoxc").innerHTML=remaining;
		}
		else
		{
			document.getElementById("suggestBoxc").style.visibility = 'hidden';
			this.posc = 0;
		}
	}
}
