 var ua = navigator.userAgent.toLowerCase();
 var isOpera = (ua.indexOf('opera') > -1);
 var isSafari = (ua.indexOf('safari') > -1);
 var isIE = (window.ActiveXObject);
var popupWindow = "";

function gid(_id){
	return document.getElementById(_id);
}

function closeAndRefresh(){
	
	window.opener.location.reload(true);
	window.close();
	
}

function closeAndFocus(){
	if (window.opener) {
		window.opener.focus();
	}
	window.close();
}

function SubmitFiltre(){
	if (checkPopupWindow()){
		/*
		if (gid('idstep').value == 'toolbar') {
			gid('idctrl').value=value=gid('idbckctrl').value;
			gid('idact').value=gid('idbckact').value;
			gid('idlayout').value='';
			gid('idformulaire_page').target='';	
		}*/
		//gid('selection').value="";
		//gid('remembercheck').value='';
		gid('idstep').value='submitfiltre';
		gid('idformulaire_page').submit();
	}
}

function SubmitFormOnKeyPress (e, typesubmit){
	var keycode;
	
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
		if (typesubmit == 'filtre') {
			SubmitFiltre();
		} else {
			doAction('rech','list','post',-1);
		}
		return false;
	}
	else
		 return true;
}

function restoreInitPageContext(){
	if (gid('oidctrl')){
		gid('idctrl').value=gid('oidctrl').value;
		gid('idact').value=gid('oidact').value;
		gid('idact').value=gid('oidact').value;
		gid('idstep').value=gid('oidstep').value;
		gid('idmenuid').value=gid('oidmenuid').value;
		gid('idtypemenu').value=gid('oidtypemenu').value;
		gid('params_arbo').value=gid('oparams_arbo').value;
	}
}

function closeAndSubmit(){
	if (window.opener) {
		bredirPref = false;
		if (gid('bredirpref')) {
			if (gid('bredirpref').value==1)
				bredirPref = true;
		}
		
		if (bredirPref) {
			window.opener.document.getElementById('idact').value = 'list';
			window.opener.document.getElementById('idctrl').value = 'populationpap';
			window.opener.document.getElementById('idstep').value = '';
			window.opener.document.getElementById('idtypemenu').value='Service';
			window.opener.document.getElementById('idmenuid').value=17;
		} else {
			window.opener.document.getElementById('idact').value=window.opener.document.getElementById('idbckact').value;
			window.opener.document.getElementById('idctrl').value=window.opener.document.getElementById('idbckctrl').value;
			window.opener.document.getElementById('idstep').value=value=window.opener.document.getElementById('idbckstep').value;
		}
		
		window.opener.document.getElementById('idlayout').value='';
		window.opener.document.getElementById('idformulaire_page').target='';
		
		//window.opener.document.getElementById('bpopupopened').value = '0';
		setParambpopupopened(0);
		
		window.opener.document.getElementById('remembercheck').value ='';

		// On décoche toutes les cases à cocher de la page principale
		oCinput = window.opener.document.getElementsByName('check[]');
		iMax    = oCinput.length;
		if( iMax > 0 ){
			for(i = 0; i < iMax; i++){
				oInput = oCinput[i];
				oInput.checked = false;
			}
		}

		window.opener.document.getElementById('idformulaire_page').submit();
		window.opener.focus();
		self.close();
	}
}

/* FUONCTION QUI DEPLIE OU REPLIE L'ARBO. */
function hasUlChild(_col)
{
	// ****
	var rValue;
	
	// ****
	var hasUlChildd;
	
	// ****
	hasUlChildd = _col.length > 0;
	rValue       = hasUlChildd;
	
	// ****
	return rValue;
}

function setImageOn(UlId) {
	srcOldImage=document.getElementById('im'+UlId).src;
	if (srcOldImage.indexOf('_on.gif')==-1) {
		newSrc=srcOldImage.replace('.gif','_on.gif');
		document.getElementById('im'+UlId).src=newSrc;
	}
}

function hideAllUl(idCurrent){
	
	//***
	var listUl;
	var listUlBis;
	var paramsArbo;
	var i;
	var j;
	
	//***
	listUl = gid('nav_principal').getElementsByTagName('ul');
	
	//***
	for(i=0; i<listUl.length; i++){
		if(listUl[i].parentNode.parentNode.id != "nav_principal"){

			if (listUl[i].id.substring(0, 3) != 'Rdp') {
				listUl[i].style.display = "none";	
			} else {
				if (listUl[i].id.split('_').length != 2)
					listUl[i].style.display = "none";
				else
					setImageOn(listUl[i].id);		
			}
		}
	}
	
	paramsArbo = gid('params_arbo').value;
	paramsArbo = paramsArbo.split('#');	
	
	for(key in paramsArbo){		
		if(paramsArbo[key] != '' && gid(paramsArbo[key])){
			document.getElementById(paramsArbo[key]).style.display = "block";
			setImageOn(paramsArbo[key]);
		}
	}
	if (gid(idCurrent))
		gid(idCurrent).className = gid(idCurrent).className + " current";
	 
}

function showOrHideSrub(_o, level, client, is_public){
	
	var liParent;
	var ulFilsStyleDisplay;
	var ulFils;
	var temp = '';
	
	
	if(gid('params_arbo').value != ""){
		temp = gid('params_arbo').value;							
	}
	liParent     = _o.parentNode;	
	ulFils = liParent.getElementsByTagName('ul');	
	
	if (_o.id.substring(2, 5) != 'Rdp') { 
		if( ulFils.length > 0)
		{
			ulFilsStyleDisplay = ulFils[0].style.display;
			if(ulFilsStyleDisplay == "block" ){
				ulFils[0].style.display = "none";
				_o.src= "/perso/"+client+"/picto/puce_nav"+level+"_" + is_public +".gif";
				temp = temp.replace(ulFils[0].id + '#', '');
				gid('params_arbo').value = temp;
				
			}else{
				ulFils[0].style.display = "block";
				_o.src= "/perso/"+client+"/picto/puce_nav"+level+"_" + is_public + "_on.gif";
				temp = temp + ulFils[0].id + '#';
				gid('params_arbo').value = temp;
			}
		}
	}
}

function showOrHideSrubCdRom(_o, level, client, is_public, path_cdrom){
	
	var liParent;
	var ulFilsStyleDisplay;
	var ulFils;
	var temp = '';
	
	
	if(gid('params_arbo').value != ""){
		temp = gid('params_arbo').value;							
	}
	liParent     = _o.parentNode;	
	ulFils = liParent.getElementsByTagName('ul');	
	if( ulFils.length > 0)
	{
		ulFilsStyleDisplay = ulFils[0].style.display;
		if(ulFilsStyleDisplay == "block" ){
			ulFils[0].style.display = "none";
			_o.src= path_cdrom+"perso/"+client+"/picto/puce_nav"+level+"_" + is_public +".gif";
			temp = temp.replace(ulFils[0].id + '#', '');
			gid('params_arbo').value = temp;
			
		}else{
			ulFils[0].style.display = "block";
			_o.src= path_cdrom+"perso/"+client+"/picto/puce_nav"+level+"_" + is_public + "_on.gif";
			temp = temp + ulFils[0].id + '#';
			gid('params_arbo').value = temp;
		}
	}	
}



function openPopup(url, titre){
	popupWindow=window.open(url, 'selectTheme', "width=1,height=1,scrollbars=yes,resizable=yes,status=no,top=0,left=0");

}

function checkAlready(hiddenF, prefixe, chkcontrol){

	//***
	var listCheck;
	var temp;
	
	//***
	listCheck = window.opener.document.getElementById(hiddenF).value;
	temp = new Array();	
	
	//***
	temp = listCheck.split(',');

	if(temp.length > 0){
		for(key in temp){
			if(temp[key] != '') {
				if (gid(prefixe + temp[key])) 
					gid(prefixe + temp[key]).checked = true;
			}
		}
	}
	
	if (chkcontrol)
		ControlCheckTheme(prefixe);
}

