
// JavaScript Document
/*
Fonction de Dreamweaver modifiée pour vérifier la validité des champs dans un formulaire
*/

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 Format_Tel(NumTel){
  var Tel;
  var i = 0;
  while (i < NumTel.length-1)
    {
    if ((NumTel.charAt(i) == ".")||(NumTel.charAt(i) == ",")||(NumTel.charAt(i) == "/")||(NumTel.charAt(i) == "-")||(NumTel.charAt(i) == " "))
      {
      Tel = NumTel.substring(0,i) + NumTel.substring(i+1,NumTel.length);
          NumTel = Tel; 
      }
      else{
      i++;
      }
    }
  return (NumTel);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- Le champs '+nm+' doit contenir une adresse email valide.\n';
      } 

		else if ((test.charAt(0) == 'U')||(test.charAt(1) == 'U')) {
			
			if (val.substring(0,7)!='') {	
			if (val.substring(0,7)!='http://') {
            //alert("Pour continuer votre inscription, vous devez accepter le règlement !")
			//document.MM_returnValue = ('');
			errors += '- Le champs '+nm+' doit contenir un lien correct (http://).\n';
												}  
										}
										}
										
		else if (test.charAt(0) == 'T') {
			
			var Tel;
			Tel = Format_Tel(val);
			
				if ((Tel.length != 10)||isNaN(Tel)||((Tel.substring(0,2)!='01')&&(Tel.substring(0,2)!='02')&&(Tel.substring(0,2)!='03')&&(Tel.substring(0,2)!='04')&&(Tel.substring(0,2)!='05')&&(Tel.substring(0,2)!='06')&&(Tel.substring(0,2)!='08'))) { errors+='- Le champs '+nm+' doit contenir un numero de téléphone valide'; }

										}
										
		else if (test.charAt(0) == 'F') {
			
			var Fax;
			Fax = Format_Tel(val);
			
			if (Fax != '') {
				
				if ((Fax.length != 10)||isNaN(Fax)||((Fax.substring(0,2)!='01')&&(Fax.substring(0,2)!='02')&&(Fax.substring(0,2)!='03')&&(Fax.substring(0,2)!='04')&&(Fax.substring(0,2)!='05')&&(Fax.substring(0,2)!='06')&&(Fax.substring(0,2)!='08'))) { errors+='-Le champs '+nm+' doit contenir un numero de fax valide.\n'; }

							}
										 }
		
		else if ((test.charAt(0) == 'C')&&(test.charAt(1) == 'P')) {
			
			if ((val.length != 5)||(isNaN(val))||val=='') { errors+='- Le champs code postal doit contenir un code postal valide (5 chiffres).\n'; }

																	}

	  else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- Le champs '+nm+' est obligatoire.\n'; 
	
			
			}
  } 
  
  
  if (errors) alert('Erreur(s) rencontré(s) :\n\n'+errors);
  document.MM_returnValue = (errors == '');
}


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_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&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function changerOnglet(image) {
	if(image=='services_associes')
		document.getElementById('services_associes').src='images/onglets/onglet_service_assoc_on.gif';
	if(image=='disponibilites')
		document.getElementById('disponibilites').src='images/onglets/onglet_disponibilite_on.gif';
	if(image=='reserver')
		document.getElementById('reserver').src='images/onglets/onglet_reserver_on.gif';		
}
// Ouverture de lien externe pour respecter les normes W3C
function open_ext_link()
{
	var liens = document.getElementsByTagName('a');
	// On récupère tous les liens (<a>) du document dans une variable (un array), ici liens.
	// Une boucle qui parcourt le tableau (array) liens du début à la fin.
	for (var i = 0 ; i < liens.length ; ++i)  {
		// Si les liens ont un nom de class égal à lien_ext, alors on agit.
		if (liens[i].className == 'lien_ext')  {
			liens[i].title = 'S\'ouvre dans une nouvelle fenêtre';
			// Au clique de la souris.
			liens[i].onclick = function()  {
				window.open(this.href);
				return false; // On ouvre une nouvelle page ayant pour URL le href du lien cliqué et on inhibe le lien réel.
			};
		}
	}
}
window.onload = open_ext_link;
// Au chargement de la page, on appelle la fonction.



