// javascript Site

window.onload=montre;
function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function ChampNonVide(ChampNom , message , FormNom) {
 if (document.forms[FormNom].elements[ChampNom].value.length < 1) {
  alert(" "+message);
  document.forms[FormNom].elements[ChampNom].focus();
  return true;
 }
}

function EmailValid (ChampNom , FormNom, lang) {
 var lib = "";
 if (lang == "fr") { lib = "Votre adresse e-mail n'est pas valide"; }
 else { lib = "Your e-mail address is not valid"; }

 adresse = document.forms[FormNom].elements[ChampNom].value;
 var place = adresse.indexOf("@",1);
 var point = adresse.indexOf(".",place+1);
  if ((place > -1)&&(adresse.length >2)&&(point > 1)) {
  return false;
  }
	else {
   alert(lib);
   document.forms[FormNom].elements[ChampNom].focus();
   return true;
  }
}

	 	  
function compare(date_1, date_2){
    diff = date_1.getTime()-date_2.getTime();
    return (diff==0?diff:diff/Math.abs(diff));
 }


function validDates(FormNom,lg) {
 var lib = "";
 var lib2 = "";
 if (lg == "fr") { 
   lib = "La date d'arrivée n'est pas valide.";
   lib2 = "Pour les mobil homes, les réservations à la semaine se font du samedi au samedi.\nVeuillez modifier votre date d\'arrivée.";
 }
 else { 
   lib = "The date of arrival is not valid."; 
   lib2 = "For mobil homes, the bookings weekly are made from Saturday to Saturday.\nPlease modify your date of arrival.";
 }

 
 var today = new Date();
 var date2 = new Date();
 date2.setFullYear(document.forms[FormNom].a1.value,document.forms[FormNom].m1.value-1,document.forms[FormNom].j1.value);

 if (date2<today) { 
   alert (lib); 
   return false; }
   
 if (document.form1.type_heb[1].checked) {  // mobil home
   	if (document.form1.unite[0].checked) {  // semaine
	  if (date2.getDay() != 6) {
		  alert (lib2);
		  return false;
	    }
	}
 }

 document.forms[FormNom].action = 'selection.asp?lang='+lg;
}

function validForm(FormNom,mode,j1,m1,a1,nuit,unite,lg,cm) {
if (lg == 'fr') {
 if (cm == 0) {
  alert("Aucune location sélectionnée");
  return false;
 }
 if (ChampNonVide('cli_nom' ,'Veuillez saisir votre nom', FormNom)) return false; 
 if (ChampNonVide('cli_prenom' ,'Veuillez saisir votre prénom', FormNom)) return false;
 if (ChampNonVide('cli_adr1' ,'Veuillez saisir votre adresse', FormNom)) return false;
 if (ChampNonVide('cli_cp' ,'Veuillez saisir votre code postal', FormNom)) return false;
 if (ChampNonVide('cli_ville' ,'Veuillez saisir votre ville', FormNom)) return false;
 if (ChampNonVide('cli_tel' ,'Veuillez saisir un numéro de téléphone', FormNom)) return false;
 if (EmailValid ('cli_email' , FormNom, lg)) return false;
 if (!(document.forms[FormNom].cgv.checked)) {
  alert(" Vous devez accepter les conditions générales de vente");
  document.forms[FormNom].cgv.focus();
  return false;
 }
 } else {
 if (cm == 0) {
  alert("No location selected");
  return false;
 }
 if (ChampNonVide('cli_nom' ,'Please tape your name', FormNom)) return false; 
 if (ChampNonVide('cli_prenom' ,'Please tape your first name', FormNom)) return false;
 if (ChampNonVide('cli_adr1' ,'Please tape your address', FormNom)) return false;
 if (ChampNonVide('cli_cp' ,'Please tape your zip code', FormNom)) return false;
 if (ChampNonVide('cli_ville' ,'Please tape your city', FormNom)) return false;
 if (ChampNonVide('cli_tel' ,'Please tape your phone', FormNom)) return false;
 if (EmailValid ('cli_email' , FormNom, lg)) return false;
 if (!(document.forms[FormNom].cgv.checked)) {
  alert(" You have to accept the general conditions of sale");
  document.forms[FormNom].cgv.focus();
  return false;
 }
 }
 
 document.forms[FormNom].action = 'confirm-resa.asp?lang='+lg+'&send=1&mode='+mode+'&j1='+j1+'&m1='+m1+'&a1='+a1+'&res_nbNuits='+nuit+'&unite='+unite;
 document.forms[FormNom].target = "_self";
 //document.forms[FormNom].submit();
}

