/*
* Copyright (c) 2009 1Calendar ApS
* All Rights Reserved.
* http://www.1calendar.dk
* Date: Thu, 11 Mar 10 12:28:48 +0000
*/

(function($){Messaging=DUI.Class.create({listeners:{},listen:function(type,callback){if($.isArray(type)){var self=this;$.each(type,function(){self.listen(this,callback);});}else{if(!this.listeners[type])
this.listeners[type]=[];this.listeners[type].push(callback);}},fire:function(type,args){if(this.listeners[type]){var self=this;$.each(this.listeners[type],function(){this.apply(self,args);});}}});})(jQuery);
;
var DateInterval=function(years,months,days,hours,minutes,seconds){if(typeof years=='string'){var P=new String(years.match(/P[^T]*/));this.years=parseInt(P.match(/\d+Y/));this.months=parseInt(P.match(/\d+M/));this.days=parseInt(P.match(/\d+D/));if(isNaN(this.years))this.years=0;if(isNaN(this.months))this.months=0;if(isNaN(this.days))this.days=0;var T=new String(years.match(/T\w*/));this.hours=parseInt(T.match(/\d+H/));this.minutes=parseInt(T.match(/\d+M/));this.seconds=parseInt(T.match(/\d+S/));if(isNaN(this.hours))this.hours=0;if(isNaN(this.minutes))this.minutes=0;if(isNaN(this.seconds))this.seconds=0;}else{this.years=years|0;this.months=months|0;this.days=days|0;this.hours=hours|0;this.minutes=minutes|0;this.seconds=seconds|0;}};DateInterval.prototype.toTime=function(){return(this.years*31536000+
this.months*2678400+
this.days*86400+
this.hours*3600+
this.minutes*60+
this.seconds)*1000;};DateInterval.prototype.toString=function(){return'P'
+(this.years?this.years+'Y':'')
+(this.months?this.months+'M':'')
+(this.days?this.days+'D':'')
+(this.hours||this.minutes||this.seconds?'T'
+(this.hours?this.hours+'H':'')
+(this.minutes?this.minutes+'M':'')
+(this.seconds?this.seconds+'S':''):'');};DateInterval.prototype.clone=function(){return new DateInterval(this.years,this.months,this.days,this.hours,this.minutes,this.seconds);}
;
Date.prototype.onSameDateAs=function(date){return(this.getFullYear()==date.getFullYear()&&this.getMonth()==date.getMonth()&&this.getDate()==date.getDate());}
Date.prototype.getISO8601UTC=function(){return this.getUTCFullYear()
+(this.getUTCMonth()<9?'0':'')
+(this.getUTCMonth()+1)
+(this.getUTCDate()<10?'0':'')
+this.getUTCDate()
+'T'
+(this.getUTCHours()<10?'0':'')
+this.getUTCHours()
+(this.getUTCMinutes()<10?'0':'')
+this.getUTCMinutes()
+(this.getUTCSeconds()<10?'0':'')
+this.getUTCSeconds()
+'Z';}
Date.prototype.getISO8601Date=function(){return this.getFullYear()
+'-'
+(this.getMonth()<9?'0':'')
+(this.getMonth()+1)
+'-'
+(this.getDate()<10?'0':'')
+this.getDate();}
Date.prototype.daysInMonth=function(){switch(this.getMonth()){case 0:case 2:case 4:case 6:case 7:case 9:case 11:return 31;case 3:case 5:case 8:case 10:return 30;case 1:return this.isLeapYear()?29:28;}}
Date.prototype.isLeapYear=function(){return new Date(this.getFullYear(),1,29).getDate()==29;}
Date.prototype.getWeek=function(offset){dowOffset=typeof(offset)=='int'?offset:1;var newYear=new Date(this.getFullYear(),0,1);var day=newYear.getDay()-dowOffset;day=(day>=0?day:day+7);var daynum=Math.floor((this.getTime()-newYear.getTime()-
(this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000)+1;var weeknum;if(day<4){weeknum=Math.floor((daynum+day-1)/7)+1;if(weeknum>52){nYear=new Date(this.getFullYear()+1,0,1);nday=nYear.getDay()-dowOffset;nday=nday>=0?nday:nday+7;weeknum=nday<4?1:53;}}else{weeknum=Math.floor((daynum+day-1)/7);}
return weeknum;};Date.prototype.setWeek=function(week){var hours=this.getHours();this.setDate(this.getDate()+(week-this.getWeek())*7);if(this.getHours()!=hours){this.setHours(this.getHours()+(hours-this.getHours())%24);}
return this;}
Date.prototype.nextWeek=function(){this.setWeek(this.getWeek()+1);return this;}
Date.prototype.previousWeek=function(){this.setWeek(this.getWeek()-1);return this;}
Date.prototype.weeksTo=function(other){var diff=other.startOfWeek().getTime()-
this.startOfWeek().getTime();return diff/604800000;}
Date.prototype.inSameWeekAs=function(date){return(this.getFullYear()==date.getFullYear()&&this.getWeek()==date.getWeek());}
Date.prototype.getWeeksInYear=function(offset){var Y=this.getFullYear();return 52+((new Date(Y,0,1)).getDay()==4||(new Date(Y,11,31)).getDay()==4);}
Date.prototype.getStartOfDay=function(){var d=this.clone();d.setHours(0,0,0,0);return d;}
Date.prototype.endOfDay=function(){var d=this.clone();d.setHours(23,59,59,999);return d;}
Date.prototype.getDayStartingMonday=function(){if(this.getDay()==0)
return 6;else
return this.getDay()-1;}
Date.prototype.setDayStartingMonday=function(day){if(day>=0&&day<7){this.setDate(this.getDate()-this.getDayStartingMonday()+day);}}
Date.prototype.startOfWeek=function(){var d=new Date(this);if(this.getDay()==0)
d.setDate(this.getDate()-6)
else
d.setDate(this.getDate()-this.getDay()+1);d.setHours(0,0,0,0);return d;}
Date.prototype.endOfWeek=function(){var d=this.startOfWeek();d.setDate(d.getDate()+6);d.setHours(23,59,59,999);return d;}
Date.prototype.clone=function(){return new Date(this.getTime());}
Date.prototype.differenceTo=function(date){var diff=Math.abs(this.getTime()-date.getTime())/1000;return new DateInterval(Math.floor(diff/31536000),Math.floor((diff%31536000)/2678400),Math.floor((diff%2678400)/86400),Math.floor((diff%86400)/3600),Math.floor((diff%3600)/60),diff%60);}
Date.prototype.differenceInDaysTo=function(date){var diff=Math.abs(this.getTime()-date.getTime());return Math.floor(diff/86400000);}
Date.prototype._add=function(interval){if(typeof interval=='string')
interval=new DateInterval(interval);this.setTime(this.getTime()+interval.toTime());return this;}
Date.prototype.subtract=function(interval){if(typeof interval=='string')
interval=new DateInterval(interval);this.setTime(this.getTime()-interval.toTime());return this;}
Date.prototype.plus=function(interval){return this.clone()._add(interval);}
Date.prototype.minus=function(interval){return this.clone().subtract(interval);}
Date.prototype.sameWeekAs=function(date){return(this.getFullYear()==date.getFullYear()&&this.getWeek()==date.getWeek());}
;
(function($){function N(a,b){return a<b?-1:a==b?0:1;}
var wkdays={'SU':0,'MO':1,'TU':2,'WE':3,'TH':4,'FR':5,'SA':6};function wkd_to_num(wkd,wkst){return(wkdays[wkd]-wkdays[wkst]+7)%7;};function sort_unique(array){array.sort(N);for(var i=0;i<array.length-1;i++){var j=i+1;while(j<array.length&&array[j]==array[i]){j++;}
if(j!=i+1)
array.splice(i,j-i-1);}}
$.extend({ical:{text:function(rule){if(!rule)
return false;var t=[];$.each(rule,function(name,val){var r=[];switch(name){case'FREQ':case'INTERVAL':case'COUNT':case'WKST':r=[val];break;case'BYDAY':case'BYMONTHDAY':case'BYWEEKNO':case'BYMONTH':$.each(val,function(){if($.isArray(this))
if(this[0]==null)
r.push(this[1]);else
r.push(this[0]+this[1]);else
r.push(this);});break;case'UNTIL':r=[val.getISO8601UTC()];break;}
t.push(name+'='+r.join(','));});return t.join(';');},rule:function(s){var params=s.split(';');var rule={};$.each(params,function(){var part=this.split('=',2);switch(part[0]){case'FREQ':case'WKST':rule[part[0]]=part[1];break;case'INTERVAL':case'COUNT':rule[part[0]]=parseInt(part[1]);break;case'BYMONTH':case'BYWEEKNO':case'BYYEARDAY':case'BYMONTHDAY':rule[part[0]]=$.map(part[1].split(','),function(n){return parseInt(n);}).sort(N);break;case'BYDAY':rule.BYDAY=$.map(part[1].split(','),function(day){if(day.length==2)
return[[null,day]];return[[parseInt(day.substr(0,day.length-2)),day.substr(day.length-2,2)]];})
break;case'UNTIL':var date=/(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z/.exec(part[1]);rule.UNTIL=new Date(Date.UTC(date[1],date[2]-1,date[3],date[4],date[5],date[6]));break;case'':return;case'BYSETPOS':case'BYHOUR':case'BYMINUTE':case'BYSECOND':default:throw(part[0]);throw'Unsupported rule';}});return rule;},repeat:function(rule,start,end){if(!rule.INTERVAL)
rule.INTERVAL=1;if(!rule.WKST)
rule.WKST='MO';var filters=[];var days,months,years;var generators=[];switch(rule.FREQ){case'DAILY':if(rule.BYMONTHDAY){days=['BYMONTHDAY',{BYMONTHDAY:rule.BYMONTHDAY.sort(N)}];}else{days=['DAILY',{DTSTART:start.clone(),INTERVAL:rule.INTERVAL}];}
if(rule.BYDAY){filters.push(['BYDAY',{DTSTART:start.clone(),WKST:rule.WKST,BYDAY:rule.BYDAY,YEARLY:false}]);}
break;case'WEEKLY':if(rule.BYDAY){days=['BYDAY',{DTSTART:start.clone(),WKST:rule.WKST,BYDAY:rule.BYDAY,YEARLY:false}];filters.push(['WEEKLY',{INTERVAL:rule.INTERVAL,WKST:rule.WKST,DTSTART:new Date(start.getFullYear(),start.getMonth(),start.getDate()-
(7-(wkdays[rule.WKST]-start.getDay()))%7)}]);}else{days=['DAILY',{DTSTART:start.clone(),INTERVAL:rule.INTERVAL*7}];}
if(rule.BYMONTHDAY){filters.push(['BYMONTHDAY',{BYMONTHDAY:rule.BYMONTHDAY.sort(N)}]);}
break;case'YEARLY':if(rule.BYYEARDAY){months=['BYYEARDAY',{DTSTART:start.clone(),BYYEARDAY:rule.BYYEARDAY.sort(N)}];if(rule.BYDAY){filters.push(['BYDAY',{DTSTART:start.clone(),WKST:rule.WKST,BYDAY:rule.BYDAY,YEARLY:true}]);}
if(rule.BYMONTHDAY){filters.push(['BYMONTHDAY',{WKST:rule.WKST,BYMONTHDAY:rule.BYMONTHDAY.sort(N)}]);}
break;}
case'MONTHLY':if(rule.BYMONTHDAY){days=['BYMONTHDAY',{BYMONTHDAY:rule.BYMONTHDAY.sort(N)}];if(rule.BYDAY){filters.push(['BYDAY',{DTSTART:start.clone(),BYDAY:rule.BYDAY,WKST:rule.WKST,YEARLY:rule.FREQ=='YEARLY'}]);}}else if(rule.BYWEEKNO&&rule.FREQ=='YEARLY'){days=['BYWEEKNO',{BYWEEKNO:rule.BYWEEKNO.sort(N),DTSTART:start.clone(),WKST:rule.WKST}];if(!rule.BYDAY)
rule.BYDAY=[[null,['SU','MO','TU','WE','TH','FR','SA'][start.getDay()]]];if(rule.BYDAY){filters.push(['BYDAY',{DTSTART:start.clone(),BYDAY:rule.BYDAY,WKST:rule.WKST,YEARLY:true}]);}}else if(rule.BYDAY){if(rule.FREQ=='YEARLY'&&!rule.BYMONTH){months=['BYDAY',{DTSTART:start.clone(),WKST:rule.WKST,BYDAY:rule.BYDAY,YEARLY:true}];}else{days=['BYDAY',{DTSTART:start.clone(),WKST:rule.WKST,BYDAY:rule.BYDAY,YEARLY:false}];}}else{if(rule.FREQ=='YEARLY'){months=['BYMONTH',{BYMONTH:[start.getMonth()+1]}];}
days=['BYMONTHDAY',{BYMONTHDAY:[start.getDate()]}];}
break;}
generators.push(years=['YEARLY',{INTERVAL:rule.FREQ=='YEARLY'?rule.INTERVAL:1}]);if(rule.BYMONTH){generators.push(['BYMONTH',{BYMONTH:rule.BYMONTH.sort(N)}]);}else if(months){generators.push(months);}else if(!rule.BYWEEKNO){generators.push(['MONTHLY',{INTERVAL:rule.FREQ=='MONTHLY'?rule.INTERVAL:1}]);}
if(days)
generators.push(days);var cached=null;var current=start.clone();var count=0;this.next=function(){if(cached){var c=cached;cached=null;return c;}
if(rule.COUNT&&count==rule.COUNT)
return false;while(true){if(current.getTime()>end.getTime()){return false;}
var accept=true;if(current.getTime()!=start.getTime()){for(var j=0;j<filters.length;j++){if(!filter(current,filters[j][0],filters[j][1])){accept=false;break;}}}
var _current=current.clone();var i=generators.length;var done=false;while(i-->0){if(generate(current,generators[i][0],generators[i][1])){while(++i<generators.length){if(!generate(current,generators[i][0],generators[i][1],true))
i-=2;}
done=true;}
if(done)
break;}
if(accept){count++;return _current;}}}
this.skipTo=function(date){if(date.getTime()<=current.getTime())
return;while(current.getFullYear()<date.getFullYear()){if(!generate(current,years[0],years[1]))
return;if(months)
generate(current,months[0],months[1]);if(days)
generate(current,days[0],days[1]);}
if(current.getFullYear()==date.getFullYear()&&current.getMonth()<date.getMonth()){if(months){do{if(!generate(current,months[0],months[1])){generate(current,years[0],years[1]);generate(current,months[0],months[1]);break;}}while(current.getMonth()<date.getMonth());}
if(days)
generate(current,days[0],days[1]);}
var next;do{if(!(next=this.next()))
break;}while(next.getTime()<date.getTime());cached=next;}
function generate(builder,kind,args,reset){if(reset){switch(kind){case'BYMONTHDAY':case'BYDAY':builder.setDate(1);}}
switch(kind){case'DAILY':var next;if(args.DTSTART.getFullYear()==builder.getFullYear()&&args.DTSTART.getMonth()==builder.getMonth()){next=builder.getDate()+args.INTERVAL;if(next>builder.daysInMonth())
return false;}else{if(args.INTERVAL==1){next=1;}else{var startOfMonth=builder.clone();startOfMonth.setDate(1);var difference=startOfMonth.differenceInDaysTo(args.DTSTART);next=(args.INTERVAL-(difference%args.INTERVAL))%args.INTERVAL+1;if(next>builder.daysInMonth())
return false;}}
args.DTSTART.setFullYear(builder.getFullYear(),builder.getMonth(),next);builder.setDate(next);return true;case'MONTHLY':builder.setMonth(builder.getMonth()+args.INTERVAL,1);return true;case'YEARLY':builder.setFullYear(builder.getFullYear()+args.INTERVAL,0,1);return true;case'WEEKLY':return Math.floor((builder.getTime()-args.START)/604800)%args.INTERVAL==0;case'BYYEARDAY':var next;if(next=fnext(args.BYYEARDAY,builder.getOrdinalNumber(),builder.isLeapYear()?366:365,reset)){builder.setMonth(0,next);return true;}
return false;case'BYMONTHDAY':var next;if(next=fnext(args.BYMONTHDAY,builder.getDate(),builder.daysInMonth(),reset)){builder.setDate(next);return true;}
return false;case'BYWEEKNO':if(!args.DATES||args.DTSTART.getFullYear()!=builder.getFullYear()){args.DTSTART.setFullYear(builder.getFullYear(),builder.getMonth());build_bywknoarray(args);}
if(next=snext(args.DATES,builder.getOrdinalNumber(),reset)){builder.setMonth(0,next);return true;}
return false;case'BYDAY':if(!args.DATES||!args.YEARLY&&args.DTSTART.getMonth()!=builder.getMonth()||args.DTSTART.getFullYear()!=builder.getFullYear()){args.DTSTART.setFullYear(builder.getFullYear(),builder.getMonth());build_bydarray(args);}
var next;if(args.YEARLY){if(next=snext(args.DATES,builder.getOrdinalNumber(),reset)){builder.setMonth(0,next);return true;}}else{if(next=snext(args.DATES,builder.getDate(),reset)){builder.setDate(next);return true;}}
return false;case'BYMONTH':var next;if(next=snext(args.BYMONTH,builder.getMonth()+1,reset)){builder.setMonth(next-1);return true;}
return false;}}
function filter(builder,kind,args){switch(kind){case'WEEKLY':return Math.floor((builder.getTime()-args.DTSTART.getTime())/604800000)%args.INTERVAL==0;case'BYDAY':if(!args.MAP)
build_byd_match_map(args);return bydmap_match(args,builder);case'BYMONTHDAY':return fmatch(args.BYMONTHDAY,builder.getDate(),builder.daysInMonth());}}
function build_bywknoarray(args){args.DATES=[];var total=args.DTSTART.isLeapYear()?366:365;var first=new Date(args.DTSTART.getFullYear(),0,1).getDay();var first_week_start=8-(first-wkdays[args.WKST]);if(first_week_start>4){first_week_start-=7;}
var weeks=(total-first_week_start+6)/7;for(var i=0;i<args.BYWEEKNO.length;i++){var weekno=args.BYWEEKNO[i];if(Math.abs(weekno)>weeks)
continue;if(weekno<0)
weekno+=weeks+1;var day=Math.max(1,first_week_start+(weekno-1)*7);var end=Math.min(day+7,total);while(day<end){args.DATES.push(day);day++;}}
sort_unique(args.DATES);}
function bydmap_match(args,builder){var day=['SU','MO','TU','WE','TH','FR','SA'][builder.getDay()];if(args.MAP.all[day])
return true;if(!args.MAP[day])
return false;var first,current,length;if(args.YEARLY){first=new Date(args.DTSTART.getFullYear(),0,1).getDay();length=builder.isLeapYear()?366:365;current=builder.getDay();}else{first=new Date(args.DTSTART.getFullYear(),args.DTSTART.getMonth(),1).getDay();length=builder.daysInMonth();current=builder.getDay();}
var week=1+Math.floor((builder.daysInMonth()-
(current>=first?current-first:first-current)-1)/7);var total=Math.floor((length-first)/7);return fmatch(week,args.MAP[day],total);}
function build_byd_match_map(args){args.MAP={};args.MAP.all=[];for(var i=0;i<args.BYDAY.length;i++){var number=args.BYDAY[i][0];var weekday=args.BYDAY[i][1];if(number==null){args.MAP.all[weekday]=true;}else{if(!args.MAP[weekday])
args.MAP[weekday]=[];args.MAP[weekday].push(number);args.MAP[weekday].sort(N);}}}
function build_bydarray(args){args.DATES=[];var length=args.YEARLY?args.DTSTART.isLeapYear()?366:365:args.DTSTART.daysInMonth();var first_weekday=(7-wkdays[args.WKST]+
(args.YEARLY?new Date(args.DTSTART.getFullYear(),0,1).getDay():new Date(args.DTSTART.getFullYear(),args.DTSTART.getMonth(),1).getDay()))%7;for(var i=0;i<args.BYDAY.length;i++){var number=args.BYDAY[i][0];var weekday=wkd_to_num(args.BYDAY[i][1],args.WKST);var first=1-first_weekday+weekday;if(weekday<first_weekday)
first+=7;last=first+Math.floor((length-first)/7)*7;if(number){offset=7*Math.abs(number)-7;if(first+offset>length)
continue;if(number>0){args.DATES.push(first+offset);}else{args.DATES.push(last-offset);}}else{nth=first;while(nth<=last){args.DATES.push(nth);nth+=7;}}}
sort_unique(args.DATES);};function fnext(array,current,max,accept_current){var ncurrent=current-max-1;var min_nr=0xffff;for(var i=0;i<array.length;i++){if(array[i]<0){if(array[i]>ncurrent){var real=max+array[i]+1;if(real<=max)
min_nr=Math.min(min_nr,real);}
if(accept_current&&array[i]==ncurrent)
return current;}else{if(array[i]>current){if(array[i]<=min_nr)
return array[i];else
return min_nr;}else if(accept_current&&array[i]==current){return current;}}}
return min_nr==0xffff?false:min_nr;}
function fmatch(haystack,needle,max){var nneedle=needle-max+1;return(sfind(needle,haystack)!==false||sfind(nneedle,haystack)!==false);}
function sfind(needle,haystack){var i=0,j=haystack.length-1;var k;do{k=Math.floor((i+j)/2);if(needle>haystack[k])
i=k+1;else if(needle==haystack[k])
return k;else
j=k-1;}while(i<=j);return false;}
function snext(array,current,accept_current){for(var i=0;i<array.length;i++){if(array[i]>current)
return array[i];else if(accept_current&&array[i]==current)
return current;}
return false;}}}});})(jQuery);
;
Array.prototype.delimJoin=function(delimiter,finalDelimiter){var list='';for(var i=0;i<this.length;i++){if(i!=0){if(i==this.length-1){list+=' '+finalDelimiter+' ';}else{list+=delimiter+' ';}}
list+=this[i];}
return list;};(function($){$.extend({ruleToText:function(rule,today){if(!rule)
return ss.i18n._t('LangRepeat.NEVER');var interval=rule.INTERVAL?rule.INTERVAL:1;var text=ss.i18n._t('LangRepeat.EVERY');function plural(n){return n%100!=1;}
var wkd2weekday={'MO':Date.CultureInfo.abbreviatedDayNames[1],'TU':Date.CultureInfo.abbreviatedDayNames[2],'WE':Date.CultureInfo.abbreviatedDayNames[3],'TH':Date.CultureInfo.abbreviatedDayNames[4],'FR':Date.CultureInfo.abbreviatedDayNames[5],'SA':Date.CultureInfo.abbreviatedDayNames[6],'SU':Date.CultureInfo.abbreviatedDayNames[0]};function isWeekdays(days){days=daysforAllWeeks(days);return(days.indexOf('MO')!=-1&&days.indexOf('TU')!=-1&&days.indexOf('WE')!=-1&&days.indexOf('TH')!=-1&&days.indexOf('FR')!=-1&&days.indexOf('SA')==-1&&days.indexOf('SU')==-1);}
function daysforAllWeeks(days){var all=[];$.each(days,function(){if(this[0]==null)
all.push(this[1]);});return all;}
function nth(n){var nth,npos;if(n==-1)
return ss.i18n._t('LangRepeat.LAST');npos=Math.abs(n);switch(npos){case 1:case 21:case 31:nth=npos+ss.i18n._t('LangRepeat.ST');break;case 2:case 22:nth=npos+ss.i18n._t('LangRepeat.ND');break;case 3:case 23:nth=npos+ss.i18n._t('LangRepeat.RD');break;default:nth=npos+ss.i18n._t('LangRepeat.TH');}
return n<0?nth+' '+ss.i18n._t('LangRepeat.LAST'):nth;}
switch(rule.FREQ){case'DAILY':if(interval!=1)
text+=' '+interval;if(rule.BYDAY&&isWeekdays(rule.BYDAY)){text+=' '+(plural(interval)?ss.i18n._t('LangRepeat.WEEKDAYS'):ss.i18n._t('LangRepeat.WEEKDAY'));}else{text+=' '+(plural(interval)?ss.i18n._t('LangRepeat.DAYS'):ss.i18n._t('LangRepeat.DAY'));}
if(rule.BYMONTH){text+=' '+ss.i18n._t('LangRepeat.IN')+' '+$.map(rule.BYMONTH,function(m){return Date.CultureInfo.monthNames[m-1];}).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}
var forAll;if(rule.BYMONTHDAY){if(rule.BYDAY&&(forAll=daysforAllWeeks(rule.BYDAY)).length){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+$.map(forAll,function(w){return wkd2weekday[w];}).delimJoin(',',ss.i18n._t('LangRepeat.OR'));text+=' '+ss.i18n._t('LangRepeat.THE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.OR'));}else{text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}}
if(rule.BYDAY){if(!forAll){var forAll=daysforAllWeeks(rule.BYDAY);if(forAll.length!=0&&!isWeekdays(rule.BYDAY)){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+
$.map(forAll,function(w){return wkd2weekday[w];}).join(', ');}}
if(rule.BYDAY.length-forAll.length>0){if(forAll.length)
text+=' '+ss.i18n._t('LangRepeat.AND');text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYDAY,function(wkd){if(wkd[0]==null)
return null;return nth(wkd[0])+' '+wkd2weekday[wkd[1]];}).join(',',ss.i18n._t('LangRepeat.AND'));}}
break;case'WEEKLY':if(interval!=1)
text+=' '+interval+' '+(plural(interval)?ss.i18n._t('LangRepeat.WEEKS'):ss.i18n._t('LangRepeat.WEEK'));if(rule.BYDAY&&isWeekdays(rule.BYDAY)){text+=(interval==1)?' '+ss.i18n._t('LangRepeat.WEEKDAY'):' '+ss.i18n._t('LangRepeat.ON')+ss.i18n._t('LangRepeat.WEEKDAYS');}else{if(interval==1)
text+=' '+ss.i18n._t('LangRepeat.WEEK');if(rule.BYMONTH){text+=' '+ss.i18n._t('LangRepeat.IN')+' '+$.map(rule.BYMONTH,function(m){return Date.CultureInfo.monthNames[m-1];}).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}
var forAll;if(rule.BYMONTHDAY){if(rule.BYDAY&&(forAll=daysforAllWeeks(rule.BYDAY)).length){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+$.map(forAll,function(w){return wkd2weekday[w];}).delimJoin(',',ss.i18n._t('LangRepeat.OR'));text+=' '+ss.i18n._t('LangRepeat.THE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.OR'));}else{text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}}
if(rule.BYDAY){if(!forAll){var forAll=daysforAllWeeks(rule.BYDAY);if(forAll.length!=0&&!isWeekdays(rule.BYDAY)){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+
$.map(forAll,function(w){return wkd2weekday[w];}).join(', ');}}
if(rule.BYDAY.length-forAll.length>0){if(forAll.length)
text+=' '+ss.i18n._t('LangRepeat.AND');text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYDAY,function(wkd){if(wkd[0]==null)
return null;return nth(wkd[0])+' '+wkd2weekday[wkd[1]];}).join(',',ss.i18n._t('LangRepeat.AND'));}}}
break;case'MONTHLY':if(rule.BYMONTH){if(interval!=1){text+=' '+interval+' '+(plural(interval)?ss.i18n._t('LangRepeat.MONTHS'):ss.i18n._t('LangRepeat.MONTH'))+' '+ss.i18n._t('LangRepeat.IN')+' ';}else{text+=' ';}
if(rule.BYMONTH){text+=$.map(rule.BYMONTH,function(m){return Date.CultureInfo.monthNames[m-1];}).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}}else{if(interval!=1){text+=' '+interval+' '+(plural(interval)?ss.i18n._t('LangRepeat.MONTHS'):ss.i18n._t('LangRepeat.MONTH'));}else{text+=' '+ss.i18n._t('LangRepeat.MONTH');}}
var forAll;if(rule.BYMONTHDAY){if(rule.BYDAY&&(forAll=daysforAllWeeks(rule.BYDAY)).length){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+$.map(forAll,function(w){return wkd2weekday[w];}).delimJoin(',',ss.i18n._t('LangRepeat.OR'));text+=' '+ss.i18n._t('LangRepeat.THE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.OR'));}else{text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}}
if(rule.BYDAY){if(!forAll){var forAll=daysforAllWeeks(rule.BYDAY);if(forAll.length!=0&&!isWeekdays(rule.BYDAY)){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+
$.map(forAll,function(w){return wkd2weekday[w];}).join(', ');}}
if(rule.BYDAY.length-forAll.length>0){if(forAll.length)
text+=' '+ss.i18n._t('LangRepeat.AND');text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYDAY,function(wkd){if(wkd[0]==null)
return null;return nth(wkd[0])+' '+wkd2weekday[wkd[1]];}).join(',',ss.i18n._t('LangRepeat.AND'));}}
break;case'YEARLY':if(rule.BYMONTH){if(interval!=1){text+=' '+interval+' '+(plural(interval)?ss.i18n._t('LangRepeat.YEARS'):ss.i18n._t('LangRepeat.YEAR'))+' '+ss.i18n._t('LangRepeat.IN');}
text+=' '+$.map(rule.BYMONTH,function(m){return Date.CultureInfo.monthNames[m-1];}).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}else{text+=interval==1?' '+ss.i18n._t('LangRepeat.YEAR'):' '+interval+' '+(plural(interval)?ss.i18n._t('LangRepeat.YEARS'):ss.i18n._t('LangRepeat.YEAR'));}
var forAll;if(rule.BYMONTHDAY){if(rule.BYDAY&&(forAll=daysforAllWeeks(rule.BYDAY)).length){text+=' '+ss.i18n._t('LangRepeat.ON')+''+$.map(forAll,function(w){return wkd2weekday[w];}).delimJoin(',',ss.i18n._t('LangRepeat.OR'));text+=' '+ss.i18n._t('LangRepeat.THE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.OR'));}else{text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYMONTHDAY,nth).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}}
if(rule.BYDAY&&isWeekdays(rule.BYDAY)){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+ss.i18n._t('LangRepeat.WEEKDAYS');}else if(rule.BYDAY){if(!forAll){var forAll=daysforAllWeeks(rule.BYDAY);if(forAll.length!=0&&!isWeekdays(rule.BYDAY)){text+=' '+ss.i18n._t('LangRepeat.ON')+' '+
$.map(forAll,function(w){return wkd2weekday[w];}).join(', ');}}
if(rule.BYDAY.length-forAll.length>0){if(forAll.length)
text+=' '+ss.i18n._t('LangRepeat.AND');text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+$.map(rule.BYDAY,function(wkd){if(wkd[0]==null)
return null;return nth(wkd[0])+' '+wkd2weekday[wkd[1]];}).delimJoin(',',ss.i18n._t('LangRepeat.AND'));}}
if(rule.BYYEARDAY){text+=' '+ss.i18n._t('LangRepeat.ONTHE')+' '+rule.BYYEARDAY.delimJoin(',',ss.i18n._t('LangRepeat.AND'));}
if(rule.BYWEEKNO){text+=' '+ss.i18n._t('LangRepeat.IN')+' '+(plural(rule.BYWEEKNO.length)?ss.i18n._t('LangRepeat.WEEKS'):ss.i18n._t('LangRepeat.WEEK'));text+=' '+rule.BYWEEKNO.delimJoin(',',ss.i18n._t('LangRepeat.AND'));}}
if(rule.COUNT){text+=' '+ss.i18n._t('LangRepeat.FOR')+' '+rule.COUNT+' '+(plural(rule.COUNT)?ss.i18n._t('LangRepeat.TIMES'):ss.i18n._t('LangRepeat.TIME'));}else if(rule.UNTIL){text+=' '+ss.i18n._t('LangRepeat.UNTIL');if(today&&today.inSameWeekAs(rule.UNTIL)){text+=' '+Date.CultureInfo.dayNames[rule.UNTIL.getDay()];}else{text+=' '+Date.CultureInfo.monthNames[rule.UNTIL.getMonth()]
+' '+rule.UNTIL.getDate();if(!(today&&today.getFullYear()==rule.UNTIL.getFullYear())){text+=', '+rule.UNTIL.getFullYear();}}}
return text;},textToRule:function(text){var ttr=new Parser(Date.CultureInfo.RTRParser);if(!ttr.start(text)){return false;}
var rule={};try{S();return rule;}catch(e){return false;}
function S(){ttr.expect('every');var n;if(n=ttr.accept('number'))
rule.INTERVAL=parseInt(n[0]);if(ttr.isDone())
throw'Unexpected end';switch(ttr.symbol){case'day(s)':rule.FREQ='DAILY';ttr.nextSymbol();F();break;case'weekday(s)':rule.FREQ='WEEKLY';rule.BYDAY=[[null,'MO'],[null,'TU'],[null,'WE'],[null,'TH'],[null,'FR']];ttr.nextSymbol();F();break;case'week(s)':rule.FREQ='WEEKLY';if(ttr.nextSymbol()){ON();F();}
break;case'month(s)':rule.FREQ='MONTHLY';if(ttr.nextSymbol()){ON();F();}
break;case'year(s)':rule.FREQ='YEARLY';if(ttr.nextSymbol()){ON();F();}
break;case'monday':case'tuesday':case'wednesday':case'thursday':case'friday':case'saturday':case'sunday':rule.FREQ='WEEKLY';rule.BYDAY=[[null,ttr.symbol.substr(0,2).toUpperCase()]];if(!ttr.nextSymbol())
return;while(ttr.accept('comma')){if(ttr.isDone())
throw'Unexpected end';var wkd;if(!(wkd=decodeWKD())){throw'Unexpected symbol '+ttr.symbol+', expected weekday';}
rule.BYDAY.push([null,wkd]);ttr.nextSymbol();}
MDAYs();F();break;case'january':case'february':case'march':case'april':case'may':case'june':case'july':case'august':case'september':case'october':case'november':case'december':rule.FREQ='YEARLY';rule.BYMONTH=[decodeM()];if(!ttr.nextSymbol())
return;while(ttr.accept('comma')){if(ttr.isDone())
throw'Unexpected end';var m;if(!(m=decodeM())){throw'Unexpected symbol '+ttr.symbol+', expected month';}
rule.BYMONTH.push([null,m]);ttr.nextSymbol();}
ON();F();break;default:throw'Unknown symbol';}}
function ON(){do{ttr.accept('on');ttr.accept('the');var nth,wkd,m;if(nth=decodeNTH()){ttr.nextSymbol();if(wkd=decodeWKD()){ttr.nextSymbol();if(!rule.BYDAY)
rule.BYDAY=[];rule.BYDAY.push([nth,wkd]);}else{if(!rule.BYMONTHDAY)
rule.BYMONTHDAY=[];rule.BYMONTHDAY.push(nth);}}else if(wkd=decodeWKD()){ttr.nextSymbol();if(!rule.BYDAY)
rule.BYDAY=[];rule.BYDAY.push([null,wkd]);}else if(ttr.symbol=='weekday(s)'){ttr.nextSymbol();if(!rule.BYDAY)
rule.BYDAY=[];rule.BYDAY.push([null,'MO']);rule.BYDAY.push([null,'TU']);rule.BYDAY.push([null,'WE']);rule.BYDAY.push([null,'TH']);rule.BYDAY.push([null,'FR']);}else if(m=decodeM()){ttr.nextSymbol();if(!rule.BYMONTH)
rule.BYMONTH=[];rule.BYMONTH.push(m);}else{return;}}while(ttr.accept('comma')||ttr.accept('the'));}
function decodeM(){switch(ttr.symbol){case'january':return 1;case'february':return 2;case'march':return 3;case'april':return 4;case'may':return 5;case'june':return 6;case'july':return 7;case'august':return 8;case'september':return 9;case'october':return 10;case'november':return 11;case'december':return 12;default:return false;}}
function decodeWKD(){switch(ttr.symbol){case'monday':case'tuesday':case'wednesday':case'thursday':case'friday':case'saturday':case'sunday':return ttr.symbol.substr(0,2).toUpperCase();break;default:return false;}}
function decodeNTH(){switch(ttr.symbol){case'first':return 1;case'second':return 2;case'third':return 3;case'nth':var v=parseInt(ttr.value[1]);if(v<-366||v>366)
throw'Nth out of range: '+v;return v;default:return false;}}
function MDAYs(){ttr.accept('on');ttr.accept('the');var nth;if(!(nth=decodeNTH())){return;}
rule.BYMONTHDAY=[nth];ttr.nextSymbol();while(ttr.accept('comma')){if(!(nth=decodeNTH())){throw'Unexpected symbol '+ttr.symbol+'; expected monthday';}
rule.BYMONTHDAY.push(nth);ttr.nextSymbol();}}
function F(){if(ttr.symbol=='until'){var date=Date.parse(ttr.text);if(!date)
throw'Cannot parse until date:'+ttr.text;rule.UNTIL=date;}else if(ttr.accept('for')){rule.COUNT=ttr.value[0];ttr.expect('number');}}}});})(jQuery);
;
(function($){Calendar=DUI.Class.create(Messaging.prototype,{listeners:{},__week:Date.today().startOfWeek(),events:[],find:function(eventId){var i=0,j=this.events.length-1;var k;do{k=Math.floor((i+j)/2);if(eventId>this.events[k].Id)
i=k+1;else if(eventId==this.events[k].Id)
return this.events[k];else
j=k-1;}while(i<=j);return false;},isAllday:function(event){return!!(event.duration.seconds==0&&event.duration.minutes==0&&event.duration.hours%24==0);},$inRange:function(normal,allday,range_start,range_duration){var isExdate=function(date){if(this.overrides.length==0)
return false;var time=date.getTime();var i=0,j=this.overrides.length-1;var k;do{k=Math.floor((i+j)/2);if(time>this.overrides[k][0])
i=k+1;else if(time==this.overrides[k][0])
return true;else
j=k-1;}while(i<=j);return false;}
var event,event_start,is_allday;var $start=range_start.getTime(),$end=range_start.plus(range_duration).getTime();for(var i=0,l=this.events.length;i<l;++i){event=this.events[i];is_allday=this.isAllday(event);event_start=is_allday?event.start.plus(event.duration):event.start;if(event.repeat){if(event_start>$end||event.end!=null&&event.end<$start)
continue;var end=event.end==null?$end:Math.min(event.end.getTime(),$end);var it=new $.ical.repeat(event.repeat,event.start,new Date(end));it.skipTo(is_allday?new Date($start).minus(event.duration):new Date($start));var date;while(date=it.next()){if(allday&&date.getTime()<=new Date($start).minus(event.duration))
continue;if(allday&&date.getTime()>=new Date($end))
continue;if(isExdate.call(event,date))
continue;(is_allday?allday:normal).addOnDate(event,date.clone(),date.clone());}}else if(event_start.getTime()>=$start&&event.start.getTime()<$end){(is_allday?allday:normal).addOnDate(event,event.start);}}},create:function(name,date,duration){var event;this.events.push(event={'Id':Math.floor(Math.random()*1000000),'calendarId':0,'categoryId':0,'locked':true,'editable':true,'name':name,'start':date.clone(),'end':date.clone(),'duration':duration.clone()});this.fire('event-add',[event]);var self=this;$.post('/api/request/?c=event.create',{'start':date.getISO8601UTC(),'duration':duration.toString(),'name':name},function(eventId){if(eventId=='not-logged-in'){location.reload();return;}
var oldId=event.Id;event.Id=eventId;self.fire('event-id-update',[oldId,eventId]);self.fire('single-event-id-update',[oldId,eventId]);event.locked=false;self.fire('event-unlock',[event,false,false]);},'json');return event;},move:function(event,date,duration){event.start=date;event.duration=duration;if(!Calendar.isAllday(event)&&!event.start.onSameDateAs(event.start.plus(duration))){event.duration=event.start.differenceTo(event.start.endOfDay());}
event.locked=true;this.fire('event-move',[event]);this.fire('event-lock',[event,true,false]);var self=this;$.post('/api/request/?c=event.move',{'Id':event.Id,'start':date.getISO8601UTC(),'duration':duration.toString()},function(r){if(r=='not-logged-in'){location.reload();return;}
event.locked=false;self.fire('event-unlock',[event,false,false]);},'json');},edit:function(event,changes){function isEmpty(ob){for(var i in ob){return false;}
return true;}
if(isEmpty(changes))
return;event.locked=true;this.fire('event-lock',[event,true,false]);if(typeof changes.repeat!='undefined')
event.repeat=changes.repeat;if(typeof changes.start!='undefined')
event.start=changes.start;if(typeof changes.duration!='undefined')
event.duration=changes.duration;if(typeof changes.name!='undefined')
event.name=changes.name;if(typeof changes.description!='undefined')
event.description=changes.description;if(typeof changes.location!='undefined')
event.location=changes.location;if(typeof changes.url!='undefined')
event.url=changes.url;if(typeof changes.categoryId!='undefined')
event.categoryId=changes.categoryId;if(!Calendar.isAllday(event)&&!event.start.onSameDateAs(event.start.plus(event.duration))){event.duration=event.start.differenceTo(event.start.endOfDay());}
if(changes.repeat||event.repeat&&changes.start){if(event.repeat.UNTIL){event.end=event.repeat.UNTIL.clone();event.end.setHours(23,59,59,999);}else if(event.repeat.COUNT){var r=new $.ical.repeat(event.repeat,event.start,new Date(2020,0,1));for(var i=1;i<event.repeat.COUNT;i++){r.next();}
event.end=r.next();event.end.setHours(23,59,59,999);}else{event.end=null;}}else if(!event.repeat){event.end=null;}
this.fire('event-edit',[event]);var self=this;$.post('/api/request/?c=event.edit',{'Id':event.Id,'start':event.start.getISO8601UTC(),'end':(event.repeat&&event.end)?event.end.getISO8601UTC():'','duration':event.duration.toString(),'categoryId':event.categoryId,'name':event.name,'repeat':event.repeat==null?'':$.ical.text(event.repeat),'description':event.description||'','location':event.location||'','url':event.url||''},function(r){if(r=='not-logged-in'){location.reload();return;}
event.locked=false;self.fire('event-unlock',[event,false,false]);},'json');},remove:function(event,options){this.fire('event-lock',[event,true,false]);var self=this;var whenRemoved=function(r){if(r=='not-logged-in'){location.reload();return;}
var i=0,j=Calendar.events.length-1;var k;do{k=Math.floor((i+j)/2);if(event.Id>Calendar.events[k].Id)
i=k+1;else
if(event.Id==Calendar.events[k].Id){Calendar.events.splice(k,1);self.fire('event-remove',[event,false,null]);return;}
else
j=k-1;}
while(i<=j);Ω};if($.isArray(event.calendarId)&&event.calendarId[0]=='location'){$.post('/api/request/?c=subscription.removeEvent',{'Id':event.Id},whenRemoved,'json');}else{$.post('/api/request/?c=event.remove',{'Id':event.Id},whenRemoved,'json');}},setWeek:function(week,callback){this.__week=week.startOfWeek();this.fire('week-change',[this.events,{'week':this.__week.clone(),'weekNo':this.__week.getWeek()}]);},getWeek:function(){return this.__week.clone();},removeShared:function(sharesubscription){var self=this;for(i=Calendar.events.length-1;i>=0;i--){if(sharesubscription.categoryId==Calendar.events[i].categoryId)
Calendar.events.splice(i,1);}
self.fire('shared-removed',[self.events]);},loadShared:function(sharedSubscriptionId,start,period){var self=this;$.post('/api/request/?c=shared.loadSharedEvents',{'sharedSubscriptionId':sharedSubscriptionId,'start':start.getISO8601UTC(),'period':period.toString()},function(events){if(events=='not-logged-in'){location.reload();return;}
var numeric_overrides=function(arr){for(var i=0,l=arr.length;i<l;++i)
arr[i][0]=parseInt(arr[i][0]);return arr;}
$.each(events,function(){self.events.push({'Id':this[0],'locked':false,'editable':this[1],'calendarId':this[2],'categoryId':this[3],'start':new Date(this[4]),'end':this[7]!=null?new Date(this[7]):null,'overrides':numeric_overrides(this[9]),'duration':new DateInterval(this[5]),'repeat':this[6]?$.ical.rule(this[6]):null,'name':this[10],'description':this[11],'location':this[12],'url':this[13],'thumb':this[14]?this[14]:null});});self.fire('shared-load',[self.events]);},'json');self.events.sort(function(a,b){return a.Id<b.Id?-1:a.Id==b.Id?0:1;});},__load:function(start,period){var self=this;$.post('/api/request/?c=calendar.load',{'start':start.getISO8601UTC(),'period':period.toString()},function(events){if(events=='not-logged-in'){location.reload();return;}
Calendar.events.splice(0);var numeric_overrides=function(arr){for(var i=0,l=arr.length;i<l;++i)
arr[i][0]=parseInt(arr[i][0]);return arr;}
$.each(events,function(){self.events.push({'Id':this[0],'locked':false,'editable':this[1],'calendarId':this[2],'categoryId':this[3],'start':new Date(this[4]),'end':this[7]!=null?new Date(this[7]):null,'overrides':numeric_overrides(this[9]),'duration':new DateInterval(this[5]),'repeat':this[6]?$.ical.rule(this[6]):null,'name':this[10],'description':this[11],'location':this[12],'url':this[13],'thumb':this[14]?this[14]:null});});self.events.sort(function(a,b){return a.Id<b.Id?-1:a.Id==b.Id?0:1;});self.fire('load',[self.events]);},'json');}},true);})(jQuery);
;
(function($){Categories=DUI.Class.create(Messaging.prototype,{listeners:{},categories:[{'Id':0,'name':ss.i18n._t('Category.HOME'),'color':'#96bf0d','visible':true,'shared':false,'locked':false}],subscriptions:[],itemIsSubscription:function(item){return $.isArray(item.Id);},find:function(categoryId){var i=0,j=this.categories.length-1;var k;do{k=Math.floor((i+j)/2);if(categoryId>this.categories[k].Id)
i=k+1;else if(categoryId==this.categories[k].Id)
return this.categories[k];else
j=k-1;}while(i<=j);return false;},create:function(name,color,shared){var self=this;var category={'Id':Math.floor(Math.random()*1000000),'name':name,'color':color,'shared':shared,'visible':true,'locked':true};this.fire('category-add',[category]);this.categories.push(category);$.post('/api/request/?c=category.create',{'name':name,'color':color.substr(1),'shared':shared},function(categoryId){if(categoryId=='not-logged-in'){location.reload();return;}
var oldId=category.Id;category.Id=categoryId;self.fire('category-id-update',[oldId,categoryId]);category.locked=false;self.fire('category-unlock',[category,false]);},'json');return category;},edit:function(category,changes){var self=this;category.locked=true;if(typeof changes.name!='undefined')
category.name=changes.name;if(typeof changes.color!='undefined')
category.color=changes.color;if(typeof changes.shared!='undefined')
category.shared=changes.shared;this.fire('category-lock',[category,true]);$.post('/api/request/?c=category.edit',{'Id':category.Id,'name':category.name,'color':category.color.substr(1),'shared':category.shared},function(r){if(r=='not-logged-in'){location.reload();return;}
category.locked=false;self.fire('category-edit',[category,changes]);self.fire('category-unlock',[category,false]);},'json');},remove:function(category){var self=this;category.locked=true;this.fire('category-lock',[category,true]);$.post('/api/request/?c=category.remove',{'Id':category.Id},function(r){if(r=='not-logged-in'){location.reload();return;}
self.categories.splice(self.categories.indexOf(category),1);self.fire('category-remove',[category]);},'json');},toggle:function(item,visible){item.visible=visible;item.locked=true;this.fire('item-lock',[item,true]);var self=this;if(this.itemIsSubscription(item)){$.post('/api/request/?c=subscription.toggle',{'type':item.Id[0],'Id':item.Id[1],'visible':item.visible},function(){item.locked=false;self.fire(visible?'item-show':'item-hide',[item,visible]);self.fire('item-unlock',[item,false]);},'json');}else{$.post('/api/request/?c=category.toggle',{'Id':item.Id,'visible':item.visible},function(r){if(r=='not-logged-in'){location.reload();return;}
item.locked=false;self.fire(visible?'item-show':'item-hide',[item,visible]);self.fire('item-unlock',[item,false]);},'json');}},__load:function(){var self=this;$.post('/api/request/?c=category.load',{},function(data){if(data=='not-logged-in'){location.reload();return;}
self.categories.splice(1);self.subscriptions.splice(0);$.each(data.c,function(){self.categories.push({'Id':this[0],'name':this[1],'color':'#'+this[2],'visible':this[3],'shared':this[4],'locked':false});});$.each(data.s,function(){self.subscriptions.push({'Id':this[0],'name':this[2],'visible':this[1],'locked':false});});self.categories.sort(function(a,b){return a.Id<b.Id?-1:a.Id==b.Id?0:1;});self.subscriptions.sort(function(a,b){return a.Id[1]<b.Id[1]?-1:a.Id[1]==b.Id[1]?0:1;});self.fire('load',[self.categories,self.subscriptions]);},'json');}},true);})(jQuery);
;
(function($){Parser=function(rules){this.rules=rules;}
Parser.prototype.start=function(text){this.text=text;this.done=false;return this.nextSymbol();}
Parser.prototype.isDone=function(){return this.done&&this.symbol==null;}
Parser.prototype.nextSymbol=function(){var p=this,best,bestSymbol;this.symbol=null;this.value=null;do{if(this.done){return false;}
best=null;$.each(this.rules,function(name,rule){var match;if(match=rule.exec(p.text)){if(best==null||match[0].length>best[0].length){best=match;bestSymbol=name;}}});if(best!=null){this.text=this.text.substr(best[0].length);if(this.text==''){this.done=true;}}
if(best==null){this.done=true;this.symbol=null;this.value=null;return;}}while(bestSymbol=='SKIP');this.symbol=bestSymbol;this.value=best;return true;}
Parser.prototype.accept=function(name){if(this.symbol==name){if(this.value){var v=this.value;this.nextSymbol();return v;}
this.nextSymbol();return true;}
return false;}
Parser.prototype.expect=function(name){if(this.accept(name)){return true;}
throw'expected '+name+' but found '+this.symbol;}})(jQuery);
;
(function($){var adjustDialog=function(){var el=$(this);var options=el.data('options');var x,y;if(!options)
return;if(options.link){x=options.link.offset().left;y=options.link.offset().top;switch(options.alignment){case'top':x+=(options.link.outerWidth()-el.width())/2;y+=options.link.outerHeight()/2+20+options.offset;break;case'left':x+=options.link.outerWidth()/2+20+options.offset;y+=(options.link.outerHeight()-el.height())/2;break;case'right':x+=options.link.outerWidth()/2-(el.width()+20)-options.offset;y+=options.link.outerHeight()/2-el.height()/2;break;case'bottom':x+=(options.link.outerWidth()-el.width())/2;y+=options.link.outerHeight()/2-el.height()-20-options.offset;break;}
if(options.sideOffset){switch(options.alignment){case'top':case'bottom':x-=(options.sideOffset-0.5)*el.width();break;case'left':case'right':y-=(options.sideOffset-0.5)*el.height();break;}}
if(options.margin){if(y<options.margin[0])
y=options.margin[0];else if(y+el.height()+options.margin[3]>$(window).height())
y=$(window).height()-el.height()-options.margin[3];if(x<options.margin[1])
x=options.margin[1];else if(x+el.width()+options.margin[2]>$(window).width())
x=$(window).width()-el.width()-options.margin[2];}}else{x=options.center[0]||.5;y=options.center[1]||.5;if(x>=0&&x<=1)
x=(x*100)+'%';if(y>=0&&y<=1)
y=(y*100)+'%';};el.css({'left':x,'top':y});}
$(window).resize(function(){$('div.dialog').each(adjustDialog);});$(document.body).click(function(evt){var $t=$(evt.target);var parent=$t.parents('.dialog.click-outside-closes').eq(0);if(parent){$('.dialog.open.click-outside-closes').filter(function(){return parent.data('uid')!=$(this).eq(0).data('uid');}).each(function(){$(this).data('close')();});}else{$('.dialog.open').each(function(){$(this).data('close')();});}});var Dialog=function(content,options){options=options||{};this.el=$('<div class="dialog" style="display: none" />');this.el.data('uid',Math.random());this.el.append($(content));if(options.link){options.link=$(options.link);options.offset=options.offset||0;options.alignment=options.alignment||'top';var pointer=$('<div class="pointer '+options.alignment+'"/>');if(options.sideOffset){switch(options.alignment){case'left':case'right':pointer.css('top',(options.sideOffset*100)+'%');break;case'top':case'bottom':pointer.css('left',(options.sideOffset*100)+'%');break;}}
this.el.append(pointer)
this.el.addClass('pointed');}else{options.center=options.center||[.5,.5];}
if(typeof options.size=='object'){this.el.css({'width':options.size[0],'height':options.size[1]});}
if(options['class'])
this.el.addClass(options['class']);if(options.modal===true&&!options.link){this.modal=true;this.el.addClass('modal');var existingCurtain=$('#modal-curtain');if(existingCurtain.size()==0){var curtain=$('<div id="modal-curtain"/>');curtain.css({'display':'none','opacity':0.6});curtain.appendTo(document.body);}};if(options.clickOutsideCloses===true){this.el.addClass('click-outside-closes');}
this.el.data('close',this.close.bind(this));this.el.data('options',options);this.el.appendTo(document.body);this.adjust();}
Dialog.prototype.adjust=function(){var options=this.el.data('options');if(options.center){var x=options.center[0];var y=options.center[1];if(x>=0&&x<=1)
this.el.css('margin-left',-this.el.width()/2);if(y>=0&&y<=1)
this.el.css('margin-top',-this.el.height()/2)}
adjustDialog.call(this.el);}
Dialog.prototype.open=function(){if(this.modal)
$('#modal-curtain').show();this.el.fadeIn('def',(function(el){return function(){el.addClass('open');}})(this.el));}
Dialog.prototype.close=function(){var options=this.el.data('options');if(options.onClose)
options.onClose(this);if(options.modal)
$('#modal-curtain').hide();this.el.fadeOut('slow',(function(el){return function(){el.remove();}})(this.el));}
$.extend({dialog:function(el,options){return new Dialog(el,options);}});})(jQuery);
;
(function($){String.prototype.entityEncode=function(){return this.replace(/&/,'&amp;').replace(/</,'&lt;').replace(/>/,'&gt;');};Function.prototype.bind=function(binding){var self=this;return function(){return self.apply(binding,arguments);};};var Form=function(legend){this.params={};this.dialog=null;this.opened=false;this.labels={};this.elements={};this.validators={};this.failedValidators=[];this.mainElement=$(legend?'<form><fieldset><h1>'+legend.entityEncode()+'</h1><table/></fieldset></form>':'<form><fieldset><table/></fieldset></form>');this.mainElement.hide();this.mainElement.bind('submit',function(){return false;});this.mainElement.bind('keydown',function(e){e.stopPropagation();});this.mainElement.appendTo(document.body);this.elementsContainer=this.mainElement.find('table');this.tabIndex=0;};Form.fieldTypes={'checkbox':function(opts,index){var el=$('<input type="checkbox" />').attr({'tabindex':index,'checked':opts.checked||false});el._val=function(){return el.attr('checked');}
return el;},'text-parse':function(opts,index){var el=$('<input />').data('value',opts.value).attr({'tabindex':index,'value':opts.format(opts.value)});var format=function(val){if(val)return val.toString();return'No date set';}
var edit=function(val){if(val)return val.toString();return'';}
var parse=Date.parse;var value=null;var remember;el.focus(function(){var el=$(this);if(el.data('remember')){el.val(el.data('remember'));el.caret(0,el.val().length);}else if(opts.edit){el.val(opts.edit(el.data('value')));if(el.data('value'))
el.caret(0,el.val().length);else
el.caret(el.val().length);}else{el.val(opts.format(el.data('value')));if(el.data('value'))
el.caret(0,el.val().length);}});el.blur(function(){var el=$(this);if(!el.val()){el.data('value',null);}else{var replace;if(replace=opts.parse(el.val())){el.data('value',replace);el.effect('highlight',{color:'#c9ff9a'});}else
el.effect('highlight',{color:'#ff849c'});}
el.data('remember',el.val());el.val(opts.format(el.data('value')));});return el;},'date-range':function(opts,index){var start=$.dateInput(opts.start.clone(),opts.hasTime);var end=$.dateInput(opts.hasTime?opts.start.plus(opts.duration):opts.start.plus(opts.duration).minus('P1D'),opts.hasTime);start.blur(function(){end.setDate(allDay.attr('checked')?start.getDate().plus(end.data('value')).minus('P1D'):start.getDate().plus(end.data('value')));});start.attr('tabindex',index).data('value',function(){return start.getDate()});end.change(function(){if(end.getDate().isBefore(start.getDate().plus('PT15M'))){end.setDate(start.getDate().plus('PT15M'));}
if(!allDay.attr('checked')&&end.getDate()>=start.getDate().next().day().clearTime()){allDay.attr('checked',true);allDay.change();}
if(allDay.attr('checked')){end.data('value',start.getDate().differenceTo(end.getDate().plus('P1D')));}else{end.data('value',start.getDate().differenceTo(end.getDate()));}})
end.attr('tabindex',index+1).data('value',opts.duration);var allDay=$('<input type="checkbox"/>').attr({'tabindex':index+2,'checked':!opts.hasTime})
allDay.click(function(){allDay.blur();allDay.change();});allDay.change(function(){if(allDay.attr('checked')){start.setHasTime(false);end.setHasTime(false);}else{start.setHasTime(true);end.setHasTime(true);if(start.getDate().getHours()==0&&start.getDate().getMinutes()==0){start.setDate(start.getDate().plus('PT8H'));}
if(end.getDate().isBefore(start.getDate().plus('PT1H'))){end.setDate(start.getDate().plus('PT1H'));}
if(start.getDate().getHours()==23&&start.getDate().getMinutes()!=0){end.setDate(start.getDate().set({hour:23,minute:59}));}
if(end.getDate()>=start.getDate().next().day().clearTime()){var ideal=start.getDate().set({hour:end.getDate().getHours(),minute:end.getDate().getMinutes()});if(ideal.isAfter(start.getDate()))
end.setDate(ideal);else end.setDate(start.getDate().plus('PT1H'));}}
if(allDay.attr('checked')){end.data('value',start.getDate().differenceTo(end.getDate().plus('P1D')));}else{end.data('value',start.getDate().differenceTo(end.getDate()));}});start.reset();end.reset();return[start,end,allDay];}}
Form.prototype={add:function(label,options){var row=$('<tr/>').appendTo(this.elementsContainer);var elems,container;if($.isArray(label)&&typeof options=='object'){var els=this._createElement(options);for(var i=0,l=label.length;i<l;i++){var name=options.name[i];var el=$('<tr><th><label/></th><td/></tr>').appendTo(this.elementsContainer);el.find('label').text(label[i]);el.find('td').append(els[i]);this.labels[name]=el.find('label');this.elements[name]=els[i];}}else if(typeof label=='object'&&!options){container=$('<div class="buttons"/>');container.appendTo($('<td colspan="2"/>').appendTo(row));$.each($.map(label,this._createElement.bind(this)),function(index,elem){elem.appendTo(container);}.bind(this));}else if(typeof options=='string'){$('<tr><th>'+'<label>'+label.entityEncode()+'</label>'+'</th>'+'<td class="text">'+options.entityEncode()+'</td></tr>').appendTo(this.elementsContainer);}else if(options instanceof jQuery){var el=$('<tr><th><label></label></th><td class="object"></td></tr>');el.find('label').text(label);el.find('td').append(options);el.appendTo(this.elementsContainer);}else{var id=(options.id||options.name);var elem=this._createElement(options);var header=$('<th><label for="'+id+'">'+label.entityEncode()+'</label></th>').appendTo(row);this.labels[options.name]=header.find('label');this.elements[options.name]=elem;this.validators[options.name]=options.test;elem.appendTo($('<td/>').appendTo(row));};this.elementsContainer.find('.button .caption').ensureTextShadow();return this;},text:function(text){$('<tr><td colspan="2"><div class="text">'+text.entityEncode()+'</div></td></tr>').appendTo(this.elementsContainer);return this;},addDom:function(dom){($('<tr/>').append($('<td colspan="2"/>').css('text-align','left').append(dom))).appendTo(this.elementsContainer);return this;},set:function(key,value){this.params[key]=value;return this;},dom:function(){this.mainElement.show();return this.mainElement;},open:function(options){this.close();this.mainElement.show();this.dialog=this.dialog||$.dialog(this.mainElement,options);this.dialog.open();this.opened=true;return this;},close:function(){if(!this.dialog)
return false;this.dialog.close();this.opened=false;$(document).unbind('keyup',this._enterKeyHandler);return this;},empty:function(){this.params={};$.each(this.elements,function(i,e){e.removeAttr('value');});return this;},get:function(name){var elem=this.elements[name];if(elem._val)
return elem._val();return elem.val()||elem.data('value')||undefined;},getValues:function(){var values=$.merge(this.params,{});$.each(this.elements,function(n,e){values[n]=this.get(n)||'';}.bind(this));return values;},validate:function(name){var value=this.get(name);var validator=this.validators[name]||function(){return true};return value&&validator.call(value,this);},_createElement:function(options){var elem;options.id=options.id||options.name;switch(options.type){case'text':case'date':case'date-difference':case'password':elem=$('<input id="'+options.id+'" name="'+options.name+'" type="'+options.type+'" maxlength="'+options['max-length']+'"/>');if(options.value&&options.type!='date')
elem.val(options.value);if(options.type=='password'&&options.repeat){elem.push($('<input id="'+options.id+'_confirmation" name="'+options.name+'_confirmation" type="password"/>')[0]);elem.val=function(value){if(value||elem[0].value==elem[1].value)
return jQuery.fn.val.call(elem,value);};};if(options.type=='text'){elem.focus(function(){elem.caret(0,elem.val().length);});}
elem.attr('tabindex',++this.tabIndex);break;case'text-area':elem=$('<textarea id="'+options.id+'" name="'+options.name+'">'+options.value+'</textarea>');elem.attr('rows',options.rows||4);elem.attr('tabindex',++this.tabIndex);break;case'button':var caption=options.value.entityEncode();elem=$('<button>'+caption+'</button>');if(options['class'])
elem.addClass(options['class']);if($.browser.msie&&$.browser.version=='7.0')
elem.addClass('ie7');if(options['default'])
elem.addClass('default');if(options.action)
elem.bind('click',function(event){elem.blur();if(options.validator)
if(!options.validator())
return false;try{$.each(this.elements,function(){this.blur();});options.action(this,this.getValues());}catch(error){};return false;}.bind(this));if(options.enter){this._enterKeyHandler=function(event){if(!this.opened)
return false;if(options.validator)
options.validator();switch(event.keyCode){case 13:if(event.altKey)
return true;elem.click();return false;};}.bind(this);$(document).bind('keyup',this._enterKeyHandler);};elem.attr('tabindex',++this.tabIndex);break;case'cancel':options.type='button';options.value=options.value||"Cancel";options.action=function(form,fields){form.empty();form.close();};elem=this._createElement(options);break;case'submit':options.type='button';options.value=options.value||"Submit";options.enter=true;elem=this._createElement(options);if(options['use-require-icon'])
options.validationHandler=function(){$.each(this.labels,function(name,label){var op=($.inArray(name,this.failedValidators)==-1)?'remove':'add';this.labels[name][op+'Class']('validation-failed');}.bind(this));}.bind(this);if(options.require)
options.validator=function(){elem.addClass('disabled');this.failedValidators=[];$.each(options.require,function(index,name){if(!this.validate(name))
this.failedValidators.push(name);}.bind(this));if(options.validationHandler)
options.validationHandler();if(this.failedValidators.length>0)
return false;elem.removeClass('disabled');return true;}.bind(this);$.each(this.elements,function(n,e){if(e.hasClass('color-picker'))
e.children().bind('click',function(event){if(options.validator)
options.validator();}.bind(this));}.bind(this));elem.attr('tabindex',++this.tabIndex);if(options.validator)
options.validator();break;case'select':elem=$('<select id="'+options.id+'" name="'+options.name+'"></select>');$.each(options.options,function(index,option){var e;if(typeof option=='string'){e=$('<option value="'+index+'">'+option.entityEncode()+'</option>');if(options['default']==index)
e.attr('selected',true);}else if(typeof option=='object'){e=$('<option value="'+option.Id+'">'+option.name.entityEncode()+'</option>');if(options['default']==option.Id)
e.attr('selected',true);if(option.color)
e.css('background-color',option.color);}else return;e.appendTo(elem);});elem.attr('tabindex',++this.tabIndex);break;case'color-picker':elem=$('<div class="color-picker"/>').data('name',options.name);if(options.value)
elem.data('value',options.value);if(options.value&&$.inArray(options.value,options.colors)==-1)
options.colors.push(options.value);$.each(options.colors||[],function(index,color){var e=$('<a class="color" href="#"/>').appendTo(elem);e.bind('click',function(event){e.blur();elem.data('value',color);elem.find('.selected').removeClass('selected');e.addClass('selected');return false;});if(options.value==color)
e.addClass('selected');e.css('background-color',color);});break;case'text-parse':case'date-range':case'checkbox':var elem=Form.fieldTypes[options.type](options,++this.tabIndex);if($.isArray(elem)){$.each(elem,function(){var el=this;el._val=function(){var v=el.data('value');if(typeof v=='function')
return v();return v;}});}else if(!elem._val){elem._val=function(){var v=elem.data('value');if(typeof v=='function')
return v();return v;}}
if($.isArray(elem)){this.tabIndex+=elem.length-1;}
break;};return elem;}};$.extend({form:function(legend){return new Form(legend);}});$.fn.extend({ensureTextShadow:function(klass){if(($.browser.opera&&$.browser.version>='9.50')||($.browser.safari&&$.browser.version>='100')||($.browser.mozilla&&$.browser.version>='1.9.1'))
return false;$.each($.map(this,$),function(index,parent){var elem=$('<span class="'+(klass||'shadow')+'">'+this.text()+'</span>').appendTo(this);var shadowColor=elem.css('color');elem.css('color',this.css('color'));this.css('color',shadowColor);this.parent().css('paddingTop',(parseInt(this.parent().css('paddingTop'))+1)+'px');});return this;}});})(jQuery);
;
(function($){$.fn.extend({caret:function(begin,end){if(this.length==0)return;if(typeof begin=='number'){end=(typeof end=='number')?end:begin;return this.each(function(){if(this.setSelectionRange){this.focus();this.setSelectionRange(begin,end);}else if(this.createTextRange){var range=this.createTextRange();range.collapse(true);range.moveEnd('character',end);range.moveStart('character',begin);range.select();}});}else{if(this[0].setSelectionRange){begin=this[0].selectionStart;end=this[0].selectionEnd;}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();begin=0-range.duplicate().moveStart('character',-100000);end=begin+range.text.length;}
return{begin:begin,end:end};}}});$.extend({'dateInput':function(value,hasTime){var input=$('<input/>');var iPhone=(window.orientation!=undefined);var field=function(n,v){if(typeof n=='undefined'){var pos=input.caret();if(pos.begin<2)
return 1;else if(pos.begin<5)
return 2;else if(pos.begin<11)
return 3;else if(pos.begin<13)
return 4;else if(pos.begin<17)
return 5;}else if(typeof v=='undefined')switch(n){case'reset':input.val(hasTime?value.toString('dd/MM/yyyy HH:mm'):value.toString('dd/MM/yyyy'));return;case 1:input.caret(0,2);return;case 2:input.caret(3,5);return;case 3:input.caret(6,10);return;case 4:if(hasTime)
input.caret(11,13);else if(input.attr('tabindex')){var next=$('[tabindex='+(parseInt(input.attr('tabindex'))+1)+']').eq(0).focus();if(!next.attr('type')||next.attr('type')=='text')
next.caret(0,2);}
return;case 5:if(hasTime)
input.caret(14,16);return;case 6:if(input.attr('tabindex')){var next=$('[tabindex='+(parseInt(input.attr('tabindex'))+1)+']').eq(0).focus();if(!next.attr('type')||next.attr('type')=='text')
next.caret(11,13);}}else{switch(n){case 1:try{Date.validateDay(v,value.getFullYear(),value.getMonth());value.setDate(v);}catch(e){return false;}
break;case 2:try{Date.validateMonth(v);value.setMonth(v,Math.min(Date.getDaysInMonth(value.getFullYear(),v),value.getDate()));}catch(e){return false;}
break;case 3:if(v>=1970&&v<2038){value.setYear(v,value.getMonth(),Math.min(Date.getDaysInMonth(value.getFullYear(),value.getMonth()),value.getDate()));}else{return false;}
break;case 4:try{Date.validateHour(v);value.setHours(v);}catch(e){return false;}
break;case 5:try{Date.validateMinute(v);value.setMinutes(v);}catch(e){return false;}
break;default:return;}
field('reset');field(n);return true;}}
field.DAY=1;field.MONTH=2;field.YEAR=3;field.HOUR=4;field.MINUTE=5;input.blur(function(){field('reset');input.change();})
input.bind('click dblclick',function(e){field(field());e.stopPropagation();})
input.bind('focus',function(e){field(field());e.stopPropagation();})
input.keydown(function(e){var k=e.charCode||e.keyCode||e.which;if((k>=63232&&k<=63235)||(k>=37&&k<=40)||k==9){e.preventDefault();var f=field();if(k==9||k==39||k==63235){field('reset');input.change();field(f+1);return false;}else if(k==37||k==63234){field('reset');input.change();field(f-1);return false;}
if(k==38||k==40||k==63232||k==63233){var m=(k==38||k==63232)?1:-1;switch(f){case field.DAY:var date=value.getDate()+m;field(field.DAY,date);field(field.DAY);break;case field.MONTH:var month=value.getMonth()+m;field(field.MONTH,month);field(field.MONTH);break;case field.YEAR:var year=value.getFullYear()+m;field(field.YEAR,year);field(field.YEAR);break;case field.HOUR:var time=value.getHours()+m;field(f,time);field(f);break;case field.MINUTE:var time=value.getMinutes()+m;field(f,time);field(f);break;}
return false;}}
if(k==8||k==46||(iPhone&&k==127)){return false;}else if(k==27){return false;}});input.keypress(function(e){e=e||window.event;var k=e.charCode||e.keyCode||e.which;var c=String.fromCharCode(k);var f=field();if(k==32||c=='/'||c==':'){field('reset');field(f+1);return false;}
if(e.ctrlKey||e.altKey||e.metaKey){return true;}else if((k>=32&&k<=125)||k>186){if(!/[0-9]/.test(c))
return false;switch(f){case field.DAY:var d=parseInt(c);var date=(value.getDate()*10+d)%100;if(!field(field.DAY,date)){field(field.DAY,d);}
break;case field.MONTH:var d=parseInt(c)-1;var month=(value.getMonth()+1)*10+d;if(!field(field.MONTH,month)){field(field.MONTH,d);}
break;case field.YEAR:var d=parseInt(c);var year=parseInt(input.val().substr(7,3)+c);if(!field(field.YEAR,year)){if(input.val().substr(6,1)!='0'){input.val(hasTime?value.toString('dd/MM/000'+d+' HH:mm'):value.toString('dd/MM/000'+d));}else{input.val(input.val().substr(0,6)+input.val().substr(7,3)+d+input.val().substr(10));}}
field(field.YEAR);break;case field.HOUR:var t=parseInt(c);var time=(value.getHours()*10+t)%100;if(!field(f,time)){field(f,t);}
break;case field.MINUTE:var t=parseInt(c);var time=(value.getMinutes()*10+t)%100;if(!field(f,time)){field(f,t);}
break;}}
return false;});input.setHasTime=function(val){hasTime=val;field('reset');}
input.startEditing=function(){field('reset')
field(field.DAY);}
input.reset=function(){field('reset');}
input.getDate=function(){return hasTime?value.clone():value.clone().clearTime();}
input.setDate=function(date){value.setTime(date.getTime());field('reset');}
return input;}});})(jQuery);
;
(function($){SharedSubscriptions=DUI.Class.create(Messaging.prototype,{listeners:{},sharedSubscriptions:[],subscriptions:[],itemIsSubscription:function(item){return $.isArray(item.Id);},find:function(sharedSubscriptionId){var i=0,j=this.sharedSubscriptions.length-1;var k;do{k=Math.floor((i+j)/2);if(sharedSubscriptionId>this.sharedSubscriptions[k].Id)
i=k+1;else if(sharedSubscriptionId==this.sharedSubscriptions[k].Id)
return this.sharedSubscriptions[k];else
j=k-1;}while(i<=j);return false;},create:function(categoryId,calendarId,displayname){var self=this;var sharedSubscription={'Id':Math.floor(Math.random()*1000000),'calendarId':calendarId,'categoryId':categoryId,'visible':true,'locked':true,'displayname':displayname};this.fire('shared-add',[sharedSubscription]);this.sharedSubscriptions.push(sharedSubscription);$.post('/api/request/?c=shared.create',{'categoryId':categoryId},function(sharedSubscriptionId){if(sharedSubscriptionId=='not-logged-in'){location.reload();return;}
var oldId=sharedSubscription.Id;sharedSubscription.Id=sharedSubscriptionId;self.fire('shared-id-update',[oldId,sharedSubscriptionId]);sharedSubscription.locked=false;self.fire('shared-unlock',[sharedSubscription,false]);},'json');return sharedSubscription;},remove:function(sharedSubscription){var self=this;sharedSubscription.locked=true;this.fire('shared-lock',[sharedSubscription,true]);$.post('/api/request/?c=shared.remove',{'Id':sharedSubscription.Id},function(r){if(r=='not-logged-in'){location.reload();return;}
self.sharedSubscriptions.splice(self.sharedSubscriptions.indexOf(sharedSubscription),1);self.fire('shared-remove',[sharedSubscription]);},'json');},toggle:function(item,visible){item.visible=visible;item.locked=true;this.fire('item-lock',[item,true]);var self=this;$.post('/api/request/?c=shared.toggle',{'Id':item.Id,'visible':item.visible},function(r){if(r=='not-logged-in'){location.reload();return;}
item.locked=false;self.fire(visible?'item-show':'item-hide',[item,visible]);self.fire('item-unlock',[item,false]);},'json');},__load:function(){var self=this;$.post('/api/request/?c=shared.load',{},function(data){if(data=='not-logged-in'){location.reload();return;}
self.sharedSubscriptions.splice(0);$.each(data,function(){self.sharedSubscriptions.push({'Id':this[0],'categoryId':this[1],'calendarId':this[2],'visible':this[3],'locked':false,'displayname':this[4]});});self.sharedSubscriptions.sort(function(a,b){return a.Id<b.Id?-1:a.Id==b.Id?0:1;});self.fire('load',[self.sharedSubscriptions]);},'json');}},true);})(jQuery);
;
(function($){function generateId(fieldId,choiceId){return fieldId+'_'+choiceId.replace(/[^A-Za-z0-9]/g,'');}
function textCutOff(text){var length=50;if(text.length>50)return text.substr(0,length-3)+"...";else return text;}
SubscriptionSelector=DUI.Class.create({institutionId:-1,fieldId:-1,redirectUrl:'',choices:{},subchoices:{},subchoicesType:{},choiceMode:null,selectedChoices:[],selectedSubchoices:{},init:function(element,institutionId,fieldId,redirectUrl){this.redirectUrl=redirectUrl;this.element=element;this.element.find('.throbber, input[type="text"], input[type="search"], select').hide();this.element.find('.choice_mode_tab').bind('click',function(event){this.setChoiceMode($(event.target).attr('class').split(' ')[0]);return false;}.bind(this));this.element.find('#collapsedSelection').hide();this.institutionsThrobber=this.element.find('#institutions .throbber');this.institutionsSelect=this.element.find('#institutions select');this.institutionsSelect.bind('change',this.__selectInstitution.bind(this));this.institutionsSelect.bind('change',this.expandSelection.bind(this));this.fieldsThrobber=this.element.find('#fields .throbber');this.fieldsSelect=this.element.find('#fields select');this.fieldsSelect.bind('change',this.__selectField.bind(this));this.choicesThrobber=this.element.find('#choices .throbber');this.choicesSelect=this.element.find('#choices select');this.choicesSelect.bind('change',this.__selectChoice.bind(this));this.choicesSelectOptions=[];this.choicesSearch=this.element.find('#choices #choiceSearch');this.choicesSearch.bind('keyup',this.__filterChoicesList.bind(this));this.choicesSearch.bind('change',this.__filterChoicesList.bind(this));this.choicesSearch.bind('focus',function(){$(this).select()});this.chosensList=this.element.find('#chosensContent > ul');this.nextButton=this.element.find('input[type="button"]');this.nextButton.bind('click',this.__createUser.bind(this));this.setChoiceMode('classes');this.__loadInstitutions();if(institutionId>0){this.institutionId=institutionId;this.element.find('#collapsedSelection').fadeIn();this.__loadFields(institutionId);}
if(fieldId>0){this.fieldId=fieldId;this.__loadChoices(fieldId);}},expandSelection:function(){this.element.find('#studentFrontPicture').hide();this.element.find('#collapsedSelection').fadeIn();},setChoiceMode:function(mode){this.choiceMode=mode;this.element.find('.choice_mode_tab').removeClass('selected');this.element.find('.choice_mode_tab.'+mode).addClass('selected');if(this.currentFieldId)
this.__loadChoices(this.currentFieldId);},__selectInstitution:function(event){var institutionId=$(event.target).val();this.setChoiceMode($(":selected",this.institutionsSelect).data('default_selection'));this.institutionId=institutionId;this.__loadFields(institutionId);},__selectField:function(event){var fieldId=$(event.target).val();this.fieldId=fieldId;this.__loadChoices(fieldId);},__selectChoice:function(event){var choiceId=$(event.target).val();if(choiceId==null){return false;}
this.choicesSelect.val(-1);if($.inArray(choiceId,this.selectedChoices)!=-1)
return false;var listItem=$('<li id="choice-'+choiceId+'"/>');listItem.data('name',this.choices[choiceId]);listItem.data('instname',$(":selected",this.institutionsSelect).data('name'));var heading=$('<div class="choiseHeading"><h4>'+textCutOff(this.choices[choiceId])+'</h4></div>');heading.appendTo(listItem);var removalAnchor=$('<a href="#">'+ss.i18n._t('EntrancePage.REMOVE')+'</a>');removalAnchor.bind('click',function(event){this.selectedChoices=$.grep(this.selectedChoices,function(v){return v!=choiceId;});this.chosensList.find('li#choice-'+choiceId).fadeOut();return false;}.bind(this));removalAnchor.appendTo(heading);var throbber=$('<img src="/themes/onecalendar/images/spinner.gif" alt="'+ss.i18n._t('Editbox.LOADING')+'" title="'+ss.i18n._t('Editbox.LOADING')+' …" class="throbber"/>');throbber.appendTo(listItem);var subchoicesList=$('<ul class="subchoices"/>');subchoicesList.appendTo(listItem);this.chosensList.append(listItem);this.selectedChoices.push(choiceId);this.__loadSubchoices(choiceId);},__filterChoicesList:function(event){var query=$(event.target).val();$.each(this.choicesSelectOptions,function(index,elem){elem=$(elem);if(elem.text().match(new RegExp(query,'i')))
elem.appendTo(this.choicesSelect);else
elem.remove();}.bind(this));},__loadInstitutions:function(){this.institutionsSelect.hide();this.institutionsThrobber.show();$.post('/api/request/?c=institutions.list',{},function(response){this.institutionsThrobber.hide();this.institutionsSelect.empty();this.institutionsSelect.append($('<option selected>'+ss.i18n._t('EntrancePage.CHOOSE')+'...</option>'));$.each(response,function(i,o){var instItem=$('<option value="'+o.Id+'">'+o.name+'</option>');instItem.data('default_selection',o.default_selection);instItem.data('name',o.name);this.institutionsSelect.append(instItem);}.bind(this));this.institutionsSelect.show();if(this.institutionId>0){this.institutionsSelect.val(this.institutionId);}}.bind(this),'json');},__loadFields:function(institutionId){this.fieldsSelect.hide();this.fieldsThrobber.show();$.post('/api/request/?c=fields.list',{Id:institutionId},function(response){this.fieldsThrobber.hide();this.fieldsSelect.empty();this.fieldsSelect.append($('<option selected>'+ss.i18n._t('EntrancePage.CHOOSE')+'...</option>'));$.each(response,function(i,o){this.fieldsSelect.append($('<option value="'+o.Id+'">'+o.name+'</option>'));}.bind(this));this.fieldsSelect.show();if(this.fieldId>0){this.fieldsSelect.val(this.fieldId);}}.bind(this),'json');},__loadChoices:function(fieldId){this.currentFieldId=fieldId;this.choicesSelect.hide();this.choicesThrobber.show();$.post('/api/request/?c='+this.choiceMode+'.listbyfield',{FieldId:fieldId},function(response){this.choices={};this.choicesThrobber.hide();this.choicesSelect.empty();this.choicesSelectOptions=[];$.each(response,function(i,o){switch(this.choiceMode){case'courses':var option=$('<option value="'+o.Id+'">'+textCutOff(o.name)+'</option>');this.choices[o.Id]=o.name;break;case'classes':var id=generateId(fieldId,o);var option=$('<option value="'+id+'">'+textCutOff(o)+'</option>');this.choices[id]=o;break;};this.choicesSelect.append(option);this.choicesSelectOptions.push(option);}.bind(this));this.choicesSelect.show();this.choicesSearch.show();}.bind(this),'json');},__loadSubchoices:function(choiceId){var choiceElem=this.chosensList.find('li#choice-'+choiceId);var subchoicesList=choiceElem.find('ul.subchoices');var selected=true;var selectedClass="checked"
var diselectedClass="unselected";if(this.choiceMode=="courses"){selected=false;}
switch(this.choiceMode){case'courses':var op='classes.listbycourse';var opts={CourseId:choiceId};choiceElem.data('name',this.choices[choiceId]);break;case'classes':var op='courses.listbyclass';var opts={ClassName:this.choices[choiceId],FieldId:this.fieldsSelect.val()};break;};$.post('/api/request/?c='+op,opts,function(response){if(this.choiceMode=='classes'){this.subchoices[choiceId]=new Array();}else{var self=this;$.each(response,function(i,n){self.subchoices[choiceId]=new Array();self.subchoices[choiceId][i]={selected:n,deselected:''};})}
this.subchoicesType[choiceId]=this.choiceMode;var self=this;choiceElem.find('.throbber').hide();var oddEven="even";$.each(response,function(i,n){oddEven=(oddEven=="even")?"odd":"even";var listItem=$('<li/>').data('id',n).addClass(oddEven).appendTo(subchoicesList);var anchor=$('<a href="#"><span class="textItem">'+textCutOff(n)+'</span></a>').appendTo(listItem);anchor.append('<span class="select"></span>');if(selected)anchor.find('.select').addClass(selectedClass);else anchor.css('selected','false');anchor.bind('click',function(event){var id=$(event.target).parent().data('id');if(id==undefined){id=$(event.target).parent().parent().data('id');var current=$(event.target).parent();}else{var current=$(event.target);}
var refChoiceId=choiceId;var num=i;if(current.css('selected')=='false'){current.css('selected','true');current.find('.select').addClass(selectedClass);self.subchoices[refChoiceId][num]={selected:'',deselected:current.text()};}else{current.css('selected','false');current.find('.select').removeClass(selectedClass);self.subchoices[refChoiceId][num]={selected:current.text(),deselected:''};}
return false;}.bind(this));}.bind(this));}.bind(this),'json');},__createUser:function(event){var names=[],queries=[];var self=this;$.each(this.selectedChoices,function(i,value){choiceId=self.subchoices[value];index=value;var className="";var typeName="";var instname=$('#choice-'+index).data('instname');var name=$('#choice-'+index).data('name');var string="inst:\""+instname+"\" and ";var strBuilder="";if(self.subchoicesType[index]=="classes"){className="class";typeName="course";string+=className+":\""+name+"\"";names.push(name);if(choiceId!=undefined){for(var i=0;i<choiceId.length;i++){if(choiceId[i]!=undefined&&choiceId[i]['selected']!=''&&choiceId[i]['selected'].length>0){strBuilder+=typeName+":\""+choiceId[i]['selected']+"\"";if(choiceId[(i+1)]!=undefined&&choiceId[(i+1)]['selected']!=''){strBuilder+=" or ";}}}}}else{className="course";typeName="class";names.push(name);string+=className+":\""+name+"\"";if(choiceId!=undefined){for(var i=0;i<choiceId.length;i++){if(choiceId[i]!=undefined&&choiceId[i]['deselected']!=''&&choiceId[i]['deselected'].length>0){strBuilder+=typeName+":\""+choiceId[i]['deselected']+"\"";if(choiceId[(i+1)]!=undefined&&choiceId[(i+1)]['deselected']!=''){strBuilder+=" or ";}}}}}
if(strBuilder!=''){if(self.subchoicesType[index]=="classes"){string+=" and not (";}else{string+=" and (";}
string+=strBuilder;string+=")";}
queries.push(string);});var nextButton=this.nextButton;var redirectUrl=this.redirectUrl;var url='';if(nextButton.attr('id')=='save-button'){url='/api/request/?c=subscription.addSearch';}else{url='/'+profileurl+'/tempuser';}
$.post(url,{'subscriptionNames[]':names,'subscriptionQueries[]':queries,'institutionId':this.institutionId,'fieldId':this.fieldId},function(response){if(response==true){if(nextButton.attr('id')=='save-button'){location.href=redirectUrl;}else{if(self.element.find('#studentRegisterInput').attr('checked')){location.href='/'+calendarurl+'#register';}else{location.href='/'+calendarurl;}}}},'json');}},true);})(jQuery);
;
function updateAdblock(url,id){jQuery.post("/api/request/?c=ads.adblock",{url:url,id:id},function(data){$('.adblock_'+id).html(data);});}
;
function RegistrationForm(){if(User_registered==1){location.href="/"+ss.i18n._t('registration.js.PROFILE');return false;}
$.form(ss.i18n._t('registration.js.REGISTER')).add(ss.i18n._t('uil.FIRST_NAME'),{type:'text',name:'FirstName'}).add(ss.i18n._t('uil.SURNAME'),{type:'text',name:'Surname'}).add(ss.i18n._t('uil.EMAIL'),{type:'text',name:'Email'}).add(ss.i18n._t('uil.PASSWORD'),{type:'password',name:'Password',repeat:true,test:function(){return this.length>3}}).add([{type:'submit','class':'big',value:ss.i18n._t('uil.CONTINUE'),require:['FirstName','Surname','Email','Password'],'use-require-icon':true,action:function(form,fields){$.post('/user/doregister',{FirstName:fields.FirstName,Surname:fields.Surname,Email:fields.Email,Password:fields.Password,locale:ss.i18n.currentLocale},function(response){if(response==true){var link=$("a#registerlink");$("#registerlink span.text").html(ss.i18n._t('registration.js.PROFILE'));link.addClass("current");link.parent().hide();link.parent().show("slow",function callback(){link.removeClass("current");});User_registered=1;form.close();}else{$("#registrationform_error").remove();$(".registrationbox").prepend('<div id="registrationform_error" style="padding:5px;color:red;font-weight:bold;">'+response.error+'</div>');$("#"+response.id).effect("highlight",{color:'red'},2500);}},'json');}},{type:'cancel',value:ss.i18n._t('uil.CLOSE')}]).open({'class':'registrationbox',center:[.5,.5],modal:true});}
(function($){$(function(){if(location.href.indexOf('#register')!=-1){RegistrationForm();}
$("#registerlink").click(function(){RegistrationForm();});});})(jQuery);
;
(function($){$(function(){$("#slct_lang").change(function(event){var title=this.options[this.selectedIndex].text;var link=this.options[this.selectedIndex].value;if(link!=""){location.href=link;}});});})(jQuery);
;