function eCheckAlphaNum(sn){
    s= sn.value;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if (!((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
           || (ch >= "0" && ch <= "9")))
             return false;
        }
   return true;
}
function CheckAlphaNum(theForm){
   for(var i=1; i<CheckAlphaNum.arguments.length; i++)
         if (!eCheckAlphaNum(theForm.elements[CheckAlphaNum.arguments[i]])){
            alert("Champs invalide");
            theForm.elements[CheckAlphaNum.arguments[i]].focus();
            return false;
        }
   return true;
}

function eCheckEMail(sn){
    s= sn.value;
    if (s == "") return true;
    if (s.indexOf("@") == -1) return false;
    if (s.indexOf(".") == -1) return false;
    at=false;
    dot=false;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                if (ch == "@"){
                  if (at) return false;
                  else at=true;
                }
                if ((ch==".") && at)
                   dot=true;
        }
        else return false;
    }
   return dot;
}

function eCheckNum(sn){
    s= sn.value;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if (!(ch >= "0" && ch <= "9"))
             return false;
        }
   return true;
}
function CheckNum(theForm){
   for(var i=1; i<CheckNum.arguments.length; i++)
         if (!eCheckNum(theForm.elements[CheckNum.arguments[i]])){
            alert("Nombre requis");
            theForm.elements[CheckNum.arguments[i]].focus();
            return false;
        }
   return true;
}

function CheckEMail(theForm){
   for(var i=1; i<CheckEMail.arguments.length; i++)
         if (!eCheckEMail(theForm.elements[CheckEMail.arguments[i]])){
            alert("Email invalide");
            theForm.elements[CheckEMail.arguments[i]].focus();
            return false;
        }
   return true;
}

function CheckRequiredFields(theForm) {
   for(i=1; i<CheckRequiredFields.arguments.length; i++)
        if(theForm.elements[CheckRequiredFields.arguments[i]].value==""){
            alert("Champs requis");
            theForm.elements[CheckRequiredFields.arguments[i]].focus();
            return false;
        }
   return true;
}

function CheckFormExemple(theForm){
     if(CheckRequiredFields(theForm, 1))
     if(CheckAlphaNum(theForm,  1))
          return true;
  return false;
}
function eCheckDate(sn) {
      s= sn.value;
	  if (s == '') return true;
      var i=0;
      tm= new Array();
      tm[0]= '';tm[1]= '';tm[2]='';tm[3]='';
      sep='';
      md = 0 ;

      while (i< s.length) {
          ch= s.substring(i, i + 1);
          if( ch<='9' && ch>='0')
              tm[md] += ch;
          else if (sep=='') {
              if(ch=='/') {
                   md++;
                   sep=ch;
              }
          }
          else if (ch==sep) {
             md++;
             if(md>2) return false;
          }
          else return false;

          i++;
      }

      if(tm[3]!='') return false;
      if(tm[0].valueOf()<1 || tm[0].valueOf()>31) return false; 
      if(tm[1].valueOf()<1 || tm[1].valueOf()>12) return false;//Month
      if(tm[2].valueOf()<100) return false;

      if ((tm[1]==4 || tm[1]==6 || tm[1]==9 || tm[1]==11) && tm[0]==31)
          return false;
      if (tm[1]==2) {
           isleap = (tm[2] % 4 == 0 && (tm[2] % 100 != 0 || tm[2] % 400 == 0));
           if (tm[0]>29 || (tm[0]==29 && !isleap))
                return false;
      }

      return (tm[3]=='');
}

function CheckDate(theForm){
   for(var i=1; i<CheckDate.arguments.length; i++)
         if (!eCheckDate(theForm.elements[CheckDate.arguments[i]])){
            alert("Date Invalide\nFormat : jj/mm/aaaa");
            theForm.elements[CheckDate.arguments[i]].focus();
            return false;
        }
   return true;
}
function eCheckFloat(sn){
    s= sn.value;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if (!((ch >= "0" && ch <= "9") || ch=="." || ch==","))
             return false;
        }
   return true;
}

function CheckFloat(theForm){
   for(var i=1; i<CheckFloat.arguments.length; i++)
         if (!eCheckFloat(theForm.elements[CheckFloat.arguments[i]])){
            alert("Format Téléphone: \n 00.00.00.00.00");
            theForm.elements[CheckFloat.arguments[i]].focus();
            return false;
        }
   return true;
}

function eCheckRadio(sn){
   if (!sn.checked)
             return false;
    return true;
 }
 
function CheckRadio(theForm,name){
   val = false;
    for(var i=2; i<CheckRadio.arguments.length; i++)
{
if(eCheckRadio(theForm.elements[CheckRadio.arguments[i]]))
 		val = true
    }
   if(!val) {
	alert('Il faut cocher une des cases de: '+name);
	 	theForm.elements[CheckRadio.arguments[2]].focus();
 }
    return val
 }