//Masque tous les onglets
function CacherElmts() {
	var args=CacherElmts.arguments;
   
	for (i=0; i<(args.length); i++) 
		document.getElementById(args[i]).style.display = 'none';
}

//Changement de la classe
function ChangerClass() {
	var args=ChangerClass.arguments;
   
	for (i=0; i<(args.length); i++) 
		document.getElementById(args[i]).className = 'BoxOnglet';
}

//Affichage des éléments
function MontrerElmts() {
	var args=MontrerElmts.arguments;
   
	for (i=0; i<(args.length); i++) 
		document.getElementById(args[i]).style.display='block';
}

//Fontion sur les touches pressées
function codeTouche(evenement)
{
        for (prop in evenement)
        {
                if(prop == 'which') return(evenement.which);
        }
        return(evenement.keyCode);
}

function scanTouche(evenement, expression)
{
		//var reCarValides = /\w/;
        var reCarValides = expression;

        var codeDecimal  = codeTouche(evenement);
        var car = String.fromCharCode(codeDecimal);
        
		if (codeTouche(evenement) != 8 && codeTouche(evenement) != 0)
			var autorisation = reCarValides.test(car);
		else
			var autorisation = true;

        return autorisation;
}

function Confirmer(fin_chaine,formulaire,id_pere) {
	if (confirm('Etes vous sûr de vouloir supprimer '+fin_chaine+' ?'))
	{
		document.getElementById('action_supprimer').value=id_pere;
		eval("document."+formulaire+".submit();");
		//alert()
		//document.location.href="";
		return true;
	}
	else 
		return false;
}

function affiche_elt(act)
{
	if (act=='Aucun')
	{
		document.getElementById('fichier').style.display='none';
		
		if (document.getElementById('fichier_comm'))
			document.getElementById('fichier_comm').style.display='none';
		
		if (document.getElementById('ancien_fichier_comm'))
			document.getElementById('ancien_fichier_comm').style.display='none';
		
		if (document.getElementById('fichier_tit'))
			document.getElementById('fichier_tit').style.display='none';
		
		if (document.getElementById('ancien_fichier_tit'))
			document.getElementById('ancien_fichier_tit').style.display='none';
			
		//document.getElementById('lien').style.display='none';
		document.getElementById('ancien_fichier').style.display='none';
	}
	else if (act=='Fichier')
	{
		document.getElementById('fichier').style.display='block';
		
		if (document.getElementById('fichier_comm'))
			document.getElementById('fichier_comm').style.display='block';
		
		if (document.getElementById('ancien_fichier_comm'))
			document.getElementById('ancien_fichier_comm').style.display='none';
		
		if (document.getElementById('fichier_tit'))
			document.getElementById('fichier_tit').style.display='block';
		
		if (document.getElementById('ancien_fichier_tit'))
			document.getElementById('ancien_fichier_tit').style.display='none';
			
		//document.getElementById('lien').style.display='none';
		document.getElementById('ancien_fichier').style.display='none';
	}
	else if (act=='Fichier_ancien')
	{
		document.getElementById('fichier').style.display='none';
		
		if (document.getElementById('fichier_comm'))
			document.getElementById('fichier_comm').style.display='none';
		
		if (document.getElementById('ancien_fichier_comm'))
			document.getElementById('ancien_fichier_comm').style.display='block';
		
		if (document.getElementById('fichier_tit'))
			document.getElementById('fichier_tit').style.display='none';
		
		if (document.getElementById('ancien_fichier_tit'))
			document.getElementById('ancien_fichier_tit').style.display='block';
			
		//document.getElementById('lien').style.display='none';
		document.getElementById('ancien_fichier').style.display='block';
	}
}

