$(document).ready(function(){
		$.ajaxSetup({
			  /*
			  beforeSend: function(xhr) {
				alert("Hello");
				xhr.setRequestHeader("Content-type", "text/html; charset=ISO-8859-1");
			  }
			  */
  		});
		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();
												}
										});

		$("form input").change(function(){
					refresh_search();
	   });
		$("form input[type=checkbox]").click(function(){
					refresh_search();
	   });

		if( $("form input[name=mdt_ref]")){
			$("form input[name=mdt_ref]").keyup(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();
				}
		});

});


