﻿function launchDialogSendtofriend(container,titre,texte) {
	container.attr("title",titre);
	container.find("p").html(texte);
	//alert($("#dialog").attr("title"));
	container.dialog({
			autoOpen: true,
			bgiframe: false,
			modal: true,
			width: 230,
			close: function(event, ui) {$(this).dialog('destroy');$("select").show();$("#lang_choix").show();},
			buttons: {
				"Send": function() {
					actionDialogSendtofriend();
					//$(this).dialog('close');
					//$(this).dialog('destroy');
				},
				"Cancel": function() {
					$(this).dialog('close');
					/*$(this).dialog('destroy');*/
				}
			}
	});
}


var html_form_sendtofriend = "";
html_form_sendtofriend += "<form id=\"to_friend_form\" method=\"get\" action=\"#\" style=\"display: block;\">";
html_form_sendtofriend += "<label for=\"prenom_nom_from_friend\">First name & name* </label>";
html_form_sendtofriend += "<input id=\"prenom_nom_from_friend\" type=\"text\" name=\"prenom_nom_from_friend\"/>";
html_form_sendtofriend += "<label for=\"email_from_friend\">My E-mail* </label>";
html_form_sendtofriend += "<input id=\"email_from_friend\" type=\"text\" name=\"email_from_friend\"/>";
html_form_sendtofriend += "<label for=\"prenom_nom_to_friend\">First name & Name of the recipient* </label>";
html_form_sendtofriend += "<input id=\"prenom_nom_to_friend\" type=\"text\" name=\"prenom_nom_to_friend\"/>";
html_form_sendtofriend += "<label for=\"email_to_friend\">E-mail of the recipient* </label>";
html_form_sendtofriend += "<input id=\"email_to_friend\" type=\"text\" name=\"email_to_friend\"/>";
html_form_sendtofriend += "<label class=\"hint\">* required fields<br />&nbsp;<br/>";
html_form_sendtofriend += "This information is confidential. It is for use by accor and is protected by the French law \"information Technology and Freedom\". To learn more, see our confidentiality policy.</label>";
html_form_sendtofriend += "<div style=\"width: 175px; text-align: justify; font-size: 9px;\">";
html_form_sendtofriend += "</div>";
html_form_sendtofriend += "</form>";

$(function() {
	$("#envoiAmi>a").click(function(){
		$("select").hide();
		$("#lang_choix").hide();
		//$("#nav_ban").css("display","none");
		//$("#actu_ban").css("display","none");
		launchDialogSendtofriend($("#dialog"),"Send to a friend",html_form_sendtofriend);
		pageTracker._trackPageview('clic_envoi_ami_gb');
		return(false);
	})
})
function actionDialogSendtofriend(){
	var expediteur = $("#prenom_nom_from_friend").val();
	var expediteur_mail = $("#email_from_friend").val();
	var destinataire = $("#prenom_nom_to_friend").val();
	var destinataire_mail = $("#email_to_friend").val();
	//$("#dialog").dialog('close');
	//$("#dialog").dialog('destroy');
	$.get("http://www.hotelf1.com/php/gb_action_send_to_friend.php", { nom_expediteur: expediteur, mail_expediteur: expediteur_mail, nom_destinataire: destinataire, mail_destinataire: destinataire_mail },
		function(data){
	    	//alert("Data Loaded: " + data);
			if(data == "ok"){
				confirmDialogSendtofriend($("#dialog_erreur"),"Confirmation","Your message has been sent");
			}else{
				errorDialogSendtofriend($("#dialog_erreur"),data,"check your email");
			}
	});
}
function errorDialogSendtofriend(container,titre,texte) {
	container.attr("title",titre);
	container.find("p").html(texte);
	container.dialog({
			autoOpen: true,
			bgiframe: false,
			modal: true,
			width: 230,
			stack: true,
			close: function(event, ui) {$(this).dialog('destroy');},
			buttons: {
				"Correct": function() {
					$(this).dialog('close');
					/*$(this).dialog('destroy');*/
				}
			}
	});
}
function confirmDialogSendtofriend(container,titre,texte) {
	container.attr("title",titre);
	container.find("p").html(texte);
	container.dialog({
			autoOpen: true,
			bgiframe: false,
			modal: true,
			width: 230,
			stack: true,
			close: function(event, ui) {$(this).dialog('destroy');},
			buttons: {
				"Close": function() {
					$(this).dialog('close');
					$(this).dialog('destroy');
					$("#dialog").dialog('close');
					$("#dialog").dialog('destroy');
				}
			}
	});
}