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];}
}


/* 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 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( nameListeCheckbox ) );
		return false;
	}
	
}

// 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 deja valide
	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;
}


/*


function select_camping()
{
	//recuperation des types de destination coches et des regions et stations selectionnees
	var typesDestination = '';
	
	var destination_camping = '';
	if(document.getElementById('destination_camping'))
	{
		destination_camping = document.getElementById('destination_camping').value;
	}
	
	
	$.ajax({
		type: "POST",
		data: "camping="+destination_camping,
		url:  "ajax/ajax_filter_search.php",
		success: function(msg){
						
		      	if(msg != ""){
		        			        	
		        	var result = msg.split('|');
		        	if(result.length == 3)
		        	{
		        		//Traitement des regions
		        		var aRegions = result[1].split(':');
		        		
                if(!display_search_selectbox(aRegions[0],aRegions[1].split(','),region))
		        		{
		        			document.getElementById('recherche_region').value = '';
		        		}
		        		
		        		//Traitement des destinations
		        		var aDestinations = result[2].split(':');
		        		if(!display_search_selectbox(aDestinations[0],aDestinations[1].split(','),station))
		        		{
		        			document.getElementById('recherche_station').value = '';
		        		}		        				        		
		        	}
			
			      }
			      
			      return false;
			      
	      	}
	    
	 });	
}

function select_pays()
{
	
	var pays = '';
	if(document.getElementById('destination_pays'))
	{
		pays = document.getElementById('destination_pays').value;
	}
		
	$.ajax({
		type: "POST",
		data: "pays="+pays,
		url:  "ajax/ajax_filter_pays.php",
		success: function(msg){
						
		      	if(msg != ""){
		        			        	
		        	var result = msg.split('|');
		        	if(result.length == 3)
		        	{
		        		//Traitement des campings
		        		var aCampings = result[1].split(':');
		        		
                if(!display_search_selectbox(aRegions[0],aRegions[1].split(','),region))
		        		{
		        			document.getElementById('recherche_region').value = '';
		        		}		        		
		        	}
			
			      }
            			      
			      return false;
			      
	      	}
	    
	 });
}


function display_search_selectbox(idSelectBox,optionList,defaut)
{

  alert(idSelectBox);
	var found = false;
	
	var selectObject = document.getElementById(idSelectBox);
	if(selectObject)
	{
		//Vide la liste
		while ( selectObject.options.length > 1) {
    					
    			selectObject.options[1] = null;
		}
		if(optionList.length > 0 && optionList!= '')
		{
			for(var i=0; i < optionList.length; i++) {
		 			
				var tabOption = optionList[i].split('##');
				var oOption = document.createElement("OPTION");
			   	oOption.text= tabOption[1];
			   	oOption.value= tabOption[0];
			   		
			   	if(defaut == tabOption[0])
			   	{
			   		oOption.selected=true;
			   		found = true;
			   	}	
			   					
	   			if(jQuery.browser.msie)
	   			{	   			
	   				selectObject.add(oOption);
	   			}
	   			else
	   			{
	   				selectObject.appendChild(oOption);
	   			}
			}
			
		}
		
		//Regeneration du code JQUERY de la station
		 document.getElementById(idSelectBox+'_input').parentNode.removeChild(document.getElementById(idSelectBox+'_input'));
		 document.getElementById(idSelectBox+'_container').parentNode.removeChild(document.getElementById(idSelectBox+'_container')); 			
		 $('#'+idSelectBox).selectbox({ containerClass: 'selectbox-wrapper '+idSelectBox});
	}
	
	return found;
}

*/

// *** 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', 'destination', 'periode', 'nom',
																		'prenom', 'telephone', 'email', 'message' ) ) {					
		document.forms['formContact'].submit();		
	}																		
	else {
		return false;
	}
}
// *** / Formulaire de contact *** //

// *** 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 *** //

// *** Formulaire de brochure *** //
function validBrochure(){	
	if ( valider_formulaire_generique('formBrochure', 'nom', 'prenom', 'email' ) ) {	
		
	request = "id_camp=" + document.getElementById('id_camp').value + "&civilite=" + document.getElementById('civilite').value + "&nom=" + document.getElementById('nom').value + "&prenom=" + document.getElementById('prenom').value + "&email=" + document.getElementById('email').value;	
	$.ajax({
		type: "POST",
		data: request,
		async: true,
		url:  "ajax/ajax_insert_brochure.php",		
		success: function(data){
			
			var tab = data.split("|");	
			var err = 0;
			
				document.getElementById('getBrochure').innerHTML = tab[1];
			
		} });
	}
}
// *** / Formulaire de brochure *** //


// *** Formulaire de brochure Fiche Camping *** //
function validBrochureCamping() {	
  
	if ( valider_formulaire_generique('formBrochureCamping', 'nom_camp', 'prenom_camp', 'email_camp' ) ) {	
		
		request = "id_camp=" + document.getElementById('id_camping').value + "&civilite=" + document.getElementById('civilite_camp').value + "&nom=" + document.getElementById('nom_camp').value + "&prenom=" + document.getElementById('prenom_camp').value + "&email=" + document.getElementById('email_camp').value;	
		//alert(request);
		//return false;
    $.ajax({
			type: "POST",
			data: request,
			async: true,
			url:  "ajax/ajax_insert_brochure.php",		
			success: function(data){
				
				var tab = data.split("|");	
				var err = 0;
				
				document.getElementById('getBrochureCamping').innerHTML = tab[1];
				
			} });
	}

}
// *** / Formulaire de brochure *** //


