function TAFDialog(lang) {
	// Language variables
	var dialogTitle = (lang == "english") ? "Email a Friend" : "Dites-le &#xE0; un ami";
	var errorEmailMsg = (lang == "english") ? "Invalid email address" : "Addresse courriel invalide";
	var errorReqMsg = (lang == "english") ? "This field is required" : "Champ obligatoire";
	
	$("body").append("<div id=\"dialog\" title=\"" + dialogTitle + "\" class=\"myDialog\"></div>");
	$.ui.dialog.defaults.bgiframe = true;
	$(function() {
		$.ajax({
			url: "/gm/" + lang + "/email-form",
			cache: false,
			success: function(html){
				$("#dialog").append(html);
				$('#emailReturnMsgSuccess').hide();
				$('#emailReturnMsgFail').hide();
				$("#dialog").dialog({
					buttons: {
						"Send": function() { $("#EmailForm").submit(); },
						"Cancel": function() { $(this).dialog("close"); }
					},
					close: function(event, ui) {
						$("#dialog").remove(); // remove dom elements upon closing the dialog
					},
					modal:true,
					width:700,
					height:550,
					zIndex:100001
				});
				if(lang == "french") { //
					$('#dialog').dialog('option', 'buttons', {
						"Envoyer": function() { $("#EmailForm").submit(); },
						"Annuler": function() { $(this).dialog("close"); }
					});
				}
				$("#EmailForm").validate({
					messages: {
						from_name: { required: errorReqMsg },
						from_email: { email: errorEmailMsg, required: errorReqMsg },
						to_email_1: { email: errorEmailMsg, required: errorReqMsg },
						to_email_2: { email: errorEmailMsg },
						to_email_3: { email: errorEmailMsg },
						to_email_4: { email: errorEmailMsg }
					},
					submitHandler: function(html) {
						$.ajax({
							type: "GET",
							data: "from_name=" + $("#from_name").val() + "&from_email=" + $("#from_email").val() + "&sendcopy=" + $("#sendcopy").attr("checked") + "&to_email_1=" + $("#to_email_1").val() + "&to_email_2=" + $("#to_email_2").val() + "&to_email_3=" + $("#to_email_3").val() + "&to_email_4=" + $("#to_email_4").val() + "&message=" + $("#message").val() +"&url=" + location.href,
							url: "/gm/"+lang+"/sendemail",
							success: function(data, textStatus) {
								$("#EmailForm").hide();
								$("#dialog").dialog('destroy');
								$('#emailReturnMsgSuccess').show();
								$("#dialog").dialog({
									buttons: {
										"OK": function() { $(this).dialog("close"); }
									},
									close: function(event, ui) {
										$("#dialog").remove(); // remove dom elements upon closing the dialog
									},
									modal:true,
									zIndex:1500000
								});
								$("#dialog").show();
							},
							error: function(XMLHttpRequest, textStatus, errorThrown) {
								$("#EmailForm").hide();
								$("#dialog").dialog('destroy');
								$('#emailReturnMsgFail').hide();
								$("#dialog").dialog({
									buttons: {
										"OK": function() { $(this).dialog("close"); }
									},
									close: function(event, ui) {
										$("#dialog").remove(); // remove dom elements upon closing the dialog
									},
									modal:true,
									zIndex:1500000
								});
								$("#dialog").show();
							}
						});
					}
				});
			}
		});
	});
}
