Index: /trunk/prototype/services/iCal.php
===================================================================
--- /trunk/prototype/services/iCal.php	(revision 5916)
+++ /trunk/prototype/services/iCal.php	(revision 5947)
@@ -512,19 +512,19 @@
                                  if($schedulable ) //Caso o evento exista
                                  {
-								 $isOrganizer = false;
-								 $isParticipant = false;
-								 
-								  foreach($schedulable['participants'] as $value)
-									if($value['user']['id'] == Config::me('uidNumber')){
-										$isParticipant = true;
-										if($value['isOrganizer'])
-											$isOrganizer = true;
-
-										if(!self::_existInMyCalendars($schedulable['id'])){
-											$interation = ICAL_ACTION_UPDATE; 
-											$interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : ICAL_ACTION_IMPORT;
-											break;
-										}                                   
-									}else
+				    $isOrganizer = false;
+				    $isParticipant = false;
+
+				    foreach($schedulable['participants'] as $value)
+					if($value['user']['id'] == Config::me('uidNumber')){
+						$isParticipant = true;
+						if($value['isOrganizer'])
+							$isOrganizer = true;
+
+						if(!self::_existInMyCalendars($schedulable['id'])){
+							$interation = ICAL_ACTION_UPDATE; 
+							$interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : ICAL_ACTION_IMPORT;
+							break;
+						}                                   
+					}else
                                     {
                                         if( self::_getTime($component , 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty( 'sequence' , false , false ) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento
@@ -989,5 +989,5 @@
         static private function _existInMyCalendars( $id )
         {
-           $sig = Controller::find(array('concept' => 'calendarSignature'), array('user','calendar'), array('filter' => array( '=' , 'user' , Config::me('uidNumber'))));       
+           $sig = Controller::find(array('concept' => 'calendarSignature'), array('user','calendar', 'isOwner'), array('filter' => array('AND', array( '=' , 'user' , Config::me('uidNumber') ) , array('=' , 'isOwner' , '1' ))));       
            $calendars = array();
            foreach ($sig as $val)
Index: /trunk/prototype/modules/calendar/interceptors/Notifications.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/Notifications.php	(revision 5804)
+++ /trunk/prototype/modules/calendar/interceptors/Notifications.php	(revision 5947)
@@ -9,12 +9,12 @@
     
 	public function formatNotification(&$uri , &$params , &$data , $original){	
-		switch ($params['type']) {
-			case 'suggestion':
-				self::formatSuggestion($params);    
-				break;
-			case 'suggestionResponse':
-				self::formatSuggestionResponse($params);    
-				break;
-			} 
+	    switch ($params['type']) {
+		case 'suggestion':
+			self::formatSuggestion($params);    
+			break;
+		case 'suggestionResponse':
+			self::formatSuggestionResponse($params);    
+			break;
+		} 
 	}
 	
@@ -78,8 +78,8 @@
                $organizer = isset( $organizers[$pCreated['schedulable']] ) ? $organizers[ $pCreated['schedulable'] ] : self::getOrganizer( $pCreated['schedulable'] );
 			   
-				if($pCreated['delegatedFrom'] != 0){
-					self::participantDelegated( $pCreated , $schedulable , $organizer);    
-					continue;
-				}
+		if($pCreated['delegatedFrom'] != 0){
+			self::participantDelegated( $pCreated , $schedulable , $organizer);    
+			continue;
+		}
 			   
                switch ($pCreated['status']) 
@@ -89,5 +89,5 @@
                        break;
                    case STATUS_UNANSWERED:
-                        self::participantCreated( $pCreated['id'] , $schedulable );
+                        self::participantCreated( $pCreated['id'] , $schedulable, false, false, $organizer );
                        break;
                } 
@@ -108,7 +108,7 @@
                     
                 if($pUpdated['delegatedFrom'] != 0){
-					self::participantDelegatedStatusChange( $pUpdated , $schedulable , $organizer , $pUpdated['status'] );    
+		    self::participantDelegatedStatusChange( $pUpdated , $schedulable , $organizer , $pUpdated['status'] );    
                 }else if( $pUpdated['status'] != STATUS_UNANSWERED && $pUpdated['status'] != STATUS_DELEGATED)
-					self::participantStatusChange( $pUpdated['id'] , $schedulable , $organizer , $pUpdated['status'] );    
+		    self::participantStatusChange( $pUpdated['id'] , $schedulable , $organizer , $pUpdated['status'] );    
             }
         }
@@ -117,7 +117,7 @@
 	public function formatSuggestion(&$params){
 	    
-		$schedulable =  Controller::read(  array( 'concept' => 'schedulable' , 'id' => $params['schedulable'] ) , null , array('deepness' => '2') ) ;
-		
-		foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador      
+	    $schedulable =  Controller::read(  array( 'concept' => 'schedulable' , 'id' => $params['schedulable'] ) , null , array('deepness' => '2') ) ;
+
+	    foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador      
             if(($v['isOrganizer'] === '1') && ($organizer = $v) ) break;
 		
@@ -227,5 +227,5 @@
 	}
 	
-	/**
+    /**
     * Monta o email de resposta que sera enviado ao delegatedFrom
     *
@@ -239,10 +239,10 @@
     public static function participantDelegatedStatusChange( &$partID , &$schedulable, $organizer, &$type = false){
 	
-		$delegatedParams = array();
-					
-		$delegated = self::_getAttendeeById($partID['id'], $schedulable);
-		$delegatedParams['delegated'] = $delegated['user']['uid'];		
-		
-		switch($partID['status']){
+	    $delegatedParams = array();
+
+	    $delegated = self::_getAttendeeById($partID['id'], $schedulable);
+	    $delegatedParams['delegated'] = $delegated['user']['uid'];		
+
+	    switch($partID['status']){
             case STATUS_ACCEPTED:
                 $delegatedParams['status'] = 'aceitou';
@@ -254,17 +254,17 @@
                 $delegatedParams['status'] = 'rejeitou';
             break;
-			case STATUS_DELEGATED:
-				$delegatedParams['status'] = 'delegou para um novo participante';
+	    case STATUS_DELEGATED:
+		    $delegatedParams['status'] = 'delegou para um novo participante';
             break;
 		}
-			//notifica o organizador a resposta do delegado
-			self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , $type, $delegatedParams );
-	
-			$method = 'REQUEST';
-			$notificationType = 'Resposta Delegação'; 
-			$part = 'attendees';
-			self::mountStruture($partID['delegatedFrom'], $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType );
-			
-			$data = array_merge($data, $delegatedParams);
+	    //notifica o organizador a resposta do delegado
+	    self::participantStatusChange( $partID['delegatedFrom'] , $schedulable , $organizer , $type, $delegatedParams );
+
+	    $method = 'REQUEST';
+	    $notificationType = 'Resposta Delegação'; 
+	    $part = 'attendees';
+	    self::mountStruture($partID['delegatedFrom'], $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType );
+
+	    $data = array_merge($data, $delegatedParams);
 			
             self::sendMail($data, $ical , $part['user']['mail'] , $subject , 'notify_response_delegated_status_body');
@@ -305,4 +305,5 @@
 			$temp = $part;
 			$part = false;
+
 			switch($temp){
 				case 'attendees':
@@ -352,15 +353,15 @@
     * @access     public
     */
-    public static function participantCreated( &$partID , &$schedulable, $type = false, $delegatedParams = false)
+    public static function participantCreated( &$partID , &$schedulable, $type = false, $delegatedParams = false, $organizer = false)
     {	
-		$method = 'REQUEST';
-		$notificationType = 'Convite de Calendario'; 
-		$part = 'attendees';
-		self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true);
-	
-  		if($delegatedParams)
-			$data = array_merge($data, $delegatedParams);
-					 
-		 self::sendMail($data, $ical , $part['user']['mail'] , $subject , !$delegatedParams  ? 'notify_create_body' : 'notify_create_delegated_body' );
+	$method = 'REQUEST';
+	$notificationType = 'Convite de Calendario'; 
+	$part = 'attendees';
+	self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true);
+
+	if($delegatedParams)
+		$data = array_merge($data, $delegatedParams);
+
+	    self::sendMail($data, $ical , $part['user']['mail'] , $subject , !$delegatedParams  ? 'notify_create_body' : 'notify_create_delegated_body', $organizer );
        
     }