// *** Formulaire de brochure CE *** //
function checkAllRegions( nameForm, nameCheck ) {
	
	if ( document.getElementById('all_regions').checked == true )
		var state = true;
	else
		var state = false;
	var checkboxes = document.getElementsByName(nameCheck);  
  for (var i=0;i<checkboxes.length;i++) {	
		checkboxes[i].checked = state;			
	}
  
  return true;
  
}

function validCaptchaBrochureCe(){	
	$.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"){								
				validFormBrochureCe();
			}else{
				alert(get_trad_champ('bad_captcha'));		
				document.forms['formBrochureCe'].elements['strcode'].select();		
				return false;
			}
		} });
	
}

function validFormBrochureCe() {
	if ( valider_formulaire_generique('formBrochureCe', 'societe', 'nom', 'prenom', 'fonction', 
																		'adresse', 'cp', 'ville', 'pays', 'telephone', 'email', 'effectif', 'message' ) ) {					
		if ( valider_liste_checkbox ( 'brochure_devis[]' ) ) {
			if ( valider_liste_checkbox ( 'regions[]' ) ) {
				if ( valider_liste_checkbox ( 'formules_ce[]' ) ) {
					document.forms['formBrochureCe'].submit();		
				}
				else {
					return false;
				}
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	}																		
	else {
		return false;
	}
}
// *** / Formulaire de brochure CE *** //

// *** / Formulaire de brochure Groupe *** //


function validFormBrochureGroupe() {
	if ( valider_formulaire_generique('formBrochureGroupe', 'societe', 'nom', 'prenom', 'fonction', 
																		'adresse', 'cp', 'ville', 'pays', 'telephone', 'email', 'effectif', 'message' ) ) {					
		if ( valider_liste_checkbox ( 'brochure_devis[]' ) ) {
			if ( valider_liste_checkbox ( 'regions[]' ) ) {
				if ( valider_liste_checkbox ( 'formules_groupe[]' ) ) {
					document.forms['formBrochureGroupe'].submit();		
				}
				else {
					return false;
				}
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	}																		
	else {
		return false;
	}
}


function validCaptchaBrochureGroupe(){	
	$.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"){								
				validFormBrochureGroupe();
			}else{
				alert(get_trad_champ('bad_captcha'));		
				document.forms['formBrochureGroupe'].elements['strcode'].select();		
				return false;
			}
		} });
	
}


// *** / Formulaire de brochure Groupe *** //

// *** Ouvrir une visite virtuelle hébergement *** //

function goToHebergement () {
	
	var urlHebergement = document.getElementById('campingEnImages').value;	
	initHerbegementPopin ( urlHebergement );	
	
}

// *** / Ouvrir une visite virtuelle hébergement *** //

// *** Imprimer un camping *** //

function printCamping(idRub, idCamping) {
	
	var Left=window.screen.width/2-400;
	var Top=window.screen.height/2-300;
	//Videment faut modifier la config!!
	var Configuration="'toolbar=no, menubar=yes, location=no, directories=no, status=no, resizeable=no, scrollbars=yes, width=800, height=500, left=" + Left + ", top=" + Top;
	window.open('fiche_camping_print.php?Rub='+idRub+'&id_camp='+idCamping,'Imprimer',Configuration);
	
}

// *** / Imprimer un camping *** //


// *** Formulaire de Recrutement *** //

function validJob() {	
	if ( valider_formulaire_generique('formJob', 'nom', 'prenom', 'email', 'telephone', 'lettre_motivation', 'cv') ) {
		document.forms['formJob'].submit();
	}
	else {
		return false;
	}		
}

// *** / Formulaire de Recrutement *** //

// *** Formulaire de Connexion Bourse *** //

function validFormLoginBourse() {	
	if ( valider_formulaire_generique('formLoginBourse', 'login', 'pwd' ) ) {
		document.forms['formLoginBourse'].submit();
	}
	else {
		return false;
	}		
}

// *** / Formulaire de Connexion Bourse *** //

// *** Formulaire d'action Bourse *** //

function validFormModifBourse() {	
	if ( valider_formulaire_generique('formModifBourse', 'libelle', 'prix', 'contenu', 'contact' ) ) {
		document.forms['formModifBourse'].submit();
	}
	else {
		return false;
	}		
}

// *** / Formulaire d'action  Bourse *** //

// *** Formulaire d'action Bourse *** //

function validFormDeleteBourse(idAnnonce) {	
	if ( confirm ( get_trad_champ("delannonce") ) ) {		
		document.forms['formDeleteBourse'+idAnnonce].submit();
	}
	else {
		return false;
	}		
}

// *** / Formulaire d'action  Bourse *** //

// *** Formulaire de contact Bourse *** //

function validformContacterBourse() {	
	if ( valider_formulaire_generique('formContacterBourse', 'message' ) ) {
		document.forms['formContacterBourse'].submit();
	}
	else {
		return false;
	}	
}

// *** / Formulaire de contact Bourse *** //
