    function PopupHelp(titre, texte) {
        w=open("",'image','width=300,height=150,toolbar=no,scrollbars=no,resizable=no');
        w.document.write("<html><head><title>"+titre+"</title>");
        w.document.write("<link rel=\"stylesheet\" href=\"/jahia/jsp/jahia/templates/aon/Aon_accuracy_templates/web_css.jsp?colorSet=blue\" type=\"text/css\"></link></head>");
        w.document.write("<body bgcolor='#FFFFFF' leftmargin='0' rightmargin='0' topmargin='0' bottommargin='0'>");
        w.document.write("<div class=\"aon_form_popupTitle\">"+titre+"</div><br />");
        w.document.write("<hr size=\"1\" width=\"100%\" color=\"#CCCCCC\">");
        w.document.write("<span class=\"aon_form_popupText\">"+texte+"</span>");
        w.document.write("</body></html>");
        w.document.close();
        w.focus();
    }


////////////////////////////////
//     Vérification date      //
////////////////////////////////

//juste pour checker si cest netscape/mozilla
var isNS4 = (navigator.appName=="Netscape")?1:0;

function check_date()
  {
  if(!isNS4)
    {
    if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
    }
    else
    {
    if(event.which < 45 || event.which > 57) returnfalse;
    }
  }

var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/";
var vDateType = 3;
var vYearType = 4;
var vYearLength = 2;
var err = 0;
if(navigator.appName == "Netscape")
  {
  if (navigator.appVersion < "5")
    {
    isNav4 = true;
    isNav5 = false;
    }
  else if (navigator.appVersion > "4")
    {
    isNav4 = false;
    isNav5 = true;
    }
  }
