function isverifan(chaineDate) 
{

//Je regarde tout d'abord si la chaîne n'est pas vide, sinon pas la peine d'aller plus loin
   if (chaineDate == "") return false

// J'utilise split pour créer un tableau dans lequel je récupère les jour mois année
// J'attends bien sûr une date formatée en JJ/MM/AAAA
   var ladate = (chaineDate).split("/")
   //alert(parseInt(ladate[0]));
// Si je n'ai pas récupéré trois éléments ou bien s'il ne s'agit pas d'entiers, pas la peine non plus d'aller plus loin
   if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2]))) return false

// Sinon, c'est maintenant que je crée la date correspondante. Attention, les mois sont étalonnés de 0 à 11
   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]))

// Bug de l'an 2000 oblige, lorsque je récupère l'année, je n'ai pas toujours 4 chiffres selon les navigateurs, je rectifie donc ici le tir.
   var annee = unedate.getYear()
   if ((Math.abs(annee)+"").length < 4) annee = annee + 2000;
   ladate= new Date();
	if(annee > ladate.getYear()){alert('Les réservations ne peuvent être éffectuées que pour l\'année en cours !');return false;}
	else{return true;}

}

function isDateValid(chaineDate) 
{

//Je regarde tout d'abord si la chaîne n'est pas vide, sinon pas la peine d'aller plus loin
   if (chaineDate == "") return false

// J'utilise split pour créer un tableau dans lequel je récupère les jour mois année
// J'attends bien sûr une date formatée en JJ/MM/AAAA
   var ladate = (chaineDate).split("/")
   //alert(parseInt(ladate[0]));
// Si je n'ai pas récupéré trois éléments ou bien s'il ne s'agit pas d'entiers, pas la peine non plus d'aller plus loin
   if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2]))) return false

// Sinon, c'est maintenant que je crée la date correspondante. Attention, les mois sont étalonnés de 0 à 11
   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]))

// Bug de l'an 2000 oblige, lorsque je récupère l'année, je n'ai pas toujours 4 chiffres selon les navigateurs, je rectifie donc ici le tir.
   var annee = unedate.getYear()
   if ((Math.abs(annee)+"").length < 4) annee = annee + 2000;

// Il ne reste plus qu'à vérifier si le jour, le mois et l'année obtenus sont les mêmes que ceux saisis par l'utilisateur.
   return ladate[0] + '/' +  ladate[1] + '/' + annee;
}
function verifreservation(date_deb, date_fin){
	document.getElementById('date_deb').value=isDateValid(date_deb);
	document.getElementById('date_fin').value=isDateValid(date_fin);
	if(document.MM_returnValue== false)return false;
	if(isverifan(date_deb)== false)return false;
	if(isverifan(date_fin)== false)return false;
	
	return true;
	
}
function createXHR() 
{
    var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
            }
        }
    return request;
}
function selectCL(id,rch){
	document.location.href='/gestion/compte.php?compte='+id+'&rch='+rch;
   }
  
function selecturl(id,url){
	document.location.href=url + '?modif='+id+'&modifsel=1';
   }
   
  
 
   /////////////////////////////////////////////////////////////////
function remplichamp(zonerch,url,champrch)
{ 
    var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              	if(xhr.responseText!=''){
					 document.getElementById(zonerch).style.display = 'block';
					 document.getElementById(zonerch).innerHTML = xhr.responseText;
				}
			}
         }
    }; 
	var rch =document.getElementById(champrch).value;
	if(rch.length>2){
		var script = url;   // local script
		xhr.open("POST", script, true);		
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send("rch=" + rch + "&zonerch=" + zonerch);
	}
}
///////////////////////////////////////////// exploitation résultat recherche//////////////////////////////////////////////////
function selecte(id, zonerch,url,zoneresultat){
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
		if(xhr.readyState  != 4)
		         {
					 document.getElementById(zonerch).style.display = 'none';
		}	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
					  document.getElementById(zoneresultat).style.display = 'block';
					  document.getElementById(zoneresultat).innerHTML = xhr.responseText;
			}
      }
};   

	xhr.open("POST", url, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" +id);
	   
   }
