/******************************************************************************
 *                                                                            *
 *  Fonctions popup  pub                                        		      *
 *                                                                            * 
 *  ***************************************************************************/ 
function popupinfo(largeur,hauteur) {

  var haut=(screen.height-hauteur)/2;
  var gauche=(screen.width-largeur)/2;
  window.open('pop_loto2.htm','prochainement','top='+haut+',left='+gauche+',width='+largeur+',height='+hauteur+',resizable=yes,toolbar=no,scrollbars=no,location=no');
}
/******************************************************************************
 *                                                                            *
 *  Fonctions popup  radio                                        		      *
 *                                                                            * 
 *  ***************************************************************************/ 
function popupradio(largeur,hauteur) {

  var haut=(screen.height-hauteur)/2;
  var gauche=(screen.width-largeur)/2;
  window.open('./radio/','popupradio','top='+haut+',left='+gauche+',width='+largeur+',height='+hauteur+',resizable=yes,toolbar=yes,scrollbars=yes,location=no');
}

/******************************************************************************
 *                                                                            *
 *  Defilement info status bar                                                *
 *                                                                            * 
 *  ***************************************************************************/ 
var Mess="18 . 18 . 18 - Centre d'Incendie et de Secours de Goncelin - Isère (38) : Site Officiel - 18 . 18 . 18";
var place=1;
function scrollIn() {
window.status=Mess.substring(0, place);
if (place >= Mess.length) {
place=1;
window.setTimeout("scrollOut()",300);
} else {
place++;
window.setTimeout("scrollIn()",100);
   } 
}
function scrollOut() {
window.status=Mess.substring(place, Mess.length);
if (place >= Mess.length) {
place=1;
window.setTimeout("scrollIn()",300);
} else {
place++;
window.setTimeout("scrollOut()",100);
   }
}

/******************************************************************************
 *                                                                            *
 *  validation de formulaires                                                *
 *                                                                            * 
 *  ***************************************************************************/ 
function CheckDate(d) {

      // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
      // Le séparateur est défini dans la variable separateur
      var amin=1955; // année mini
      var amax=2005; // année maxi
      var separateur="/"; // separateur entre jour/mois/annee
      var j=(d.substring(0,2));
      var m=(d.substring(3,5));
      var a=(d.substring(6));
      var ok=1;
      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
          ok=0;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
          ok=0;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
          ok=0;
      }
      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) {
          ok=0;
      }
      if (ok==1) {
         var d2=new Date(a,m-1,j);
         j2=d2.getDate();
         m2=d2.getMonth()+1;
         a2=d2.getYear();
         if (a2<=100) {a2=1900+a2}
         if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
         
            ok=0;
         }
      }
      return ok;
   }


//expressions regulieres
var exp_nom = /[a-zA-Z\s\-]{1,25}/ ;
var exp_prenom = /[a-zA-Z\s\-]{1,25}/;
var exp_numrue = /\d{0,5}/;
var exp_rue = /\w{1,40}/;
var exp_cp=/[0-9][0-9]\d{3}/;
var exp_ville=/[a-zA-Z\-\s]{1,25}/;
var exp_email=/^[a-z][a-z_0-9\.]+@[a-z_0-9\.]+\.[a-z]{2,3}$/i;
var exp_pssw = /\w{4,25}/;
var exp_login = /\w{4,25}/;
var exp_tel = /\d{10}/;
var exp_surface = /^\d{0,10}$/;
var exp_prix = /^\d{0,10}$/;
var exp_jpg = /^.*[\.]{1}[j]{1}[p]{1}[e]?[g]{1}$/i;
var exp_ref = /^[a-zA-Z0-9]{0,10}$/;
var exp_date = /^[0-3][0-9]\/[0-1][0-9]\/\d{3}/;


//initialisation des variables necessaire pour la verif du formulaire
var message="";
var msgbox=false;
var blank="";

//fonction de validation d'expression
function isValid(pattern, str){
    return pattern.test(str);
}
//fonction de construction du message d'erreur
var cpt=0;
function buildmess(champ) {
         //alert ("coucou");
    msgbox=true;
    cpt++;
    message+=blank+champ;
    if (blank=="") {
       blank = ", " ;
    }
}
//fonction de verification de formulaire
function veriform(form){
	if (document.getElementById('form_recrutement')) {
			   if ((form.telpor.value!='') && (!isValid(exp_tel,form.telpor.value))){
          buildmess("Autre Téléphone");
          form.telpor.value="";
          form.telpor.focus();
	           }
			   if ((form.email.value!='') && (!isValid(exp_email,form.email.value))){
				  buildmess("Email");
				  form.email.value="";
				  form.email.focus();
			   }
			   if ((form.cp.value!='') && (!isValid(exp_cp,form.cp.value))){
				  buildmess("Code Postal");
				  form.cp.value="";
				  form.cp.focus();
			   }
 			   if (!isValid(exp_tel,form.teldom.value)){
		                  buildmess("Téléphone");
		                  form.teldom.value="";
		                  form.teldom.focus();
		           }
			   if (!CheckDate(form.naissance.value)){
				  buildmess("Date de Naissance");
				  form.naissance.value="";
				  form.naissance.focus();
			   }			   
			   if (!isValid(exp_ville,form.ville.value)){
				  buildmess("Ville");
				  form.ville.value="";
				  form.ville.focus();
			   }		           
		           if (!isValid(exp_nom,form.prenom.value)){
				  buildmess("Prénom");
				  form.prenom.value="";
				  form.prenom.focus();
			   }
			   if (!isValid(exp_nom,form.nom.value)){
				  buildmess("Nom");
				  form.nom.value="";
				  form.nom.focus();
			   }
      }

	if (document.getElementById('form_contact')) {

			   if ((form.commentaire.value=='')){
            buildmess("Message");
            form.commentaire.value="";
            form.commentaire.focus();
	           }
			   if ((form.sujet.value=='')){
            buildmess("Sujet");
            form.sujet.value="";
            form.sujet.focus();
	           }
			   
			   if ((form.telpor.value!='') && (!isValid(exp_tel,form.telpor.value))){
            buildmess("Téléphone");
            form.telpor.value="";
            form.telpor.focus();
	           }
			   if (!isValid(exp_email,form.email.value)){
				  buildmess("Email");
				  form.email.value="";
				  form.email.focus();
			   }

        if (!isValid(exp_nom,form.prenom.value)){
				  buildmess("Prénom");
				  form.prenom.value="";
				  form.prenom.focus();
			   }
			   if (!isValid(exp_nom,form.nom.value)){
				  buildmess("Nom");
				  form.nom.value="";
				  form.nom.focus();
			   }
      }

   if (msgbox==true) {
	   if (cpt>1) {
       	alert("Saisie invalide pour les champs : " + message + ".");
       	cpt=0;
	   } else {
		 alert("Saisie invalide pour le champ : " + message + ".");
		 cpt=0;  
	   }
       message="";
       blank="";
       msgbox=false;
	return false ;
   } else {
       return true ;
   }
}


