function confirmSupp(){
rep=confirm('Confirmer la suppression ?');
return rep;
}
function confirmInserDispo(){
rep=confirm('Remettre la disponibilité ?');
return rep;
}

function ouvre_popup(page,w,h) {
       window.open(page,"nom_popup","menubar=no, status=no, scrollbars=no, menubar=no, width="+w+", height="+h+", left=500, top=300");
   }

function controlCGV(lang) {
 if (document.getElementById("cgv").checked) {
	 return true;
 }
 else {	 
     if (lang=='fr') alert('Vous devez accepter les CGV');
	 if (lang=='es') alert("Debe aceptar las Condiciones Generales de Alquiler !");
	 if (lang=='en') alert("You must overview of renting rules and regulations");	 
	 return false;
 }
}

function controlUpdatePrix() {
  f=document.forms[0];

  var exp=new RegExp("^[0-9]+[\.]?[0-9]*$","gi");
  if (!exp.test(f.reduction.value)) {
      alert("Erreur dans la réduction");
	  return false;
  }
  exp=new RegExp("^[0-9]+[\.]?[0-9]*$","gi");
  if (!exp.test(f.tarif_base.value)) {
      alert("Erreur dans le tarif");
	  return false;
  }
  exp=new RegExp("^[0-9]+[\.]?[0-9]*$","gi");  
  if (!exp.test(f.tarif_base1.value)) {
      alert("Erreur dans le prix barré");
	  return false;
  }  
  return true
}

function controlLocataire(lang) {
  f=document.forms[0];
  if (f.nom.value == "") {
     if (lang=='fr') alert("Veuillez remplir le champ nom");
	 if (lang=='es') alert("Introduzca su nombre");
	 if (lang=='en') alert("Enter your name");
	 return false
  }
   
   if (f.email.value == "") {
     if (lang=='fr')  alert("Veuillez remplir le champ Email");
	 if (lang=='es') alert("Introduzca su email");
	 if (lang=='en') alert("Enter your email address");	 
	 return false
  }
    var exp=new RegExp("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+))*$","gi");
  if (!exp.test(f.email.value)) {
     if (lang=='fr')  alert("L'adresse Email est incorrecte");
	 if (lang=='es') alert("Su dirección email es incorrecta");
	 if (lang=='en') alert("Your email address is incorrect");	  
      
	  return false;
  }
   if (f.email2.value !=f.email.value) {
     if (lang=='fr')  alert("Le champ confirmation d'adresse est erroné");
	 if (lang=='es') alert("Su dirección email confirmation  es incorrecta");
	 if (lang=='en') alert("Your email address confirmation is incorrect");		 
	 return false
  } 

  return true
}
function controlProprio() {
  f=document.forms[1];
  if (f.nom.value == "") {
     if (lang=='fr') alert("Veuillez remplir le champ nom");
	 if (lang=='es') alert("Introduzca su nombre");
	 if (lang=='en') alert("Enter your name");
	 return false
  }
  
   if (f.email.value == "") {
     if (lang=='fr')  alert("Veuillez remplir le champ Email");
	 if (lang=='es') alert("Introduzca su email");
	 if (lang=='en') alert("Enter your email address");	 
	 return false
  }
    var exp=new RegExp("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+))*$","gi");
  if (!exp.test(f.email.value)) {
     if (lang=='fr')  alert("L'adresse Email est incorrecte");
	 if (lang=='es') alert("Su dirección email es incorrecta");
	 if (lang=='en') alert("Your email address is incorrect");	 
	  return false;
  }
     if (f.email2.value !=f.email.value) {
     if (lang=='fr')  alert("Le champ confirmation d'adresse est erroné");
	 if (lang=='es') alert("Su dirección email confirmation  es incorrecta");
	 if (lang=='en') alert("Your email address confirmation is incorrect");	
	 return false
  } 
   
  if (f.telephone.value == "") {
     if (lang=='fr')       alert("Veuillez remplir le champ Téléphone");
	 if (lang=='es') alert("Introduzca su tel fijo");
	 if (lang=='en') alert("Enter your Tel (land line)");	 
	 return false
  }
  return true
}
function controlLogin(lang) {
  f=document.forms[0];  
   if (f.email.value == "") {
     if (lang=='fr')  alert("Veuillez remplir le champ Email");
	 if (lang=='es') alert("Introduzca su email");
	 if (lang=='en') alert("Enter your email address");	
	 return false
  }
    var exp=new RegExp("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+))*$","gi");
  if (!exp.test(f.email.value)) {
     if (lang=='fr')  alert("L'adresse Email est incorrecte");
	 if (lang=='es') alert("Su dirección email es incorrecta");
	 if (lang=='en') alert("Your email address is incorrect");	
	  return false;
  }
  if (f.pass.value == "") {
     if (lang=='fr')    alert("Veuillez saisir le mot de passe")
	 if (lang=='es') alert("Introduzca su password");
	 if (lang=='en') alert("Enter your password");		 
	 return false
  }  
  
  return true
}