function affiche_elt_nb(act,nb)
{
	if (act=='Aucun')
	{
		if (document.getElementById('fichier'+nb))
			document.getElementById('fichier'+nb).style.display='none';
			
		/*if (document.getElementById('photo'+nb))
			document.getElementById('photo'+nb).style.display='none';*/

		if (document.getElementById('fichier_comm'+nb))
			document.getElementById('fichier_comm'+nb).style.display='none';
		
		if (document.getElementById('ancien_fichier_comm'+nb))
			document.getElementById('ancien_fichier_comm'+nb).style.display='none';

		if (document.getElementById('fichier_tit'+nb))
			document.getElementById('fichier_tit'+nb).style.display='none';
		
		if (document.getElementById('ancien_fichier_tit'+nb))
			document.getElementById('ancien_fichier_tit'+nb).style.display='none';

		document.getElementById('ancien_fichier'+nb).style.display='none';
	}
	else if (act=='Fichier')
	{
		if (document.getElementById('fichier'+nb))
			document.getElementById('fichier'+nb).style.display='block';

		if (document.getElementById('fichier_comm'+nb))
			document.getElementById('fichier_comm'+nb).style.display='block';
			
		/*if (document.getElementById('photo'+nb))
			document.getElementById('photo'+nb).style.display='block';*/
		
		if (document.getElementById('ancien_fichier_comm'+nb))
			document.getElementById('ancien_fichier_comm'+nb).style.display='none';

		if (document.getElementById('fichier_tit'+nb))
			document.getElementById('fichier_tit'+nb).style.display='block';
		
		if (document.getElementById('ancien_fichier_tit'+nb))
			document.getElementById('ancien_fichier_tit'+nb).style.display='none';

		document.getElementById('ancien_fichier'+nb).style.display='none';
	}
	else if (act=='Fichier_ancien')
	{
		if (document.getElementById('fichier'+nb))
			document.getElementById('fichier'+nb).style.display='none';

		if (document.getElementById('fichier_comm'+nb))
			document.getElementById('fichier_comm'+nb).style.display='none';
			
		/*if (document.getElementById('photo'+nb))
			document.getElementById('photo'+nb).style.display='none';*/
		
		if (document.getElementById('ancien_fichier_comm'+nb))
			document.getElementById('ancien_fichier_comm'+nb).style.display='block';

		if (document.getElementById('fichier_tit'+nb))
			document.getElementById('fichier_tit'+nb).style.display='none';
		
		if (document.getElementById('ancien_fichier_tit'+nb))
			document.getElementById('ancien_fichier_tit'+nb).style.display='block';

		document.getElementById('ancien_fichier'+nb).style.display='block';
	}
}

//Passage d'un select multiple vers un autre
function move_item(from, to)
{
  var f;
  var SI;

  if(eval(from+".options.length")>0)
  {
    for(i=0;i<eval(from+".length");i++)
    {
      if(eval(from+".options["+i+"].selected"))
      {
        SI=eval(from+".selectedIndex");
        f=eval(from+".options["+SI+"].index");
	  
		eval(to+".options["+to+".length]=new Option("+from+".options["+SI+"].text,"+from+".options["+SI+"].value);");
		
		eval(from+".options["+SI+"]=null;");
        i--; 
      }
    }
  }
}


function PostSelect_bis(){
	var args=PostSelect_bis.arguments;
   
	for (i=0; i<(args.length); i++) 
	{
		// On compte le nombre d'item de la liste select
		NbCol1 = eval("document.getElementById('"+args[i]+"').length;");
		
		// On lance une boucle pour selectionner tous les items
		for(a=0; a<NbCol1; a++){
		 eval("document.getElementById('"+args[i]+"').options["+a+"].selected = true;");
		}
	}
	
	// On soumet le formulaire
	//document.forms.submit();
}