// Fonction pour l'initialisation des checkbox dans la liste de sélection de thème
// Décoche et met disabled à true les checkbox sous-thèmes dont les thèmes parents sont décochés.
function ControlCheckTheme (prefixe) {
	//***
	listUl = gid('listeselect').getElementsByTagName('ul');
	
	//***
	for(i=0; i<listUl.length; i++){
		if(listUl[i].parentNode.parentNode.id != "listeselect"){
			idtheme = listUl[i].parentNode.parentNode.id.split('_');
			if (gid(prefixe + idtheme[1])) {
				if (!gid(prefixe + idtheme[1]).checked) {
					idthemeChild = listUl[i].id.split('_');
					if (gid(prefixe + idthemeChild[1])) {
						gid(prefixe + idthemeChild[1]).checked = false;
						gid(prefixe + idthemeChild[1]).disabled = true;
					}
				}
			}
		}
	}
}

function ctrlSubItem (_o) {
	idtheme = _o.id.split('_');
	
	if (gid('Theme_' + idtheme[1])) {
		listUl = gid('Theme_' + idtheme[1]).getElementsByTagName('ul');
		for(i=0; i<listUl.length; i++){
			idthemeChild = listUl[i].id.split('_');
			if (gid('rub_' + idthemeChild[1])) {
				if (_o.checked) {
					gid('rub_' + idthemeChild[1]).disabled = false;
				} else {
					gid('rub_' + idthemeChild[1]).checked = false;
					gid('rub_' + idthemeChild[1]).disabled = true;
				}
			}
		}
	}
}

function ctrlSubItem2 (_o) {
	idtheme = _o.id.split('_');
	
	if (gid('Theme_' + idtheme[1])) {
		listUl = gid('Theme_' + idtheme[1]).getElementsByTagName('ul');
		for(i=0; i<listUl.length; i++){
			idthemeChild = listUl[i].id.split('_');
			if (gid('rub_' + idthemeChild[1]))
				gid('rub_' + idthemeChild[1]).checked = _o.checked;
		}
	}
}

function updateSelectTheme(hiddenF, textF, divName){
	
	/*
	
	hiddenF : correspond au champ input hidden qui recoit la liste des cases cochées
	textF : correspond au champ de texte a mettre à jour 
	divName : correspond a la DIV dans laquelle on va liste l'ensemble des libel des cases cochées
	
	*/	
	
	//***
	var tabInput = new Array();
	var tempStr;
	var cpt;
	var divContent;

	//***
	tabInput = gid('listeselect').getElementsByTagName('input');
	tempStr = '';
	cpt = 0;
	divContent = '';		
		
	for(i=0; i< tabInput.length; i++){		
		if(tabInput[i].checked != false && tabInput[i].id != undefined){	
			tempStr = tempStr + tabInput[i].value + ',';
			divContent = divContent + gid('label_' + tabInput[i].value).innerHTML + '<br/>';
			cpt++;
		}		
	}
	
	tempStr = tempStr.substring(0, tempStr.length - 1);
	
	if(cpt > 0){
		if(textF != '')
			window.opener.document.getElementById(textF).value = cpt + ' sélectionné(s)';
		window.opener.document.getElementById(hiddenF).value = tempStr;
		if(divName != '')
			window.opener.document.getElementById(divName).innerHTML = divContent;
	}
	else
	{
		if(textF != '')
			window.opener.document.getElementById(textF).value = "-Tous-           ->";
		window.opener.document.getElementById(hiddenF).value = "";		
	}
	
	if (isPopulationForm()) {
		window.opener.document.getElementById('idstep').value = 'post';
		window.opener.document.getElementById('brefreshdata').value = 1;
		window.opener.document.getElementById('idformulaire_page').submit();
		window.close();
	} else
		window.close();
}

// indique si la popup courante est bloquante ou non
function isPopulationForm () {
	isPopulationForm = false;
	
	if (window.opener)
		if (window.opener.document.getElementById('idctrl').value == 'population')
			if (window.opener.document.getElementById('idact').value == 'ajouterpop' || window.opener.document.getElementById('idact').value == 'modifier')
				isPopulationForm = true;

	return isPopulationForm;
}

function updateSelectDesc(hiddenF, textF){
	
	//***
	var key;
	var tabInput = new Array();
	var tempStr;
	var cpt;

	//***
	tabInput = gid('listeselect').getElementsByTagName('input');
	key = 0;
	tempStr = '';
	cpt = 0;
		
	for(i=0; i<tabInput.length; i++){
		
		if(tabInput[i].checked != false && tabInput[i].id != undefined){	
			tempStr = tempStr + tabInput[i].value + ',';
			cpt++;
		}		
	}
	
	tempStr = tempStr.substring(0, tempStr.length - 1);

	
	if(cpt > 0){
		window.opener.document.getElementById(textF).value = cpt + ' sélectionné(s)';
		window.opener.document.getElementById(hiddenF).value = tempStr;
	}
	else
	{
		window.opener.document.getElementById(textF).value = "-Tous-           ->";
		window.opener.document.getElementById(hiddenF).value = "";		
	}
	
	window.close();
}

function updateSelectSupport(hiddenF, textF, divName){
	tempStr = '';
	divContent = '';
	
	tabOptions = document.getElementsByName('selectsupport');
	for (var i=0; i<tabOptions.length; i++) {
		if (tabOptions[i].checked) {
        	tempStr = tabOptions[i].value;
			divContent = gid('nomsupport_'+tempStr).innerHTML;
		}
	}
	
	if (tempStr == '') {
		doAction('support','select','err_noidselect',-1);
	} else {
		if(divName != '')
			window.opener.document.getElementById(divName).innerHTML = divContent;
		window.opener.document.getElementById('libsupport').value = divContent;
		window.opener.document.getElementById(hiddenF).value = tempStr;
		window.close();
	}
}

function checkSelected(hiddenF, SelectToUpdate){

	//***
	var listCheck;
	var temp;
	
	//***
	listCheck = window.opener.document.getElementById(hiddenF).value;
	temp = new Array();	
	
	//***
	temp = listCheck.split(',');

	if(temp.length > 0){
		tabOptions = gid(SelectToUpdate).getElementsByTagName('option');
		for (var i=0; i<tabOptions.length; i++) {
			for(key in temp){
				if (temp[key] == gid(SelectToUpdate).options[i].value)
					gid(SelectToUpdate).options[i].selected = true;
			}
		}
	}
}

function checkAllSimple(idCheckAll,nameCheckboxes){
	var allCheckbox;
	var lstCheckbox;
	var iMax;
	allCheckbox= document.getElementById(idCheckAll);
	if (allCheckbox){
		valCheck=allCheckbox.checked;
		lstCheckbox = document.getElementsByName(nameCheckboxes);
		iMax    = (lstCheckbox ? lstCheckbox.length : 0);
		for(i = 0; i < iMax; i++){
			lstCheckbox[i].checked = valCheck;
		}
	}
}

function checkAll(_o){
	 // ****
	var oCinput;
	var oInput;
	var conf_tout_selectionner;
	var isAllSection;
	var oName;
	var colName;
	var i;
	var iMax;
	var isChecked;
	// ****
	conf_tout_selectionner = "tout_selectionner";
	oName                 = _o.name.toString();
	isChecked             = true;
	// ****
	isAllSection = oName.toUpperCase() == conf_tout_selectionner.toUpperCase();
	// ****
	colName = isAllSection ? _o.value : _o.name;
	oCinput = document.getElementsByName(colName);
	iMax    = (oCinput ? oCinput.length : 0);

	// ****
	if( iMax > 0 ){
		// ****
		if( isAllSection ){
			// ****
			for(i = 0; i < iMax; i++){
				oInput = oCinput[i];
				oInput.checked = _o.checked;
				
				removeCheck(oInput.id);
			}
		}else{
			// ****
			for(i = 0; i < iMax; i++){
				oInput = oCinput[i];
				isChecked = isChecked && oInput.checked;
			}                               
			// ****
			oInput         = document.getElementById("tout_selectionner");
			oInput.checked = isChecked;                          
		}
	} else{
		//alert("DEBUG :: PROBEME");
	}
}