function changelist(date1,chpJ){
var eltDate = date1.split(";");
var mois = eltDate[0];
var annee = eltDate[1];

var nbJ = 31;
if (mois==4 || mois==6 || mois==9 || mois==11 ) { nbJ = 30; }
if (mois==2) {
  nbJ = 28;
  if ((annee%4==0&&annee%100!=0)||annee%400==0) {nbJ = 29; }
}
temp = chpJ;
var val= temp.options[temp.selectedIndex].value;

for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null;
for (i=0;i<nbJ;i++){
temp.options[i]=new Option(i+1,i+1);
}
if (val > nbJ) { val = nbJ; }
temp.options[val-1].selected=true;


}

// Différence entre les 2 dates
function bissextile(annee) {
if (annee%4==0 && annee %100!=0 || annee%400==0) return true; else return false
}

function nb_01_01(date){
nb_mois=new Array(13);
nb_mois=[,0,31,59,90,120,151,181,212,243,273,304,334];
j=eval(date[0]) ; m=eval(date[1]) ; a=eval(date[2]);
nb=nb_mois[m]+j-1 ;
if (bissextile(a) && m>2) nb++;

return nb;
}

function nb_jour_annee(a1,a2){
n=0;
if (a1==a2) n=0 ; else
for (i=a1; i<a2; i++) {n += 365; if (bissextile(i)) n++}

return n;
}

function changeNuit(date1,date2){

a1=eval(date1[2]) ; a2=eval(date2[2]) ; 
nb=nb_jour_annee(date1[2],date2[2]) - nb_01_01(date1) + nb_01_01(date2);
if (nb > 31) {nb = 31; }
document.form1.nuits.value =nb;
}

function selType(lib1,lib2,nmax,smax,lg) {
	
	var t = '';
	
	if (document.form1.type_heb[0].checked) {  // emplacement
	t = '<div style="float:left;"><input name="unite" class="radio" type="radio" value=1 checked onClick="changeDate(document.form1.j1,document.form1.m1,document.form1.a1,\''+lg+'\');">'+lib2+'</div>';
    t += '<div style="float:left;margin-left:30px;" id="listen"><select name="nuits" class="boite2" onChange="changeDate(document.form1.j1,document.form1.m1,document.form1.a1,\''+lg+'\');">';
	for(n=1;n<=nmax;n++)
    {
	t += '<option value='+n+' >'+n+'</option>';
	}
    t += '</select></div><br><br>';
	}
				
	if (document.form1.type_heb[1].checked) {
		t = '<div style="float:left;"><input name="unite" class="radio" type="radio" value=2 checked onClick="selUnite();changeDate(document.form1.j1,document.form1.m1,document.form1.a1,\''+lg+'\');">'+lib1+'</div>';
		t += '<div style="float:left;margin-left:15px;" id="listes"><select name="semaines" class="boite2" onChange="changeDate(document.form1.j1,document.form1.m1,document.form1.a1,\''+lg+'\');">';
		for(s=1;s<=smax;s++) {
		t += '<option value='+s+'>'+s+'</option>';
		}
		t += '</select></div><br>';
		t += '<div style="clear:both;float:left;"><input name="unite" class="radio" type="radio" value=1 onClick="selUnite();changeDate(document.form1.j1,document.form1.m1,document.form1.a1,\''+lg+'\');">'+lib2+'</div>';
        t += '<div style="float:left;margin-left:30px;" id="listen"><select name="nuits" class="boite2" onChange="changeDate(document.form1.j1,document.form1.m1,document.form1.a1,\''+lg+'\');">';
	    for(n=2;n<=nmax;n++)
         {
	     t += '<option value='+n+' >'+n+'</option>';
	     }
        t += '</select></div><br><br>';
        
	}

   document.getElementById("unite_div").innerHTML=t;
   
   if (document.form1.type_heb[1].checked) {
     document.getElementById("listen").style.display = "none";
   }

}


function selUnite() {
	 if (document.form1.unite[0].checked) {
       document.getElementById("listes").style.display = "block";
	   document.getElementById("listen").style.display = "none";
	 } 
	 if (document.form1.unite[1].checked) {
	   document.getElementById("listen").style.display = "block";
	   document.getElementById("listes").style.display = "none";
	 }
}