/////////////////////////////////////////////////////////////////////////////////////////////////
function lister_champs(theform)//icic la fonction qui va gÚnÚrer les ÚlÚments a envoyer
{
   var url='';
   for (i=0; i<theform.elements.length; i++)
   {
       if(((theform.elements[i].type=='radio' ||theform.elements[i].type=='checkbox') && theform.elements[i].checked==true) || (theform.elements[i].type!='radio' &&theform.elements[i].type!='checkbox'))//control si c'est des radio ou check box et incrÚmente le rÚsultat QUE si c'est cochÚ (sans þa il prendrais les deux)
           {
   if(theform.elements[i].type=='select-multiple' || theform.elements[i].type=='select' )//si c'est un select multiple 
   {
    for(j = theform.elements[i].length-1; j >= 0; j-=1)//on parcours les element du select multiple
       {
          if(theform.elements[i].options[j].selected)//si selectionnÚ on incremente
             {
                             if(url){url+='&';}
           url+=theform.elements[i].name+'='+theform.elements[i].options[j].value;
             }
     }
   }
   if(url){url+='&';}
   if(theform.elements[i].type!='select-multiple'){  url+=theform.elements[i].name+'='+theform.elements[i].value;}
           }
        }
return url;//onretourne le resultat vers la fonction appelÚe
}

function exploiteform(form,zonemsg,zone,msg,url,test,action){
	if(typeof form!="object"){form = document.getElementById(form);} //retourne object
	if(test==true){if(document.MM_returnValue==false) return false;}
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
		if(xhr.readyState  != 4)
		         {
					 document.getElementById(zonemsg).style.display = 'block';
					 document.getElementById(zonemsg).innerHTML = msg;
		}	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
				if(action=="0"){
					  document.getElementById(zonemsg).style.display = 'none';
					  document.getElementById(zone).style.display = 'block';
					  document.getElementById(zone).innerHTML = xhr.responseText;
				}
			}
      }
};   

	var script = url;   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(lister_champs(form) + "&action=" + action);
	return false;
}

/////////////////////////////////
 function promo(action,id){

	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { document.getElementById('divpromo').innerHTML = xhr.responseText; }
         }
	};   

	var script = 'promotionajax.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("action=" + action + "&id=" + id);
}  


function list_control_produit(controle, divcont){
		var xhr = createXHR();
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              if(xhr.responseText!=''){
								 document.getElementById(divcont).innerHTML = xhr.responseText;
								 document.getElementById(divcont).style.display = 'block';
							 }
				 }
         }
    }; 
	var script = "/gestion/divcont.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("controle=" + controle);
}
/////////////////////////////////////////////:

