/**
 * Yacht designers search 
 *
 * Author: waldemarm
 */
$(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();
	});		
	
	
	$("#builder_search").bind('keyup',function(){
		$.ajax({
			url: '/property/yacht/builder/search?type=designer&amp;name=' + $("#builder_search").val(),
			type: 'GET',			
			success: function(data) {
				var founded_items = $(data).find("items_found").text($(data).find("items_found").html());
				
				if(founded_items==''){
					$("#itemsFound").hide('fast');
					$('#showResults').css('display','none');
				}
				else{
					if(founded_items>0){
						$('#showResults').css('display','');
					}
					else{
						$('#showResults').css('display','none');
					}
					$("#itemsFound").show('fast');
					$("#itemsFound").html('Found: '+founded_items);
				}
				

				$("#result_id_list").attr('value',$(data).find("items_found").attr("ids"));
				
			}
		});				
	});
		
		
		
	
	$("#search_button").click(function() {
		$("#location_form").submit();
	});
	
	$("#go_button").click(function() {
		$("#name_form").submit();
	});
						   
						   
	var location_options = {
		script: "/agent/location_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);
	
	
	var name_options = {
		script: "/builder/name_suggest",
		varname: "?type=exterior&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);
});