function changeDate(d,m,y,lg){
	
d1 = d;
m1 = m;
a1 = y;

var val1= d1.options[d1.selectedIndex].value;
var val2= m1.options[m1.selectedIndex].value;
var val3= a1.options[a1.selectedIndex].value;
var valn= 0;


if (document.form1.type_heb[0].checked) {  // emplacement
 valn= document.form1.nuits.options[document.form1.nuits.selectedIndex].value;
} else {
	if (document.form1.unite[0].checked) {  //semaine
		valn= document.form1.semaines.options[document.form1.semaines.selectedIndex].value * 7;
	} else {
		valn= document.form1.nuits.options[document.form1.nuits.selectedIndex].value;
	}
}

date1 = new Date(val3,val2-1,val1);

var jourdep = document.getElementById('jsem');
jourdep.innerHTML = jComplete(date1.getDay(),lg);

date1.setDate(date1.getDate()+parseInt(valn));

document.form1.j2.value = date1.getDate();
document.form1.m2.value = date1.getMonth()+1;
document.form1.a2.value = date1.getFullYear();

var datedep = document.getElementById('datedepart');
datedep.innerHTML = dateComplete(date1.getDay(),date1.getDate(),(date1.getMonth()+1),date1.getFullYear(),lg); 

 

}


function jComplete(day,lg) {
	
	var tab_day=new Array(7);
	
	if (lg == 'fr') {
        tab_day=['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'];
	} else {	
        tab_day=['sun.', 'mon.', 'tue.', 'wed.', 'thu.', 'fri.', 'sat.'];
	}

	var ladate = tab_day[day];
	return ladate;
}

function dateComplete(day,no,month,year,lg) {
	
	var tab_mois=new Array(12);
	var tab_day=new Array(7);
	
	if (lg == 'fr') {
	    tab_mois=['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
        tab_day=['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'];
	} else {	
        tab_mois=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'Septembrer', 'October', 'November', 'December'];
        tab_day=['sun.', 'mon.', 'tue.', 'wed.', 'thu.', 'fri.', 'sat.'];
	}

	var ladate = tab_day[day] + " " + no + " " + tab_mois[month-1] + " " + year;
	return ladate;
}

function dateadd(per,n,d) {
   switch(per) {
      case "yyyy": d.setYear(d.getFullYear()+n); break
      case "m": d.setMonth(d.getMonth()+n); break
      case "ww": n*=7
      case "d": d.setDate(d.getDate()+n); break
      case "h": d.setHours(d.getHours()+n); break
      case "n": d.setMinutes(d.getMinutes()+n); break
      case "s": d.setSeconds(d.getSeconds()+n)
   }
   return d
}


function calculCm(i, totAd, totEn, totAuto, totMoto, totCcar, totElec10a) {
  var total = document.getElementById('totalnuit'+i);
  var nbAd = document.form1.elements['adultes'+i].value;
  var nbEn = document.form1.elements['enfants'+i].value;
  var nbAuto = document.form1.elements['auto'+i].value;
  var nbMoto = document.form1.elements['moto'+i].value;
  var nbCcar = document.form1.elements['campingcar'+i].value;
  var nbElec10a = document.form1.elements['electricite'+i].value;

  t = parseFloat(totAd) * nbAd;
  t += parseFloat(totEn) * nbEn;
  t += parseFloat(totAuto) * nbAuto;
  t += parseFloat(totMoto) * nbMoto;
  t += parseFloat(totCcar) * nbCcar;
  t += parseFloat(totElec10a) * nbElec10a;
  val = parseFloat(document.form1.elements['tot1'+i].value);
  new_tot = val + t;
  new_tot = format(new_tot, 2, " ");
  new_tot_ch = new_tot.toString();
  new_tot_ch = new_tot_ch.replace('.',',');
  total.innerHTML = new_tot_ch + "&nbsp;&euro;"; 
}