function checkAllDay(_o){
	
	 // ****
	var oCinput;
	var oInput;
	var conf_tout_selectionner;
	var isAllSection;
	var oName;
	var colName;
	var i;
	var iMax;
	var isChecked;

	// ****
	conf_tout_selectionner = "tout_selectionner";
	oName                 = _o.name.toString();
	isChecked             = true;
	
	// ****
	isAllSection = oName.toUpperCase() == conf_tout_selectionner.toUpperCase();
	
	// ****
	colName = isAllSection ? _o.value : _o.name;
	oCinput = document.getElementsByName(colName);
	iMax    = oCinput.length;

	// ****
	if( iMax > 0 ){
		// ****
		if( isAllSection ){
			// ****
			for(i = 0; i < iMax; i++){
				oInput = oCinput[i];
				oInput.checked = _o.checked;								
			}
			
			if(!gid('tout_selectionner').checked){
				//tabHeure = gid('liste_horaire').getElementsByTagName('input');
				for(i=1; i<=18; i++){
					gid('horaire_'+i).checked = false;
				}	
			}
			
		}else{
			// ****
			for(i = 0; i < iMax; i++){
				oInput = oCinput[i];
				isChecked = isChecked && oInput.checked;
			}                               
			// ****
			oInput         = document.getElementById("tout_selectionner");
			oInput.checked = isChecked; 
			
			if(!gid('tout_selectionner').checked){
				//tabHeure = gid('liste_horaire').getElementsByTagName('input');
				for(i=1; i<=18; i++){
					gid('horaire_'+i).checked = false;
				}		
			}

		}
	} else{
		//alert("DEBUG :: PROBEME");
	}
}

function disableAllCheckbox(){
	var i;
	gid('lundi').disabled = true;
	gid('mardi').disabled = true;
	gid('mercredi').disabled = true;
	gid('jeudi').disabled = true;
	gid('vendredi').disabled = true;
	gid('samedi').disabled = true;
	gid('dimanche').disabled = true;
	gid('tout_selectionner').disabled = true;
	
	gid('lundi').checked = false;
	gid('mardi').checked = false;
	gid('mercredi').checked = false;
	gid('jeudi').checked = false;
	gid('vendredi').checked = false;
	gid('samedi').checked = false;
	gid('dimanche').checked = false;
	gid('tout_selectionner').checked = false;
	
	
	for(i=1; i<=18; i++){
	
		gid('horaire_'+i).disabled = true;
		gid('horaire_'+i).checked = false;
	
	}
	return true;
	
}

function enableAllCheckbox(){
	
	var i;
	gid('lundi').disabled = false;
	gid('mardi').disabled = false;
	gid('mercredi').disabled = false;
	gid('jeudi').disabled = false;
	gid('vendredi').disabled = false;
	gid('samedi').disabled = false;
	gid('dimanche').disabled = false;
	gid('tout_selectionner').disabled = false;	
	
	for(i=1; i<=18; i++){
	
		gid('horaire_'+i).disabled = false;
	
	}
	return true;
}


function verifAllDay(obj){
	
	//var tabHoraire;
	//tabHoraire = gid('liste_horaire').getElementsByTagName('input');
	
	if(gid('tout_selectionner').checked != true){
		
		for(i=1; i<=18;  i++){
			gid('horaire_'+i).checked = false;			
		}
		obj.checked = true;
	}
}

/**
* Effacement des variables de liste paginée (sinon pb lorsqu'on passe d'une rubrique à une autre (Exemple : utilisateur -> page suivante puis clic dans le menu sur Descripteur -> on se retrouve en page 2)
*/
function cleanupListData(){
	if (gid('offset')){
		gid('offset').value='0';
		gid('coltri').value='';
		gid('senstri').value='';
		gid('remembercheck').value='';
	}
}

function sendToServiceOrTheme(_themeouservice, _idthemeouservice) {
	gid('idtypemenu').value = _themeouservice;
	gid('idmenuid').value = _idthemeouservice;
	if (_themeouservice == 'Theme'){
		gid('idctrl').value = 'them';
		gid('idact').value = 'listcoupures';
	} else {
		gid('idctrl').value='';
		gid('idact').value='';
	}
	gid('idstep').value='';
	gid('idlayout').value='';
	gid('idformulaire_page').target='';	
	
	if (gid('selection'))
		gid('selection').value="";
	
	if (gid('binitliste'))
		gid('binitliste').value="";
	
	gid('idchangemenu').value='1';
	gid('idformulaire_page').submit(); 
}
 
function doMenuAction(themeouservice,idthemeouservice,level,perso,hasChildren){
	if (level==2 && (themeouservice=='Service' || themeouservice=='Rdp') && hasChildren=='true')
		showOrHideSrub(gid('im'+themeouservice+'_'+idthemeouservice),level-1,perso,'public');
	else if (checkPopupWindow())
		sendToServiceOrTheme(themeouservice, idthemeouservice);
}

function initFiltre(){
	// Réinitialise les variables de filtres de notre liste

	if (gid('commonliste')) {
		tabInput = gid('commonliste').getElementsByTagName('input');
		for(key in tabInput){
			if (tabInput[key].name) {
				var NameVar = tabInput[key].name;
				if ((NameVar.substring(0,7) == 'filtre_') || (NameVar.substring(0,8) == 'hfilter_') || (NameVar.substring(0,14) == 'opDatehfilter_')) {
					tabInput[key].value="";
				}
			}
		}
		
		tabSelect = gid('commonliste').getElementsByTagName('select');
		for(key in tabSelect){
			if (tabSelect[key].name) {
				var NameVar = tabSelect[key].name;
				
				if ((NameVar.substring(0,7) == 'filtre_') || (NameVar.substring(0,13) == 'opDatefiltre_')) {
					if (tabSelect[key].options[0]) {
						tabSelect[key].options[0].selected = true;
					}
				}
			}
		}
		//gid('remembercheck').value='-1,';
		gid('offset').value="0";
	}
	}

function cancelFiltre(context,act){
	restoreInitPageContext();
	initFiltre();
	doAction(context,act,'cancelfiltre',-1);
}
function checkPopupWindow(){
//	if ((!popupWindow ||popupWindow==null) && gid("bpopupopened").value != 1){

	if (gid("bpopupopened").value != 1){
		return true;
	}
	else if (popupWindow.closed == true){
		return true;
	}
	else {
		alert("Veuillez fermer la fenêtre en cours d'édition via le bouton fermer en bas à droite");
		return false;
	}
	
}

function classer(ctrl,act,targetAct){
    var options = 'toolbars=0,width=1000,height=620,top=0,left=0,resizable=yes,status=no,scrollbars=yes';
    var popupClasser;
	popupClasser=window.open('','popupClasser',options); 
	if (gid('idstep').value!='toolbar'){
		gid('idbckact').value=gid('idact').value;
		gid('idbckctrl').value=gid('idctrl').value;
		gid('idbckstep').value=gid('idstep').value;
	}
	gid('idlayout').value='popup';
	gid('idstep').value='toolbar';
	gid('idformulaire_page').target='popupClasser';
	gid('idact').value=act;
	gid('idctrl').value=ctrl;
	gid('idformulaire_page').submit(); 
	if (targetAct!=''){
		gid('idact').value=gid('idbckact').value;
		gid('idctrl').value=gid('idbckctrl').value;
		gid('idstep').value=gid('idbckstep').value;
		gid('idlayout').value='';
		gid('idformulaire_page').target='';
	}
}