function controlNewClient(statut0,lang) {
  f=document.forms['identification'];
//alert('statut0');
  if (!f.civil[0].checked && !f.civil[1].checked && !f.civil[2].checked ){
     if (lang=='fr') alert("Veuillez préciser Mr,Mme,Melle");
	 if (lang=='es') alert("Sr,Sra,Srita ?");
	 if (lang=='en') alert("Mr,Mrs,Ms ?");	 
	 return false	  
  }
  if (f.nom.value == "") {
     if (lang=='fr') alert("Veuillez remplir le champ nom");
	 if (lang=='es') alert("Introduzca su nombre");
	 if (lang=='en') alert("Enter your name");
	 return false
  }
  
   if (f.email.value == "") {
     if (lang=='fr')  alert("Veuillez remplir le champ Email");
	 if (lang=='es') alert("Introduzca su email");
	 if (lang=='en') alert("Enter your email address");	 
	 return false
  }
    var exp=new RegExp("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+))*$","gi");
  if (!exp.test(f.email.value)) {
     if (lang=='fr')  alert("L'adresse Email est incorrecte");
	 if (lang=='es') alert("Su dirección email es incorrecta");
	 if (lang=='en') alert("Your email address is incorrect");	 
	  return false;
  }
     if (f.email2.value !=f.email.value) {
     if (lang=='fr')  alert("Le champ confirmation d'adresse est erroné");
	 if (lang=='es') alert("Su dirección email confirmation  es incorrecta");
	 if (lang=='en') alert("Your email address confirmation is incorrect");	
	 return false
  } 
   
  if (f.telephone.value == "") {
     if (lang=='fr')       alert("Veuillez remplir le champ Téléphone");
	 if (lang=='es') alert("Introduzca su tel fijo");
	 if (lang=='en') alert("Enter your Tel (land line)");	 
	 return false
  } 
  if (f.pass.value == "") {
     if (lang=='fr')    alert("Veuillez saisir le mot de passe")
	 if (lang=='es') alert("Introduzca su password");
	 if (lang=='en') alert("Enter your password");		 
	 return false
  }  
 
    if (f.adresse.value == "") {
     alert("Veuillez saisir votre adresse")
     if (lang=='fr')      alert("Veuillez saisir votre adresse")
	 if (lang=='es') alert("Introduzca  domicilio");
	 if (lang=='en') alert("Enter your address");	 
	 return false
  }
     if (f.cp.value == "") {
     if (lang=='fr') alert("Veuillez saisir le code postal");
	 if (lang=='es') alert("Introduzca  CP");
	 if (lang=='en') alert("Enter your postcode");	 
	 return false
  }
  
     if (f.ville.value == "") {
     if (lang=='fr') alert("Veuillez  saisir la ville");
	 if (lang=='es') alert("Introduzca  Ciudad");
	 if (lang=='en') alert("Enter your Town");		 
	 return false
  }
  if (statut0=='update'){
     repIdentification("controleUpdateClient.php",lang)}
  else{ 
     repIdentification("controleNewClient.php",lang);}
  return false;  

}


function setPhoto(vignette,photo,maxw,maxh,w,h) {
temp=window.document.images[photo].src;
window.document.images[photo].src=window.document.images[vignette].src;
  if (w>h) {
      dest_w=maxw;
      dest_h=Math.round(maxw*h/w);
  }
  else {
      dest_h=maxh;
      dest_w=Math.round(maxh*w/h);
   }
window.document.images[photo].width=dest_w;
window.document.images[photo].height=dest_h;
return true;
}

function getDatefr(strDate){	 // dd/mm/aaaa 
var day1,month1,year1;
  day1 = parseInt(strDate.substring(0,2),10);
  month1 = parseInt(strDate.substring(3,5),10);
  year1 = parseInt(strDate.substring(6,10),10);
  d = new Date(year1,month1-1,day1);
  return d;  
}
	  
function nbJours(date_inf,date_sup){ // format dd/mm/aaaa
var nb,d1,d2;
	d1=getDatefr(date_inf);
	d2=getDatefr(date_sup);
	nb=Math.round((d2.getTime()-d1.getTime())/(3600*1000*24));
    return nb;										  
}