//Demande de confirmation avant suppression d'une photo d'une application
function ConfSupprPhoto(valeur) {
	if (confirm('Etes vous sûr de vouloir supprimer la photo '+valeur+' ?'))
	{
		document.getElementById('photo_a_supprimer').value=valeur;
		document.suppression_photo.submit();
		//alert()
		//document.location.href="";
		return true;
	}
	else 
		return false;
}

//On bidouille l'histoire des applications
function alert_application(valeur,langues_etat)
{
	
	
	block = 0;
	
	for (var i=0;i<langues_etat.length;i++)
	{
		for (var j=0;j<langues_etat[i].length;j++)
		{
			//Si on se trouve dans le tableau a l'endroit qui concerne l'option que l'on parcourt
			if (langues_etat[i][j]["loption"]==valeur && langues_etat[i][j]["vide"]==1)
			{
				if (document.getElementById('lediteur_'+langues_etat[i][j]["id_langue"]))
					document.getElementById('lediteur_'+langues_etat[i][j]["id_langue"]).style.display = 'none';
				
				if (document.getElementById('letitre_'+langues_etat[i][j]["id_langue"]))
					document.getElementById('letitre_'+langues_etat[i][j]["id_langue"]).style.display = 'none';
					
				if (document.getElementById('secteur_appli_'+langues_etat[i][j]["id_langue"]))
					document.getElementById('secteur_appli_'+langues_etat[i][j]["id_langue"]).style.display = 'none';
				
				if (document.getElementById("bong_"+langues_etat[i][j]["id_langue"]))
					document.getElementById("bong_"+langues_etat[i][j]["id_langue"]).className='BoxOnglet';
				
				if (document.getElementById("ongl_"+langues_etat[i][j]["id_langue"]))
					document.getElementById("ongl_"+langues_etat[i][j]["id_langue"]).style.display='none';
			}
			//Si ce n'est pas vide
			else if (langues_etat[i][j]["loption"]==valeur && langues_etat[i][j]["vide"]==0)
			{
				//On affiche nos onglets
				if (document.getElementById("ongl_"+langues_etat[i][j]["id_langue"]))
					document.getElementById("ongl_"+langues_etat[i][j]["id_langue"]).style.display='block';
				
				//Si c'est le premier onglet que l'on parcourt, c'est lui qui est selectionné par défaut
				if (block==0)
				{					
					if (document.getElementById("bong_"+langues_etat[i][j]["id_langue"]))
						document.getElementById("bong_"+langues_etat[i][j]["id_langue"]).className='BoxOngletFonce';
					
					if (document.getElementById('lediteur_'+langues_etat[i][j]["id_langue"]))
						document.getElementById('lediteur_'+langues_etat[i][j]["id_langue"]).style.display = 'block';
					
					if (document.getElementById('letitre_'+langues_etat[i][j]["id_langue"]))
						document.getElementById('letitre_'+langues_etat[i][j]["id_langue"]).style.display = 'block';
					
					if (document.getElementById('secteur_appli_'+langues_etat[i][j]["id_langue"]))
						document.getElementById('secteur_appli_'+langues_etat[i][j]["id_langue"]).style.display = 'block';
					
					block++;
				}
				else
				{
					if (document.getElementById("bong_"+langues_etat[i][j]["id_langue"]))
						document.getElementById("bong_"+langues_etat[i][j]["id_langue"]).className='BoxOnglet';
					
					if (document.getElementById('lediteur_'+langues_etat[i][j]["id_langue"]))
						document.getElementById('lediteur_'+langues_etat[i][j]["id_langue"]).style.display = 'none';
					
					if (document.getElementById('letitre_'+langues_etat[i][j]["id_langue"]))
						document.getElementById('letitre_'+langues_etat[i][j]["id_langue"]).style.display = 'none';
					
					if (document.getElementById('secteur_appli_'+langues_etat[i][j]["id_langue"]))
						document.getElementById('secteur_appli_'+langues_etat[i][j]["id_langue"]).style.display = 'none';
				}
			}
		}
	}
}

