

function onloadpage(iFromIndex, iMailSent)
{	
	if (iFromIndex)
	{
		if (iMailSent)
		  alert ("Nous avons bien enregistr\351 votre demande\n\nMerci de l'int\351r\352t que vous portez \340 L'Egide");
		else
			alert ("Une erreur s'est produite !\n\nNous n'avons pas pu enregistrer votre demande");
	}
	
	return null; 
}

function onclickok()
{
	with (document.forms["envoyer"])  
	{				
  	if (confirmnewsletter())
  		submit();	   
  }
   
  return null;
}

function confirmnewsletter()
{
	with (document.forms["envoyer"])  
	{				
		if ((emledt.value == "") || (!testEmail(emledt.value)))
		{
			alert ("L'email est incorrect!");
			return false;   
		}
  }
   
  return true;
}

function confirmcontact()
{	
	with (document.forms["contact"])  
	{				
		if (nameedt.value == "") 
		{
			alert ("Le nom n'est pas renseign\351!");
			return false;
		}
		
		if ((emailedt.value == "") || (!testEmail(emailedt.value)))
		{
			alert ("L'email est incorrect!");
			return false;
		}
		
		if (objectedt.value == "") 
		{
			alert ("L'objet n'est pas renseign\351!");
			return false;
		}
		
		if (msgedt.value == "") 
		{
			alert ("Le message n'est pas renseign\351!");
			return false;
		}
				
		return true;
	}
}

function confirmpetition()
{	
	with (document.forms["petition"])  
	{				
		if (firstnameedt.value == "") 
		{
			alert ("Le pr\351nom n'est pas renseign\351!");
			return false;
		}
		
		if (nameedt.value == "") 
		{
			alert ("Le nom n'est pas renseign\351!");
			return false;
		}
		
		if ((emailedt.value == "") || (!testEmail(emailedt.value)))
		{
			alert ("L'email est incorrect!");
			return false;
		}
		
		if (verifemailedt.value != emailedt.value)
		{
			alert ("La v\351rification de l'email a \351chou\351e!");
			return false;
		}
						
		return true;
	}
}

function confirmpetitionorg()
{	
	with (document.forms["petition"])  
	{				
		if (orgedt.value == "") 
		{
			alert ("Le nom de l'organisation n'est pas renseign\351!");
			return false;
		}
		
		if (firstnameedt.value == "") 
		{
			alert ("Le pr\351nom du repr\351sentant n'est pas renseign\351!");
			return false;
		}
		
		if (nameedt.value == "") 
		{
			alert ("Le nom du repr\351sentant n'est pas renseign\351!");
			return false;
		}
		
		if ((emailedt.value == "") || (!testEmail(emailedt.value)))
		{
			alert ("L'email est incorrect!");
			return false;
		}
		
		if (verifemailedt.value != emailedt.value)
		{
			alert ("La v\351rification de l'email a \351chou\351e!");
			return false;
		}
						
		return true;
	}
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


function getCookieVal (offset)
{
   var endstr = document.cookie.indexOf (";", offset);
   
   if (endstr == -1)
      endstr = document.cookie.length;
   
   return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name)
{
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   
   while (i < clen)
   {
      var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		
		i = document.cookie.indexOf(" ", i) + 1;
		
		if (i == 0)
			break; 
	}
	
	return null;
}

  
function SetCookie (name, value)
{	
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}


// est un caractère spécial ?
function isSpecial(CAR)
{
   // La liste des caractères spéciaux
   var Special = new Array("<",">","(",")","[","]","\\",".",",",";",":","#"," ","'","\"")
   
   for(var IndSpe=0;IndSpe < Special.length ; IndSpe++)
		if (CAR == Special[IndSpe])
      	return true;
   
   return false; 
}

// est un caractère [a..z] | [A..Z] 
function isA(CAR)
{   
   return ((CAR >= "a") && (CAR <= "z")) || ((CAR >= "A") && (CAR <= "Z"));
}


// Est un caractère Ascii 128 - (special && sp) ?
function isC(CAR)
{
   return (CAR.charCodeAt(0) <= 126) && (CAR.charCodeAt(0) >= 32) && !isSpecial(CAR); 
}

// est un Chiffre [0..9]
function isD(CAR)
{
   return (CAR >= "0") && (CAR <= "9");
}

// est un alphanumérique
function isAD(CAR)
{
   return isA(CAR) || isD(CAR);
}

function isAlphaNum(STR)
{
	// vérifie chaque caractère de la chaine STR
	for (var IndStr=0; IndStr < STR.length ; IndStr++)
		if (!isAD(STR.charAt(IndStr)) && !(STR.charAt(IndStr) == "-")) 
         return false;
	
   return true;
}	

function isNum(STR)
{
	// vérifie chaque caractère de la chaine STR
	for (var IndStr=0; IndStr < STR.length ; IndStr++)
		if (!(isD(STR.charAt(IndStr))) ) 
         return false;
	
   return true;
}	


// est une Chaine de caractères
function isString(STR)
{
   // vérifie chaque caractère de la chaine STR
	for (var IndStr=0; IndStr < STR.length ; IndStr++)
		if (!(isC(STR.charAt(IndStr))) ) 
         return false;
	
   return true;
}

function isDotString(STR)
{
   var POINT = STR.indexOf(".");
   
   if (POINT > 0)
   {
      var LeftPart = STR.slice(0,POINT);
   	var RightPart = STR.slice(POINT + 1,STR.length);
   	
      return (isString(LeftPart)) && (isDotString(RightPart));
  	}
  	else
   	return isString(STR);
}

// est LocalPart
function isLocalPart(STR)
{
  return isDotString(STR);
}

function isLetDigHyp(CAR)
{
   return isAD(CAR) || (CAR == "-");
}

function isName(STR)
{
   // Vérifie que le 1er caractère de la chaine sont des [A..Z] ou [a..z]
   //if (!isA( STR.charAt(0))) 
   //   return false;
      
   // Vérifie que les caractères suivants sont des [a..z] || [A..Z] || [0..9] || "-"
   for (var IndName=1 ; IndName < STR.length ; IndName++)
      if (!isLetDigHyp(STR.charAt(IndName)))
         return false;
  
  return true;            
}

// est Domaine
function isDomaine(STR)
{
  var POINT = STR.indexOf(".")

  if (POINT > 0)
  {
	  var LeftPart = STR.slice(0,POINT);
     var RightPart = STR.slice(POINT + 1 , STR.length); 
      
     return isName(LeftPart) && (isDomaine(RightPart) || isString(RightPart));
  }
  else 
     return false;
}

function testEmail(chaine)
{		
	var Arobace = chaine.indexOf("@");
	
	chaine = chaine.toLowerCase();
	
	// Commence les tests : Arobace présente et pas en premier
	if (Arobace > 0)
	{
   	var LocalPart = chaine.slice(0,Arobace);
   	var Domaine = chaine.slice(Arobace + 1, chaine.length);
   	
   	return isLocalPart(LocalPart) && isDomaine(Domaine);
   }
	else
	   return false;
}