//
function verifierDateResa(){
    function close(){
	$("a.close").click(function(){
	    $(msgResa).hide();   
	});
    }
    var msgResa = $("#msgResa");
    var load = $("#loader");
    $(load).hide();
    $(msgResa).hide();
    $("a#verifDate").click(function(){
		    
	var dateArrivee = $("#datepicker").val();
	
	if(dateArrivee == ""){
	    $(load).hide();
	    $(msgResa).text("");
	    $(msgResa).show();
	    $(msgResa).append('<a href="#" title="Fermer" class="close"><img src="imagesFront/close.png" alt=""/></a>Vous devez choisir une date en cliquant dans le champ date d\'arrivée.');
	    close();
	}else{
	    
	    var idCh = $("a#verifDate").attr("rel");
	    $("a#verifDate").hide();
	    $(load).show();
	    $.ajax({
		type: 'GET',      // envoi des données en POST
		url: ' pages/verifier_date_resa.php?dateA='+dateArrivee+'&idCh='+idCh+' ',     // envoi au fichier défini dans l'attribut action
		success: function(msg) {     // callback en cas de succès
		    $(msgResa).text("");
		    $(msgResa).show();
		    if(msg == 0){
			$(load).hide();
			$(msgResa).append('<a href="#" title="Fermer" class="close"><img src="imagesFront/close.png" alt=""/></a>Cette chambre est disponible à cette date');
			$("input.submit").show();
			close();
		    }else{
			$(load).hide();
			$(msgResa).append('<a href="#" title="Fermer" class="close"><img src="imagesFront/close.png" alt=""/></a>Cette chambre est déjà réservée à cette date');
			$("input.submit").hide();
			close();
		    }
		    $("a#verifDate").show();
		}
	   });
	}
    });   
}


function carteInteractive(){
    var carte = $("p#carteInteractive");
    $(carte).show();
    $("a.carteInteractive").click(function(){
	$(carte).toggle();
    });
}