function creneau_coche(num)
{
	document.creneau_reserve.matin[num].checked=true;
	document.creneau_reserve.apresmidi[num].checked=true;
	document.creneau_reserve.soiree[num].checked=true;
}

function aff_mask(id)
{
	if (document.getElementById(id).style.display=='block')
		document.getElementById(id).style.display='none';
	else
		document.getElementById(id).style.display='block';
}

function limitcar(texte, nb, maxi) {
 if (texte.value.length > maxi)
   texte.value = texte.value.substring(0, maxi);
 else 
   nb.value = maxi - texte.value.length;
}

function storeCaret(text)
{ // voided
}

function AddText(startTag,defaultText,endTag,champ) 
{

 if (champ.createTextRange) 
 {
  var text;
  champ.focus(champ.caretPos);
  champ.caretPos = document.selection.createRange().duplicate();
  if(champ.caretPos.text.length>0)
  {
   champ.caretPos.text = startTag + champ.caretPos.text + endTag;
  }
  else
  {
   champ.caretPos.text = startTag+defaultText+endTag;
  }
 }
 else champ.value += startTag+defaultText+endTag;
}


//Demande de confirmation avant suppression d'une photo d'une réalisation
function ConfSupprPhotoRealisation(nom, valeur) {
	if (confirm('Etes vous sûr de vouloir supprimer la photo '+nom+' ?'))
	{
		document.getElementById('photo_a_supprimer').value=valeur;
		document.action_photo.submit();
		//alert()
		//document.location.href="";
		return true;
	}
	else 
		return false;
}
//Demande de confirmation avant suppression d'une photo d'une réalisation
function ConfSupprPhotoTerrain(nom, valeur) {
	if (confirm('Etes vous sûr de vouloir supprimer la photo '+nom+' ?'))
	{
		document.getElementById('photo_a_supprimer').value=valeur;
		document.action_photo.submit();
		//alert()
		//document.location.href="";
		return true;
	}
	else 
		return false;
}
//Affichage des pièces dans le formulaire
function AffichPieces(nb,nb_max)
{
	for (r=1;r<=nb_max;r++)
	{
		if (r<=nb)
			eval("document.getElementById('piece"+r+"').style.display='block';");
		else
			eval("document.getElementById('piece"+r+"').style.display='none';");
	}
}

//Demande de confirmation avant suppression d'un PDF d'un modèle
function ConfSupprPDFModele(nom, valeur) {
	if (confirm('Etes vous sûr de vouloir supprimer le PDF '+nom+' ?'))
	{
		document.getElementById('pdf_a_supprimer').value=valeur;
		document.action_pdf.submit();
		//alert()
		//document.location.href="";
		return true;
	}
	else 
		return false;
}

//Fonction javascript pour la partie Programmes neufs
function NomOuPas(sel)
{
	if (sel==4)
		document.getElementById('nom_plan_autre').style.display='block';
	else
		document.getElementById('nom_plan_autre').style.display='none';
}


//Affichage des pièces dans le formulaire
function AffichTypologies(nb,nb_max)
{
	for (r=1;r<=nb_max;r++)
	{
		if (r<=nb)
			eval("document.getElementById('typologie"+r+"').style.display='block';");
		else
			eval("document.getElementById('typologie"+r+"').style.display='none';");
	}
}

function activ_desactiv_objet_autre(valeur)
{
	if (valeur=="Autre")
	{
		document.getElementById("objet_autre").readOnly=false;
		document.getElementById("objet_autre").className="form_large";
	}
	else if (valeur=="Demande de rendez-vous")
	{
		document.getElementById("objet_autre").readOnly=true;
		document.getElementById("objet_autre").value='';
		document.getElementById("objet_autre").className="form_large_disabled";
	}
}

function verif_vider(valeur)
{
	if (valeur=="S'il s'agit d'une demande de rendez-vous, merci de préciser vos disponibilités.")
		document.getElementById("message").value='';
}