@@ -379,13 +380,13 @@
     {	
         $method = 'REPLY';
-		$notificationType = 'Convite Aceito';
-		$part = 'me';
-		
-		self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true );
-		       
-		if($delegatedParams){
-			$data = array_merge($data, $delegatedParams);
-			$tplDelegated = 'notify_delegated_status_body';
-		}
+	$notificationType = 'Convite Aceito';
+	$part = 'me';
+
+	self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType, true );
+
+	if($delegatedParams){
+		$data = array_merge($data, $delegatedParams);
+		$tplDelegated = 'notify_delegated_status_body';
+	}
 
        switch($type)
@@ -403,7 +404,7 @@
                 $subject['notificationType'] = 'Convite rejeitado';
             break;
-			case STATUS_DELEGATED:
-				if($delegatedParams)
-					$data = array_merge($data, $delegatedParams);
+		case STATUS_DELEGATED:
+		    if($delegatedParams)
+			$data = array_merge($data, $delegatedParams);
                 $tpl =   'notify_delegated_body';
                 $subject['notificationType'] = 'Convite delegado';
@@ -412,5 +413,5 @@
        }
         
-        self::sendMail($data, $ical , $organizer['user']['mail'] , $subject , $tpl);
+        self::sendMail($data, $ical , $organizer['user']['mail'] , $subject , $tpl, false);
     }
     
