function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

function YB_LitTitle(objName) {
  var obj = MM_findObj(objName);
  return(eval("obj.title"));
}

function YB_validateForm() { //v5.0 en anglais pour formmail3b.asp
  var i,p,q,nm,test,num,min,max,errors='',args=YB_validateForm.arguments;
  if (document.f.DateArrivee_012.value=='' && document.f.DateArriveeBS_015.value=='') errors+='- Date is required.\n' ;
  if (document.f.DateDepart_013.value=='' && document.f.DateDepartBS_016.value=='') errors+='- Date is required.\n' ;
  if (!document.f.TypeReservation_009[0].checked && !document.f.TypeReservation_009[1].checked && !document.f.TypeReservation_009[2].checked && !document.f.TypeReservation_009[3].checked && !document.f.TypeReservation_009[4].checked) errors+='- Type of hiring is required.\n' ;
  if (!document.f.ModeDePaiement_024[0].checked && !document.f.ModeDePaiement_024[1].checked && !document.f.ModeDePaiement_024[2].checked) errors+='- Type of payment is required.\n' ;
  if (document.f.MontantSejour_019.value == '0.00') errors+='- Amount of the stay is required.\n' ;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); MM_changeProp(val.name,'','style.backgroundColor','#FFFFFF','INPUT/TEXT');
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) { errors+='- '+YB_LitTitle(nm)+' must contain an e-mail address.\n'; MM_changeProp(nm,'','style.backgroundColor','#FFFF00','INPUT/TEXT'); }
      } else if (test!='R') {
        if (isNaN(val)) { errors+='- '+YB_LitTitle(nm)+' must contain a number.\n'; MM_changeProp(nm,'','style.backgroundColor','#FFFF00','INPUT/TEXT'); }
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) { errors+='- '+YB_LitTitle(nm)+' must contain a number between '+min+' and '+max+'.\n'; MM_changeProp(nm,'','style.backgroundColor','#FFFF00','INPUT/TEXT'); }
    } } } else if (test.charAt(0) == 'R') { errors += '- '+YB_LitTitle(nm)+' is required.\n'; MM_changeProp(nm,'','style.backgroundColor','#FFFF00','INPUT/TEXT'); } }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function arrondir(nombre, decimales) {
  if (isNaN(nombre)) return "";
  if (decimales == 0) {
     var n = Math.round(nombre);
     return n.toString();
  }
  else if (decimales > 0) {
     if (document.all) var undefined; // Netscape 4 ne connaît pas la constante "undefined" 
     var p10 = Math.pow(10, decimales);
     var n = Math.round(nombre * p10); 
     n = n.toString();
     var point = n.length - decimales;
     if (point >= 0) n = n.substring(0, point) + "." + n.substring(point);
     else n = "0." + formater(n, decimales);
  }
  else {
     var p10 = Math.pow(10, -decimales);
     var n = Math.round(nombre / p10) * p10;
     n = n.toString();
  }
  if (nombre.signe_decimal == undefined) return n;
  else return n.replace(".", nombre.signe_decimal);
}

function DecomposeDate(LeParam1){ 
// Sépare les jours, les mois et les années dans une date de type "22-05-1981"
// Renvoye le tout dans un tableau de taille 3
LeRetour = new Array(3);
LeJour="";
LeMois="";
LeAnnee="";
// Extraction du jour
i=0;
while((LeParam1.charAt(i)!="-")&&(i<10)){
LeJour+=LeParam1.charAt(i);
i++;
}
if(LeJour.charAt(0)=="0"){
LeJour=LeJour.charAt(1);
}
LeParam1=LeParam1.substring(i+1,LeParam1.length);

// Extraction du mois
i=0;
while((LeParam1.charAt(i)!="-")&&(i<10)){
LeMois+=LeParam1.charAt(i);
i++;
}
if(LeMois.charAt(0)=="0"){
LeMois=LeMois.charAt(1);
}
LeParam1=LeParam1.substring(i+1,LeParam1.length);
// Extraction de l'année
LeAnnee=LeParam1;
LeRetour[0]=LeJour;
LeRetour[1]=LeMois;
LeRetour[2]=LeAnnee;
return LeRetour;
}

