/* ------------     CONTACT     --------------------------- */

function change_Check_Value(){
	if(document.contact.choix1.checked==true){
		document.contact.souhait1.value='true';
	}
	if(document.contact.choix2.checked==true){
		document.contact.souhait2.value='true';
	}
	if(document.contact.choix3.checked==true){
		document.contact.souhait3.value='true';
	}
	if(document.contact.choix4.checked==true){
		document.contact.souhait4.value='true';
	}
}

var checkmail = /^[\w\-]+(\.[\w\-]+)*@[\w\-]+(\.[\w\-]+)*\.[\w\-]{2,}$/;

function verifMail(email) {
    verif=checkmail.test(email)
    if(verif){
		return true;
	}else{
		return false;
	}
}

function verif_Form_contact(){
	var email = document.contact.email.value; 
	
	if(document.contact.nom.value=="" ||  document.contact.prenom.value=="" || document.contact.email.value=="" || document.contact.message.value==""){
		alert("Vous n'avez pas rempli tous les champs obligatoire");
	}else{
		if(!verifMail(email)) {
			alert("L'adresse email est incorrecte");
		}else{
			document.contact.submit();
		}

	}
}


function verif_Divers(){
	
		var xhr = getXhr();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				leselect = xhr.responseText;
				if(leselect=="true"){
					verif_Form_contact()
				}else{
					alert("Le code Anti-Spam saisi ne correspond pas au code proposé");
				}
			}
		}
	
		divers=document.contact.divers.value;
		
		xhr.open("POST","captcha/verif_divers.php?SID",true);
		
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		xhr.send("divers="+divers);
}




function popupprint(idform){
	window.open('print_formation.php?idform='+idform+'','impression','width=730,height=600,top=150,left=150,toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes,directories=no');
}

function ancreTheme(){
	window.location.href='#theme'+document.getElementById('theme').value;
}

function tailleCalqueMenu() {

	if(document.getElementById('contenu').clientHeight <= 440){
		document.getElementById('contenu').style.height='440px';
	}
	
	// Agrandissement du menu, si (hauteur de contenu + 45px) sup à hauteur minimale de 486px;

	if(document.getElementById('contenu').clientHeight + 45 > 486){
		document.getElementById('menu').style.height=(document.getElementById('contenu').clientHeight + 45)+'px';
	}

}

function tailleCalqueMenuAccueil() {

	if(document.getElementById('encart2').clientHeight <= 200){
		document.getElementById('encart2').style.height='200px';
	}
	
	if(document.getElementById('contenu_accueil').clientHeight <= 579){
		document.getElementById('contenu_accueil').style.height='579px';
	}
	

	if(document.getElementById('encart2').clientHeight > 200){
		document.getElementById('menu').style.height=(220 + 10 + document.getElementById('encart2').clientHeight + 45)+'px';
	}

}


/* *******************************************************************/
/* ********************      ADMINISTRATION      *********************/
/* *******************************************************************/


// Ce n'est pas tout a fait de l'AJAX : Asynchronous JavaScript And XML , mais juste de l'utilisation de XmlHttpRequest car il n'y a pas de XML
// Sert à retourner des données de la base sans recharger la page

function getXhr(){
	var xhr = null;
	if(window.XMLHttpRequest){ // Firefox et autres
		xhr = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP"); // ICI
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}else{ // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		xhr = false;
	}
	return xhr
}


function afficheSousRub(){
	if(document.getElementById('rub').value=="1"){
		document.getElementById('ligne_vide_1').style.display='none';
		document.getElementById('ligne_bloc_haut').style.display='none';
	}else{
		document.getElementById('ligne_vide_1').style.display='';
		document.getElementById('ligne_bloc_haut').style.display='';
	}
	
	if(document.getElementById('rub').value=="6"){
		document.getElementById('ligne_srub').style.display='';
	}else{
		document.getElementById('ligne_srub').style.display='none';
		document.getElementById('srub').options.selectedIndex='0';
	}
	
	if( (document.getElementById('rub').value=="6" && document.getElementById('srub').value=="1") || document.getElementById('rub').value=="7" || document.getElementById('rub').value=="9"){						// Adresse utile et Contact
		document.getElementById('ligne_vide_2').style.display='none';
		document.getElementById('ligne_titre_2').style.display='none';
		document.getElementById('ligne_bloc_central').style.display='none';
	}else{
		document.getElementById('ligne_vide_2').style.display='';
		document.getElementById('ligne_titre_2').style.display='';
		document.getElementById('ligne_bloc_central').style.display='';
	}
}

function refresh(lurl){
	window.opener.location.href=lurl;
}

function verifFormTexte(){
	if(document.getElementById('rub').value!="0"){
		if(document.getElementById('rub').value==6){
			if(document.getElementById('srub').value!="0"){
				document.oForm.submit();
			}else{
				alert("Vous devez selectionnez la sous-rubrique concernée");
			}
		}else{
			document.oForm.submit();
		}
	}else{
		alert("Vous devez selectionnez la rubrique concernée");
	}
}



/* *************************************************** LIENS UTILES ********************************************** */

