// JavaScript Document
function PopupCentrer(page,largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

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

function disabledFormL(val) {
		if(val != "") {
			//window.location.href = "index.php?module=detail_loc&id="+val;
			var myName = val.options[val.selectedIndex].text.replace(/\s+/g,"");
			myName = myName.replace("°", "");
			myName = myName.replace(".", "");
			myName = myName.replace("é", "e");
			myName = myName.replace("è", "e");
			myName = myName.replace("'", "");
			window.location.href = "detail_loc-"+val.value+"-"+myName+".html";
			/*document.getElementById("search_quartier").disabled = true;
			document.getElementById("search_room").disabled 	= true;
			document.getElementById("part_4").disabled 			= true;
			document.getElementById("part_3").disabled 			= true;
			document.getElementById("part_2").disabled 			= true;*/
		} /*else {
			document.getElementById("search_quartier").disabled = false;
			document.getElementById("search_room").disabled 	= false;
			document.getElementById("part_4").disabled 			= false;
			document.getElementById("part_3").disabled 			= false;
			document.getElementById("part_2").disabled 			= false;
		}*/
}

function disabledFormV(val) {
		if(val != "") {
			//window.location.href = "index.php?module=detail_vente&id="+val;
			var myName = val.options[val.selectedIndex].text.replace(/\s+/g,"");
			myName = myName.replace("°", "");
			myName = myName.replace(".", "");
			myName = myName.replace("é", "e");
			myName = myName.replace("è", "e");
			myName = myName.replace("'", "");
			window.location.href = "detail_vente-"+val.value+"-"+myName+".html";
			/*document.getElementById("search_quartier").disabled = true;
			document.getElementById("search_type_bien").disabled = true;*/
		} /*else {
			document.getElementById("search_quartier").disabled = false;
			document.getElementById("search_type_bien").disabled = false;
		}*/
}

function verifEmail(email) {
	invalidMailChars = "/\?!()<^>àâèéêëîïôöùûç#%*µ¨£$,;:+{}'";
	erreurMail=false;
	//recherche des caractères contenus dans invalidChars	
	for (i=0;i<invalidMailChars.length;i++){
		if(email.indexOf(invalidMailChars.charAt(i))!=-1) {
			erreurMail=true;
		}
	}
	if  (email.indexOf(' ')!==-1 ) {erreurMail=true;} // si il n'y a un espace
	if  (email.indexOf('.')==-1  || email.indexOf('@')==-1) {erreurMail=true;} // si il n'y a ni "@" ni "."
	if  (email.indexOf('..')!==-1 || email.indexOf('@.')!==-1 || email.indexOf('.@')!==-1) {erreurMail=true;} // si il y a ".." ,".@","@."
	if  (email.indexOf('@')!=email.lastIndexOf('@')) {erreurMail=true;} // si il y a plus de deux "@"
	if ((email.indexOf('@')==0) || (email.indexOf('.')==0) || (email.lastIndexOf('@')==email.length-1) || (email.lastIndexOf('.')==email.length-1)) {erreurMail=true;} // si  "@" ou "." commencent ou finissent => si il n'y a que un "." ou un "@" ou ".@" ou "@."
	if ((email.lastIndexOf('@')-email.lastIndexOf('.'))>1) {erreurMail=true;} // si le dernier "." est avant "@"
	if (email.length-1-email.lastIndexOf('.')==1) {erreurMail=true;} // si le dernier "." est suivi d'un seul caractere

	return erreurMail;		
}

function IsNumeric(strString)
//  check for valid numeric strings     
{
  var strValidChars = "0123456789.-";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
  {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1)
    {
      blnResult = false;
    }
  }
  return blnResult;
}


function validForm() {
	error = "";
	with(document.form_resa) {
		//NOM
		if(nom.value == "") {
			error += "- Votre nom\n";
		}
		//PRENOM
		if(prenom.value == "") {
			error += "- Votre prénom\n";
		}
		//EMAIL
		/*if(email.value == "") {
			error += "- Votre email\n";
		}*/
		//EMAIL VALID
		if(verifEmail(email.value)) {
			error += "- Votre email\n";
		}			
		//TEL
		if(tel.value == "") {
			error += "- Votre téléphone\n";
		}
		// ADULTS QTY
		if(adults.value == "") {
			error += "- Nombre d'adultes\n";
		} else {
			if(!IsNumeric(adults.value)) {
				error += "- Nombre d'adultes si soyez numerique\n";
			}
		}
		// CHILDREN QTY
		if(children.value == "") {
			error += "- Nombre enfants\n";
		} else {
			if(!IsNumeric(children.value)) {
				error += "- Nombre enfants si soyez numerique\n";
			}
		}
	}

	if(error!= "") {
		error = "Veuillez verifier les champs suivants : \n"+error
		alert(error);
	} else {
		document.form_resa.submit();
	}
}
