/* Formulaire de contact */ 

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.email.value=="" || document.contact.message.value==""){
		alert("Vous n'avez pas rempli tous les champs obligatoires");
	}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 tailleCalqueContenu() {

	if(screen.height>768){
		if(document.all) {
			var haut = (document.body.clientHeight);
		}else{
			var haut = (window.innerHeight);
		}
		
		if(haut>597){
			document.getElementById("menu_gauche").style.height=(haut-149)+'px';
			document.getElementById("contenu").style.height=(haut-189)+'px';
			document.getElementById("conteneur").style.height=(haut)+'px';
		}
	}

}

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 rafraichit(lurl){
	window.opener.location.href=lurl;
}

function popupResizable(page,width,height,top,left){
	window.open(page,'fenetre','width='+width+',height='+height+',top='+top+',left='+left+',toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes,directories=no');
}

function ouvrePopup(page,title,width,height,top,left){
	window.open(page,title,'width='+width+',height='+height+',top='+top+',left='+left+',toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=no,directories=no');
}

function transmettre(url){
	window.opener.location.href=url;
}


/***     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 rempli_menu_doc(id_type){
	
		var xhr = getXhr();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				leselect = xhr.responseText;
				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);
}


/* ACTUALITES */

function rempli_menu_doc_actu(id_type,lequel){
	
		var xhr = getXhr();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				leselect = xhr.responseText;
				document.getElementById('contenant_id_doc'+lequel).innerHTML = leselect;
				
			}
		}
	
		xhr.open("POST","contenu/actualites/listes/generation_menu_doc.php",true);
		
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		xhr.send("id_type="+id_type+"&lequel="+lequel);
}

function rempli_champ_url(lequel){
	
		var xhr = getXhr();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				url = xhr.responseText;
				document.getElementById('lien'+lequel).value=url;
			}
		}
	
		xhr.open("POST","contenu/actualites/listes/generation_url.php",true);
		
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		id_doc=document.getElementById('id_doc'+lequel).value;
		
		xhr.send("id_doc="+id_doc+"&lequel="+lequel);
}



function afficheLigneFormulaire(){
	if(document.getElementById('type_actu').options.selectedIndex==1){
		
		document.getElementById('ligne_espace').style.display='';
		
		document.getElementById('ligne_libelle1').style.display='';
		document.getElementById('ligne_libelle2').style.display='none';
		
	
		document.getElementById('ligne_choix1').style.display='none';
		document.getElementById('ligne_type_doc1').style.display='none';
		document.getElementById('ligne_doc1').style.display='none';
		document.getElementById('ligne_lien1').style.display='';
		
		document.getElementById('ligne_choix2').style.display='none';
		document.getElementById('ligne_type_doc2').style.display='none';
		document.getElementById('ligne_doc2').style.display='none';
		document.getElementById('ligne_lien2').style.display='none';
		
		
		document.getElementById('ligne_details').style.display='none';
		
		
	}else if(document.getElementById('type_actu').options.selectedIndex==2){
		
		document.getElementById('ligne_espace').style.display='';
		
		document.getElementById('ligne_libelle1').style.display='';
		
		document.getElementById('ligne_choix1').style.display='';
		document.getElementById('ligne_lien1').style.display='';
		document.getElementById('ligne_libelle2').style.display='';
		document.getElementById('ligne_choix2').style.display='';
		document.getElementById('ligne_lien2').style.display='';
		
		document.getElementById('ligne_details').style.display='none';
	
	}else if(document.getElementById('type_actu').options.selectedIndex==3){

		document.getElementById('ligne_espace').style.display='';
		
		document.getElementById('ligne_libelle1').style.display='';
		document.getElementById('ligne_libelle2').style.display='none';
		
	
		document.getElementById('ligne_choix1').style.display='none';
		document.getElementById('ligne_type_doc1').style.display='none';
		document.getElementById('ligne_doc1').style.display='none';
		document.getElementById('ligne_lien1').style.display='none';
		
		document.getElementById('ligne_choix2').style.display='none';
		document.getElementById('ligne_type_doc2').style.display='none';
		document.getElementById('ligne_doc2').style.display='none';
		document.getElementById('ligne_lien2').style.display='none';
		
		
		document.getElementById('ligne_details').style.display='';
		
	}else if(document.getElementById('type_actu').options.selectedIndex==4){
		
		document.getElementById('ligne_espace').style.display='none';
		
		document.getElementById('ligne_libelle1').style.display='none';
		document.getElementById('ligne_libelle2').style.display='none';
		
	
		document.getElementById('ligne_choix1').style.display='none';
		document.getElementById('ligne_type_doc1').style.display='none';
		document.getElementById('ligne_doc1').style.display='none';
		document.getElementById('ligne_lien1').style.display='none';
		
		document.getElementById('ligne_choix2').style.display='none';
		document.getElementById('ligne_type_doc2').style.display='none';
		document.getElementById('ligne_doc2').style.display='none';
		document.getElementById('ligne_lien2').style.display='none';
		
		
		document.getElementById('ligne_details').style.display='none';
	
	}
}