function DateMachine(LeParam1){
// Renvoye une date sans les 0 dans les mois ou les jours "02/03/1981" -> "2/3/1981"
LaDate = new Array(3);
LaDate = DecomposeDate(LeParam1);
LeRetour = LaDate[0]+"/"+LaDate[1]+"/"+LaDate[2];
return LeRetour;
}

function DateAnglaise(LeParam1,LeParam2){
// Renvoye une date en format anglais avec le séparateur choisi "02/03/1981" -> "1981-3-2"
// Le premier paramètre est la date a convertir, le second est le caractère de séparation choisi
LaDate = new Array(3);
LaDate = DecomposeDate(LeParam1);
LeRetour = LaDate[2]+LeParam2+LaDate[1]+LeParam2+LaDate[0];
return LeRetour;
}

function NbJoursEntreDates(LeParam1,LeParam2){
// Compare 2 dates au format jj/mm/aaaa
//var LeParam1 = DateAnglaise(LeParam1,"/");// Ne pas oublier d'utiliser cette fonction
// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
//var LeParam2 = DateAnglaise(LeParam2,"/");
LeParam1 = Date.parse(LeParam1);
LeParam2 = Date.parse(LeParam2);
LaDiff = Math.floor((LeParam2 - LeParam1)/1000/60/60/24);
return LaDiff;
}

function trop() {
  if (eval(document.f.NombrePersonnes_011.value)>eval(document.f.NbMaxPers_010.value))
    alert('Too many persons.');
}

function PasSamedi(LaDate) {
// retourne vrai si la date passée en paramètre (au format mm-jj-aaaa) n'est pas un samedi
// retourne faux si une chaîne vide est passée en paramètre

if (LaDate != '') {
  mois = Number(LaDate.substr(0,2))-1 ;
  jour = Number(LaDate.substr(3,2)) ;
  annee = Number(LaDate.substr(6,4)) ;
  TheDate = new Date(annee,mois,jour) ;
  return !(TheDate.getDay()==6) ;
  }
else {
  return false ;
  }
}

function ybCalc() {
// calcule le montant de la réservation et remplit ce qui peut l'être
// pour les réservations à la semaine
ybTauxAcompte = 0.5 ;
ybAssuAnnuSem = 15 ;

var dummy ;
var jours ;

if (PasSamedi(document.f.DateArrivee_012.value)) {
  alert('The day of arrival in high season or\nin season has to be Saturday.') ;
  document.f.DateArrivee_012.value = '' ;
  }
if (PasSamedi(document.f.DateDepart_013.value)) {
  alert('The day of departure in high season or\nin season has to be Saturday.') ;
  document.f.DateDepart_013.value = '' ;
  }
jours = Math.abs(NbJoursEntreDates(document.f.DateArrivee_012.value,document.f.DateDepart_013.value)) ;
if (isNaN(eval(jours))) jours = 0;
document.f.NbSemaines_014.value = Math.round(eval(jours)/7) ;

if (document.f.AssuranceAnnulation_018.checked==true) {
  dummy = eval(document.f.NbSemaines_014.value) * ybAssuAnnuSem ;
  document.f.AssuranceAnnulation_021.value = dummy.toFixed(2) ;
  }
else {
  document.f.AssuranceAnnulation_021.value = '0.00' ;
  }

jours = Math.abs(NbJoursEntreDates(document.f.DateArriveeBS_015.value,document.f.DateDepartBS_016.value)) ;
if (isNaN(eval(jours))) jours = 0 ;
document.f.NbNuitees_017.value = eval(jours) ;

dummy = eval(document.f.MontantSejour_019.value) ;
if (isNaN(dummy)) {
  document.f.MontantSejour_019.value = '0.00' ;
  }
else {
  document.f.MontantSejour_019.value = dummy.toFixed(2) ;
  }

dummy = eval(document.f.MontantSejour_019.value) + eval(document.f.FraisReservation_020.value) + eval(document.f.AssuranceAnnulation_021.value) ;
document.f.MontantTotalSejour_022.value =  dummy.toFixed(2) ;

dummy = Math.round(eval(document.f.MontantSejour_019.value) * ybTauxAcompte)+ eval(document.f.FraisReservation_020.value) + eval(document.f.AssuranceAnnulation_021.value) ;
document.f.MontantAcompte_023.value = dummy.toFixed(2) ;

}

