$(document).ready(function(){
		$.ajaxSetup({
			  beforeSend: function(xhr) {
				$('img#loading_img').show();
			  },
			  success: function(xhr){
				$('img#loading_img').hide();
			  }
  		});
		
		var param = $("form").serialize();
		
		$("#result").load( "index.php", 	{ data:param, page:"search_engine" } );
		$("#div_fav").load( "index.php", 	{ data:param, page:"favorite" }, function(){
									$("dl#favorite dd").click(function(){
										window.location.href = $(this).prev("dt").children("a").attr("href");
									});
						} );

		
		$("#localisation").autocomplete("autocomp.html", {
											allowWhiteSpace:true,
											noCache:true,
											selectFirst:true,
											autoFill:true,
											onItemSelect:function(li){
													if( li == null ) return alert("No match!");
													// if coming from an AJAX call, let's use the CityId as the value
													if( !!li.extra ) var sValue = li.extra[0];
													// otherwise, let's just display the value in the text box
													else var sValue = li.selectValue;
													$("#com_num").attr('value', sValue);
													refresh_search();
												},
											onAutoFill:function(val){
													$("#com_num").attr('value', val);
													refresh_search();
												}
										});

		$("input").each(function(){
			$(this).change(function(){
				refresh_search();
			});
		});
		
		$("checkbox").each(function(){
			$(this).click(function(){
				refresh_search();
			});
		});

		
		function refresh_search(){
			var param = $("form").serialize();
			$("#result").load( "index.php", { data:param, page:"search_engine" }  );
			$("#div_fav").load( "index.php", 	{ data:param, page:"favorite" }, function(){
										$("dl#favorite dd").click(function(){
											window.location.href = $(this).prev("dt").children("a").attr("href");
										});
							} );
		}
		

    	$("input[name=transac]").click(function(){
				if(this.value=="v"){
					$(".info_loc").hide();
					$(".info_vte").show();
				}else{
					$(".info_loc").show();
					$(".info_vte").hide();
				}
				jQuery.each(jQuery.browser, function(i) {
				  if($.browser.msie){
					refresh_search();
				  }
				});
		});
					
		$("input[name=transac]:checked").each(function(){
				if(this.value=="v"){
					$(".info_loc").hide();
					$(".info_vte").show();
				}else{
					$(".info_loc").show();
					$(".info_vte").hide();
				}
		});

});

