function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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_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];}
}
/*
// verifie la validite d'un email
function validemail(champ)
{
	
	
	var email = document.getElementById(champ);
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) 
	{
	 	alert(get_trad_champ("email"));
		email.focus
		return false;
	}
	else
	{
		return true;
	}
}

// verifie les champs obligatoire d'un formulaire
valider_formulaire = function () {
	var tab = valider_formulaire.arguments;

	taille = tab.length;

	for (i=0;i<taille;i++) {
		if (tab[i]=="email") {
			if (!validemail(tab[i])) {
				return 0; 
			}
		}else{
			if ((document.formulaire.elements[tab[i]].value.trim()=="") || (document.formulaire.elements[tab[i]].value.trim()==" ")) {
				str_temp = tab[i].replace(/_/g," ");
				alert(get_trad_champ(str_temp));
				return 0; 
			}
		}
	}
	
	document.formulaire.submit();
}
*/
/* Fonctions génériques de validation de formulaire */
// Verifie la validite d'un email
function valide_mail_generique ( nameForm, champ ) {
	
	var email = document.forms[nameForm].elements[champ];
		
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if ( !filter.test(email.value) ) {
		
	 	alert(get_trad_champ("email"));
		email.select();
		return false;
	}
	else {
		return true;
	}
}


// Verifie les champs obligatoire d'un formulaire
valider_formulaire_generique = function () {
	var tab = valider_formulaire_generique.arguments;

	taille = tab.length;

	if ( taille > 0 ) {

		nameForm = tab[0];
		
		for ( i = 1; i < taille; i++ ) {
			
			if ( tab[i] == "email" ) {
				if ( !valide_mail_generique( nameForm, tab[i] ) ) {
					return false; 
				}
			}
			else {
				if ( ( document.forms[nameForm].elements[tab[i]].value.trim() == "" ) ) {				
					alert ( get_trad_champ( tab[i] ) );				
					document.forms[nameForm].elements[tab[i]].select();
					return false; 
				}
			}
		}
		
		return true;
		
	}
	else {
		return false;
	}
}

/*
// Exemple d'appel
function validForm() {
	if ( valider_formulaire_generique('nom_du_formulaire', 'champ_1', 'champ_2' ... ) ) {				
		document.forms['nom_du_formulaire'].submit();					
	}
	else {
		return false;
	}		
}
*/

function empechechar()
{
	if( event.keyCode < 48 || event.keyCode > 57 )
 	{ 
 		alert(get_trad_champ("numeric") );
   		event.returnValue = false;
   	}
}

// fonction qui fait apparaitre le sablier sur soumission de formulaire un peu long..

// Variable témoin de la validation effectuée ou pas
var deja = 0;

function valider(nom_form) {
	// Si on n'a pas déjà validé
	if ( deja == 0 ) {

		// On marque qu'on valide
		deja = 1;
					
		// On affecte le style 'sablier' au corps de la page
		document.body.className = 'sablier';
		
		// On lance la soumission du formulaire
		eval('document.'+nom_form+'.submit()');
	} /*else {
		alert('Le formulaire est déjà validé, veuillez patienter.'); */
}

function show_sablier()
{
	document.body.className = 'sablier';
}


// verifie les champs obligatoire d'un formulaire
verif_formulaire_nom = function () {
	var tab = verif_formulaire_nom.arguments;
	var nom_form = "formulaire";
	
	taille = tab.length;

	if (taille>0)
	{
		nom_form = tab[0];
	}	

	for (i=1;i<taille;i++) {
		if (tab[i]=="email") {
			if (!validemail(tab[i])) {
				return 0; 
			}
		}else{
	
			if ((document.getElementById(tab[i]).value.trim()=="")  || (document.getElementById(tab[i]).value.trim()==" ")) {
				//str_temp = tab[i].replace(/_/g," ");
				str_temp = tab[i];
				alert(get_trad_champ(str_temp));
				return 0; 
			}
		}
	}
	
	return true
}

String.prototype.trim = function() {

        return this.replace(/^\s+|\s+$/g,"");

}

function isValidDate ( _fieldId )
{
    if ( _fieldId == "" )
        return true;

    // Récupération de la valeur
    var totalDate    = document.getElementById( _fieldId ).value;
    if ( totalDate == "" )
        return false;
   
    // Découpage de la date récupérée
    var aDate = totalDate.split( "/" );
    if ( aDate.length != 3 )
        return false;

    // Création d'un objet date
    var generatedDate = new Date ( aDate[ 2 ], aDate[ 1 ] - 1, aDate[ 0 ] );
   
    // Test
    if (     generatedDate.getFullYear() == aDate[ 2 ]
        &&    generatedDate.getMonth() + 1 == aDate[ 1 ]
        &&    generatedDate.getDate() == aDate[ 0 ] )
        return true;
   
    return false;
}

// ===================================================================== //
// ============================ LES BALCONS ============================ //
// ===================================================================== //

// *** Formulaire de newsletter home *** //

function validFormHomeNewsletter() {		
	if ( valider_formulaire_generique('formHomeNewsletter', 'email' ) ) {
		document.forms['formHomeNewsletter'].submit();
	}
	else {
		return false;
	}	
}

// *** / Formulaire de newsletter home *** //

