Index: trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/draw_api.js	(revision 5588)
+++ trunk/expressoMail1_2/js/draw_api.js	(revision 5592)
@@ -2884,150 +2884,72 @@
 			var endEvent = function(date){ 
 				if(!!User.preferences.defaultCalendar){ 
-					return  parseInt(date.getTime()) + 
-						(	!!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ?  
+					return  new Date(parseInt(date.getTime()) + 
+						    (!!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ?  
 							(Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration * 60000) :
 							(User.preferences.defaultDuration * 60000)
-						);
+						));
 				}else 
-					return parseInt(date.getTime()) + (User.preferences.defaultDuration * 60000); 
+					return new Date(parseInt(date.getTime()) + (User.preferences.defaultDuration * 60000)); 
 			};       
+
+			var emails = $("#to_values_"+ID).val().split(',');
+			
+			
+			//Normalização dos dados evita ter que reemplementar toda as funcionalidades do calendar
 			eventDetails({ 
+					
+					acl: {inviteGuests: true, organization: true ,participationRequired: false, read: true, write: true},
+					alarms: [],
+					allDay: false,
+					attachments: [],
+					attendee: '',//TODOOOOOO,
+					calendar: User.preferences.defaultCalendar ? User.preferences.defaultCalendar : Calendar.calendars[0],
+					calendars: Calendar.calendars,
+					category: '',
+					class: '1',
+					delegatedFrom: {},
+					endDate: startEvent.toString(User.preferences.dateFormat),
+					startDate: endEvent(startEvent).toString(User.preferences.dateFormat),
+					startHour: startEvent.toString(User.preferences.hourFormat),
+					endHour: endEvent(startEvent).toString(User.preferences.hourFormat),
+					timezone: User.preferences.defaultCalendar ? Calendar.calendarOf[User.preferences.defaultCalendar].timezone : User.preferences.timezone,
 					summary : $("#subject_"+ID).text(),
 					description : $("#body_" + ID).text(),
 					startTime: startEvent.getTime(),
-					endTime: endEvent(startEvent)
-			}, 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
-				});
-				$('.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') {						
-						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");
-			}
+					endTime: endEvent(startEvent),
+					timezones: Timezone.timezones,
+					me: {name: User.me.name, mail: User.me.mail, acl: 'rowi', status: '1', delegatedFrom: '0', id: User.me.id},
+					organizer: {name: User.me.name, mail: User.me.mail, acl: 'rowi', status: '1', delegatedFrom: '0' , id: User.me.id},
+					statusParticipants: {accepted: 0, cancelled: 0, tentative: 0, unanswered:emails.length},
+					location: '',
+					attendee: $.map(emails, function( mail ){			
+						
+						var decoded =  Encoder.htmlDecode(mail);
+						var newAttendeeName = "";
+
+						var user = DataLayer.get('user', ["=", "mail", decoded.match(/<([^<]*)>[\s]*$/) ? decoded.match(/<([^<]*)>[\s]*$/)[1].toLowerCase() : decoded], true);
+						
+						if( $.type(user) == "array")
+								user = user[0];
+
+						if(!user)
+							user = {name : decoded.match(/"([^"]*)"/)[1] , mail : decoded.match(/[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])/)[1]};
+
+						if(User.me.mail == user.mail)
+							return(null);
+							
+						user.isExternal = (!!user && !(!!user.isExternal)) ? 0 : 1;
+
+						return  DataLayer.merge({
+							name: user.name,
+							mail: user.mail,
+							acl:  'r',
+							delegatedFrom: '0',
+							status: '4'
+						}, !!user.id ? {id : DataLayer.put('participant', {user: user.id, isExternal: user.isExternal}) } : {id: DataLayer.put('participant', {user: user})}); 
+				
+					})	
 					
-			$.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;
-						}
-					}
-				}
-					
-				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', [{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>'
-							}
-						},
-						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;
-				}
-			});						
+			}, true, path, true);
 		}
 		subject.appendChild(new_event_logo);