else
  {
  isIE4 = true;
  }

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType)
  {
  vDateType = dateType;
  if (vDateValue == "~")
    {
    alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
    vDateName.value = "";
    vDateName.focus();
    return true;
    }
  var whichCode = (window.Event) ? e.which : e.keyCode;
  if (vDateValue.length > 8 && isNav4)
    {
    if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
    return true;
    }
  var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
  if (alphaCheck.indexOf(vDateValue) >= 1)
    {
    if (isNav4)
      {
      vDateName.value = "";
      vDateName.focus();
      vDateName.select();
      return false;
      }
    else
      {
      vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
      return false;
      }
    }
    if (whichCode == 8)
    return false;
    else
      {
      var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
      if (strCheck.indexOf(whichCode) != -1)
        {
        if (isNav4)
          {
          if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1))
            {
            alert("La date inscrite est non valide \n Veuillez la vérifier");
            vDateName.value = "";
            vDateName.focus();
            vDateName.select();
            return false;
            }
          if (vDateValue.length == 6 && dateCheck)
            {
            var mDay = vDateName.value.substr(2,2);
            var mMonth = vDateName.value.substr(0,2);
            var mYear = vDateName.value.substr(4,4)
            if (mYear.length == 2 && vYearType == 4)
              {
              var mToday = new Date();
              var checkYear = mToday.getFullYear() + 30;
              var mCheckYear = '20' + mYear;
              if (mCheckYear >= checkYear)
              mYear = '19' + mYear;
              else
              mYear = '20' + mYear;
              }
            var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
            if (!dateValid(vDateValueCheck))
              {
              alert("La date inscrite est non valide \n Veuillez la vérifier");
              vDateName.value = "";
              vDateName.focus();
              vDateName.select();
              return false;
              }
            return true;
            }
          else
            {
            if (vDateValue.length >= 8  && dateCheck)
              {
              if (vDateType == 3)
                {
                var mMonth = vDateName.value.substr(2,2);
                var mDay = vDateName.value.substr(0,2);
                var mYear = vDateName.value.substr(4,4)
                vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
                }
              var vDateTypeTemp = vDateType;
              vDateType = 1;
              var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
              if (!dateValid(vDateValueCheck))
                {
                alert("La date inscrite est non valide \n Veuillez la vérifier");
                vDateType = vDateTypeTemp;
                vDateName.value = "";
                vDateName.focus();
                vDateName.select();
                return false;
                }
              vDateType = vDateTypeTemp;
              return true;
              }
            else
              {
              if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1))
                {
                alert("La date inscrite est non valide \n Veuillez la vérifier");
                vDateName.value = "";
                vDateName.focus();
                vDateName.select();
                return false;
                }
              }
            }
          }
        else
          {
          if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1))
            {
            alert("La date inscrite est non valide \n Veuillez la vérifier");
            vDateName.value = "";
            vDateName.focus();
            return true;
            }
          if (vDateValue.length >= 8 && dateCheck)
            {
            if (vDateType == 3) // dd/mm/yyyy
              {
              var mDay = vDateName.value.substr(0,2);
              var mMonth = vDateName.value.substr(3,2);
              var mYear = vDateName.value.substr(6,4)
              }
            if (vYearLength == 4)
              {
              if (mYear.length < 4)
                {
                alert("La date inscrite est non valide \n Veuillez la vérifier");
                vDateName.value = "";
                vDateName.focus();
                return true;
                }
              }
            var vDateTypeTemp = vDateType;
            vDateType = 1;
            var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
            if (mYear.length == 2 && vYearType == 4 && dateCheck)
              {
              var mToday = new Date();
              var checkYear = mToday.getFullYear() + 30;
              var mCheckYear = '20' + mYear;
              if (mCheckYear >= checkYear)
              mYear = '19' + mYear;
              else
              mYear = '20' + mYear;
              vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
              if (vDateTypeTemp == 3)
              vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
              }
            if (!dateValid(vDateValueCheck))
              {
              alert("La date inscrite est non valide \n Veuillez la vérifier");
              vDateType = vDateTypeTemp;
              vDateName.value = "";
              vDateName.focus();
              return true;
              }
            vDateType = vDateTypeTemp;
            return true;
            }
          else
            {
            if (vDateType == 1)
              {
              if (vDateValue.length == 2)
                {
                vDateName.value = vDateValue+strSeperator;
                }
              if (vDateValue.length == 5)
                {
                vDateName.value = vDateValue+strSeperator;
                }
              }
            if (vDateType == 2)
              {
              if (vDateValue.length == 4)
                {
                vDateName.value = vDateValue+strSeperator;
                }
              if (vDateValue.length == 7)
                {
                vDateName.value = vDateValue+strSeperator;
                }
              }
            if (vDateType == 3)
              {
              if (vDateValue.length == 2)
                {
                vDateName.value = vDateValue+strSeperator;
                }
              if (vDateValue.length == 5)
                {
                vDateName.value = vDateValue+strSeperator;
                }
              }
            return true;
            }
          }
        if (vDateValue.length == 10&& dateCheck)
          {
          if (!dateValid(vDateName))
            {
            alert("La date inscrite est non valide \n Veuillez la vérifier");
            vDateName.focus();
            vDateName.select();
            }
          }
        return false;
        }
      else
        {
        if (isNav4)
          {
          vDateName.value = "";
          vDateName.focus();
          vDateName.select();
          return false;
          }
        else
          {
          vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
          return false;
          }
        }
      }
    }