function afficheValueFormulaire(){
	if(document.getElementById('type_actu').options.selectedIndex==1){
		
		document.getElementById('libelle_lien1').value='';
		document.getElementById('libelle_lien2').value='';
		
	
		document.oForm.choix1[0].checked=true;
		document.oForm.type1.checked=0;
		//document.oForm.type1[0].checked=0;
		//document.oForm.type1[1].checked=0;
		//document.oForm.type1[2].checked=0;
		//document.oForm.type1[3].checked=0;
		document.getElementById('id_doc1').selectedIndex=0;
		document.getElementById('lien1').value='';
		
		document.oForm.choix2[0].checked=true;
		document.oForm.type2.checked=0;
		//document.oForm.type2[0].checked=0;
		//document.oForm.type2[1].checked=0;
		//document.oForm.type2[2].checked=0;
		//document.oForm.type2[3].checked=0;
		document.getElementById('id_doc2').selectedIndex=0;
		document.getElementById('lien2').value='';
		
		document.getElementById('details_actu').value='';
		
	}else if(document.getElementById('type_actu').options.selectedIndex==2){
		
		document.getElementById('libelle_lien1').value='';
		document.getElementById('lien1').value='';
		
		document.getElementById('details_actu').value='';
	
	}else if(document.getElementById('type_actu').options.selectedIndex==3){

		document.getElementById('ligne_espace').style.display='';
		
		document.getElementById('ligne_libelle1').style.display='';
		document.getElementById('libelle_lien1').value='Lire la suite';
		document.getElementById('libelle_lien2').value='';
		
	
		document.oForm.choix1[0].checked=true;
		document.oForm.type1.checked=0;
		//document.oForm.type1[1].checked=0;
		//document.oForm.type1[2].checked=0;
		//document.oForm.type1[3].checked=0;
		document.getElementById('id_doc1').selectedIndex=0;
		document.getElementById('lien1').value='';
		
		document.oForm.choix2[0].checked=true;
		document.oForm.type2.checked=0;
		//document.oForm.type2[0].checked=0;
		//document.oForm.type2[1].checked=0;
		//document.oForm.type2[2].checked=0;
		//document.oForm.type2[3].checked=0;
		document.getElementById('id_doc2').selectedIndex=0;
		document.getElementById('lien2').value='';
		
	}else if(document.getElementById('type_actu').options.selectedIndex==4){
		
		document.getElementById('libelle_lien1').value='';
		document.getElementById('libelle_lien2').value='';
		
	
		document.oForm.choix1[0].checked=true;
		document.oForm.type1.checked=0;
		//document.oForm.type1[0].checked=0;
		//document.oForm.type1[1].checked=0;
		//document.oForm.type1[2].checked=0;
		//document.oForm.type1[3].checked=0;
		document.getElementById('id_doc1').selectedIndex=0;
		document.getElementById('lien1').value='';
		
		document.oForm.choix2[0].checked=true;
		document.oForm.type2.checked=0;
		//document.oForm.type2[0].checked=0;
		//document.oForm.type2[1].checked=0;
		//document.oForm.type2[2].checked=0;
		//document.oForm.type2[3].checked=0;
		document.getElementById('id_doc2').selectedIndex=0;
		document.getElementById('lien2').value='';
		
		document.getElementById('details_actu').value='';
	
	}
}

function suppLigneFormulaire(lequel){

	if(lequel==1){
		document.oForm.type1.checked=0;
		//document.oForm.type1[0].checked=0;
		//document.oForm.type1[1].checked=0;
		//document.oForm.type1[2].checked=0;
		//document.oForm.type1[3].checked=0;
		document.getElementById('ligne_type_doc1').style.display='none';
		document.getElementById('id_doc1').selectedIndex=0;
		document.getElementById('ligne_doc1').style.display='none';
		document.getElementById('lien1').value='';
	}else if(lequel==2){
		document.oForm.type2.checked=0;
		//document.oForm.type2[0].checked=0;
		//document.oForm.type2[1].checked=0;
		//document.oForm.type2[2].checked=0;
		//document.oForm.type2[3].checked=0;
		document.getElementById('ligne_type_doc2').style.display='none';
		document.getElementById('id_doc2').selectedIndex=0;
		document.getElementById('ligne_doc2').style.display='none';
		document.getElementById('lien2').value='';
	}

}

