

//-----------------------------------------------------------
// Fonction opposée à la fonction php "XMLStrClean"
// Utilisée pour les éléments de titre et de commentaire dans un fichier XML
String.prototype.XMLStrRestore = function ()
{
    outstring = this;
    outstring = outstring.replace(/[#]{3}001[#]{3}/g, "<");
    outstring = outstring.replace(/[#]{3}002[#]{3}/g, ">");
    outstring = outstring.replace(/[#]{3}003[#]{3}/g, "&");
    return outstring;
}


//-----------------------------------------------------------
// Suppression des caractères d'espacements initiaux et finaux
// exemples :
// alert("    exemple    ".RLTrim()); */
String.prototype.RLTrim = function ()
{
	return this.replace(/(^\s*)|(\s*$)/g,"");
}


//-----------------------------------------------------------
// Suppression des caractères d'espacement sauf l'espace à l'intérieur 
// d'une chaîne et tous types de caractères d'espacement en bordure d'une chaîne.
// exemples :
// alert("    exemple    ".EscapesErase()); */
String.prototype.EscapesErase = function ()
{
	//return this.replace(/(^[\t\r\n\f\v]*)|([\t\r\n\f\v]*$)/g,"");
	return this.replace(/([\t\r\n\f\v]*)|(^\s*)|(\s*$)/g,"");
}


//-----------------------------------------------------------
String.prototype.IsInteger = function ()
{
    mystring = this;
    if (mystring.match(/^\d+$|^\d+\.\d{2}$/ ) ) 
    {
        return true;
    }
    else
    {
        return false;
    }
}

//-----------------------------------------------------------
// Nettoyage du contenu (ie des noeuds enfants) d'un élément html
//(div, span)
function nettoyage_div(div_cible)
{
	//var div_cible = document.getElementById(nom_div);
	
	if (div_cible != null)
	{
		if (div_cible.childNodes.length > 0)
		{
			//alert(div_cible.childNodes.length);
	    	var nombre_enfants = div_cible.childNodes.length;
	    	for (i = 0; i < nombre_enfants; i++)
	    	{
				//alert(div_cible.lastChild.firstChild.nodeValue);
	    		div_cible.removeChild(div_cible.lastChild);
	    	}
		}
	}
}


//-----------------------------------------------------------
// Nettoyage du contenu (ie des noeuds enfants) d'un élément html
//(div, span) et application d'un style "masque"
// ATTENTION : ici 'nom_div' est une chaîne de caractères
function nettoyage_div_2(nom_div)
{
	var div_cible = null;
	div_cible = document.getElementById(nom_div);
	
	if (div_cible != null)
	{
		if (div_cible.childNodes.length > 0)
		{
			//alert(div_cible.childNodes.length);
	    	var nombre_enfants = div_cible.childNodes.length;
	    	for (i = 0; i < nombre_enfants; i++)
	    	{
				//alert(div_cible.lastChild.firstChild.nodeValue);
	    		div_cible.removeChild(div_cible.lastChild);
	    	}
		}
		div_cible.className = "masque";
	}
}


//-----------------------------------------------------------
// Nettoyage du contenu (ie des noeuds enfants) d'un élément html
// et insertion d'une nouvelle chaîne de caractères
function remplace_div(div_cible, chaine_in)
{
	if (div_cible != null)
	{
		if (div_cible.childNodes.length > 0)
		{
			//alert(div_cible.childNodes.length);
	    	var nombre_enfants = div_cible.childNodes.length;
	    	for (i = 0; i < nombre_enfants; i++)
	    	{
				//alert(div_cible.lastChild.firstChild.nodeValue);
	    		div_cible.removeChild(div_cible.lastChild);
	    	}
		}
	
		var n_texte = document.createTextNode(chaine_in);
		div_cible.appendChild(n_texte);
	}
}


//---------------------------------------------------
// Affichage / masquage d'une "*" rouge à gauche d'un champ en cours de validation
// aff == true => affichage
// aff == false => masquage
function indique_erreur(id_span, aff)
{
	if (id_span.length <= 0) return;

	var span_courant = document.getElementById(id_span);
	if (span_courant != null)
		(aff == true) ? (span_courant.className = "erreur affiche") : (span_courant.className = "erreur masque");
		
	return;
}


//---------------------------------------------------
// Activation / désactivation d'un élément de formulaire (ex : input de type "button")
// aff == true => affichage
// aff == false => masquage
function activ(id, activ)
{
	if (id.length <= 0) return;

	var id_courant = document.getElementById(id);
	if (id_courant != null)
		(activ == true) ? (id_courant.disabled = "") : (id_courant.disabled = "disabled");
		
	return;
}


//-------------------------------------------------
// VERIFICATION DE DATES
// Auteur : Guillaume Marc
//  email : adalberto@wanadoo.fr
// Adaptation : Damien Schnell

function validation_date(date_in)
{
	var date = "";
	var jour = 0;
	var mois = 0;
	var annee = 0;
	date = date.concat(date_in);
	
	//alert(date);
	
	// controle de la longueur de la chaine aaaa/mm/jj = 10 //
	if (date.length == 10) 
	{
		if (date.substr(2, 1) == "/" && date.substr(5, 1) == "/")
		{
			var chaine_jour = "";
			chaine_jour = date.substr(0, 2);
			//alert(chaine_jour);
			if (chaine_jour.charAt(0) == "0")
				chaine_jour = chaine_jour.substr(1, 1);
			//alert(chaine_jour);
			jour = parseInt(chaine_jour);

			var chaine_mois = "";
			chaine_mois = date.substr(3, 2);
			if (chaine_mois.charAt(0) == "0")
				chaine_mois = chaine_mois.substr(1, 1);
			mois = parseInt(chaine_mois);

			annee = parseInt(date.substr(6, 4));
			//alert(jour);
			//alert(mois);
			//alert(annee);

			if (mois >= 1 && mois <= 12)
			{  // verifie que le mois verifie 1<mois<12
				if (jour <= longueurMois(mois, annee))
				{ // controle le jour par 
					return true;                        // rapport a la longueur du mois 
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		else
		{
			 return false;
		}
	}
	else
	{
		return false;
	}
}

 // La fonction renvoit la longueur d'un mois precis 
 // en tenant compte du mois de fevrier et des années bissextiles 

 function longueurMois(mois,annee){
  if (mois==4 || mois==6 || mois==9 || mois==11) return 30;
   else if ((mois==2) && estBissextile(annee)) return 29;
   else if (mois==2) return 28;
   else return 31;
  }

  /* Les annees bissextiles sont les annees paires divisibles par
     quatre et qui ne sont pas des annees de centaine et les annees
     de centaine qui sont divisibles par 400.
     (par exemple 1600 etait bissextile, 2000 aussi mais pas 1900
      qui est divisible par 4 et paire mais pas divisible par 400) 
  */

 // fonction appelée par validation_date() 

 function estBissextile(ans){
  if (((ans % 4 == 0) && ans % 100 != 0) || ans % 400 == 0)
   return true;//c'est une annee bissextile 
  else
   return false;//ce n'en est pas une 
 }


//---------------------------------------------------
// VERIFICATION de la syntaxe D'UN EMAIL
function validation_email(email)
{
	// email contient l'adresse email à vérifier
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
		return true;
	else
		return false;
/*	
	if (ereg(".+(@.+)(.[[:alpha:]]{2}([[:alpha:]]?))$",$email))
		return true;
	else
		return false;
*/}


//---------------------------------------------------
// Fonctions de (re)dimensionnement de page

//-----
// Récupération de la hauteur de la page
function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }
    else {
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}


//-----
// Récupération de la largeur de la page
function getWindowWidth() {
    var windowWidth=0;
    if (typeof(window.innerWidth)=='number') {
        windowWidth=window.innerWidth;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientWidth) {
         windowWidth = document.documentElement.clientWidth;
    }
    else {
     if (document.body&&document.body.clientWidth) {
         windowWidth=document.body.clientWidth;
      }
     }
    }
    return windowWidth;
}
//alert(getWindowWidth());

//-----
// Définition de la hauteur du div "pageMiddle"
function setPageHeightWidth()
{
    if (document.getElementById)
    {
        var windowHeight = getWindowHeight();
        var windowWidth = getWindowWidth();
        if (windowHeight > 0 && windowWidth > 0)
        {
            // Redimensionnement du div "pageMiddle"
            var div_pageMiddle = null;
			var div_page = document.getElementById("page");
			var div_pageTopMiddleRight = document.getElementById("pageTopMiddleRight");
            var div_pageTop = document.getElementById("pageTop");
            var div_pageMiddle = document.getElementById("pageMiddle");
            var div_pageLeft = document.getElementById("pageLeft");
            var div_pageRight = null;
            div_pageRight = document.getElementById("pageRight");
            var div_pageBottom = document.getElementById("pageBottom");
            if (div_pageMiddle != null)
            {
				var h_pageTop = div_pageTop.offsetHeight;
            	var h_pageBottom = div_pageBottom.offsetHeight;
            	var w_page = div_page.offsetWidth;
            	var w_pageLeft = div_pageLeft.offsetWidth;
            	var w_pageRight = 0;
            	if (div_pageRight != null)
            		w_pageRight = div_pageRight.offsetWidth + div_pageRight.style.paddingLeft + div_pageRight.style.paddingRight;

            	var div_nav_int = null;
            	var h_nav_int = 0;
            	div_nav_int = document.getElementById("navigation_interne");
            	if (div_nav_int != null)
            		h_nav_int = div_nav_int.offsetHeight;
            	//alert(windowHeight + " " + h_pageTop + " " + h_titre);
            
            	// On retranche ces 2 hauteurs à celle de la page pour déterminer celle du div "pageMiddle"
            	// ATTENTION : ne pas affecter "div_pageMiddle.style.height" si "h_pageMiddle" == 0
            	// sinon erreur javascript !
            	var h_pageMiddle = 0;
				var w_pageTopMiddleRight = 0;
            	var w_pageTop = 0;
            	var w_pageMiddle = 0;
            	var w_pageBottom = 0;
            	if (h_nav_int <= 0)
	            	h_pageMiddle = windowHeight - h_pageTop - h_pageBottom;
	            else
		            h_pageMiddle = windowHeight - h_pageTop - h_pageBottom - h_nav_int;
            	if (h_pageMiddle > 0)
	            {
	            	div_pageMiddle.style.height = h_pageMiddle + 'px';
	            	div_pageLeft.style.height = windowHeight + 'px';
	            	if (div_pageRight != null)
		            	div_pageRight.style.height = h_pageMiddle + 'px';
	            }
            	
				//alert("div_page.style.marginLeft = " + div_page.style.marginLeft);
				//alert("div_page.style.backgroundColor = " + div_page.style.backgroundColor);
				
				w_pageTopMiddleRight = (90 / 100) * windowWidth - w_pageLeft;// - div_page.style.marginLeft - div_page.style.marginRight;// - (windowWidth - w_page);
            	w_pageMiddle = (90 / 100) *  windowWidth - w_pageLeft - w_pageRight;
            	//alert(w_pageMiddle);
            	//w_pageMiddle = windowWidth - w_pageLeft - w_pageRight - div_page.style.marginLeft - div_page.style.marginRight;// - (windowWidth - w_page);
            	//alert(w_pageMiddle);
            	w_pageBottom = w_pageTop = w_pageTopMiddleRight;
            	if (w_pageMiddle > 0)
	            	div_pageMiddle.style.width = w_pageMiddle + 'px';
            	if (w_pageTopMiddleRight > 0)
	            {
	            	div_pageTopMiddleRight.style.width = w_pageTopMiddleRight + 'px';
	            	div_pageTop.style.width = w_pageTop + 'px';
	            	div_pageBottom.style.width = w_pageBottom + 'px';
	            }
            }
		}
	}
}


//---------------------------------------------------
function logout()
{
	question = "Souhaitez-vous revenir au site public?";
	//alert('COUCOU');
	if (confirm(question))
	{
		document.getElementById("form_logout").submit();
	}
}


//---------------------------------------------------
//---------------------------------------------------
//---------------------------------------------------
//---------------------------------------------------

