var id;

var inputid;


Event.observe(window, "load", function() {
	$$(".clickable").each(function(bloc){
		var links = bloc.getElementsByTagName("A");
		if(links.length == 1) {
			bloc.style.cursor = "pointer";
			bloc.setAttribute("title", "Se rendre sur la page "+links[0].href);
			bloc.onclick = function() {document.location.href = links[0]};
		}
	});
});

function refresh_data_lei(type, commune) {
	new Ajax.Request(
				 '/ajax/refresh_lei.php',
				 {
					method:'post',
					parameters:'type='+type+'&commune='+commune
				 }
			);
}

function actus_defilement(action, categorie)
{	
	var divupdate;
	nom_commune = "";
	try{
	switch(categorie)
	{
		case "actus_enfance":
			id = $('actus_enfance_id').value;
			divupdate = 'actus_enfance_index';
			inputid = 'actus_enfance_id';
			break;
			
		case "actus_culture":
			id = $('actus_culture_id').value;
			divupdate = 'actus_culture_index';
			inputid = 'actus_culture_id';
		break;
			
		case "actus_association":
			id = $('actus_association_id').value;
			divupdate = 'actus_association_index';
			inputid = 'actus_association_id';
		break;
		
		case "breves":
			id = $('breves_id').value;
			divupdate = 'breves_index';
			inputid = 'breves_id';
		break;
		
		case "A_la_une":
			id = $('A_la_une_id').value;
			divupdate = 'A_la_une';
			inputid = 'A_la_une_id';
		break;
		default:
			id = $('breves_id').value;
			divupdate = 'zone_update_breve';
			inputid = 'breves_id';
			nom_commune = categorie;
			categorie = $("idCommuneBreves").value;
		break;
	}
	}catch(e){id=null;}
	
	if(id && divupdate && inputid)
	{	
		
		if(nom_commune == 'Dambach-la-Ville')
		{
			new Ajax.Request(
							 '/ajax/getactusD.php',
							 {
								method:'post',
								parameters:'id_actu='+id+'&div='+divupdate+'&input='+inputid+'&action='+action+"&categorie="+categorie+"&nom_commune="+nom_commune,
								onComplete:function(transport){actus_defilementOK(transport, divupdate);}
							 }
						);	
		}
		else
		{
		new Ajax.Request(
							 '/ajax/getactus.php',
							 {
								method:'post',
								parameters:'id_actu='+id+'&div='+divupdate+'&input='+inputid+'&action='+action+"&categorie="+categorie+"&nom_commune="+nom_commune,
								onComplete:function(transport){actus_defilementOK(transport, divupdate);}
							 }
						);	
		}
	}					 	
}

function actus_defilementOK(reponse, divupdate)
{
	var tmp = reponse.responseText.split("<!-- ||");
	//alert(divupdate);
	if(divupdate == 'zone_update_breve') {
		$(divupdate).innerHTML = reponse.responseText;
		return;
	}
	
	new Effect.toggle(
					  divupdate,
					  'Appear',
						  {
						  afterFinish:function () 
												{
													$(divupdate).innerHTML = reponse.responseText;
													new Effect.toggle(divupdate,'Appear',{duration:0.25});
												},
						  duration:0.25
						  }
					);	
	if(tmp.length > 1) {
		var titre = tmp[1].substring(0, tmp[1].length - 3);
		var zone_titre = null;
		if(divupdate == "A_la_une") zone_titre = ALAUNE;
		if(zone_titre != null) {
			zone_titre.addVariable("leTitre", titre);
			zone_titre.write("titreActuSlide");
		}
	}
}

function recherche()
{
	search=$('input_rechercher').value;	
	document.location.href = '/search.php?recherche='+search;

}

function recherche_commune()
{
	search=$('input_rechercher').value;
	commune=$('commune').value;
	
	//alert(commune);
	document.location.href = '/search.php?recherche='+search;

}

function VisiterCommune(id) {
	if(id == 'epfig') {
		window.open('http://www.commune-epfig.fr',"_blank");	
	}
	else if(id != '0' )	{
		window.open('http://www.pays-de-barr.fr/'+id+"/","_blank");
	}
}

function versSiteCommune() {
	VisiterCommune($('plan_commune_select').value);
}

function augementer(){

	var reg = new RegExp("px", "g");
	var tailleActuelle = document.body.style.fontSize;
	tailleActuelle = Number(tailleActuelle.replace(reg, ""));
			
	if(tailleActuelle<18){
		
		var newTaille = tailleActuelle+1;
		
		document.body.style.fontSize = newTaille + 'px';
		
	}
}


function diminuer(){
	var reg = new RegExp("px", "g");
	var tailleActuelle = document.body.style.fontSize;
	tailleActuelle = Number(tailleActuelle.replace(reg, ""));
			
	if(tailleActuelle>11){
		
		var newTaille = tailleActuelle-1;
		
		document.body.style.fontSize = newTaille + 'px';
		
	}
}

var menu = 0;
var categorie_generale_courante = '';

function surVol(id1){}

function sousVol(id2){}

function afficheImageDansMenu(nombre){
	if(categorie_generale_courante != nombre){
		categorie_generale_courante = nombre;
	} else {
		categorie_generale_courante = nombre;
	}
}

function afficheMenu(id) {
	
	document.getElementById('ssmenu_rubrique_01').style.display='none';
	document.getElementById('ssmenu_rubrique_02').style.display='none';
	document.getElementById('ssmenu_rubrique_04').style.display='none';
	document.getElementById('ssmenu_rubrique_03').style.display='none';
	document.getElementById('ssmenu_rubrique_05').style.display='none';
	document.getElementById('ssmenu_rubrique_06').style.display='none';
	document.getElementById('ssmenu_rubrique_07').style.display='none';
	document.getElementById('ssmenu_'+id).style.display='block';
}

function afficheMenu2(){
	// menu = 0;
}

function cacheMenu(id) {
	document.getElementById('ssmenu_'+id).style.display='none';
/*	var y = getY();
	if((y > 294) || (y < 235)) {
		categorie_generale_courante = '';
		document.getElementById('ssmenu_'+id).style.display='none';
	}*/
}		
			
function afficheSousMenu(id) {
	$('sousmenu_'+id).style.display = 'block';	
}

function cacheSousMenu(id) {
	$('sousmenu_'+id).style.display = 'none';	
}