function verifFormActu(){

	if(document.oForm.date_debut.value!=""){
		if(document.oForm.date_fin.value!=""){
			if(document.getElementById('type_actu').selectedIndex!=0){
					if(document.oForm.titre_actu.value!=""){
					
						if(document.getElementById('type_actu').selectedIndex==1){
						
							if(document.oForm.libelle_lien1.value!=""){
								if(document.oForm.lien1.value!=""){
									document.oForm.submit();
								}else{
									alert("Vous n'avez pas saisi le lien 1");
								}
							}else{
								alert("Vous n'avez pas saisi le libellé du lien 1");
							}
							
						}else if(document.getElementById('type_actu').selectedIndex==2){
						
							if(document.oForm.libelle_lien1.value!=""){
								if(document.oForm.lien1.value!=""){
									document.oForm.submit();
								}else{
									alert("Vous n'avez pas saisi le lien 1");
								}
							}else{
								alert("Vous n'avez pas saisi le libellé du lien 1");
							}
							
						}else if(document.getElementById('type_actu').selectedIndex==3){
						
							if(document.oForm.libelle_lien1.value!=""){
								//if(document.getElementById('details_actu').value!=""){
									document.oForm.submit();
								//}else{
									//alert("Vous n'avez pas saisi le détail de l'actualité");
								//}
							}else{
								alert("Vous n'avez pas saisi le libellé du lien 1");
							}
							
						}else if(document.getElementById('type_actu').selectedIndex==4){
							document.oForm.submit();
						}
						
					}else{
						alert("Vous n'avez pas sélectionné le titre de l'actualité");
					}
			}else{
				alert("Vous n'avez pas sélectionné le type d'actualité");
			}
		}else{
			alert("Vous n'avez pas saisi le champ date de fin d'édition");
		}	
	}else{
		alert("Vous n'avez pas saisi le champ date de début d'édition");		
	}

}

/* FIN des ACTUALITES */


/* Dans l'admin de documentation technique */

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 changeCouleur(idcellule,couleur){
	document.getElementById(idcellule).style.background=couleur;
}


/* *************************************************** 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;
				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);
}

/* *************************** MAILING LISTE ******************************* */

function allerVers(ancre){
	document.location.href='#'+ancre;
}

function verifMailForm(nbre){
	var ok=0;
	if(document.aForm.email.value!=""){
	
		if(nbre>1){
			for(i=0;i<nbre;i++){
				if(document.aForm.groupe_id[i].checked == true){
					document.aForm.submit();
					ok=1;
					break;
				}
			}
		}
		
		if(nbre==1){
			if(document.aForm.groupe_id.checked == true){
				document.aForm.submit();
				ok=1;
			}
		}
		
		if(ok==0){
			alert("Vous devez cocher un groupe");
		}
		
	}else{
		alert("Vous devez saisir un email");
	}
}


function groupeTest(){
	if(document.oForm.groupe.value!=""){
		document.oForm.submit();
	}else{
		alert("Vous devez saisir le nom d'un groupe");
	}
}

function popuplettre(page,width,height,top,left){
	window.open(page,'popuplettre','width='+width+',height='+height+',top='+top+',left='+left+',toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=no,directories=no');
}

/* ********************* Fin de la mailing liste ********************** */



/* *************************** Nom de Domaine ******************************* */

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

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


function verifDate(ladate) {

	if (ladate.length!=10){
		return false;
	}else{
	    jour=ladate.substring(0,2);
		mois=ladate.substring(3,5);
	    annee=ladate.substring(6,10);
		separateur=ladate.charAt(2)+ladate.charAt(5);
		if (isNaN(jour+mois+annee) || annee>3000 || annee<1900 || separateur!="//"){
			return false;
		}else{
			return true;
		}
	}

}


function verifFormDomaine(){

var email = document.oForm.email_contact.value;
var ladate = document.oForm.date_creation.value;

	if(document.oForm.domaine.value!=""){
		if(verifDate(ladate)) {
			if(document.oForm.proprietaire.value!=""){
				if(verifMail(email)) {
					document.oForm.submit();
				}else{
					alert("L'adresse email est incorrecte");
				}
			}else{
				alert("Vous n'avez pas saisi le propriétaire du domaine");
			}
		}else{
			alert("Veuillez saisir une date de création au format JJ/MM/AAAA");
		}
	}else{
		alert("Vous n'avez pas saisi le nom de domaine");
	}
	
}

function valeurcheckbox(nbre_domaine){

  var nbre=new Number();
  var nbre=nbre_domaine+1;
  for(i=1;i<nbre;i++){
	 if(document.getElementById('check'+i).checked == false){
	  	document.getElementById('domaine'+i).value=0; 
	 }
  }
  
}

function verifoForm(){
	document.oForm.submit();
}


function checkCheckbox(){
	if(document.getElementById('option1').checked == true){
		document.getElementById('accept').value='oui'; 
	}else{
		document.getElementById('accept').value='non'; 
	}
	if(document.getElementById('option2').checked == true){
		document.getElementById('refuse').value='oui'; 
	}else{
		document.getElementById('refuse').value='non'; 
	}
}


/* 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);
