/* 
	ED - 12.07.2006
	Fonction AddEvent de John Resig 
	http://ejohn.org/projects/flexible-javascript-events/
*/
 function addEvent( obj, type, fn ) {
   if ( obj.attachEvent ) {
     obj['e'+type+fn] = fn;
     obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
     obj.attachEvent( 'on'+type, obj[type+fn] );
   } else
     obj.addEventListener( type, fn, false );
 }
 
 function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

/* Affichage d'un calendrier pour les formulaires avec recherche par date */
function affiche_calendrier(nom, form) {
	if (document.getElementById) {
		document.write("<a href=\"#\" onclick=\"window.open('/adminsite/calendrier/calendrierjs.html?champ=" + nom + "&form=" + form +"', 'calendrier', 'width=135, height=138, toolbar=no, location=no, status=yes, resizable=yes'); return false;\"><img src=\"/images/calendrier.png\" border=\"0\"  alt=\"choisir une date\"></a>");
	}
}

/* Activation du service selectionné dans la liste des services */
function activerService() {

	var index = window.document.getElementById('selectservices').selectedIndex;
	if( index == 0)
		return;
	var url = window.document.getElementById('selectservices').options[index].value;

	/* Analyse target */
	var indexTarget = url.indexOf(':');
	if (indexTarget > 0) {
		var target =  url.substring(0,indexTarget);
		url = url.substring(indexTarget + 1);
		window.open(url, target);
	} else {
		window.location.href=url.substring(1);
	}
}

/* Affichage d'une image dans une popup */
function afficheImage(source) {
	// Ouverture du pop-up
	window.open(source,'pop','status=no,directories=no,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes');
}

function atteindreAncre(ancre) {
	if (ancre != 'null'){
		window.location.href += '#' + ancre;
	}
}

/* Fonction utilisée dans la recherche avancée pour réinitialiser les formulaires */
function viderFormulaire(criteres) {
	criteres = criteres.split(";");
	var champReinit = "";
	var valeurChamp = "";
	
	for (var i=0; i < (criteres.length); i++) {
		champReinit = eval("document.forms['recherche_avancee']." + criteres[i].substring(0, criteres[i].indexOf("=")));
		valeurChamp = criteres[i].substring(criteres[i].indexOf("=")+1);
		
		if (champReinit) {
			
			var sType = champReinit.type;
			//bouton radio
			if (!sType) {
				for (var i = 0; i < champReinit.length; i++)
					champReinit[i].checked = false;
			} 
			//checkbox
			else if(sType == 'checkbox')
				champReinit.checked = false;
			//autres
			else
			champReinit.value = valeurChamp;
		}
	}
}


/* Fonction permettant d'afficher le bouton imprimer (donc uniquement si javascript est actif) */
function afficherBoutonImprimer(intitule) {
	document.write('<li id="imprimer">');
	document.write('<span onclick="window.print(); return false;">' + intitule + '</span>');
	document.write('</li>');
}


/* Fonction permettant d'intervertir l'id d'un élément avec un autre */
function switchId(ancienIdItem, nouvelIdItem) {
	var itemSwitch = window.document.getElementById(ancienIdItem);
	
	if (itemSwitch != null) {
		itemSwitch.id = nouvelIdItem;
	}
}


/* Fonctions Eurodoc*/

var rech_suppDivShown = false;
var rech_doctDivShown = false;

/* Fonction permettant d'afficher ou masquer les criteres supplementaires */

function showOrHideCriteria(){

	var rech_suppDiv = document.getElementById('rech_supp');
	
	var linkA = document.getElementById('linkCriteriaA');
	var linkB = document.getElementById('linkCriteriaB');

	if (rech_suppDivShown){
		rech_suppDiv.style.display='none';
		linkA.style.display='inline';
		linkB.style.display='none';
		//linkA.value = "Plus de critères";
	}
	else{
		rech_suppDiv.style.display='block';
		linkA.style.display='none';
		linkB.style.display='inline';
		//linkA.value = "Moins de critères";
	}
	
	rech_suppDivShown = !rech_suppDivShown;
}