function doToolbarAction(ctrl,act,targetAct){
	if (act == 'listpreclassement') {
		sendToServiceOrTheme('Service', 123); // Id dans Service pour la liste des pré-classement : 123
	} else if (act == 'in_cart') {
		sendToServiceOrTheme('Service', 138); // Id dans Service pour le contenu du panier : 138
	} else {
		width=1;
		height=1;
		if (act == 'newsml') {
			width=600;
			height=800;
		}
		internalDoToolbarAction(ctrl,act,targetAct,'toolbars=0,resizable=yes,status=no,scrollbars=yes,width='+width+',height='+height+',top=0,left=0');
	}
}

function doToolbarActionWithPopupOption(ctrl,act,targetAct,popupOption){
	internalDoToolbarAction(ctrl,act,targetAct,popupOption);
}

/* action faite dans la toolbar */
function internalDoToolbarAction(ctrl,act,targetAct,popupOption){
	restoreInitPageContext();
	if (act=='classer'){
		classer(ctrl,act,targetAct);
	}
	else {
		if (checkPopupWindow()){
			if (targetAct!=''){
				var namepopup = 'popupWindow';
				if (act == 'impressionpdf' || act == 'telecharger') {
					namepopup = 'popupservice';
				}
				popupWindow=window.open('',namepopup,popupOption); 
				gid('idbckact').value=gid('idact').value;
				gid('idbckctrl').value=gid('idctrl').value;
				gid('idbckstep').value=gid('idstep').value;
				gid('idlayout').value='popup';
				gid('idformulaire_page').target=namepopup;
			} else {
				gid('idformulaire_page').target='';
				gid('idlayout').value='';
			}
			gid('bactiontab').value='';
			gid('idstep').value='toolbar';
			gid('idact').value=act;
			if (ctrl!='')
				gid('idctrl').value=ctrl;
			gid('idformulaire_page').submit(); 
			if (targetAct!=''){
				gid('idact').value=gid('idbckact').value;
				gid('idctrl').value=gid('idbckctrl').value;
				gid('idstep').value=gid('idbckstep').value;
				gid('idlayout').value='';
				gid('idformulaire_page').target='';
			}
		}
	}
}


function doselectionListe(ctrl,act,targetAct){
	if (checkPopupWindow()){
		strRememberchk = gid('remembercheck').value.replace(/(^\s*)|(\s*$)/g,'');
		
		if (strRememberchk.length > 1) {
			gid('selection').value="selection";
			gid('idstep').value="selection";
			gid('offset').value="0";
			doToolbarAction(ctrl,act,targetAct);
		}
	}
}
function redoselectionListe(ctrl,act,targetAct){
	if (checkPopupWindow()){
		gid('selection').value="";
		gid('idstep').value="noselection";
		gid('offset').value="0";
		
		if (gid('tout_selectionner')) {
			checkAll(gid('tout_selectionner'));
		}
		doToolbarAction(ctrl,act,targetAct);
	}
}

function refrechPopup(blclose, bbloq){
	//gid('idact').value=gid('idbckact').value;
	//gid('idctrl').value=gid('idbckctrl').value;
	//gid('idstep').value=gid('idbckstep').value;
	gid('idlayout').value='';
	if (gid('remembercheck'))
		gid('remembercheck').value ='';
	if (blclose){		
		if (! popupWindow.closed){
			 popupWindow.close();
		}
		popupWindow=null;
		
		//gid('bpopupopened').value = '0';
	}
	else {
		if (bbloq) {
			//gid('bpopupopened').value = '1';
		} else {	
			//gid('bpopupopened').value = '0';
		}
	}
	gid('idformulaire_page').target='';	
	gid('idformulaire_page').submit(); 
}



/* action dans le formulaire et dans la barre d'outil (on connait déjà ctrl et act)*/
function doAction(ctrl,act,step){
	if (checkPopupWindow()){

		/* La fonction doAction est utilisé pour le formulaire Classer.
			Lorsqu'on fait appel à cette fonction à partir de ce formulaire il faut récupérer la valeur de 'bpopupopened' de l'opener
			avant de faire le submit pour ne pas perdre l'aspect bloquant des autres popups ouvertes en plus de Classer
		*/
		if (!isPopupBloquante())
			if (window.opener)
				gid('bpopupopened').value = window.opener.document.getElementById('bpopupopened').value;
		
		
		restoreInitPageContext();
		gid('idctrl').value=ctrl;
		gid('idact').value=act;
		gid('idstep').value=step;
		gid('idformulaire_page').target='';		
		gid('idformulaire_page').submit(); 
	}
}

function gotoOffset(offset,act){
	if (checkPopupWindow()){
		restoreInitPageContext();
		gid('offset').value=offset;
		gid('idact').value=act;
		gid('idstep').value='offset';
		gid('idformulaire_page').submit();
	}
}
function sort(col,sens, act){
	if (checkPopupWindow()){
		restoreInitPageContext();
		gid('coltri').value=col;
		gid('senstri').value=sens;
		gid('offset').value=0;
		//gid('remembercheck').value='-1,';
		gid('idact').value=act;
		gid('idstep').value='sort';
		gid('idformulaire_page').submit();
	}
}
function applyFiltre(act){
	if (checkPopupWindow()){
		restoreInitPageContext();
		gid('remembercheck').value='-1,';
		gid('offset').value="0";
		gid('idact').value=act;
		gid('idstep').value='applyfiltre';
		gid('idformulaire_page').submit();
	}
}
function removeCheck(idcheck){
	checkBox=gid(idcheck);
	remembercheck=gid('remembercheck')
	if (checkBox.checked==false){
		valRememberCheck=remembercheck.value;
		replaceToken=','+checkBox.value+',';
		valRememberCheck=valRememberCheck.replace(replaceToken,',');
		remembercheck.value=valRememberCheck
	}
	else {
		if (remembercheck.value.indexOf(checkBox.value) == -1) {
			if (remembercheck.value=='') remembercheck.value=',';
			remembercheck.value=remembercheck.value+checkBox.value+',';
		}
	}
	//alert(remembercheck.value);
}


function writeSpanMenu(type,id,str){
	idSpan='sp'+type+'_'+id;
	if (gid(idSpan))
		gid(idSpan).innerHTML='&nbsp;'+str+'';
}


function doActionContentTab(key,ctrl,act,targetAct){
		if (checkPopupWindow()){
			if (targetAct!=''){
				popupWindow=window.open('','popupWindow','toolbars=0,width=1,height=1,top=0,left=0'); 
				gid('idbckact').value=gid('idact').value;
				gid('idbckctrl').value=gid('idctrl').value;
				gid('idbckstep').value=gid('idstep').value;
				gid('idlayout').value='popup';
				gid('idstep').value='toolbar';
				gid('idformulaire_page').target='popupWindow';
			}
			
			gid('idActionContentTab').value=key;
			gid('bactiontab').value='1';
			gid('idact').value=act;
			gid('idctrl').value=ctrl;
			gid('idstep').value='toolbar';
			
			gid('idformulaire_page').submit(); 
			if (targetAct!='') setTimeout("popupWindow.focus();",1000);
			if (targetAct!=''){
				gid('idact').value=gid('idbckact').value;
				gid('idctrl').value=gid('idbckctrl').value;
				gid('idstep').value=gid('idbckstep').value;
				gid('idlayout').value='';
				gid('idformulaire_page').target='';
			}
		}
}
function dovisibilite(ctrl,act,targetAct){
	if (checkPopupWindow()){
		if (gid('remembercheck'))
			strRememberchk = gid('remembercheck').value.replace(/(^\s*)|(\s*$)/g,'');

		gid('rdpinvisible').value="visible";
		gid('rdpvisible').value="visible";
		gid('idstep').value="rdpinvisible";
		gid('offset').value="0";
		doToolbarAction(ctrl,act,targetAct);
	}
}
// passage à l'affichage
function viewPdfGenere(urlPdf)
{
	if( navigator.appVersion.substring(0,1)>=4 )
	{
	    TailleDispoV=screen.availHeight;
		TailleDispoH=screen.availWidth;
	}
	else
	{
	    TailleDispoV=600;
	    TailleDispoH=800;
	}
	pdfView=window.open(urlPdf,'','toolbars=0,resizable=yes,status=no,scrollbars=yes,width='+TailleDispoH+',height='+TailleDispoV,',top=0,left=0,x=0,y=0'); 
	if(pdfView && pdfView.window && pdfView.window.focus){
		pdfView.window.focus();
		if (pdfView.window.opener) pdfView.window.opener.close();
	}	
}												

