
function emailLink(){
  var a = emailLink.arguments;
  var ret = "";
  if(a.length >= 3){
    for(i=2; i<a.length; i++){
      ret += a[i]+'.';
    }
    ret = ret.substr(0, ret.length - 1)+'@'+a[1];
  }
  document.write('<a href="mailto:'+ret+'" class="contact_lien">'+a[0]+'</a>');
}

function checkformConcours(f){
  msg = new Array();
  message = '';
  cptErrors=0;
  
  champs = new Array();  
  champs[0]='nom';
  champs[1]='prenom';
  champs[2]='npa';
  champs[3]='localite';
  champs[4]='email';
  champs[5]='telephone';
  champs[6]='birthdate';

  focusme = 0;
  
  for (i=0; i<champs.length; i++){
    $('#lbl-'+champs[i]).removeClass('lbl_error');
    $('#'+champs[i]).removeClass('field_error');
  }

  if (!email_valide($('#email').val())){
    $('#lbl-email').addClass('lbl_error');
    $('#email').addClass('field_error');
    msg[cptErrors] ='        - Adresse email invalide !';
    cptErrors++;
    focusme = 4;
  }
  
  for (i=champs.length-1; i>=0; i--){
    if (trim($('#'+champs[i]).val())==''){
      $('#lbl-'+champs[i]).addClass('lbl_error');
      $('#'+champs[i]).addClass('field_error');
      if (i != focusme){
        focusme = i;
      }
      msg[cptErrors] ='        - Champ obligatoire : '+champs[i].toUpperCase();
      cptErrors++;
    }
  }
  
  if (msg.length > 0){
    message = '     LE FORMULAIRE COMPORTE DES ERREURS :     \n\n';
    for (i=msg.length-1;i>=0;i--){
      message += msg[i] +'\n';
    }
    alert(message);
    $('#'+champs[focusme]).select();
    return false;
  }

  return true;
}


function checkformCourrier(f){
  
  msg = new Array();
  message = '';
  cptErrors=0;
  
  champs = new Array();  
  champs[0]='nom';
  champs[1]='email';
  champs[2]='adresse';
  champs[3]='cp';
  champs[4]='lieu';
  champs[5]='message';
  
  focusme = 0;
  
  for (i=0; i<champs.length; i++){
    $('#lbl-'+champs[i]).removeClass('lbl_error');
    $('#'+champs[i]).removeClass('field_error');
  }

  if (!email_valide($('#email').val())){
    $('#lbl-email').addClass('lbl_error');
    $('#email').addClass('field_error');
    msg[cptErrors] ='        - Adresse email invalide !';
    cptErrors++;
    focusme = 1;
  }
  
  for (i=champs.length-1; i>=0; i--){
    if (trim($('#'+champs[i]).val())==''){
      $('#lbl-'+champs[i]).addClass('lbl_error');
      $('#'+champs[i]).addClass('field_error');
      if (i != focusme){
        focusme = i;
      }
      msg[cptErrors] ='        - Champ obligatoire : '+champs[i].toUpperCase();
      cptErrors++;
    }
  }
  
  if (msg.length > 0){
    message = '     LE FORMULAIRE COMPORTE DES ERREURS :     \n\n';
    for (i=0;i<msg.length;i++){
      message += msg[i] +'\n';
    }
    alert(message);
    $('#'+champs[focusme]).select();
    return false;
  }

  return true;
}


function email_valide(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}


function trim(str) {
  return str.replace(/^\s+|\s+$/g, '') ;
}

function reload_pub(){
  //alert('Rechargement des pubs de la page...');
}