// *** Formulaire de contact *** //
function validCaptchaContact(){	
	$.ajax({
		type: "POST",
		data: "captcha="+document.getElementById('strcode').value,
		async: true,
		url:  "ajax/ajax_verif_captcha.php",		
		success: function(data){
			
			var tab = data.split("|");	
			var err = 0;
			
			if(tab[1] == "OK"){								
				validFormContact();
			}else{
				alert(get_trad_champ('bad_captcha'));		
				document.forms['formContact'].elements['strcode'].select();		
				return false;
			}
		} });
	
}

function validFormContact() {
	if ( valider_formulaire_generique('formContact', 'nom',	'prenom', 'telephone', 'email', 'message' ) ) {
		document.forms['formContact'].submit();		
	}																		
	else {
		return false;
	}
}

// Verifie la validite d'un email
function valider_liste_checkbox ( nameListeCheckbox ) {
	
	var checkboxes = document.getElementsByName(nameListeCheckbox);  
	var indiceValid = 0;
	
  for ( var i=0; i < checkboxes.length; i++ ) {	
		if ( checkboxes[i].checked == true ) {
			indiceValid = 1;
		}			
	}
	  
  // Au moins une case est cochée
  if ( indiceValid == 1 ) {
  	return true;
  }
  // Si aucune case cochée
	else {
		alert ( get_trad_champ( 'checkBrochure' ) );
		return false;
	}
	
}

// *** Formulaire de contact *** //
function validCaptchaBrochure(){	
	
	$.ajax({
		type: "POST",
		data: "captcha="+document.getElementById('strcode').value,
		async: true,
		url:  "ajax/ajax_verif_captcha.php",		
		success: function(data){
			
			var tab = data.split("|");	
			var err = 0;
			
			if(tab[1] == "OK"){								
				
				validFormBrochure();
			}else{
											
				alert(get_trad_champ('bad_captcha'));		
				document.forms['formBrochure'].elements['strcode'].select();		
				return false;
			}
		} });
	
}

function validFormBrochure() {
	if ( valider_liste_checkbox ( 'brochure[]' ) ) {
		if ( valider_formulaire_generique('formBrochure', 'nom',	'prenom', 'adresse', 'cp', 'ville', 'telephone', 'email' ) ) {
			document.forms['formBrochure'].submit();		
		}																		
		else {
			return false;
		}	
	}
	else {
		return false;
	}
}

//update Listes
function updateListResidence(ws_ville){
	$.ajax({
		type: "post",
		data: "ws_ville="+ws_ville,
		async: true,
		url:  "ajax/ajax_update_liste_residences.php",		
		success: function(data){			
			$('#residence').html(data);			
			$('#type_hebergement').html("<option value=\"\">------------------------------------------------------</option>");
		} });
}

// *** / Formulaire de contact *** //
function updateListTypeHebergement(ws_etablissement){		
	$.ajax({
		type: "post",
		data: "ws_etablissement="+ws_etablissement,
		async: true,
		url:  "ajax/ajax_update_liste_type_hebergement.php",		
		success: function(data){			
			$('#type_hebergement').html(data);			
		} });
}


// *** / Ajax - Moteur de recherche *** //
function getListeResidenceForMoteur(station) {		
	$.ajax({
		type: "post",
		data: "station="+station,
		async: true,
		url:  "ajax/ajax_get_residence_for_moteur.php",		
		success: function(data){				
			
			var tab = data.split("|");
			
			$('#search_form_etab').html(tab[0]);						
			$('#search_form_etab').resetSS();			
			
			if ( tab[1] != "" ) {
				$('#search_form_search_themes').html(tab[1]);	
				$('#search_form_search_themes').resetSS();			
			}	
			
						
		} });
}

function getListeStationForMoteur(residence) {			
	$.ajax({
		type: "post",
		data: "residence="+residence,
		async: true,
		url:  "ajax/ajax_get_station_for_moteur.php",		
		success: function(data){	
			
			var tab = data.split("|");
					
			$('#search_form_search_themes').html(tab[0]);		
			$('#search_form_search_themes').resetSS();				
			
			if ( tab[1] != "" ) {
				$('#search_form_etab').html(tab[1]);
				$('#search_form_etab').resetSS();			
			}
				
		} });
}



// *** Formulaire de newsletter *** //
function validCaptchaNewsletter(){	
	$.ajax({
		type: "POST",
		data: "captcha="+document.getElementById('strcode').value,
		async: true,
		url:  "ajax/ajax_verif_captcha.php",		
		success: function(data){
			
			var tab = data.split("|");	
			var err = 0;
			
			if(tab[1] == "OK"){								
				validFormNewsletter();
			}else{
				alert(get_trad_champ('bad_captcha'));		
				document.forms['formNewsletter'].elements['strcode'].select();		
				return false;
			}
		} });
	
}

function validFormNewsletter() {
	if ( valider_formulaire_generique('formNewsletter', 'nom', 'prenom', 'email' ) ) {					
		document.forms['formNewsletter'].submit();		
	}																		
	else {
		return false;
	}
}
// *** / Formulaire de newsletter *** //

// *** Ouverture popin saison *** //
function openPopinSaison() {			
	$.fn.colorbox({opacity:"0.7" , close:"FERMER" , width:"450px" , height:"230px" , scrolling:false , scalePhotos:false ,inline:true, href:"#changeSeasonPopin"});		
}
