
function enregistrer_alerte()
{
	var ajax = new PMP.util.pmpAjax("/_modules/bien/alias.ajax", "POST");
	
	if(!ajax)
	{
		var msgbox = new PMP.util.pmpMsgBox("L'instanciation de la classe AJAX a échouée", "erreur", titreBox);
		return false;
	}
	
	ajax.appendData("action", "enregistrer_alerte");
	ajax.appendData("nomprenom", $("#nomprenomalerte").val());
	ajax.appendData("email", $("#emailalerte").val());
	
	var types = PMP.dom.getElementsByMaskId("typealerte_%s", "input");
	chaine = '';
	var j=0
	for(i = 0; i < types.length; i++)
	{
		if(types[i].checked == true)
		{
			chaine += (j>0 ? '|' : '')+ types[i].value;
			j++;
		}
	}
	
	ajax.appendData('type', chaine);
	
	var chambres = PMP.dom.getElementsByMaskId("nb_chambrealerte_%s", "input");
	chaine = '';
	var j=0
	for(i = 0; i < chambres.length; i++)
	{
		if(chambres[i].checked == true)
		{
			chaine += (j>0 ? '|' : '')+ chambres[i].value;
			j++;
		}
	}
	
	ajax.appendData('chambre', chaine);
	
	ajax.appendData("amount", $("#amountalerte").val());
			
	ajax.send({context:true});
	
	if(ajax.reponse.etat)
	{
		$("#alertform").dialog('close');		
		$("#div_alerte").attr('title', 'Information');
		$("#div_alerte").html('Votre alerte a bien été enregistrée');
		
		$("#div_alerte").dialog({
	    	modal: true,
			bgiframe: true,
	    	width: 300,
	    	//height: 200,
	    	dialogClass: "confirmation",
	    	autoOpen: false,
			draggable: false,
			resizable: false,
	    	overlay: { opacity: 1, background: "white" },
			buttons: {'Fermer': function(){$(this).dialog("close");}}
  		});
  		
		$("#div_alerte").dialog('open');
	}
	else{
		//var chaine = ajax.reponse.message;
		var tmp = ''+ajax.reponse.champs+'';
		var chaine = '<span class=\"ui-icon ui-icon-alert\" style=\"float:left; margin:0 7px 20px 0;\"></span>Certains champs n\'ont pas été correctement saisis, merci de vérifier les éléments marqués ci-dessous.';
		
		var tab = tmp.split(',');		
		
		for(i=0;i<tab.length;i++)
		{
			if(tab[i] == 'nomprenom')
				document.getElementById('span_nomprenomalerte').className = 'erreursaisie';
			
			if(tab[i] == 'email')
				document.getElementById('span_emailalerte').className = 'erreursaisie';
			
			if(tab[i] == 'email_format')
				document.getElementById('span_emailalerte').className = 'erreursaisie';
		}
		
		$('#div_alerte').attr('title', 'Erreur');
		$("#div_alerte").html(chaine);
		
		$("#div_alerte").dialog({
	    	modal: true,
			bgiframe: true,
	    	width: 300,
	    	//height: 200,
	    	dialogClass: "erreur",
	    	autoOpen: false,
			draggable: false,
			resizable: false,
	    	overlay: { opacity: 1, background: "white" },
			buttons: {'Fermer': function(){$(this).dialog("close");}}
  		});
		$("#div_alerte").dialog('open');
	}
	
	return ajax.reponse;
}

function envoyer_email()
{
	var ajax = new PMP.util.pmpAjax("/_modules/bien/alias.ajax", "POST");
	
	if(!ajax)
	{
		var msgbox = new PMP.util.pmpMsgBox("L'instanciation de la classe AJAX a échouée", "erreur", titreBox);
		return false;
	}
	
	ajax.appendData("action", "envoyer_email");
	ajax.appendData("nomprenom", $("#nompremail").val());
	ajax.appendData("email", $("#emailmail").val());	
	ajax.appendData('message', $("#mailmsg").val());
	ajax.appendData('reference', $("#referencemail").val());
	ajax.appendData('telephone', $("#telephonemail").val());
	
	ajax.send({context:true});
	
	if(ajax.reponse.etat)
	{
		$("#mailform").dialog('close');
		$("#msg_mail").attr('title', 'Information');
		$("#msg_mail").html('<span class=\"ui-icon ui-icon-alert\" style=\"float:left; margin:0 7px 20px 0;\"></span>Votre message a bien été envoyé.');
		$("#msg_mail").dialog({
		    modal: true,
			bgiframe: true,
		    dialogClass: 'confirmation',
		    autoOpen: false,
			draggable: false,
			resizable: false,
		    overlay: { opacity: 1, background: "white" },
			buttons: {'Fermer': function(){$(this).dialog("close");}}
	  	});		
		$("#msg_mail").dialog('open');
		
		$("#nompremail").val('');
		$("#emailmail").val('');	
		$("#mailmsg").val('');
	}
	else{
		//var chaine = ajax.reponse.message;
		var chaine = '<span class=\"ui-icon ui-icon-alert\" style=\"float:left; margin:0 7px 20px 0;\"></span>Certains champs n\'ont pas été correctement saisis, merci de vérifier les éléments marqués ci-dessous.<ul>';
		var tmp = ''+ajax.reponse.champs+'';
		
		var tab = tmp.split(',');		
		
		for(i=0;i<tab.length;i++)
		{
			if(tab[i] == 'nomprenom')
				document.getElementById('span_nompremail').className = 'erreursaisie';
			
			if(tab[i] == 'email')
				document.getElementById('span_emailmail').className = 'erreursaisie';
			
			if(tab[i] == 'email_format')
				document.getElementById('span_emailmail').className = 'erreursaisie';
			
			if(tab[i] == 'message')
				document.getElementById('span_mailmsg').className = 'erreursaisie';
		}
		
		chaine += '</ul>';
		
		$("#msg_mail").html(chaine);
		$("#msg_mail").attr('title', 'Erreur');
		$("#msg_mail").dialog({
		    modal: true,
			bgiframe: true,
		    dialogClass: 'erreur',
		    autoOpen: false,
			draggable: false,
			resizable: false,
		    overlay: { opacity: 1, background: "white" },
			buttons: {'Fermer': function(){$(this).dialog("close");}}
	  	});
		$("#msg_mail").dialog('open');
	}
	
	return ajax.reponse;
}