function verif_lienForm(){
	if(document.getElementById('idtheme').options.selectedIndex>0){
		if(document.lienForm.intitule.value!=""){
			//if(document.lienForm.url.value!=""){
				//if(document.lienForm.url_home.value!=""){
						document.lienForm.submit();
				//}else{
					//alert("Vous n'avez pas saisi l'adresse du site");
				//}
			//}else{
				//alert("Vous n'avez pas saisi l'adresse sur laquelle pointe le lien");
			//}
		}else{
			alert("Vous n'avez pas saisi l'intitulé du lien");
		}
	}else{
		alert("Vous n'avez pas sélectionné le thème associé au lien");
	}
	
}

function verif_themeForm(){
	if(document.getElementById('idtheme').options.selectedIndex>0){
		if(document.baForm.lequeltheme.value!=""){
			document.baForm.submit();
		}else{
			alert("Vous n'avez pas saisi l'intitulé du thème");
		}
	}else{
		alert("Vous n'avez pas sélectionné de thème");
	}
	
}	

function alimenteChamp(){
	document.baForm.lequeltheme.value=document.baForm.idtheme.options[document.baForm.idtheme.selectedIndex].text;
	i=document.baForm.idtheme.options[document.baForm.idtheme.selectedIndex].value;
}

function confirm(page,width,height){
	window.open(page,'confirmation','width='+width+',height='+height+',top='+screen.height/2+',left='+screen.width/4+',toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=no,directories=no');
}

function rafraichir(lurl){
	window.opener.location.href=lurl;
}

/* *************************************************** FORMATION INTRA ********************************************** */

function enregistreOrdreForm(id_form){
	
		var xhr = getXhr();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				leselect = xhr.responseText;
				document.location.href='index.php?lien=12&smenu=3';
			}
		}
	
		xhr.open("POST","contenu/formation/formation_valide.php?quelleaction=4",true);
		
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		ordre=document.getElementById('ordre'+id_form).value;
		
		xhr.send("idformation="+id_form+"&ordre="+ordre);
}

function verifFormForm(){
	if(document.oForm.chapitre.value!="0"){
		if(document.oForm.titre1.value!=""){
			document.oForm.submit();
		}else{
			alert("Vous n'avez pas saisi le titre de la formation");
		}
	}else{
		alert("Vous n'avez pas selectionné le chapitre");
	}
}

function verif_chapitreForm(){
	if(document.getElementById('idchapitre').options.selectedIndex>0){
		if(document.baForm.lequelchapitre.value!=""){
			document.baForm.submit();
		}else{
			alert("Vous n'avez pas saisi l'intitulé du chapitre");
		}
	}else{
		alert("Vous n'avez pas sélectionné de chapitre");
	}
	
}	


function alimenteChampForm(){
	document.baForm.lequelchapitre.value=document.baForm.idchapitre.options[document.baForm.idchapitre.selectedIndex].text;
	i=document.baForm.idchapitre.options[document.baForm.idchapitre.selectedIndex].value;
}




/* *************************************************** DOCUMENTATION ********************************************** */

function verifDoc(nbre){
	var coche='non';

	if(document.oForm.titre_doc.value!=""){
		if(nbre>1){
			for(i=0;i<nbre;i++){
				if(document.oForm.type[i].checked==true){
					coche='oui';
				}
			}
		}else{
			if(document.oForm.type.checked==true){
				coche='oui';
			}
		}
		
		if(coche=='oui'){
			document.oForm.submit();
		}else{
			alert("Vous n'avez pas cochez le thème du document");
		}
		
	}else{
		alert("Vous n'avez pas saisi le titre du document");
	}
}

function rempli_menu_doc(id_type){
	
		var xhr = getXhr();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				leselect = xhr.responseText;
				
				/*
					if(document.all){	//IE
					
						document.getElementById('contenant_id_doc').innerHTML = leselect;
					
					}else{	// DOM
					
						// pour vider le contenu de "contenant_id_doc"
						while(document.getElementById('contenant_id_doc').firstChild) document.getElementById('contenant_id_doc').removeChild(document.getElementById('contenant_id_doc').firstChild);
		
						
						// pour créer le menu déroulant
						var unSelect = document.createElement("select");
						unSelect.setAttribute("onchange","document.miForm.submit();");
						unSelect.setAttribute("name","id_doc");
						unSelect.setAttribute("id","id_doc");
						
						// gérer les options dynamiquement en AJAX : à FAIRE
						var oOption1 = document.createElement("option");
						oOption1.value = "5";
						oOption1.text = "Sélectionnez le fichier à modifier";
						
						var oOption2 = document.createElement("option");
						oOption2.value = "1";
						oOption2.text = "unTexte";
					

						unSelect.appendChild(oOption1);
						unSelect.appendChild(oOption2);
						document.getElementById('contenant_id_doc').appendChild(unSelect);
						
				}
				
				*/
				
				document.getElementById('contenant_id_doc').innerHTML = leselect;
				
			}
		}
	
		xhr.open("POST","contenu/doc_tech/listes/generation_menu_doc.php",true);
		
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		xhr.send("id_type="+id_type);
}

/* ************************* ACTIONS EN ESSONNE  ********************************************** */

function verifFormAction(){

	if(tinyMCE.getContent("details_action")!=""){
		document.oForm.submit();
	}else{
		alert('Vous n\'avez pas saisi le texte lié à l\'action');
	}	

}

/* *******************************************************************/
/* ****************      FONCTIONS DREAMWEAVER      ******************/
/* *******************************************************************/


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);