$(document).ready(function() {
		// Fiche aide en popup
		if($('a[id|="showAide"]').length){
	        $('a[id|="showAide"]').click(function(){
	                if($('#iframewindow').length){$.closeWindow("iframewindow");}
	                frameTitle = $(this).siblings('.titreAide').text();
	                aideId = $(this).attr('name');
	                $.newWindow({id:"iframewindow",posx:500,posy:200,width:700,height:400,title:frameTitle, type:"iframe"});
	                $.updateWindowContent("iframewindow", "<iframe src='/cg27/fiche_detail?id=" + aideId + "&type=1' width='700' height='400'/>");
	        });
		}
		
		// Fiche presse en popup
		if($('a[id|="showPresse"]').length){
	        $('a[id|="showPresse"]').click(function(){
	                if($('#iframewindow').length){$.closeWindow("iframewindow");}
	                frameTitle = "Communiqu&eacute; de presse";
	                presseId = $(this).attr('name');
	                $.newWindow({id:"iframewindow",posx:500,posy:200,width:560,height:300,title:frameTitle, type:"iframe"});
	                $.updateWindowContent("iframewindow", "<iframe src='/cg27/fiche_detail?id=" + presseId + "&type=2' width='560' height='300'/>");
	        });
		}
		// Fiche publication en popup
		if($('a[id|="showPublication"]').length){
	        $('a[id|="showPublication"]').click(function(){
	                if($('#iframewindow').length){$.closeWindow("iframewindow");}
	                frameTitle = "Publication";
	                publicationId = $(this).attr('name');
	                $.newWindow({id:"iframewindow",posx:500,posy:200,width:560,height:400,title:frameTitle, type:"iframe"});
	                $.updateWindowContent("iframewindow", "<iframe src='/cg27/fiche_detail?id=" + publicationId + "&type=3' width='560' height='400'/>");
	        });
		}			

		//Choix du mode de recherche
		if ($('#choixAfficheResultats a').length){
			$('#choixAfficheResultats a').click(function(){
				$('input[name|="searchOrder"]').attr('value', $(this).attr('name'));
				$(this).attr('class', 'triRecherche_actif');
				$(this).siblings().attr('class', 'triRecherche_inactif');
				$(this).parent().parent().submit();
			});
		}
		if ($('#choixAfficheResultatsRappel a').length){
			$('#choixAfficheResultatsRappel a').click(function(){
				$('input[name|="searchOrder"]').attr('value', $(this).attr('name'));
				$(this).attr('class', 'triRecherche_actif');
				$(this).siblings().attr('class', 'triRecherche_inactif');
				$(this).parent().parent().submit();
			});
		}
		
		//Navigation gauche : texte alternatif!
		if($('a[rel=tooltip]').length){
			$('a[rel=tooltip]').tooltip();
		}	
});

function readCookie(name){
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return "Username";
}

function updateFiltre(selectedCategoryId){
	var categoriesFiltreForm = document.forms["categoriesFiltreForm"];
	var categoriesFiltreConteneur = document.getElementById("categoriesFiltre");
	var allCategories = categoriesFiltreConteneur.childNodes;
	for (var i=0;i<allCategories.length;i++){
		var curCategorie = allCategories.item(i);
		if (curCategorie.nodeName == "A"){
			var categorieId = curCategorie.id;
			if (categorieId == selectedCategoryId){	
				categoriesFiltreForm.elements["categorieSelectionnee"].value=categorieId;
				break;
			}		
		}
	}
	categoriesFiltreForm.submit();
}

function validationCommentaires(){
	var commentateur = document.getElementsByName("commentateurActuPortail")[0].value;
	document.getElementsByName("commentateurActuPortail")[0].value = stripHTML(commentateur);
	var commentaire = document.getElementsByName("texteCommentaireActuPortail")[0].value;
	document.getElementsByName("texteCommentaireActuPortail")[0].value = stripHTML(commentaire);
	document.submitToContainerList.submit();
}

function stripHTML(txt){ 
    return txt.replace(/(<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>)|(<!--.*?-->)/gim, "")
}

