// script.js Admin



function modifTarifs(typeChambre) {
 if (confirm("Vous allez mettre à jour vos périodes tarifaires. Continuer ?")) {
  document.form1.action = 'gestion-tarifs.asp?mode=2&typeCh='+typeChambre;
  document.form1.submit();
 }
//openFen("","fenetre");
//document.form1.target = "fenetre";
//document.form1.submit();
}

function suppTarifs(i,typeChambre) {
   if (confirm("Etes-vous sûr de vouloir supprimer cette période ?")) {
     date1 = document.form1.elements['dPer1_'+i].value;
     date2 = document.form1.elements['dPer2_'+i].value;
     param = '&typeCh='+typeChambre+'&dated='+date1+'&datef='+date2;
     //window.location ='gestion-tarifs.asp?mode=3'+param;
	
   }
 
}

function validDateTarifs(date1,m,nbper){
 var eltDate = date1.split("/");
 date1 = new Date(parseInt(eltDate[2]),parseInt(eltDate[1]-1),parseInt(eltDate[0]));
 date1.setDate(date1.getDate()+1);

 dd = date1.getDate();
 if (dd<10) dd = "0"+dd;
 mm = date1.getMonth()+1;
 if (mm<10) mm = "0"+mm;
 
 if ((m-1) < nbper) {
  document.form1.elements['dPer1_'+m].value = dd+'/'+mm+'/'+date1.getFullYear();
 } else {
  document.form1.elements['dPer1_1'].value = dd+'/'+mm+'/'+date1.getFullYear();
 }

}

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 ChampNonVide1(ChampNom , message , FormNom) {
 if (!document.forms[FormNom].elements[ChampNom].checked) {
  alert(" "+message);
  document.forms[FormNom].elements[ChampNom].focus();
  return true;
 }
}

function EmailValid (ChampNom , FormNom) {
 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("Votre adresse e-mail n'est pas valide");
   document.forms[FormNom].elements[ChampNom].focus();
   return true;
  }
}


function validForm(FormNom,mode,j1,m1,a1,nuit) {

 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)) return false;
 if (ChampNonVide1('ConditionsGenerales' ,'Veuillez acceptez les condition generales de reservation', FormNom)) return false;
 
 document.forms[FormNom].action = 'confirme_res.php?send=1';
 document.forms[FormNom].target = "_self";
 //document.forms[FormNom].submit();
 
 //openFen("","fenetre");
//document.form2.target = "fenetre";
//document.form2.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 > 20) {nb = 20; }
document.form1.nuits.value =nb;
}


function changeDate(d,m,y,n){
d1 = d;
m1 = m;
a1 = y;
n1 = n;
var val1= d1.options[d1.selectedIndex].value;
var val2= m1.options[m1.selectedIndex].value;
var val3= a1.options[a1.selectedIndex].value;
var valn= n1.options[n1.selectedIndex].value;

date1 = new Date(val3,val2-1,val1);
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();

}

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 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=1,toolbar=no,scrollbars=1,menubar=no,location=no,left="+le+", top="+he,false);
	win.focus();
}

function openWin2(win, w, h) {

	window.open(win,"fiche","height="+h+",width="+w+",status=no,toolbar=no,scrollbars=1,menubar=no,location=no,left=20, top=20",false);
	//location.reload();
}





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,msg) {
   if (confirm("Etes-vous sûr de vouloir supprimer "+msg+" ?")) {
     //window.location = url;
	
   }
 
}



function DoDate(dt) {
	window.opener.editC.dte.value = dt;
	self.close();	
}

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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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];}
}




