Index: trunk/prototype/modules/calendar/js/calendar.codecs.js
===================================================================
--- trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 5938)
+++ trunk/prototype/modules/calendar/js/calendar.codecs.js	(revision 5947)
@@ -468,4 +468,6 @@
 
 		var pref = User.preferences;
+		
+		var Owner = decodeOwnerCalendar(evtObj.calendar);	
 
 		var res = $.map(evtObj, function( form ){
@@ -476,31 +478,31 @@
 				participants : $.map(form.attendee, function( attendee, i ){
 					if(isNaN(attendee)){
-						return{
-							id: attendee,
-							acl: form.attendeeAcl[i],
-							delegatedFrom: !!form.delegatedFrom[i] ? form.delegatedFrom[i] : 0,
-							isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ),
-							isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0,
-							acl: form.attendeeAcl[i].replace('o', '')
-						};
+					    return{
+						    id: attendee,
+						    acl: form.attendeeAcl[i],
+						    delegatedFrom: !!form.delegatedFrom[i] ? form.delegatedFrom[i] : 0,
+						    isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ),
+						    isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0,
+						    acl: form.attendeeAcl[i].replace('o', '')
+					    };
 					}else{
-						if(DataLayer.get('participant', attendee).user == User.me.id){
+						if(DataLayer.get('participant', attendee).user == Owner.id){
 							var me = {
-								user: User.me.id,
-								status: form.status,
-								id: attendee,
-								isOrganizer: 0,
-								receiveNotification : (!!form.receiveNotification ? 1 : 0),
-								alarms: typeof(form.alarmTime) != 'undefined' ? 
-									$.map( form.alarmTime || [], function( alarmTime, i ){
-
-										if( alarmTime === "" )
-											return( null );
-
-										return !!form.alarmId[i] ?
-											{ type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] } : 
-											{ type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] };
-									}) : []
-							};
+							    user: User.id,
+							    status: form.status,
+							    id: attendee,
+							    isOrganizer: 0,
+							    receiveNotification : (!!form.receiveNotification ? 1 : 0),
+							    alarms: typeof(form.alarmTime) != 'undefined' ? 
+								$.map( form.alarmTime || [], function( alarmTime, i ){
+
+								    if( alarmTime === "" )
+									    return( null );
+
+								    return !!form.alarmId[i] ?
+									    { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] } : 
+									    { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] };
+								    }) : []
+						    };
 							
 							if(form.startDate){
@@ -509,10 +511,10 @@
 								
 								DataLayer.put('notification', {
-									participant: me.id,
-									type: 'suggestion',
-									startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'),
-									endTime:  Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'),
-									allDay: ( !!form.allDay ? 1 : 0 ),
-									schedulable: form.idEvent
+								    participant: me.id,
+								    type: 'suggestion',
+								    startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'),
+								    endTime:  Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'),
+								    allDay: ( !!form.allDay ? 1 : 0 ),
+								    schedulable: form.idEvent
 								});
 							
@@ -547,15 +549,17 @@
 			if(!(typeof(objEvent) == 'object'))
 				return (null);
-			
-			var participantInfo = {}, delegatedFrom = {}, me = DataLayer.copy(User.me);
+
+			var Owner = decodeOwnerCalendar(objEvent.calendar);
+
+			var participantInfo = {}, delegatedFrom = {}, me = DataLayer.copy( Owner );
 			
 			var constantAcl = function(acl){
-				var returns = {};
-				for (var i in constantsParticipant){
-					returns[constantsParticipant[i]] = acl.indexOf(i) >= 0 ? true : false
-				}
-				return returns;
+			var returns = {};
+			for (var i in constantsParticipant){
+				returns[constantsParticipant[i]] = acl.indexOf(i) >= 0 ? true : false
+			}
+			return returns;
 			};
-								
+
 		    return {
 			    "class": objEvent["class"],
@@ -575,5 +579,5 @@
 			    endHour: dateCalendar.formatDate(Timezone.getDateEvent(new Date(parseInt(objEvent.endTime)),  objEvent.timezone, objEvent.calendar, objEvent.DayLigth, 'endTime'), User.preferences.hourFormat),
 			    allDay: !!parseInt( objEvent.allDay ),
-				attachments: $.map(objEvent.attachments || [], function( attachment, i ){
+			    attachments: $.map(objEvent.attachments || [], function( attachment, i ){
 					var attach = DataLayer.get('schedulableToAttachment', attachment, false);
                                         var ext = attach.name.split('.');
@@ -583,51 +587,51 @@
 				}),						
 			    attendee: $.map(objEvent.participants || [], function( participant, i ){						
-					
-					if(delegateAttendee[participant])
-						return(null);
-					
-					var attend = DataLayer.get('participant', (participant.id || participant));
-					attend.user = DataLayer.get('user', attend.user);
-					
-					statusParticipants[ statusLabels[attend.status] ]++;  	
-					
-					if( attend.user.id ===  me.id ){
-					    participantInfo.user = {
-							id: attend.id,
-							status : attend.status,
-							delegatedFrom: attend.delegatedFrom || '0',
-							acl: attend.acl,
-							receiveNotification : attend.receiveNotification,
-							alarms : $.map(attend.alarms || [], function( alarm ){
-								var alarm = DataLayer.get('alarm', alarm);
-                                                                return (alarm == "" ? (null) : alarm);
-							})
-						};
-						me.id = attend.id;
-						return(null);
-					};
-					
-					var person = {
-						id: attend.id,
-						name: attend.user.name != 'false' ? attend.user.name : '',
-						mail: attend.user.mail,
-						status : attend.status,
-						isExternal: attend.isExternal,
-						acl: attend.acl,
-						delegatedFrom: attend.delegatedFrom
-					};
-					
-					if(!!parseInt(attend.delegatedFrom)){
-						delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person);
-						return(null);
-					}
-					
-					if( !!parseInt(attend.isOrganizer )){
-					    participantInfo.organizer = DataLayer.copy(person);
-						return(null);
-					};					
-					
-					return (person);
-				}),
+
+				if(delegateAttendee[participant])
+					return(null);
+
+				var attend = DataLayer.get('participant', (participant.id || participant));
+				attend.user = DataLayer.get('user', attend.user);
+
+				statusParticipants[ statusLabels[attend.status] ]++;  	
+
+				if( attend.user.id ===  me.id ){
+				    participantInfo.user = {
+					id: attend.id,
+					status : attend.status,
+					delegatedFrom: attend.delegatedFrom || '0',
+					acl: attend.acl,
+					receiveNotification : attend.receiveNotification,
+					alarms : $.map(attend.alarms || [], function( alarm ){
+					    var alarm = DataLayer.get('alarm', alarm);
+					    return (alarm == "" ? (null) : alarm);
+					})
+				    };
+				    me.id = attend.id;
+				    return(null);
+				};
+
+				var person = {
+				    id: attend.id,
+				    name: attend.user.name != 'false' ? attend.user.name : '',
+				    mail: attend.user.mail,
+				    status : attend.status,
+				    isExternal: attend.isExternal,
+				    acl: attend.acl,
+				    delegatedFrom: attend.delegatedFrom
+				};
+
+				if(!!parseInt(attend.delegatedFrom)){
+				    delegatedFrom[attend.delegatedFrom] = DataLayer.copy(person);
+					return(null);
+				}
+
+				if( !!parseInt(attend.isOrganizer )){
+				    participantInfo.organizer = DataLayer.copy(person);
+					return(null);
+				};					
+
+				return (person);
+			    }),
 			    organizer: participantInfo.organizer || me,
 			    alarms: !!participantInfo.user ? participantInfo.user.alarms : [],
@@ -640,8 +644,23 @@
 				statusParticipants: statusParticipants
 			};
