// WARNING: to fully use the checkFieldsData(),
//          /pro/javascript/check_functions.js MUST BE INCLUDED before
//          this file in the JSP page.

// ======= Form checking =======
function checkFieldsData()
{
 // Met le nom en majuscule et le prénom en Capital !!!


 // TODO !!!!!!!!!!!!!!!!

 // Vérifier la validité de chaque type de champ présent !!!!!!!!!!!!!!

 return true;
}

// Call with true for initialization from body onLoad
FF_initMel = "";
function doubleCheckEmail(mel, isOblig, isOnLoadInit)
{
 if (isOnLoadInit)
 { FF_initMel = mel; return; }
 if (isEmptyTrimmed(mel))
 {
   if (isOblig)  
   { alert("Merci de préciser l'email"); return false; }
   return true;
 }
 if (! isEmail(mel))
 { alert("L\'email n'est pas correct"); return false; }
 if (mel != FF_initMel)
 {
   if (! confirm("Confirmez l'adresse email saisie : \n" + mel))
     return false;
 }
 return true;
}

// ======= Fields Display =======

var mo= new Array("Mois","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août",
 "Septembre","Octobre","Novembre","Décembre");
function L_Jour(sel)
{ for(i=1; i<=31; i++)
  document.write("<option value='", i,(i==sel)?"' selected>":"'>", i,"</option>"); }
function L_JourBad(sel)
{ document.write('<option value="0">Jour<\/option>');
  for(i=1; i<=31; i++)
   document.write('<option value="', i,(i==sel)?'" selected>':'">', i,'<\/option>'); }
function L_Mois(sel)
{ for(i=1; i<=12; i++)
  document.write("<option value='", i,(i==sel)?"' selected>":"'>", i,"</option>"); }
function L_MoisTxt(sel)
{ for(i=1; i<=12; i++)
  document.write("<option value='", i,(i==sel)?"' selected>":"'>", mo[i],"</option>"); }
function L_MoisTxtBad(sel)
{ for(i=0; i<=12; i++)
  document.write("<option value='", i,(i==sel)?"' selected>":"'>", mo[i],"</option>"); }
function L_An(sel)
{ dt = new Date(); i=dt.getFullYear(); st=i+10;
  for(; i<st; i++)
   document.write("<option value='", i,(i==sel)?"' selected>":"'>", i,"</option>"); }
function L_Heure(sel)
{ for(i=0; i<=23; i++)
  document.write("<option value='", i,(i==sel)?"' selected>":"'>", i,"</option>"); }
function L_Min(sel)
{ for(i=0; i<=55; i+=5)
  document.write("<option value='", i,(i==sel)?"' selected>":"'>", (i<10 ?'0':''),i,"</option>"); }


// ----- Date and Time -----
function FF_DateTime(prefx,keyname, yy,mm,dd, hr,mn)
{
 document.write('<select name="',prefx,'D',keyname,'" size="1">');
 L_Jour(dd);
 document.write('</select><select name="',prefx,'M',keyname,'" size="1">');
 L_MoisTxt(mm);
 document.write('</select><select name="',prefx,'Y',keyname,'" size="1">');
 L_An(yy);
 document.write('</select>&nbsp;à&nbsp;');
 document.write('<select name="',prefx,'H',keyname,'" size="1">');
 L_Heure(hr);
 document.write('</select>:<select name="',prefx,'N',keyname,'" size="1">');
 L_Min(mn);
 document.write('</select>');
 return;
}

// ----- Date -----
function FF_Date(prefx,keyname, yy,mm,dd)
{
 document.write('<select name="',prefx,'D',keyname,'" size="1">');
 L_Jour(dd);
 document.write('</select><select name="',prefx,'M',keyname,'" size="1">');
 L_Mois(mm);
 document.write('</select><select name="',prefx,'Y',keyname,'" size="1">');
 L_An(yy);
 document.write('</select>');
 return;
}

// ----- Bad Date -----
function FF_BadDate(prefx,keyname, yy,mm,dd)
{
 document.write('<select name="',prefx,'D',keyname,'" size="1">');
 L_JourBad(dd);
 document.write('</select><select name="',prefx,'M',keyname,'" size="1">');
 L_MoisTxtBad(mm);
 document.write('</select><input type="text" name="',prefx,'Y',keyname,'" value="', (yy<0 ? 'Année' : yy),'" size="6" maxlength="4" />');
 return;
}

