//Ouverture de la popup modale pour le partage d'un deal par email
function openModalShareDealByMail(id, uri){
	var html =    '<form method="post" id="formSharingMail">'
				+	'<p class="center">Recipient email address</p>'
				+	'<p class="center">'
				+		'<input style="width:200px;" type="text" id="destinataireEmail" name="destinataireEmail" />'
				+	'</p>'
				+ 	'<input type="hidden" id="dealUri" name="dealUri" value="'+uri+'" />'
				+ 	'<input type="hidden" id="dealId" name="dealId" value="'+id+'" />'
				+ 	'<p id="errorMail" class="center" style="display:none;">&nbsp;</p>'
				+	'<p style="text-align: right;" class="resetP"><a target="_blank" href="page,10,privacy-statement">Privacy Statement</a></p>'
				+ '</form>';
				
	$("#dialog").attr('title', 'Share this Sweet Deal by Email');
	$("#dialog").html(html);
	
	$("#dialog").dialog({
		modal:true,
		resizable:false,
		buttons: {
					'Cancel' : function(){
						$(this).dialog('close');
					},
					'Send' : function(){
						var vraiOuFauxCheck  = false;
						$("#destinataireEmail").attr('style', 'width:200px;color:#000000;background:ffffff;');
						$("#errorMail").attr('style', 'display:none;');
						if (valideSyntaxOfMail($("#destinataireEmail").val())){
							$.post(
								"ajax/deal.ajax.php?task=shareByMail", $("#formSharingMail").serialize(),
								function(data){
									var tabReponse = data.split('|@|');
									if(tabReponse[0] == 'ok') {
										$('#dialog').html('<p class="center">Your email has been sent.</p>');
									}
									else {
										$('#dialog').html('<p class="center">An internal error has occured.</p>');
									}
									$('#dialog').dialog('option', 'buttons', { "Close": function() { $(this).dialog("close"); } });
								}
							);
						}
						else {
							$("#destinataireEmail").attr('style', 'width:200px;color:#000000;background:#dbeff7;');
							$("#errorMail").attr('style', 'display:block;');
							$("#errorMail").html('<span style="font-weight:bold;color:#000000;">Invalid email address!</span>');
						}
					}
		},
		close : function(){
			resetModalDialog();
			$(this).dialog('destroy');
		}
	});
}

function openModalCompleterInfos(){
	var html =    '<form method="post" id="formCompleterInfos">'
				+	'<p class="center">'
				+		'Yor email'
				+	'</p>'
				+	'<p class="center">'
				+		'<input style="width:200px;" type="text" id="EmailMembre" name="EmailMembre" />'
				+	'</p>'
				+ 	'<p id="errorMail" class="center" style="display:none;">&nbsp;</p>'
				+ '</form>';
				
	$("#dialog").attr('title', 'Complete your profile');
	$("#dialog").html(html);
	
	$("#dialog").dialog({
		modal:true,
		resizable:false,
		buttons: {
					'Cancel' : function(){
						$(this).dialog('close');
					},
					'Submit' : function(){
						$("#EmailMembre").attr('style', 'width:200px;color:#000000;background:ffffff;');
						$("#errorMail").attr('style', 'display:none;');
						if (valideSyntaxOfMail($("#EmailMembre").val())){
							var params = "avecEmail=true&champ=memberemail&value1="+$("#EmailMembre").val()+"&value2="+$("#EmailMembre").val();
							$.ajax({
								type: "POST",
								url: "ajax/mon_compte.ajax.php?task=FormEmail",
								data: params,
								success: function(msg){
									var tabReponse = msg.split('|@|');
									if(tabReponse[0] == 'ok') {
										$('#dialog').html('<p class="center">Your profile is now complete.</p>');
									}
									else {
										$('#dialog').html('<p class="center">An internal error has occured.</p>');
									}
									$('#dialog').dialog('option', 'buttons', { "Close": function() { $(this).dialog("close"); } });
							   },
							   failure: function(){
								   $("#dialog").html('<p class="center">An internal error has occured</p>');
								   $("#dialog").attr('title', 'Error');
									openModalDialog();
							   }
							});
						}
						else {
							$("#EmailMembre").attr('style', 'width:200px;color:##000000;background:#dbeff7;');
							$("#errorMail").attr('style', 'display:block;');
							$("#errorMail").html('<span style="font-weight:bold;color:#000000;">Invalid email!</span>');
						}
					}
		},
		close : function(){
			resetModalDialog();
			$(this).dialog('destroy');
		}
	});
}

function showLocalisation(adresse){
	var map;
	$("#dialog").attr('title', 'Map');
	$("#dialog").dialog({
		modal:true,
		resizable:false,
		height:500,
		width:700,
		buttons: {
					'Close' : function(){
						$(this).dialog('close');
					}
		},
		close : function(){
			resetModalDialog();
			$(this).dialog('destroy');
		}
	});

	if (GBrowserIsCompatible()) {
		var SkooponIcon = new GIcon(G_DEFAULT_ICON);
		SkooponIcon.image = "http://www.twangoo.com/images/TwangooGMapIcon.png";
		markerOptions = { icon:SkooponIcon };
		map = new google.maps.Map2(document.getElementById("dialog")); 
		// Recherche des coordonnées d'un point dont on connait l'adresse :
		var geocoder = new google.maps.ClientGeocoder();
		geocoder.getLatLng(adresse, function (coord) {
			// Et centrage de la map sur les coordonnées renvoyées par Google :
			map.setCenter(coord, 16);
			var marker = new GMarker(coord, markerOptions);
			map.addOverlay(marker);
			var mapControl = new GLargeMapControl3D();
			map.addControl(mapControl);
		});
	} 
}

//Pour la synchronisation du compte à rebours
function serverTime() { 
	var time = null; 
    $.ajax({
		url: 'ajax/common.ajax.php?task=serverSyncTime', 
        async: false, 
		dataType: 'text', 
        success: function(text) { 
            time = new Date(text); 
        }, error: function(http, message, exc) { 
            time = new Date(); 
    }}); 
    return time; 
}

