var resourceStatusColor={};resourceStatusColor.qtip2Class=[];resourceStatusColor.qtip2Class["R"]="qtip-bootstrap";resourceStatusColor.qtip2Class["A"]="qtip-bootstrap";resourceStatusColor.qtip2Class["V"]="qtip-bootstrap";resourceStatusColor.qtip=[];resourceStatusColor.qtip["R"]="light";resourceStatusColor.qtip["A"]="light";resourceStatusColor.qtip["V"]="light";resourceStatusColor.event=[];resourceStatusColor.event["R"]="#f15858";resourceStatusColor.event["A"]="#a7a7a7";
resourceStatusColor.event["V"]="#87bd41";resourceStatusColor.resourceClass=[];resourceStatusColor.resourceClass["R"]="refused";resourceStatusColor.resourceClass["A"]="waitingForValidation";resourceStatusColor.resourceClass["V"]="validated";if(typeof String.prototype.endsWith!=="function")String.prototype.endsWith=function(suffix){return this.indexOf(suffix,this.length-suffix.length)!==-1};
function prepareCalendarEvents(reservationEvents,labels,filters){var result=filters.viewResourceData?[]:reservationEvents;$.each(reservationEvents,function(index,reservationEvent){reservationEvent.calendarViewMode=true;reservationEvent.reservationId=reservationEvent.id;reservationEvent.reservationTitle=reservationEvent.title;reservationEvent.reservationStatus=reservationEvent.status;if(filters.viewResourceData)$.each(reservationEvent.resources,function(index,reservedResource){if(filters.resourceUri&&
!reservedResource.resourceURI.endsWith(filters.resourceUri))return;if(filters.categoryUri&&!reservedResource.categoryURI.endsWith(filters.categoryUri))return;var reservedResourceEvent=$.extend({},reservationEvent);reservedResourceEvent.id=reservedResource.id;reservedResourceEvent.title=reservedResource.name;reservedResourceEvent.status=reservedResource.status;result.push(reservedResourceEvent)})});$.each(result,function(index,event){event.borderColor=resourceStatusColor.event[event.status];event.backgroundColor=
resourceStatusColor.event[event.status];event.qtip={};event.qtip.title=labels.bookedBy+event.bookedBy;var $content=$("\x3cdiv\x3e").addClass("event-qtip").append(renderReservation(event,labels,filters).html());event.qtip.content=$("\x3cdiv\x3e").append($content).html();event.qtip.color=resourceStatusColor.qtip[event.status];event.qtip.classes=resourceStatusColor.qtip2Class[event.status]});return result}
function displayQTip(event){var $source;if(!event)event=null;if(event!=null&&event.$event)$source=$(event.$event);else $source=$("div.fc-event");$source.trigger("displayQTip")}function hideQTip(event){var $source;if(!event)event=null;if(event!=null&&event.$event)$source=$(event.$event);else $source=$("div.fc-event");$source.trigger("hideQTip")}
function calendarEventRenderV1(event,$event){event.$event=$event;$event.qtip({content:{title:{text:event.qtip.title,button:$("\x3cdiv\x3e").append($("\x3cimg\x3e",{src:webContext+"/util/icons/qtip-closed.gif",alt:labels.close,style:"margin-top: -2px;"})).html()},text:event.qtip.content},style:{width:"auto",border:{width:5,radius:5},padding:7,textAlign:"left",tip:true,name:event.qtip.color},position:{adjust:{screen:true},corner:{target:"topLeft",tooltip:"bottomLeft"}},show:{delay:0,when:{event:"displayQTip"}},
hide:{when:"hideQTip",fixed:true}})}function calendarEventRender(event,$event){event.$event=$event;$event.qtip({content:{title:{text:event.qtip.title,button:labels.close},text:event.qtip.content},style:{tip:true,classes:"qtip-shadow "+event.qtip.classes},position:{adjust:{method:"flip flip"},viewport:$(window),at:"top left",my:"bottom left"},show:{delay:0,event:"displayQTip"},hide:{fixed:true,event:"hideQTip"}})}
function renderReservationListing(reservationEvents,labels,filters){var $listing=$("\x3cul\x3e",{id:"reservationList"});var $periodBloc;if(reservationEvents&&reservationEvents.length>0){var oldDate;var isFirstReservationOfWeek;$.each(reservationEvents,function(index,reservationEvent){var reservationBeginDate=$.fullCalendar.moment(reservationEvent.start);if(index==0||oldDate.isoWeek()!=reservationBeginDate.isoWeek()){$listing.append(renderWeekSeparation(reservationBeginDate,labels));oldDate=reservationBeginDate;
isFirstReservationOfWeek=true;$periodBloc=$("\x3cul\x3e").addClass("reservationList").appendTo($listing)}if(!isFirstReservationOfWeek)$listing.append(renderReservationSeparation());$periodBloc.append(renderReservation(reservationEvent,labels,filters));isFirstReservationOfWeek=false})}return $listing}
function renderWeekSeparation(date,labels){var $separation=$("\x3ch3\x3e").addClass("reservationPeriode");$separation.append(labels.week+" "+date.isoWeek());return $("\x3cli\x3e").append($separation)}function renderReservationSeparation(){return $("\x3cdiv\x3e").addClass("reservation-separation")}
function renderReservation(reservation,labels,filters){if(!filters.language)filters.language="";var $reservation=$("\x3cli\x3e").addClass("reservation");if(!reservation.calendarViewMode)$reservation.click(function(event){goToReservation(reservation.id,filters.objectView,filters.isPortlet);return false});if(!reservation.calendarViewMode)$reservation.append(renderReservationAuthor(reservation,labels,filters).attr("title",labels.reservationLink));var goToReservationLink="javascript:onClick\x3dgoToReservation("+
reservation.reservationId+", '"+filters.objectView+"', "+filters.isPortlet+")";if(reservation.calendarViewMode)$reservation.append($("\x3ch4\x3e").append($("\x3ca\x3e",{href:goToReservationLink,title:labels.reservationLink}).append(reservation.reservationTitle)));else $reservation.append($("\x3ch4\x3e").append($("\x3ca\x3e").append(reservation.title).attr("title",labels.reservationLink)));if(reservation.place)if(reservation.calendarViewMode)$reservation.append($("\x3cp\x3e").addClass("reservationPlace").append(reservation.place));
else{var $info=$("\x3cdiv\x3e").addClass("reservationInfo");var $place=$("\x3cdiv\x3e").addClass("reservationPlace");var $bloc=$("\x3cdiv\x3e").addClass("bloc").append($("\x3cspan\x3e").append(reservation.place));$reservation.append($info.append($place.append($bloc)))}$reservation.append($("\x3cp\x3e").addClass("reservationDesc").append(reservation.reason.replace(/\n/,"\x3cbr/\x3e")));if(reservation.resources&&reservation.resources.length>0){var $resources=$("\x3cul\x3e").addClass("reservationRessources").appendTo($reservation);
$.each(reservation.resources,function(index,resource){var $resource=$("\x3cli\x3e").addClass(resourceStatusColor.resourceClass[resource.status]).append($("\x3ca\x3e",{href:"#",title:labels.resourceLink}).append(resource.name));$resources.append($resource);if(!reservation.calendarViewMode)$("a",$resource).click(function(){goToResource(resource.id,filters.objectView,filters.isPortlet);return false});else $("a",$resource).attr("href","javascript:onClick\x3dgoToResource("+resource.id+", '"+filters.objectView+
"', "+filters.isPortlet+")")})}$reservation.append($("\x3chr\x3e").addClass("clear"));if(reservation.calendarViewMode)$reservation.append($("\x3ca\x3e",{href:goToReservationLink}).addClass("reservation-link").append(labels.reservationLink));return $reservation}
function renderReservationAuthor(reservation,labels,filters){var $author=$("\x3ch5\x3e").append(renderReservationDates(reservation,labels,filters));if(!filters.planningOfUser){$author.append(" - ").append($("\x3cspan\x3e").addClass("reservationAuthor").append(labels.bookedBy));$author.append(" ").append(reservation.bookedBy)}return $author}
function renderReservationDates(reservation,labels,filters){var $result=$("\x3cspan\x3e").addClass("reservationDate");var isReservationOnOneDay=true;var beginDate=$.fullCalendar.moment(reservation.start);var endDate=$.fullCalendar.moment(reservation.end);if(!beginDate.isSame(endDate)){$result.append(labels.from);isReservationOnOneDay=false}else $result.append(labels.the);$result.append(" ").append(beginDate.locale(filters.language).format("L"));if(isReservationOnOneDay)$result.append(" ").append(labels.hourFrom);
$result.append(" ").append(beginDate.format("HH:mm"));if(isReservationOnOneDay)$result.append(" ").append(labels.hourTo);else{$result.append(" ").append(labels.to);$result.append(" ").append(endDate.locale(filters.language).format("L"))}$result.append(" ").append(endDate.format("HH:mm"));return $result}function goToReservation(id,objectView,isPortlet){var link="ViewReservation?reservationId\x3d"+id+"\x26objectView\x3d"+objectView;goToLink(link,objectView,isPortlet)}
function goToResource(id,objectView,isPortlet){var link="ViewResource?resourceId\x3d"+id+"\x26provenance\x3dcalendar\x26objectView\x3d"+objectView;goToLink(link,objectView,isPortlet)}function goToLink(link,objectView,isPortlet){if(isPortlet)spWindow.loadContent(link);else location.href=link};