function format(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

function ajout_panier(i,id,j1,m1,a1,nuit,unite,typeheb,nMax,lg) {
	
 var lib = "";
 if (lg == "fr") { lib1 = "Vous devez sélectionner au moins une personne"; 
                   lib2 = "Vous pouvez réserver jusqu'à 3 locations"; }
 else { lib1 = "You have to select at least a person";
        lib2 = "You can reserve up to 3 rentals"; }
//sel = document.form1.elements['nbchamb'+i];
//nbCh = sel.options[sel.selectedIndex].value;
nbCh = 1;
nbAd = document.form1.elements['adultes'+i].value;
nbEn = document.form1.elements['enfants'+i].value;
nbAuto = document.form1.elements['auto'+i].value;
nbMoto = document.form1.elements['moto'+i].value;
nbCcar = document.form1.elements['campingcar'+i].value;
nbElec10a = document.form1.elements['electricite'+i].value;
nMax = parseInt(nMax) + parseInt(nbCh);

if  (nMax > 3) { alert(lib2); }
else {

if ((nbAd != 0) || (nbEn != 0)) {
  param = 'id='+id+'&nb='+nbCh+'&j1='+j1+'&m1='+m1+'&a1='+a1+'&nuits='+nuit+'&unite='+unite+'&type_heb='+typeheb;
  /*for (j=1;j<=nbCh;j++) {
   pers = document.form1.elements['pers'+i+j].value;
   temp = pers.split(",");
   param = param + '&ad'+j+'='+temp[0]+'&en'+j+'='+temp[1];
  }*/

   param = param + '&ad='+nbAd+'&en='+nbEn;
   param = param + '&auto='+nbAuto+'&moto='+nbMoto+'&ccar='+nbCcar+'&elec10a='+nbElec10a;
   window.location ='panier.asp?lang='+lg+'&'+param;

}
else { alert(lib1); }

}
}

 //liste_val=new Array();
  //liste=new Array(); 

/*function chgCh(k)
 {
  
  c=document.getElementById("nbchamb"+k).value;
  
  if (c == 1) {
    t = '';
 	document.getElementById("chambre2_div"+k).innerHTML=t;
   }
   
  if ((c == 2) || (c==3)) {
   
    ch_p = 'pers'+k+'2';
    t='<select name='+ch_p+' class="boite3" >';
	for(i=0;i<liste.length;i++)
    {
	   s = "";
       t+="<option "+s+" value=\""+liste_val[i]+"\">"+liste[i]+"</option>";
    }
    t+='</select><br>';	
	document.getElementById("chambre2_div"+k).innerHTML=t;
  
 
    if (c == 3) {
    ch_p = 'pers'+k+'3';
    t+='<select name='+ch_p+' class="boite3" >';
	for(i=0;i<liste.length;i++)
    {
	   s = "";
       t+="<option "+s+" value=\""+liste_val[i]+"\">"+liste[i]+"</option>";
    }
    t+='</select><br>';
		  
	  document.getElementById("chambre2_div"+k).innerHTML=t;
     }
 }
    
   
}
*/

function ajout_ch(lg,j1,m1,a1,nuit,unite,typeheb,nMax) {
if (lg == "fr") {
 if (nMax >= 3) {
  alert("Vous ne pouvez réserver plus de 3 locations. \nSi vous souhaitez modifier votre sélection, vous devez supprimer une location.");
  return false;
 }
} else {
  if (nMax >= 3) {
  alert("You can reserve no more than 3 rentals. \nIf you wish to modify your selection, vous have to delete a rental.");
  return false;
 }
}
window.location = 'selection.asp?lang='+lg+'&j1='+j1+'&m1='+m1+'&a1='+a1+'&nuits='+nuit+'&unite='+unite+'&type_heb='+typeheb+'&ajout=1';
}

function changeCalMois(FormNom) {
 var m = document.forms[FormNom].mois.value;
 var a = document.forms[FormNom].annee.value;
 document.forms[FormNom].action = document.forms[FormNom].action + '&d=01/'+m+'/'+a;
 document.forms[FormNom].submit();
}

function go(page) {
//if (validDate() == true) {
form2.action = page+'?periode=1'; 
form2.submit();
//}

}


function openWin(win, w, h) {
	var le = (screen.availWidth - w) /2;
	var he = (screen.availHeight -h) /2;
	win = window.open(win,null,"height="+h+",width="+w+",status=no,toolbar=no,scrollbars=auto,menubar=no,location=no,left="+le+", top="+he,false);
	win.focus();
}

function openWinNews(win, w, h) {
	var le = (screen.availWidth - w) /2;
	var he = (screen.availHeight -h) /2;
	win = window.open(win,null,"height="+h+",width="+w+",status=no,toolbar=no,scrollbars=1,resizable=1,menubar=no,location=no,left="+le+", top="+he,false);
	win.focus();
}

function openWin2(win, w, h) {
	win = window.open(win,"fiche","height="+h+",width="+w+",status=no,toolbar=no,scrollbars=1,menubar=no,resizable=1,location=no,left=40, top=40",false);
	win.focus();
}



function afficherZoom(i){
document.all['popup'+i].style.display='block';
}
function cacherZoom(i){
document.all['popup'+i].style.display='none';
}



function open_calendrier(win, w, h) {

	window.open(win,"calendrier","height="+h+",width="+w+",status=no,toolbar=no,scrollbars=no,menubar=no,location=no,left=20, top=20",false);
	//location.reload();
}

function supp(url) {
   if (confirm("Etes-vous sûr de vouloir supprimer cette réservation?")) {
     window.location = url;
	
   }
 
}

function modif_resa(url,lg) {
if (lg == 'fr') {
   if (confirm("Vous allez modifier vos dates de réservation. Votre sélection sera perdue. Continuer ?")) {
     window.location = url;
   }
} else {
   if (confirm("You go to modify your dates of booking. Your selection will be lost. Continue ?")) {
     window.location = url;
   }
}
 
}

function DoDate(dt) {
	window.opener.editC.dte.value = dt;
	self.close();	
}