@@ -425,5 +426,5 @@
     * @access     public
     */
-    private static function sendMail(&$data , &$ical , $to ,  &$subject , $template )
+    private static function sendMail(&$data , &$ical , $to ,  &$subject , $template, $from = false )
     { 
        $ical2 = $ical;
@@ -435,5 +436,5 @@
        $mail['body'] = parseTPL::load_tpl( $data ,ROOTPATH.'/modules/calendar/templates/'.$template.'.tpl');
        $mail['subject'] = parseTPL::load_tpl( $subject ,ROOTPATH.'/modules/calendar/templates/notify_subject.tpl');;
-       $mail['from'] = '"'.Config::me('cn').'" <'.Config::me('mail').'>';
+       $mail['from'] = $from ? ('"'.$from['user']['name'].'" <'.$from['user']['mail'].'>') : ('"'.Config::me('cn').'" <'.Config::me('mail').'>');
        $mail['to'] = $to;
        Controller::create( array( 'service' => 'SMTP' ), $mail ); 
@@ -456,11 +457,11 @@
        if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd'])))
        {
-			$method = 'CANCEL';
-			$notificationType = 'Cancelamento de Calendario';
-			$part = 'othersAttendees';
-			self::mountStruture($uri['id'], $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType );
+	    $method = 'CANCEL';
+	    $notificationType = 'Cancelamento de Calendario';
+	    $part = 'othersAttendees';
+	    self::mountStruture($uri['id'], $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType );
                 
-           if(count($part) > 0)
-            self::sendMail($data, $ical , implode(',' , $part) ,$subject, 'notify_cancel_body');
+	    if(count($part) > 0)
+		self::sendMail($data, $ical , implode(',' , $part) ,$subject, 'notify_cancel_body');
        }
     }
@@ -484,10 +485,10 @@
        if((Config::regGet('noAlarm') === false) && (self::futureEvent( $schedulable['startTime'] , $schedulable['rangeEnd'])))
        {  
-			$method = 'CANCEL';
-			$notificationType = 'Cancelamento de Calendario';
-			$part = 'others';
-			self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType );
-		                            
-			self::sendMail($data, $ical , $participant['user']['mail'] , $subject , 'notify_cancel_body');  
+	    $method = 'CANCEL';
+	    $notificationType = 'Cancelamento de Calendario';
+	    $part = 'others';
+	    self::mountStruture(false, $schedulable, false , $data,  $subject, $ical, $part, $method, $notificationType );
+
+	    self::sendMail($data, $ical , $participant['user']['mail'] , $subject , 'notify_cancel_body');  
         }
     }
@@ -518,8 +519,8 @@
        if ( ($alt === true) && (Config::regGet('noAlarm') === false) && (self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'])) ) 
        {			
-			$method = 'REQUEST';
-			$notificationType = 'Modificação de Calendario'; 
-			$part = 'othersAttendees';
-			self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType);
+	    $method = 'REQUEST';
+	    $notificationType = 'Modificação de Calendario'; 
+	    $part = 'othersAttendees';
+	    self::mountStruture($partID, $schedulable, $type , $data,  $subject, $ical, $part, $method, $notificationType);
 
             if ( isset($part) && count($part) > 0)
Index: /trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5907)
+++ /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5947)
@@ -659,6 +659,6 @@
             }
             //TODO - Padronizar retorno do deepness
-//            if(isset($v['user']))
-//                $result[$i]['user'] = Controller::read( array( 'concept' => 'user' , 'id' => $v['user']), false, false); 
+            if(isset($v['user']))
+                $result[$i]['user'] = Controller::read( array( 'concept' => 'user' , 'id' => $v['user']), false, false); 
           }
        }       
@@ -815,5 +815,5 @@
 	//Caso uma busca não retorne nenhum resultado e foi buscado pelas assinaturas do usuario logado apenas
 	$isValidSignature = false;
-		
+
 	//Veirifica pois o usuário pode ter varias assinaturas mas não ser dona de nenhuma
 	if(count($result) > 0){
@@ -849,5 +849,5 @@
                              'timezone' => isset($v->timezone) ? $v->timezone : (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo',
                              'dtstamp' => time().'000',
-                             'location' => $urlA[ (count($urlA)-2) ]
+                             'location' => $urlA[ (count($urlA)-3) ].'/'.$urlA[ (count($urlA)-2) ]
                             );
 
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);
+				
+			    }
                                 
                         }
