

	$(document).ready(function(){
		$('.bloc ul').hide();
		$('.bloc h1').click(function(){
			montre($(this).parent('div').attr('id'));
		});
		$('.bloc .bas').click(function(){
			montre($(this).parent('div').attr('id'));
		});
		
		nbo=0;   /* variable globale pour le nombre d'onglet*/
		if($('.documents li a')){
			
			spip_out();
		}
	});
    
	function spip_out(){
		$('a.spip_out').click( function() {
			window.open(this.href); return false; 
		});	
	}
    
	function mailing(){
		$('#formulaire_recommander').hide("slow");
		$('#recommander').hide();
		$("#formulaire_recommander").show();
		$("#recommander").show();
		$(".spip_bouton").show();
	
	}
	
	function montre(id){
		if($('#'+id+' ul').css('display')=="none"){
			$('.bloc ul').hide();
			$('.bloc .bas img').attr('src','squelettes/images/fleche.png');
			$('#'+id+' ul').show();
			$('#'+id+' .bas img').attr('src','squelettes/images/fleche_haut.png');
		}else{
			$('.bloc ul').hide();
			$('.bloc .bas img').attr('src','squelettes/images/fleche.png');
		}
	}
	
	
	function afficheOnglet(){
		$('#onglets div').click(function(){
			$('#fiche div').hide();
			$('#onglets div').attr('class','');
			
			var o=$(this).attr('id');
			$(this).attr('class','actif');
			$("#div_"+o).show();
            
            var num = $('#div_'+o+' .numregion').val();
            
            $("#googlemap").show();
            loadMap(num);
			
		});
		return false;
	}
    
	function fermerOnglet(){
		$('#onglets div a').click(function(){
			var o=$(this).attr('id')
			$("#onglet"+o).remove();
			$("#div_onglet"+o).remove();
			$("#fiche div:last").show();	
			$("#onglets div:last").attr('class','actif');
		});
		return false;
	
	}
    
	function reconditionneurold(){
		if($('#pro').attr('checked')==true){
			var c=1;
		}else if($('#part').attr('checked')==true){
			var c=2;
		}
		if(($('#pro').attr('checked')==true && $('#part').attr('checked')==true)||($('#pro').attr('checked')==false && $('#part').attr('checked')==false)){
			var c=3;
		}
		var r=$('#region').attr('value');
		$.ajax({
			type: "POST",
			url: "squelettes/inc_reconditionneur.php",
			data: "condition="+c+"&region="+r,
			success: function(data){
				var cbo=$("#onglets div").length;
				if(cbo<4){
					nbo++;
					
					$("#onglets").append("<div id='onglet_"+nbo+"'>Recherche n&deg;"+nbo+"<a href='#' id='_"+nbo+"'><span>Fermer</span></a></div>");
					$('#fiche').append("<div id='div_onglet_"+nbo+"'></div>");
					$('#fiche div').hide();
					$('#onglets div').attr('class','');
					$('#div_onglet_'+nbo).html(data);
					$('#div_onglet_'+nbo).show();
					$('#onglets div:last').attr('class','actif');
					afficheOnglet();
					fermerOnglet();
					spip_out();
                    $("#googlemap").show();
                    loadScript();
				}else{
					alert("Fermez un onglet !");
				}
			},
			error: function(){

			}		
		 });
	}
    
	function reconditionneur(){
		if($('#pro').attr('checked')==true){
			var c=1;
		}else if($('#part').attr('checked')==true){
			var c=2;
		}
		if(($('#pro').attr('checked')==true && $('#part').attr('checked')==true)||($('#pro').attr('checked')==false && $('#part').attr('checked')==false)){
			var c=3;
		}
		var r=$('#region').attr('value');
		$.ajax({
			type: "POST",
			url: "squelettes/inc_reconditionneur.php",
			data: "condition="+c+"&region="+r,
			success: function(data){
				var cbo=$("#onglets div").length;
				if(cbo<4){
					nbo++;

					$("#onglets").append("<div id='onglet_"+nbo+"'>Recherche n&deg;"+nbo+"<a href='#' id='_"+nbo+"'><span>Fermer</span></a></div>");
					$('#fiche').append("<div id='div_onglet_"+nbo+"'></div>");
					$('#fiche div').hide();
					$('#onglets div').attr('class','');
					$('#div_onglet_'+nbo).html(data);
					$('#div_onglet_'+nbo).show();
					$('#onglets div:last').attr('class','actif');
					afficheOnglet();
					fermerOnglet();
					spip_out();
                    
                    var num = $('#div_onglet_'+nbo+' .numregion').val();
                    
                    $("#googlemap").show();
                    loadScript(num);
				}else{
					alert("Fermez un onglet !");
				}
			},
			error: function(){

			}		
		 });
	}
    

	function redistributeur(){
		if($('#pro').attr('checked')==true){
			var c=1;
		}else if($('#part').attr('checked')==true){
			var c=2;
		}
		if(($('#pro').attr('checked')==true && $('#part').attr('checked')==true)||($('#pro').attr('checked')==false && $('#part').attr('checked')==false)){
			var c=3;
		}
		var r=$('#region').attr('value');
		$.ajax({
			type: "POST",
			url: "squelettes/inc_redistribution.php",
			data: "condition="+c+"&region="+r,
			success: function(data){
				var cbo=$("#onglets div").length;
				if(cbo<4){
					nbo++;
                    
					$("#onglets").append("<div id='onglet_"+nbo+"'>Recherche n&deg;"+nbo+"<a href='#' id='_"+nbo+"'><span>Fermer</span></a></div>");
					$('#fiche').append("<div id='div_onglet_"+nbo+"'></div>");
					$('#fiche div').hide();
					$('#onglets div').attr('class','');
					$('#div_onglet_'+nbo).html(data);
					$('#div_onglet_'+nbo).show();
					$('#onglets div:last').attr('class','actif');
					afficheOnglet();
					fermerOnglet();
					spip_out();
                    
                    var num = $('#div_onglet_'+nbo+' .numregion').val();
                    
                    $("#googlemap").show();
                    loadScript(num);
				}
			},
			error: function(){

			}		
		 });
	}