Index: trunk/expressoMail1_2/js/main.js
===================================================================
--- trunk/expressoMail1_2/js/main.js	(revision 5339)
+++ trunk/expressoMail1_2/js/main.js	(revision 5357)
@@ -2075,12 +2075,12 @@
 		return;
 	}
-
+	stringEmail = Element("to_"+ID).value;
+	stringEmail += Element("cco_"+ID).value =='' ? "":", "+Element("cco_"+ID).value;
+	stringEmail += Element("cc_"+ID).value =='' ? "":", "+Element("cc_"+ID).value;
 	if (expresso_offline) {
-		stringEmail = Element("to_"+ID).value;
-		stringEmail += Element("cco_"+ID).value =='' ? "":", "+Element("cco_"+ID).value;
-		stringEmail += Element("cc_"+ID).value =='' ? "":", "+Element("cc_"+ID).value;
+		
 		var invalidEmail = searchEmail(stringEmail);
 		if(Element("to_"+ID).value=="" && Element("cco_"+ID).value=="" && Element("cc_"+ID).value=="") {
-			write_msg(get_lang("message without receiver."));
+			write_msg(get_lang("message without receiver"));
 			return;
 		}else if(invalidEmail[0] == true){
@@ -2095,5 +2095,10 @@
 	}
 	else{
-		cExecuteForm("$this.imap_functions.send_mail", form, handler_send_message, ID);
+		if(stringEmail != "")
+			cExecuteForm("$this.imap_functions.send_mail", form, handler_send_message, ID);
+		else{
+			write_msg(get_lang("message without receiver"));
+			return;
+		}
 	}
 }
@@ -3332,9 +3337,10 @@
 function import_calendar(data){
     var import_url = '$this.db_functions.import_vcard&msg_folder='+data;
-
-	function handler_import_calendar(data){
-		if(data === true){
-			write_msg(get_lang("The event was imported successfully."));
-		}
+	var logUser;
+	var up;
+    function handler_import_calendar(data){
+            if(data === true){
+                    write_msg(get_lang("The event was imported successfully."));
+            }
             else if( data['url'] )
             {
@@ -3350,8 +3356,92 @@
             else
                 write_msg(get_lang(data));
-	}
-	if(confirm(get_lang("Do you confirm this import to your Calendar?"))){
-                    cExecute( import_url +'&from_ajax=true',handler_import_calendar);
-    }
+    }	
+	if(new_agenda == 'false'){
+		if(confirm(get_lang("Do you confirm this import to your Calendar?"))){
+			cExecute( import_url +'&from_ajax=true',handler_import_calendar);
+		}
+	}else{			
+		$( "#import-dialog" ).dialog({
+			autoOpen: false,
+			height: 220,
+			modal: true,
+			resizable : false,
+			buttons: {
+				Cancel: function() {
+					$( this ).dialog( "close" );
+				},
+				"Importar": function() {
+					$.ajax({
+						 url: "controller.php?action="+import_url+'&from_ajax=true&selected='+$("#select-agenda option:selected").val()+'&status='+$("#select-status option:selected").val(),
+						 success: function(data){
+							data = connector.unserialize(data);
+							if(data == "ok"){
+								if(!up)
+									alert("Importado com sucesso para "+$("#select-agenda option:selected").text());
+								else
+									alert("Evento atualizado com sucesso ... ");
+							}
+							else{
+								if(!up)
+									alert("Ocorreu um erro ao importar o evento para a agenda "+$("#select-agenda option:selected").text());
+								else
+									alert("Ocorreu um erro ao atualizar o evento  ... ");
+							}
+						}
+					});
+					
+					$( this ).dialog( "close" );
+				}
+			},
+			close: function(event) {
+				event.stopPropagation();
+			},
+			closeOnEscape: true
+		});
+		$.ajax({
+				url: '../prototype/modules/calendar/index.php',
+				async: false,
+				success: function(){
+					$.ajax({
+					url: "controller.php?action="+import_url+'&from_ajax=true&selected='+$("#select-agenda option:selected").val()+'&readable=true',
+					async: false,
+					success: function(data){
+						data = connector.unserialize(data);
+						if(data){
+							up = true;
+							$("#select-agenda").css("display", "none");
+							$("#import-dialog" ).children("p:first-child").css("display", "none");
+							$("#import-dialog" ).dialog({
+								height: 160,
+								title: 'Atualizar Evento'
+							});
+							$(".ui-dialog-buttonpane").find(".ui-button:last").children().html("Atualizar");
+						}
+						else{
+							$.getJSON("../prototype/me.php", function(user){
+								logUser = user;
+								up = false;
+								$("#select-agenda").css("display", "");
+								$("#import-dialog" ).children("p:first-child").css("display", "");
+								$.getJSON("../prototype/request.php",
+								{
+									concept : "calendarSignature",
+									criteria : {'deepness' : 2},
+									filter : ["=", "user", logUser.id]
+								}, function(calendarSignatures){
+									$("#select-agenda").html('');
+									for(var calendario in calendarSignatures){
+										var doc = document .createElement("OPTION");
+										doc.value = calendarSignatures[parseInt(calendario)].calendar.id;
+										doc.innerHTML = calendarSignatures[parseInt(calendario)].calendar.name;
+										$("#select-agenda").append(doc);
+									}
+								});
+							});
+						}
+					}});
+				}});
+		}
+		$( "#import-dialog" ).dialog( "open" );
 }
 function open_msg_part(data){