function dateValid(objName)
  {
  var strDate;
  var strDateArray;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var booFound = false;
  var datefield = objName;
  var strSeparatorArray = new Array("-"," ","/",".");
  var intElementNr;
  var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    strDate = objName;
  if (strDate.length < 1)
    {
    return true;
    }
  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
    {
    if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
      {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);
      if (strDateArray.length != 3)
        {
        err = 1;
        return false;
        }
      else
        {
        strDay = strDateArray[0];
        strMonth = strDateArray[1];
        strYear = strDateArray[2];
        }
      booFound = true;
      }
    }
  if (booFound == false)
    {
    if (strDate.length>5)
      {
      strDay = strDate.substr(0, 2);
      strMonth = strDate.substr(2, 2);
      strYear = strDate.substr(4);
      }
    }
    if (strYear.length == 2)
      {
      strYear = '20' + strYear;
      }
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
    intday = parseInt(strDay, 10);
    if (isNaN(intday))
      {
      err = 2;
      return false;
      }
    intMonth = parseInt(strMonth, 10);
    if (isNaN(intMonth))
      {
      for (i = 0;i<12;i++)
        {
        if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase())
          {
          intMonth = i+1;
          strMonth = strMonthArray[i];
          i = 12;
          }
        }
      if (isNaN(intMonth))
        {
        err = 3;
        return false;
        }
      }
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear))
      {
      err = 4;
      return false;
      }
    if (intMonth>12 || intMonth<1)
      {
      err = 5;
      return false;
      }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
      {
      err = 6;
      return false;
      }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
      {
      err = 7;
      return false;
      }
    if (intMonth == 2)
      {
      if (intday < 1)
        {
        err = 8;
        return false;
        }
      if (LeapYear(intYear) == true)
        {
        if (intday > 29)
          {
          err = 9;
          return false;
          }
        }
      else
        {
        if (intday > 28)
          {
          err = 10;
          return false;
          }
        }
      }
    return true;
  }

function LeapYear(intYear)
  {
  if (intYear % 100 == 0)
    {
    if (intYear % 400 == 0) { return true; }
    }
  else
    {
    if ((intYear % 4) == 0) { return true; }
    }
  return false;
  }

////////////////////////////////
//   Vérification Téléphone   //
////////////////////////////////


//juste pour checker si cest netscape/mozilla
var isNS4 = (navigator.appName=="Netscape")?1:0;

