function Chiffre(Valeur,Type){
var checkOK = "0123456789";	
if(Type.toUpperCase()=="TEL"){checkOK+="(+) "}
if(Type.toUpperCase()=="AGENCE"){checkOK+="-"}
if(Type.toUpperCase()=="CHIF-"){checkOK+="-., "}
if(Type.toUpperCase()=="DEVICE"){checkOK+="FRF,. EUR"}

  var checkStr = Valeur
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
return allValid;
}

function Valid_Form(theForm){
	for ( var i= 0 ; i < theForm.elements.length  ; i++) // champs non modiable
		if (theForm.elements[i].type == 'text') 
			theForm.elements[i].value = theForm.elements[i].value.trim() ;

  if (theForm.f_Nom.value == "")
  {
    alert("Indiquez votre nom dans le champ \"Nom\".");
    theForm.f_Nom.focus();
    return (false);
  }

  if (theForm.f_Prenom.value == "")
  {
    alert("Indiquez votre Prénom dans le champ \"Prénom\".");
    theForm.f_Prenom.focus();
    return (false);
  }

  if (theForm.f_Tel.value.length < 10)
  {
    alert("Tapez au moins 10 chiffres dans le champ \"Téléphone\".");
    theForm.f_Tel.focus();
    return (false);
  }

  if (!Chiffre(theForm.f_Tel.value,"tel"))
  {
    alert("Ne tapez que  '(+) 0123456789' caractères dans le champ 'Téléphone'.");
    theForm.f_Tel.select();
    return (false);
  }

  
  if (theForm.f_Appel.selectedIndex < 1)
  {
    alert("Sélectionnez votre \"Préférence télephonique\".");
    theForm.f_Appel.focus();
    return (false);
  }

  if (theForm.f_Adr1.value == "")
  {
    alert("Précisez votre adresse dans le champ \"Adresse\".");
    theForm.f_Adr1.focus();
    return (false);
  }

var CP=RenvoiNum(theForm.f_CP.value);
  if( (CP==0) || (CP<1000) || (CP>99999) )
  {
    alert("Tapez une valeur en 5 chiffres pour le champ \"Code postal\".");
    theForm.f_CP.focus();
    return (false);
  }


  if (theForm.f_Ville.value == "")
  {
    alert("Précisez la ville dans le champ \"Ville\".");
    theForm.f_Ville.focus();
    return (false);
  }

// Controle adresse email 
var checkStr = Valid_Email(theForm.f_Email.value, 'Indiquez votre adresse E-mail pour obtenir une réponse.')
if (checkStr == '')
   { 
    theForm.f_Email.focus()
    return (false);
   }

if (theForm.name != 'BDBCandidature') { 
  if (theForm.f_Client.selectedIndex < 1)
  {
    alert("Précisez  \"Votre situation\".");
    theForm.f_Client.focus();
    return (false);
  }

  if (!Chiffre(theForm.f_Agence.value,"agence"))
  {
    alert("Ne tapez que  chiffre caractères dans le champ \"N° d'Agence BNP\".");
    theForm.f_Agence.select();
    return (false);
  }
    if (theForm.f_Message.value.length > 300)
  {
    alert("Tapez au plus 300 caractères dans le champ \"Votre message\".");
    theForm.message.focus();
    return (false);
  }
  
} 
// if (theForm.name == 'BDBCandidature') {
//	theForm.f_mailto.value = 'bdb_recrutement@banque-de-bretagne.fr' ; 
// }
return true;
}


function return_date(strval) {
var strdate = new String(strval);
if (strdate.length < 8 )return '' ;

// strdate = strdate.replace (/(\/)/g , '.');
var DateNow = new Date(); 
var anneeNow = parseInt(DateNow.getFullYear()) ;
var jourNow = parseInt(DateNow.getDate()) ;
var moisNow = parseInt(DateNow.getMonth()) + 1 ;
var lastday = [ 0, 31 , 29 , 31 , 30 , 31, 30 , 31, 31, 30, 31, 30, 31 ] ;
var reg1 = /^\d{2}\/\d{2}\/\d{4}/ ;
var reg2 = /^\d{2}\d{2}\d{4}/ ;
var frm1 = reg1.test(strdate)  ;
var frm2 = reg2.test(strdate)  ;
if (frm1 == false && frm2 == false) return '' ;
var pm = (frm1 == true) ? 3 : 2 ;
var pa = (frm1 == true) ? 6 : 4 ;

var sday = strdate.substring(0,2) ;
var smois = strdate.substring(pm, pm + 2) ;
var sann = strdate.substring(pa);
var nday = parseFloat (sday) ;
var nmois = parseFloat (smois) ;
var nann = parseFloat (sann) ;
// if (nann < anneeNow ) return '' ;
if (nann > (anneeNow - 18) ) return '' ; // majeur
// if (nmois > 12 || nmois < 1  || (nann == anneeNow && nmois < moisNow ) ) return '' ;
if (nmois > 12 || nmois < 1 ) return '' ;
// if (nday > lastday[nmois] || nday < 1 || (nann == anneeNow && nmois == moisNow && nday <= jourNow )) return '' ;
if (nday > lastday[nmois] || nday < 1 ) return '' ;
return (sday + '/' + smois + '/' + sann) ;
}	

// trim 
String.prototype.trim = function()
{ return this.replace(/(^\s*)|(\s*$)/g, ""); }