-		});	
-	return notArray ? res[0] : res;
+		});
+	return (notArray ? res[0] : res);
     }
 });
+
+
+function decodeOwnerCalendar(calendar){
+    if(calendar && !parseInt(Calendar.signatureOf[calendar].isOwner)){
+	var Owner = DataLayer.get('calendarSignature', {filter: ['AND', ['=','calendar', calendar], ['=','isOwner','1']], criteria: {deepness: 2}});
+
+	if($.isArray(Owner))
+	    Owner = Owner[0];
+	
+	return Owner.user;
+    }
+    return User.me;
+
+    
+}
 
 function decodeRepeat ( form ) {
@@ -744,55 +763,56 @@
 		    var tzId =  form.timezone || Calendar.signatureOf[form.calendar].calendar.timezone || User.preferences.timezone,
 
-		    formatString = ( typeof form.allDay !== "undefined" && !!form.allDay )? pref.dateFormat+" HH:mm" : pref.dateFormat + " " + pref.hourFormat,
-			
-		    participants = []; 
+		    formatString = ( typeof form.allDay !== "undefined" && !!form.allDay )? pref.dateFormat+" HH:mm" : pref.dateFormat + " " + pref.hourForma;
+
+		    var Owner = decodeOwnerCalendar(form.calendar);
+
 		    return {
-			      "class": form["class"],
-				  startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'),
-				  endTime:  Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'),  //+ (!!form.allDay ? 86400000 : 0) ,
-				  allDay: ( !!form.allDay ? 1 : 0 ),       
-			      id: form.idEvent,
-			      location: form.location,
-			      category: form.category,
-			      calendar: form.calendar,
-			      summary: form.summary,
-			      description: form.description,
-			      timezone: tzId,
-				  attachments: $.map(form.attachment || [], function( attachment, i ){
-						return {attachment: attachment}
-				  }),
-			      repeat: this.decodeRepeat( form ),
-			      participants: $.map( form.attendee || [], function( attendee, i ){
-
-						if( !attendee || attendee === "" )
-							return( null );
-
-						var participant = {};
-						participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ;
-						
-						if( participant.user === User.me.id ){
-							return DataLayer.merge({
-								id: attendee,
-								isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ),
-								acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', ''),
-								alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){
-										if( alarmTime === "" )
-											return( null );
-										 return !!form.alarmId[i] ? { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] }:
-																	{ type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] };
-									}),
-								status: !!form.status ? form.status : 3
-								}, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {});							
-						}else{
-							return DataLayer.merge({
-								id: attendee,
-								acl: form.attendeeAcl[i],
-								isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ),
-								isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0,
-								acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', '')
-							}, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {});	
-						};
-					  })
-			    };
+			    "class": form["class"],
+			    startTime: Date.parseExact(form.startDate + (!!form.allDay ? " 00:00": " "+$.trim(form.startHour)) , formatString ).toString('yyyy-MM-dd HH:mm:00'),
+			    endTime:  Date.parseExact(form.endDate + ( !!form.allDay ? " 00:00": " "+$.trim(form.endHour)), formatString ).toString('yyyy-MM-dd HH:mm:00'),  //+ (!!form.allDay ? 86400000 : 0) ,
+			    allDay: ( !!form.allDay ? 1 : 0 ),       
+			    id: form.idEvent,
+			    location: form.location,
+			    category: form.category,
+			    calendar: form.calendar,
+			    summary: form.summary,
+			    description: form.description,
+			    timezone: tzId,
+			    attachments: $.map(form.attachment || [], function( attachment, i ){
+					return {attachment: attachment}
+			    }),
+			    repeat: this.decodeRepeat( form ),
+			    participants: $.map( form.attendee || [], function( attendee, i ){
+
+				if( !attendee || attendee === "" )
+				    return( null );
+
+				var participant = {};
+				participant.user = (attendee!= User.me.id) ? DataLayer.get('participant', attendee).user : attendee ;
+
+				if( participant.user === Owner.id ){
+				    return DataLayer.merge({
+				    id: attendee,
+				    isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ),
+				    acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', ''),
+				    alarms: participant.alarms = $.map( form.alarmTime || [], function( alarmTime, i ){
+					if( alarmTime === "" )
+					    return( null );
+					return !!form.alarmId[i] ? { type: form.alarmType[i], unit: form.alarmUnit[i], time: form.alarmTime[i], id: form.alarmId[i] }:
+					    { type: form.alarmType[i],unit: form.alarmUnit[i], time: form.alarmTime[i] };
+					}),
+				    status: !!form.status ? form.status : 3
+				    }, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {});
+				}else{
+				    return DataLayer.merge({
+					id: attendee,
+					acl: form.attendeeAcl[i],
+					isOrganizer: (form.attendee_organizer == attendee ? 1 : 0 ),
+					isExternal: !!parseInt(form.attendeeType[i]) ? 1 : 0,
+					acl: form.attendee_organizer == attendee ? (form.attendeeAcl[i].indexOf('o') < 0 ? form.attendeeAcl[i]+'o' : form.attendeeAcl[i]) : form.attendeeAcl[i].replace('o', '')
+				    }, form.delegatedFrom[i] != '0' ? {delegatedFrom: form.delegatedFrom[i]} : {});
+				};
+			    })
+			};
 		    });
 