function formulaire(){
    var contact = $("#contact");
    var error = $("p.error");
    var load = $("p.load");
    $(contact).hide();
    $(error).hide();
    $(load).hide();
    
    $("a.contact").click(function(){
	$(contact).fadeIn(300);
    });
    
    $("a.close").click(function(){
	$(contact).fadeOut();
    });
    
    $("form#contactForm").submit(function(e){
	e.preventDefault();
	if( ($("#email").val() == "") || ($("#objet").val() == "") || ($("#message").val() == "")  ){
	    $(error).text("");
	    $(error).append("Tous les champs sont obligatoires").fadeIn(200);
	}else{
	    var datas = $(this).serialize();
	    $(load).show();
	    $(error).text("");
	    $.ajax({
		type: 'POST',      // envoi des données en POST
		url: $(this).attr('action'),     // envoi au fichier défini dans l'attribut action
		data: datas,     // sélection des champs à envoyer
		success: function(msg) {     // callback en cas de succès
		    $(error).text("");
		    $(load).hide();
		    if(msg == 1){
			$(error).append("Votre message a bien été envoyé.");
			$(error).fadeIn(200);
			$("form#contactForm").hide();
		    }else{
			$(error).append("Votre message n'a pas été envoyé au destinataire.");
		    }
		}
	   });
	}
    });
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MasquerDiv(nom_div){
	var div = nom_div;
	document.getElementById('div_'+div).style.display = 'none';
}

function setproperty(div, value, initvalue){
	if(document.getElementById(div).style.fontSize == value+"px"){
		document.getElementById(div).style.fontSize = initvalue+"px";
	}else{
		document.getElementById(div).style.fontSize = value+"px";
	}
}

function confirmerSuppressionDossier(modId,dr,sd){
	if(confirm("Etes-vous sûr de vouloir supprimer ce dossier ?\nTous les fichiers présents dans ce dossier seront supprimés")){
	window.location="index.php?m="+modId+"&dr="+dr+"&sd="+sd+"&supprimerDossier";
	}
}

function confirmerSuppressionFichier(modId,dr,sd,fichier,div,typeAffichage){
	if(confirm("Etes-vous sûr de vouloir supprimer ce fichier ?")){
	window.location="index.php?m="+modId+"&dr="+dr+"&sd="+sd+"&fichier="+fichier+"&supprimerFichier&div="+div+"&af="+typeAffichage+"";
	}
}

function confirmerSuppression(modId,enrId,titre,rub){
	if(confirm("Etes-vous sûr de vouloir supprimer cet enregistrement ?")){
	window.location="index.php?"+modId+"&"+enrId+"&t="+titre+"&supprimer=true&div="+rub+"";
	}
}

function confirmerSuppression2(url,enrId,titre,rub){
	if(confirm("Etes-vous sûr de vouloir supprimer cet enregistrement ?")){
	window.location="index.php?"+url+"&"+enrId+"&t="+titre+"&supprimer=true&div="+rub+"";
	}
}

// coloriser champ lors d'un focus
function color_input(id){
	document.getElementById(id).style.backgroundColor = '#EBEBEB';
}
function no_color_input(id){
	document.getElementById(id).style.backgroundColor = '#FFFFFF';
}

// Afficher et masquer un div
// Afficher et masquer un div
function AfficherDiv(nom_div,puce){
	var div = nom_div;
	var modifierPuce = puce;
	 if(document.getElementById('div_'+div).style.display == 'block'){
	 	document.getElementById('div_'+div).style.display = 'none';
		if(modifierPuce){
			document.getElementById('puce_'+div).src = 'imagesDefault/puce_plus.gif';
		}
	}else{
		document.getElementById('div_'+div).style.display = 'block';
		document.getElementById('puce_'+div).src = 'imagesDefault/puce_moins.gif';
	}
	 
}
function MasquerDiv(nom_div){
	var div = nom_div;
	document.getElementById('div_'+div).style.display = 'none';
}

function AfficherDivInfosPratiques(nom_div1, nom_div2, nom_div3){
	document.getElementById('div_'+nom_div1).style.display = 'block';
	document.getElementById('bt_'+nom_div1).backgroundImage = 'imagesFront/bt_infos_on.png';
	document.getElementById('div_'+nom_div2).style.display = 'none';
	document.getElementById('bt_'+nom_div2).backgroundImage = 'imagesFront/bt_infos_off.png';
	document.getElementById('div_'+nom_div3).style.display = 'none';
	document.getElementById('bt_'+nom_div3).backgroundImage = 'imagesFront/bt_infos_off.png';
}


// gestion des menus déroulant
window.onload=affiche_div;
function affiche_div(id){
	var div = document.getElementById('div_'+id);
	for (var i = 0; i<=100; i++) {
		if (document.getElementById('div_'+i)) {
		document.getElementById('div_'+i).style.display='none';
		}
	}
	if(div){
	document.getElementById('div_'+id).style.display='block';
	document.getElementById('div_'+id).style.marginBottom = '20px';
	}
}

function coloriserDt(div,color){
	document.getElementById('dt'+div).style.backgroundColor = color;
}

function coloriser(div){
	document.getElementById(div).style.backgroundColor = '#EBEBEB';
}
function divFondBlanc(div){
	document.getElementById(div).style.backgroundColor = '#FFFFFF';
}

window.onload=montre;
function montre(nameDD,id) {
var d = document.getElementById(nameDD+id);
	for (var i = 1; i<=100; i++) {
		if (document.getElementById(nameDD+i)) {
			//alert(nameDD+i);
			document.getElementById(nameDD+i).style.display='none';
		}
	}
	if(d){
		d.style.display='block';
	}
}

function verifSelectFichier(){
	if(document.form1.image_a_copier.value == ''){
	alert("Sélectionner une image à enregistrer");
	return false;
	}else{
	return true;
	}
}

function progression(){
	document.getElementById("progression").style.display = 'block';
}

