Index: trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 5343)
+++ trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 5358)
@@ -437,4 +437,6 @@
 	};	
 
+	var isOrganizer = !!evtObj[0].id ? 0 : 1;
+	
 	var res = $.map(evtObj, function( objEvent ){			
 		    
@@ -460,7 +462,13 @@
 			}	
 			var temp = [];
-			
+			var tempAlarm = [];
+					
 			var typeAlarm = function(obj){
+				var alarm = [];
 				for(var i = 0; i < obj.length; i++){
+					if(tempAlarm[obj[i].id]) 
+						continue; 
+					tempAlarm[obj[i].id] = true;
+					
 					if(obj[i].type == "1"){
 						obj[i].type = 'alert';
@@ -470,6 +478,7 @@
 						obj[i].type = 'sms';
 					}
+					alarm.push(obj[i]);
 				}
-				return obj;
+				return alarm;
 			}
 		    return {
@@ -490,37 +499,32 @@
 			      allDay: !!parseInt( objEvent.allDay ),
 	  // 				attachments: this.decode( "attachment:detail", form ),
-			      attendee: $.map(objEvent.participants || [], function( participant ){
-				if(participant.indexOf('java') >= 0)
-					return (null);
-				if(temp[participant])
-					return (null);
-				temp[participant] = true;	
+			      attendee: $.map(objEvent.participants || [], function( participant, i ){
+						if(participant.indexOf('java') >= 0) 
+							return (null); 
+						if(temp[participant]) 
+							return (null); 
+						temp[participant] = true;
+						
+					var attend = DataLayer.get('participant', participant);
+					attend.user = DataLayer.get('user', attend.user)
 					
-						participant = DataLayer.get( "participant", participant);
-					
-					statusParticipants[participant.status]++; 
-					var user = DataLayer.get( "user", participant.user.id || participant.user );
-					var getIdUser = function(user){
-						if(user.owner)
-							return 'external:'+user.id;
-						else if(user.id == User.me.id)
-							return user.id;
-						else return 'internal:'+user.id;
-					}; 	
+					statusParticipants[attend.status]++;  	
 					 
-					  var person = { uid: getIdUser(user),
-						         name: user.name,
-								 mail: user.mail
-								};
-
-					  if( person.uid ===  me.uid )
+					  var person = { uid: attend.id,
+						 name: attend.user.name,
+						 mail: attend.user.mail,
+						 isExternal: attend.isExternal
+						};
+
+					  if( attend.user.id ===  me.uid )
 					  {
-					      participantInfo.status = participant.status;
+					      participantInfo.status = attend.status;
 					      participantInfo.alarms = typeAlarm(objEvent.alarms);
 					  }
-					  if( parseInt( participant.isOrganizer ) )
+					  if( parseInt( attend.isOrganizer ) )
 					  {
+						 isOrganizer = ((attend.user.id == User.me.id) || (!!!attend.user)) ? 1 : 0;
 					      participantInfo.organizer = person;
-					      return( null );
+						  return(null);
 					  }
 
@@ -534,5 +538,5 @@
 			    };
 		});
-	res[0].isOrganizer = res[0].organizer.uid == User.me.id ? 1 : 0;
+	res[0].isOrganizer = isOrganizer;
 	res[0].statusParticipants = statusObject(statusParticipants);
 	if( !notArray )
@@ -594,6 +598,6 @@
 		    participants = []; 
 
-		    if( form.idEvent )
-			participants = DataLayer.get( "participant:detail", [ "=", "schedulable", form.idEvent ] );
+		    //if( form.idEvent )
+			//	participants = DataLayer.get( "participant:detail", [ "=", "schedulable", form.idEvent ] );
 			
 			var spaces = function(hours){
@@ -620,37 +624,14 @@
 			      participants: $.map( form.attendee || [], function( attendee, i ){
 
-					if( !attendee || attendee === "" )
-					return( null );
+						if( !attendee || attendee === "" )
+							return( null );
 
 						var participant = {};
-						var isCurrentParticipant = function(user, event){
-							var participant =  DataLayer.get('participant', ['AND',['=', 'user', user],['=', 'schedulable', event]]);
-							if(participant != '')
-								return participant[0].id;
-							else
-								return false;
-						};  
+						participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ;
 						
-						if((attendee.indexOf('internal') >= 0) || (attendee.indexOf('external') >= 0)){
-							participant.user = attendee.replace(/[a-z:]/g, ""),
+						if( participant.user === User.me.id ){
+							if(!!form.idEvent )
+								participant.id = attendee;
 							participant.isOrganizer = ( !i ? 1 : 0 );
-							if(attendee.indexOf('external') >= 0)
-								participant.isExternal = 1;
-							var id = '';
-							if(participant.user == User.me.id)
-								participant.status = form.status;
-							if((form.idEvent) && (id = isCurrentParticipant(participant.user, form.idEvent)))
-								participant.id = id;
-								return participant;
-						}else if(attendee.indexOf('java') >= 0){		  
-							participant.user = attendee;
-							participant.isOrganizer = ( !i ? 1 : 0 );
-							participant.isExternal= 1;
-						}else{ 	
-							participant.user = attendee;
-							participant.isOrganizer = ( !i ? 1 : 0 );
-						}
-					      
-						if( attendee === User.me.id ){
 							var obj = form.alarmTime ? form : pref;
 							participant.alarms = $.map( obj.alarmTime || [], function( alarmTime, i ){
@@ -659,5 +640,4 @@
 									return( null );
 
-								
 								if(obj.alarmId[i] === "")
 									return { type: obj.alarmType[i],unit: obj.alarmUnit[i], time: obj.alarmTime[i] };
@@ -665,12 +645,15 @@
 									return { type: obj.alarmType[i], unit: obj.alarmUnit[i], time: obj.alarmTime[i], id: obj.alarmId[i] };
 							});
-							
-							if( participants[ attendee ] ){
-								participant.id = participants[ attendee ].id;
-							}
 							participant.status = form.status;
-					    }
-
-					      return( participant );
+						}else{
+							participant.id = attendee;
+							participant.isOrganizer = ( !i ? 1 : 0 );
+							if(!!parseInt(form.attendeeType[i]))
+								participant.isExternal= 1;
+						}
+						if( participants[ attendee ] ){
+							participant.id = participants[ attendee ].id;
+						}
+						return( participant );
 					  })
 			    };
@@ -742,5 +725,5 @@
 					  {
 					      participantInfo.organizer = person;
-					      return( null );
+						  return(null);
 					  }
 
Index: trunk/prototype/modules/calendar/js/helpers.js
===================================================================
--- trunk/prototype/modules/calendar/js/helpers.js	(revision 5354)
+++ trunk/prototype/modules/calendar/js/helpers.js	(revision 5358)
@@ -432,7 +432,5 @@
 			
 			blkAddAtendee.find('li.attendee .button').addClass('small').button({text:false, icons: {primary:'ui-icon-close'}}).click(function () {
-				var participant =  DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable', $(this).parents().find('.id-event').first().val()]]);
-				if(participant)
-					DataLayer.remove('participant', participant[0].id);
+				DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val());
 				$(this).parent().remove();
 			});
@@ -600,20 +598,14 @@
 						lastEditAttendeeToolTip.qtip('destroy');
 
+					var userId = '';
 					var newAttendeeId = '';
 
 					if (user){
-						if(user[0].isExternal)
-							newAttendeeId = 'external:'+user[0].id;
-						else
-							newAttendeeId = 'internal:'+user[0].id;
-
 						if (!skipAddNewLine) {
 							blkAddAtendee.find('dd.attendee-list ul.attendee-list').append(
-								DataLayer.render('templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: user[0].name, mail: user[0].mail}])
+								DataLayer.render('templates/participants_add_itemlist.ejs', {user: user[0]})
 							)
 							.find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() {
-								var participant =  DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable',$(this).parents().find('.id-event').first().val()]]);
-								if(participant)
-									DataLayer.remove('participant', participant[0].id);
+								DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val());
 								$(this).parent().remove();
 							}).end()
@@ -629,13 +621,12 @@
 						 */
 
-						newAttendeeId = DataLayer.put('user', {name: newAttendeeName, mail: newAttendeeEmail, isExternal: isExternal});
+						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('templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail}])
+							DataLayer.render('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() {
-							var participant =  DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable', $(this).parents().find('.id-event').first().val()]]);
-							if(participant)
-								DataLayer.remove('participant', participant[0].id);
+							DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val());
 							$(this).parent().remove();
 						}).end()
@@ -671,4 +662,11 @@
 						lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip;
 
+
+
+
+
+
+
+
 						$(this).val('');
 
@@ -704,6 +702,7 @@
 						if ($(event.target).is('input')) {
 							old_item = $(event.target).parents('li');
+							newAttendeeId = DataLayer.put('participant', {user: old_item.find('.id').html(), isExternal: 0});
 							blkAddAtendee.find('dd.attendee-list ul.attendee-list')
-							.append(DataLayer.render('templates/participants_add_itemlist.ejs', [{id: 'internal:'+old_item.find('.id').text(), name: old_item.find('.name').html()}]))
+							.append(DataLayer.render('templates/participants_add_itemlist.ejs', [{id: newAttendeeId, name: old_item.find('.name').html(), isExternal: 0}]))
 							.find('.button').addClass('small').button({text:false, icons: {primary:'ui-icon-close'}}).click(function () {
 								$(this).parent().remove();
Index: trunk/prototype/modules/calendar/index.php
===================================================================
--- trunk/prototype/modules/calendar/index.php	(revision 5349)
+++ trunk/prototype/modules/calendar/index.php	(revision 5358)
@@ -349,5 +349,5 @@
 
 		eventClick: function( evt, event, view ){
-			eventDetails( DataLayer.get( "schedulable", evt.id ), true );
+			eventDetails( DataLayer.get( "schedulable", evt.id), true);
 		}
 	});
Index: trunk/prototype/modules/calendar/templates/participants_search_itemlist.ejs
===================================================================
--- trunk/prototype/modules/calendar/templates/participants_search_itemlist.ejs	(revision 5341)
+++ trunk/prototype/modules/calendar/templates/participants_search_itemlist.ejs	(revision 5358)
@@ -2,5 +2,5 @@
 <li class="ui-widget-content" style="width:6000px;" title="<%=data[i]['name']%>">
 	<input type="checkbox" name="opcao">
-	<input type="hidden" value="internal:<%=data[i]['id']%>">
+	<input type="hidden" value="<%=data[i]['id']%>">
 	<label class="name"><%=data[i]['name']%></label>
 	<label class="email hidden"><%=data[i]['mail']%></label>
Index: trunk/prototype/modules/calendar/templates/attendee_add.ejs
===================================================================
--- trunk/prototype/modules/calendar/templates/attendee_add.ejs	(revision 5353)
+++ trunk/prototype/modules/calendar/templates/attendee_add.ejs	(revision 5358)
@@ -21,4 +21,5 @@
 						<input type="checkbox" value="<%= data.event.organizer.uid %>" disabled="disabled">
 						<input type="hidden" name="attendee[]" value="<%=data.event.organizer.uid%>">
+						<input type="hidden" name="attendeeType[]" value="0">
 						<input type="hidden" name="attendee_organizer[]" value="<%=data.event.organizer.uid%>">
 						<label for="attendee_organizer" title="<%= data.event.organizer.name ? data.event.organizer.name: '' %>" class="name"><%= data.event.organizer.name ? data.event.organizer.name : '' %></label>
@@ -37,4 +38,5 @@
 						<input type="checkbox" value="<%= data.event.attendee[i].uid %>" disabled="disabled">
 						<input type="hidden" name="attendee[]" value="<%=data.event.attendee[i].uid%>">
+						<input type="hidden" name="attendeeType[]" value="<%=data.event.attendee[i].isExternal%>">
 						<label title="<%= data.event.attendee[i].name ? data.event.attendee[i].name: '' %>" class="name"><%= data.event.attendee[i].name ? data.event.attendee[i].name : '' %></label>
 						<label title="<%= data.event.attendee[i].mail ? data.event.attendee[i].mail : '' %>" class="mail"><%= data.event.attendee[i].mail ? data.event.attendee[i].mail : '' %></label>
@@ -81,5 +83,5 @@
 		
 	</dl>
-<% if (data.event.me.uid == data.event.organizer.uid) { %>
+<% if (data.event.isOrganizer == 1) { %>
 	<dl class="block-add-attendee">
 		<dt class="add-attendee">Adicionar convidados</dt>
Index: trunk/prototype/modules/calendar/templates/participants_add_itemlist.ejs
===================================================================
--- trunk/prototype/modules/calendar/templates/participants_add_itemlist.ejs	(revision 5341)
+++ trunk/prototype/modules/calendar/templates/participants_add_itemlist.ejs	(revision 5358)
@@ -3,4 +3,5 @@
 		<input type="checkbox" value="<%= data[0].id %>" disabled="disabled">
 		<input type="hidden" name="attendee[]" value="<%= data[0].id %>">
+		<input type="hidden" name="attendeeType[]" value="<%=data[0].isExternal%>">
 		<label title="<%= data[0].name ? data[0].name : '' %>" class="name"><%= data[0].name ? data[0].name : '' %></label>
 		<label title="<%= data[0].mail ? data[0].mail : '' %>" class="mail"><%= data[0].mail ? data[0].mail : '' %></label>
