Index: trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/draw_api.js	(revision 5391)
+++ trunk/expressoMail1_2/js/draw_api.js	(revision 5392)
@@ -2599,109 +2599,123 @@
 	subject.innerHTML = info_msg.subject;
 	subject.className = "header_message_field";
-	var new_event_logo = document.createElement("IMG");
-	new_event_logo.title = "Criar evento a partir deste email";
-	new_event_logo.alt = "Criar evento a partir deste email";
-	new_event_logo.src = "./templates/default/images/calendar_add.png";
-	new_event_logo.style.cursor = "pointer";
-	new_event_logo.style.marginLeft = "5px";
-	new_event_logo.onclick = function(){
-		DataLayer.dispatchPath = "../prototype/";
-		var path = "../prototype/modules/calendar/";
-		eventDetails({ 
-				summary : $("#subject_"+ID).text(),
-				description : $("#body_" + ID).text(),
-				startTime: $.now(),
-				endTime:!!User.preferences.defaultCalendar ? Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration != "" ? ($.now() + Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration * 60000) : (User.preferences.defaultDuration * 60000)
-				: $.now() + (User.preferences.defaultDuration * 60000)
-		}, true, path);
-		
-		//TimePicker Não está funcionando corretamente, o motivo ainda é desconhecido.
-		/*
-		$(".new-event-win").find('input.time').timepicker({ 
-			closeText: 'Ok',
-			hourGrid: 4,
-			minuteGrid: 10,
-			//ampm : ((User.preferences.hourFormat.length > 5) ? true: false),
-			timeFormat: "hh:mm tt",
-			onSelect: function (selectedDateTime){
-				if(!(User.preferences.hourFormat.length == 5))
-					$(this).val(selectedDateTime.replace(/[\.]/gi, ""));								
-			},
-			onClose : function (selectedDateTime){
-				if(!(User.preferences.hourFormat.length == 5))
-					$(this).val(selectedDateTime.replace(/[\.]/gi, ""));
-			}
-		});
-		*/
-		
-		var emails = $("#to_values_"+ID).val();
-		emails = emails.split(",");
-		var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6');
-		var onShowToolTip = function(arg0) {
-			$('.qtip-active .button.close').button({
-				icons: {primary: "ui-icon-close"},
-				text: false
+	if(new_agenda == "True" && $("#expressoCalendarid")[0]){
+		var new_event_logo = document.createElement("IMG");
+		new_event_logo.title = "Criar evento a partir deste email";
+		new_event_logo.alt = "Criar evento a partir deste email";
+		new_event_logo.src = "./templates/default/images/calendar_add.png";
+		new_event_logo.style.cursor = "pointer";
+		new_event_logo.style.marginLeft = "5px";
+		new_event_logo.onclick = function(){
+			DataLayer.dispatchPath = "../prototype/";
+			var path = "../prototype/modules/calendar/";
+			eventDetails({ 
+					summary : $("#subject_"+ID).text(),
+					description : $("#body_" + ID).text(),
+					startTime: $.now(),
+					endTime:!!User.preferences.defaultCalendar ? Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration != "" ? ($.now() + Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration * 60000) : (User.preferences.defaultDuration * 60000)
+					: $.now() + (User.preferences.defaultDuration * 60000)
+			}, true, path);
+			
+			//TimePicker Não está funcionando corretamente, o motivo ainda é desconhecido.
+			/*
+			$(".new-event-win").find('input.time').timepicker({ 
+				closeText: 'Ok',
+				hourGrid: 4,
+				minuteGrid: 10,
+				//ampm : ((User.preferences.hourFormat.length > 5) ? true: false),
+				timeFormat: "hh:mm tt",
+				onSelect: function (selectedDateTime){
+					if(!(User.preferences.hourFormat.length == 5))
+						$(this).val(selectedDateTime.replace(/[\.]/gi, ""));								
+				},
+				onClose : function (selectedDateTime){
+					if(!(User.preferences.hourFormat.length == 5))
+						$(this).val(selectedDateTime.replace(/[\.]/gi, ""));
+				}
 			});
-			$('.qtip-active .button').button()
-			.filter('.save').click(function(event, ui) {
-				if (saveContact()) {						
-					lastEditAttendeeToolTip.qtip("destroy");
-				} else {
-					return false;
-				}
-			}).end()
-			.filter('.cancel').click(function(event, ui) {
-				lastEditAttendeeToolTip.qtip("destroy");
-			})
-
-			/** 
-			 * Trata o ENTER no campo da tooltip, equivalente a salvar 
-			 * o novo convidado.
-			 */
-			$('.qtip-active input').keydown(function(event) {
-				if (event.keyCode == '13') {						
+			*/
+			
+			var emails = $("#to_values_"+ID).val();
+			emails = emails.split(",");
+			var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6');
+			var onShowToolTip = function(arg0) {
+				$('.qtip-active .button.close').button({
+					icons: {primary: "ui-icon-close"},
+					text: false
+				});
+				$('.qtip-active .button').button()
+				.filter('.save').click(function(event, ui) {
 					if (saveContact()) {						
 						lastEditAttendeeToolTip.qtip("destroy");
+					} else {
+						return false;
 					}
-
+				}).end()
+				.filter('.cancel').click(function(event, ui) {
 					lastEditAttendeeToolTip.qtip("destroy");
-					event.preventDefault();
-				}
-			})
-			.filter('[name="name"]').Watermark("informe o nome do contato").end()
-			.filter('[name="mail"]').Watermark("informe o email do contato");
-		}
-				
-		$.each(emails, function(index, value) { 
-			var decoded =  Encoder.htmlDecode(value);
-			var newAttendeeName = "";
-			if(decoded.match(/<([^<]*)>[\s]*$/)){
-				var user = DataLayer.get('user', ["=", "mail", decoded.match(/<([^<]*)>[\s]*$/)[1].toLowerCase()], true);
-				if(!(!!user)){
-					newAttendeeName = decoded.match(/"([^"]*)"/)[1];
-					var newAttendeeEmail = decoded.match(/<([^<]*)>[\s]*$/)[1];
-				}
-			}
-			else{
-				var user = DataLayer.get('user', ["=", "mail", decoded], true);
-				if(!(!!user)){
-					if(decoded.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/))
-						var newAttendeeEmail = decoded;
-					else{
-						var newAttendeeEmail = "";
-						newAttendeeName = decoded;
+				})
+
+				/** 
+				 * Trata o ENTER no campo da tooltip, equivalente a salvar 
+				 * o novo convidado.
+				 */
+				$('.qtip-active input').keydown(function(event) {
+					if (event.keyCode == '13') {						
+						if (saveContact()) {						
+							lastEditAttendeeToolTip.qtip("destroy");
+						}
+
+						lastEditAttendeeToolTip.qtip("destroy");
+						event.preventDefault();
+					}
+				})
+				.filter('[name="name"]').Watermark("informe o nome do contato").end()
+				.filter('[name="mail"]').Watermark("informe o email do contato");
+			}
+					
+			$.each(emails, function(index, value) { 
+				var decoded =  Encoder.htmlDecode(value);
+				var newAttendeeName = "";
+				if(decoded.match(/<([^<]*)>[\s]*$/)){
+					var user = DataLayer.get('user', ["=", "mail", decoded.match(/<([^<]*)>[\s]*$/)[1].toLowerCase()], true);
+					if(!(!!user)){
+						newAttendeeName = decoded.match(/"([^"]*)"/)[1];
+						var newAttendeeEmail = decoded.match(/<([^<]*)>[\s]*$/)[1];
 					}
 				}
-			}
-				
-			var isExternal = (!!user && !(!!user.isExternal)) ? 0 : 1;
-			var add = false;
-			if(user){
-				if(!(blkAddAtendee.find('label.mail[title="' + user[0].mail + '"]').length)){
-					user[0].id =  DataLayer.put('participant', {user: user[0].id, isExternal: isExternal});
+				else{
+					var user = DataLayer.get('user', ["=", "mail", decoded], true);
+					if(!(!!user)){
+						if(decoded.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/))
+							var newAttendeeEmail = decoded;
+						else{
+							var newAttendeeEmail = "";
+							newAttendeeName = decoded;
+						}
+					}
+				}
+					
+				var isExternal = (!!user && !(!!user.isExternal)) ? 0 : 1;
+				var add = false;
+				if(user){
+					if(!(blkAddAtendee.find('label.mail[title="' + user[0].mail + '"]').length)){
+						user[0].id =  DataLayer.put('participant', {user: user[0].id, isExternal: isExternal});
+						blkAddAtendee.find('dd.attendee-list ul.attendee-list').append(
+							DataLayer.render(path+'templates/participants_add_itemlist.ejs', user)
+						)
+						.find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() {
+							DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val());
+							$(this).parent().remove();
+						}).end()
+						.scrollTo('max');
+						add = true;
+					}
+				}else{
+					userId = DataLayer.put('user', {name: newAttendeeName, mail: newAttendeeEmail, isExternal: isExternal});
+					newAttendeeId = DataLayer.put('participant', {user: userId, isExternal: isExternal});
+					
 					blkAddAtendee.find('dd.attendee-list ul.attendee-list').append(
-						DataLayer.render(path+'templates/participants_add_itemlist.ejs', user)
-					)
-					.find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() {
+						DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail, isExternal: 1}])
+					).find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() {
 						DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val());
 						$(this).parent().remove();
@@ -2710,43 +2724,31 @@
 					add = true;
 				}
-			}else{
-				userId = DataLayer.put('user', {name: newAttendeeName, mail: newAttendeeEmail, isExternal: isExternal});
-				newAttendeeId = DataLayer.put('participant', {user: userId, isExternal: isExternal});
-				
-				blkAddAtendee.find('dd.attendee-list ul.attendee-list').append(
-					DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail, isExternal: 1}])
-				).find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() {
-					DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val());
-					$(this).parent().remove();
-				}).end()
-				.scrollTo('max');
-				add = true;
-			}
-			if(add){
-				lastEditAttendeeToolTip = blkAddAtendee.find('dd.attendee-list li:last');
-				lastEditAttendeeToolTip.qtip({
-					show: {ready: false, solo: true, when: {event: 'click'}},
-					hide: false,
-					content: {
-						text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', {attendee:{name:( (!!user ? (!!user[0] ? (!!user[0].name ? !!user[0].name : newAttendeeName): newAttendeeName) : newAttendeeName)), mail:(!!user ? (!!user[0] ? (!!user[0].mail ? !!user[0].mail : newAttendeeEmail): newAttendeeEmail) : newAttendeeEmail)}} ) ), 
-						title: {
-							text:'Detalhes do participante', 
-							button: '<a class="button close" href="#">close</a>'
+				if(add){
+					lastEditAttendeeToolTip = blkAddAtendee.find('dd.attendee-list li:last');
+					lastEditAttendeeToolTip.qtip({
+						show: {ready: false, solo: true, when: {event: 'click'}},
+						hide: false,
+						content: {
+							text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', {attendee:{name:( (!!user ? (!!user[0] ? (!!user[0].name ? user[0].name : newAttendeeName): newAttendeeName) : newAttendeeName)), mail:(!!user ? (!!user[0] ? (!!user[0].mail ? user[0].mail : newAttendeeEmail): newAttendeeEmail) : newAttendeeEmail)}} ) ), 
+							title: {
+								text:'Detalhes do participante', 
+								button: '<a class="button close" href="#">close</a>'
+							}
+						},
+						style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}},
+						position: {
+							corner: {
+								target: 'rightMiddle',
+								tooltip: 'leftMiddle'
+							},
+							adjust: {x:0, y:0}
 						}
-					},
-					style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}},
-					position: {
-						corner: {
-							target: 'rightMiddle',
-							tooltip: 'leftMiddle'
-						},
-						adjust: {x:0, y:0}
-					}
-				});
-				lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip;
-			}
-		});						
-	}
-	subject.appendChild(new_event_logo);
+					});
+					lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip;
+				}
+			});						
+		}
+		subject.appendChild(new_event_logo);
+	}
 	tr5.appendChild(td5);
 	tr5.appendChild(subject);