function showOrEtudiantOrDoctorant(){

	var rech_etudDiv = document.getElementById('rech_etud');
	var rech_doctDiv = document.getElementById('rech_doct');
	var inputDoct = document.getElementById('type_pop')
	
	var linkDoctorant = document.getElementById('linkDoctorant');
	var linkEtudiant = document.getElementById('linkEtudiant');
	var inputDoct = document.getElementById('type_pop');

	if (rech_doctDivShown){
		rech_etudDiv.style.display='block';	
		rech_doctDiv.style.display='none';	
		linkDoctorant.style.display='inline';
		linkEtudiant.style.display='none';
		//linkA.value = "Plus de critères";
		inputDoct.value="";
	}
	else{
		rech_etudDiv.style.display='none';	
		rech_doctDiv.style.display='block';	
		linkDoctorant.style.display='none';
		linkEtudiant.style.display='inline';
		//linkA.value = "Moins de critères";
		inputDoct.value="doctorant";
	}
	
	rech_doctDivShown = !rech_doctDivShown;
}

function showOrHideDoctorant(){

	var rech_etudDiv = document.getElementById('rech_etud');
	var rech_doctDiv = document.getElementById('rech_doct');	
	var inputDoct = document.getElementById('type_pop');
	
	var linkA = document.getElementById('a_rech_doct');

	if (rech_doctDivShown){
		rech_etudDiv.style.display='block';	
		rech_doctDiv.style.display='none';
		linkA.firstChild.nodeValue = "Rechercher sur doctorants";
		inputDoct.value="";
	}
	else{
		rech_etudDiv.style.display='none';	
		rech_doctDiv.style.display='block';
		linkA.firstChild.nodeValue = "Rechercher sur etudiants";
		inputDoct.value="doctorant";
	}
	
	rech_doctDivShown = !rech_doctDivShown;
}

function showMessageFieldEurodoc(typeAide, f1, f2) {
	showMessageFieldEurodoc2(typeAide, f1, f2, '');
}

function showMessageFieldEurodoc2(typeAide, f1, f2, form) {
	numToolbox = '';
	nomForm = form;
	field1 = f1;
	field2 = f2;
	fieldRequete = '';
	texte = '';
	nomApplet = '';
	// Type d'insertion (liste)
	typeInsertion = '';

	//AM 200309 : L'arbre des structures doit prendre en compte la langue courante dans le front office

	   	var indexSlash1 = typeAide.indexOf('/');
		var lg = '';
		var filtre = '';
		if (indexSlash1 != -1)
		{
			var indexSlash2 = typeAide.indexOf('/', indexSlash1 + 1);
			if (indexSlash2 != -1)
			{
				lg = typeAide.substring(indexSlash1 + 1, indexSlash2);
				filtre = typeAide.substring(indexSlash2 + 1);
			}
			else
			{
				lg = typeAide.substring(indexSlash1 + 1);
			}
		}
//		alert("'/adminsite/menu/menu.jsp?MODE=STRUCTURE&LANGUE='+lg+'&FILTRE='+filtre, 'menu2', 'scrollbars=yes, resizable=yes, status=yes, width=600, height=400, top=320, left=320'");
//		alert("'/adminsite/menu/menu.jsp?MODE=GROUPE&CODE='+value, 'menu2', 'scrollbars=yes, resizable=yes, status=yes, width=600, height=400, top=320, left=320'");
		//sList = window.open('/adminsite/menu/menu.jsp?MODE=GROUPE&CODE='+value, 'menu2', 'scrollbars=yes, resizable=yes, status=yes, width=600, height=400, top=320, left=320');
	//sList = window.open('/adminsite/menu/menu.jsp?MODE=STRUCTURE&LANGUE='+lg+'&FILTRE='+filtre, 'menu2', 'scrollbars=yes, resizable=yes, status=yes, width=600, height=400, top=320, left=320');
//	alert('/adminsite/menu/menu_diplomes.jsp?MODE=GROUPE&CODE=ETUDIANTS_ORACLE&LANGUE='+lg+'&FILTRE='+filtre, 'menu2', 'scrollbars=yes, resizable=yes, status=yes, width=600, height=400, top=320, left=320');
	sList = window.open('/adminsite/menu/menu_diplomes.jsp?MODE=GROUPE&CODE=ETUDIANTS_ORACLE&LANGUE='+lg+'&FILTRE='+filtre, 'menu2', 'scrollbars=yes, resizable=yes, status=yes, width=600, height=400, top=320, left=320');

}
