var busloc1 = "";
var wbSiteWSn1 = new String();
function ValidatesearchBusinessFooter(act,wbSite)
{
	wbSiteWSn1 = wbSite;
	var is_zip = 0;
	if(document.getElementById('busKeyword1').value.match(/^\s*$/) || document.getElementById('busKeyword1').value=='name or category')
	{
		alert("Please enter a business name or category to perform a search");
		document.getElementById('busKeyword1').focus();
		return false;
	}	
	if(document.getElementById('buslocation1').value.match(/^\s*$/))
	{
		alert("Please enter the location as City, State");
		document.getElementById('buslocation1').focus();
		return false;
	}	
	searchLocation=trimAllVSerarchFooter(document.getElementById('buslocation1').value);
	if(searchLocation.length<5){
		alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
		return false;
		document.getElementById('buslocation1').focus();
	}
	locationArray=searchLocation.split(",");	
	if(locationArray.length==1)
	{ 
		alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
		document.getElementById('buslocation1').focus();
		return false;						
	}
	else if(locationArray.length==2)
	{
		locationArray[0]=trimAllVSerarchFooter(locationArray[0]);
		locationArray[1]=trimAllVSerarchFooter(locationArray[1]);		
		if(locationArray[0].match(/[0-9]+/)){
				alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
				document.getElementById('buslocation1').focus();
				return false;
		}
		else 
		{			
			stateArray=locationArray[1].split(" ");
			if(stateArray.length>2){
				alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
				document.getElementById('buslocation1').focus();
				return false;
			}
			stateArray[0]=trimAllVSerarchFooter(stateArray[0]);
			if(stateArray[0].match(/[0-9]+/)){
				//alert("Please enter proper State name.");
				alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
				document.getElementById('buslocation1').focus();
				return false;
			} 
			
			if(stateArray[0].length<2){				
				alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
				document.getElementById('buslocation1').focus();
				return false;
			}	
			if(stateArray.length==2){		
				stateArray[1]=trimAllVSerarchFooter(stateArray[1]);
				if(!stateArray[1].match(/^[0-9]{5}$/)){				
					alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
					document.getElementById('buslocation1').focus();
					return false;
				}
			}
		}
	}
	else if(locationArray.length==3)
	{		
		locationArray[0]=trimAllVSerarchFooter(locationArray[0]);
		locationArray[1]=trimAllVSerarchFooter(locationArray[1]);
		locationArray[2]=trimAllVSerarchFooter(locationArray[2]);
		if(locationArray[0].match(/[0-9]+/))
		{
			alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
			document.getElementById('buslocation1').focus();
			return false;
		}
		else if(locationArray[1].length>2)
		{
			alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
			document.getElementById('buslocation1').focus();
			return false;
		}
		else if(locationArray[1].match(/[0-9]+/))
		{
			alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
			document.getElementById('buslocation1').focus();
			return false;
		}
		else if(!locationArray[2].match(/^[0-9]{5}$/))
		{				
			alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
			document.getElementById('buslocation1').focus();
			return false;
		}
		busloc1 = locationArray[2];
	}
	else
	{
		alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
		document.getElementById('buslocation1').focus();
		return false;
	}

	if(busloc1 == "")
		busloc1 = document.getElementById('buslocation1').value;
	
	if(!isNaN(busloc1))
	{
		is_zip = 1;
	}
	else if(act == 1)
	{
		busloc1 = ReplaceSpecialCharsWithBlankFooter(busloc1);		
		buslocArray=busloc1.split(",");
		
		state = '';
		city = '';
		
		if(buslocArray[0] != '' && busloc1.length>0)
		{
			city = trimAllVSerarchFooter(buslocArray[0].toLowerCase());
			city = city.replace(/ /g,"-");
			city = ReplaceSpecialCharsWithBlankFooter(city);
		}
		
		if(buslocArray[1] != '' && busloc1.length>0)
		{
			state = trimAllVSerarchFooter(buslocArray[1]);
			rowstr = trimAllVSerarchFooter(buslocArray[1]);
			rowstrarr = rowstr.split(" ");
			stateLwr = rowstrarr[0].toLowerCase();						
			stateLwr = stateLwr.replace(/ /g,"");
			stateLwr = stateLwr.replace(/[ \f\n\r\t\v]+/g,""); 	
			stateLwr = stateLwr.replace(/(^\s+)|(\s+$)/g,"");
			stateLwr = stateLwr.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '');
			stateLwr = stateLwr.replace(/\s/g,"");								
			stateLwr = ReplaceSpecialCharsWithBlankFooter(stateLwr);
			state = trimAllVSerarchFooter(stateLwr);
		}
		
		keyword = document.getElementById('busKeyword1').value.replace(/&/g,"-amp-");
		keyword = trimAllVSerarchFooter(keyword);
		keyword = ReplaceSpecialCharsWithBlankFooter(keyword);
		keyword = keyword.replace(/ /g,"-");
		keyword = keyword.replace(/%/g,"%25");
		keyword = keyword.toLowerCase();
		
		if(keyword.match(/^\s*$/))
		{
			alert("Please enter a business name or category to perform a search..");
			document.getElementById('busKeyword1').focus();
			return false;
		}
		if(state.match(/^\s*$/) || city.match(/^\s*$/))
		{
			alert("Please Enter your location in the following format.\nCity, State (San Diego, CA)");
			document.getElementById('buslocation1').focus();
			return false;
		}
	
		url = wbSite+"s/"+trimAllVSerarchFooter(keyword)+"/"+trimAllVSerarchFooter(city)+"/"+trimAllVSerarchFooter(state);			
		ValidateSearch_H_Footer(url);
		
	}	
	if(act==1 && is_zip)
	{		
		alert("Enter your location in the following format.\nCity, State (San Diego, CA)");
		document.getElementById('buslocation1').focus();
		return false;
	}
}

function ReplaceSpecialCharsWithBlankFooter(keyword)
{	
	var arr;
	arr = new Array('!','@','#','$','%','^','(',')','{','}','[',']','/','\\','~','`','<','>','"','?');
	for(i=0; i<arr.length; i++)
	{
		while (keyword.indexOf(arr[i]) > -1) 
		{
			keyword = keyword.replace(arr[i],"");
		}
	}
	return keyword;	
}
function ValidateSearch_H_Footer(url)
{	
	window.location=url;
}
function trimAllVSerarchFooter(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 focusBlankFooter(ele)
{
	ele.value='';
}
function checkEnterFooter(e,act,wbSite)
{
	var keyCode = null;	
	if( e.which ){
	  keyCode = e.which;
	}else if( e.keyCode ){
	  keyCode = e.keyCode;
	}	
	if( 13 == keyCode )	{
	   ValidatesearchBusinessFooter(act,wbSite);
	   return false;
	}
	return true;
}