function affSynthese(idcoupure,format,datecreation){
	gid('idActionContentTab').value=idcoupure+'@@0';
	gid('format').value=format;
	gid('datecreation').value=datecreation;
	doAction('synt','detail','affsynt',-1);
}
function SubmitEnDateDu() {
	if (window.opener) {
			window.opener.document.getElementById("perioderdp").value = gid("perioderdpfromdate").value;
			window.opener.document.getElementById('idformulaire_page').target='';
			window.opener.document.getElementById('idact').value='list';
			window.opener.document.getElementById('idlayout').value='';
			window.opener.document.getElementById('idstep').value='';
			if (window.opener.document.getElementById('offset'))
				window.opener.document.getElementById('offset').value=0;
			window.opener.document.getElementById('idformulaire_page').submit();
			window.opener.focus();
			window.close();
	}
}


function resizeOW() {
	var w, h, fixedW, fixedH, diffW, diffH;

	var ww=300;
	//initialisation de la hauteur par défaut mini
	var hh=200;
	//incrément pour IE
	var step=20;
	
	window.moveTo(0, 0);
	if (document.all) {
		self.window.resizeTo(100,100);
		self.window.resizeTo(document.body.scrollWidth,document.body.scrollHeight);
	
		if (document.body.clientWidth<800) {
			self.window.resizeBy(600-document.body.clientWidth,0);
		} else {
			self.window.resizeBy(0,70);
		}	
		if (document.body.clientHeight<175) self.window.resizeBy(0,175-document.body.clientHeight);

		//fixedW = document.body.clientWidth;
		//fixedH = document.body.clientHeight;
		//diffW = fixedW - document.body.clientWidth;
		//diffH = fixedH - document.body.clientHeight;
	} else {
		window.resizeTo(0,0);
		window.sizeToContent();
		window.resizeBy(100,100);
		
		//fixedW = window.innerWidth;
		//fixedH = window.innerHeight;
		//diffW = fixedW - window.innerWidth;
		//diffH = fixedH - window.innerHeight;
	}
	
	//w = fixedW + diffW;
	//h = fixedH + diffH;
	
	//if (h >= screen.availHeight) w += 16;
	//if (w >= screen.availWidth)  h += 16;
	//w = Math.min(w,screen.availWidth);
	//h = Math.min(h,screen.availHeight);
	
	//if (document.all) h += 70;
	//window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}
/*########################
# RESIZE IFRAME HTML POUR SUPPRIMER DOUBLE ASCENSEUR
########################*/
function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function fctCssExist(cssName) {
	var mySheet;
	mySheet = false;
	if (cssName != null && document.styleSheets && document.styleSheets.length) {
		for (i=0; i<document.styleSheets.length; i++) {
			var styleSheetHref=document.styleSheets[i].href;
			if(styleSheetHref.substring(styleSheetHref.length-cssName.length) == cssName) {
				mySheet = document.styleSheets[i];
				break;
			}
		}
	}
	return mySheet;
}

function getCssRules(myCss){
	var rulesArray;
	rulesArray=false;
	if(myCss.rules) rulesArray=myCss.rules;
	else if (myCss.cssRules) rulesArray=myCss.cssRules;
	return rulesArray;
}

function getCssDivHeight(cssName,divId){
	var myCss,ret,rulesArray;
	myCss=fctCssExist(cssName);
	/*val par defaut si le navigateur ne supporte pas l'inspection de la CSS via le DOM (Firefox et IE le supporte) */
	ret=96;
	if (!(myCss==false)){
		rulesArray=getCssRules(myCss);
		for (i=0; i<rulesArray.length; i++){
			if (rulesArray[i].selectorText=="DIV#"+divId || rulesArray[i].selectorText=="div#"+divId){
				ret=rulesArray[i].style.height;
				ret=parseInt(ret.replace('px',''));
			}
		}
	}
	return ret;	
}
/* -------------------------------------------------------*/
/*  fonction pour obtenir la hauteur de la page  courante */
/* -------------------------------------------------------*/
function getBrowserWindowHeight() {
   var height = -1;
   var mode = document.compatMode;

   if ( (mode || isIE) && !isOpera ) {
      switch (mode) { // (IE, Gecko)
         case 'CSS1Compat': // Standards mode
            height = document.documentElement.clientHeight;
            break;

         default: // Quirks
            height = document.body.clientHeight;
      }
   } else { // Safari, Opera
      height = self.innerHeight;
   }
	return height;
}

/* -------------------------------------------------------*/
/*  fonction pour obtenir la largeur de la page  courante */
/* -------------------------------------------------------*/

function getBrowserWindowWidth() {
   var width = -1;  
   var mode = document.compatMode;

   if ( (mode || isIE) && !isOpera ) {
      switch (mode) { // (IE, Gecko)
         case 'CSS1Compat': // Standards mode
            width = document.documentElement.clientWidth;
            break;

         default: // Quirks
            width = document.body.clientWidth;
      }
   } else { // Safari, Opera
      width = self.innerWidth;
   }
	return width;
}

// indique si la popup courante est bloquante ou non
function isPopupBloquante () {
	isBloquant = true;
	if (gid('idact'))
		if (gid('idact').value == 'impressionpdf' || gid('idact').value == 'telecharger' || gid('idact').value == 'classer')
			isBloquant = false;
	return isBloquant;
}


/* 
setParambpopupopened est appelée à l'ouverture et à la fermeture d'une popup (évènement onload/onunload de la popup)
Cette fonction met à jour un champ caché 'bpopupopened' de la fenêtre principale indiquant à celle-ci qu'une fenêtre bloquante existe ou non
Si la popup est non bloquante on ne doit faire aucune action sur le paramètre 'bpopupopened' sinon problème d'interraction possible avec les autres fenêtres bloquantes
*/
function setParambpopupopened(p_value) {
	if (isPopupBloquante())
		if (window.opener)
			if (window.opener.document.getElementById('bpopupopened'))
				window.opener.document.getElementById('bpopupopened').value = p_value;
}


function setFocusOnElem(focused,list,letter,letterpos){
	idElem='tr'+list+letter+letterpos;
	if (gid(idElem)){
		elem=gid(idElem);
		if (focused==false){
			if (elem.className.indexOf('_selected')!=-1){
				elem.className=elem.className.substr(0,elem.className.indexOf('_selected'));
			}

		}
		else if (elem.className.indexOf('_selected')==-1){
			elem.className=elem.className+'_selected';
		}
	}
}
function loseCurrentFocus(){
	setFocusOnElem(false,currentList,currentLetter,currentPos);
}

function initFocusElem(typeList){
	setLstPos(typeList,firstLetterByLst[typeList],1);
	gid(currentList+currentLetter+currentPos).focus();
}

function setLstPos(list,letter,letterpos){
	if (list!=currentList || letter!=currentLetter || letterpos!=currentPos){
		setFocusOnElem(false,currentList,currentLetter,currentPos);
		currentList=list;
		currentLetter=letter;
		currentPos=letterpos;
	}
	setFocusOnElem(true,currentList,currentLetter,currentPos);
}
function checkMoveTab(e){
	if (e.ctrlKey==false && (currentList=='A' || currentList=='B')){
	  	if (e.keyCode==currentLetter.charCodeAt(0)){		 
			 moveToPos=currentPos+(e.shiftKey ? -1 : 1);
			 if (gid(currentList+currentLetter+moveToPos)){
				gid(currentList+currentLetter+moveToPos).focus();
			 	setLstPos(currentList,currentLetter,moveToPos);
			 }
	  	}
	  	else {
				moveToLetter=String.fromCharCode(e.keyCode);
				 if (gid(currentList+moveToLetter+'1')){
					gid(currentList+moveToLetter+'1').focus();
					setLstPos(currentList,moveToLetter,1);
			}
	  	}
	  }
	  else {
	  	ctrlLetter=String.fromCharCode(e.keyCode);
		  if (ctrlLetter=='M' || ctrlLetter=='C'){
			/* positionnement sur le premier élément de la liste demandé */
			typeList=(ctrlLetter=='M' ? 'A' : 'B');
			gid(typeList+firstLetterByLst[typeList]+'1').focus();
			setLstPos(typeList,firstLetterByLst[typeList],1);
		}
		
	  }
}

/* Fonction utilisée dans la fenêtre Mise à jour en masse des RM */
/* Utilisée pour mettre à enabled/disabled les champs input en fonction des checkbox 'mettre à jour' */
function chkMajModifierTout (_o) {
	prefixe = 'chkmaj';
	oName = _o.name.toString();
	inputName = oName.substring(prefixe.length, oName.length);

	if (gid(inputName)) {
		gid(inputName).disabled = (!_o.checked);
		if (!_o.checked)
			gid('h'+inputName).value =  gid(inputName).value;
	}
}

function actOnCloseToutModifier(act) {
	if (gid('orig').value == 'classer')
		doAction('coupures',act,'retour',-1);
	else
		closeAndFocus();
}

function LanceModifRM(idcoupure) {
	gid('idcoupuretochange').value = idcoupure;
	doAction('rech','classer','modifRM',-1);
}

function changeTypeTheme(_o) {
	IdTypeSelected = _o.options[_o.selectedIndex].value;
	isdisable = (IdTypeSelected == 9);
	
	nbPopulation = document.getElementsByName('population[]').length;
	for (i=1; i<=nbPopulation; i++){
		chkidname = 'chkpopulation_'+i;
		gid(chkidname).disabled = isdisable;
	}
	gid('tout_selectionner').disabled = isdisable;
}

function getCssValueForPreloadBandeau(aClass,element) {
	// la CSS disposant des infos du bandeau est la dernière incluse, d'où le "document.styleSheets.length-1"
	rulesArray=getCssRules(document.styleSheets[document.styleSheets.length-1]);
	
	for (i=0; i<rulesArray.length; i++){
		var currentClass = rulesArray[i].selectorText;
		
		if (currentClass.indexOf(aClass) != -1)
			return rulesArray[i].style[element];
	}
	return '';
}

function preloadImage(ImageSrc) {
	if (document.images) {
		NewImage = new Image();
		NewImage.src = ImageSrc;
	}
}

function preloadMenuEtBandeau(perso) {
	if (perso == '')
		perso =  "base";
	
	if (document.images) {

		// Préload des images du menu
		for (lev=1; lev<=3; lev++){
			preloadImage("/perso/" + perso + "/picto/puce_nav" + lev + "_private.gif");
			preloadImage("/perso/" + perso + "/picto/puce_nav" + lev + "_private_on.gif");
			preloadImage("/perso/" + perso + "/picto/puce_nav" + lev + "_public.gif");
			preloadImage("/perso/" + perso + "/picto/puce_nav" + lev + "_public_on.gif");
			preloadImage("/perso/" + perso + "/picto/pucerond_nav" + lev + "_private.gif");
			preloadImage("/perso/" + perso + "/picto/pucerond_nav" + lev + "_public.gif");
		}
		
		// Préload des images du bandeau d'action
		if (gid('btn_actions')) {
			tabLiensAction = gid('btn_actions').getElementsByTagName('a');
			for (key in tabLiensAction){
				classBt = tabLiensAction[key].className;
				
				if (classBt!=null && classBt!='' && classBt!='undefined') {
					cssValue = getCssValueForPreloadBandeau(classBt+':hover','backgroundImage');
					srcBtHover = "/perso/" + perso + cssValue.substring(cssValue.indexOf('/picto/'), cssValue.indexOf(')'));
	
					preloadImage(srcBtHover);
				}
			}
		}
	}
}

function changeConfig(_o) {
	IdFreqSelected = _o.options[_o.selectedIndex].value;
	
	bjour = true;
	bjmois = true;
	bmois = true;
	bparite = true;
	
	switch (IdFreqSelected) {
		case 'H':
			bjour = false;
			break;
		case '2H':
			bjour = false;
			bparite = false;
			break;
		case 'M':
			bjmois = false;
			break;
		case '2M':
			bjmois = false;
			bparite = false;
			break;
		case '3M':
			bjmois = false;
			break;
		case '6M':
			bjmois = false;
			break;
		case 'A':
			bjmois = false;
			bmois = false;
			break;
	}

	gid('joursemaine').disabled = bjour;
	gid('jourmois').disabled = bjmois;
	gid('mois').disabled = bmois;
	gid('parite').disabled = bparite;
}

function FreezePage() {
	/*	var ar;
		var curOffset;
		
	document.getElementById("parentDiv").style.display = 'inline'; */
	
	ShowIndicator();

	/* AJOUT LLE */
	/*ar = document.getElementsByName('check[]');
	curOffset = -1;
	for (i=0; i<ar.length && curOffset == -1; i++){
		if (ar[i].value == key) {
			curOffset = i;
		}
	}
	gid('bactiontab').value=curOffset;
	/* FIN AJOUT LLE */
}

function ShowIndicator() {
	document.getElementById("waitIndicatorDiv").style.display = 'block';
	// document.getElementById("animLifeRay" ).style.display = 'block';
	document.getElementById("btnWithMargin" ).style.display = 'none';
}

function showSubMenu(idBtn) {
	if (gid('sousmenu')) {
		gid('sousmenu').style.display = "block";
		gid('sousmenu').style.left = gid(idBtn).offsetLeft + "px";
	}
}

function hideSubMenu() {
	if (gid('sousmenu'))
		gid('sousmenu').style.display = "none";
}

function doActionSubMenu(p_typeact, p_idtype) {
	if (p_typeact == 'integration') {
		gid('typeinteg').value = p_idtype;
		doToolbarAction('coupures','integcoupuresuite','Fenetre_secondaire');
	} else
		doToolbarAction(gid('idctrl').value,p_idtype,'Fenetre_secondaire'); 
}

function manageCheckbox3State(_o, suffixe) {
	Oldsrc = _o.src;
	hiddenid = suffixe + _o.id.substring(_o.id.indexOf('_') + 1);
	
	if (Oldsrc.indexOf('chk_disabled.gif')!=-1) {
		_o.src = '/perso/base/picto/chk_checked.gif';
		gid(hiddenid).value = 1;
	} else {
		if (Oldsrc.indexOf('chk_normal.gif')!=-1) {
			_o.src = '/perso/base/picto/chk_checked.gif';
			gid(hiddenid).value = 1;
		} else {
			_o.src = '/perso/base/picto/chk_normal.gif';
			gid(hiddenid).value = 0;
		}
	}
}

function checkAllForCheckBox3States(_o, idconteneurchk, sufidhidden, sufidchk) {
	tabHiddenRdp = gid(idconteneurchk).getElementsByTagName('input');

	for (key in tabHiddenRdp){
		if (tabHiddenRdp[key].id) {
			if (tabHiddenRdp[key].id.indexOf(sufidhidden)!=-1) {
				fullIdImg = sufidchk + tabHiddenRdp[key].id.substring(tabHiddenRdp[key].id.indexOf('_') + 1);
				
				if (_o.checked) {
					tabHiddenRdp[key].value = 1;
					gid(fullIdImg).src = '/perso/base/picto/chk_checked.gif';
				} else {
					tabHiddenRdp[key].value = 0;
					gid(fullIdImg).src = '/perso/base/picto/chk_normal.gif';
				}
			}
		}
	}
}

function redirPref() {
	if (gid('bredirpref'))
		gid('bredirpref').value=1;
	closeAndFocus();
}

function autoriseTypeDoc(_o, enablewhen) {
	IdTypeSelected = _o.options[_o.selectedIndex].value;
	isdisable = (IdTypeSelected != enablewhen);
	gid('search_typedoc').disabled = isdisable;
}

function openLinkAnalyser(link) {
	window.open(link, "_blank");
}



/* PAP : CI-DESSOUS FONCTIONS POUR DEPLIER/REPLIER LES LISTES DE RMS. */
function tout_plier(){
	gid("tout_plier").style.display="none";
	gid("tout_deplier").style.display="block";
	
	listRow = gid('commonliste').getElementsByTagName('tr');
	for (var i=1; i<listRow.length; i++) {
		plier(i);
	}
} 

function tout_deplier(){
	gid("tout_deplier").style.display="none";
	gid("tout_plier").style.display="block";
	
	listRow = gid('commonliste').getElementsByTagName('tr');
	for (var i=1;i<listRow.length;i++) {
		deplier(i);
	}
} 

function plier(rm){
	if (gid("tr_deplier_"+rm))
		gid("tr_deplier_"+rm).style.display="none";
	if (gid("span_plie_"+rm))
		gid("span_plie_"+rm).style.display="inline";
} 

function deplier(rm){
	//if (isIE)
	//	gid("tr_deplier_"+rm).style.display="block"; 
	//else
	//	gid("tr_deplier_"+rm).style.display="table-row";
	
	if (gid("tr_deplier_"+rm))
		gid("tr_deplier_"+rm).style.display=""
	if (gid("span_plie_"+rm))
		gid("span_plie_"+rm).style.display="none";
} 

/* Pap v1_1 - Recherche avancée, fonction sur le changement de valeur de la combo "type de média"
- la combo "chaine" est grisée si les choix pour la combo multiple "Type de média" sont différents de "Radios et TV"
- la combo "périodicité" n'est utilisable que si un seul type de média sélectionné et qu'il s'agit de "Presse" ou "Radio et TV" */

function RechPap_actionOnChangeTypeMedia(_o, _bkeepSelectedValue) {


	if (_o) {
		isdisableChaine = false;
		isdisablePeriodicite = true;
		isdisableTypePresse = true;
		isdisableDiffusionSupport = true;
		isdisableNiveauDiffusion = false;
		
		isdisableFamille = false;
		isdisableCategorie = false;
		isdisableThema = false;
		isdisablePays = false;
		isdisableTarifPub = false;	
			
        
		nbSelected = 0;
		
		for (i=0; i<_o.length; i++) {
			if (_o[i].selected)
				nbSelected++;
			
			if (_o[i].value == 'RADIO') {
				if (_o[i].selected) {
					isdisableFamille = true;
					isdisableCategorie = true;
					isdisableThema = true;
					isdisablePeriodicite = true;
					isdisablePays = true;
					isdisableTypePresse = true;
					isdisableTarifPub = true;	
					isdisableDiffusionSupport = true;
					isdisableNiveauDiffusion = true;
				} else {
					isdisableChaine = true;
				}
            }
			
			if (_o[i].value == 'PRESSE') {
				if (_o[i].selected) {
					isdisablePeriodicite = false;
					isdisableTypePresse = false;
					RechPap_comboPeriodiciteHandler(true, _bkeepSelectedValue);
				} else {
					RechPap_comboPeriodiciteHandler(false, _bkeepSelectedValue);
				}
			}
			
			if (_o[i].value == 'WEB' || _o[i].value == 'PRESSE')   {
				if (_o[i].selected)
					isdisableDiffusionSupport = false;
			}
			
			if (_o[i].value == 'WEB' && _o[i].selected) {
				isdisableNiveauDiffusion = true;
			}
		}
        
		if (!isdisablePeriodicite && nbSelected>1)
			isdisablePeriodicite = true;

		if (!_bkeepSelectedValue && isdisableChaine) {
			gid("search_chaine").options[0].selected = true;
        }
		gid('search_chaine').disabled = isdisableChaine;
		
        
        
		if (!_bkeepSelectedValue && isdisablePeriodicite) {
			gid("search_periodicite").options[0].selected = true;
        }
		gid('search_periodicite').disabled = isdisablePeriodicite;
        
        
        
        if (!_bkeepSelectedValue && isdisableTypePresse) {
			gid("search_typepresse").options[0].selected = true;
        }
		gid('search_typepresse').disabled = isdisableTypePresse;
   
   
		if (!_bkeepSelectedValue && isdisableNiveauDiffusion)
			gid("search_niveaudiffusion").options[0].selected = true;
		gid('search_niveaudiffusion').disabled = isdisableNiveauDiffusion;
		
   
        if (!_bkeepSelectedValue && isdisableDiffusionSupport) {
			gid("search_combo_diffusion").options[0].selected = true;
			gid('search_diffusion').value = '';
			gid('search_diffusion_entre1').value = '';
			gid('search_diffusion_entre2').value = '';
        }
		gid('search_combo_diffusion').disabled = isdisableDiffusionSupport;      
		gid('search_diffusion').disabled = isdisableDiffusionSupport; 
		gid('search_diffusion_entre1').disabled = isdisableDiffusionSupport; 
		gid('search_diffusion_entre2').disabled = isdisableDiffusionSupport; 
     
     	
     
     
     	if (!_bkeepSelectedValue && isdisableFamille) {
			gid("search_famille").options[0].selected = true;
        }
		gid('search_famille').disabled = isdisableFamille;
   
     	if (!_bkeepSelectedValue && isdisableCategorie) {
			gid("search_categorie").options[0].selected = true;
        }
		gid('search_categorie').disabled = isdisableCategorie;
		
     	if (!_bkeepSelectedValue && isdisableThema) {
			gid("search_thema").options[0].selected = true;
        }
		gid('search_thema').disabled = isdisableThema;
		
		if (!_bkeepSelectedValue && isdisablePays) {
			gid("search_pays").options[0].selected = true;
        }
		gid('search_pays').disabled = isdisablePays;
		
 		if (!_bkeepSelectedValue && isdisableTarifPub) {
			gid("search_combo_tarifpub").options[0].selected = true;
			gid('search_tarifpub').value = '';
			gid('search_tarifpub_entre1').value = '';
			gid('search_tarifpub_entre2').value = '';
        }
		gid('search_combo_tarifpub').disabled = isdisableTarifPub;      
		gid('search_tarifpub').disabled = isdisableTarifPub; 
		gid('search_tarifpub_entre1').disabled = isdisableTarifPub; 
		gid('search_tarifpub_entre2').disabled = isdisableTarifPub; 
     
	}
}

/* Pap v1_1 - Recherche avancée, Gestion de la combo périodicité. Pour les types de presse on retire "jours de semaine" et "week end" */
function RechPap_comboPeriodiciteHandler(p_isTypePresseSelected, _bkeepSelectedValue) {
	if (!arraySavedPeriodicite && !arraySavedPeriodiciteTypePresse) {
		var retAllPeriodicite = new Array();
		var retPeriodiciteTypePresse = new Array();
		
		var iAllPeriodicite = 0;
		var iPeriodiciteTypePresse = 0;
		
		if (gid("search_periodicite")) {
			tabOptions = gid("search_periodicite").getElementsByTagName('option');
			for (var i=1; i<tabOptions.length; i++) {
				var tmpKeyValue = new Array(tabOptions[i].value, tabOptions[i].text);
				if (tabOptions[i].value == "Jours de la semaine" || tabOptions[i].value == "Week-End") {
					retAllPeriodicite[iAllPeriodicite] = tmpKeyValue;
					
				} else {
					retAllPeriodicite[iAllPeriodicite] = tmpKeyValue;
					retPeriodiciteTypePresse[iPeriodiciteTypePresse] = tmpKeyValue;
					iPeriodiciteTypePresse++;
				}
				iAllPeriodicite++;
			}
		}
	
		arraySavedPeriodicite = retAllPeriodicite;
		arraySavedPeriodiciteTypePresse = retPeriodiciteTypePresse;
	}
	
	var savedSelectedValue = gid("search_periodicite").options[gid("search_periodicite").selectedIndex].value;
	videCombo("search_periodicite", false);

	_arrayValues = (p_isTypePresseSelected) ? arraySavedPeriodiciteTypePresse : arraySavedPeriodicite;
	for (var i=0; i<_arrayValues.length; i++) {
		tmpValue = _arrayValues[i];
		key = tmpValue[0];
		value = tmpValue[1];
		bSelected = (_bkeepSelectedValue && savedSelectedValue == key) ? true : false;
		ajouterOption(gid("search_periodicite"), key , value, bSelected);
	}
}



/* Pap v1_1 - Recherche avancée, renvoie un tableau contenant les données d'un champ de type select
Utilisé pour sauvegarder les données du select avant mise à jour de ses valeurs */
function initTabFromSelectOptions(_idSelectToSave) {
	var ret = new Array();
	if (gid(_idSelectToSave)) {
		tabOptions = gid(_idSelectToSave).getElementsByTagName('option');
		for (var i=1; i<tabOptions.length; i++) {
			var tmpKeyValue = new Array(tabOptions[i].value, tabOptions[i].text);
			ret[i-1] = tmpKeyValue;
		}
	}
	return ret;
}

/* Pap v1_1 - Recherche avancée, ajout d'une option dans une combo box */
function ajouterOption(_gidSelect, _key, _text, _bselected) {
	nouvel_element = new Option(_text,_key,false,_bselected);
	_gidSelect.options[_gidSelect.length] = nouvel_element;
}

/* Pap v1_1 - Recherche avancée, vidage d'une combo, on laisse l'option "--Tous--" (d'où indice 1 et pas 0) */
function videCombo(_idCombo, _bDisabled) {
	tabOptions = gid(_idCombo);
	tabOptions.options[0].selected = true;
	while (tabOptions.length > 1) {
		tabOptions.options[1] = null;
	}
	tabOptions.disabled = _bDisabled;
}

/* Pap v1_1 - Recherche avancée, mise à jour d'une combo en fonction d'un choix dans une autre combo (ex : Famille <> Catégorie, ...),  */
function updateAvailableOptions(_idComboToChange, _selectedIdParent, _arrayValues, _bkeepSelectedValue) {
	// Récupération de la valeur sélectionnée pour la combo qu'il faut mettre à jour
	var savedSelectedValue = gid(_idComboToChange).options[gid(_idComboToChange).selectedIndex].value;
	
	/* On commence par vider la combo Catégorie avant de la remplir avec les catégories correspondantes à la famille sélectionnée  */
	videCombo(_idComboToChange, false);

	for (var i=0; i<_arrayValues.length; i++) {
		tmpValue = _arrayValues[i];
		key = tmpValue[0];
		value = tmpValue[1];
		
		splittedId = key.split('_');

		if (_selectedIdParent == splittedId[0]) {
			bSelected = (_bkeepSelectedValue && savedSelectedValue == key) ? true : false;
			ajouterOption(gid(_idComboToChange), key , value, bSelected);
		}
	}
}	

/* Pap v1_1 - Recherche avancée, fonction sur le changement de valeur de la combo "Famille", impacte la combo "Catégorie" 
le paramètre _bkeepSelectedValue permet après mise à jour de réinitialiser la valeur selected avec celle qui était active avant mise à jour de la combo.
Utile lors du rechargement de la page la recherche avancée depuis Affiner. */
function RechPap_actionOnChangeFamille(_o, _bkeepSelectedValue) {
	if (_o) {
		if (_o.options[_o.selectedIndex].value == '') {
			videCombo("search_categorie", true);
			videCombo("search_thema", true);
		} else
			updateAvailableOptions("search_categorie", _o.options[_o.selectedIndex].value, arraySavedCategories, _bkeepSelectedValue);
	}
}

/* Pap v1_1 - Recherche avancée, fonction sur le changement de valeur de la combo "Catégorie", impacte la combo "Thématique" 
_bkeepSelectedValue - Voir "RechPap_actionOnChangeFamille" */
function RechPap_actionOnChangeCategorie(_o, _bkeepSelectedValue) {
	if (_o) {
		if (_o.options[_o.selectedIndex].value == '')
			videCombo("search_thema", true);
		else {
			splittedId = _o.options[_o.selectedIndex].value.split('_');
			IdCategory = splittedId[1];
			updateAvailableOptions("search_thema", IdCategory, arraySavedThematique, _bkeepSelectedValue);
		}
	}
}

/* Pap v1_1 - Recherche avancée, fonction sur le changement de valeur de la combo "Niveau diffusion", impacte la combo "Département"
Si le niveau de diffusion est différent de régional (ie IdNiveauDiffusion = 2), la combo département est grisée.
_bkeepSelectedValue - Voir "RechPap_actionOnChangeFamille" */
function RechPap_actionOnChangeNiveaudiffusion(_o, _bkeepSelectedValue) {
	if (_o) {
		ComboDept = gid("search_dept");
		if (!_bkeepSelectedValue)
			ComboDept.options[0].selected = true;
		ComboDept.disabled = (_o.options[_o.selectedIndex].value != '2');
	}
}

/* Pap v1_1 - paramétrage du thème, affiche le plan de classement */
function managePlanClassement(_show) {
	if (_show) {
		gid('classement_plan').style.display = "block";
		gid('search_combo_tarifpub').style.display = "none";
		gid('search_combo_diffusion').style.display = "none";
	} else {
		gid('classement_plan').style.display = "none";
		gid('search_combo_tarifpub').style.display = "inline";
		gid('search_combo_diffusion').style.display = "inline";
	}
}

function updateSelectClassement(hiddenF, textF, divName){
	idselected = '';
	
	tabOptions = document.getElementsByName('selectclassement');
	for (var i=0; i<tabOptions.length; i++) {
		if (tabOptions[i].checked)
			idselected = tabOptions[i].value;
	}
	
	if (idselected == '') {
		doAction('classement','select','err_noidselect',-1);
	} else {
		listClassement = window.opener.document.getElementById("listidclassement");
		if (listClassement) {
			if (listClassement.value == "")
				newlist = idselected;
			else
				newlist = listClassement.value + "," + idselected;
				
			window.opener.document.getElementById("listidclassement").value = newlist;
			window.opener.document.getElementById("idstep").value = "refreshListClassement";
			window.opener.document.getElementById('idformulaire_page').submit();
		}

		window.close();
	}
}

function validateVisibilitySwitchableClassements(_o) {
	
	if (gid('table_switchable_classements')) {
		IdProfil = _o.options[_o.selectedIndex].value;
	
		if (IdProfil == 9 || IdProfil == 10 || IdProfil == 12)
			gid('table_switchable_classements').style.display = "block";
		else
			gid('table_switchable_classements').style.display = "none";
	}
}