/////////////////////////////////
 function affphotoGM(photo){
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { 
			var w_s=win_size();
			 var lardiv=parseInt(document.getElementById('divphotoGM').style.width)*1;
               document.getElementById('divphotoGM').style.left=Math.floor(w_s[0]/2)-Math.floor(parseInt(lardiv)/2)+'px'; 
			   document.getElementById('divphotoGM').style.top=Math.floor(w_s[2])+parseInt(100)+'px'; 
			   document.getElementById('divphotoGM').style.display = 'block';
			document.getElementById('divphotoGM').innerHTML = xhr.responseText; }
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/_selficheGM.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("selphoto=" + photo);
}
function cachephotoGM(){
			   document.getElementById('divphotoGM').style.display = 'none';
}

 function afffiche(id){
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { 
			var w_s=win_size();
			 var lardiv=parseInt(document.getElementById('divphotoGM').style.width)*1;
               document.getElementById('divphotoGM').style.left=Math.floor(w_s[0]/2)-Math.floor(parseInt(lardiv)/2)+'px'; 
			   document.getElementById('divphotoGM').style.top=Math.floor(w_s[2])+parseInt(100)+'px'; 
			   document.getElementById('divphotoGM').style.display = 'block';
			document.getElementById('divphotoGM').innerHTML = xhr.responseText;
			}
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/_fiche_ajax.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id);
}
 function affContactTerrain(id){
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { 
		/*	var w_s=win_size();
			 var lardiv=parseInt(document.getElementById('divphotoGM').style.width)*1;
               document.getElementById('divphotoGM').style.left=Math.floor(w_s[0]/2)-Math.floor(parseInt(lardiv)/2)+'px'; 
			   document.getElementById('divphotoGM').style.top=Math.floor(w_s[2])+parseInt(100)+'px'; */
			   document.getElementById('divphotoGM').style.display = 'block';
			document.getElementById('divphotoGM').innerHTML = xhr.responseText; }
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/_selContactTerrain.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id);
}

 function affContactTerraincenter(id){
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { 
			var w_s=win_size();
			 var lardiv=parseInt(document.getElementById('divphotoGM').style.width)*1;
               document.getElementById('divphotoGM').style.left=Math.floor(w_s[0]/2)-Math.floor(parseInt(lardiv)/2)+'px'; 
			   document.getElementById('divphotoGM').style.top=Math.floor(w_s[2])+parseInt(10)+'px'; 
			   document.getElementById('divphotoGM').style.display = 'block';
			document.getElementById('divphotoGM').innerHTML = xhr.responseText; }
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/_selContactTerrain.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id);
}

 function affContactOffrescenter(id,idM,prix,nb_chambre,geo_carte,niveau,niveau_id){
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { 
			var w_s=win_size();
			 var lardiv=parseInt(document.getElementById('divphotoGM').style.width)*1;
               document.getElementById('divphotoGM').style.left=Math.floor(w_s[0]/2)-Math.floor(parseInt(lardiv)/2)+'px'; 
			   document.getElementById('divphotoGM').style.top=Math.floor(w_s[2])+parseInt(10)+'px'; 
			   document.getElementById('divphotoGM').style.display = 'block';
			document.getElementById('divphotoGM').innerHTML = xhr.responseText; }
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/_selContactOffres.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id + "&idM=" + idM + "&prix=" + prix + "&nb_chambre=" + nb_chambre + "&geo_carte=" + geo_carte + "&niveau=" + niveau + "&niveau_id=" + niveau_id);
}

 function affContactAgence(id){
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { 
			var w_s=win_size();
			 var lardiv=parseInt(document.getElementById('divphotoGM').style.width)*1;
               document.getElementById('divphotoGM').style.left=Math.floor(w_s[0]/2)-Math.floor(parseInt(lardiv)/2)+'px'; 
			   document.getElementById('divphotoGM').style.top=Math.floor(w_s[2])+parseInt(10)+'px'; 
			   document.getElementById('divphotoGM').style.display = 'block';
			document.getElementById('divphotoGM').innerHTML = xhr.responseText; }
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/_selContactAgence.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id);
}

////////////////////////////SIMULATEUR/////////////////////

 function affsimulateur(montant){
	 montant = montant.replace(" " ,"");
     montant = montant.replace("," ,".");
     montant=parseFloat(montant);
   var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 	
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) { 
			var w_s=win_size();
			 var lardiv=parseInt(document.getElementById('divsimulateur').style.width)*1;
               document.getElementById('divsimulateur').style.left=Math.floor(w_s[0]/2)-Math.floor(parseInt(lardiv)/2)+'px'; 
			   document.getElementById('divsimulateur').style.top=Math.floor(w_s[2])+parseInt(10)+'px'; 
			   document.getElementById('divsimulateur').style.display = 'block';
			document.getElementById('divsimulateur').innerHTML = xhr.responseText; }
         }
	};   
   //alert (port);
   // changer client_id en client
	var script = '/simulateur.php';   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("montant=" + montant);
}

