
jQuery(document).ready(function(){
	
	jQuery("select[name='typeRecherche']").change(function () {
		var tabId = jQuery(this).val();
		tabId = tabId.split('|');
		id_categorie = tabId[0];
		if (tabId[1]){
			id_type = tabId[1];
		}
		else{
			id_type="";
		}
		if (id_categorie != 1){
			jQuery("#capacite").val("-");
			jQuery("#capacite").attr("disabled", true);
		}
		else{
			jQuery("#capacite").attr("disabled", false);
		}
		jQuery.ajax({
			type: "POST",
			url: App.Dispatch.get100_09,
			async: false,
			cache: false,
			data: ({
				id_categorie: id_categorie,
				id_type: id_type
			}),
			success:function(data) {
				jQuery(".jqLocalisation").html(data);
				}
		});
	});
	
	jQuery("#rechercheHome").submit(function(event, data) {
		var tabId = jQuery("select[name='typeRecherche']").val();
		tabId = tabId.split('|');
		type_recherche = tabId[0];
		if (tabId[1]){
			type = tabId[1];
			jQuery("input[name='type']").val(type);
		}
		else{
			type="";
		}
		
		var tabIdLoc = jQuery("select[name='localisation_id']").val();
		tabIdLoc = tabIdLoc.split('|');
		pays_id = tabIdLoc[0];
		if (tabIdLoc[1]){
			region_id = tabIdLoc[1];
		}
		else{
			region_id="";
		}
		var capacite = jQuery("#capacite").val();
		if (isNaN(capacite)==false){
			capacite="";
			}
		jQuery("#typeRecherche").attr("disabled", true);
		jQuery("#localisation_id").attr("disabled", true);
		jQuery("#guide_id_region").attr("disabled", true);
		var newUrl = '?p=' + jQuery("input[name='p']").val() + "&sp=" + jQuery("input[name='sp']").val() + "&type_recherche=" + type_recherche +"&type=" + type  + "&pays_id=" + pays_id + "&region_id=" + region_id + capacite;
		
		
		jQuery("#capacite").attr("disabled", true);
		
		event.stopPropagation();
		document.location.href = App.Dispatch.getRoot + decodeURIComponent(newUrl);
		return false;
	});
	
});

	