@@ -923,5 +943,5 @@
 
     encoder: function( evtObj, filter ){
-	
+      
 	if( !evtObj )
 	    return( false );
@@ -993,5 +1013,6 @@
                     allDay: parseInt( evt.allDay ),
                     isRepeat: isRepeat,
-                    occurrence: i }, eventEditable(evt.id, isRepeat, i ) ) );
+                    occurrence: i,
+		    calendar: evt.calendar}, eventEditable(evt.id, isRepeat, i ) ) );
 	});
 
Index: trunk/prototype/modules/calendar/js/helpers.js
===================================================================
--- trunk/prototype/modules/calendar/js/helpers.js	(revision 5937)
+++ trunk/prototype/modules/calendar/js/helpers.js	(revision 5947)
@@ -76,9 +76,9 @@
 
 	if(!isMail)
-	objEvent = DataLayer.encode( "schedulable:preview", objEvent );
+	    objEvent = DataLayer.encode( "schedulable:preview", objEvent );
 	
 	if(typeof(objEvent.id) == 'undefined'){
-			objEvent.alarms = Calendar.signatureOf[User.preferences.defaultCalendar || Calendar.calendarIds[0]].defaultAlarms || false;
-			objEvent.useAlarmDefault = 1;
+	    objEvent.alarms = Calendar.signatureOf[User.preferences.defaultCalendar || Calendar.calendarIds[0]].defaultAlarms || false;
+	    objEvent.useAlarmDefault = 1;
 	}
 	
