

$(document).ready(function() {

		window.submitForm = function() {
			window.onbeforeunload = null;
			document.detailForm.submit();
		}
	
		$("a.filter").click(function() {
			document.detailForm.filter.value = this.innerHTML;
			document.detailForm.submit();
		});		

	$("#search_button").click(function() {
		$("#location_form").submit();
	});
	
	$("#go_button").click(function() {
		$("#name_form").submit();
	});
						   
	$('#by_name').focus(function(){
		if( $(this).val() == 'Naval Architect Name' ) $(this).val('');
	})
	$('#by_name').blur(function(){
		if( $(this).val() == '' ) $(this).val('Naval Architect Name');
	})
	$('#by_location').focus(function(){
		if( $(this).val() == 'Country' ) $(this).val('');
	})
	$('#by_location').blur(function(){
		if( $(this).val() == '' ) $(this).val('Country');
	})
	
	var name_options = {
		script: "/builder/name_suggest",
		varname: "?type=naval&name",
		json: false,
		maxresults: 35,
		callback: function(d) {
			//var redirect_url = "/yacht-brokers/index.htm?id=" + d.id;
			//alert(redirect_url);
			//window.location = redirect_url;
		}
	};
	
	var as = new bsn.AutoSuggest('by_name', name_options);
	
	var location_options = {
			script: "/agent/country_suggest",
			varname: "?name",
			json: false,
			maxresults: 35,
			callback: function(d) {
				/*
				if (d.id.indexOf("b", 0) == 0) {
					//Its a branch
					var branch_id = d.id.substring(1);
					var redirect_url = "/yacht-brokers/list.htm?name=" + branch_id;
					window.location = redirect_url;
				} else {
					var country_id = d.id;
					var redirect_url = "/yacht-brokers/list.htm?cc=" + country_id;
					window.location = redirect_url;
				}
				*/
			}
		};
		
		var as = new bsn.AutoSuggest('by_location', location_options);
	
});
