//nom fenêtre de retour SPPLUS
/*** DISABLED DURING PREINSCRIPTION ***/
self.name="sitecom";
function doSubmit() {
  var oForm=document.getElementById("form01");
  if(verifyForm(oForm)) {
    var sLink = 'message_attente';
    if(sLang=='en'||sLang=='es') sLink+='_'+sLang;
    var oPop=window.open(sLink+'.html','SPPLUS','width=750,height=560,left=20,top=20');
    //oPop.focus();
    //oForm.submit();
    //document.location.href='index.html';
  }
  return false;
} 


/*** AJAX INIT ***/
$.ajax({
  contentType: "application/x-www-form-urlencoded;charset=Windows-1252"
});
/*** ERROR MESSAGES ***/
switch(sLang) {
  case 'en' :
    aMessage[30001]="Our files already show a registration with the same last name, first name and date of birth. (^)";
    aMessage[30002]="The confirmation EMAIL (^) does not match\nyour EMAIL address(^).";
    aMessage[30011]="The date of birth is incorrect.";
    aMessage[30012]="To participate in the marathon of Grand Toulouse you have to be born before october the 25th, 1989.";
    aMessage[30013]="To participate in the relay of Grand Toulouse you have to be born before october the 25th, 1991.";
    break;
  case 'es' :
    aMessage[30001]="Nuestros archivos muestran ya un registro con el mismo nombre, nombre y fecha de nacimiento. (^)";
    aMessage[30002]="El valor del correo electrónico `^` no corresponde con el valor de confirmación del correo electrónico `^`.";
    aMessage[30011]="El fecha de nacimiento es incorrecto.";
    aMessage[30012]="Para participar al maratón los participantes deben haber nacido antes del 25 de octubre de 1989.";
    aMessage[30013]="Para participar al maratón por relevos los participantes deben haber nacido antes del 25 de octubre de 1991.";
    break;
  default:
    aMessage[30001]="Une inscription portant votre nom, prénom et date de naissance existe deja dans nos dossiers. (^)";
    aMessage[30002]="L'adresse EMAIL de CONFIRMATION (^) ne correspondent pas avec \nl'adresse EMAIL (^).";
    aMessage[30011]="La date de naissance est incorrecte.";
    aMessage[30012]="Pour participer au marathon vous devez être nés avant le 25 octobre 1989.";
    aMessage[30013]="Pour participer au relais les participants doivent être nés avant le 25 octobre 1991.";
    break;
}
/*** TRAITEMENT DES CHAMP OPTIONNELS ***/
$(document).ready( function () {
  /*** UPPERCASE ***/
  $("#id0101,#id0107,#id0108,#id0118,#id0123,#id0128").change(function(){this.value=this.value.toUpperCase()});
  $("#id0102,#id0119,#id0124,#id0129").change(function(){
    var rSep=new RegExp(/[\s-]/);
    var aSep=rSep.exec(this.value);
    var aPrenom=this.value.split(rSep);
    this.value="";
    for(var p=0;p<aPrenom.length;p++) this.value+=aPrenom[p].substr(0,1).toUpperCase()+aPrenom[p].substr(1).toLowerCase()+(aSep && aSep[p]?aSep[p]:"");
  });
  /*** VERIFICATION DOUBLONS INSCRIPTION ***/
  $("#id0101,#id0102,#id0103").change(function() {
    var dToday=new Date();
    if($("#id0101").val().length>0
      && $("#id0102").val().length>0
      && $("#id0103").val().length>0 ) {
        $.post('checkDoublons.js',{annee: dToday.getFullYear(), nom: $("#id0101").val(), prenom: $("#id0102").val(), dob: $("#id0103").val()},
          function(data) { 
            eval(data);
            if(sDossier.length>0) {
              alert(aMessage[30001].toError(sDossier).message);
            } 
          },"script");
    }
  });
  /*** VERIFICATION DE L'ADRESSE MAIL ***/
  $("#id0111").change(function(e) {
    $("#id011101").val('');
  });
  $("#id011101").change(function(e) {
    if($(this).val()!=$("#id0111").val()) {
      $(this).select();
      alert(aMessage[30002].toError($(this).val(),$("#id0111").val()).message);
      $(this).val("");
    }
  }); 
  /*** OUVRIR INPUT TELECHARGEMENT LICENSE ***/
  $(":input[name=input0114]").click(function(){
      $("#para011403,#para011404,#para011405,#para011406").show("slow");
  });
  /*** OUVRIR INPUT TELECHARGEMENT SAS ***/
  $(":input[name=input0115]").click(function(){
      $("#para011505,#para011506").show("slow");
  });
});
/*** FUNCTION TO CHECK AGE ***/ 
var oDate;
var sMarType=/relais/i.test(document.location.href)?"rel":"mar";
function checkDate(oField) {
  if(!oField.value)  return false;
  oDate=oField;
  var dDateMarMin=new Date(1989,9,25);
  var dDateRelMin=new Date(1991,9,25);
  if(sMarType=="rel") {
    var dDateMin=dDateRelMin; 
    var sMessage=aMessage[30013];
  } else {
    var dDateMin=dDateMarMin; 
    var sMessage=aMessage[30012];
  }
  var aDate=oDate.value.split(/[\D]/);
  var dDate=new Date(aDate[2],aDate[1] - 1,aDate[0]);
  if(isNaN(dDate)) {
    alert(aMessage[30011]);
    window.setTimeout("oDate.select()",10)
  return false;
  }
  if(dDate>=dDateMin) {
    alert(sMessage);
    window.setTimeout("oDate.select()",10)
    return false
  } else {
    return true;
  }
}
