// JavaScript Document
$(document).ready(function(){
	// grey text
	$(".input1").click(function(){
		if($(".input1").val()=="e.g. Dog Trainer")
			$(".input1").val("").css("color","#666666");
		else
			$(".input1").css("color","#000000");
	}).blur(function(){
		if($(".input1").val()=="")
			$(".input1").val("e.g. Dog Trainer").css("font-weight","normal");
		else if($(".input1").val()=="e.g. Dog Trainer")
			$(".input1").css("color","#666666");
		else
			$(".input1").css("color","#000000");		
	});
	$(".input2").click(function(){
		if($(".input2").val()=="e.g. Essex or RM1")
			$(".input2").val("").css("color","#666666");
		else
			$(".input2").css("color","#000000");
	}).blur(function(){
		if($(".input2").val()=="")
			$(".input2").val("e.g. Essex or RM1").css("font-weight","normal");
		else if($(".input1").val()=="e.g. Essex or RM1")
			$(".input1").css("color","#666666");			
		else
			$(".input2").css("color","#000000");		
	});
	
	var options, a;
	var a = $('#query').autocomplete({ 
		serviceUrl:'http://petsindex.co.uk/inc/autocomplete.php',
		minChars:2, 
		delimiter: /(,|;)\s*/, // regex or character
		maxHeight:400,
		width:300,
		zIndex: 9999,
		deferRequestBy: 0, //miliseconds
		params: { country:'Yes' }, //aditional parameters
		noCache: false, //default is false, set to true to disable caching
		// callback function:
		onSelect: function(value, data){ $("#query").val(data) }
	  });	
	var xx = $('#searchfor').autocomplete({ 
		serviceUrl:'http://petsindex.co.uk/inc/autocomplete.php',
		minChars:2, 
		delimiter: /(,|;)\s*/, // regex or character
		maxHeight:400,
		width:300,
		zIndex: 9999,
		deferRequestBy: 0, //miliseconds
		params: { country:'No' }, //aditional parameters
		noCache: false, //default is false, set to true to disable caching
		// callback function:
		onSelect: function(value, data){ $("#searchfor").val(data) }
	  });	
	var cc = $('#in_query').autocomplete({ 
		serviceUrl:'http://petsindex.co.uk/inc/autocomplete.php',
		minChars:2, 
		delimiter: /(,|;)\s*/, // regex or character
		maxHeight:400,
		width:300,
		zIndex: 9999,
		deferRequestBy: 0, //miliseconds
		params: { country:'Yes' }, //aditional parameters
		noCache: false, //default is false, set to true to disable caching
		// callback function:
		onSelect: function(value, data){ $("#in_query").val(data) }
	  });	
	var dd = $('#in_searchfor').autocomplete({ 
		serviceUrl:'http://petsindex.co.uk/inc/autocomplete.php',
		minChars:2, 
		delimiter: /(,|;)\s*/, // regex or character
		maxHeight:400,
		width:300,
		zIndex: 9999,
		deferRequestBy: 0, //miliseconds
		params: { country:'No' }, //aditional parameters
		noCache: false, //default is false, set to true to disable caching
		// callback function:
		onSelect: function(value, data){ $("#in_searchfor").val(data) }
	  });	
	/*$("#dosearch").hover(function(){
		$(this).attr("src","images/search_button_hover.gif");
	},function(){
		$(this).attr("src","images/search_button.gif");
	});*/
	$("#dosearch").click(function(){
		if($("#in_searchfor").length==0){
			wa_searchf = "http://petsindex.co.uk/search/";
			ssearchfor = $("#searchfor").val().replace(/\s\s+/gi," ").replace(/\s$/gi,'');
			slocation = $("#query").val().replace(/\s\s+/gi," ").replace(/\s$/gi,'');
		}else{
			wa_searchf = "http://petsindex.co.uk/search/";
			ssearchfor = $("#in_searchfor").val().replace(/\s\s+/gi," ").replace(/\s$/gi,'');
			slocation = $("#in_query").val().replace(/\s\s+/gi," ").replace(/\s$/gi,'');			
		}
		if(ssearchfor=="e.g. Dog Trainer" || ssearchfor=="" || ssearchfor==" "){
			messagebox("Please enter your search query","Alert!");
		}else{
			if(slocation=="e.g. Essex or RM1")
				slocation = 'uk';
			$(location).attr("href",wa_searchf+"?/"+ssearchfor.toLowerCase().replace(/ /gi,"-")+"/"+slocation.toLowerCase());
		}
	})
	$('#messagebox').dialog({
		autoOpen: false,
		modal:true,
		width: 350,
		buttons: {
		"Ok": function() { 
			$(this).dialog("close"); 
		}}
	});	
});
function messagebox(msg,mtitle){
	$("#messagebox").html(msg);
	$("#messagebox").dialog("open");
}
function scrolltop(elementid){
	var d = elementid.offset().top; 
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: d}, 800); 
}