// ----- Personal ! -----
function FF_Sex(keyname, F_SEX_MR, F_SEX_MME, F_SEX_MLLE, sex)
{
 document.write('M.<input type="radio" tabindex="1" name="',keyname,'" value="',F_SEX_MR,'" ',
  (sex==F_SEX_MR ? 'checked' : ''), ' />&nbsp;');
 document.write('Mme<input type="radio" tabindex="2" name="',keyname,'" value="',F_SEX_MME,'" ',
  (sex==F_SEX_MME ? 'checked' : ''), ' />&nbsp;');
 document.write('Mlle<input type="radio" tabindex="3" name="',keyname,'" value="',F_SEX_MLLE,'" ',
  (sex==F_SEX_MLLE ? 'checked' : ''), ' />&nbsp;');
 return;
}

// ----- Address -----
function FF_Address(fieldname,labeel,strNum,strNam,town,cp,pays,dept,addinfo)
{
 document.write('<input type="hidden" name="',fieldname,'" value="">'); // Field en champ caché
 // document.write('<tr><td colspan="4"><input type="text" size="22" maxlength="50" ', labeel, ' /></td></tr>');
 document.write('<tr><td>Rue</td><td colspan="3" >N&deg;');
 document.write('<input type="text" size="8" maxlength="20" ', strNum); // Numéro de rue
 document.write('/><input type="text" size="40" maxlength="250" ', strNam);
 document.write('></td></tr><tr><td>Ville</td><td>');
 document.write('<input type="text" size="20" maxlength="50" ', town); // Ville
 document.write('/></td><td>Code Postal');
 document.write('</td><td><input type="text" size="10" maxlength="10" ', cp);
 document.write('/></td></tr><tr><td>Pays</td><td>');
 document.write('<input type="text" size="20" maxlength="50" ', pays);  // Pays
 document.write('/></td><td>Département');
 document.write('</td><td><input type="text" size="20" maxlength="50" ', dept);  // Dépt
 document.write('/></td></tr><tr><td>Indications, compléments...</td><td colspan="3" >');
 document.write('<input type="text" size="56" maxlength="250" ', addinfo);
 document.write('/></td></tr>');
 return;
}

// ----- Address -----
function FF_GetAddress(fieldname,labeel,strNum,strNam,town,cp,pays,dept,addinfo)
{
 // document.write(labeel,'<br />');
 document.write(strNum,' ', strNam, '<br />'); // rue
 document.write(cp,' ',town,'<br />'); // ville
 document.write(dept,' ',pays,'<br />'); // pays
 document.write(addinfo);
 return;
}

// ----- Select ----- 
//  Pour ne rien sélectionner, mettre par exemple en première 
//   ligne dans dispArr "Sélectionner..." avec valeur
//   correspondante "" dans valArr
function FF_SelectDisplay(keyname, val, valArr, dispArr)
{
 document.write('<select name="',keyname,'">');
 for (i=0; i<dispArr.length; i++)
 {
  document.write('<option value="',valArr[i],'" ',
   (val==valArr[i] ? 'selected':''), '>',dispArr[i],'</option>');
 }
 document.write('</select>');
 return;
}

// ----- Select with "AUTRE" input text -----
// ATTENTION, UN SEUL pour un keyname donné !!
function FF_SelectDisplayOther(keyname, val, valArr, dispArr)
{
 selct=false;
 document.write('<select name="',keyname,'" onChange="elm=this.form.SELOTHER',keyname,
 '; if (elm) { if (selectedIndex==(options.length-1)) elm.disabled=false; else elm.disabled=true; }" >');
 for (i=0; i<dispArr.length; i++)
 {
  selct = selct || (val==valArr[i]); 
  document.write('<option value="',valArr[i],'" ',
   (val==valArr[i] ? 'selected':''), '>',dispArr[i],'</option>');
 }
 document.write('<option value="',(selct ? '' : val), '" ', 
  ((selct || val=="") ? '>' : 'selected>'),
  'Autre</option></select>');
 return;
}
  
// -- Complementary part : display the text box for "AUTRE"
function FF_SelectDisplayOtherPart2(keyname, val)
{
 document.write('<input name="SELOTHER',keyname,'" value="',val,
 '" onChange="elm=this.form.',keyname,'; elm.options[elm.options.length-1].value=this.value; elm.selectedIndex=elm.options.length-1; " />');
 return;
}