@@ -564,4 +564,30 @@
 				}
 			}
+
+			var participant =  UI.dialogs.addEvent.find('dd.me input[name="attendee[]"]').val();
+			if( !parseInt(Calendar.signatureOf[$(this).val()].isOwner) ){
+			    var signature = Calendar.signatureOf[$(this).val()];
+			    var organizer = DataLayer.get('calendarSignature', {filter: ['AND', ['=','calendar',signature.calendar.id], ['=','isOwner','1']], criteria: {deepness: 2}});
+			    
+			    if($.isArray(organizer))
+				organizer = organizer[0];
+			    DataLayer.put('participant', {id: participant, user: organizer.user.id, mail: organizer.user.mail});
+			    
+			    UI.dialogs.addEvent.find('dt.me').html(organizer.user.name);
+			    UI.dialogs.addEvent.find('li.organizer input[name="attendee_organizer"]').val(participant);
+			    UI.dialogs.addEvent.find('li.organizer label').filter('.name').html(organizer.user.name).end()
+			    .filter('.mail').html(organizer.user.mail).attr('title',organizer.user.mail);
+
+			}else{
+			    UI.dialogs.addEvent.find('dt.me').html(User.me.name);
+			    DataLayer.put('participant', {id: participant, user: User.me.id, mail: User.me.mail});
+			    UI.dialogs.addEvent.find('li.organizer input[name="attendee_organizer"]').val(participant);
+			    UI.dialogs.addEvent.find('li.organizer label').filter('.name').html(User.me.name).end()
+			    .filter('.mail').html(User.me.mail).attr('title',User.me.mail);
+			}
+			
+			
+			
+			
 	    });
 		
Index: trunk/prototype/modules/calendar/js/init.js
===================================================================
--- trunk/prototype/modules/calendar/js/init.js	(revision 5943)
+++ trunk/prototype/modules/calendar/js/init.js	(revision 5947)
@@ -320,6 +320,10 @@
                                 });
                                 
-                            }else
-                                eventDetails( DataLayer.get( "schedulable", evt.id), true);
+                            }else{
+				var schedulable = DataLayer.get( "schedulable", evt.id);
+				schedulable.calendar = evt.calendar;
+				eventDetails( schedulable, true);
+				
+			    }
                                 
                         }