function check_tel01()
  {
  if(!isNS4)
    {
    if(event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
    }
    else
    {
    if(event.which < 45 || event.which > 57) returnfalse;
    }
  }

var re = /^\(?(\d{2})\)?[\.\-\/ ]?(\d{2})[\.\-\/ ]?(\d{2})?[\.\-\/ ]?(\d{2})?[\.\-\/ ]?(\d{2})$/

function check_tel02(telinput)
  {
  validPhone = re.exec(telinput.value)
  if (validPhone)
    {
    telinput.value = validPhone[1] + "." + validPhone[2] + "." + validPhone[3] + "." + validPhone[4] + "." + validPhone[5]
    }
  else
    {
    alert('Votre numéro de téléphone doit avoir le format "##########" \n' + 'Par exemple : "0145472200"')
    telinput.focus()
    telinput.select()
    }
  return false
  }

////////////////////////////////
//     Vérification nombre    //
////////////////////////////////

function check_num() {
  //juste pour checker si cest netscape/mozilla
  var isNS4 = (navigator.appName=="Netscape")?1:0;

  if(!isNS4)
  {
    if(event.keyCode < 46 || event.keyCode > 57 || event.keyCode==47) event.returnValue = false;
  }
  else
  {
    if(event.which < 46 || event.which > 57 || event.which==47) return false;
  }
  return true;
}

function check_num2(numinput) {
  reNum = /^[0-9]*.?[0-9]*$/
  validNum = reNum.exec(numinput.value)
  if (!validNum)
    {
    alert('Le champ doit être au format "####.##" \n' + 'Par exemple : "1234.12"')
    numinput.focus()
    numinput.select()
    }
  return false
}


////////////////////////////////
//     Vérification email     //
////////////////////////////////

function mail_ok(mailinput)
    {
    var a,i,j,k;
    i=0;
    k=0;
    //alert('mailinput.value = ' + mailinput.value);
	var lst = document.getElementsByName(mailinput.name);
	//var lst = mailinput.value;
	if(lst.length == 0)
	{
		lst = document.getElementsByName(mailinput.name);
		//lst = mailinput.value;
	}
	a = lst[0].value;
    for(j=0; j<a.length-1;j++)
	{
	if(a.charAt(j)=="@")
			i++;
	}
    for(j=0; j<a.length-1;j++)
	{
	if(a.charAt(j)==".")
			k++;
	}
    if(i!=1 || k<1)
	{
	alert('Une adresse e-mail doit avoir le format "utilisateur@domain.com" \n' + 'Par exemple : "george.dupont@net.com"');
	return false;
	}
    }
    
function validate(sender,myarray,err_hd) {

var message_erreur = !err_hd?new Array('Les erreurs suivantes sont survenues:\n'):new Array(err_hd+'\n');
var error = false;


for (i=0;i<myarray.length;i++) {
  //field = document.forms[sender.name].elements[myarray[i][0]];
    field = document.forms[sender].elements[myarray[i][0]];
	
/* Bloc 1 vérifie les champs qui doivent être renseignés */
  if (myarray[i][1].indexOf('e')>-1) {
    if (!field.value) {
      error = true;
      message_erreur.push(myarray[i][2]);
    }
  }

/* Bloc 2 vérifie si l'adresse électronique est correcte dans la forme */
  else if (myarray[i][1].indexOf('m')>-1) {
    if (field.value) {
      var usr = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
      var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
      var regex = "^"+usr+"\@"+domain+"$";
      var myrxp = new RegExp(regex);
      var check = (myrxp.test(field.value));
        if (check!=true) {
          error=true;
          message_erreur.push(field.value+" "+myarray[i][2]);
        }
      }
    }

/* Bloc 3 vérifie les champs dont la valeur doit être numérique */
  else if (myarray[i][1].indexOf('n')>-1) {
    var num_error = false;
    if(field.value) {
      var myvalue = field.value;
      var num = myvalue.match(/[^0-9,\.]/gi)
      var dot = myvalue.match(/\./g);
      var com = myvalue.match(/,/g);
      if (num!=null) {
        num_error = true;
      }
      else if ((dot!=null)&&(dot.length>1)) {
        num_error = true;
      }
      else if ((com!=null)&&(com.length>1)) {
        num_error = true;
      }
      else if ((com!=null)&&(dot!=null)) {
        num_error = true;
      }
    }
	
    if (num_error==true) {
       
		error = true;
		// gestion des CA
		// le message =myarray[i][2]
		if (myarray[i][0].indexOf("cam")==0)
		{
			
			var borne=myarray[i][0].substring(2,5);
			var numero=myarray[i][0].substring(5,6);
			if (borne=="min")
			{
				message_erreur.push("Le CA minimal du crit\350re "+numero+" "+myarray[i][2]);
			}
			else if (borne=="max")
			{
				message_erreur.push("Le CA maximal du crit\350re "+numero+" "+myarray[i][2]);
			}
		}
		else
		{
        message_erreur.push(myvalue+" "+myarray[i][2]);
		}
    }
  }

/* Bloc 3 bis vérifie les champs dont la valeur doit être numérique */
  else if (myarray[i][1].indexOf('x')>-1) {
    var num_error = false;
    if(field.value) {
      var myvalue = field.value;
      var num = myvalue.match(/[^0-9]/gi)

      if (num!=null) {
        num_error = true;
      }
      /*else if ((dot!=null)&&(dot.length>1)) {
        num_error = true;
      }
      else if ((com!=null)&&(com.length>1)) {
        num_error = true;
      }
      else if ((com!=null)&&(dot!=null)) {
        num_error = true;
      }*/
    }
	
    if (num_error==true) {
       
		error = true;
		// gestion des CA
		// le message =myarray[i][2]
		if (myarray[i][0].indexOf("cam")==0)
		{
			
			var borne=myarray[i][0].substring(2,5);
			var numero=myarray[i][0].substring(5,6);
			if (borne=="min")
			{
				message_erreur.push("Le CA minimal du crit\350re "+numero+" "+myarray[i][2]);
			}
			else if (borne=="max")
			{
				message_erreur.push("Le CA maximal du crit\350re "+numero+" "+myarray[i][2]);
			}
		}
		else if (myarray[i][0]=="ca")
		{
			message_erreur.push("Le CA "+myarray[i][2]);
		}
		else
		{
        message_erreur.push(myvalue+" "+myarray[i][2]);
		}
    }
  }
  
/* Bloc 4 vérifie la valeur à l'aide d'une expression régulière sur un modèle déterminé */
  else if (myarray[i][1].indexOf('r')>-1) {
    var regexp = myarray[i][3];
    if (field.value) {
      if (!regexp.test(field.value)) {
        error = true;
        message_erreur.push(field.value+" "+myarray[i][2]);
      }
    }
  }

/* Bloc 5 vérifie les champs qui doivent être formatés comme des prix et modifie éventuellement le formatage */
  else if (myarray[i][1].indexOf('p')>-1) {
    var myvalue = field.value;
    var reg = /,-{1,}|\.-{1,}/;
    var nantest_value = myvalue.replace(reg,"");
    var num = nantest_value.match(/[^0-9,\.]/gi)
    sep = myarray[i][1].substr(1,1)?myarray[i][1].substr(1,1):',';
    if (field.value) {
      var myvalue = field.value.replace(/\./,',');
      if (myvalue.indexOf(',')==-1) {
        field.value = myvalue+sep+'00';
      }
      else if (myvalue.indexOf(",--")>-1) {
        field.value = myvalue.replace(/,--/,sep+'00');
      }
      else if (myvalue.indexOf(",-")>-1) {
        field.value = myvalue.replace(/,-/,sep+'00');
      }
      else if (!myvalue.substring(myvalue.indexOf(',') + 2)) {
        error=true;
        message_erreur.push(field.value+" "+myarray[i][2]);
      }
      else if (myvalue.substring(myvalue.indexOf(',') + 3)!='') {
        error=true;
        message_erreur.push(field.value+" "+myarray[i][2]);
      }
      else if (num!=null) {
        error=true;
        message_erreur.push(field.value+" "+myarray[i][2]);
      }
    }
  }

/* Bloc 6 vérifie les champs de nom et rectifie éventuellement la casse */
  else if (myarray[i][1].indexOf('c')>-1) {
    var noble = new Array(" d\'", "de","von","van","der","d","la","da","of");
    var newvalue='';
    var myvalue = field.value.split(/\b/);
    for (k=0;k<myvalue.length;k++) {
      newvalue+= myvalue[k].substr(0,1).toUpperCase()+myvalue[k].substring(1);
    }
    for(k=0;k<noble.length;k++){
      var reg = new RegExp ("\\b"+noble[k]+"\\b","gi");
      newvalue = newvalue.replace(reg,noble[k]);
    }
    field.value = newvalue;
  }
/* Bloc 7 vérifie la longueur des champs */
  else if (myarray[i][1].indexOf('l')>-1) {
    var longueur = myarray[i][3];
    //alert (longueur + ' - '+field.value);
    if (field.value) {
      if (field.value.length>longueur) {
        error = true;
		message_erreur.push("la valeur "+field.value+" "+myarray[i][2]);

      }
    }
   }
   //alert(field.name+" "+field.value);
}

/* En cas d'erreur, les messages d'erreur récoltés sont exploités ici puis affichés.
   Si le formulaire est correctement rempli, il est transmis */
  if (error) {
    message_erreur = message_erreur.join('\n\xB7 ');
    alert(message_erreur);
    return false;
  }
  else {
	return true;
  }
}

function doesExist(fonction) {
	doesExist = typeof(this[fonction])!='undefined' ? typeof(this[fonction])=='function' : false;
   return doesExist;

}

/* Script de test de longueur de textarea */
function testlongueur(champ, longueur, msg) 
{ 
        controlelongueur(champ, longueur, msg); 
        var data = champ.value; 
        var val = data.length; 
        if(val > longueur) 
        { 
                champ.focus(); 
                alert("Texte trop long !"); 
        } 
} 



function controlelongueur(champ, lmax, msg) 
{ 
        var txt=champ.value; 
        var nb= txt.length+1; 
        var msgtxt = ""; 
        if (nb>lmax) 
        { 
                champ.value=txt.substring(0,lmax); 
                nb=lmax; 
                msgtxt = "limite atteinte"; 
        } 
        
        var obj = document.getElementById(msg); 
        if(obj!=null) 
        { 
                   obj.innerHTML=msgtxt; 
           } 
} 
