﻿
function initSearch() { 

// Initialise the search box control on the site

	$("#q").focus(function () {
		var txt = ($(this).val() == "Search") ? "" : $(this).val();
		$(this).val(txt);
	});
	$("#q").blur(function () {
		var txt = ($(this).val() == "") ? "Search" : $(this).val();
		$(this).val(txt);
	});
	$("#go").click(function () {
					
	    window.location = "/search.aspx?search=" + $("#q").val();
		//$(this).parent().submit();	
		return false;
	});
	// Submit form when enter is pressed in textfield
	$("#q").keypress(function(e){
									  
		  if(e.which == 13){
		   window.location = "/search.aspx?search=" + $("#q").val();
			//$(this).parent().submit();	
			return false;
		   }

      });

// Initialise the care home search on the home page
      
	$("#searchButton").click(function () {	
		if (document.getElementById('searchText').value == ''){
			alert("you must enter a a location to search for.");
		}else{
	    	window.location = "/care-homes/location-search-results.aspx?query=" + $("#searchText").val();
			//$(this).parent().submit();	
			return false;
		}
	});
	
    $("#searchText").keypress(function(e){
									  
		if (document.getElementById('searchText').value == ''){
			
		}else{										   
		  if(e.which == 13){
			window.location = "/care-homes/location-search-results.aspx?query=" + $("#searchText").val();
			return false;
		   }
		}
      });
}

// Used to set default button for textbox on the advanced search page
function clickButton(e, buttonid){
		
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);
      if (bt){
	
          if (evt.keyCode == 13){
                bt.click();
                return false;
          }
      }
}