$(document).ready(function()
{
	function CloseSendEmail()
	{
		$("#currentMsgSuccess").hide();
		$("#currentMsgError").hide();
		$(":input[type=text]").attr("value", "");
		$("#sendmail label.error").remove();
	}
	
	var  command = "";
	$("#dialog_mail").dialog({ width: 500, height: 230, autoOpen: false, bgiframe: true, modal :true,draggable : false, close: CloseSendEmail});

	$("div.video img").click(function() { $("#dialog_videos").dialog('open'); });

	$("div.sendMail").click(function() {
		command = this.id;
		$("#dialog_mail").dialog('open');
	});
	
	$("#sendmail").validate({
		event: "keyup",
		rules:
		{
			email : { required : true, email : true }
		},
		messages:
		{
			email : { required : "Champs Requis" , email : "E-mail Invalide" }
		}
	});

	$("#sendmail").submit(function()
	{
		$("#currentMsgSuccess").hide();
		$("#currentMsgError").hide();
		if(command != "")
		{
			if($("#sendmail").valid())
			{
				$("#currentMsg").html("Envoi en cours. veuillez patienter...");
				$("#progress-sendmail").show();
				var otherc = command.split("#");
				var email = $("#email").val();
				var optins = $(":input[@name=optinssendmail]:checked").val();
				optins = ((optins == undefined) ? "off" : optins);
				var reponse = $.ajax({
					type  : "POST",
					url   : "./index.php?action="+otherc[0],
					data  : "subaction="+otherc[1]+"&id="+otherc[2]+"&email="+email+"&optinssendmail="+optins,
					async: false,
					success: function(result) { $(this).remove(); }
				}).responseText;
				$("#progress-sendmail").hide();
				if(reponse == "true")
					$("#currentMsgSuccess").show();
				else if(reponse == "false")
					$("#currentMsgError").show();
			}
		}
	});
});