// JavaScript Document
//this function is used for check user input for search and it should be included in all pages -- created on 25-Nov-2008
function validate_search(){
		
		var category=document.search_form123.keyword.value;
		
		var location=document.search_form123.location.value;
		createCookie('last_action','main',7);
		createCookie('byajaxnext',5,7);
		//For reseting the clicked business cookie scroll Position Y -direction
		if(readCookie('posy')) eraseCookie('posy');
		//
	if(location==""){
			alert("Please enter a location for search");
			return false;
	}else if(location.length<3){
		alert("Location should be atleast 3 char long");
		return false;
	}else{
		
			l=location.length;
			var n=0;
			for(i=0;i<=l;++i){
				a=location.charAt(i);
				if(a==","){
					n=1;
				}
			}
			if(n==1){
				location = location.replace(/^\s+/,'').replace(/\s+$/,'');//trim the given string
				location=location.split(",");
				//location=makelink(location[1])+"/"+makelink(location[0]);
				location2=makelink(location[0]);
				if(location[1]!=""){
					location1=makelink(location[1]);
					location=location1+"/"+location2;
				}else{
					location=location2;
				}
				
			}else{
				location=makelink(location);	
			}
			
			s3=category;
			out = "&"; // replace this
			add = "%26"; // with this
			while (s3.indexOf(out)>-1) {

			pos= s3.indexOf(out);

			s3 = "" + (s3.substring(0, pos) + add + 

			s3.substring((pos + out.length), s3.length));

			}
			category=s3;
			category=makelink(category);
			if(n==0){
						location=location.toLowerCase();
				switch(location){
					case "liverpool" :
							location="Merseyside/Liverpool";
							break;
					case "london" :
							location="Greater-London/London";
							break;
					case "macclesfield" :
							location="Cheshire/Macclesfield";
							break;
					case "manchester" :
							location="Greater-Manchester/Manchester";
							break;
					case "preston" :
							location="Lancashire/Preston";
							break;
					case "ramsbottom" :
							location="Lancashire/Ramsbottom";
							break;
					case "blackpool" :
							location="Lancashire/Blackpool";
							break;
				}
			}
			if(category.length<2){
				  	
					document.location="/uk/"+location+"/guide";
					
				  }else{
					
			document.location="/search/"+location+"/"+category;
				  }
			return false;

		
	}
}
function validate_search_main(){
		var category=document.search_form_main.keyword.value;
		var location=document.search_form_main.location.value;
		createCookie('last_action','main',7);
		createCookie('byajaxnext',5,7);
		//For reseting the clicked business cookie scroll Position Y -direction
		if(readCookie('posy')) eraseCookie('posy');
		//
	if(location=="e.g. Manchester"){
		location="";
	}
	if(location==""){
			alert("Please enter a location for search");
			return false;
	}else if(location.length<3){
		alert("Location should be atleast 3 char long");
		return false;
	}else{
		
			l=location.length;
			var n=0;
			for(i=0;i<=l;++i){
				a=location.charAt(i);
				if(a==","){
					n=1;
				}
			}
			if(n==1){
				location = location.replace(/^\s+/,'').replace(/\s+$/,'');//trim the given string
				location=location.split(",");
				//location=makelink(location[1])+"/"+makelink(location[0]);
				location2=makelink(location[0]);
				if(location[1]!=""){
					location1=makelink(location[1]);
					location=location1+"/"+location2;
				}else{
					location=location2;
				}
				
			}else{
				location=makelink(location);	
			}
			
			s3=category;
			out = "&"; // replace this
			add = "%26"; // with this
			while (s3.indexOf(out)>-1) {

			pos= s3.indexOf(out);

			s3 = "" + (s3.substring(0, pos) + add + 

			s3.substring((pos + out.length), s3.length));

			}
			category=s3;
			category=makelink(category);
			if(n==0){
						location=location.toLowerCase();
				switch(location){
					case "liverpool" :
							location="Merseyside/Liverpool";
							break;
					case "london" :
							location="Greater-London/London";
							break;
					case "macclesfield" :
							location="Cheshire/Macclesfield";
							break;
					case "manchester" :
							location="Greater-Manchester/Manchester";
							break;
					case "preston" :
							location="Lancashire/Preston";
							break;
					case "ramsbottom" :
							location="Lancashire/Ramsbottom";
							break;
					case "blackpool" :
							location="Lancashire/Blackpool";
							break;
				}
			}
			change_cookie();  //clear cookies for search
			if(category=="Food-and-Drink"){
				document.location="/browse/uk/"+location+"/Food-and-Drink";
			}else if(category=="Nightlife"){
				document.location="/browse/uk/"+location+"/Nightlife";
			}
			else if(category=="Entertainment-and-Arts"){
				document.location="/browse/uk/"+location+"/Entertainment-and-Arts";
			}
			else if(category=="Beauty-and-Fitness"){
				document.location="/browse/uk/"+location+"/Beauty-and-Fitness";
			}
			else if(category=="Travel-and-Transportation"){
				document.location="/browse/uk/"+location+"/Travel-and-Transportation";
			}
			else if(category=="Health-and-Medical"){
				document.location="/browse/uk/"+location+"/Health-and-Medical";
			}
			else if(category=="Animals-and-Pets"){
				document.location="/browse/uk/"+location+"/Animals-and-Pets";
			}
			else if(category=="Legal-and-Financial"){
				document.location="/browse/uk/"+location+"/Legal-and-Financial";
			}
			else if(category=="General-Services"){
				document.location="/browse/uk/"+location+"/General-Services";
			}
			else if(category=="Car-and-Auto"){
				document.location="/browse/uk/"+location+"/Car-and-Auto";
			}
			else if(category=="Education-and-Employment"){
				document.location="/browse/uk/"+location+"/Education-and-Employment";
			}
			else if(category=="View-all-categories"){
				document.location="/browse/uk/"+location;
			}
			else if(category=="whatson"){
				document.location="/uk/"+location+"/whatson";
			}
			else if(category.length<2){
					document.location="/uk/"+location+"/guide";
					
				  }else{
					
			document.location="/search/"+location+"/"+category;
				  }
			return false;

		
	}
}
//function is used for validate city search from index page
function event_serch(){
	//var location=document.getElementById("location").value;
	var location=document.changeLocation.location.value;
	var type=document.changeLocation.type.value;
	if(location=="e.g. Manchester") location="";
	if(location.length<3){
		alert("Location should be atleast 3 char long");
		return false;
	}else{
		query="location="+location
		if(type!=""){
		document.location="/weekendguide/redirect?type="+type+"&"+query;
		}else{
		document.location="/weekendguide/redirect?"+query;
		}
		return false;
   }
}
function event_serch1(){
	
	var location=document.getElementById("location1").value;
	if(location=="e.g. Manchester") location="";
	if(location.length<3){
		alert("Location should be atleast 3 char long");
		return false;
	}else{
		query="location="+location
		document.location="/weekendguide/redirect?"+query;
		return false;
   }
}
function validate_index(){
	if(document.frm_index_search.location1.value==""){
		alert("Please enter a location to discover");
		return false;
	}else{
		var location=document.frm_index_search.location1.value;
		l=location.length;
			var n=0;
			for(i=0;i<=l;++i){
				a=location.charAt(i);
				if(a==","){
					n=1;
				}
			}
			if(n==1){
				location = location.replace(/^\s+/,'').replace(/\s+$/,'');//trim the given string
				location=location.split(",");
				//location=makelink(location[1])+"/"+makelink(location[0]);
				location2=makelink(location[0]);
				if(location[1]!=""){
					location1=makelink(location[1]);
					location=location1+"/"+location2;
				}else{
					location=location2;
				}
				
			}else{
				location=makelink(location);	
			}
			
			document.location="/uk/"+location+"/guide";
		//var category="";
		//query="location="+location+"&a=find_location";
		//query="location="+location+"&category="+category;
		//document.location="/listings/urlredirect?"+query;
		return false;
	}
}
function validate_city_search(){
	if(document.frm_city.keyword.value==""){
		alert("Please enter a keyword for search");
		return false;
	}else{
		var location=document.frm_city.city.value+", "+ document.frm_city.county.value;
		var category=document.frm_city.keyword.value;
		query="location="+location+"&category="+category;
		document.location="/listings?"+query;
		return false;
	}
}
function validate_search2(){
	var category=document.getElementById("category").value;
	var location=document.getElementById("store_finder_location").value;
	if(location==""){
			alert("Please enter a location for search");
		return false;
	}else if(location.length<3){
				alert("location should be atleast 3 char long");
		return false;
	}else{
			query="location="+location+"&category="+category;
			document.location="/listings/urlredirect?"+query;
			return false;

		}
	}
	
	//Function for replace special characters from given string
	function makelink(myString){
  		myString = myString.replace(/^\s+/,'').replace(/\s+$/,'');//trim the given string
		//var myRegExp = new RegExp("'|\\\\|\"\|!\|@\|£\|$\|%\|^\|&\|*\|(\|)\|+\|=\|}\|]\|[\|\|:\|;\|?\|>\|.\|<\|~\|‘\|’\|‚\|“\|”\|„\|†\|‡\|‰\|‹\|›\|™\|#\|¡\|¢\|.\|¤\|¥\|¦\|§\|¨\|©\|ª\|«\|¬\|®\|¯\|°\|±\|²\|³\|µ\|¶\|¿\| \|»\|º\|¼\|½\|¾\|¸\|¹","g");
		var myRegExp = new RegExp(",|\\\\|\"\|!\|@\|\£|\$|&|\™|\<|\:|\;|\~|\‘|\’|\‚|\“|\”|\„|\†|\‰|\‹|\›|\#|\¡|\¢|\¤|\¥|\¦|\§|\¨|\©|\ª|\«|\¬|\®|\¯|\°|\±|\²|\³|\µ|\¶|\¿|\»|\º|\¼|\½|\¾|\¸|\¹| ","g");
		var myResult = myString.replace(myRegExp, "-");
		myResult = myResult.replace('$','-',"g");
		myResult = myResult.replace('.','-',"g");
		myResult = myResult.replace('>','-',"g");
		myResult = myResult.replace('?','-',"g");
		myResult = myResult.replace('(','-',"g");
		myResult = myResult.replace(')','-',"g");
		myResult = myResult.replace('{','-',"g");
		myResult = myResult.replace('}','-',"g");
		myResult = myResult.replace('[','-',"g");
		myResult = myResult.replace(']','-',"g");
		myResult = myResult.replace('.','-',"g");
		myResult = myResult.replace('\'',"","g");
		myResult = myResult.replace("'","","g");
		myResult = myResult.replace(".","-","g");
		myResult = myResult.replace('-------',"-","g");
		myResult = myResult.replace('------',"-","g");
		myResult = myResult.replace('-----',"-","g");
		myResult = myResult.replace('----',"-","g");
		myResult = myResult.replace('---',"-","g");
		myResult = myResult.replace('--',"-","g");
		var srtLen = myResult.length;
		if(myResult.charAt(srtLen-1)=="-"){
			myResult = myResult.substring(0, srtLen-1);
		}
	   return myResult;
 }