function calcul_mens(){
var apport= document.getElementById('apport').value;
apport = apport.replace(" " ,"");
apport = apport.replace("," ,".");
apport=parseFloat(apport);

var K= document.getElementById('K').value;
if(K==''){
	alert('Capital emprunté est obligatoire !');
	return;
}
K = K.replace(" " ,"");
K = K.replace("," ,".");
K=parseFloat(K);
K=K-apport;
var as= document.getElementById('as').value;
as = as.replace(" " ,"");
as = as.replace("," ,".");
as=parseFloat(as);
var t= document.getElementById('t').value;
if(t==''){
	alert('Taux annuel est obligatoire !');
	return;
}
t = t.replace(" " ,"");
t = t.replace("," ,".");
t=parseFloat(t);
t=t+as;
t=t/100;
var n = document.getElementById('n').value;
if(n==''){
	alert('Nombre de d\'années est obligatoire !');
	return;
}
n = n.replace(" " ,"");
n = n.replace("," ,".");
n=parseInt(n);
n=n*12;
var m=0;
m=(K*(t/12))/(1-(Math.pow((1+(t/12)),-n)));

/*var ct=((m*n)+fd)-K;
ct=ct+'';
var l = ct.indexOf('.',0);
l=l+3;
ct=ct.substr(0,l);
document.getElementById('ct').value=ct;*/
m=m+'';
l = m.indexOf('.',0);
l=l+3;
m=m.substr(0,l);
document.getElementById('m').value=m;

}

function calcul_K(){
var fd= document.getElementById('fd').value;
fd = fd.replace(" " ,"");
fd = fd.replace("," ,".");
fd=parseFloat(fd);
var m= document.getElementById('m').value;
if(m==''){
	alert('Mensualités est obligatoire !');
	return;
}
m = m.replace(" " ,"");
m = m.replace("," ,".");
m=parseFloat(m);
var as= document.getElementById('as').value;
as = as.replace(" " ,"");
as = as.replace("," ,".");
as=parseFloat(as);
var t= document.getElementById('t').value;
if(t==''){
	alert('Taux annuel est obligatoire !');
	return;
}
t = t.replace(" " ,"");
t = t.replace("," ,".");
t=parseFloat(t);
t=t+as;
t=t/100;
var n = document.getElementById('n').value;
if(n==''){
	alert('Nombre de mensualités est obligatoire !');
	return;
}
n = n.replace(" " ,"");
n = n.replace("," ,".");
n=parseInt(n);
var K=0;
K=(m*(1-(Math.pow((1+(t/12)),-n))))/(t/12);

var ct=((m*n)+fd)-K;
ct=ct+'';
var l = ct.indexOf('.',0);
l=l+3;
ct=ct.substr(0,l);
document.getElementById('ct').value=ct;

K=K+'';
l = K.indexOf('.',0);
l=l+3;
K=K.substr(0,l);
document.getElementById('K').value=K;
}

//////////////////////PLANS///////////////////////////////////
function selnews(n, produit){
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
					  document.getElementById('divCAT2').innerHTML = xhr.responseText;
		 }
      }
	};   
	var script = "/selplan.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("n="+n+"&produit="+produit);
	return false;
}

///////////////////////////////////////////////////////////

function selsecteur(voirdiv,niveau,niveau_id){
	document.location='/index.php?niveau='+niveau+'&niveau_id='+niveau_id+'&voirdiv=divrub'+voirdiv
}
function selcarte(){
	document.location='/offres_terrains_conforeco.htm';
}

////////////////////////////////////////////////////

function selvideo(videosel)
{ 
	var reg=new RegExp("[|||]+", "g");
    var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              	if(xhr.responseText!=''){
					var tabchamp=xhr.responseText.split(reg);
					 document.getElementById('divplayer').innerHTML = tabchamp[0];
					 document.getElementById('divdescription').innerHTML = tabchamp[1];
					 $('#player').jwplayer({
					  flashplayer:'/file_flash/player.swf',
					  autostart:false,
					  skin:'/file_flash/five/five.xml'
					});
				}
			}
         }
    }; 
		var script = "/videosel.php";   // local script
		xhr.open("POST", script, true);		
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send("videosel=" + videosel);

}
