$().ready(function() {
    
    // Quickfind search / CMS
    $('#search').focus(function() {
      $(this).val('');
    });
        
	$(".home-icon").click(function() {
		window.location=$(this).find("a").attr("href");return false;
	});
    
    $('#quick_search').val('Enter, name, town or county to search.');
    $('#quick_search').focus(function() {
        window.location = "http://www.obituarynews.co.uk/death_notices";
        //$(this).val('');
    });
    
    $('#bulk_county').val('Add (1) county per line');
    $('#bulk_county').focus(function() {
      $(this).val('');
    });
    
    $('#bulk_town').val('Add (1) town per line');
    $('#bulk_town').focus(function() {
      $(this).val('');
    });
    
	$.ajaxSetup ({  
		cache: false  
	});
    
    // Forms  ----------------------------------
	$("#country_id").change(function(){
       
        var id = $(this).val();			  
		var loadUrl = '/ajax/formCounties/' + id;
		var ajaxDiv = '#result_county_id';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);
        
        $("#county_id")[0].selectedIndex = 0;
        $("#town_id")[0].selectedIndex = 0;

	});
    
    // Needs to be called here and in ajax_forms as well!!!
    $("#county_id").change(function(){
    
        var id = $(this).val();			  
        var loadUrl = '/ajax/formTowns/' + id;
        var ajaxDiv = '#result_town_id';
        
        $.get(
        	loadUrl,
        	{language: "php", version: 5},
        	function(responseText){
        		$(ajaxDiv).html(responseText);
        	},
        	"html"
        );
        
        $("#town_id")[0].selectedIndex = 0;
    
    });
    
    // Search Forms With *Any*  ----------------------------------
	$("#country_id_search").change(function(){
       
        var id = $(this).val();			  
		var loadUrl = '/ajax/formCountiesSearch/' + id;
		var ajaxDiv = '#result_county_id';
        
		$.get(
			loadUrl,
			{language: "php", version: 5},
			function(responseText){
				$(ajaxDiv).html(responseText);
			},
			"html"
		);
        
        $("#county_id")[0].selectedIndex = 0;
        $("#town_id")[0].selectedIndex = 0;

	});
    
    // Needs to be called here and in ajax_forms as well!!!
    $("#county_id_search").change(function(){
    
        var id = $(this).val();			  
        var loadUrl = '/ajax/formTownsSearch/' + id;
        var ajaxDiv = '#result_town_id';
        
        $.get(
        	loadUrl,
        	{language: "php", version: 5},
        	function(responseText){
        		$(ajaxDiv).html(responseText);
        	},
        	"html"
        );
        
        $("#town_id")[0].selectedIndex = 0;
    
    });
    
    
});

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

