
function IsEmail(email) {
// Vérifie si un Email est correct
   var saisie,saisie1,saisie2,saisie3;
   saisie = email.indexOf("@");
   if (saisie!=(-1)) {
      longueur = email.length;
      saisie1 = email.substring(saisie+1,longueur);
      saisie2 = saisie1.indexOf(".");
      longueur = saisie1.length;
      saisie3 = saisie1.substring(saisie2+1,longueur);
      if (saisie2==(-1)) return false;
      else {
         if (saisie3 == "") return false;
         else return true;
      }
   }
   else return false;
   }

   


function valide_estimation()
{
	if ((document.form1.nom.value.length == 0)||(document.form1.prenom.value.length == 0)||(document.form1.tel.value.length == 0))
	{
	alert("Certains champs obligatoires ne sont pas remplis !");
	return false;
	}
	else
	{
	
	if(!IsEmail(document.form1.email.value)) 
	{
	alert("Merci d'indiquer une adresse e-mail valide.");
	return false;
	}
	else
	document.form1.submit();
	
	}
		
	

}




function calc(m,d,t)
{
	var xhr_object = null;
								
				if(window.XMLHttpRequest) // Firefox
				   xhr_object = new XMLHttpRequest();
				else if(window.ActiveXObject) // Internet Explorer
				   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
					else { // XMLHttpRequest non supporté par le navigateur
						   alert("Votre navigateur ne supporte pas la methode d'identification Fleurlys...");
						   return;
						}
						
				//var seid	  = window.document.getElementById("sid").innerHTML;		
				var filename = "calc.php";
				var data     = null;
				var method   = "GET";
								
				data="m="+m+"&d="+d+"&t="+t;
			
				if(method == "GET" && data != null) {
				   filename += "?"+data;
				   data      = null;
				}
				
				xhr_object.open(method, filename, true);	

					xhr_object.onreadystatechange =function() {
					
					 if(xhr_object.readyState == 1) { 
								   }
							
							if(xhr_object.readyState == 4) {
							
								var res = xhr_object.responseText;
	
								window.document.getElementById("rescalc").innerHTML=res;
							
							}
							
					
														}				

												
						xhr_object.send(data);							
				
	
	
}








var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
		newWin.close();
	}
}

function popUp2(strURL,strType,strHeight,strWidth) {
	closeWin();
	var strOptions="";
	if (strType=="console") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location, height="+strHeight+",width="+strWidth;
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}

function popUp(strURL,strType,strHeight,strWidth) {
	closeWin();
	var strOptions="";
	if (strType=="console") strOptions="resizable,scrollbars,height=940,width=760";
	if (strType=="fixed") strOptions="status,height=940,width=760";
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location, height=940,width=760";
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
} 



function adapt_av()
{
	 window.document.getElementById("actualisation").innerHTML='<img src="img/loader.gif" width="8" height="8"/> Actualisation en cours...';
		if(document.search_form.av[0].checked==true)
		{
			document.getElementById('type').options[0]=new Option('------- Tous -------', '-1'); 
			document.getElementById('type').options[1]=new Option('Maison', 'Maison'); 
			document.getElementById('type').options[2]=new Option('Appartements / Studios', '5'); 
			document.getElementById('type').options[3]=new Option('Terrains', '10'); 
			document.getElementById('type').options[4]=new Option('Emplacements / Garages', '15'); 
			document.getElementById('type').options[5]=new Option('Locaux Commerciaux', '20'); 
			document.getElementById('type').options[6]=new Option('Projets en construction', '25'); 
			
			
		}
		
		if(document.search_form.av[1].checked==true)
		{
			document.getElementById('type').options[0]=new Option('------- Tous -------', '-1'); 
			document.getElementById('type').options[1]=new Option('Maisons', '50'); 
			document.getElementById('type').options[2]=new Option('Appartements / Studios', '55'); 
			document.getElementById('type').options[3]=new Option('Emplacements / Garages', '60'); 
			document.getElementById('type').options[4]=new Option('Locaux Commerciaux', '65'); 
			document.getElementById('type').options[5]=new Option('Locations Saisonnières', '70'); 
		}
	
	 window.document.getElementById("actualisation").innerHTML='';
}

function apply_price_mask()
{
	oNumberMask = null;
	oNumberMask = new Mask("#_###", "number");
	oNumberMask.attach(document.search_form.prixvalue);
	// Reformatage
	if (document.search_form.prixvalue.value != '')
	   document.search_form.prixvalue.value = oNumberMask.format(document.search_form.prixvalue.value); 	
	
}

function update_town()
{
	
	 window.document.getElementById("actualisation").innerHTML='<img src="img/loader.gif" width="8" height="8"/> Actualisation en cours...';
	

	var r=document.getElementById('type').options[document.getElementById('type').selectedIndex].value;
	
	/////////////////////////////
	
	var xhr_object = null;
								
				if(window.XMLHttpRequest) // Firefox
				   xhr_object = new XMLHttpRequest();
				else if(window.ActiveXObject) // Internet Explorer
				   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
					else { // XMLHttpRequest non supporté par le navigateur
						   alert("Votre navigateur ne supporte pas les requetes XHTML HTTP...");
						   return;
						}
						
					
				var filename = "inc.update_town.php";
				var data     = null;
				var method   = "GET";
								
				data="r="+r;
			
				if(method == "GET" && data != null) {
				   filename += "?"+data;
				   data      = null;
				}
				
				xhr_object.open(method, filename, true);	

					xhr_object.onreadystatechange =function() {
					
					
					if(xhr_object.readyState == 1) { 
					 window.document.getElementById("actualisation").innerHTML='<img src="img/loader.gif" width="8" height="8"/> Actualisation en cours...';
								   }
							
							if(xhr_object.readyState == 4) {
								 window.document.getElementById("actualisation").innerHTML='';
							var res = xhr_object.responseText;
							window.document.getElementById("typespan").innerHTML=res;
							
							
							
							
							
							}
							
					
														}				

												
						xhr_object.send(data);		



	
	///////////////////////////
}
