busloc = "";
function ValidatesearchBusiness(frmname,act)
{
	frm = eval("document."+frmname);
	var is_zip = 0; 
	if(frm.busKeyword.value.match(/^\s*$/) || frm.busKeyword.value=='name or category')
	{
		alert("Please enter a business name or category to perform a search");
		frm.busKeyword.focus();
		return false;
	}
	
	if(frm.buslocation.value.match(/^\s*$/))
	{
		alert("Please enter the location as City, State or Zip");
		frm.buslocation.focus();
		return false;
	}
	
	if(frm.busKeyword.value.match(/#/))
	{
		alert("Business name should not have special character like '#'.");
		frm.buslocation.focus();
		return false;
	}
	
	searchLocation=trimAll(frm.buslocation.value);
	if(searchLocation.length<5){
		alert("Search location should be more than 4 characters.\nEnter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
		return false;
		frm.buslocation.focus();
	}
	locationArray=searchLocation.split(",");
	if(locationArray.length==1)
	{ 
		// User has enteredeither city or zipcode only
		if(isNaN(locationArray[0])){
			// If city only
			if(locationArray[0].match(/[0-9]+/)){
				//alert("Please enter proper city name i.e. San Diego");
				alert("Enter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
				frm.buslocation.focus();
				return false;
			} 
		}else if(locationArray[0].length>5){
			// If zip code only			
			alert("Entered zip code should be of five charaters");
			frm.buslocation.focus();
			return false;					
		}
	}
	else if(locationArray.length==2)
	{
		// location is having more than one element
		locationArray[0]=trimAll(locationArray[0]);
		locationArray[1]=trimAll(locationArray[1]);
		if(locationArray[0].match(/[0-9]+/)){
				//alert("Please enter proper city name i.e. San Diego, CA");
				alert("Enter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
				frm.buslocation.focus();
				return false;
		}
		else 
		{			
			stateArray=locationArray[1].split(" ");
			if(stateArray.length>2){
				alert("Enter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
				frm.buslocation.focus();
				return false;
			}
			stateArray[0]=trimAll(stateArray[0]);
			if(stateArray[0].match(/[0-9]+/)){
				//alert("Please enter proper State name.");
				alert("Enter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
				frm.buslocation.focus();
				return false;
			} 
			if(stateArray[0].length<2){				
				alert("Enter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
				frm.buslocation.focus();
				return false;
			}	
			if(stateArray.length==2){		
				stateArray[1]=trimAll(stateArray[1]);
				if(!stateArray[1].match(/^[0-9]{5}$/)){				
					//alert("Please enter proper Zipecode after state name, Entered zip code should be of five charaters");
					alert("Enter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nZip (92107)\nCity, State, zip (San Diego, CA, 92107)");
					frm.buslocation.focus();
					return false;
				}
			}
		}
	}
	else if(locationArray.length==3)
	{		
		// location is having more than one element
		locationArray[0]=trimAll(locationArray[0]);
		locationArray[1]=trimAll(locationArray[1]);
		locationArray[2]=trimAll(locationArray[2]);
		if(locationArray[0].match(/[0-9]+/))
		{
			//alert("Please enter proper city name i.e. San Diego, CA");
			alert("Enter your location in one of the following formats.\nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
			frm.buslocation.focus();
			return false;
		}
		else if(locationArray[1].length>2)
		{
			alert("Enter your location in one of the following formats.\nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
			frm.buslocation.focus();
			return false;
		}
		else if(locationArray[1].match(/[0-9]+/))
		{
			//alert("Please enter proper State name.");
			alert("Enter your location in one of the following formats.\nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
			frm.buslocation.focus();
			return false;
		}
		else if(!locationArray[2].match(/^[0-9]{5}$/))
		{				
			//alert("Please enter proper Zipecode after state name, Entered zip code should be of five charaters");
			alert("Enter your location in one of the following formats.\nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
			frm.buslocation.focus();
			return false;
		}
		busloc = locationArray[2];
	}
	else
	{
		alert("Enter your location in one of the following formats.\nCity (San Diego) \nCity, State (San Diego, CA)\nCity, State zip (San Diego, CA 92107)\nCity, State, zip (San Diego, CA, 92107)\nZip (92107)");
		frm.buslocation.focus();
		return false;
	}

	if(act==2)		
		url= HTTP_LOCATION+'?mysession='+ encodeBase64("reviews_SearchBusiness") +'&buslocation='+frm.buslocation.value+'&busKeyword='+frm.busKeyword.value.replace(/&/g,"-amp-")+'&mode=search';
	
	if(busloc == "")
		busloc = frm.buslocation.value;

	if(!isNaN(busloc))
	{
		is_zip = 1;
	}
	else if(act == 1)
	{
		buslocArray=busloc.split(",");
		city = trimAll(buslocArray[0].toLowerCase());
		city = city.replace(/ /g,"-");
		state = trimAll(buslocArray[1]);
		rowstr = trimAll(buslocArray[1]);
		rowstrarr = rowstr.split(" ");
		state = trimAll(rowstrarr[0].toLowerCase());
		keyword = frm.busKeyword.value.replace(/&/g,"-amp-");
		keyword = ReplaceSpecialCharsWithBlank(keyword);
		keyword = keyword.replace(/ /g,"-");		
		keyword = keyword.replace(/%/g,"%25");
		keyword = keyword.toLowerCase();
		showkeyword = frm.busKeyword.value;
		showkeyword = ReplaceSpecialCharsWithBlank(showkeyword);
		document.getElementById('showkey').innerHTML = showkeyword;
		url = HTTP_LOCATION+"s/"+keyword+"/"+city+"/"+state;
		ValidateSearch_H(url);
	}
	
	if(act==1 && is_zip)
	{
		getCityState(busloc);
	}
	else if(act == 2)
	{
		document.getElementById('showkey').innerHTML = frm.busKeyword.value;
		ValidateSearch_H(url);
	}	
}

function ReplaceSpecialCharsWithBlank(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 getCityState(busloc)
{
	var url = "";	
	url = HTTP_LOCATION+"?mysession=" + encodeBase64('business_getCityState');
	url = url+"&zip="+busloc;
	ObjHTTP5.open("GET", url , true);
	ObjHTTP5.onreadystatechange = cb_getCityState;
	ObjHTTP5.send(null);
}

function cb_getCityState()
{	
	if (ObjHTTP5.readyState == 4 && ObjHTTP5.status == 200)	
	{		
		str = ObjHTTP5.responseText;
		buslocarr = str.split(",");
		city = trimAll(buslocarr[0].toLowerCase());
		city = city.replace(/ /g,"-");
		state = trimAll(buslocarr[1].toLowerCase());
		keyword = frm.busKeyword.value.replace(/&/g,"-amp-");
		keyword = ReplaceSpecialCharsWithBlank(keyword);
		keyword = keyword.replace(/ /g,"-");
		keyword = keyword.replace(/%/g,"%25");
		keyword = keyword.toLowerCase();
		showkeyword = frm.busKeyword.value;
		showkeyword = ReplaceSpecialCharsWithBlank(showkeyword);
		document.getElementById('showkey').innerHTML = showkeyword;
		url = HTTP_LOCATION+"s/"+keyword+"/"+city+"/"+state;
		ValidateSearch_H(url);
	}
}

function ValidateSearch_H(url)
{
	if(document.getElementById('videoDiv'))
	{
		document.getElementById('videoDiv').style.visibility="hidden";
	}
	showTimer(20,30,"searchTimer");
	//document.getElementById('imgLoading').style.display = "";
	window.location = url;
}
function trimAll(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 checkEnter(e){var keyCode=null;if(e.which)
{keyCode=e.which;}
else if(e.keyCode)
{keyCode=e.keyCode;}
if(13==keyCode)
{ValidatesearchBusiness('SearchForm1',1);return false;}
return true;}
var offsetxpoint=-60
var offsetypoint=20
var ie=document.all
var ns6=document.getElementById&&!document.all
var enabletip=false
if(ie||ns6)
var tipobj=document.all?document.all["dhtmltooltip"]:document.getElementById?document.getElementById("dhtmltooltip"):""
function ietruebody(){return(document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body}
function mojotip(){if(ns6||ie){tipobj.innerHTML="This is a Mojo Bar.  A member earns 1 point of Mojo for every review they write and <span class=TxtOrangeBld>1</span> additional point of Mojo for every person who voted one of their reviews as &quot;Helpful&quot;. The Mojo bar is a way to quickly see how much Mojo a member has earned. The more Mojo a member has, the more involved they are in the community and the more helpful their reviews are. Go get some Mojo... yeah baby!"
enabletip=true
return false}}
function showreviewtip(ReviewTxt){if(ns6||ie){tipobj.innerHTML=ReviewTxt;enabletip=true
return false}}
function positiontip(e){if(enabletip){var curX=(ns6)?e.pageX:event.clientX+ietruebody().scrollLeft;var curY=(ns6)?e.pageY:event.clientY+ietruebody().scrollTop;var rightedge=ie&&!window.opera?ietruebody().clientWidth-event.clientX-offsetxpoint:window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera?ietruebody().clientHeight-event.clientY-offsetypoint:window.innerHeight-e.clientY-offsetypoint-20
var leftedge=(offsetxpoint<0)?offsetxpoint*(-1):-1000
if(rightedge<tipobj.offsetWidth)
tipobj.style.left=ie?ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px":window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if(curX<leftedge)
tipobj.style.left="5px"
else
tipobj.style.left=curX+offsetxpoint+"px"
if(bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie?ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px":window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"}}
function hidemojotip(){if(ns6||ie){enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''}}
document.onmousemove=positiontip
function showTimer(H,W,Id){var DvLayerId=document.getElementById("searchBackground");var DvMessageId=document.getElementById(Id);var ScrollHeight=document.body.scrollHeight;var ScrollWidth=document.body.scrollWidth;var ClientHeight=document.documentElement.clientHeight;var ClietnWidth=document.documentElement.clientWidth;var OffsetHeight=document.documentElement.offsetHeight;var OffsetWidth=document.documentElement.offsetWidth;DvLayerId.style.display="";if(ScrollHeight<ClientHeight)
{if(BrowserDetect.browser=="Explorer"||BrowserDetect.browser=="Firefox"||BrowserDetect.browser=="Netscape")
DvLayerId.style.height=ClientHeight+30+"px";else
DvLayerId.style.height=ScrollHeight+30+"px";}
else
DvLayerId.style.height=ScrollHeight+100+"px";PosLeft=W/2;DvLayerId.style.width=ClietnWidth+"px";DvLayerId.style.top=0+"px";DvLayerId.style.left=0+"px";DvMessageId.style.left=450+"px";DvMessageId.style.top=270+"px";DvMessageId.style.width=500+"px";DvMessageId.style.display="";}
function checkBusiness(){if(document.SearchForm1.busKeyword.value == "name or category")document.SearchForm1.busKeyword.value="";return true;}