function datesValideInd(date_inf,date_sup) {// format dd/mm/aaaa pour les dates indipo/réservation
 nb=nbJours(date_inf.value,date_sup.value);
	if (nb<0){
		alert("L'ordre des dates est erroné !");
		return false;
	}    

	return true; // nb>=3
}
function datesValide(date_inf,date_sup,lang) {// format dd/mm/aaaa
 nb=nbJours(date_inf.value,date_sup.value);
	if (nb<0){
	 if (lang=='fr') alert("La date de départ est incorrecte !");
	 if (lang=='es') alert("La fecha de salida no es válido");
	 if (lang=='en') alert("The departure date is invalid");	
		return false;
	}    
	if (nb<3){
	 if (lang=='fr')alert('Vous ne pouvez pas réserver moins de 3 nuits');
	 if (lang=='es') alert("No se puede reservar menos de 3 noches");
	 if (lang=='en') alert("You can not book less than 3 nights");	
		return false;
	}
	return true; // nb>=3
}

function datesValide1(id,date_inf,date_sup,ha,hd,nbperson,lang) {// format dd/mm/aaaa
var nb;
 nb=nbJours(date_inf.value,date_sup.value);
	if (nb<0){
	 if (lang=='fr') alert("La date de départ est incorrecte !");
	 if (lang=='es') alert("La fecha de salida no es válido");
	 if (lang=='en') alert("The departure date is invalid");		
		return false;
	}    
	if (nb<3){
	 if (lang=='fr')alert('Vous ne pouvez pas réserver moins de 3 nuits');
	 if (lang=='es') alert("No se puede reservar menos de 3 noches");
	 if (lang=='en') alert("You can not book less than 3 nights");				
		return false;
	}
	repDispo(id,date_inf,date_sup,ha,hd,nbperson);
	return false; // pour les tests
	return true; // nb>=3
}
function repDispo(id, d1,d2,h_arrivee,h_depart,nbperson) 
{ 
var xhr; 
var data;
var ha,hd,i,url;
i=h_arrivee.selectedIndex;
ha=h_arrivee.options[i].value;
i=h_depart.selectedIndex;
hd=h_depart.options[i].value;
i=nbperson.selectedIndex;
nb=nbperson.options[i].value;

    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }
 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if (xhr.status  == 200) {
              //   document.getElementById("messageDispo").innerHTML = xhr.responseText;
			    if (xhr.responseText=="DISPO") {
				document.getElementById("form-reserver").submit();
				}
				else { 
				// pas dispo ou erreur	 
				 document.getElementById("messageDispo").style.display="block";
				 if ( document.getElementById("form-rechercher")) {// lien pour la recherche
				   //  url="../pages/liste-recherche.php?date_sup="+d1.value+"&date_inf="+d2.value;
				   
				    document.getElementById("form-rechercher").date_inf.value=d1.value;
					document.getElementById("form-rechercher").date_sup.value=d2.value;
				 };
				 if ( document.getElementById("rappeldate"))
				    document.getElementById("rappeldate").style.display="none";
				 if (document.getElementById("tableprix"))
				    document.getElementById("tableprix").style.display="none";
				 } 
			  }
              else {
                 document.getElementById("messageDispo").innerHTML = xhr.status;
				 
			  }
         }
    }; 
   url="getDispo.php";
   xhr.open( 'POST', url,  true); 
   data='ID_APPART='+id.value+'&date_inf_r='+d1.value+'&date_sup_r='+d2.value+'&h_arrivee='+ha+'&h_depart='+hd+'&nb_person_r='+nb;
 //  alert(data);
   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
   xhr.send(data);
}
function repIdentification(url,lang) 
{ 
var email;
var id_client;
id_client="";
email=document.getElementById("identification").email.value;
if (document.getElementById("identification").id_client) 
   id_client=document.getElementById("identification").id_client.value;

    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }
 
    xhr.onreadystatechange  = function()
    {   
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) { 
				               //   document.getElementById("messageDispo").innerHTML = xhr.responseText;
			    if (xhr.responseText=="OK") document.getElementById("identification").submit();
				else {// pas dispo ou erreur
                 if (lang=='fr') alert("Email déjà existant pour un compte client !"); 
	             if (lang=='es') alert("Su dirección e-mail ya es utilizada por una cuenta cliente");
	             if (lang=='en') alert("Your email address is already in use for a customer account");
		         return false;
				}
			  }
              else {
               //  document.getElementById("messageDispo").innerHTML = xhr.status;
			 return false;
			  }
         }
    }; 
   xhr.open( 'POST', url,  true); 
   data='email='+email+'&id_client='+id_client;

   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
   xhr.send(data);
}