<?xml version="1.0" encoding="UTF-8"?>
<!--
 -
 -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2018 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<v:page name="calendar" decor="template/template.vspx" style="template/template.xsl" fast-render="1" button-anchors="1" xmlns:v="http://www.openlinksw.com/vspx/" xmlns:vm="http://www.openlinksw.com/vspx/macro" doctype="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <v:method name="sortColumn" arglist="in columnLabel varchar, in columnName varchar, in sortField varchar, in sortOrder varchar, in sortDirection varchar, in columnProperties varchar">
    <![CDATA[
      declare image, onclick any;

      image := '';
      onclick := sprintf ('onclick="javascript: odsPost(this, [\'%s\', \'%s\']);"', sortField, columnName);
      if (sortOrder = columnName)
      {
        if (sortDirection = 'desc')
        {
          image := '&nbsp;<img src="/ods/images/icons/orderdown_16.png" border="0" alt="Down"/>';
        }
        else if (sortDirection = 'asc')
        {
          image := '&nbsp;<img src="/ods/images/icons/orderup_16.png" border="0" alt="Up"/>';
        }
      }
      http (sprintf ('<th %s %s>%s%s</th>', columnProperties, onclick, columnLabel, image));
    ]]>
  </v:method>

  <v:method name="sortChange" arglist="in columnName varchar, in sortOrder varchar, in sortDirection varchar, inout ds vspx_data_set">
    <![CDATA[
      if (is_empty_or_null (columnName))
        return;

      ds.vc_reset ();
      if (udt_get (self, sortOrder) = columnName)
      {
        udt_set (self, sortDirection, either (equ (udt_get (self, sortDirection), 'asc'), 'desc', 'asc'));
      } else {
        udt_set (self, sortDirection, 'asc');
      }
      udt_set (self, sortOrder, columnName);
    ]]>
  </v:method>

  <v:method name="columnHeaderShow" arglist="in columnLabel varchar, in columnName varchar, in sortField varchar, in sortOrder varchar, in sortDirection varchar, in settingsName varchar, in defaultVisible integer, in isSortable integer, in columnProperties varchar">
    <![CDATA[
      if (not cast (get_keyword (settingsName, self.settings, defaultVisible) as integer))
        return;

      if (isSortable = 1)
      {
        self.sortColumn (columnLabel, columnName, sortField, sortOrder, sortDirection, columnProperties);
      } else {
        http (sprintf ('<th nowrap="nowrap" %s>%s</th>', columnProperties, columnLabel));
      }
    ]]>
  </v:method>

  <v:method name="columnEnabled" arglist="in columnVisibleName varchar, in defaultVisible integer">
    <![CDATA[
      return cast (get_keyword (columnVisibleName, self.settings, defaultVisible) as integer);
    ]]>
  </v:method>

  <v:method name="actionTest" arglist="">
    <![CDATA[
      declare tmp, params, permissions any;

      params := self.vc_page.vc_event.ve_params;
      tmp := get_keyword ('id', params, '');
      if (tmp <> '')
      {
        self.v_id := cast (tmp as integer);
        if (self.v_id <> -1)
        {
          permissions := CAL.WA.event_rights (self.domain_id, self.v_id, self.account_rights);
          if (permissions = 'W')
          {
          self.cAction := 'edit';
          }
          else if (permissions = 'R')
          {
            self.cAction := 'view';
          }
          self.cSubAction := CAL.WA.event_kind (self.v_id);
          if ((self.cSubAction = 'event') and (self.cScope not in ('tasks', 'search')))
            self.cScope := 'events';
          if (self.cSubAction = 'task')
            self.cScope := 'tasks';
        }
      }

      tmp := get_keyword ('search', params, get_keyword ('q', params, ''));
      if (tmp <> '')
      {
        self.cScope := 'search';
        self.cSearch := null;
        CAL.WA.xml_set ('keywords', self.cSearch, tmp);
        tmp := get_keyword ('mode', params, 'browse');
        if (tmp = 'advanced')
          CAL.WA.xml_set('mode', self.cSearch, 'advanced');
        self.cAction := tmp;
      }

      tmp := get_keyword ('URI', params, '');
      if (tmp <> '')
      {
        self.vc_page.vc_event.ve_params := CAL.WA.set_keyword ('f_uri', params, tmp);
        self.cScope := 'events';
        self.cAction := 'import';
        self.icSource := 2;
        self.v_tags := '';
        self.icUser := '';
        self.icPassword := '';
        self.icSync := 1;
        self.icAttendees := 2;
      }
      tmp := get_keyword ('action', params, '');
      if (tmp <> '')
        self.cAction := tmp;
    ]]>
  </v:method>

  <v:method name="initData" arglist="">
    <![CDATA[
      self.cShowTasks := CAL.WA.settings_showTasks (self.settings);
      self.cPrivacy := case when CAL.WA.access_is_write (self.account_rights) then 0 else 1 end;
      if (isnull (self.cScope))
        self.cScope := CAL.WA.settings_defaultView (self.settings);
      if (isnull (self.cDay))
        self.cDay := CAL.WA.dt_curdate (self.cTimeZone);
      if (isnull (self.cMonth))
      {
        self.cMonth := CAL.WA.dt_BeginOfMonth (self.cDay);
        self.cnMonth := self.cMonth;
      }
      if (isnull (self.cnMonth))
        self.cnMonth := self.cMonth;
      if (self.cScope = 'day')
      {
        self.cStart := self.cDay;
        self.cEnd := self.cDay;
      }
      if (self.cScope = 'week')
      {
        self.cStart := cast (CAL.WA.dt_BeginOfWeek (self.cDay, self.cWeekStarts) as date);
        self.cEnd := cast (CAL.WA.dt_EndOfWeek (self.cDay, self.cWeekStarts) as date);
      }
      if (self.cScope = 'month')
      {
        self.cStart := cast (CAL.WA.dt_BeginOfWeek (CAL.WA.dt_BeginOfMonth (self.cDay), self.cWeekStarts) as date);
        self.cEnd := cast (CAL.WA.dt_EndOfWeek (CAL.WA.dt_EndOfMonth (self.cDay), self.cWeekStarts) as date);
      }
      self.cDays := self.initDays (self.cMonth);
      if (CAL.WA.dt_compare (self.cMonth, self.cnMonth))
      {
        self.cnDays := self.cDays;
      } else {
        self.cnDays := self.initDays (self.cnMonth);
      }
    ]]>
  </v:method>

  <v:method name="initDays" arglist="inout cMonth datetime">
    <![CDATA[
      declare N, M, wStart, wCount, mStart, mLastday, dStart integer;
      declare cDays any;

      wStart := CAL.WA.dt_WeekDay (cMonth, self.cWeekStarts);
      mLastday := CAL.WA.dt_LastdayOfMonth (cMonth);
      wCount := 4;
      if (wStart <> 1)
        wCount := wCount + 1;
      if (mLastday - 28 - (7 - wStart) > 0)
        wCount := wCount + 1;
      mStart := case when (wCount = 6 ) then 0 else 1 end;
      dStart := mStart * 7 + wStart - 1;

      cDays := make_array (49, 'any');
      M := CAL.WA.dt_LastdayOfMonth (dateadd ('day', -1, cMonth));
      for (N := dStart - 1; N >= 0 ; N := N - 1)
      {
        cDays[N] := -M;
        M := M - 1;
      }
      M := 1;
      for (N := dStart; N < dStart + mLastday; N := N + 1)
      {
        cDays[N] := M;
        M := M + 1;
      }
      M := 1;
      for (N := dStart + mLastday; N < 49; N := N + 1)
      {
        cDays[N] := -M;
        M := M + 1;
      }
      return cDays;
    ]]>
  </v:method>

  <v:method name="showTimeZone" arglist="inout fValue any">
    <![CDATA[
      return sprintf ('GMT %s%02d:00', case when cast (fValue as integer) < 0 then '-' else '+' end,  abs(cast (fValue as integer)));
    ]]>
  </v:method>

  <v:method name="showEvent" arglist="in _id integer, in e_event integer, in e_subject varchar, in e_start datetime, in e_end datetime, in e_repeat varchar, in e_repeat_offset integer, in e_reminder integer, in e_attendees integer, in e_continue varchar">
    <![CDATA[
      declare domain_id integer;
      declare onclick, showDelete, showAnnotate, color, S, T, R varchar;

        S := 'null';
        if (not isnull (e_repeat_offset))
          S := cast (e_repeat_offset as varchar);
      color := self.showEventColor (_id);
      showDelete := '';
      showAnnotate := '';
      if (CAL.WA.event_rights (self.domain_id, _id, self.account_rights) = 'W')
      {
        showDelete :=  sprintf ('<span id="d_%d_%s" onclick="eDelete(event, this, %s)">[<span class="EV_delete">X</span>]</span> ', _id, S, S);
        showAnnotate := sprintf ('<img border="0" width="11" height="11" title="Annotate" alt="Annotate" src="image/ann_16.gif" onclick="eAnnotea (event, %d, %d, %d);" /> ', _id, self.domain_id, self.account_id);
      }
      domain_id := (select E_DOMAIN_ID from CAL.WA.EVENTS where E_ID = _id);  
      onclick := '';
      if (not DB.DBA.is_empty_or_null (self.sid))
        onclick := 'onclick="javascript: eView(this);"';
      R := self.showEventSubjectTmp (_id, e_event, e_subject, e_repeat, e_reminder, e_attendees);
      if (e_event = 1)
      {
        T := sprintf ('<div id="e_%d_%s" class="EV vevent" typeof="sioct:EventCalendar" %s %s about="%V">%s%s%s<span style="display:none;">%s</span>%s</div>', _id, S, color, onclick, CAL.WA.event_sioc_iri (domain_id, _id), e_continue, showDelete, showAnnotate, self.prepareField (e_start, 'dtstart', null), R);
      } else {
        T := sprintf ('<div id="e_%d_%s" class="EV vevent" typeof="sioct:EventCalendar" %s %s about="%V">%s%s%s<span class="EV_time">%s-%s</span>%s</div>', _id, S, color, onclick, CAL.WA.event_sioc_iri (domain_id, _id), e_continue, showDelete, showAnnotate, self.prepareField (e_start, 'dtstart', CAL.WA.dt_timestring (e_start)), self.prepareField (e_end, 'dtend', CAL.WA.dt_timestring (e_end)), R);
      }
      return T;
    ]]>
  </v:method>

  <v:method name="showEventColor" arglist="in _id integer">
    <![CDATA[
      declare S varchar;

      S := CAL.WA.event_color (_id, self.domain_id);
      if (S = '#fafafa')
        return '';
      return sprintf ('style="background-color: %s;"', CAL.WA.event_color (_id, self.domain_id));
    ]]>
  </v:method>

  <v:method name="showEventDate" arglist="in eTime datetime, in eTimeProperty varchar, in eMode varchar, in eReversed varchar">
    <![CDATA[
      if (eMode = 'date')
        return self.prepareField (eTime, eTimeProperty, null);
      if (eMode = 'time')
        return self.prepareField (eTime, eTimeProperty, sprintf ('<span class="EVL_time">%s</span>', CAL.WA.dt_timestring (eTime, self.cTimeFormat)));
      if ((eMode = 'dateTime') and not eReversed)
        return self.prepareField (eTime, eTimeProperty, sprintf ('%s <span class="EVL_time">%s</span>', CAL.WA.dt_datestring (eTime, self.cDateFormat), CAL.WA.dt_timestring (eTime, self.cTimeFormat)));
      if ((eMode = 'dateTime') and eReversed)
        return self.prepareField (eTime, eTimeProperty, sprintf ('<span class="EVL_time">%s</span> %s', CAL.WA.dt_timestring (eTime, self.cTimeFormat), CAL.WA.dt_datestring (eTime, self.cDateFormat)));
      return '';
    ]]>
  </v:method>

  <v:method name="showTagEventDate" arglist="in eTime datetime, in eTimeString varchar">
    <![CDATA[
      return sprintf ('<span id="dt_%s" unselectable="on" onclick="eDate(this)" class="EVL EVL_duration">%s</span>', CAL.WA.dt_datestring (eTime, 'Y.M.D'), eTimeString);
    ]]>
  </v:method>

  <v:method name="showEventStart" arglist="in e_event integer, in e_time datetime, in e_timeProperty varchar">
    <![CDATA[
      if (isnull (e_time))
        return;

      e_time := CAL.WA.event_gmt2user (e_time, self.cTimezone, self.cDaylight);
      http (self.showTagEventDate (e_time, self.showEventDate (e_time, e_timeProperty, case when e_event = 1 then 'date' else 'dateTime' end, 0)));
    ]]>
  </v:method>

  <v:method name="showEventEnd" arglist="in e_event integer, in e_time datetime, in e_timeProperty varchar">
    <![CDATA[
      if (isnull (e_time))
        return;

      e_time := CAL.WA.event_gmt2user (e_time, self.cTimezone, self.cDaylight);
      http (self.showTagEventDate (e_time, self.showEventDate (e_time, e_timeProperty, case when e_event = 1 then 'date' else 'dateTime' end, 1)));
    ]]>
  </v:method>

  <v:method name="showEventDuration" arglist="in e_event integer, in e_start datetime, in e_end datetime">
    <![CDATA[
      declare S varchar;

      if (isnull (e_start))
        return self.showEventEnd (e_event, e_end, 'dtend');

      e_start := CAL.WA.event_gmt2user (e_start, self.cTimezone, self.cDaylight);
      e_end := CAL.WA.event_gmt2user (e_end, self.cTimezone, self.cDaylight);
      if (CAL.WA.dt_compare (e_start, e_end))
      {
        if (e_event = 1)
        {
          S := self.showEventDate (e_start, 'dtstart', 'date', 0);
        } else {
          S := self.showEventDate (e_start, 'dtstart', 'dateTime', 0);
          if (not isnull (e_end))
            S := sprintf ('%s - %s', S, self.showEventDate (e_end, 'dtend', 'time', 0));
        }
        http (self.showTagEventDate (e_start, S));
      } else {
        if (e_event = 1)
        {
          S := self.showTagEventDate (e_start, self.showEventDate (e_start, 'dtstart', 'date', 0));
          if (not isnull (e_end))
            S := sprintf ('%s - %s', S, self.showTagEventDate (e_end, self.showEventDate (e_end, 'dtend', 'date', 0)));
        } else {
          S := self.showTagEventDate (e_start, self.showEventDate (e_start, 'dtstart', 'dateTime', 0));
          if (not isnull (e_end))
            S := sprintf ('%s - %s', S, self.showTagEventDate (e_end, self.showEventDate (e_end, 'dtend', 'dateTime', 0)));
        }
        http (S);
      }
    ]]>
  </v:method>

  <v:method name="showEventSubjectTmp" arglist="in _id integer, in e_event integer, in e_subject varchar, in e_repeat varchar, in e_reminder varchar, in e_attendees integer">
    <![CDATA[
      declare domain_id integer;
      declare onclick varchar;
      
      domain_id := (select E_DOMAIN_ID from CAL.WA.EVENTS where E_ID = _id);  
      onclick := '';
      if (not DB.DBA.is_empty_or_null (self.sid))
        onclick := sprintf ('onclick="javascript: eView(\'e_%d\'); return false;"', _id);
      return sprintf ('<a id="e_%d" href="%s" %s class="EVL EVL_subject app" about="%V"> %s%s%s%s</a>', _id, CAL.WA.utf2wide (CAL.WA.event_sioc_iri (domain_id, _id)), onclick, CAL.WA.utf2wide (CAL.WA.event_sioc_iri(domain_id, _id)), self.repeatableImage (e_repeat), self.reminderImage (e_reminder), self.attendeesImage (e_attendees), self.prepareField (CAL.WA.show_subject (e_subject), 'summary', null));
    ]]>
  </v:method>

  <v:method name="showEventSubject" arglist="in _id integer, in e_event integer, in e_subject varchar, in e_repeat varchar, in e_reminder varchar, in e_attendees integer">
    <![CDATA[
      http (self.showEventSubjectTmp (_id, e_event, e_subject, e_repeat, e_reminder, e_attendees));
    ]]>
  </v:method>

  <v:method name="showContinue" arglist="in dt datetime, in e_event integer, in e_start datetime, in e_end datetime">
    <![CDATA[
      declare S varchar;

      S := '';
      dt := CAL.WA.dt_dateClear (dt);
      e_start := CAL.WA.dt_dateClear (e_start);
      e_end := CAL.WA.dt_dateClear (e_end);
      if (e_start < dt)
          S := '<img src="image/tr_close2.gif" border="0" />';
      if (e_end > dt)
        {
          if (S <> '')
          {
            S := '... ';
          } else {
            S := '<img src="image/tr_close.gif" border="0" />';
          }
        }
      return S;
    ]]>
  </v:method>

  <v:method name="repeatableImage" arglist="in eRepeat any">
    <![CDATA[
      if (is_empty_or_null (eRepeat))
        return '';
      return '<img border="0" width="11" height="11" title="Repeatable Event" alt="Repeatable Event" src="image/repeatable.gif" /> ';
    ]]>
  </v:method>

  <v:method name="reminderImage" arglist="in eReminder any">
    <![CDATA[
      if (coalesce (eReminder, -1) <= 0)
        return '';
      return '<img border="0" width="11" height="11" title="Has Reminder" alt="Has Reminder" src="image/reminder.gif" /> ';
    ]]>
  </v:method>

  <v:method name="attendeesImage" arglist="in eAttendees any">
    <![CDATA[
      if (coalesce (eAttendees, -1) <= 0)
        return '';
      return '<img border="0" width="11" height="11" title="Has Attendees" alt="Has Attendees" src="/ods/images/icons/group_16.png" /> ';
    ]]>
  </v:method>

  <v:method name="permaLink" arglist="in domain_id integer, in id integer">
    <![CDATA[
      return sprintf('<a href="%s" title="PermaLink" alt="PermaLink">(<img border="0" width="11" height="11" src="image/link.gif" />)</a>', CAL.WA.utf2wide (SIOC..calendar_event_iri(domain_id, id)));
    ]]>
  </v:method>

  <v:method name="calcDate" arglist="in N integer">
    <![CDATA[
      if (self.cDays [N] > 0)
        return cast (dateadd ('day', self.cDays [N] - 1, self.cMonth) as date);
      if ((self.cDays [N] < 0) and (N < 24))
        return cast (dateadd ('day', abs (self.cDays [N]) - 1, dateadd ('month', -1, self.cMonth)) as date);
      if ((self.cDays [N] < 0) and (N > 24))
        return cast (dateadd ('day', abs (self.cDays [N]) - 1, dateadd ('month', 1, self.cMonth)) as date);
    ]]>
  </v:method>

  <v:method name="nCalcDate" arglist="in N integer">
    <![CDATA[
      if (self.cnDays [N] > 0)
        return cast (dateadd ('day', self.cnDays [N] - 1, self.cnMonth) as date);
      if ((self.cnDays [N] < 0) and (N < 24))
        return cast (dateadd ('day', abs (self.cnDays [N]) - 1, dateadd ('month', -1, self.cnMonth)) as date);
      if ((self.cnDays [N] < 0) and (N > 24))
        return cast (dateadd ('day', abs (self.cnDays [N]) - 1, dateadd ('month', 1, self.cnMonth)) as date);
    ]]>
  </v:method>

  <v:method name="repeatParam" arglist="in eRepeat varchar, in cRepeat varchar, in cRepeatParam integer, in cRepeatIndex integer">
    <![CDATA[
      if (eRepeat = cRepeat)
      {
        if (eRepeat = 'D1')
        {
          if (cRepeatParam = 1)
            return self.v_repeatParam1;
        }
        else if (eRepeat = 'W1')
        {
          if (cRepeatParam = 1)
            return self.v_repeatParam1;
          if (cRepeatParam = 2)
            return bit_and (cast (self.v_repeatParam2 as integer), power (2, cRepeatIndex));
        }
        else if (eRepeat = 'M1')
        {
          if (cRepeatParam = 1)
            return self.v_repeatParam1;
          if (cRepeatParam = 2)
            return self.v_repeatParam2;
        }
        else if (eRepeat = 'M2')
        {
          if (cRepeatParam = 1)
            return self.v_repeatParam1;
          if (cRepeatParam = 2)
            return self.v_repeatParam2;
          if (cRepeatParam = 3)
            return self.v_repeatParam3;
        }
        else if (eRepeat = 'Y1')
        {
          if (cRepeatParam = 1)
            return self.v_repeatParam1;
          if (cRepeatParam = 2)
            return self.v_repeatParam2;
        }
        else if (eRepeat = 'Y2')
        {
          if (cRepeatParam = 1)
            return self.v_repeatParam1;
          if (cRepeatParam = 2)
            return self.v_repeatParam2;
          if (cRepeatParam = 3)
            return self.v_repeatParam3;
        }
      }
      return '';
    ]]>
  </v:method>

  <v:method name="singleObjectName" arglist="in objectsName any">
    <![CDATA[
      if (objectsName = 'events')
        return 'Event';
      if (objectsName = 'tasks')
        return 'Task';
      return '';
    ]]>
  </v:method>

  <v:method name="prepareField" arglist="inout fValue any, in fProperty varchar, in fShowValue any">
    <![CDATA[
      declare F, FS, T, P varchar;

      -- value
         if (is_empty_or_null (fValue))
         {
        F := ' ';
      }
      else if (fProperty = 'description')
          {
        F := sprintf ('<pre style="margin: 0; white-space: pre-wrap;">%V</pre>', cast (fValue as varchar));
      }
      else if (internal_type (fValue) = 211)
      {
        F := CAL.WA.dt_datestring (fValue, self.cDateFormat);
           }
      else
      {
        F := cast (fValue as varchar);
         }
      if (is_empty_or_null (fProperty))
        return F;

      FS := fShowValue;
      if (isnull (FS))
      {
        FS := F;
        if (fProperty <> 'description')
          FS := sprintf ('%V', FS);
      }

      P := '';
      -- vcalendar class
      if (not is_empty_or_null (fProperty))
        P := P || sprintf (' class="%s"', fProperty);

      -- vcalendar special values
      if (fProperty in ('dtstart', 'dtend', 'completed', 'created', 'last-modified'))
        P := P || sprintf (' title="%s"', substring (cast (fValue as varchar), 1, 10));

      -- dc properties
      if (fProperty = 'summary')
        P := P || ' property="dc:title"';

      -- tag
      T := 'span';
      if (fProperty = 'dtstart')
        T := 'abbr';
      if (fProperty = 'dtend')
        T := 'abbr';
      return sprintf ('<%s%s>%s</%s>', T, P, CAL.WA.utf2wide (FS), T);
    ]]>
  </v:method>

  <v:method name="viewField" arglist="inout fValue any, in fProperty varchar, in fShowValue any">
    <![CDATA[
      http (self.prepareField(fValue, fProperty, fShowValue));
    ]]>
  </v:method>

  <v:method name="viewTags" arglist="inout fValue any">
    <![CDATA[
        if (is_empty_or_null (fValue))
        {
          http ('&nbsp;');
        } else {
          declare N, L integer;
          declare delimiter varchar;
          declare tags any;

          delimiter := '';
          tags := CAL.WA.tags2vector (fValue);
          L := length (tags);
          for (N := 0; N < L; N := N + 1)
          {
            http (delimiter);
          http (sprintf ('<a href="%s">%s</a>', SIOC..tag_iri (CAL.WA.forum_iri (self.domain_id), tags[N]), tags[N]));
            delimiter := ', ';
          }
        }
    ]]>
  </v:method>

  <v:method name="arrays4Reminder" arglist="inout x any, inout y any">
    <![CDATA[
      x := make_array (14, 'any');
      x[0] := 'No reminder';
      x[1] := '5 minutes';
      x[2] := '10 minutes';
      x[3] := '15 minutes';
      x[4] := '20 minutes';
      x[5] := '25 minutes';
      x[6] := '30 minutes';
      x[7] := '45 minutes';
      x[8] := '1 hour';
      x[9] := '2 hours';
      x[10]:= '3 hours';
      x[11]:= '1 day';
      x[12]:= '2 days';
      x[13]:= '1 week';
      y:= make_array (14, 'any');
      y[0] := '-1';
      y[1] := '300';
      y[2] := '600';
      y[3] := '900';
      y[4] := '1200';
      y[5] := '1500';
      y[6] := '1800';
      y[7] := '2700';
      y[8] := '3600';
      y[9] := '7200';
      y[10]:= '10800';
      y[11]:= '86400';
      y[12]:= '172800';
      y[13]:= '604800';
    ]]>
  </v:method>

  <v:method name="shareNode" arglist="in event_id integer, in grants varchar, in override integer">
    <![CDATA[
      declare N, pos, id integer;
      declare name, V any;

      grants := replace(grants, ' ', '');
      grants := replace(grants, ',,', ',');
      grants := trim(grants, ',', '');
      grants := grants || ',';
      for (select U_ID, U_NAME from CAL.WA.EVENT_GRANTS, DB.DBA.SYS_USERS where G_GRANTER_ID = self.account_id and G_EVENT_ID = event_id and G_GRANTEE_ID = U_ID) do
      {
        name := U_NAME;
        id := U_ID;
        pos := strstr(grants, name || ',');
        if (isnull (pos))
        {
          if (override)
            delete from CAL.WA.EVENT_GRANTS where G_GRANTER_ID = self.account_id and G_GRANTEE_ID = id and G_EVENT_ID = event_id;
        } else {
          grants := replace (grants, name || ',', '');
        }
      }
      V := split_and_decode (trim (grants, ','), 0, '\0\0,');
      for (N := 0; N < length (V); N := N + 1)
      {
        id := (select U_ID from SYS_USERS where U_NAME = V[N]);
        if (not isnull(id))
          insert into CAL.WA.EVENT_GRANTS (G_GRANTER_ID, G_GRANTEE_ID, G_EVENT_ID)
            values(self.account_id, id, event_id);
      }
    ]]>
  </v:method>

  <v:method name="shareSelect" arglist="in event_id integer">
    <![CDATA[
      declare grants any;

      grants := '';
      for (select U_ID, U_NAME from CAL.WA.EVENT_GRANTS, DB.DBA.SYS_USERS where G_GRANTER_ID = CAL.WA.domain_owner_id (self.domain_id) and G_GRANTEE_ID = U_ID and G_EVENT_ID = event_id) do
        grants := grants || cast (U_NAME as varchar) || ',';
      return trim (grants, ',');
    ]]>
  </v:method>

  <v:method name="initNewEvent" arglist="">
    <![CDATA[
      declare pYear, pMonth, pDay, pHour, pMinute integer;

      self.v_id := -1;
      self.v_subject := '';
      self.v_description := '';
      self.v_location := '';
      self.v_privacy := CAL.WA.domain_is_public (self.domain_id);
      self.v_attendees := '';
      self.v_attendees_count := 0;
      self.v_tags := '';
      self.v_event := 0;
      if (isnull (self.on_date))
      {
        CAL.WA.dt_dateDecode (self.cDay, pYear, pMonth, pDay);
      } else {
        CAL.WA.dt_dateDecode (self.calcDate (self.on_date), pYear, pMonth, pDay);
      }
      if (isnull (self.on_time)) {
        CAL.WA.dt_timeDecode (CAL.WA.dt_curtime (self.cTimeZone), pHour, pMinute);
      } else {
        if (self.on_time = -1)
        {
          self.v_event := 1;
          pHour := 12;
          pMinute := 0;
        } else {
          pHour := self.on_time / 60;
          pMinute := mod (self.on_time, 60);
        }
      }
      self.v_eventStart := CAL.WA.dt_encode (pYear, pMonth, pDay, pHour, pMinute);
      self.v_eventEnd := dateadd ('hour', 1, self.v_eventStart);
      self.v_repeat := '';
      self.v_repeatParam1 := 0;
      self.v_repeatParam2 := 0;
      self.v_repeatParam3 := 0;
      self.v_repeatUntil := null;
      self.v_reminder := 600;
      self.v_notes := '';
      self.v_acl := null;
      self.v_grants := '';
    ]]>
  </v:method>

  <v:method name="saveEvent" arglist="">
    <![CDATA[
      declare N, M integer;
      declare tmp, acl_users, params, sd, ed any;

      declare exit handler for SQLSTATE '*'
      {
        if (__SQL_STATE = 'TEST')
        {
          self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
          self.vc_is_valid := 0;
          return;
        }
        resignal;
      };

      params := self.vc_page.vc_event.ve_params;

      self.v_subject := trim (self.e_subject.ufl_value);
      self.v_location := trim (self.e_location.ufl_value);
      self.v_description := trim (self.e_description.ufl_value);
      self.v_attendees := trim (self.e_attendees.ufl_value);
      if ((self.cAction = 'create') or (CAL.WA.event_rights (self.domain_id, self.v_id, self.account_rights) = 'W'))
      self.v_privacy := cast (self.e_privacy.ufl_value as integer);
      self.v_tags := trim (self.e_tags.ufl_value);
      self.v_notes := trim (get_keyword ('e_notes', params, ''));
      self.v_grants := '';
      for (N := 0; N < length (params); N := N + 2)
      {
        if ((params [N] like 'f_fld_1_%') and (trim (params [N+1]) <> ''))
        {
          acl_users := split_and_decode (trim (params[N+1]), 0, '\0\0,');
          for (M := 0; M < length (acl_users); M := M + 1)
          {
            if (not isnull (CAL.WA.account_id (trim (acl_users[M]))))
              self.v_grants := self.v_grants || ',' || acl_users[M];
          }
        }
      }
      self.v_grants := trim (self.v_grants, ',');
      self.v_acl := serialize (DB.DBA.wa_aci_params (params));

      CAL.WA.test (self.v_subject, vector('name', 'Name', 'class', 'varchar', 'minLength', 0, 'maxLength', 255));
      CAL.WA.test (self.v_location, vector('name', 'Location', 'class', 'varchar', 'minLength', 0, 'maxLength', 255));
      CAL.WA.test (self.v_tags, vector ('name', 'Tags', 'class', 'tags'));
      tmp := CAL.WA.tags2vector (self.v_tags);
      tmp := CAL.WA.vector_unique (tmp);
      self.v_tags := CAL.WA.vector2tags (tmp);

      -- event
      declare pDate date;
      declare pTime time;

      self.v_event := cast (get_keyword ('e_event', params, '0') as integer);
      pDate := CAL.WA.test (trim (self.e_eventStartDate.ufl_value), vector('name', 'Event start date', 'class', 'date-'||self.cDateFormat, 'canEmpty', 0));
      if (self.v_event = 0)
      {
        pTime := CAL.WA.dt_stringtime (self.e_eventStartTime.ufl_value);
      } else {
        pTime := CAL.WA.dt_timeEncode (12, 0);
      }
      self.v_eventStart := CAL.WA.dt_join (pDate, pTime);
      pDate := CAL.WA.test (trim (self.e_eventEndDate.ufl_value), vector('name', 'Event end date', 'class', 'date-'||self.cDateFormat, 'canEmpty', 0));
      if (self.v_event = 0)
      {
        pTime := CAL.WA.dt_stringtime (self.e_eventEndTime.ufl_value);
      } else {
        pTime := CAL.WA.dt_timeEncode (12, 0);
      }
      self.v_eventEnd := CAL.WA.dt_join (pDate, pTime);
      if (self.v_eventEnd < self.v_eventStart)
        signal ('TEST', '''End date'' value should be greater then ''Start date'' value!<>');

      -- repeat
      self.v_repeat := trim (get_keyword ('e_repeat', params, ''));
      self.v_repeatParam1 := 0;
      self.v_repeatParam2 := 0;
      self.v_repeatParam3 := 0;
      if (self.v_repeat = 'D1')
      {
        self.v_repeatParam1 := self.e_repeat_param1_D1.ufl_value;
        self.v_repeatParam1 := CAL.WA.test (self.v_repeatParam1, vector('name', 'Day(s)', 'class', 'integer', 'minValue', 1));
      }
      else if (self.v_repeat = 'W1')
      {
        self.v_repeatParam1 := self.e_repeat_param1_W1.ufl_value;
        self.v_repeatParam1 := CAL.WA.test (self.v_repeatParam1, vector('name', 'Week(s)', 'class', 'integer', 'minValue', 1));
        self.v_repeatParam2 := 0;
        for (N := 0; N < 7; N := N + 1)
          if (cast (get_keyword ('e_repeat_param2_W1_' || cast (N as varchar), params, '0') as integer))
            self.v_repeatParam2 := bit_or (self.v_repeatParam2, power (2, N));
      }
      else if (self.v_repeat = 'M1')
      {
        self.v_repeatParam1 := cast (self.e_repeat_param1_M1.ufl_value as integer);
        self.v_repeatParam2 := cast (self.e_repeat_param2_M1.ufl_value as integer);
      }
      else if (self.v_repeat = 'M2')
      {
        self.v_repeatParam1 := cast (self.e_repeat_param1_M2.ufl_value as integer);
        self.v_repeatParam2 := cast (self.e_repeat_param2_M2.ufl_value as integer);
        self.v_repeatParam3 := cast (self.e_repeat_param3_M2.ufl_value as integer);
      }
      else if (self.v_repeat = 'Y1')
      {
        self.v_repeatParam1 := self.e_repeat_param1_Y1.ufl_value;
        self.v_repeatParam1 := CAL.WA.test (self.v_repeatParam1, vector('name', 'Year(s)', 'class', 'integer', 'minValue', 1));
        self.v_repeatParam2 := self.e_repeat_param2_Y1.ufl_value;
      }
      else if (self.v_repeat = 'Y2')
      {
        self.v_repeatParam1 := cast (self.e_repeat_param1_Y2.ufl_value as integer);
        self.v_repeatParam2 := cast (self.e_repeat_param2_Y2.ufl_value as integer);
        self.v_repeatParam3 := cast (self.e_repeat_param3_Y2.ufl_value as integer);
      }

      -- range
      if (self.v_repeat = '')
      {
        self.v_repeatUntil := null;
      } else {
        if (cast (get_keyword ('e_repeatUntilKind', params, '0') as integer) = 1)
        {
          self.v_repeatUntil := CAL.WA.test (trim (self.e_repeatUntil.ufl_value), vector('name', 'Range until date', 'class', 'date-'||self.cDateFormat));
        } else {
          self.v_repeatUntil := null;
        }
      }
      -- validate ACL rules
      DB.DBA.wa_aci_validate (DB.DBA.wa_aci_params (params));

      -- reminder
      self.v_reminder := cast (trim (self.e_reminder.ufl_value) as integer);

      self.v_id := CAL.WA.event_update (
        self.v_id,
        null,
        self.domain_id,
        self.v_subject,
        self.v_description,
        self.v_location,
        self.v_attendees,
        self.v_privacy,
        self.v_tags,
        self.v_event,
                     CAL.WA.event_user2gmt (self.v_eventStart, self.cTimezone, self.cDaylight),
                     CAL.WA.event_user2gmt (self.v_eventEnd, self.cTimezone, self.cDaylight),
        self.v_repeat,
        self.v_repeatParam1,
        self.v_repeatParam2,
        self.v_repeatParam3,
        self.v_repeatUntil,
        self.v_reminder,
        self.v_notes
      );
      CAL.WA.event_update_acl (self.v_id, self.v_acl);
      self.shareNode (self.v_id, self.v_grants, 1);

      if (self.cScope = 'tasks')
        self.cScope := 'events';
    ]]>
  </v:method>

  <v:method name="initNewTask" arglist="">
    <![CDATA[
      self.v_id := -1;
      self.v_subject := '';
      self.v_description := '';
      self.v_privacy := CAL.WA.domain_is_public (self.domain_id);
      self.v_attendees := '';
      self.v_attendees_count := 0;
      self.v_tags := '';
      self.v_eventStart := self.cDay;
      self.v_eventEnd := self.cDay;
      self.v_priority := 3;
      self.v_status := '';
      self.v_complete := 0;
      self.v_completed := null;
      self.v_notes := '';
      self.v_acl := null;
      self.v_grants := '';
    ]]>
  </v:method>

  <v:method name="saveTask" arglist="">
    <![CDATA[
      declare N, M integer;
      declare acl_users, tmp, params any;

      declare exit handler for SQLSTATE '*'
      {
        if (__SQL_STATE = 'TEST')
        {
          self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
          self.vc_is_valid := 0;
          return;
        }
        resignal;
      };

      params := self.vc_page.vc_event.ve_params;

      self.v_subject := trim (self.t_subject.ufl_value);
      self.v_description := trim (self.t_description.ufl_value);
      self.v_priority := cast (self.t_priority.ufl_value as integer);
      self.v_status := self.t_status.ufl_value;
      self.v_complete := cast (self.t_complete.ufl_value as integer);
      self.v_attendees := trim (self.t_attendees.ufl_value);
      if ((self.cAction = 'create') or (CAL.WA.event_domain (self.v_id) = self.domain_id))
      self.v_privacy := cast (self.t_privacy.ufl_value as integer);
      self.v_tags := trim (self.t_tags.ufl_value);
      self.v_notes := trim (get_keyword ('t_notes', params, ''));
      self.v_grants := '';
      for (N := 0; N < length (params); N := N + 2)
      {
        if ((params [N] like 'f_fld_1_%') and (trim (params [N+1]) <> ''))
        {
          acl_users := split_and_decode (trim (params[N+1]), 0, '\0\0,');
          for (M := 0; M < length (acl_users); M := M + 1)
          {
            if (not isnull (CAL.WA.account_id (trim (acl_users[M]))))
              self.v_grants := self.v_grants || ',' || acl_users[M];
          }
        }
      }
      self.v_grants := trim (self.v_grants, ',');
      self.v_acl := serialize (DB.DBA.wa_aci_params (params));

      CAL.WA.test (self.v_subject, vector('name', 'Name', 'class', 'varchar', 'minLength', 1, 'maxLength', 255));
      CAL.WA.test (self.v_tags, vector ('name', 'Tags', 'class', 'tags'));
      tmp := CAL.WA.tags2vector (self.v_tags);
      tmp := CAL.WA.vector_unique (tmp);
      self.v_tags := CAL.WA.vector2tags (tmp);

      self.v_eventStart := CAL.WA.test (trim (self.t_eventStartDate.ufl_value), vector('name', 'Task start date', 'class', 'date-'||self.cDateFormat));
      if (self.v_eventStart = '')
      {
        self.v_eventStart := null;
      } else {
        self.v_eventStart := CAL.WA.dt_join (self.v_eventStart, CAL.WA.dt_timeEncode (12, 0));
      }

      self.v_eventEnd := CAL.WA.test (trim (self.t_eventEndDate.ufl_value), vector('name', 'Task due date', 'class', 'date-'||self.cDateFormat));
      if (self.v_eventEnd = '')
      {
        self.v_eventEnd := null;
      } else {
        self.v_eventEnd := CAL.WA.dt_join (self.v_eventEnd, CAL.WA.dt_timeEncode (12, 0));
      }
      if (self.v_eventEnd < self.v_eventStart)
        signal ('TEST', '''Due date'' value should be greater then ''Start date'' value!<>');

      if ((self.v_complete = 100) or (self.v_status = 'Completed'))
      {
        if (isnull (self.v_eventStart))
          signal ('TEST', '''Start date'' value can''t be empty for completed tasks!<>');
        if (isnull (self.v_eventEnd))
          signal ('TEST', '''Due date'' value can''t be empty for completed tasks!<>');
      }

      self.v_completed := CAL.WA.test (trim (self.t_completed.ufl_value), vector('name', 'Task completed date', 'class', 'date-'||self.cDateFormat));
      if (self.v_completed = '')
        self.v_completed := null;
      if ((isnull (self.v_completed)) and ((self.v_complete = 100) or (self.v_status = 'Completed')))
        self.v_completed := CAL.WA.dt_curdate ();
      if (not isnull (self.v_completed))
        self.v_completed := CAL.WA.dt_join (self.v_completed, CAL.WA.dt_timeEncode (12, 0));
      if (self.v_completed < self.v_eventStart)
        signal ('TEST', '''Completed date'' value should be greater then ''Start date'' value!<>');

      -- validate ACL rules
      DB.DBA.wa_aci_validate (DB.DBA.wa_aci_params (params));

      self.v_id := CAL.WA.task_update (
        self.v_id,
        null,
        self.domain_id,
        self.v_subject,
        self.v_description,
        self.v_attendees,
        self.v_privacy,
        self.v_tags,
                     CAL.WA.event_user2gmt (self.v_eventStart, self.cTimezone, self.cDaylight),
                     CAL.WA.event_user2gmt (self.v_eventEnd, self.cTimezone, self.cDaylight),
        self.v_priority,
        self.v_status,
        self.v_complete,
        self.v_completed,
        self.v_notes
      );
      CAL.WA.event_update_acl (self.v_id, self.v_acl);
      self.shareNode (self.v_id, self.v_grants, 1);
    ]]>
  </v:method>

  <v:method name="priorityLabel" arglist="in priority integer">
    <![CDATA[
     if (priority = 1)
       return 'Highest';
     if (priority = 2)
       return 'High';
     if (priority = 4)
       return 'Low';
     if (priority = 5)
       return 'Lowest';
     return 'Normal';
    ]]>
  </v:method>

  <v:method name="myTags" arglist="in fieldName varchar">
    <![CDATA[
      if ((select count (*) from CAL.WA.TAGS where T_DOMAIN_ID = self.domain_id and T_COUNT > 0 and T_TAG <> '' order by T_TAG))
      {
        http ('<tr>');
        http ('<th>My Tags</th>');
          http ('<td>');
            for (select T_TAG from CAL.WA.TAGS where T_DOMAIN_ID = self.domain_id and T_COUNT > 0 and T_TAG <> '' order by T_TAG) do
            {
              http (sprintf ('<a href="#" onclick="javascript: return addTag(\'%s\', \'%s\');">%s</a> ', T_TAG, fieldName, T_TAG));
            }
          http ('</td>');
        http ('</tr>');
      }
    ]]>
  </v:method>

  <v:method name="eventHeader" arglist="in id integer, in objectName varchar">
    <![CDATA[
      declare event_domain_id integer;
      declare S varchar;

      S := initcap (self.cAction) || ' ' || objectName;
      event_domain_id := (select E_DOMAIN_ID from CAL.WA.EVENTS where E_ID = id);
      if (event_domain_id <> self.domain_id)
        S := S || sprintf (' (Calendar: %V)', CAL.WA.domain_name (event_domain_id));

      return S;
    ]]>
  </v:method>

  <v:method name="windowOpen" arglist="in p_url varchar, in p_name varchar, in p_title varchar, in p_class varchar">
    <![CDATA[
      return  sprintf ('<span onclick="javascript: windowShow(\'%s\', \'calendar_%s_window\'); return false;" title="%s %s" class="%s">%s</span>', CAL.WA.page_url (self.domain_id, p_url, self.sid, self.realm), p_name, p_name, p_title, p_class, p_name);
    ]]>
  </v:method>

  <v:method name="showColorRef" arglist="in statusName varchar">
    <![CDATA[
      declare fieldName varchar;
      
      fieldName := self.colorFieldName (statusName);
      http (sprintf ('<input type="hidden" id="%s" name="%s" value="%s" />', fieldName, fieldName, get_keyword (fieldName, self.settings, '#000')));
      http (sprintf ('<div id="%s_div" class="ss_color" style="cursor: pointer; background-color: %s;"></div><div style="float: left;">&nbsp;- %s</div>', fieldName, get_keyword (fieldName, self.settings, '#000'), statusName));
    ]]>
  </v:method>

  <v:method name="colorFieldName" arglist="in statusName varchar">
    <![CDATA[
      return 'color_' || replace (ucase (statusName), ' ', '_');
    ]]>
  </v:method>

  <vm:pagetitle>Calendar</vm:pagetitle>
  <vm:pagewrapper>
    <vm:header>
      Calendar
    </vm:header>
    <vm:variables>
      <v:variable persist="0" name="e_order" type="varchar" default="'E_EVENT_START'" />
      <v:variable persist="0" name="e_direction" type="varchar" default="'asc'" />

      <v:variable persist="0" name="ts_order" type="varchar" default="'E_EVENT_START'" />
      <v:variable persist="0" name="ts_direction" type="varchar" default="'asc'" />

      <v:variable persist="0" name="s_order" type="varchar" default="'E_EVENT_START'" />
      <v:variable persist="0" name="s_direction" type="varchar" default="'asc'" />

      <v:variable persist="0" name="cAction" type="varchar" default="'browse'" />
      <v:variable persist="0" name="cSubAction" type="varchar" default="''" />
      <v:variable persist="0" name="cScope" type="varchar" default="null" />
      <v:variable persist="0" name="cSearch" type="any" default="null" />

      <v:variable persist="0" name="cDay" type="date" default="null" />
      <v:variable persist="0" name="cMonth" type="date" default="null" />
      <v:variable persist="0" name="cDays" type="any" default="null" />
      <v:variable persist="0" name="cStart" type="date" default="null" />
      <v:variable persist="0" name="cEnd" type="date" default="null" />

      <v:variable persist="0" name="cnMonth" type="date" default="null" />
      <v:variable persist="0" name="cnDays" type="any" default="null" />

      <v:variable name="cLabels" type="integer" default="1" />
      <v:variable name="cChars" type="integer" default="60" />
      <v:variable name="cShowTasks" type="integer" default="1" />
      <v:variable name="cPrivacy" type="integer" default="0" />

      <v:variable name="icSource" type="any" default="-1" />
      <v:variable name="icUser" type="varchar" />
      <v:variable name="icPassword" type="varchar" />
      <v:variable name="icSync" type="integer" default="1" />
      <v:variable name="icAttendees" type="integer" default="2" />

      <v:variable name="exType" type="integer" />
      <v:variable name="exName" type="varchar" />
      <v:variable name="exUser" type="varchar" />
      <v:variable name="exPassword" type="varchar" />
      <v:variable name="exEvents" type="integer" />
      <v:variable name="exTasks" type="integer" />
      <v:variable name="exPeriodFrom" type="datetime" />
      <v:variable name="exPeriodTo" type="datetime" />
      <v:variable name="exTagsInclude" type="varchar" />
      <v:variable name="exTagsExclude" type="varchar" />

      <v:variable persist="temp" name="on_date" type="integer" default="null" />
      <v:variable persist="temp" name="on_time" type="integer" default="null" />
      <v:variable name="v_id" type="any" default="-1" />
      <v:variable name="v_subject" type="varchar" default="''"/>
      <v:variable name="v_description" type="varchar" default="''"/>
      <v:variable name="v_location" type="varchar" default="''"/>
      <v:variable name="v_event" type="integer" default="0"/>
      <v:variable name="v_eventStart" type="datetime" default="null"/>
      <v:variable name="v_eventEnd" type="datetime" default="null"/>
      <v:variable name="v_completed" type="datetime" default="null" />
      <v:variable name="v_privacy" type="integer" default="0" />
      <v:variable name="v_attendees" type="varchar" default="''" />
      <v:variable name="v_attendees_count" type="integer" default="0" />
      <v:variable name="v_tags" type="varchar" default="''"/>
      <v:variable name="v_repeat" type="varchar" default="''"/>
      <v:variable name="v_repeatParam1" type="integer" default="0"/>
      <v:variable name="v_repeatParam2" type="integer" default="0"/>
      <v:variable name="v_repeatParam3" type="integer" default="0"/>
      <v:variable name="v_repeatUntil" type="date" default="null"/>
      <v:variable name="v_reminder" type="integer" default="600"/>

      <v:variable name="v_priority" type="integer" default="3"/>
      <v:variable name="v_complete" type="integer" default="0"/>
      <v:variable name="v_status" type="varchar" default="''"/>
      <v:variable name="v_notes" type="varchar" default="''" />
      <v:variable name="v_acl" type="any" default="null" />
      <v:variable name="v_grants" type="any" default="null"/>

      <v:variable name="vg_id" type="any" default="null" />
      <v:variable name="vg_account_id" type="varchar" default="null" />
      <v:variable name="vg_account" type="varchar" default="''" />
      <v:variable name="vg_enable" type="integer" default="1" />
      <v:variable name="vg_mode" type="varchar" default="'R'" />

      <v:variable name="vs_id" type="any" default="null" />
      <v:variable name="vs_calendar" type="varchar" default="''" />
      <v:variable name="vs_grant_id" type="varchar" default="null" />
      <v:variable name="vs_calendar_id" type="varchar" default="null" />
      <v:variable name="vs_visible" type="varchar" default="1" />
      <v:variable name="vs_color" type="varchar" default="'#888'" />

      <v:variable name="vu_id" type="any" default="-1" />
      <v:variable name="vu_name" type="varchar" default="''" />
      <v:variable name="vu_uri" type="varchar" default="''" />
      <v:variable name="vu_user" type="varchar" default="''" />
      <v:variable name="vu_password" type="varchar" default="''" />
      <v:variable name="vu_include" type="varchar" default="''" />
      <v:variable name="vu_exclude" type="varchar" default="''" />

      <v:variable name="ve_id" type="any" default="-1" />
      <v:variable name="ve_name" type="varchar" default="''" />
      <v:variable name="ve_type" type="varchar" default="''" />
      <v:variable name="ve_update_type" type="integer" default="0" />
      <v:variable name="ve_update_period" type="varchar" default="''" />
      <v:variable name="ve_update_freq" type="integer" default="0" />
      <v:variable name="ve_options" type="any" default="null" />
      <v:variable name="ve_result" type="any" default="null" />

      <v:variable name="v_tabNo" param-name="tabNo" type="varchar" default="0" />

      <v:variable name="tv_status" type="varchar" default="'All'" />

      <v:variable name="s_url" type="varchar" default="''" />
    </vm:variables>
    <vm:pagebody>
      <table id="MTB">
        <tr>
          <!-- Navigation left column -->
          <td id="LC">
            <vm:if test="self.cAction <> 'settings'">
              <vm:if test="self.account_rights = 'W'">
                <vm:event />
              </vm:if>
              <vm:calendar />
              <vm:bookmarklet />
              <vm:calendars />
              <vm:exchange />
              <vm:formats />
            </vm:if>
            <vm:if test="self.cAction = 'settings'">
              <div class="lc lc_close">
                <vm:if test="self.account_rights = 'W'">
                <span onclick="javascript: vspxPost('command', 'select', 'settings', 'mode', 'settings');" title="Settings" class="gems gems2" style="color: black;">Settings</span>
                </vm:if>
                <span onclick="javascript: vspxPost('command', 'select', 'settings', 'mode', 'bookmarklet');" title="Bookmarklet" class="gems gems2" style="color: black;">Bookmarklet</span>
                <vm:if test="self.account_rights = 'W'">
                <span onclick="javascript: vspxPost('command', 'select', 'settings', 'mode', 'upstreamBrowse');" title="Upstreams" class="gems gems2" style="color: black;">Upstreams</span>
                <span onclick="javascript: vspxPost('command', 'select', 'settings', 'mode', 'grantBrowse');" title="Share My Calendar" class="gems gems2" style="color: black;">Share My Calendar</span>
                <span onclick="javascript: vspxPost('command', 'select', 'settings', 'mode', 'sharedBrowse');" title="Accepted Calendars" class="gems gems2" style="color: black;">Accepted Calendars</span>
                </vm:if>
                <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
                <span onclick="javascript: vspxPost('command', 'select', 'settings', 'mode', 'back');" title="Back" class="gems gems2" style="color: black;">Back</span>
              </div>
            </vm:if>
          </td>
          <!-- Navigation right column -->
          <td id="RC" typeof="sioct:Calendar" about="<?V CAL.WA.forum_iri (self.domain_id) ?>">
            <v:template type="simple" name="template_error" condition="not self.vc_is_valid">
              <div class="error">
                <p><v:error-summary/></p>
              </div>
            </v:template>
            <div class="main_page_area">
      <v:before-data-bind>
        <![CDATA[
          self.actionTest ();
          self.initData ();
        ]]>
      </v:before-data-bind>
      <?vsp
        declare sparqlUrl, graphIri any;
        
        sparqlUrl := 'http://' || SIOC..get_cname () || '/sparql';
        graphIri := SIOC..get_graph ();
        http(sprintf('<input type="hidden" id="sparqlUrl" name="sparqlUrl" value="%s?default-graph-uri=%U&amp;query=%U&amp;format=%U"/>', sparqlUrl, graphIri, 'DESCRIBE <_RDF_>', 'application/sparql-results+xml')); 
      ?>
      <v:text name="tabNo" xhtml_id="tabNo" type="hidden" value="--self.v_tabNo" />
      <?vsp
        if (0)
        {
      ?>
                <v:button action="simple" name="command" value="Submit">
            <v:on-post>
              <![CDATA[
                      declare N integer;
                      declare params, S, cCommand, cMode, cPermission, cParams, kind any;

                      params := e.ve_params;
                      cCommand := get_keyword ('export', params, '');
                if (cCommand in ('rss', 'atom', 'rdf'))
                {
                        S := sprintf('%s/export.vspx?output=%s&scope=%s', CAL.WA.iri_fix (CAL.WA.forum_iri (self.domain_id)), cCommand, self.cScope);
                        if (self.cScope = 'events')
                  {
                          S := S || sprintf ('&order=%s&direction=%s', self.e_order, self.e_direction);
                        }
                        if (self.cScope = 'tasks')
                        {
                          S := S || sprintf ('&order=%s&direction=%s', self.ts_order, self.ts_direction);
                        }
                        else if (self.cScope = 'search')
                        {
                          S := S || sprintf ('&order=%s&direction=%s', self.s_order, self.s_direction);
                    if (trim (self.s_keywords.ufl_value) <> '')
                      S := S || '&keywords=' || trim (self.s_keywords.ufl_value);
                    if (trim (self.s_tags.ufl_value) <> '')
                      S := S || '&tags=' || trim (self.s_tags.ufl_value);
                  }

                  self.vc_redirect(S);
                  return;
                }

                      cCommand := get_keyword ('select', params, '');
                      if (cCommand <> '')
                      {
                        if (cCommand = 'create')
                        {
                    self.cAction := 'create';
                          self.cSubAction := get_keyword ('mode', params, 'event');
                          if (get_keyword ('mode', params, 'event') = 'task')
                    {
                      self.initNewTask ();
                    } else {
                      self.initNewEvent ();
                    }
                          if (get_keyword ('onDate', params, '') <> '')
                            self.on_date := cast (get_keyword ('onDate', params) as integer);
                          if (get_keyword ('onTime', params, '') <> '')
                            self.on_time := cast (get_keyword ('onTime', params) as integer);
                        }
                        else if (cCommand = 'settings')
                        {
                          cMode := get_keyword ('mode', params, '');
                          if (cMode = 'settings')
                          {
                            self.cAction := cMode;
                            self.cSubAction := '';
                          }
                          if (cMode = 'bookmarklet')
                          {
                            self.cAction := cCommand;
                            self.cSubAction := cMode;
                          }
                          else if (cMode = 'upstreamBrowse')
                          {
                            self.cSubAction := cMode;
                          }
                          else if (cMode = 'sharedBrowse')
                          {
                            self.cSubAction := cMode;
                          }
                          else if (cMode = 'grantBrowse')
                          {
                            self.cSubAction := cMode;
                          }
                          else if (cMode = 'sharedUpdate')
                          {
                            self.cAction := cCommand;
                            self.cSubAction := cMode;
                            self.vs_id := cast (get_keyword ('id', params) as integer);
                          }
                          else if (cMode = 'back')
                          {
                            self.cAction := 'browse';
                            self.cSubAction := '';
                          }
                        }
                        else if (cCommand = 'search')
                        {
                          cMode := get_keyword ('mode', params, '');
                          if (cMode = 'simple')
                          {
                            if ((trim (self.keywords.ufl_value) <> '') or (self.cScope = 'search'))
                            {
				                      self.cScope := 'search';
				                      self.cAction := 'browse';
				                      self.cSearch := null;
				                      CAL.WA.xml_set('keywords', self.cSearch, self.keywords.ufl_value);
				                    }
                          }
                          else if (cMode = 'advanced')
                          {
				                    self.cScope := 'search';
				                    self.cAction := 'advanced';
				                    self.cSearch := null;
				                    CAL.WA.xml_set('mode', self.cSearch, 'advanced');
                          }
                        }
                        else
                        {
                    cParams := split_and_decode(cCommand, 0,'\0\0_');
                          if (length (cParams) > 2)
                          {
                            if (cParams[1] = 'month')
                            {
                        if (atoi (cParams[2]) = -1)
                          self.cnMonth := dateadd ('month', -1, self.cnMonth);
                        if (atoi (cParams[2]) = 1)
                          self.cnMonth := dateadd ('month', 1, self.cnMonth);
                              if (atoi (cParams[2]) = 0)
                              {
                          if ((self.cDay < self.cnMonth) or (self.cDay > CAL.WA.dt_EndOfMonth (self.cnMonth)))
                                  if (dayofmonth (self.cDay) > CAL.WA.dt_LastDayOfMonth (self.cnMonth))
                                  {
                              self.cDay := CAL.WA.dt_EndOfMonth (self.cnMonth);
                            } else {
                              self.cDay := dateadd ('day', dayofmonth (self.cDay)-1, self.cnMonth);
                            }
                          self.cScope := 'month';
                          self.cMonth := null;
                          self.cnMonth := null;
                        }
                      }
                            if (cParams[1] = 'today')
                            {
                              self.cScope := 'day';
                              self.cDay := CAL.WA.dt_curdate (self.cTimeZone);
                              self.cMonth := null;
                              self.cnMonth := null;
                            }
                            if (cParams[1] = 'day')
                            {
                        self.cMonth := self.cnMonth;
                              self.cDays := self.initDays (self.cMonth);
                        N := atoi (cParams[2]) * 7 + atoi (cParams[3]);
                        self.cDay := self.calcDate (N);
                        if ((cParams[0] = 'd') or ((self.cDay >= self.cStart) and (self.cDay <= self.cEnd)) or (self.cScope = 'events'))
                          self.cScope := 'day';
                        self.cMonth := null;
                        self.cnMonth := null;
                      }
                      self.cAction := 'browse';
                      self.initData ();
                    }
                  }
                }
                
                      cCommand := get_keyword ('date', params, '');
                      if (cCommand <> '')
                      {
                  cParams := split_and_decode(cCommand, 0,'\0\0_');
                        if (length (cParams) > 1)
                        {
                    self.cDay := stringdate (cParams [1]);
                    self.cMonth := null;
                    self.cAction := 'browse';
                    self.cScope := 'day';
                  }
                }

                      cCommand := get_keyword ('edit', params, '');
                      if (cCommand <> '')
                      {
                  cParams := split_and_decode(cCommand, 0,'\0\0_');
                        if (length (cParams) > 1)
                        {
                    self.v_id := cast (cParams [1] as integer);
                          cPermission := CAL.WA.event_rights (self.domain_id, self.v_id, self.account_rights);
                          if (cPermission = 'W')
                          {
                    self.cAction := 'edit';
                          }
                          else if (cPermission = 'R')
                          {
                            self.cAction := 'view';
                          }
                          else
                          {
                            return;
                          }
                          self.cSubAction := CAL.WA.event_kind (self.v_id);
                }
                      }

                      cCommand := get_keyword ('view', params, '');
                      if (cCommand <> '')
                      {
                        cParams := split_and_decode(cCommand, 0,'\0\0_');
                        if (length (cParams) > 1)
                        {
                          self.v_id := cast (cParams [1] as integer);
                          cPermission := CAL.WA.event_rights (self.domain_id, self.v_id, self.account_rights);
                          if (not ((cPermission = 'W') or (cPermission = 'R')))
                            return;

                          self.cAction := 'view';
                          self.cSubAction := CAL.WA.event_kind (self.v_id);
                        }
                      }

                      cCommand := get_keyword ('delete', params, '');
                      if (cCommand <> '')
                      {
                  cParams := split_and_decode(cCommand, 0,'\0\0_');
                  if (length (cParams) > 1)
                        {
                          self.v_id := cast (cParams [1] as integer);
                          if (CAL.WA.event_rights (self.domain_id, self.v_id, self.account_rights) <> 'W')
                            return;

                          CAL.WA.event_delete (self.v_id, get_keyword ('onOffset', params));
                        }
                }

                      cCommand := get_keyword ('exchange', params, '');
                      if (cCommand <> '')
                      {
                        if (cCommand = 'import')
                        {
                  self.cAction := cCommand;
                    self.icSource := -1;
                    self.v_tags := '';
                          self.icUser := '';
                          self.icPassword := '';
                          self.icSync := 1;
                          self.icAttendees := 2;
                  }
                        else if (cCommand = 'export')
                        {
                          self.cAction := cCommand;
                          self.exType := -1;
                          self.exName := 'calendar.ics';
                          self.exUser := '';
                          self.exPassword := '';
                          self.exEvents := 1;
                          self.exTasks := 1;
                          self.exPeriodFrom := null;
                          self.exPeriodTo := null;
                          self.exTagsInclude := '';
                          self.exTagsExclude := '';
                        }
                        else if (cCommand = 'publishBrowse')
                        {
                          self.cAction := cCommand;
                        }
                        else if (cCommand = 'subscribeBrowse')
                        {
                          self.cAction := cCommand;
                        }
                        else if (cCommand = 'syncmlBrowse')
                        {
                          self.cAction := cCommand;
                        }
                }
                self.vc_data_bind(e);
               ]]>
             </v:on-post>
          </v:button>
      <?vsp
        }
      ?>

      <vm:if test="self.cAction in ('browse', 'advanced')">
        <vm:if test="self.cAction = 'advanced'">
          <div class="new-form-body">
            <table cellspacing="0">
              <tr>
                <th width="30%">
                        <vm:label for="" value="Space delimited keyword list" />
                </th>
                <td>
                        <v:text name="s_keywords" value="--CAL.WA.xml_get ('keywords', self.cSearch)" fmt-function="CAL.WA.utf2wide" xhtml_class="textbox" xhtml_size="60" />
                </td>
              </tr>
              <tr>
                <th>
                  <vm:label for="s_tags" value="Tags (comma-separated)" />
                </th>
                <td>
                        <v:text name="s_tags" value="--CAL.WA.xml_get ('tags', self.cSearch)" fmt-function="CAL.WA.utf2wide" xhtml_class="textbox" xhtml_size="60" />
                </td>
              </tr>
            </table>
          </div>
                <div class="form-footer" style="margin: 0;   border-top: 0;">
                  <v:button action="simple" name="s_search" value="Search" xhtml_class="form-button">
              <v:on-post>
                <![CDATA[
                  self.cSearch := null;
                  CAL.WA.xml_set ('mode', self.cSearch, 'advanced');
                  CAL.WA.xml_set ('keywords', self.cSearch, trim (self.s_keywords.ufl_value));
                  CAL.WA.xml_set ('tags', self.cSearch, trim (self.s_tags.ufl_value));
                  self.vc_data_bind(e);
                ]]>
              </v:on-post>
            </v:button>
                  <v:button action="simple" name="s_cancel" value="Cancel" xhtml_class="form-button">
              <v:on-post>
                <![CDATA[
                  self.cAction := 'browse';
                  self.vc_data_bind (e);
                ]]>
              </v:on-post>
            </v:button>
          </div>
        </vm:if>

              <table cellspacing="0" cellpadding="0" style="width: 100%;">
          <tr style="height: 18px;">
            <td>
                    <v:button action="simple" name="day" value="Day" xhtml_class="-- case when (self.cScope = 'day') then 'calendar_tab calendar_tabActive' else 'calendar_tab' end" xhtml_alt="Day">
                <v:on-post>
                  <![CDATA[
                    self.cScope := 'day';
                    self.cAction := 'browse';
                    self.cMonth := null;
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
                    <v:button action="simple" name="week" value="Week" xhtml_class="-- case when (self.cScope = 'week') then 'calendar_tab calendar_tabActive' else 'calendar_tab' end" xhtml_alt="Week">
                <v:on-post>
                  <![CDATA[
                    self.cScope := 'week';
                    self.cAction := 'browse';
                    self.cMonth := null;
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
                    <v:button action="simple" name="month" value="Month" xhtml_class="-- case when (self.cScope = 'month') then 'calendar_tab calendar_tabActive' else 'calendar_tab' end" xhtml_alt="Month">
                <v:on-post>
                  <![CDATA[
                    self.cScope := 'month';
                    self.cAction := 'browse';
                    self.cMonth := null;
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
                    <v:button action="simple" name="events" value="Events" xhtml_class="-- case when (self.cScope = 'events') then 'calendar_tab calendar_tabActive' else 'calendar_tab' end" xhtml_alt="Event List">
                <v:on-post>
                  <![CDATA[
                    self.cScope := 'events';
                    self.cAction := 'browse';
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
                    <v:button action="simple" name="tasks" value="Tasks" xhtml_class="-- case when (self.cScope = 'tasks') then 'calendar_tab calendar_tabActive' else 'calendar_tab' end" xhtml_alt="Task List">
                <v:on-post>
                  <![CDATA[
                    self.cScope := 'tasks';
                    self.cAction := 'browse';
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
              <vm:if test="not isnull (self.cSearch)">
                      <v:button action="simple" name="search" value="Search" xhtml_class="-- case when (self.cScope = 'search') then 'calendar_tab calendar_tabActive' else 'calendar_tab' end" xhtml_alt="Search List">
                  <v:on-post>
                    <![CDATA[
                      self.cScope := 'search';
                      self.cAction := CAL.WA.xml_get ('mode', self.cSearch, 'browse');
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
              </vm:if>
            </td>
            <vm:if test="self.cScope not in ('events', 'tasks', 'search')">
            <td align="right">
              <span class="CE_name">
                <?vsp
                  if (self.cScope = 'day')
                    http (sprintf ('%s %d, %d', monthname (self.cDay), dayofmonth (self.cDay), year (self.cDay)));

                    if (self.cScope = 'week')
                    {
                      if (year (self.cStart) <> year (self.cEnd))
                      {
                      http (sprintf ('%s %d, %d - %s %d, %d', monthname (self.cStart), dayofmonth (self.cStart), year (self.cStart), monthname (self.cEnd), dayofmonth (self.cEnd), year (self.cEnd)));
                    } else {
                        if (month (self.cStart) <> month (self.cEnd))
                        {
                        http (sprintf ('%s %d - %s %d, %d', monthname (self.cStart), dayofmonth (self.cStart), monthname (self.cEnd), dayofmonth (self.cEnd), year (self.cEnd)));
                      } else {
                        http (sprintf ('%s %d - %d, %d', monthname (self.cStart), dayofmonth (self.cStart), dayofmonth (self.cEnd), year (self.cEnd)));
                      }
                    }
                  }

                  if (self.cScope = 'month')
                    http (sprintf ('%s %d', monthname (self.cMonth), year (self.cMonth)));

                ?>
              </span>
                      <v:button action="simple" name="previous" value="--'&amp;lt;'" xhtml_class="calendar_button" xhtml_alt="Previous">
                <v:on-post>
                  <![CDATA[
                    if (self.cScope = 'day')
                      self.cDay := dateadd ('day', -1, self.cDay);
                    if (self.cScope = 'week')
                      self.cDay := dateadd ('day', -7, self.cDay);
                    if (self.cScope = 'month')
                      self.cDay := dateadd ('month', -1, self.cDay);
                      self.cMonth := null;
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
                      <v:button action="simple" name="next" value="--'&amp;gt;'" xhtml_class="calendar_button" xhtml_alt="Next">
                <v:on-post>
                  <![CDATA[
                    if (self.cScope = 'day')
                      self.cDay := dateadd ('day', 1, self.cDay);
                    if (self.cScope = 'week')
                      self.cDay := dateadd ('day', 7, self.cDay);
                    if (self.cScope = 'month')
                        if (dayofmonth (self.cDay) > CAL.WA.dt_LastDayOfMonth (dateadd ('month', 1, self.cMonth)))
                        {
                        self.cDay := CAL.WA.dt_LastDayOfMonth (dateadd ('month', 1, self.cMonth));
                      } else {
                        self.cDay := dateadd ('month', 1, self.cDay);
                      }
                      self.cMonth := null;
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
                      <v:button action="simple" name="today" value="Today" xhtml_class="calendar_button" xhtml_alt="Today">
                <v:on-post>
                  <![CDATA[
                    self.cScope := 'day';
                    self.cDay := CAL.WA.dt_curdate (self.cTimeZone);
                      self.cMonth := null;
                    self.initData ();
                    self.vc_data_bind (e);
                  ]]>
                </v:on-post>
              </v:button>
            </td>
             </vm:if>
          </tr>
        </table>
        <div class="CE_container">
          <v:before-data-bind>
            <![CDATA[
                    self.tv_status := get_keyword ('tvf_status', self.vc_page.vc_event.ve_params, CAL.WA.settings_taskFilter (self.settings));
            ]]>
          </v:before-data-bind>
            <table width="100%" cellspacing="0">
              <tr>
                <td>
                      <vm:if test="(self.cScope not in ('day', 'week', 'month')) and (self.account_rights = 'W')">
            <vm:if test="(self.cScope <> 'search')">
                          <v:button action="simple" name="new" value="--'New ' || self.singleObjectName (self.cScope)" xhtml_class="button">
              <v:on-post>
                <![CDATA[
                  self.cAction := 'create';
                                self.cSubAction := case when (self.cScope = 'events') then 'event' else 'task' end;
          		    self.vc_data_bind(e);
                ]]>
              </v:on-post>
            </v:button>
            </vm:if>
                        <v:button action="simple" name="delete" value="Delete" xhtml_onclick="--'javascript: return confirmAction(\'Are you sure that you want to delete the selected item(s)?\', document.F1, \'cb_item\', \'No items were selected for deletion.\');'" xhtml_class="button">
              <v:on-post>
                <![CDATA[
                              declare N, L, id integer;
                              declare params any;

                              params := e.ve_params;
                              L := length(params);
                              for (N := 0; N < L; N := N + 4)
                              {
                                if (params[N] = 'cb_item')
                                {
                                  id := cast (params[N+1] as integer);
                                  if (CAL.WA.event_rights (self.domain_id, id, self.account_rights) = 'W')
                                    CAL.WA.event_delete(id);
                                }
                              }
                              commit work;
          		    self.vc_data_bind(e);
                ]]>
              </v:on-post>
            </v:button>

                  <div class="menuBar" id="exportBar">
                    <input type="button" value="Gems" class="menuButton button" onmousedown="return this.blur();" onclick="return menuPopup(this, 'exportMenu');" title="<?V initcap (self.cScope) ?> Gems" />
                    <div class="menu" id="exportMenu">
                      <?vsp
                        http (sprintf ('<a class="menuItem" href="javascript: void (0);" onclick="javascript: vspxPost(\'command\', \'export\', \'rss\')"  title="%s"><img src="image/rss-icon-16.gif"  border="0" alt="%s"/> %s</a>', 'RSS',  'RSS',  'RSS'));
                        http (sprintf ('<a class="menuItem" href="javascript: void (0);" onclick="javascript: vspxPost(\'command\', \'export\', \'atom\')" title="%s"><img src="image/blue-icon-16.gif" border="0" alt="%s"/> %s</a>', 'Atom', 'Atom', 'Atom'));
                        http (sprintf ('<a class="menuItem" href="javascript: void (0);" onclick="javascript: vspxPost(\'command\', \'export\', \'rdf\')"  title="%s"><img src="image/rdf-icon-16.gif"  border="0" alt="%s"/> %s</a>', 'RDF',  'RDF',  'RDF'));
                      ?>
                    </div>
                  </div>
                </vm:if>
                </td>
                <td align="right">
                <vm:if test="(self.cScope = 'tasks')">
                  Show
                  <v:select-list name="tvf_status" xhtml_id="tvf_status" xhtml_onchange="javascript: this.form.submit();">
                    <v:on-init>
                      <![CDATA[
                              declare x, y any;

                              x := make_array (7, 'any');
                        x[0] := 'All';
                              x[1] := 'Completed';
                              x[2] := 'Not Completed';
                              x[3] := '~ Not Started';
                              x[4] := '~ In Progress';
                              x[5] := '~ Waiting';
                              x[6] := '~ Deferred';
                              y := make_array (7, 'any');
                              y[0] := 'All';
                              y[1] := 'Completed';
                              y[2] := 'Not Completed';
                              y[3] := 'Not Started';
                              y[4] := 'In Progress';
                              y[5] := 'Waiting';
                              y[6] := 'Deferred';
                              control.vsl_item_values := y;
                        control.vsl_items := x;
                        control.ufl_value := '';
                      ]]>
                    </v:on-init>
                    <v:before-data-bind>
                      <![CDATA[
                        control.ufl_value := self.tv_status;
                      ]]>
                    </v:before-data-bind>
                  </v:select-list>
                </vm:if>
                  <span id="navigation"></span>
                </td>
              </tr>
            </table>
          <div id="content" class="CE_main">
            <vm:if test="self.cScope in ('day', 'week', 'month')">
              <table class="CE_table" cellspacing="0">
                <?vsp
                        declare N, M, L, D, W integer;
                  declare pStart, pEnd, hasEvents integer;
                  declare pHour, pMinute integer;
                  declare dt date;
                  declare S, C, onClick varchar;
                  declare V any;

                        if (self.cScope = 'day')
                        {
                    V := make_array (48, 'any');
                    for (N := 0; N < 48; N := N + 1)
                      V[N] := vector ();
                    hasEvents := 0;
                    for (select distinct rs.*
                                from CAL.WA.events_forPeriod (rs0, rs1, rs2, rs3, rs4, rs5)(e_id integer, e_event integer, e_subject varchar, e_start datetime, e_end datetime, e_repeat varchar, e_repeat_offset integer, e_reminder integer, e_attendees integer) rs
                       where rs0 = self.domain_id
                         and rs1 = self.cDay
                         and rs2 = self.cDay
                                 and rs3 = self.cPrivacy
                           and rs4 = self.cShowTasks
                                 and rs5 = self.account_rights
                         order by e_event DESC, e_start) do
                    {
                            if (e_event = 1)
                            {
                              if (hasEvents = 0)
                              {
                        http ('<tr class="CE_row">');
                        http ('<th class="CE_cell CE_cell_time">&nbsp;</th>');
                        http ('<td class="CE_cell">');
                        hasEvents := 1;
                      }
                              http (self.showEvent (e_id, e_event, e_subject, e_start, e_end, e_repeat, e_repeat_offset, e_reminder, e_attendees, self.showContinue (self.cDay, e_event, e_start, e_end)));
                            }
                            else
                            {
                              if (CAL.WA.dt_compare (e_start, self.cDay))
                              {
                        CAL.WA.dt_timeDecode (e_start, pHour, pMinute);
                        pStart := pHour*2 + pMinute/30;
                              }
                              else
                              {
                                pStart := 0;
                              }
                              if (CAL.WA.dt_compare (e_end, self.cDay))
                              {
                        CAL.WA.dt_timeDecode (e_end, pHour, pMinute);
                        pEnd := pHour*2 + pMinute/30;
                              }
                              else
                              {
                                pEnd := 48;
                              }
                              for (N := pStart; N < pEnd; N := N + 1)
                              {
                                if ((N = pStart) and (pEnd - pStart > 1) and CAL.WA.dt_compare (e_start, self.cDay))
                                {
                            S := '<img src="image/tr_close.gif" border="0" />';
                                }
                                else if ((N = pEnd-1) and (pEnd - pStart > 1) and CAL.WA.dt_compare (e_end, self.cDay))
                                {
                            S := '<img src="image/tr_close2.gif" border="0" />';
                                }
                                else if (CAL.WA.dt_compare (e_start, self.cDay) and CAL.WA.dt_compare (e_end, self.cDay) and (pEnd - pStart = 1))
                                {
                                  S := '';
                                }
                                else
                                {
                            S := '... ';
                                }
                                aset (V, N, vector_concat(V[N], vector (self.showEvent (e_id, e_event, e_subject, e_start, e_end, e_repeat, e_repeat_offset, e_reminder, e_attendees, S))));
                        }
                      }
                    }
                    if (hasEvents) {
                      http ('</td>');
                      http ('</tr>');
                    }

                        C := '';
                        if (CAL.WA.dt_compare (self.cDay, curdate ()))
                          C := C || ' CE_cell_today';
                        if (self.domain_id > 0)
                          C := C || ' CE_cell_pointer';
                          for (N := 0; N < 48; N := N + 1)
                          {
                      http ('<tr class="CE_row">');
                        if (mod (N, 2) = 0)
                          http (sprintf ('<th class="CE_cell CE_cell_time %s" rowspan="2">%s</th>', case when (N = 46) then 'CE_cell_bottom' else '' end, CAL.WA.dt_timestring (CAL.WA.dt_timeEncode (N/2, 0), self.cTimeFormat)));
                        onClick := '';
                              if ((self.domain_id > 0) and (self.account_rights = 'W'))
                          onClick := sprintf (' onclick="javascript: cNewEvent(event, null, %d);"', N*30);
                        S := '';
                        if (length (V[N]))
                          S := 'style="background: #FAFAFA;"';
                        http (sprintf ('<td class="CE_new CE_cell CE_cell_odd %s" %s %s>', C, S, onClick));

                              L := length (V[N]);
                              for (M := 0; M < L; M := M + 1)
                          http (V[N][M]);

                        if (not length (V[N]))
                          http ('&nbsp;');
                        http ('</td>');
                      http ('</tr>');
                    }
                  }
                        else if (self.cScope = 'week')
                  {
                          L := length (self.cDays);
                          for (N := 0; N < L; N := N + 1)
                    {
                      W := floor (N / 7);
                      D := mod (N, 7);
                      dt := self.calcDate (N);
                      if ((dt >= self.cStart) and (dt <= self.cEnd))
                      {
                        http ('<tr class="CE_row_week">');
                          C := '';
                          if (mod (N, 7) = 6)
                            C := C || ' CE_cell_bottom';
                          http (sprintf ('<td class="CE_cell CE_cell_week CE_cell_middle%s">', C));
                          C := '';
                          if (self.cDays[N] > 0)
                            C := C || ' C_onmonth';
                          if (self.cDays[N] < 0)
                            C := C || ' C_offmonth';
                          if (CAL.WA.dt_isWeekDay (dt, self.cWeekStarts))
                          {
                            C := C || ' C_weekday2';
                          } else {
                            C := C || ' C_weekend';
                          }
                          if (CAL.WA.dt_compare (dt, curdate ()))
                            C := C || ' C_today';
                          http (sprintf ('<div onclick="cSelect(this)" id="d_day_%d_%d" class="CE_cell_header%s">%s %d</div>', W, D, C, CAL.WA.dt_WeekName (dt, self.cWeekStarts, 0), abs (self.cDays [N])));
                          http ('&nbsp;');
                          http ('</td>');
                          C := '';
                          if (CAL.WA.dt_compare (dt, curdate ()))
                            C := C || ' CE_cell_today';
                          if (self.domain_id > 0)
                            C := C || ' CE_cell_pointer';
                          onClick := 'javascript: void(0);';
                                if ((self.domain_id > 0) and (self.account_rights = 'W'))
                            onClick := sprintf (' onclick="javascript: cNewEvent(event, %d, -1);"', N);
                          hasEvents := 0;
                          for (select distinct rs.*
                                       from CAL.WA.events_forPeriod (rs0, rs1, rs2, rs3, rs4, rs5)(e_id integer, e_event integer, e_subject varchar, e_start datetime, e_end datetime, e_repeat varchar, e_repeat_offset integer, e_reminder integer, e_attendees integer) rs
                                where rs0 = self.domain_id
                                  and rs1 = dt
                                  and rs2 = dt
                                        and rs3 = self.cPrivacy
                                  and rs4 = self.cShowTasks
                                        and rs5 = self.account_rights
                                order by e_event DESC, e_start) do
                          {
                            if (not hasEvents)
                              http (sprintf ('<td class="CE_new CE_cell %s" style="background: #FAFAFA;" %s">', C, onClick));
                            hasEvents := 1;
                                  http (self.showEvent (e_id, e_event, e_subject, e_start, e_end, e_repeat, e_repeat_offset, e_reminder, e_attendees, self.showContinue (dt, e_event, e_start, e_end)));
                          }
                          if (not hasEvents)
                          {
                            http (sprintf ('<td class="CE_new CE_cell %s" %s">', C, onClick));
                            http ('&nbsp;');
                          }
                          http ('</td>');
                        http ('</tr>');
                      }
                    }
                  }
                        else if (self.cScope = 'month')
                        {
                          L := length (self.cDays);
                          for (N := 0; N < L; N := N + 1)
                          {
                      W := floor (N / 7);
                      D := mod (N, 7);
                      dt := self.calcDate (N);
                            if ((dt >= self.cStart) and (dt <= self.cEnd))
                            {
                        if (D = 0)
                          http ('<tr class="CE_row_month">');
                        C := '';
                        if (D < 6)
                          C := C || ' CE_cell_middle';
                        if (CAL.WA.dt_compare (dt, curdate ()))
                          C := C || ' CE_cell_today';
                        if (self.domain_id > 0)
                          C := C || ' CE_cell_pointer';
                        onClick := '';
                              if ((self.domain_id > 0) and (self.account_rights = 'W'))
                          onClick := sprintf (' onclick="javascript: cNewEvent(event, %d, -1);"', N);
                        http (sprintf ('<td width="%s" class="CE_new CE_cell %s" %s>', '14.2857%', C, onClick));
                        C := '';
                        if (self.cDays[N] > 0)
                          C := C || ' C_onmonth';
                        if (self.cDays[N] < 0)
                          C := C || ' C_offmonth';
                              if (CAL.WA.dt_isWeekDay (dt, self.cWeekStarts))
                              {
                          C := C || ' C_weekday2';
                        } else {
                          C := C || ' C_weekend';
                        }
                        if (CAL.WA.dt_compare (dt, curdate ()))
                          C := C || ' C_today';
                        http (sprintf ('<div onclick="cSelect(this)" id="d_day_%d_%d" class="CE_cell_header%s">%d</div>', W, D, C, abs (self.cDays [N])));
                        for (select distinct rs.*
                                     from CAL.WA.events_forPeriod (rs0, rs1, rs2, rs3, rs4, rs5)(e_id integer, e_event integer, e_subject varchar, e_start datetime, e_end datetime, e_repeat varchar, e_repeat_offset integer, e_reminder integer, e_attendees integer) rs
                              where rs0 = self.domain_id
                                and rs1 = dt
                                and rs2 = dt
                                      and rs3 = self.cPrivacy
                                and rs4 = self.cShowTasks
                                      and rs5 = self.account_rights
                              order by e_event DESC, e_start) do
                        {
                                http (self.showEvent (e_id, e_event, e_subject, e_start, e_end, e_repeat, e_repeat_offset, e_reminder, e_attendees, self.showContinue (dt, e_event, e_start, e_end)));
                        }
                        http ('</td>');
                        if (D = 6)
                          http ('</tr>');
                      }
                    }
                  }
                ?>
              </table>
            </vm:if>

                  <vm:if test="self.cScope in ('events', 'tasks', 'search')">
              <v:data-source name="dsrc" expression-type="sql" nrows="0" initial-offset="0">
                <v:before-data-bind>
                  <![CDATA[
                          declare sql varchar;

                          if (self.cScope = 'search')
                          {
                            if (isnull (self.cSearch))
                            {
                              sql := 'select * from CAL.WA.EVENTS where 1 = 0';
                            } else {
                              sql := CAL.WA.search_sql (self.domain_id, self.cPrivacy, self.cSearch, self.account_rights);
                            }
                            self.sortChange (get_keyword ('s_sortColumn', e.ve_params), 's_order', 's_direction', self.ds);
                            sql := sql || sprintf (' order by %s %s, E_ID', self.s_order, self.s_direction);
                          }
                          else
                          {
                            sql := CAL.WA.search_sql (self.domain_id, self.cPrivacy, null, self.account_rights);
                            sql := sql || sprintf (' and a.E_KIND = %d', case when (self.cScope = 'tasks') then 1 else 0 end);
                            if (self.cScope = 'tasks')
                            {
                              CAL.WA.settings_set (self.domain_id, 'taskFilter', self.tv_status);
                              if (self.tv_status <> 'All')
                                sql := sql || sprintf (' and coalesce (a.E_STATUS, '''') %s', case when (self.tv_status = 'Not Completed') then '<> ''Completed''' else '= ''' || self.tv_status || '''' end);

                              self.sortChange (get_keyword ('t_sortColumn', e.ve_params), 'ts_order', 'ts_direction', self.ds);
                              sql := sql || sprintf (' order by %s %s', self.ts_order, self.ts_direction);
                            }
                            else
                            {
                    self.sortChange (get_keyword ('e_sortColumn', e.ve_params), 'e_order', 'e_direction', self.ds);
                              sql := sql || sprintf (' order by %s %s', self.e_order, self.e_direction);
                          }
                          }
                          control.ds_sql := sql;
                          control.ds_nrows := CAL.WA.settings_rows (self.settings);
                          control.ds_parameters := null;
                  ]]>
                </v:before-data-bind>
	              <v:after-data-bind>
	                control.ds_make_statistic ();
	              </v:after-data-bind>
              </v:data-source>

              <v:data-set name="ds" data-source="self.dsrc" scrollable="1">

                <v:template name="ds_header" type="simple" name-to-remove="table" set-to-remove="bottom">
                        <table class="ODS_grid" style="border: 0px;">
                          <thead>
                      <tr>
                              <th class="checkbox">
                            <input type="checkbox" name="cb_all" value="Select All" onclick="selectAllCheckboxes(this, 'cb_item')"/>
                          </th>
                              <?vsp
                                if (self.cScope = 'events')
                                {
                                  self.sortColumn ('Duration', 'E_EVENT_START', 'e_sortColumn', self.e_order, self.e_direction, 'width="10%"');
                                  self.sortColumn ('Name', 'E_SUBJECT', 'e_sortColumn', self.e_order, self.e_direction, '');
                                  self.columnHeaderShow ('Location', 'E_LOCATION', 'e_sortColumn', self.e_order, self.e_direction, 'event_E_LOCATION', 0, 0, ' width="1%"');
                                  self.columnHeaderShow ('Updated' , 'E_UPDATED' , 'e_sortColumn', self.e_order, self.e_direction, 'event_E_UPDATED' , 1, 1, ' width="1%"');
                                  self.columnHeaderShow ('Created' , 'E_CREATED' , 'e_sortColumn', self.e_order, self.e_direction, 'event_E_CREATED' , 0, 1, ' width="1%"');
                                }
                                else if (self.cScope = 'tasks')
                                {
                                  self.sortColumn ('Name', 'E_SUBJECT', 't_sortColumn', self.ts_order, self.ts_direction, '');
                                  self.columnHeaderShow ('Start'    , 'E_EVENT_START', 't_sortColumn', self.ts_order, self.ts_direction, 'task_E_START',     0, 1, ' width="5%"');
                                  self.columnHeaderShow ('Due'      , 'E_EVENT_END'  , 't_sortColumn', self.ts_order, self.ts_direction, 'task_E_END',       1, 1, ' width="5%"');
                                  self.columnHeaderShow ('Completed', 'E_COMPLETED'  , 't_sortColumn', self.ts_order, self.ts_direction, 'task_E_COMPLETED', 0, 1, ' width="1%"');
                                  self.columnHeaderShow ('Status'   , 'E_STATUS'     , 't_sortColumn', self.ts_order, self.ts_direction, 'task_E_STATUS',    1, 1, ' width="3%"');
                                  self.columnHeaderShow ('Priority' , 'E_PRIORITY'   , 't_sortColumn', self.ts_order, self.ts_direction, 'task_E_PRIORITY',  1, 1, ' width="1%"');
                                  self.columnHeaderShow ('Updated'  , 'E_UPDATED'    , 't_sortColumn', self.ts_order, self.ts_direction, 'task_E_UPDATED',   0, 1, ' width="1%"');
                                  self.columnHeaderShow ('Created'  , 'E_CREATED'    , 't_sortColumn', self.ts_order, self.ts_direction, 'task_E_CREATED',   0, 1, ' width="1%"');
                                }
                                else if (self.cScope = 'search')
                                {
                                  self.sortColumn ('Type'   , 'E_KIND'       , 's_sortColumn', self.s_order, self.s_direction, '');
                                  self.sortColumn ('Item'   , 'E_EVENT_START', 's_sortColumn', self.s_order, self.s_direction, '');
                                  self.sortColumn ('Updated', 'E_UPDATED'    , 's_sortColumn', self.s_order, self.s_direction, '');
                                }
                              ?>
                              <th class="action">Action</th>
                      </tr>
                    </thead>
                  </table>
                </v:template>

                <v:template name="ds_repeat" type="repeat" name-to-remove="" set-to-remove="">

                  <v:template name="ds_browse" type="browse" name-to-remove="table" set-to-remove="both">
                              <?vsp
                                declare e_id, e_event, e_subject, e_kind any;
                                declare rowset vspx_row_template;

                                rowset := (control as vspx_row_template).te_rowset;

                                --  0 - E_ID
                                --  1 - E_DOMAIN_ID
                                --  2 - E_KIND
                                --  3 - E_SUBJECT
                                --  4 - E_EVENT
                                --  5 - E_EVENT_START,
                                --  6 - E_EVENT_END,
                                --  7 - E_REPEAT,
                                --  8 - E_REMINDER,
                                --  9 - E_LOCATION,
                                -- 10 - E_ATTENDEES,
                                -- 11 - E_COMPLETED,
                                -- 12 - E_STATUS,
                                -- 13 - E_PRIORITY,
                                -- 14 - E_CREATED,
                                -- 15 - E_UPDATED

                                e_id := rowset[0];
                                e_event := rowset[4];
                                e_subject := rowset[3];
                                e_kind := rowset[2];
                              ?>
                          <table>
                            <tr class="vevent" typeof="sioct:EventCalendar">
                              <?vsp
                                  http (sprintf ('<td align="center" valign="top" %s>', self.showEventColor (e_id)));
                                if (CAL.WA.event_rights (self.domain_id, e_id, self.account_rights) = 'W')
                                    http (sprintf ('<input type="checkbox" name="cb_item" value="%d" onclick="selectCheck(this, \'cb_item\')" />', e_id));
                                  http ('</td>');
                              ?>
                              <vm:if test="self.cScope = 'events'">
                        <td nowrap="nowrap">
                                  <?vsp self.showEventDuration (e_event, rowset[5], rowset[6]); ?>
                        </td>
                        <td>
                                  <?vsp self.showEventSubject (e_id, e_event, e_subject, rowset[7], rowset[8], rowset[10]); ?>
                        </td>
                        <vm:if test="self.columnEnabled ('event_E_LOCATION', 0)">
                          <td nowrap="nowrap">
                                    <?vsp self.viewField (rowset[9], 'location', null); ?>
                          </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('event_E_UPDATED', 1)">
                        <td nowrap="nowrap">
                                    <?vsp self.viewField (rowset[15], 'last-modified', null); ?>
                        </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('event_E_CREATED', 0)">
                          <td nowrap="nowrap">
                                    <?vsp self.viewField (rowset[14], 'created', null); ?>
                          </td>
                        </vm:if>
                        </vm:if>
            <vm:if test="self.cScope = 'tasks'">
                        <td>
                                  <?vsp self.showEventSubject (e_id, e_event, e_subject, rowset[7], rowset[8], rowset[10]); ?>
                        </td>
                        <vm:if test="self.columnEnabled ('task_E_START', 0)">
                        <td nowrap="nowrap">
                                    <?vsp self.showEventStart (e_event, rowset[5], 'dtstart'); ?>
                        </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('task_E_END', 1)">
                        <td nowrap="nowrap">
                                    <?vsp self.showEventEnd (e_event, rowset[6], 'dtend'); ?>
                        </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('task_E_COMPLETED', 0)">
                        <td nowrap="nowrap">
                                    <?vsp self.showEventEnd (e_event, rowset[11], 'completed'); ?>
                        </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('task_E_STATUS', 1)">
                        <td nowrap="nowrap">
                                    <span style="color: <?V get_keyword (self.colorFieldName (rowset[12]), self.settings, '#000') ?>;"><v:label value="--rowset[12]" /></span>
                        </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('task_E_PRIORITY', 1)">
                          <td nowrap="nowrap">
                                    <?vsp self.viewField (self.priorityLabel(rowset[13]), 'priority', null); ?>
                          </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('task_E_UPDATED', 0)">
                        <td nowrap="nowrap">
                                    <?vsp self.viewField (rowset[15], 'last-modified', null); ?>
                        </td>
                        </vm:if>
                        <vm:if test="self.columnEnabled ('task_E_CREATED', 0)">
                          <td nowrap="nowrap">
                                    <?vsp self.viewField (rowset[14], 'created', null); ?>
                          </td>
                        </vm:if>
            </vm:if>
            <vm:if test="self.cScope = 'search'">
                        <td style="padding: 0 2px 0 2px;">
                          <?vsp
                                    if (e_kind = 0)
                              http ('Event');
                                    else if (e_kind = 1)
                              http ('Task');
                                    else if (e_kind = 2)
                              http ('Note');
                          ?>
                        </td>
                        <td style="padding: 0 2px 0 2px;">
                          <?vsp
                                    self.showEventDuration (e_event, rowset[5], rowset[6]);
                              http ('&nbsp;');
                                    self.showEventSubject (e_id, e_event, e_subject, rowset[7], rowset[8], rowset[10]);
                          ?>
                        </td>
                        <td nowrap="nowrap" style="padding: 0 2px 0 2px;">
                                  <?vsp self.viewField (rowset[15], 'last-modified', null); ?>
                        </td>
                              </vm:if>
                              <?vsp
                                declare permissions, actions any;

                                actions := '';
                                permissions := CAL.WA.event_rights (self.domain_id, e_id, self.account_rights);
                                if (permissions = 'W')
                                {
                                  actions := sprintf ('<span onclick="javascript: vspxPost (\'command\', \'edit\', \'x_%d\'); return false;" class="link">edit</span>', e_id)
                                             || ' | '
                                             || self.windowOpen (sprintf ('annotea.vspx?oid=%d', e_id), 'annotate', e_subject, 'link');
                                }
                                if (CAL.WA.discussion_check () and CAL.WA.conversation_enable (self.domain_id))
                                  actions := actions || either (equ(actions, ''), '', ' | ') || self.windowOpen (sprintf ('conversation.vspx?id=%d', e_id), 'discuss', e_subject, 'link');
                                  http ('<td nowrap="nowrap">' || actions || '</td>');
                              ?>
                      </tr>
                    </table>
                  </v:template>

                </v:template>

                      <v:template name="ds_footer" type="simple" name-to-remove="table" set-to-remove="top">
                  <table>
                  </table>
                </v:template>

                      <span id="ds_navigation">
                        <vm:ds-navigation data-set="ds" />
                </span>

              </v:data-set>
            </vm:if>

              <script type="text/javascript">
                <![CDATA[
                exchangeHTML();
                ]]>
              </script>
          </div>
        </div>
      </vm:if>

      <vm:if test="self.cAction in ('create', 'edit', 'view')">
        <v:text name="timeZone" xhtml_id="timeZone" type="hidden" value="--self.cTimeZone" />
        <v:text name="timeFormat" xhtml_id="timeFormat" type="hidden" value="--self.cTimeFormat" />
        <v:text name="dateFormat" xhtml_id="dateFormat" type="hidden" value="--self.cDateFormat" />
      </vm:if>

            <v:template type="simple" name="template_edit_event" enabled="--case when (self.cAction in ('create', 'edit')) and (self.cSubAction = 'event') then 1 else 0 end">
        <v:before-data-bind>
          <![CDATA[
            declare params any;
            params := self.vc_page.vc_event.ve_params;

            if (isnull (get_keyword ('e_subject', params)))
            {
            declare exit handler for not found goto _end;

                    if (self.cAction = 'edit')
              {
                declare tmp any;

                select E_SUBJECT,
                       E_DESCRIPTION,
                       E_LOCATION,
                             E_ATTENDEES,
                             E_PRIVACY,
                       E_TAGS,
                       E_EVENT,
                             CAL.WA.event_gmt2user (E_EVENT_START, self.cTimezone, self.cDaylight),
                             CAL.WA.event_gmt2user (E_EVENT_END, self.cTimezone, self.cDaylight),
                       E_REPEAT,
                       E_REPEAT_PARAM1,
                       E_REPEAT_PARAM2,
                       E_REPEAT_PARAM3,
                       E_REPEAT_UNTIL,
                       E_REMINDER,
                       E_TAGS,
                             blob_to_string (E_NOTES),
                             E_ACL
                  into self.v_subject,
                       self.v_description,
                       self.v_location,
                             self.v_attendees_count,
                             self.v_privacy,
                       self.v_tags,
                       self.v_event,
                       self.v_eventStart,
                       self.v_eventEnd,
                       self.v_repeat,
                       self.v_repeatParam1,
                       self.v_repeatParam2,
                       self.v_repeatParam3,
                       self.v_repeatUntil,
                       self.v_reminder,
                       self.v_tags,
                             self.v_notes,
                             self.v_acl
                  from CAL.WA.EVENTS
                 where E_ID = self.v_id;

                       self.v_attendees := CAL.WA.attendees_return (self.v_id);
                       self.v_grants := self.shareSelect (self.v_id);
                       self.rdf_iri := SIOC..calendar_event_iri (self.domain_id, self.v_id);
                 return;
              }
            _end:;

              self.initNewEvent ();
              }
          ]]>
        </v:before-data-bind>
              <div class="form-header">
                <v:label format="%s" value="--self.eventHeader (self.v_id, 'event')" />
        </div>
        <div id="e" class="c1">
          <div class="tabs">
                  <div onclick="javascript: showTab('e', 4, 0);" class="tab " id="e_tab_0">Main</div>
                  <div onclick="javascript: showTab('e', 4, 1);" class="tab " id="e_tab_1">Repeats</div>
                  <div onclick="javascript: showTab('e', 4, 2);" class="tab " id="e_tab_2">Notes</div>
                  <div onclick="javascript: showTab('e', 4, 3);" class="tab " id="e_tab_3" style="display: <?V case when self.v_privacy > 1 then '' else 'none' end ?>">Sharing</div>
          </div>
          <div class="contents">
            <div id="e_content_0" class="tabContent" style="display: none;">
              <table class="form-body" cellspacing="0">
            <tr>
                  <th width="25%">
                          <vm:label for="e_subject" value="Name" />
              </th>
              <td>
                          <v:text name="e_subject" xhtml_id="e_subject" null-value="''" value="--self.v_subject" fmt-function="CAL.WA.utf2wide" xhtml_class="textbox" xhtml_size="60" />
              </td>
            </tr>
            <tr>
              <th valign="top">
                <v:label for="e_eventEndDate" value="Duration"/>
              </th>
              <td>
                <table>
                  <tr>
                    <td width="1%">
                      <?vsp
                                  http(sprintf('<input type="checkbox" name="e_event" id="e_event" value="1" %s onchange="javascript: shCell(\'e_eventStartTime\'); shCell(\'e_eventEndTime\');" />', CAL.WA.checkedAttribute (self.v_event, 1)));
                      ?>
                    </td>
                    <td nowrap="nowrap" width="1%" colspan="2">
                                &amp;nbsp;<vm:label for="e_event" value="--'All day event'" />
                    </td>
                  </tr>
                  <tr>
                          <td />
                    <td  width="1%" align="right">
                            From
                    </td>
                    <td>
                                <input type="hidden" name="e_eventStartDate_save" id="e_eventStartDate_save" value="<?V CAL.WA.dt_datestring (self.v_eventStart, self.cDateFormat) ?>" />
                                <v:text name="e_eventStartDate" xhtml_id="e_eventStartDate" null-value="--''" value="--CAL.WA.dt_datestring (self.v_eventStart, self.cDateFormat)" xhtml_onclick="--sprintf ('datePopup(\'e_eventStartDate\', \'%s\', function(){dateUpdate(\'e_eventStartDate\', [\'e_eventEndDate\'], \'%s\');});', self.cDateFormat, self.cDateFormat)" xhtml_onchange="--sprintf ('dateUpdate(\'e_eventStartDate\', [\'e_eventEndDate\'], \'%s\');', self.cDateFormat)" xhtml_class="textbox" xhtml_size="10" />
                                <a href="#" id="e_eventStartDate_select" onclick="datePopup('e_eventStartDate', '<?V self.cDateFormat ?>', function(){dateUpdate('e_eventStartDate', ['e_eventEndDate'], '<?V self.cDateFormat ?>');}); return false;" class="noapp">
                        <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif"/>
                      </a>
                                <v:select-list name="e_eventStartTime" xhtml_id="e_eventStartTime">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x any;

                            x := make_array (48, 'any');
                                      for (N := 0; N < 24; N := N + 1)
                                      {
                              x[2*N]   := CAL.WA.dt_timestring (CAL.WA.dt_timeEncode (N, 0), self.cTimeFormat);
                              x[2*N+1] := CAL.WA.dt_timestring (CAL.WA.dt_timeEncode (N, 30), self.cTimeFormat);
                            }
                            control.vsl_item_values := x;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := CAL.WA.dt_timestring (CAL.WA.dt_timeCeiling (self.v_eventStart, 30), self.cTimeFormat);
                          ]]>
                        </v:before-data-bind>
                                  <v:after-data-bind>
                                    <![CDATA[
                                      if (cast (get_keyword ('e_event', self.vc_page.vc_event.ve_params, self.v_event) as integer) = 1)
                                      {
                                        control.vc_add_attribute ('style', 'display: none;');
                                      }
                                    ]]>
                                  </v:after-data-bind>
                      </v:select-list>
                    </td>
                  </tr>
                  <tr>
                    <td />
                    <td  width="1%" align="right">
                            To
                    </td>
                    <td>
                                <v:text name="e_eventEndDate" xhtml_id="e_eventEndDate" null-value="--''" value="--CAL.WA.dt_datestring (self.v_eventEnd, self.cDateFormat)" xhtml_onclick="--sprintf ('datePopup(\'e_eventEndDate\', \'%s\');', self.cDateFormat)" xhtml_class="textbox" xhtml_size="10" />
                                <a href="#" id="e_eventEndDate_select" onclick="datePopup('e_eventEndDate', '<?V self.cDateFormat ?>'); return false;" class="noapp">
                        <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif"/>
                      </a>
                                <v:select-list name="e_eventEndTime" xhtml_id="e_eventEndTime">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x any;

                            x := make_array (48, 'any');
                            for (N := 0; N < 24; N := N + 1) {
                              x[2*N]   := CAL.WA.dt_timestring (CAL.WA.dt_timeEncode (N, 0), self.cTimeFormat);
                              x[2*N+1] := CAL.WA.dt_timestring (CAL.WA.dt_timeEncode (N, 30), self.cTimeFormat);
                            }
                            control.vsl_item_values := x;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := CAL.WA.dt_timestring (CAL.WA.dt_timeCeiling (self.v_eventEnd, 30), self.cTimeFormat);
                          ]]>
                        </v:before-data-bind>
                                  <v:after-data-bind>
                                    <![CDATA[
                                      if (cast (get_keyword ('e_event', self.vc_page.vc_event.ve_params, self.v_event) as integer) = 1)
                                      {
                                        control.vc_add_attribute ('style', 'display: none;');
                                      }
                                    ]]>
                                  </v:after-data-bind>
                      </v:select-list>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>
                  <th valign="top">
                          <vm:label for="e_description" value="Description" />
              </th>
              <td>
                          <v:textarea name="e_description" xhtml_id="e_description" null-value="--''" value="--self.v_description" fmt-function="CAL.WA.utf2wide" xhtml_cols="45" xhtml_rows="6" />
              </td>
            </tr>
            <tr>
              <th>
                          <vm:label for="e_location" value="Location" />
              </th>
              <td>
                          <v:text name="e_location" xhtml_id="e_location" null-value="''" value="--self.v_location" fmt-function="CAL.WA.utf2wide" xhtml_class="textbox" xhtml_size="60" />
              </td>
            </tr>
            <tr>
                  <th>
                    <vm:label for="e_reminder" value="--'Reminder'" />
                  </th>
                  <td>
                          <v:select-list name="e_reminder" xhtml_id="e_reminder">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x, y any;

                            self.arrays4Reminder (x, y);
                            control.vsl_item_values := y;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.v_reminder;
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                  </td>
                </tr>
                      <vm:if test="(self.cAction = 'create') or (CAL.WA.event_domain (self.v_id) = self.domain_id)">
                <tr>
                        <th>
                          <vm:label for="e_privacy" value="--'Privacy'" />
                        </th>
                        <td>
                            <v:select-list name="e_privacy" xhtml_id="e_privacy" xhtml_onchange="javascript: (this.value == \'2\')? OAT.Dom.show(\'e_tab_3\'): OAT.Dom.hide(\'e_tab_3\');">
                            <v:item value="0" name="Private" />
                              <v:item value="2" name="ACL" />
                            <v:item value="1" name="Public" />
                            <v:before-data-bind>
                              <![CDATA[
                                control.ufl_value := self.v_privacy;
                              ]]>
                            </v:before-data-bind>
                          </v:select-list>
                        </td>
                      </tr>
                      </vm:if>
                      <tr>
                        <th valign="top">
                          <vm:label for="e_attendees" value="Attendees" />
                        </th>
                        <td valign="top">
                          <v:textarea name="e_attendees" xhtml_id="e_attendees" null-value="--''" value="--self.v_attendees" fmt-function="CAL.WA.utf2wide" xhtml_cols="45" xhtml_rows="6" />
                          <?vsp
                            if (CAL.WA.instance_check (self.account_id, 'AddressBook'))
                              http (self.windowOpen('contacts.vspx?dst=mc&params=e_attendees:s1;', 'Select', 'Select', 'button'));
                            if (self.v_attendees_count)
                              http (self.windowOpen('attendees.vspx?id=' || cast (self.v_id as varchar), 'Details', 'Details', 'button'));
                          ?>
                        </td>
                      </tr>
                      <tr>
                  <th>
                          <vm:label for="e_tags" value="Tags (comma-separated)" />
                  </th>
                  <td>
                          <v:text name="e_tags" xhtml_id="e_tags" null-value="''" value="--self.v_tags" xhtml_class="textbox" xhtml_size="60" />
                          <?vsp if (CAL.WA.tag_rule_exists (self.account_id)) { ?>
                            <input type="button" value="Suggest" onclick="javascript: tagsShow('<?V CAL.WA.page_url (self.domain_id, 'tags.vspx?fld=e_tags') ?>', 'e');" class="button" />
                          <?vsp } ?>
                      <input type="button" value="Clear" onclick="javascript: document.F1.elements['e_tags'].value = ''" class="button" />
                  </td>
                </tr>
                  <?vsp self.myTags ('e_tags'); ?>
              </table>
            </div>
            <div id="e_content_1" class="tabContent" style="display: none;">
              <table class="form-body" cellspacing="0">
                <tr>
                  <th width="25%" valign="top">
                          Repeats
              </th>
              <td>
                <table>
                  <tr>
                    <td />
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_0" value="" %s />', CAL.WA.checkedAttribute (self.v_repeat, '')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_0" value="--'No repeat'" />
                    </td>
                  </tr>
                  <tr>
                    <td width="1%" rowspan="2" valign="top">
                      Daily
                    </td>
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_1" value="D1" %s />', CAL.WA.checkedAttribute (self.v_repeat, 'D1')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_1" value="--'Every'" />
                      <v:text name="e_repeat_param1_D1" null-value="''" value="--self.repeatParam (self.v_repeat, 'D1', 1, null);" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_1\');'" xhtml_class="textbox" xhtml_size="1" /> day(s)
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_2" value="D2" %s />', CAL.WA.checkedAttribute (self.v_repeat, 'D2')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_2" value="--'Every weekday (Monday-Friday)'" />
                    </td>
                  </tr>
                  <tr>
                    <td>
                      Weekly
                    </td>
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_3" value="W1" %s />', CAL.WA.checkedAttribute (self.v_repeat, 'W1')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_3" value="--'Every'" />
                      <v:text name="e_repeat_param1_W1" null-value="''" value="--self.repeatParam (self.v_repeat, 'W1', 1, null);" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_3\');'" xhtml_class="textbox" xhtml_size="1" /> week(s) on
                      <?vsp
                        http (sprintf ('<input type="checkbox" value="1" %s name="e_repeat_param2_W1_0" onfocus="checkRepetition (\'e_repeat\', \'e_repeat_3\');" /> M', case when is_empty_or_null (self.repeatParam (self.v_repeat, 'W1', 2, 0)) then '' else 'checked="checked"' end));
                        http (sprintf ('<input type="checkbox" value="1" %s name="e_repeat_param2_W1_1" onfocus="checkRepetition (\'e_repeat\', \'e_repeat_3\');" /> T', case when is_empty_or_null (self.repeatParam (self.v_repeat, 'W1', 2, 1)) then '' else 'checked="checked"' end));
                        http (sprintf ('<input type="checkbox" value="1" %s name="e_repeat_param2_W1_2" onfocus="checkRepetition (\'e_repeat\', \'e_repeat_3\');" /> W', case when is_empty_or_null (self.repeatParam (self.v_repeat, 'W1', 2, 2)) then '' else 'checked="checked"' end));
                        http (sprintf ('<input type="checkbox" value="1" %s name="e_repeat_param2_W1_3" onfocus="checkRepetition (\'e_repeat\', \'e_repeat_3\');" /> T', case when is_empty_or_null (self.repeatParam (self.v_repeat, 'W1', 2, 3)) then '' else 'checked="checked"' end));
                        http (sprintf ('<input type="checkbox" value="1" %s name="e_repeat_param2_W1_4" onfocus="checkRepetition (\'e_repeat\', \'e_repeat_3\');" /> F', case when is_empty_or_null (self.repeatParam (self.v_repeat, 'W1', 2, 4)) then '' else 'checked="checked"' end));
                        http (sprintf ('<input type="checkbox" value="1" %s name="e_repeat_param2_W1_5" onfocus="checkRepetition (\'e_repeat\', \'e_repeat_3\');" /> S', case when is_empty_or_null (self.repeatParam (self.v_repeat, 'W1', 2, 5)) then '' else 'checked="checked"' end));
                        http (sprintf ('<input type="checkbox" value="1" %s name="e_repeat_param2_W1_6" onfocus="checkRepetition (\'e_repeat\', \'e_repeat_3\');" /> S', case when is_empty_or_null (self.repeatParam (self.v_repeat, 'W1', 2, 6)) then '' else 'checked="checked"' end));
                      ?>
                    </td>
                  </tr>
                  <tr>
                    <td rowspan="2" valign="top">
                      Monthly
                    </td>
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_4" value="M1" %s />', CAL.WA.checkedAttribute (self.v_repeat, 'M1')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_4" value="--'Every'" />
                      <v:select-list name="e_repeat_param1_M1" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_4\');'" >
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x any;

                            x := make_array (12, 'any');
                            for (N := 0; N < 12; N := N + 1)
                              x[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := x;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'M1', 1, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                      month(s) on
                      <v:select-list name="e_repeat_param2_M1" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_4\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x any;

                            x := make_array (31, 'any');
                            for (N := 0; N < 31; N := N + 1)
                              x[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := x;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'M1', 2, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                      day
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_5" value="M2" %s />', CAL.WA.checkedAttribute (self.v_repeat, 'M2')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_5" value="--'Every'" />
                      <v:select-list name="e_repeat_param1_M2" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_5\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x any;

                            x := make_array (12, 'any');
                            for (N := 0; N < 12; N := N + 1)
                              x[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := x;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'M2', 1, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                      month(s) on the
                      <v:select-list name="e_repeat_param2_M2" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_5\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x, y any;

                            x := make_array (5, 'any');
                            x[0] := 'first';
                            x[1] := 'second';
                            x[2] := 'third';
                            x[3] := 'fourth';
                            x[4] := 'last';
                            y := make_array (5, 'any');
                            for (N := 0; N < 5; N := N + 1)
                              y[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := y;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'M2', 2, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                      <v:select-list name="e_repeat_param3_M2" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_5\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x, y any;

                            x := make_array (10, 'any');
                            x[0] := 'Day';
                            x[1] := 'Weekday';
                            x[2] := 'Weekend';
                            x[3] := 'Monday';
                            x[4] := 'Tuesday';
                            x[5] := 'Wednesday';
                            x[6] := 'Thursday';
                            x[7] := 'Friday';
                                      x[8] := 'Saturday';
                                      x[9] := 'Sunday';
                            y:= make_array (10, 'any');
                            y[0] := '10';
                            y[1] := '11';
                            y[2] := '12';
                            y[3] := '1';
                            y[4] := '2';
                            y[5] := '3';
                            y[6] := '4';
                            y[7] := '5';
                            y[8] := '6';
                            y[9] := '7';
                            control.vsl_item_values := y;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'M2', 3, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                   </td>
                  </tr>
                  <tr>
                    <td rowspan="2" valign="top">
                      Yearly
                    </td>
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_6" value="Y1" %s />', CAL.WA.checkedAttribute (self.v_repeat, 'Y1')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_6" value="--'Every'" />
                      <v:text name="e_repeat_param1_Y1" null-value="''" value="--self.repeatParam (self.v_repeat, 'Y1', 1, null);" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_6\');'" xhtml_class="textbox" xhtml_size="1" /> year(s)
                      on
                      <v:select-list name="e_repeat_param2_Y1" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_6\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x, y any;

                            x := make_array (12, 'any');
                            x[0] := 'January';
                            x[1] := 'February';
                            x[2] := 'March';
                            x[3] := 'April';
                            x[4] := 'May';
                            x[5] := 'June';
                            x[6] := 'July';
                            x[7] := 'August';
                            x[8] := 'September';
                            x[9] := 'October';
                            x[10]:= 'November';
                            x[11]:= 'December';
                            y:= make_array (12, 'any');
                            for (N := 0; N < 12; N := N + 1)
                              y[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := y;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'Y1', 2, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                      <v:select-list name="e_repeat_param3_Y1" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_6\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x any;

                            x := make_array (31, 'any');
                            for (N := 0; N < 31; N := N + 1)
                              x[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := x;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'Y1', 3, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                    </td>
                  </tr>
                  <tr>
                    <td>
                      <?vsp
                                  http(sprintf('<input type="radio" name="e_repeat" id="e_repeat_7" value="Y2" %s />', CAL.WA.checkedAttribute (self.v_repeat, 'Y2')));
                      ?>
                                &amp;nbsp;
                      <vm:label for="e_repeat_7" value="--'The'" />
                      <v:select-list name="e_repeat_param1_Y2" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_7\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x, y any;

                            x := make_array (5, 'any');
                            x[0] := 'first';
                            x[1] := 'second';
                            x[2] := 'third';
                            x[3] := 'fourth';
                            x[4] := 'last';
                            y := make_array (5, 'any');
                            for (N := 0; N < 5; N := N + 1)
                              y[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := y;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'Y2', 1, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                      <v:select-list name="e_repeat_param2_Y2" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_7\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x, y any;

                            x := make_array (10, 'any');
                            x[0] := 'Day';
                            x[1] := 'Weekday';
                            x[2] := 'Weekend';
                            x[3] := 'Monday';
                            x[4] := 'Tuesday';
                            x[5] := 'Wednesday';
                            x[6] := 'Thursday';
                            x[7] := 'Friday';
                            x[8] := 'Saturday';
                            x[9] := 'Sunday';
                            y:= make_array (10, 'any');
                            y[0] := '10';
                            y[1] := '11';
                            y[2] := '12';
                            y[3] := '1';
                            y[4] := '2';
                            y[5] := '3';
                            y[6] := '4';
                            y[7] := '5';
                            y[8] := '6';
                            y[9] := '7';
                            control.vsl_item_values := y;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'Y2', 2, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                      of
                      <v:select-list name="e_repeat_param3_Y2" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeat\', \'e_repeat_7\');'">
                        <v:on-init>
                          <![CDATA[
                            declare N integer;
                            declare x, y any;

                            x := make_array (12, 'any');
                            x[0] := 'January';
                            x[1] := 'February';
                            x[2] := 'March';
                            x[3] := 'April';
                            x[4] := 'May';
                            x[5] := 'June';
                            x[6] := 'July';
                            x[7] := 'August';
                            x[8] := 'September';
                            x[9] := 'October';
                            x[10]:= 'November';
                            x[11]:= 'December';
                            y:= make_array (12, 'any');
                            for (N := 0; N < 12; N := N + 1)
                              y[N] := cast ((N+1) as varchar);
                            control.vsl_item_values := y;
                            control.vsl_items := x;
                            control.ufl_value := '';
                          ]]>
                        </v:on-init>
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.repeatParam (self.v_repeat, 'Y2', 3, null);
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr>
              <th valign="top">
                <v:label for="e_repeat_range" value="Repeats range"/>
              </th>
              <td>
                  <table>
                    <tr>
                      <td>
                <?vsp
                  declare S varchar;

                  S := '';
                  if (isnull (self.v_repeatUntil))
                    S := 'checked="checked"';
                  http(sprintf('<input type="radio" name="e_repeatUntilKind" id="e_repeatUntilKind_0" value="0" %s />', S));
                ?>
                                &amp;nbsp;
                <vm:label for="e_repeatUntilKind_0" value="--'No end date'" />
              </td>
            </tr>
            <tr>
              <td>
                <?vsp
                  declare S varchar;

                  S := '';
                  if (not isnull (self.v_repeatUntil))
                    S := 'checked="checked"';
                  http(sprintf('<input type="radio" name="e_repeatUntilKind" id="e_repeatUntilKind_1" value="1" %s />', S));
                ?>
                                &amp;nbsp;
                <vm:label for="e_repeatUntilKind_1" value="--'Until'" />
                                &amp;nbsp;
                                <v:text name="e_repeatUntil" xhtml_id="e_repeatUntil" null-value="--''" value="--CAL.WA.dt_datestring (self.v_repeatUntil, self.cDateFormat)" xhtml_onfocus="--'javascript: checkRepetition (\'e_repeatUntilKind\', \'e_repeatUntilKind_1\');'" xhtml_onclick="--sprintf ('datePopup(\'e_repeatUntil\', \'%s\');', self.cDateFormat)" xhtml_class="textbox" xhtml_size="10" />
                                <a href="#" id="e_repeatUntil_select" onclick="datePopup('e_repeatUntil', '<?V self.cDateFormat ?>'); return false;" class="noapp">
                  <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif"/>
                </a>
              </td>
            </tr>
                  </table>
                  </td>
                </tr>
              </table>
            </div>
            <div id="e_content_2" class="tabContent" style="display: none;">
              <table class="form-body" cellspacing="0">
                <tr>
                  <th width="20%" valign="top">
                    Notes
                  </th>
                  <td>
                          <textarea id="e_notes" name="e_notes" style="width: 400; height: 170"><?vsp http (coalesce (self.v_notes, '')); ?></textarea>
                      <![CDATA[
                            <script type="text/javascript" src="/ods/ckeditor/ckeditor.js"></script>
                            <script type="text/javascript">
                              var oEditor = CKEDITOR.replace('e_notes');
                        </script>
                      ]]>
                  </td>
                </tr>
              </table>
            </div>
                  <div id="e_content_3" class="tabContent" style="display: none;">
                    <fieldset>
                      <legend><b>ODS users</b></legend>
                      <table class="form-body" cellspacing="0">
                        <tr>
                          <td style="width: 90%; background-color: white;">
                            <table id="f_tbl" class="ODS_grid">
                              <thead>
                                <tr>
                                  <th width="100%">Value</th>
                                  <th class="action">Action</th>
                                </tr>
                              </thead>
                        		  <![CDATA[
                        		    <script type="text/javascript">
                                <?vsp
                                  declare N, L integer;
                                  declare acl_values any;

                                  L := 0;
                                  acl_values := split_and_decode (self.v_grants, 0, '\0\0,');
                                  for (N := 0; N < length (acl_values); N := N + 1)
                                  {
                                    L := 1;
                                    if (self.cAction <> 'view')
                                    {
                                      http (sprintf ('OAT.MSG.attach(OAT, "PAGE_LOADED", function(){TBL.createRow("f", null, {fld_1: {mode: 1, value: "%s", form: "F1"}});});', acl_values[N], 'U'));
                                    } else {
                                      http (sprintf ('OAT.MSG.attach(OAT, "PAGE_LOADED", function(){TBL.createViewRow("f", {fld_1: {value: "%s"}});});', acl_values[N]));
                                    }
                                  }
                                ?>
                        		    </script>
                        		  ]]>
                              <tr id="f_tr_no" style="display: <?V case when L=0 then '' else 'none' end ?>;"><td colspan="<?V case when self.cAction='view' then 1 else 2 end ?>"><b>No Shares</b></td></tr>
                        		</table>
                        	</td>
                          <vm:if test="self.cAction <> 'view'">
                            <td valign="top" nowrap="nowrap">
                              <img class="pointer" src="/ods/images/icons/add_16.png" border="0" alt="Add Share" title="Add Share" onclick="javascript: TBL.createRow('f', null, {fld_1: {mode: 1, form: 'F1'}});" />
                            </td>
                          </vm:if>
                        </tr>
                      </table>
                    </fieldset>
                    <fieldset>
                      <legend><b>WebID users</b></legend>
                    <table class="form-body" cellspacing="0">
                      <tr>
                        <td style="width: 90%; background-color: white;">
                            <table id="s_tbl" class="ODS_grid">
                              <thead>
                              <tr>
                                <th width="15%">Type</th>
                                <th>Value</th>
                                <th width="1%" nowrap="nowrap">ACL: (R)ead, (W)rite</th>
                                  <th class="action">Action</th>
                              </tr>
                            </thead>
                              <tbody id="s_tbody">
                                <tr id="s_tr_no"><td colspan="4"><b>No Shares</b></td></tr>
                      		  <![CDATA[
                      		    <script type="text/javascript">
                            <?vsp
                                    declare acl any;

                              acl := (select WAI_ACL from DB.DBA.WA_INSTANCE where WAI_ID = self.domain_id);
                              acl := case when isnull (acl) then vector () else deserialize (acl) end;
                                    DB.DBA.wa_aci_lines (acl);

                              acl := deserialize (self.v_acl);
                                    DB.DBA.wa_aci_lines (acl, self.cAction);
                           		    ?>
                           		    </script>
                           		  ]]>
                              </tbody>
                          </table>
                        </td>
                        <vm:if test="self.cAction <> 'view'">
                        <td valign="top" nowrap="nowrap">
                            <img class="pointer" src="/ods/images/icons/add_16.png" border="0" alt="Add Share" title="Add Share" onclick="javascript: TBL.createRow('s', null, {fld_1: {mode: 50, onchange: function(){TBL.changeCell50(this);}}, fld_2: {mode: 51, form: 'F1', tdCssText: 'white-space: nowrap;', className: '_validate_ _webid_'}, fld_3: {mode: 52, value: [1, 0, 0], tdCssText: 'width: 1%; white-space: nowrap; text-align: center;'}});" />
                        </td>
                        </vm:if>
                      </tr>
                    </table>
                    </fieldset>
                  </div>
          </div>
        </div>
              <div class="form-footer">
                <v:button action="simple" name="e_create" value="--case when (self.cAction = 'create') then 'Create' else 'Update' end" xhtml_class="form-button" xhtml_onclick="return validateInputs(this);">
            <v:on-post>
              <![CDATA[
                self.saveEvent ();
                if (not self.vc_is_valid)
                  return;

                      commit work;
                self.cAction := 'browse';
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
                <v:button action="simple" name="e_create_new" value="Create and New" enabled="--case when (self.cAction = 'create') then 1 else 0 end" xhtml_class="form-button" xhtml_onclick="return validateInputs(this);">
            <v:on-post>
              <![CDATA[
                self.saveEvent ();
                if (not self.vc_is_valid)
                  return;

                      commit work;
                self.initNewEvent ();
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
                <v:button action="simple" name="e_cancel" value="Cancel" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                      commit work;
                self.cAction := 'browse';
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        </div>
      </v:template>

            <v:template type="simple" name="template_view_event" enabled="--case when (self.cAction = 'view') and (self.cSubAction = 'event') then 1 else 0 end">
        <v:before-data-bind>
          <![CDATA[
            declare exit handler for not found goto _end;

            select E_SUBJECT,
                   E_DESCRIPTION,
                   E_LOCATION,
                         E_ATTENDEES,
                         E_PRIVACY,
                   E_TAGS,
                   E_EVENT,
                         E_EVENT_START,
                         E_EVENT_END,
                   E_REPEAT,
                   E_REPEAT_PARAM1,
                   E_REPEAT_PARAM2,
                   E_REPEAT_PARAM3,
                   E_REPEAT_UNTIL,
                   E_REMINDER,
                   E_TAGS,
                   blob_to_string (E_NOTES)
              into self.v_subject,
                   self.v_description,
                   self.v_location,
                         self.v_attendees_count,
                         self.v_privacy,
                   self.v_tags,
                   self.v_event,
                   self.v_eventStart,
                   self.v_eventEnd,
                   self.v_repeat,
                   self.v_repeatParam1,
                   self.v_repeatParam2,
                   self.v_repeatParam3,
                   self.v_repeatUntil,
                   self.v_reminder,
                   self.v_tags,
                   self.v_notes
              from CAL.WA.EVENTS
             where E_ID = self.v_id;

                  self.v_attendees := CAL.WA.attendees_return (self.v_id);
                  self.rdf_iri := SIOC..calendar_event_iri (self.domain_id, self.v_id);
            return;

          _end:;
            self.initNewEvent ();
          ]]>
        </v:before-data-bind>
              <div class="form-header">
                <v:label format="%s" value="--self.eventHeader (self.v_id, 'event')" />
        </div>
              <div id="t" class="c1">
                <div class="tabs">
                  <div onclick="javascript: showTab('t', 2, 0);" class="tab " id="t_tab_0">Main</div>
                  <vm:if test="not isnull (__proc_exists ('QRcode encodeString8bit', 2))">
                  <div onclick="javascript: showTab('t', 2, 1);" class="tab " id="t_tab_1">QRCode</div>
                  </vm:if>
                </div>
                <div class="contents vevent" typeof="sioct:EventCalendar" about="<?V SIOC..calendar_event_iri (self.domain_id, self.v_id) ?>">
                  <div id="t_content_0" class="tabContent" style="display: none;">
                    <table class="form-body" cellspacing="0">
            <tr>
              <th width="25%">
                Name
              </th>
              <td>
                      <?vsp self.viewField (self.v_subject, 'summary', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                Duration
              </th>
              <td>
                      <?vsp self.showEventDuration (self.v_event, self.v_eventStart, self.v_eventEnd); ?>
              </td>
            </tr>
            <tr>
              <th valign="top">
                Description
              </th>
              <td>
                      <?vsp self.viewField (self.v_description, 'description', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                Location
              </th>
              <td>
                      <?vsp self.viewField (self.v_location, 'location', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                Reminder
              </th>
              <td>
                <?vsp
                  declare N integer;
                  declare x, y any;

                  self.arrays4Reminder (x, y);
                  N := CAL.WA.vector_indexOf (y, cast (self.v_reminder as varchar), 0);
                        self.viewField (x [N], '', null);
                ?>
              </td>
            </tr>
            <tr>
              <th>
                Tags
              </th>
              <td>
                      <?vsp self.viewTags (self.v_tags); ?>
              </td>
            </tr>
            <tr>
              <th>
                Repeats
              </th>
              <td>
                <?vsp
                  self.viewField (CAL.WA.vcal_recurrence2str (self.v_repeat,
                                                              self.v_RepeatParam1,
                                                              self.v_RepeatParam2,
                                                              self.v_RepeatParam3,
                                                              self.v_repeatUntil
                                                                   ),
                                        '',
                                        null
                                 );
                ?>
              </td>
            </tr>
            <tr>
              <th>
                Repeats range
              </th>
              <td>
                      <?vsp self.viewField (self.v_repeatUntil, '', null); ?>
              </td>
            </tr>
            <tr>
              <th valign="top">
                Notes
              </th>
              <td>
                      <?vsp self.viewField (self.v_notes, '', null); ?>
              </td>
            </tr>
          </table>
        </div>
                  <div id="t_content_1" class="tabContent" style="display: none;">
              		  <?vsp
              		    declare vcard, qrcode any;

        		          vcard := CAL.WA.export_vcal (self.domain_id, vector (self.v_id));
                      qrcode := ODS.ODS_API.qrcode (vcard, 120, 120, 3);
        		        ?>
                    <table class="form-body" cellspacing="0">
                      <tr>
                        <td align="center">
                    		  <?vsp
                            if (qrcode is not null)
	                            http (sprintf ('<img id="qrcode" src="data:image/jpg;base64,%s"/>', qrcode));
              		        ?>
                        </td>
                      </tr>
                      <tr>
                        <td align="center">
                          <b>iCal Event Data</b>
                        </td>
                      </tr>
                    </table>
                  </div>
                </div>
              </div>
              <div class="form-footer">
                <v:button action="simple" name="ev_edit" value="Edit" enabled="--case when CAL.WA.event_rights (self.domain_id, self.v_id, self.account_rights) = 'W' then 1 else 0 end" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      self.cAction := 'edit';
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
                <v:button action="simple" name="ev_cancel" value="Back" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.cAction := 'browse';
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        </div>
      </v:template>

            <v:template type="simple" name="template_edit_task" enabled="--case when (self.cAction in ('create', 'edit')) and (self.cSubAction = 'task') then 1 else 0 end">
        <v:before-data-bind>
          <![CDATA[
                  if (isnull (get_keyword ('t_subject', self.vc_page.vc_event.ve_params)))
                  {
              declare exit handler for not found goto _end;

                    if (self.cAction = 'edit')
                    {
                declare tmp any;

                select E_SUBJECT,
                       E_DESCRIPTION,
                             E_ATTENDEES,
                             E_PRIVACY,
                       E_TAGS,
                             CAL.WA.event_gmt2user (E_EVENT_START, self.cTimezone, self.cDaylight),
                             CAL.WA.event_gmt2user (E_EVENT_END, self.cTimezone, self.cDaylight),
                             CAL.WA.event_gmt2user (E_COMPLETED, self.cTimezone, self.cDaylight),
                       E_PRIORITY,
                       E_STATUS,
                       E_COMPLETE,
                             blob_to_string (E_NOTES),
                             E_ACL
                  into self.v_subject,
                       self.v_description,
                             self.v_attendees_count,
                             self.v_privacy,
                       self.v_tags,
                       self.v_eventStart,
                       self.v_eventEnd,
                       self.v_completed,
                       self.v_priority,
                       self.v_status,
                       self.v_complete,
                             self.v_notes,
                             self.v_acl
                  from CAL.WA.EVENTS
                 where E_ID = self.v_id;

                       self.v_attendees := CAL.WA.attendees_return (self.v_id);
                       self.v_grants := self.shareSelect (self.v_id);
                       self.rdf_iri := SIOC..calendar_event_iri (self.domain_id, self.v_id);
                 return;
              }
            _end:;

              self.initNewTask ();
            }
          ]]>
        </v:before-data-bind>
              <div class="form-header">
                <v:label format="%s" value="--self.eventHeader (self.v_id, 'task')" />
        </div>
        <div id="t" class="c1">
          <div class="tabs">
                  <div onclick="javascript: showTab('t', 4, 0);" class="tab " id="t_tab_0">Main</div>
                  <div onclick="javascript: showTab('t', 4, 1);" class="tab " id="t_tab_1">Notes</div>
                  <div onclick="javascript: showTab('t', 4, 2);" class="tab " id="t_tab_2" style="display: <?V case when self.v_privacy > 1 then '' else 'none' end ?>">Sharing</div>
          </div>
          <div class="contents">
            <div id="t_content_0" class="tabContent" style="display: none;">
              <table class="form-body" cellspacing="0">
            <tr>
                  <th width="25%">
                          <vm:label for="t_subject" value="Name" />
              </th>
              <td>
                          <v:text name="t_subject" xhtml_id="t_subject" null-value="''" value="--self.v_subject" fmt-function="CAL.WA.utf2wide" xhtml_class="textbox" xhtml_size="60" />
              </td>
            </tr>
            <tr>
              <th>
                          <vm:label for="t_eventStartDate" value="Start Date" />
              </th>
              <td>
                          <input type="hidden" name="t_eventStartDate_save" id="t_eventStartDate_save" value="<?V CAL.WA.dt_datestring (self.v_eventStart, self.cDateFormat) ?>" />
                          <v:text name="t_eventStartDate" xhtml_id="t_eventStartDate" null-value="--''" value="--CAL.WA.dt_datestring (self.v_eventStart, self.cDateFormat)" xhtml_onclick="--sprintf ('datePopup(\'t_eventStartDate\', \'%s\', function(){dateUpdate(\'t_eventStartDate\', [\'t_eventEndDate\'], \'%s\');});', self.cDateFormat, self.cDateFormat)" xhtml_onchange="--sprintf ('dateUpdate(\'t_eventStartDate\', [\'t_eventEndDate\'], \'%s\');', self.cDateFormat)" xhtml_class="textbox" xhtml_size="10" />
                          <a href="#" id="t_eventStartDate_select" onclick="datePopup('t_eventStartDate', '<?V self.cDateFormat ?>', function(){dateUpdate('t_eventStartDate', ['t_eventEndDate'], '<?V self.cDateFormat ?>');}); return false;" class="noapp">
                  <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif"/>
                </a>
              </td>
            </tr>
            <tr>
              <th>
                          <vm:label for="t_eventEndDate" value="Due Date" />
              </th>
              <td>
                          <v:text name="t_eventEndDate" xhtml_id="t_eventEndDate" null-value="--''" value="--CAL.WA.dt_datestring (self.v_eventEnd, self.cDateFormat)" xhtml_onclick="--sprintf ('datePopup(\'t_eventEndDate\', \'%s\');', self.cDateFormat)" xhtml_onchange="dateUpdate(\'t_eventEndDate\', [\'t_eventStartDate\']);" xhtml_class="textbox" xhtml_size="10" />
                          <a href="#" id="t_eventEndDate_select" onclick="datePopup('t_eventEndDate', '<?V self.cDateFormat ?>'); return false;" class="noapp">
                  <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif"/>
                </a>
              </td>
            </tr>
            <tr>
              <th>
                          <vm:label for="t_priority" value="Priority" />
              </th>
              <td>
                          <v:select-list name="t_priority" xhtml_id="t_priority">
                  <v:on-init>
                    <![CDATA[
                      declare N integer;
                      declare x, y any;

                      x := make_array (5, 'any');
                      x[0] := 'Highest';
                      x[1] := 'High';
                      x[2] := 'Normal';
                      x[3] := 'Low';
                      x[4] := 'Lowest';
                      y := make_array (5, 'any');
                      for (N := 0; N < 5; N := N + 1)
                        y[N] := cast ((N+1) as varchar);
                      control.vsl_item_values := y;
                      control.vsl_items := x;
                      control.ufl_value := '3';
                    ]]>
                  </v:on-init>
                  <v:before-data-bind>
                    <![CDATA[
                      control.ufl_value := self.v_priority;
                    ]]>
                  </v:before-data-bind>
                </v:select-list>
              </td>
            </tr>
            <tr>
              <th>
                          <vm:label for="t_status" value="Status" />
              </th>
              <td>
                          <v:select-list name="t_status" xhtml_id="t_status" xhtml_onchange="javascript: changeComplete(this);">
                  <v:on-init>
                    <![CDATA[
                      declare x any;

                                x := vector ('Not Started', 'In Progress', 'Completed', 'Waiting', 'Deferred');
                      control.vsl_item_values := x;
                      control.vsl_items := x;
                      control.ufl_value := '';
                    ]]>
                  </v:on-init>
                  <v:before-data-bind>
                    <![CDATA[
                      control.ufl_value := self.v_status;
                    ]]>
                  </v:before-data-bind>
                </v:select-list>
              </td>
            </tr>
            <tr>
              <th>
                          <vm:label for="t_completed" value="Completed" />
                        </th>
                        <td>
                          <v:text name="t_completed" xhtml_id="t_completed" null-value="--''" value="--CAL.WA.dt_datestring (self.v_completed, self.cDateFormat)" xhtml_onclick="--sprintf ('datePopup(\'t_completed\', \'%s\'); changeComplete(this);', self.cDateFormat)" xhtml_class="textbox" xhtml_size="10" xhtml_onchange="javascript: changeComplete(this);"/>
                          <a href="#" id="t_completed_select" onclick="datePopup('t_completed', '<?V self.cDateFormat ?>'); changeComplete('t_completed'); return false;" class="noapp">
                            <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif" />
                          </a>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          <vm:label for="t_complete" value="Complete (%)" />
              </th>
              <td>
                          <v:select-list name="t_complete" xhtml_id="t_complete" xhtml_onchange="javascript: changeComplete(this);">
                  <v:on-init>
                    <![CDATA[
                      declare x any;

                                x := vector ('0', '25', '50', '75', '100');
                      control.vsl_item_values := x;
                      control.vsl_items := x;
                      control.ufl_value := '0';
                    ]]>
                  </v:on-init>
                  <v:before-data-bind>
                    <![CDATA[
                                if (not isnull (self.v_complete))
                                {
                                  if (not CAL.WA.vector_contains (control.vsl_item_values, self.v_complete))
                                  {
                                    declare N, isAdded integer;
                                    declare x any;

                                    isAdded := 0;
                                    x := vector ();
                                    for (N := 0; N < length (control.vsl_item_values); N := N + 1)
                                    {
                                      if (not isAdded and (self.v_complete < atoi (control.vsl_item_values[N])))
                                      {
                                        isAdded := 1;
                                        x := vector_concat (x, vector (cast (self.v_complete as varchar)));
                                      }
                                      x := vector_concat (x, vector (control.vsl_item_values[N]));
                                    }
                                    control.vsl_item_values := x;
                                    control.vsl_items := x;
                                  }
                                }
                      control.ufl_value := self.v_complete;
                    ]]>
                  </v:before-data-bind>
                </v:select-list>
              </td>
            </tr>
            <tr>
                  <th valign="top">
                          <vm:label for="t_description" value="Description" />
              </th>
              <td>
                          <v:textarea name="t_description" xhtml_id="t_description" null-value="--''" value="--self.v_description" fmt-function="CAL.WA.utf2wide" xhtml_cols="45" xhtml_rows="6" />
                        </td>
                      </tr>
                      <vm:if test="(self.cAction = 'create') or (CAL.WA.event_domain (self.v_id) = self.domain_id)">
                      <tr>
                        <th>
                          <vm:label for="t_privacy" value="--'Privacy'" />
                        </th>
                        <td>
                            <v:select-list name="t_privacy" xhtml_id="t_privacy" xhtml_onchange="javascript: (this.value == \'2\')? OAT.Dom.show(\'t_tab_2\'): OAT.Dom.hide(\'t_tab_2\');">
                            <v:item value="0" name="Private" />
                              <v:item value="2" name="ACL" />
                            <v:item value="1" name="Public" />
                            <v:before-data-bind>
                              <![CDATA[
                                control.ufl_value := self.v_privacy;
                              ]]>
                            </v:before-data-bind>
                          </v:select-list>
              </td>
            </tr>
                      </vm:if>
            <tr>
                        <th valign="top">
                          <vm:label for="t_attendees" value="Attendees" />
                        </th>
                        <td>
                          <v:textarea name="t_attendees" xhtml_id="t_attendees" null-value="--''" value="--self.v_attendees" fmt-function="CAL.WA.utf2wide" xhtml_cols="45" xhtml_rows="6" />
                          <?vsp
                            if (CAL.WA.instance_check (self.account_id, 'AddressBook'))
                              http (self.windowOpen('contacts.vspx?dst=mc&params=t_attendees:s1;', 'Select', 'Select', 'button'));
                            if (self.v_attendees_count)
                              http (self.windowOpen('attendees.vspx?id=' || cast (self.v_id as varchar), 'Details', 'Details', 'button'));
                          ?>
                        </td>
                      </tr>
                      <tr>
              <th>
                          <vm:label for="t_tags" value="Tags (comma-separated)" />
              </th>
              <td>
                          <v:text name="t_tags" xhtml_id="t_tags" null-value="''" value="--self.v_tags" xhtml_class="textbox" xhtml_size="60" />
                          <?vsp if (CAL.WA.tag_rule_exists (self.account_id)) { ?>
                            <input type="button" value="Suggest" onclick="javascript: tagsShow('<?V CAL.WA.page_url (self.domain_id, 'tags.vspx?fld=t_tags') ?>', 't');" class="button" />
                          <?vsp } ?>
                  <input type="button" value="Clear" onclick="javascript: document.F1.elements['t_tags'].value = ''" class="button" />
              </td>
            </tr>
                  <?vsp self.myTags ('t_tags'); ?>
          </table>
        </div>
            <div id="t_content_1" class="tabContent" style="display: none;">
              <table class="form-body" cellspacing="0">
                <tr>
                  <th width="20%" valign="top">
                          <vm:label for="t_notes" value="Notes" />
                  </th>
                  <td>
                          <textarea id="t_notes" name="t_notes" style="width: 400; height: 170"><?vsp http (coalesce (self.v_notes, '')); ?></textarea>
                    <![CDATA[
                            <script type="text/javascript" src="/ods/ckeditor/ckeditor.js"></script>
                            <script type="text/javascript">
                              var oEditor = CKEDITOR.replace('t_notes');
                      </script>
                    ]]>
                  </td>
                </tr>
              </table>  
            </div>
                  <div id="t_content_2" class="tabContent" style="display: none;">
                    <fieldset>
                      <legend><b>ODS users</b></legend>
                      <table class="form-body" cellspacing="0">
                        <tr>
                          <td style="width: 90%; background-color: white;">
                            <table id="f_tbl" class="ODS_grid">
                              <thead>
                                <tr>
                                  <th width="100%">Value</th>
                                  <th class="action">Action</th>
                                </tr>
                              </thead>
                        		  <![CDATA[
                        		    <script type="text/javascript">
                                <?vsp
                                  declare N, L integer;
                                  declare acl_values any;

                                  L := 0;
                                  acl_values := split_and_decode (self.v_grants, 0, '\0\0,');
                                  for (N := 0; N < length (acl_values); N := N + 1)
                                  {
                                    L := 1;
                                    if (self.cAction <> 'view')
                                    {
                                      http (sprintf ('OAT.MSG.attach(OAT, "PAGE_LOADED", function(){TBL.createRow("f", null, {fld_1: {mode: 1, value: "%s", form: "F1"}});});', acl_values[N], 'U'));
                                    } else {
                                      http (sprintf ('OAT.MSG.attach(OAT, "PAGE_LOADED", function(){TBL.createViewRow("f", {fld_1: {value: "%s"}});});', acl_values[N]));
                                    }
                                  }
                                ?>
                        		    </script>
                        		  ]]>
                              <tr id="f_tr_no" style="display: <?V case when L=0 then '' else 'none' end ?>;"><td colspan="<?V case when self.cAction='view' then 1 else 2 end ?>"><b>No Shares</b></td></tr>
                        		</table>
                        	</td>
                          <vm:if test="self.cAction <> 'view'">
                            <td valign="top" nowrap="nowrap">
                              <img class="pointer" src="/ods/images/icons/add_16.png" border="0" alt="Add Share" title="Add Share" onclick="javascript: TBL.createRow('f', null, {fld_1: {mode: 1, form: 'F1'}});" />
                            </td>
                          </vm:if>
                        </tr>
                      </table>
                    </fieldset>
                    <fieldset>
                      <legend><b>WebID users</b></legend>
                    <table class="form-body" cellspacing="0">
                      <tr>
                        <td style="width: 90%; background-color: white;">
                            <table id="s_tbl" class="ODS_grid">
                              <thead>
                              <tr>
                                <th width="15%">Type</th>
                                <th>Value</th>
                                <th width="1%" nowrap="nowrap">ACL: (R)ead, (W)rite</th>
                                  <th class="action">Action</th>
                              </tr>
                            </thead>
                              <tbody id="s_tbody">
                                <tr id="s_tr_no"><td colspan="4"><b>No Shares</b></td></tr>
                      		  <![CDATA[
                      		    <script type="text/javascript">
                            <?vsp
                                    declare acl any;

                                    -- inherited
                              acl := (select WAI_ACL from DB.DBA.WA_INSTANCE where WAI_ID = self.domain_id);
                              acl := case when isnull (acl) then vector () else deserialize (acl) end;
                                    DB.DBA.wa_aci_lines (acl);

                              acl := deserialize (self.v_acl);
                                    DB.DBA.wa_aci_lines (acl, self.cAction);
                           		    ?>
                           		    </script>
                           		  ]]>
                              </tbody>
                          </table>
                        </td>
                        <vm:if test="self.cAction <> 'view'">
                        <td valign="top" nowrap="nowrap">
                            <img class="pointer" src="/ods/images/icons/add_16.png" border="0" alt="Add Share" title="Add Share" onclick="javascript: TBL.createRow('s', null, {fld_1: {mode: 50, onchange: function(){TBL.changeCell50(this);}}, fld_2: {mode: 51, form: 'F1', tdCssText: 'white-space: nowrap;', className: '_validate_ _uri_'}, fld_3: {mode: 52, value: [1, 0, 0], tdCssText: 'width: 1%; white-space: nowrap; text-align: center;'}});" />
                        </td>
                        </vm:if>
                      </tr>
                    </table>
                    </fieldset>
                  </div>
          </div>
        </div>
              <div class="form-footer">
                <v:button action="simple" name="t_create" value="--case when (self.cAction = 'create') then 'Create' else 'Update' end" enabled="--case when (self.cAction in ('create', 'edit')) then 1 else 0 end" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.saveTask ();
                if (not self.vc_is_valid)
                  return;

                      commit work;
                self.cAction := 'browse';
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
                <v:button action="simple" name="t_create_new" value="Create and New" enabled="--case when (self.cAction = 'create') then 1 else 0 end" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.saveTask ();
                if (not self.vc_is_valid)
                  return;

                      commit work;
                self.initNewTask ();
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
                <v:button action="simple" name="t_cancel" value="Cancel" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                      commit work;
                self.cAction := 'browse';
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        </div>
      </v:template>

            <v:template type="simple" name="template_view_task" enabled="--case when (self.cAction = 'view') and (self.cSubAction = 'task') then 1 else 0 end">
        <v:before-data-bind>
          <![CDATA[
            declare exit handler for not found goto _end;

            select E_SUBJECT,
                   E_DESCRIPTION,
                   E_TAGS,
                         CAL.WA.event_gmt2user (E_EVENT_START, self.cTimezone, self.cDaylight),
                         CAL.WA.event_gmt2user (E_EVENT_END, self.cTimezone, self.cDaylight),
                         CAL.WA.event_gmt2user (E_COMPLETED, self.cTimezone, self.cDaylight),
                   E_PRIORITY,
                   E_STATUS,
                   E_COMPLETE,
                   blob_to_string (E_NOTES)
              into self.v_subject,
                   self.v_description,
                   self.v_tags,
                   self.v_eventStart,
                   self.v_eventEnd,
                   self.v_completed,
                   self.v_priority,
                   self.v_status,
                   self.v_complete,
                   self.v_notes
              from CAL.WA.EVENTS
             where E_ID = self.v_id;

                  self.v_attendees := CAL.WA.attendees_return (self.v_id);
                  self.rdf_iri := SIOC..calendar_event_iri (self.domain_id, self.v_id);
             return;

          _end:;
            self.initNewTask ();
          ]]>
        </v:before-data-bind>
              <div class="form-header">
                <v:label format="%s" value="--self.eventHeader (self.v_id, 'task')" />
        </div>
              <div id="t" class="c1">
                <div class="tabs">
                  <div onclick="javascript: showTab('t', 2, 0);" class="tab " id="t_tab_0">Main</div>
                  <vm:if test="not isnull (__proc_exists ('QRcode encodeString8bit', 2))">
                  <div onclick="javascript: showTab('t', 2, 1);" class="tab " id="t_tab_1">QRCode</div>
                  </vm:if>
                </div>
                <div class="contents vevent" typeof="sioct:EventCalendar" about="<?V SIOC..calendar_event_iri (self.domain_id, self.v_id) ?>">
                  <div id="t_content_0" class="tabContent" style="display: none;">
                    <table class="form-body" cellspacing="0">
            <tr>
              <th width="25%">
                Name
              </th>
              <td>
                      <?vsp self.viewField (self.v_subject, 'summary', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                Start Date
              </th>
              <td>
                      <?vsp self.viewField (self.v_eventStart, 'dtstart', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                Due Date
              </th>
              <td>
                      <?vsp self.viewField (self.v_eventEnd, 'dtend', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                      Priority
              </th>
              <td>
                      <?vsp self.viewField (self.priorityLabel (self.v_priority), '', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                      Status
              </th>
              <td>
                      <?vsp self.viewField (self.v_status, '', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                      Completed
              </th>
              <td>
                      <?vsp self.viewField (self.v_completed, 'completed', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                      Complete (%)
              </th>
              <td>
                      <?vsp self.viewField (self.v_complete, '', null); ?>
              </td>
            </tr>
            <tr>
              <th valign="top">
                Description
              </th>
              <td>
                      <?vsp self.viewField (self.v_description, 'description', null); ?>
              </td>
            </tr>
            <tr>
              <th>
                Tags
              </th>
              <td>
                      <?vsp self.viewTags (self.v_tags); ?>
              </td>
            </tr>
            <tr>
              <th valign="top">
                Notes
              </th>
              <td>
                      <?vsp self.viewField (self.v_notes, '', null); ?>
              </td>
            </tr>
          </table>
        </div>
                  <div id="t_content_1" class="tabContent" style="display: none;">
              		  <?vsp
              		    declare vcard, qrcode any;

        		          vcard := CAL.WA.export_vcal (self.domain_id, vector (self.v_id));
                      qrcode := ODS.ODS_API.qrcode (vcard, 120, 120, 3);
        		        ?>
                    <table class="form-body" cellspacing="0">
                      <tr>
                        <td align="center">
                    		  <?vsp
                            if (qrcode is not null)
	                            http (sprintf ('<img id="qrcode" src="data:image/jpg;base64,%s"/>', qrcode));
              		        ?>
                        </td>
                      </tr>
                      <tr>
                        <td align="center">
                          <b>iCal Task Data</b>
                        </td>
                      </tr>
                    </table>
                  </div>
                </div>
              </div>
              <div class="form-footer">
                <v:button action="simple" name="tv_edit" value="Edit" enabled="--case when CAL.WA.event_rights (self.domain_id, self.v_id, self.account_rights) = 'W' then 1 else 0 end" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      self.cAction := 'edit';
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
                <v:button action="simple" name="tv_cancel" value="Back" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.cAction := 'browse';
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        </div>
      </v:template>

      <vm:if test="self.cAction = 'import'">
              <div class="form-header">
                <v:label format="%s" value="Import" />
        </div>

        <div class="new-form-body">
          <table cellspacing="0">
            <tr>
                    <th rowspan="4" valign="top" width="30%">
                      Source type
              </th>
                <td nowrap="nowarap">
                      <v:radio-button name="icSource_0" xhtml_id="icSource_0" group-name="icSource" value="0" xhtml_onchange="javascript: destinationChange(this, {show: [\'imp_td_0\'], hide: [\'imp_td_1\', \'imp_td_2\', \'imp_tr_31\', \'imp_tr_32\'], exec: [srcImportLabel]});">
                    <v:before-render>
                      <![CDATA[
                        control.ufl_selected := either(lte(self.icSource, 0), 1, 0);
                      ]]>
                    </v:before-render>
                  </v:radio-button>
                      &amp;nbsp;
                  <b><vm:label for="icSource_0" value="--'File'" /></b>
                </td>
              </tr>
              <tr>
                <td nowrap="nowarap">
                      <v:radio-button name="icSource_1" xhtml_id="icSource_1" group-name="icSource" value="1" xhtml_onchange="javascript: destinationChange(this, {show: [\'imp_td_1\', \'imp_tr_31\', \'imp_tr_32\'], hide: [\'imp_td_0\', \'imp_td_2\'], exec: [srcImportLabel]});">
                    <v:before-render>
                      <![CDATA[
                        control.ufl_selected := either(equ(self.icSource, 1), 1, 0);
                      ]]>
                    </v:before-render>
                  </v:radio-button>
                      &amp;nbsp;
                  <b><vm:label for="icSource_1" value="--'WebDAV'" /></b>
                </td>
              </tr>
              <tr>
                <td nowrap="nowarap">
                      <v:radio-button name="icSource_3" xhtml_id="icSource_3" group-name="icSource" value="3" xhtml_onchange="javascript: destinationChange(this, {show: [\'imp_td_2\', \'imp_tr_31\', \'imp_tr_32\'], hide: [\'imp_td_0\', \'imp_td_1\'], exec: [srcImportLabel]});">
                        <v:before-render>
                          <![CDATA[
                            control.ufl_selected := either(equ(self.icSource, 3), 1, 0);
                          ]]>
                        </v:before-render>
                      </v:radio-button>
                      &amp;nbsp;
                      <b><vm:label for="icSource_3" value="--'CalDAV'" /></b>
                    </td>
                  </tr>
                  <tr>
                    <td nowrap="nowarap">
                      <v:radio-button name="icSource_2" xhtml_id="icSource_2" group-name="icSource" value="2" xhtml_onchange="javascript: destinationChange(this, {show: [\'imp_td_2\', \'imp_tr_31\', \'imp_tr_32\'], hide: [\'imp_td_0\', \'imp_td_1\'], exec: [srcImportLabel]});">
                    <v:before-render>
                      <![CDATA[
                        control.ufl_selected := either(equ(self.icSource, 2), 1, 0);
                      ]]>
                    </v:before-render>
                  </v:radio-button>
                      &amp;nbsp;
                  <b><vm:label for="icSource_2" value="--'URL'" /></b>
              </td>
            </tr>
                <tr>
                    <th>
                      <span id="srcLabel">Local File Name (.ics)</span>
                  </th>
                    <td>
                      <span id="imp_td_0" style="display: <?V case when self.icSource < 1 then '' else 'none' end ?>;">
                      <input type="file" name="f_file" size="60" />
                      </span>
                      <span id="imp_td_1" style="display: <?V case when self.icSource = 1 then '' else 'none' end ?>;">
                        <v:text name="f_dav" xhtml_id="f_dav" value="--get_keyword ('f_dav', self.vc_page.vc_event.ve_params, '')" xhtml_size="60" />
                        <input type="button" value="Browse..." onclick="davBrowse ('f_dav');" />
                   		  <![CDATA[
                  		    <script type="text/javascript">
                            OAT.Loader.load(['dav'], function(){OAT.WebDav.init(davOptions);});
                  		    </script>
              			    ]]>
                      </span>
                      <span id="imp_td_2" style="display: <?V case when self.icSource > 1 then '' else 'none' end ?>;">
                        <v:text name="f_uri" value="--get_keyword ('f_uri', self.vc_page.vc_event.ve_params, '')" xhtml_size="60" />
                      </span>
                    </td>
                </tr>
                  <tr id="imp_tr_31" style="<?V case when self.icSource < 1 then 'display: none;' else '' end ?>;">
                    <th>
                      <label for="i_user">User</label>
                  </th>
                  <td>
                      <v:text name="i_user" xhtml_id="i_user" value="--self.icUser" null-value="''" xhtml_class="" />
                    </td>
                  </tr>
                  <tr id="imp_tr_32" style="<?V case when self.icSource < 1 then 'display: none;' else '' end ?>;">
                    <th>
                      <label for="i_password">Password</label>
                    </th>
                    <td>
                      <v:text name="i_password" xhtml_id="i_password" type="password" value="--''" null-value="''" xhtml_class="" />
                  </td>
                </tr>
              <tr>
                <th>
                      <label for="i_tags">Tags (comma-separated)</label>
                </th>
                <td>
                      <v:text name="i_tags" xhtml_id="i_tags" value="--self.v_tags" xhtml_class="textbox" xhtml_size="60" />
                </td>
              </tr>
              <?vsp self.myTags ('i_tags'); ?>
                  <tr>
                    <th>
                      <label for="i_attendees">Mails to attendees</label>
                    </th>
                    <td>
                      <v:select-list name="i_attendees" xhtml_id="i_attendees">
                        <v:item value="0" name="No action" />
                        <v:item value="1" name="Reset mail status" />
                        <v:item value="2" name="No mails" />
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := self.icAttendees;
                            control.vc_data_bound := 1;
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                    </td>
                  </tr>
                  <tr>
                    <th></th>
                    <td>
                      <label>
                        <v:check-box name="i_sync" is-boolean="1" true-value="1" false-value="0" value="--self.icSync" />
                        <b>Sync after import</b>
                      </label>
                    </td>
                  </tr>
          </table>
                <script type="text/javascript">
                  <![CDATA[
                    destinationChange($('icSource_0'), {show: ['imp_td_0'], hide: ['imp_td_1', 'imp_td_2', 'imp_tr_31', 'imp_tr_32'], exec: [srcImportLabel]});
                    destinationChange($('icSource_1'), {show: ['imp_td_1', 'imp_tr_31', 'imp_tr_32'], hide: ['imp_td_0', 'imp_td_2'], exec: [srcImportLabel]});
                    destinationChange($('icSource_2'), {show: ['imp_td_2', 'imp_tr_31', 'imp_tr_32'], hide: ['imp_td_0', 'imp_td_1'], exec: [srcImportLabel]});
                    destinationChange($('icSource_3'), {show: ['imp_td_2', 'imp_tr_31', 'imp_tr_32'], hide: ['imp_td_0', 'imp_td_1'], exec: [srcImportLabel]});
                  ]]>
                </script>
        </div>

              <div class="form-footer">
                <v:button action="simple" name="import" value="Import" xhtml_class="form-button">
              <v:on-post>
                <![CDATA[
                  declare tmp, content any;

                        declare exit handler for SQLSTATE '*'
                        {
                        if ((__SQL_STATE = 'TEST') or (__SQL_STATE like 'CAL%')) 
                          {
                      self.vc_error_message := CAL.WA.test_clear (__SQL_MESSAGE);
                      self.vc_is_valid := 0;
                      return;
                    }
                    resignal;
                  };

                      self.icUser := trim (self.i_user.ufl_value);
                      self.icPassword := self.i_password.ufl_value;
                      if (self.icSource_0.ufl_selected)
                        {
                        self.icSource := 0;
                    content := trim(get_keyword ('f_file', self.vc_page.vc_event.ve_params, ''));
                          if (is_empty_or_null (content))
                          signal ('TEST', 'Please select file from your local file system!');
                    }
                      else if (self.icSource_1.ufl_selected)
                      {
                        self.icSource := 1;
                        self.f_dav.ufl_value := trim(self.f_dav.ufl_value);
                        tmp := http_physical_path_resolve (replace (self.f_dav.ufl_value, ' ', '%20'));
                        content := CAL.WA.dav_content (CAL.WA.host_url () || tmp, 1, self.icUser, self.icPassword);
                          if (isnull(content))
                          signal ('TEST', 'Bad import source!');
                      }
                      else if (self.icSource_2.ufl_selected)
                      {
                        self.icSource := 2;
                    self.f_uri.ufl_value := trim(self.f_uri.ufl_value);
                          if (is_empty_or_null (self.f_uri.ufl_value))
                          signal ('TEST', 'Please select correct URL address!');

                        content := CAL.WA.dav_content (self.f_uri.ufl_value, 1, self.icUser, self.icPassword);
                          if (isnull(content))
                          signal ('TEST', 'Bad URL source!');
                  }
                      else if (self.icSource_3.ufl_selected)
                      {
                        self.icSource := 3;
                        self.f_uri.ufl_value := trim (self.f_uri.ufl_value);
                        if (is_empty_or_null (self.f_uri.ufl_value))
                          signal ('TEST', 'Please select correct URL address!');

                        if (not CAL.WA.import_CalDAV_check (self.f_uri.ufl_value, vector ('user', self.icUser, 'password', self.icPassword), 1))
                          signal ('TEST', 'Bad CalDAV source!');
                      }

                  -- test tags value
                  self.v_tags := trim (self.i_tags.ufl_value);
                  CAL.WA.test (self.v_tags, vector ('name', 'Tags', 'class', 'tags'));
                  tmp := CAL.WA.tags2vector (self.v_tags);
                  tmp := CAL.WA.vector_unique (tmp);
                  self.v_tags := CAL.WA.vector2tags (tmp);

                  -- vCard
                      if (self.icSource = 3)
                      {
                        CAL.WA.import_CalDAV (self.domain_id, self.f_uri.ufl_value, vector ('user', self.icUser, 'password', self.icPassword, 'tags', self.v_tags, 'events', 1, 'tasts', 1, 'sync', self.i_sync.ufl_selected, 'mailAttendees', self.i_attendees.ufl_value));
                      } else {
                      CAL.WA.import_vcal (self.domain_id, content, vector ('tags', self.v_tags, 'events', 1, 'tasts', 1, 'sync', self.i_sync.ufl_selected, 'mailAttendees', self.i_attendees.ufl_value));
                      }

                      commit work;
                  self.cAction := 'browse';
                  self.vc_data_bind(e);
                 ]]>
               </v:on-post>
            </v:button>
                <v:button action="simple" name="i2_cancel" value="Cancel" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                      commit work;
                self.cAction := 'browse';
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        </div>
        </vm:if>

            <vm:if test="self.cAction = 'export'">
              <div class="form-header">
                <v:label format="%s" value="Export" />
              </div>

              <div class="new-form-body">
                <table cellspacing="0">
                  <tr>
                    <td colspan="2" class="new-section">
                      Destination
                    </td>
                  </tr>
                  <tr>
                    <th rowspan="3" valign="top" width="30%">
                      <v:label for="e_file" value="Destination type" />
                    </th>
                    <td nowrap="nowarap">
                      <v:radio-button name="ex_destination_type_0" xhtml_id="ex_destination_type_0" group-name="ex_destination_type" value="0" xhtml_onchange="javascript: destinationChange(this, {hide: [\'ex_tr_0\', \'ex_tr_1\', \'ex_destination_button\']});">
                        <v:before-render>
                          <![CDATA[
                            control.ufl_selected := either(lte(self.exType, 0), 1, 0);
                          ]]>
                        </v:before-render>
                      </v:radio-button>
                      <xsl:call-template name="nbsp" />
                      <b><vm:label for="ex_destination_type_0" value="--'File'" /></b>
                    </td>
                  </tr>
                  <tr>
                    <td nowrap="nowarap">
                      <v:radio-button name="ex_destination_type_1" xhtml_id="ex_destination_type_1" group-name="ex_destination_type" value="1" xhtml_onchange="javascript: destinationChange(this, {show: [\'ex_tr_0\', \'ex_tr_1\', \'ex_destination_button\']});">
                        <v:before-render>
                          <![CDATA[
                            control.ufl_selected := either(equ(self.exType, 1), 1, 0);
                          ]]>
                        </v:before-render>
                      </v:radio-button>
                      &amp;nbsp;
                      <b><vm:label for="ex_destination_type_1" value="--'WebDAV'" /></b>
                    </td>
                  </tr>
                  <tr>
                    <td nowrap="nowarap">
                      <v:radio-button name="ex_destination_type_2" xhtml_id="ex_destination_type_2" group-name="ex_destination_type" value="2" xhtml_onchange="javascript: destinationChange(this, {show: [\'ex_tr_0\', \'ex_tr_1\'], hide: [\'ex_destination_button\']});">
                        <v:before-render>
                          <![CDATA[
                            control.ufl_selected := either(equ(self.exType, 2), 1, 0);
                          ]]>
                        </v:before-render>
                      </v:radio-button>
                      &amp;nbsp;
                      <b><vm:label for="ex_destination_type_2" value="--'URL'" /></b>
                    </td>
                  </tr>
                  <tr>
                    <th>
                      Destination name (URL)
                    </th>
                    <td>
                      <v:text name="ex_destination" xhtml_id="ex_destination" value="--self.exName" xhtml_size="60" />
                      <input type="button" id="ex_destination_button" value="Browse..." onclick="davBrowse ('ex_destination');" style="display: none;" />
                          <![CDATA[
                		    <script type="text/javascript">
                          OAT.Loader.load(['dav'], function(){OAT.WebDav.init(davOptions);});
                		    </script>
                          ]]>
                    </td>
                  </tr>
                  <tr id="ex_tr_0" style="<?V case when self.exType < 1 then 'display: none;' else '' end ?>;">
                    <th>
                      User
                    </th>
                    <td>
                      <v:text name="ex_user" value="--self.exUser" null-value="''" xhtml_class="" />
                    </td>
                  </tr>
                  <tr id="ex_tr_1" style="<?V case when self.exType < 1 then 'display: none;' else '' end ?>;">
                    <th>
                      Password
                    </th>
                    <td>
                      <v:text name="ex_password" type="password" value="--''" null-value="''" xhtml_class="" />
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" class="new-section">
                      Options
                    </td>
                  </tr>
                  <tr>
                    <th valign="top">
                      Related objects
                    </th>
                    <td>
                      <label>
                        <v:check-box name="ex_events" is-boolean="1" true-value="1" false-value="0" value="--self.exEvents" />
                        Events
                      </label>
                      <br />
                      <label>
                        <v:check-box name="ex_tasks" is-boolean="1" true-value="1" false-value="0" value="--self.exTasks" />
                        Tasks
                      </label>
                    </td>
                  </tr>
                  <tr>
                    <th>
                      Period - from
                    </th>
                    <td>
                      <v:text name="ex_periodFrom" xhtml_id="ex_periodFrom" value="--self.exPeriodFrom" xhtml_onclick="--sprintf ('datePopup(\'ex_periodFrom\', \'%s\');', self.cDateFormat)" xhtml_class="textbox" xhtml_size="10" />
                      <a href="#" id="ex_periodFrom_select" onclick="datePopup('ex_periodFrom', '<?V self.cDateFormat ?>'); return false;" class="noapp">
                        <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif" />
                      </a>
                    </td>
                  </tr>
                  <tr>
                    <th>
                      - to
                    </th>
                    <td>
                      <v:text name="ex_periodTo" xhtml_id="ex_periodTo" value="--self.exPeriodTo" xhtml_onclick="--sprintf ('datePopup(\'ex_periodTo\', \'%s\');', self.cDateFormat)" xhtml_class="textbox" xhtml_size="10" />
                      <a href="#" id="ex_periodTo_select" onclick="datePopup('ex_periodTo', '<?V self.cDateFormat ?>'); return false;" class="noapp">
                        <img border="0" title="pick" alt="pick" src="image/pick_calendar.gif" />
                      </a>
                    </td>
                  </tr>
                  <tr>
                    <th>
                      <v:label for="ex_tags_include" value="Include with tags (comma-separated)" />
                    </th>
                    <td>
                      <v:text name="ex_tags_include" value="--self.exTagsInclude" xhtml_class="textbox" xhtml_size="60" />
                      <input type="button" value="Clear" onclick="javascript: document.F1.elements['ex_tags_include'].value = ''" class="button" />
                    </td>
                  </tr>
                  <?vsp self.myTags ('ex_tags_include'); ?>
                  <tr>
                    <th>
                      <v:label for="ex_tags_exclude" value="Exclude with tags (comma-separated)" />
                    </th>
                    <td>
                      <v:text name="ex_tags_exclude" value="--self.exTagsExclude" xhtml_class="textbox" xhtml_size="60" />
                      <input type="button" value="Clear" onclick="javascript: document.F1.elements['ex_tags_exclude'].value = ''" class="button" />
                    </td>
                  </tr>
                  <?vsp self.myTags ('ex_tags_exclude'); ?>
                </table>
              </div>

              <div class="form-footer">
                <v:button action="simple" name="ex_export" value="Export" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      declare tmp, content any;
                      declare exOptions any;

                      declare exit handler for SQLSTATE '*'
                      {
                        if (__SQL_STATE = 'TEST')
                        {
                          self.vc_error_message := CAL.WA.test_clear (__SQL_MESSAGE);
                          self.vc_is_valid := 0;
                          return;
                        }
                        resignal;
                      };
                      if (self.ex_destination_type_0.ufl_selected)
                      {
                        self.exType := 0;
                      }
                      else if (self.ex_destination_type_1.ufl_selected)
                      {
                        self.exType := 1;
                      }
                      else if (self.ex_destination_type_2.ufl_selected)
                      {
                        self.exType := 2;
                      }
                      self.exName := trim (self.ex_destination.ufl_value);
                      if (is_empty_or_null (self.exName))
                      {
                        self.vc_error_message := 'Please enter correct destination name (URL)!';
                        self.vc_is_valid := 0;
                        return;
                      }
                      tmp := trim (self.ex_tags_include.ufl_value);
                      CAL.WA.test (tmp, vector ('name', 'Include Tags', 'class', 'tags'));
                      tmp := CAL.WA.tags2vector (tmp);
                      tmp := CAL.WA.vector_unique (tmp);
                      self.exTagsInclude := CAL.WA.vector2tags (tmp);

                      tmp := trim (self.ex_tags_exclude.ufl_value);
                      CAL.WA.test (tmp, vector ('name', 'Exclude Tags', 'class', 'tags'));
                      tmp := CAL.WA.tags2vector (tmp);
                      tmp := CAL.WA.vector_unique (tmp);
                      self.exTagsExclude := CAL.WA.vector2tags (tmp);
                      self.exPeriodFrom := CAL.WA.test (trim (self.ex_periodFrom.ufl_value), vector('name', 'Period from date', 'class', 'date-'||self.cDateFormat));
                      if (is_empty_or_null (self.exPeriodFrom))
                        self.exPeriodFrom := null;
                      self.exPeriodTo := CAL.WA.test (trim (self.ex_periodTo.ufl_value), vector('name', 'Period from date', 'class', 'date-'||self.cDateFormat));
                      if (is_empty_or_null (self.exPeriodTo))
                        self.exPeriodTo := null;
                      if (self.exPeriodTo < self.exPeriodFrom)
                        signal ('TEST', '''Period to date'' value should be greater then ''Period from date'' value!<>');

                      self.exUser := trim (self.ex_user.ufl_value);
                      self.exPassword := self.ex_password.ufl_value;
                      self.exEvents := case when self.ex_events.ufl_selected then 1 else 0 end;
                      self.exTasks := case when self.ex_tasks.ufl_selected then 1 else 0 end;
                      exOptions := vector ('events', self.exEvents, 'tasks', self.exTasks, 'periodFrom', self.exPeriodFrom, 'periodTo', self.exPeriodTo, 'tagsInclude', self.exTagsInclude, 'tagsExclude', self.exTagsExclude);

                      content := CAL.WA.export_vcal (self.domain_id, null, exOptions);
                      if (self.exType = 0)
                      {
                        http_rewrite ();
                        http_request_status ('HTTP/1.1 200 OK');
                        http_header (sprintf ('Content-Type: application/x-download\r\nContent-Disposition: inline; filename="%s"\r\n', self.exName));
                        http (content);
                        http_flush ();
                      }
                      else if (self.exType = 1)
                      {
                        declare retValue, permissions any;
                        {
                          declare exit handler for SQLSTATE '*'
                          {
                            self.vc_error_message := 'Export is NOT posted successfully, please verify path and parameters!';
                            self.vc_is_valid := 0;
                            return;
                          };
                          permissions := USER_GET_OPTION (self.exUser, 'PERMISSIONS');
                          if (isnull (permissions))
                          {
                            permissions := '110100000RR';
                          }
                          retValue := DB.DBA.DAV_RES_UPLOAD (self.exName, content, 'text/calendar', permissions, self.exUser, null, self.exUser, self.exPassword);
                          if (DB.DBA.DAV_HIDE_ERROR (retValue) is null)
                          {
                            self.vc_error_message := 'WebDAV: ' || DB.DBA.DAV_PERROR (retValue);
                            self.vc_is_valid := 0;
                            return;
                          }
                        }
                      }
                      else if (self.exType = 2)
                      {
                        declare retContent, resHeader, reqHeader any;

                        reqHeader := null;
                        if (self.exUser <> '')
                        {
                          reqHeader := sprintf ('Authorization: Basic %s', encode_base64(self.exUser || ':' || self.exPassword));
                        }
                        commit work;
                        {
                          declare exit handler for SQLSTATE '*'
                          {
                            self.vc_error_message := 'Connection Error in HTTP Client';
                            self.vc_is_valid := 0;
                            return;
                          };
                          retContent := http_get (self.exName, resHeader, 'PUT', reqHeader, content);
                          if (not (length (resHeader) > 0 and (resHeader[0] like 'HTTP/1._ 2__ %' or  resHeader[0] like 'HTTP/1._ 3__ %')))
                          {
                            self.vc_error_message := 'Export is NOT posted successfully, please verify URL and parameters!';
                            self.vc_is_valid := 0;
                            return;
                          }
                        }
                      }
                      commit work;

                      commit work;
                      self.cAction := 'browse';
                      self.vc_data_bind(e);
                     ]]>
                   </v:on-post>
                </v:button>
                <v:button action="simple" name="ex_cancel" value="Cancel" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      commit work;
                      self.cAction := 'browse';
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
              </div>
            </vm:if>

            <vm:if test="self.cAction in ('publishBrowse', 'subscribeBrowse', 'syncmlBrowse')">
              <div class="form-header">
                <?vsp
                  declare T varchar;

                  T := '';
                  if (self.cAction = 'publishBrowse')
                  {
                    T := 'Publications';
                  }
                  else if (self.cAction = 'subscribeBrowse')
                  {
                    T := 'Subscriptions';
                  }
                  else if (self.cAction = 'syncmlBrowse')
                  {
                    T := 'SyncML';
                  }
                  http (T);
                ?>
              </div>
              <v:button action="simple" name="new_exchange" value="--'New'" xhtml_class="button">
                <v:after-data-bind>
                  <![CDATA[
                    if (self.cAction = 'publishBrowse')
                  {
                      control.ufl_value := 'New Publication';
                    }
                    else if (self.cAction = 'subscribeBrowse')
                    {
                      control.ufl_value := 'New Subscription';
                  }
                    else
                    {
                      control.ufl_value := 'New SyncML';
                    }
                  ]]>
                </v:after-data-bind>
                <v:on-post>
                  <![CDATA[
                    if (self.cAction = 'publishBrowse')
                  {
                      self.cAction := 'publishCreate';
                    }
                    else if (self.cAction = 'subscribeBrowse')
                    {
                      self.cAction := 'subscribeCreate';
                  }
                    else
                    {
                      self.cAction := 'syncmlCreate';
                    }
                    self.vc_data_bind(e);
                  ]]>
                </v:on-post>
              </v:button>
              <v:button action="simple" name="delete_exchange" value="Delete" xhtml_class="button">
                <v:after-data-bind>
                  <![CDATA[
                    control.vc_add_attribute ('onclick', 'javascript: return confirmAction(\'Are you sure that you want to delete the selected item(s)?\', document.F1, \'cb_item\', \'No items were selected for deletion.\');');
                  ]]>
                </v:after-data-bind>
                <v:on-post>
                  <![CDATA[
                    if (self.cAction in ('publishBrowse', 'syncmlBrowse'))
                    {
                      declare N, L integer;
                      declare params any;

                      params := e.ve_params;
                      L := length(e.ve_params);
                      for (N := 0; N < L; N := N + 4)
                        if (params[N] = 'cb_item')
                          delete from CAL.WA.EXCHANGE where EX_ID = cast (params[N+1] as integer);
                    } else {
                      self.cAction := 'subscribeDelete';
                    }
                    commit work;
                    self.vc_data_bind(e);
                  ]]>
                </v:on-post>
              </v:button>
              <v:data-source name="dsrc_exchanges" expression-type="sql" nrows="0" initial-offset="0">
                <v:before-data-bind>
                  <![CDATA[
                    control.ds_sql := sprintf ('select * from CAL.WA.EXCHANGE where EX_DOMAIN_ID = %d and EX_TYPE = %d order by EX_NAME', self.domain_id, case when self.cAction = 'publishBrowse' then 0 else case when self.cAction = 'subscribeBrowse' then 1 else 2 end end);
                  ]]>
                </v:before-data-bind>
              </v:data-source>

              <div style="min-height: 200px">
                <v:data-set name="ds_exchanges" data-source="self.dsrc_exchanges" scrollable="1">
                  <v:template name="ds_exchanges_header" type="simple" name-to-remove="table" set-to-remove="bottom">
                    <table class="ODS_grid" style="border: 0px;">
                      <thead>
                        <tr>
                          <th class="checkbox">
                            <input type="checkbox" name="cb_all" value="Select All" onclick="selectAllCheckboxes(this, 'cb_item')" />
                          </th>
                          <th>Name</th>
                          <th width="5%" nowrap="nowrap">Executed On</th>
                          <th width="5%" nowrap="nowrap">Status</th>
                          <th class="action">Action</th>
                        </tr>
                      </thead>
                    </table>
                  </v:template>
                  <v:template name="ds_exchanges_repeat" type="repeat">

                    <v:template type="if-not-exists" name-to-remove="table" set-to-remove="both">
                      <table>
                      </table>
                    </v:template>

                    <v:template name="ds_exchanges_browse" type="browse" name-to-remove="table" set-to-remove="both">
                      <table>
                        <tr>
                          <td class="checkbox">
                            <input type="checkbox" name="cb_item" value="<?V (control as vspx_row_template).te_column_value('EX_ID') ?>" onclick="selectCheck(this, 'cb_item')" />
                          </td>
                          <td nowrap="nowrap">
                            <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('EX_NAME')" />
                          </td>
                          <td nowrap="nowrap">
                            <v:label value="--CAL.WA.dt_datetimestring ((control.vc_parent as vspx_row_template).te_column_value('EX_EXEC_TIME'), self.cDateFormat, self.cTimeFormat)" />
                          </td>
                          <td nowrap="nowrap">
                      		  <?vsp
                      		    if ((control as vspx_row_template).te_column_value('EX_EXEC_LOG') is not null)
                  {
                      		      http (sprintf ('<a href="#" onclick="javascript: return windowShow(\'%s?msg=%U\');"><img src="/ods/images/icons/stop_16.png" border="0"/></a>', CAL.WA.page_url (self.domain_id, 'message.vspx'), (control as vspx_row_template).te_column_value('EX_EXEC_LOG')));
                  }
                      		    else
                  {
                      		      http ('OK');
                  }
                      		  ?>
                          </td>
                          <td class="action">
                            <v:button action="simple" name="edit_exchange" value="Edit" xhtml_class="button">
                              <v:on-post>
                                <![CDATA[
                                  self.ve_id := (control.vc_parent as vspx_row_template).te_column_value('EX_ID');
                                  if (self.cAction = 'publishBrowse')
                  {
                                    self.cAction := 'publishUpdate';
                                  }
                                  else if (self.cAction = 'subscribeBrowse')
                                  {
                                    self.cAction := 'subscribeUpdate';
                  }
                                  else
                                  {
                                    self.cAction := 'syncmlUpdate';
                                  }
                                  self.vc_data_bind(e);
                                ]]>
                              </v:on-post>
                            </v:button>
                            <v:button action="simple" name="sync_exchange" value="Sync" xhtml_class="button">
                              <v:on-post>
                                <![CDATA[
                                  declare exit handler for SQLSTATE '*'
                                  {
                                    if (__SQL_STATE like 'CAL%')
                                    {
                                      self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
                                      self.vc_is_valid := 0;
                                      return;
                                    }
                                    resignal;
                                  };
                                  self.ve_id := (control.vc_parent as vspx_row_template).te_column_value('EX_ID');
                                  if (self.cAction = 'syncmlBrowse')
                                  {
                                    self.cAction := 'syncmlExec';
                                  } else {
                                  CAL.WA.exchange_exec (self.ve_id);
                                    commit work;
                                  }
                                  self.vc_data_bind(e);
                                ]]>
                              </v:on-post>
                            </v:button>
                          </td>
                        </tr>
                      </table>
                    </v:template>

                  </v:template>

                  <v:template type="simple" name-to-remove="table" set-to-remove="top">
                    <table>
                    </table>
                  </v:template>

                </v:data-set>
              </div>
              <div style="width: 100%; border-top: 1px solid #7f94a5;">
                <v:button action="simple" name="back" value="Back" xhtml_class="button">
                  <v:on-post>
                    <![CDATA[
                      commit work;
                      self.cAction := 'browse';
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
              </div>
            </vm:if>

            <v:template name="exchange_form" type="simple" enabled="--case when self.cAction in ('publishCreate', 'publishUpdate', 'subscribeCreate', 'subscribeUpdate', 'syncmlCreate', 'syncmlUpdate') then 1 else 0 end">
              <div class="form-header">
                <?vsp
                  declare T varchar;

                  T := '';
                  if (self.cAction = 'publishCreate')
                  {
                    T := 'Publications/Create';
                  }
                  else if (self.cAction = 'publishUpdate')
                  {
                    T := 'Publications/Update';
                  }
                  else if (self.cAction = 'subscribeCreate')
                  {
                    T := 'Subscriptions/Create';
                  }
                  else if (self.cAction = 'subscribeUpdate')
                  {
                    T := 'Subscriptions/Update';
                  }
                  else if (self.cAction = 'syncmlCreate')
                  {
                    T := 'SyncML/Create';
                  }
                  else if (self.cAction = 'syncmlUpdate')
                  {
                    T := 'SyncML/Update';
                  }
                  http (T);
                ?>
              </div>
              <v:before-data-bind>
                <![CDATA[
                  declare params any;
                  params := self.vc_page.vc_event.ve_params;

                  if (isnull (get_keyword ('exc_name', params)))
                  {
                    declare exit handler for not found goto _end;

                    if (self.cAction in  ('publishUpdate', 'subscribeUpdate', 'syncmlUpdate'))
                  {
                      select EX_TYPE,
                             EX_NAME,
                             EX_UPDATE_TYPE,
                             EX_UPDATE_PERIOD,
                             EX_UPDATE_FREQ,
                             deserialize (EX_OPTIONS)
                        into self.ve_type,
                             self.ve_name,
                             self.ve_update_type,
                             self.ve_update_period,
                             self.ve_update_freq,
                             self.ve_options
                        from CAL.WA.EXCHANGE
                       where EX_ID = self.ve_id;

                       return;
                  }
                  _end:;

                    self.ve_type := case when (self.cAction = 'publishCreate') then 0 else case when (self.cAction = 'subscribeCreate') then 1 else 2 end end;
                    self.ve_id := null;
                    self.ve_name := '';
                    self.ve_update_type := case when (self.cAction in ('publishCreate', 'syncmlCreate')) then 1 else 2 end;
                    self.ve_update_period := case when (self.cAction in ('publishCreate', 'syncmlCreate')) then null else 'hourly' end;
                    self.ve_update_freq := case when (self.cAction in ('publishCreate', 'syncmlCreate')) then null else 1 end;
                    self.ve_options := vector ();
                  }
                ]]>
              </v:before-data-bind>
              <div class="new-form-body">
                <table cellspacing="0">
                <tr>
                  <th width="30%">
                      <label for="exc_name">Name</label>
                  </th>
                  <td>
                      <v:text name="exc_name" xhtml_id="exc_name" null-value="--''" value="--self.ve_name" xhtml_size="60" />
                  </td>
                </tr>
                  <vm:if test="self.cAction not in ('syncmlCreate', 'syncmlUpdate')">
                <tr>
                    <th rowspan="<?V case when (self.cAction in ('publishCreate', 'publishUpdate')) then 3 else 2 end ?>" valign="top">
                      Refresh type
                    </th>
                    <td nowrap="nowarap">
                      <label>
                        <v:radio-button name="exc_update_type_0" group-name="exc_update_type" value="0">
                          <v:before-render>
                            <![CDATA[
                              control.ufl_selected := either (lte (self.ve_update_type, 0), 1, 0);
                            ]]>
                          </v:before-render>
                        </v:radio-button>
                        <b>manually</b>
                      </label>
                  </td>
                </tr>
                  <vm:if test="self.cAction in ('publishCreate', 'publishUpdate')">
                <tr>
                      <td nowrap="nowarap">
                        <label>
                          <v:radio-button name="exc_update_type_1" group-name="exc_update_type" value="1">
                            <v:before-render>
                              <![CDATA[
                                control.ufl_selected := either (equ (self.ve_update_type, 1), 1, 0);
                              ]]>
                            </v:before-render>
                          </v:radio-button>
                          <b>after any entry is changed</b>
                        </label>
                  </td>
                </tr>
                  </vm:if>
                <tr>
                    <td nowrap="nowarap">
                      <label>
                        <v:radio-button name="exc_update_type_2" group-name="exc_update_type" value="2">
                          <v:before-render>
                            <![CDATA[
                              control.ufl_selected := either (equ (self.ve_update_type, 2), 1, 0);
                            ]]>
                          </v:before-render>
                        </v:radio-button>
                        <b>every</b>
                      </label>
                      <v:text name="exc_update_freq" value="--self.ve_update_freq" xhtml_size="2" />
                      <v:select-list name="exc_update_period">
                        <v:item value="hourly" name="hour(s)" />
                        <v:item value="daily" name="day(s)" />
                      <v:before-data-bind>
                        <![CDATA[
                            control.ufl_value := self.ve_update_period;
                        ]]>
                      </v:before-data-bind>
                    </v:select-list>
                  </td>
                </tr>
                  </vm:if>
                <tr>
                    <td colspan="2" class="new-section">
                      <?V case when (self.cAction in ('publishCreate', 'publishUpdate')) then 'Destination' else  case when (self.cAction in ('subscribeCreate', 'subscribeUpdate')) then 'Source' else  'Exchange' end end ?>
                  </td>
                </tr>
                  <vm:if test="self.cAction not in ('syncmlCreate', 'syncmlUpdate')">
                <tr>
                      <th rowspan="<?V case when (self.cAction in ('subscribeCreate', 'subscribeUpdate')) then 3 else 2 end ?>" valign="top">
                      <?V case when (self.cAction in ('publishCreate', 'publishUpdate')) then 'Destination' else  'Source' end ?> type
                          </th>
                    <td nowrap="nowarap">
                      <label>
                          <v:radio-button name="exc_options_type_1" xhtml_id="exc_options_type_1" group-name="exc_options_type" value="1" xhtml_onchange="javascript: destinationChange(this, {show: [\'exc_options_name_button\'], clear: [\'exc_options_name\'], exec: [excLabel]});">
                          <v:before-render>
                            <![CDATA[
                                control.ufl_selected := either (lte (get_keyword ('type', coalesce (self.ve_options, vector ()), 1), 1), 1, 0);
                            ]]>
                          </v:before-render>
                        </v:radio-button>
                          <b>WebDAV File URL</b>
                      </label>
                          </td>
                        </tr>
                    <vm:if test="self.cAction in ('subscribeCreate', 'subscribeUpdate')">
                        <tr>
                    <td nowrap="nowarap">
                      <label>
                            <v:radio-button name="exc_options_type_3" xhtml_id="exc_options_type_3" group-name="exc_options_type" value="3" xhtml_onchange="javascript: destinationChange(this, {hide: [\'exc_options_name_button\'], clear: [\'exc_options_name\'], exec: [excLabel]});">
                            <v:before-render>
                              <![CDATA[
                                control.ufl_selected := either (equ (get_keyword ('type', coalesce (self.ve_options, vector ()), 1), 3), 1, 0);
                              ]]>
                            </v:before-render>
                          </v:radio-button>
                          <b>CalDAV Path</b>
                        </label>
                      </td>
                    </tr>
                    </vm:if>
                    <tr>
                      <td nowrap="nowarap">
                        <label>
                          <v:radio-button name="exc_options_type_2" xhtml_id="exc_options_type_2" group-name="exc_options_type" value="2" xhtml_onchange="javascript: destinationChange(this, {hide: [\'exc_options_name_button\'], clear: [\'exc_options_name\'], exec: [excLabel]});">
                          <v:before-render>
                            <![CDATA[
                                control.ufl_selected := either (equ (get_keyword ('type', coalesce (self.ve_options, vector ()), 1), 2), 1, 0);
                            ]]>
                          </v:before-render>
                        </v:radio-button>
                        <b>URL</b>
                      </label>
                          </td>
                        </tr>
                  </vm:if>
                        <tr>
                    <th>
                      <vm:if test="self.cAction in ('syncmlCreate', 'syncmlUpdate')">
                        <label for="exc_options_name">WebDAV SyncML Path</label>
                      </vm:if>
                      <vm:if test="self.cAction not in ('syncmlCreate', 'syncmlUpdate')">
                        <label for="exc_options_name"><span id="excLabel">WebDAV File Name (.ics)</span></label>
                      </vm:if>
                          </th>
                          <td>
                      <v:text name="exc_options_name" xhtml_id="exc_options_name" value="--get_keyword ('name', self.ve_options)" xhtml_size="60" />
                      <input type="button" id="exc_options_name_button" value="Browse..." onclick="davBrowse ('exc_options_name', <?V case when (self.cAction in ('syncmlCreate', 'syncmlUpdate')) then 'true' else 'false' end ?>);" style="display: <?V case when (get_keyword ('type', self.ve_options, 1) <> 1) then 'none' else '' end ?>" />
                          <![CDATA[
                  		    <script type="text/javascript">
                            OAT.Loader.load(['dav'], function(){OAT.WebDav.init(davOptions);});
                  		    </script>
                          ]]>
                          </td>
                        </tr>
                        <tr>
                    <th>
                      <label for="exc_options_user">User</label>
                    </th>
                          <td>
                      <v:text name="exc_options_user" xhtml_id="exc_options_user" value="--get_keyword ('user', self.ve_options)" null-value="''" />
                          </td>
                        </tr>
                        <tr>
                    <th>
                      <label for="exc_options_password">Password</label>
                    </th>
                          <td>
                      <v:text name="exc_options_password" xhtml_id="exc_options_password" type="password"  value="--get_keyword ('password', self.ve_options)" null-value="''" />
                          </td>
                        </tr>
                        <tr>
                    <td colspan="2" class="new-section">
                      Options
                          </td>
                        </tr>
                  <tr>
                    <th>
                      <label for="exc_options_attendees">Mails to attendees</label>
                    </th>
                    <td>
                      <v:select-list name="exc_options_attendees" xhtml_id="exc_options_attendees">
                        <v:item value="0" name="No action" />
                        <v:item value="1" name="Reset mail status" />
                        <v:item value="2" name="No mails" />
                        <v:before-data-bind>
                          <![CDATA[
                            control.ufl_value := get_keyword ('mailAttendees', self.ve_options, 2);
                            control.vc_data_bound := 1;
                          ]]>
                        </v:before-data-bind>
                      </v:select-list>
                    </td>
                  </tr>
                  <vm:if test="self.cAction in ('syncmlCreate', 'syncmlUpdate')">
                    <tr>
                      <th>
                        <label for="exc_options_mode">Sync mode</label>
                      </th>
                      <td>
                        <v:select-list name="exc_options_mode" xhtml_id="exc_options_mode">
                          <v:item value="0" name="Update both" />
                          <v:item value="1" name="Update client" />
                          <v:item value="-1" name="Update SyncML server" />
                          <v:before-data-bind>
                            <![CDATA[
                              control.ufl_value := get_keyword ('mode', self.ve_options);
                              control.vc_data_bound := 1;
                            ]]>
                          </v:before-data-bind>
                        </v:select-list>
                      </td>
                    </tr>
                  </vm:if>
                        <tr>
                    <th valign="top">
                      Related objects
                    </th>
                          <td>
                      <label>
                        <v:check-box name="exc_options_events" is-boolean="1" true-value="1" false-value="0">
                          <v:before-render>
                            <![CDATA[
                              control.ufl_selected := get_keyword ('events', coalesce (self.ve_options, vector ()), 1);
                            ]]>
                          </v:before-render>
                        </v:check-box>
                        Events
                      </label>
                      <br />
                      <label>
                        <v:check-box name="exc_options_tasks" is-boolean="1" true-value="1" false-value="0">
                          <v:before-render>
                            <![CDATA[
                              control.ufl_selected := get_keyword ('tasks', coalesce (self.ve_options, vector ()), 1);
                            ]]>
                          </v:before-render>
                        </v:check-box>
                        Tasks
                      </label>
                          </td>
                        </tr>
                      </table>
                <script type="text/javascript">
                  <![CDATA[
                    destinationChange($('exc_options_type_1'), {show: ['exc_options_name_button'], clear: ['exc_options_name'], exec: [excLabel]});
                    destinationChange($('exc_options_type_3'), {hide: ['exc_options_name_button'], clear: ['exc_options_name'], exec: [excLabel]});
                    destinationChange($('exc_options_type_2'), {hide: ['exc_options_name_button'], clear: ['exc_options_name'], exec: [excLabel]});
                  ]]>
                </script>
                    </div>
              <div class="form-footer">
                <v:button action="simple" name="exc_save" value="--case when self.cAction in ('publishCreate', 'subscribeCreate', 'syncmlCreate') then 'Create' else 'Update' end" xhtml_class="form-button">
                  <v:on-post>
                        <![CDATA[
                      declare _type, _name, _nameTest, _user, _password, _attendees, _mode, _events, _tasks any;
                    declare tmp, params any;

                          declare exit handler for SQLSTATE '*'
                          {
                            if (__SQL_STATE = 'TEST')
                            {
                    self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
                    self.vc_is_valid := 0;
                    return;
                  }
                  resignal;
                };
                    params := self.vc_page.vc_event.ve_params;


                    self.ve_name := trim (self.exc_name.ufl_value);
                    self.ve_update_freq := null;
                    self.ve_update_period := null;
                    if (self.exc_update_type_0.ufl_selected)
                    {
                      self.ve_update_type := 0;
                    }
                    else if (self.exc_update_type_1.ufl_selected)
                    {
                      self.ve_update_type := 1;
                    }
                    else if (self.exc_update_type_2.ufl_selected)
                    {
                      self.ve_update_type := 2;
                      self.ve_update_freq := self.exc_update_freq.ufl_value;
                      self.ve_update_period := self.exc_update_period.ufl_value;
                    }
                      if (self.cAction in ('syncmlCreate', 'syncmlUpdate'))
                      {
                        _type := 1;
                      } else {
                    _type := 0;
                    if (self.exc_options_type_1.ufl_selected)
                    {
                      _type := 1;
                    }
                    else if (self.exc_options_type_2.ufl_selected)
                    {
                      _type := 2;
                    }
                        else if (self.exc_options_type_3.ufl_selected)
                        {
                          _type := 3;
                        }
                      }
                    _name := trim (self.exc_options_name.ufl_value);
                      if (self.cAction in ('syncmlCreate', 'syncmlUpdate'))
                        _name := _name || '/';
                      if (_type = 1)
                      {
                        _name := '/' || _name;
                      _name := replace (_name, '//', '/');
                      }
                      _nameTest := ODS..dav_path_normalize(_name);
                      if (self.cAction in ('syncmlCreate', 'syncmlUpdate'))
                      {
                        if ((DB.DBA.yac_syncml_version_get (_nameTest) = 'N') or (DB.DBA.yac_syncml_type_get (_nameTest) not in ('vcalendar_11', 'vcalendar_12')))
                          signal ('TEST', 'Bad SyncML folder.<>');
                      }

                    _user := trim (self.exc_options_user.ufl_value);
                    _password := self.exc_options_password.ufl_value;
                      if (_type = 1)
                      {
                        tmp := '1__';
                        if ((self.ve_type = 0) or (self.ve_type = 2))
                        {
                          _nameTest := CAL.WA.dav_parent (_nameTest);
                          tmp := '11_';
                        }
                        if (not CAL.WA.dav_check_authenticate (_nameTest, _user, _password, tmp))
                          signal ('TEST', 'The user has no rights for this folder.<>');
                        }

                      _attendees := cast (self.exc_options_attendees.ufl_value as integer);
                      _mode := cast (self.exc_options_mode.ufl_value as integer);
                    _events := case when self.exc_options_events.ufl_selected then 1 else 0 end;
                      _tasks := case when self.exc_options_tasks.ufl_selected then 1 else 0 end;

                      self.ve_options := vector ('type', _type, 'name', _name, 'user', _user, 'password', _password, 'mailAttendees', _attendees, 'mode', _mode, 'events', _events, 'tasks', _tasks);

                    CAL.WA.test (self.ve_name, vector('name', 'Name', 'class', 'varchar', 'minLength', 1, 'maxLength', 255));
                    if (self.ve_update_type = 2)
                       CAL.WA.test (self.ve_update_freq, vector ('name', 'Frequency', 'class', 'integer', 'minValue', 1, 'maxValue', 30));
                      CAL.WA.test (_name, vector('name', 'Resource Name', 'class', 'varchar', 'minLength', 1, 'maxLength', 255));

                      self.ve_update_freq := cast (self.ve_update_freq as integer);
                      if (self.cAction in ('publishCreate', 'subscribeCreate', 'syncmlCreate'))
                      		{
                        insert into CAL.WA.EXCHANGE (EX_DOMAIN_ID, EX_TYPE, EX_NAME, EX_UPDATE_TYPE, EX_UPDATE_PERIOD, EX_UPDATE_FREQ, EX_OPTIONS)
                          values (self.domain_id, self.ve_type, self.ve_name, self.ve_update_type, self.ve_update_period, self.ve_update_freq, serialize (self.ve_options));
                      } else {
                        update CAL.WA.EXCHANGE
                           set EX_NAME = self.ve_name,
                               EX_UPDATE_TYPE = self.ve_update_type,
                               EX_UPDATE_PERIOD = self.ve_update_period,
                               EX_UPDATE_FREQ = self.ve_update_freq,
                               EX_OPTIONS = serialize (self.ve_options)
                         where EX_ID = self.ve_id;
                					}

                      commit work;
                      self.cAction := case when (self.cAction in ('publishCreate', 'publishUpdate')) then 'publishBrowse' else case when (self.cAction in ('subscribeCreate', 'subscribeUpdate')) then 'subscribeBrowse' else 'syncmlBrowse' end end;
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                <v:button action="simple" name="exc_cancel" value="Cancel" xhtml_class="form-button">
                      <v:on-post>
                        <![CDATA[
                      commit work;
                      self.cAction := case when (self.cAction in ('publishCreate', 'publishUpdate')) then 'publishBrowse' else case when (self.cAction in ('subscribeCreate', 'subscribeUpdate')) then 'subscribeBrowse' else 'syncmlBrowse' end end;
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
                </div>
            </v:template>

            <v:template name="exchange_delete" type="simple" enabled="--case when self.cAction in ('subscribeDelete') then 1 else 0 end">
              <div class="form-header">
                Subscriptions/Delete
              </div>
              <div class="new-form-body">
                <br />
                <b>The following subscription(s) will be deleted. For checked subscriptions corresponding events/tasks will be deleted too.</b>
                <br /><br />
                <table class="ODS_grid">
                  <thead>
                    <tr>
                      <th class="checkbox">
                        <input type="checkbox" name="cb_all" value="Select All" onclick="selectAllCheckboxes(this, 'cb_item')" />
                      </th>
                      <th style="text-align: left;">Name</th>
                    </tr>
                  </thead>
                  <?vsp
                    declare N integer;
                    declare params any;

                    params := self.vc_page.vc_event.ve_params;
                    for (N := 0; N < length(params); N := N + 4)
                    {
                      if (params[N] = 'cb_item')
                      {
                  ?>
                        <tr>
                          <td class="checkbox">
                            <input type="hidden" name="ex_item" value="<?V params[N+1] ?>" />
                            <input type="checkbox" name="cb_item" value="<?V params[N+1] ?>" onclick="selectCheck(this, 'cb_item')" />
                          </td>
                          <td nowrap="nowrap">
                            <?V CAL.WA.exchange_name (cast (params[N+1] as integer)) ?>
                          </td>
                        </tr>
                  <?vsp
                      }
                    }
                  ?>
                </table>
              </div>
              <div class="form-footer">
                <v:button action="simple" name="exc_delete" value="Delete" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      declare N, L integer;
                      declare params any;

                      params := e.ve_params;
                      L := length (params);
                      for (N := 0; N < L; N := N + 4)
                      {
                        if (params[N] = 'cb_item')
                        {
                          delete from CAL.WA.EVENTS where E_EXCHANGE_ID = cast (params[N+1] as integer);
                        }
                      }
                      for (N := 0; N < L; N := N + 4)
                      {
                        if (params[N] = 'ex_item')
                        {
                          delete from CAL.WA.EXCHANGE where EX_ID = cast (params[N+1] as integer);
                        }
                      }
                      commit work;
                      self.cAction := 'subscribeBrowse';
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
                <v:button action="simple" name="exc_delete_cancel" value="Cancel" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      commit work;
                      self.cAction := 'subscribeBrowse';
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
              </div>
            </v:template>

            <v:template name="exchange_sync" type="simple" enabled="--case when self.cAction in ('syncmlExec') then 1 else 0 end">
              <v:before-data-bind>
                <![CDATA[
                  declare params any;
                  params := self.vc_page.vc_event.ve_params;

                  if (isnull (get_keyword ('exc_options_mode2', params)))
                  {
                    declare exit handler for not found goto _end3;

                    select EX_TYPE,
                           EX_NAME,
                           EX_UPDATE_TYPE,
                           EX_UPDATE_PERIOD,
                           EX_UPDATE_FREQ,
                           deserialize (EX_OPTIONS)
                      into self.ve_type,
                           self.ve_name,
                           self.ve_update_type,
                           self.ve_update_period,
                           self.ve_update_freq,
                           self.ve_options
                      from CAL.WA.EXCHANGE
                     where EX_ID = self.ve_id;

                    self.exc_options_mode2.ufl_value := get_keyword ('mode', self.ve_options);
                    self.ve_result := null;
                  }

                 _end3:;
                ]]>
              </v:before-data-bind>
              <div class="form-header">
                SyncML/Execute
              </div>
              <div class="new-form-body">
                <table cellspacing="0">
                  <tr>
                    <th width="30%">
                      Name
                    </th>
                    <td>
                      <?V self.ve_name ?>
                    </td>
                  </tr>
                  <tr>
                    <th>
                      <v:label for="exc_options_mode2" value="Sync mode" />
                    </th>
                    <td>
                      <v:select-list name="exc_options_mode2">
                        <v:item value="0" name="Update both" />
                        <v:item value="1" name="Update client" />
                        <v:item value="-1" name="Update SyncML server" />
                      </v:select-list>
                    </td>
                  </tr>
                  <?vsp
                    if (not isnull (self.ve_result))
                    {
                      http (sprintf ('<tr><th>Synced (Events, Tasks)</th><td>In - (%d, %d), Out - (%d, %d)</td></tr>', self.ve_result[0][0], self.ve_result[0][1], self.ve_result[1][0], self.ve_result[1][1]));
                    }
                  ?>
                </table>
              </div>
              <div class="form-footer">
                <v:button action="simple" name="exc_sync_exec" value="Sync" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      declare _mode any;

                      _mode := cast (self.exc_options_mode2.ufl_value as integer);
                      self.ve_result := CAL.WA.exchange_exec (self.ve_id, 0, _mode);

                      commit work;
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
                <v:button action="simple" name="exc_sync_cancel" value="Cancel" xhtml_class="form-button">
                  <v:on-post>
                    <![CDATA[
                      commit work;
                      self.cAction := 'syncmlBrowse';
                      self.vc_data_bind(e);
                    ]]>
                  </v:on-post>
                </v:button>
              </div>
            </v:template>

            <vm:if test="self.cAction = 'settings'">
              <div class="form-header">
                <?vsp
                  declare S, T varchar;

                  S := 'Preferences: ';
                  T := '';
                  if (self.cAction = 'settings' and self.cSubAction = '')
                  {
                    T := 'Settings';
                  }
                  if (self.cSubAction = 'bookmarklet')
                  {
                    T := 'Bookmarklet';
                  }
                  else if (self.cSubAction = 'upstreamBrowse')
                  {
                    T := 'Upstreams';
                  }
                  else if (self.cSubAction = 'upstreamCreate')
                  {
                    T := 'Upstreams/Create';
                  }
                  else if (self.cSubAction = 'upstreamUpdate')
                  {
                    T := 'Upstreams/Update';
                  }
                  else if (self.cSubAction = 'publishBrowse')
                  {
                    T := 'Publications';
                  }
                  else if (self.cSubAction = 'publishCreate')
                  {
                    T := 'Publications/Create';
                  }
                  else if (self.cSubAction = 'publishUpdate')
                  {
                    T := 'Publications/Update';
                  }
                  else if (self.cSubAction = 'subscribeBrowse')
                  {
                    T := 'Subscriptions';
                  }
                  else if (self.cSubAction = 'subscribeCreate')
                  {
                    T := 'Subscriptions/Create';
                  }
                  else if (self.cSubAction = 'subscribeUpdate')
                  {
                    T := 'Subscriptions/Update';
                  }
                  else if (self.cSubAction = 'grantBrowse')
                  {
                    T := 'My Sharings';
                  }
                  else if (self.cSubAction = 'grantCreate')
                  {
                    T := 'My Sharings/Create';
                  }
                  else if (self.cSubAction = 'grantUpdate')
                  {
                    T := 'My Sharings/Update';
                  }
                  else if (self.cSubAction = 'sharedBrowse')
                  {
                    T := 'My Accepted Calendars';
                  }
                  else if (self.cSubAction = 'sharedCreate')
                  {
                    T := 'My Accepted Calendars/Create';
                  }
                  else if (self.cSubAction = 'sharedUpdate')
                  {
                    T := 'My Accepted Calendars/Update';
                  }
                  http (S || T);
                ?>
              </div>

                <v:template type="simple" enabled="--case when self.cSubAction = '' then 1 else 0 end">
                  <div id="s" class="c1">
                    <div class="tabs">
                      &amp;nbsp;<vm:tabCaption tab="s" tabsCount="4" tabNo="0" caption="General" />
                      &amp;nbsp;<vm:tabCaption tab="s" tabsCount="4" tabNo="1" caption="Grids" />
                      &amp;nbsp;<vm:tabCaption tab="s" tabsCount="4" tabNo="2" caption="Calendar" />
                      &amp;nbsp;<vm:tabCaption tab="s" tabsCount="4" tabNo="3" caption="Discussion" />
                    </div>
                    <div id="s_contents" class="contents">
                      <div id="s_content_0" class="tabContent" style="display: none;">
                        <table class="form-body" cellspacing="0">
                          <tr>
                            <th width="30%">
                              <v:label for="sr_chars" value="Contact name display" />
                            </th>
                            <td>
                              <?vsp
                                http(sprintf('<input type="radio" name="sr_chars" id="sr_chars_0" value="0" %s />', CAL.WA.checkedAttribute (CAL.WA.settings_chars (self.settings), 0)));
                              ?>
                              &amp;nbsp;<vm:label for="s_chars_0" value="--'show everything'" />
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <?vsp
                                declare S varchar;

                                S := '';
                                if (CAL.WA.settings_chars (self.settings) <> 0)
                                  S := 'checked="checked"';
                                http(sprintf('<input type="radio" name="sr_chars" id="sr_chars_1" value="1" %s />', S));
                              ?>
                              &amp;nbsp;<vm:label for="s_chars_1" value="--'show no more than'" />&amp;nbsp;
                              <v:text name="s_chars" null-value="--''" value="--get_keyword('chars', self.settings, '60')" xhtml_size="3" />
                              &amp;nbsp;<vm:label for="s_chars_1" value="--'characters'" />&amp;nbsp;
                            </td>
                          </tr>
                        <tr>
                            <th>
                              <v:label for="s_rows" value="Rows per page" />
                            </th>
                            <td>
                              <v:text name="s_rows" value="--CAL.WA.settings_rows (self.settings)" xhtml_size="3" />
                            </td>
                          </tr>
                          <tr>
                            <th>
                              Atom File Version
                          </th>
                            <td>
                              <v:select-list name="s_atomVersion">
                                <v:item value="0.3" name="0.3" />
                                <v:item value="1.0" name="1.0" />
                                <v:before-data-bind>
                                  <![CDATA[
                                    control.ufl_value := CAL.WA.settings_atomVersion (self.settings);
                                  ]]>
                                </v:before-data-bind>
                              </v:select-list>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_showTasks" xhtml_id="s_showTasks" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword('showTasks', self.settings, '1') as integer)" />
                                Show tasks in Calendar
                              </label>
                            </td>
                        </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                                <v:check-box name="s_attendees" xhtml_id="s_attendees" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('mailAttendees', self.settings, '1') as integer)" />
                                Send mails to attendees
                              </label>
                            </td>
                          </tr>
                      </table>
                      </div>
                      <div id="s_content_1" class="tabContent" style="display: none;">
                        <table class="form-body" cellspacing="0">
                        <tr>
                            <th width="30%">
                              Show columns in 'Events' view
                            </th>
                            <td>
                              <label>
                              <v:check-box name="s_e_column_3" xhtml_id="s_e_column_3" is-boolean="1" true-value="1" false-value="0" value="--cast (get_keyword ('event_E_LOCATION', self.settings, '0') as integer)" />
                                Location
                              </label>
                          </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_e_column_1" xhtml_id="s_e_column_1" is-boolean="1" true-value="1" false-value="0" value="--cast (get_keyword ('event_E_UPDATED', self.settings, '1') as integer)" />
                                Updated
                              </label>
                          </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_e_column_2" xhtml_id="s_e_column_2" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('event_E_CREATED', self.settings, '0') as integer)" />
                                Created
                              </label>
                          </td>
                          </tr>
                          <tr>
                            <th width="30%">
                              Show columns in 'Tasks' view
                            </th>
                            <td>
                              <label>
                              <v:check-box name="s_t_column_1" xhtml_id="s_t_column_1" is-boolean="1" true-value="1" false-value="0" value="--cast (get_keyword ('task_E_STATUS', self.settings, '1') as integer)" />
                                Status
                              </label>
                          </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_t_column_5" xhtml_id="s_t_column_5" is-boolean="1" true-value="1" false-value="0" value="--cast (get_keyword ('task_E_PRIORITY', self.settings, '1') as integer)" />
                                Priority
                              </label>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_t_column_6" xhtml_id="s_t_column_6" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('task_E_START', self.settings, '0') as integer)" />
                                Start Date
                              </label>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_t_column_7" xhtml_id="s_t_column_7" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('task_E_END', self.settings, '1') as integer)" />
                                Due Date
                              </label>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_t_column_2" xhtml_id="s_t_column_2" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('task_E_COMPLETED', self.settings, '0') as integer)" />
                                Completed
                              </label>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_t_column_3" xhtml_id="s_t_column_3" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('task_E_UPDATED', self.settings, '0') as integer)" />
                                Updated
                              </label>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <label>
                              <v:check-box name="s_t_column_4" xhtml_id="s_t_column_4" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('task_E_CREATED', self.settings, '0') as integer)" />
                                Created
                              </label>
                            </td>
                          </tr>
                          <tr>
                            <th>
                              Colorize Tasks (Status Based)
                            </th>
                            <td>
                              <?vsp self.showColorRef ('Not Started'); ?>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <?vsp self.showColorRef ('In Progress'); ?>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <?vsp self.showColorRef ('Completed'); ?>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <?vsp self.showColorRef ('Waiting'); ?>
                            </td>
                          </tr>
                          <tr>
                            <th></th>
                            <td>
                              <?vsp self.showColorRef ('Deferred'); ?>
                            </td>
                          </tr>
                        </table>
                        <script type="text/javascript">
                          <![CDATA[
                        		OAT.Event.attach("color_NOT_STARTED_div", "click", function (){CAL.colorRef('color_NOT_STARTED');});
                        		OAT.Event.attach("color_IN_PROGRESS_div", "click", function (){CAL.colorRef('color_IN_PROGRESS');});
                        		OAT.Event.attach("color_COMPLETED_div", "click", function (){CAL.colorRef('color_COMPLETED');});
                        		OAT.Event.attach("color_WAITING_div", "click", function (){CAL.colorRef('color_WAITING');});
                        		OAT.Event.attach("color_DEFERRED_div", "click", function (){CAL.colorRef('color_DEFERRED');});
                          ]]>
                        </script>
                      </div>
                      <div id="s_content_2" class="tabContent" style="display: none;">
                        <table class="form-body" cellspacing="0">
                          <tr>
                            <th width="30%">
                              Default view
                            </th>
                            <td>
                              <v:select-list name="s_defaultView">
                                <v:item value="day" name="Day" />
                                <v:item value="week" name="Week" />
                                <v:item value="month" name="Month" />
                                <v:before-data-bind>
                                <![CDATA[
                                    control.ufl_value := CAL.WA.settings_defaultView (self.settings);
                                ]]>
                                </v:before-data-bind>
                              </v:select-list>
                          </td>
                        </tr>
                          <tr>
                            <th>
                              Week starts on
                            </th>
                            <td>
                              <v:select-list name="s_weekStarts">
                                <v:item value="m" name="Monday" />
                                <v:item value="s" name="Sunday" />
                <v:before-data-bind>
                  <![CDATA[
                                    control.ufl_value := CAL.WA.settings_weekStarts (self.settings);
                  ]]>
                </v:before-data-bind>
                              </v:select-list>
                            </td>
                          </tr>
                  <tr>
                            <th>
                              Time format
                    </th>
                    <td>
                              <v:select-list name="s_timeFormat">
                                <v:item value="e" name="13:00" />
                                <v:item value="u" name="01:00 pm" />
                                <v:before-data-bind>
                                  <![CDATA[
                                    control.ufl_value := CAL.WA.settings_timeFormat (self.settings);
                                  ]]>
                                </v:before-data-bind>
                              </v:select-list>
                    </td>
                  </tr>
                  <tr>
                        <th>
                              Date format
                    </th>
                    <td>
                              <v:select-list name="s_dateFormat">
                                <v:item value="dd.MM.yyyy" name="31.12.2007" />
                                <v:item value="MM/dd/yyyy" name="12/31/2007" />
                                <v:item value="yyyy/MM/dd" name="2007/12/31" />
                                <v:before-data-bind>
                                  <![CDATA[
                                    control.ufl_value := CAL.WA.settings_dateFormat (self.settings);
                                  ]]>
                                </v:before-data-bind>
                              </v:select-list>
                    </td>
                  </tr>
                  <tr>
                        <th>
                              Timezone
                    </th>
                    <td>
                              <v:select-list name="s_timeZone">
                                <v:on-init>
                                  <![CDATA[
                                    declare N integer;
                                    declare timezones, x, y any;

                                    timezones := CAL.WA.tz_array();
                                    x := make_array (length (timezones)/2+1, 'any');
                                    y := make_array (length (timezones)/2+1, 'any');
                                    x[0] := '';
                                    y[0] := '- Not selected -';
                                    for (N := 1; N < length (x); N := N + 1)
                                    {
                                      x[N] := timezones[(N-1)*2];
                                      y[N] := x[N];
                                    }
                                    control.vsl_item_values := x;
                                    control.vsl_items := y;
                                    control.ufl_value := '';
                                  ]]>
                                </v:on-init>
                                <v:before-data-bind>
                                  <![CDATA[
                                    control.ufl_value := CAL.WA.settings_timeZoneName (self.settings, null);
                                  ]]>
                                </v:before-data-bind>
                              </v:select-list>
                    </td>
                  </tr>
                          <tr>
                            <th>Effective timezone</th>
                            <td>
                              <?vsp http (self.showTimeZone (self.cTimeZone / 60)); ?>
                            </td>
                          </tr>
                          <tr>
                            <th>Daylight Saving Time (DST)</th>
                            <td>
                              <v:select-list name="s_daylight">
                                <v:item value="0" name="No" />
                                <v:item value="1" name="Last Sunday in March - Last Sunday in October (Europa)" />
                                <v:item value="2" name="Second Sunday in March - First Sunday in November (US)" />
                                <v:before-data-bind>
                                  <![CDATA[
                                    control.ufl_value := CAL.WA.settings_daylight (self.settings);
                                  ]]>
                                </v:before-data-bind>
                              </v:select-list>
                            </td>
                          </tr>
                        </table>
                      </div>
                      <div id="s_content_3" class="tabContent" style="display: none;">
                        <table class="form-body" cellspacing="0">
                          <v:template type="simple" enabled="--either (equ (CAL.WA.discussion_check (), 1), 0, 1)">
                  <tr>
                              <td class="error_text" colspan="2">
                                <b>The Discussion feature is disabled. You need to install the ODS Discussion package in order to use it.</b>
                    </td>
                  </tr>
                          </v:template>
                  <tr>
                            <th width="30%">&amp;nbsp;</th>
                    <td>
                              <label>
                              <?vsp
                                declare S, T varchar;

                                  S := case when (not CAL.WA.discussion_check ()) then 'disabled="disabled"' else '' end;
                                  T := case when (cast(get_keyword ('conv', self.settings, '0') as integer) = 1) then 'checked' else '' end;
                                http (sprintf ('<input type="checkbox" name="s_conv" value="1" %s %s />', T, S));
                              ?>
                      				  Enable discussions on this instance
                              </label>
                    </td>
                  </tr>
                  <tr>
                            <th width="30%">&amp;nbsp;</th>
                    <td>
                              <label>
                              <?vsp
                                declare S, T varchar;

                                  S := case when (not CAL.WA.discussion_check ()) then 'disabled="disabled"' else '' end;
                                  T := case when (cast(get_keyword ('conv_init', self.settings, '0') as integer) = 1) then 'checked' else '' end;
                                http (sprintf ('<input type="checkbox" name="s_conv_init" value="1" %s %s />', T, S));
                              ?>
                      				  Initialize the news group with existing posts
                              </label>
                    </td>
                  </tr>
                </table>
                  </div>
                    </div>
                  </div>
                  <div class="form-footer">
                    <v:button name="sp_save" action="simple" value="Save" xhtml_class="form-button">
                    <v:on-post>
                      <![CDATA[
                          declare rows, chars any;
                          declare tmp, conv, s_conv, s_conv_init, params any;

                          params := self.vc_page.vc_event.ve_params;

                        declare exit handler for SQLSTATE '*'
                        {
                          if (__SQL_STATE = 'TEST')
                          {
                            self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
                            self.vc_is_valid := 0;
                            return;
                          }
                          resignal;
                        };

                          rows := trim(self.s_rows.ufl_value);
                          chars := trim(self.s_chars.ufl_value);
                          if (get_keyword ('sr_chars', params, '-1') = '0')
                            chars := '0';

                          CAL.WA.test(rows, vector('name', 'Rows per page', 'class', 'integer', 'type', 'integer', 'minValue', 5, 'maxValue', 1000));
                          CAL.WA.test(chars, vector('name', 'Max name length', 'class', 'integer', 'type', 'integer', 'minValue', 0, 'maxValue', 255));

                          conv := cast (get_keyword ('conv', self.settings, '0') as integer);
                          s_conv := cast (get_keyword ('s_conv', params, '0') as integer);
                          s_conv_init := cast (get_keyword ('s_conv_init', params, '0') as integer);

                          self.settings := CAL.WA.set_keyword ('chars', self.settings, cast(cast(chars as integer) as varchar));
                          self.settings := CAL.WA.set_keyword ('rows', self.settings, cast(cast(rows as integer) as varchar));
                          self.settings := CAL.WA.set_keyword ('atomVersion', self.settings, self.s_atomVersion.ufl_value);
                          self.settings := CAL.WA.set_keyword ('defaultView', self.settings, self.s_defaultView.ufl_value);
                          self.settings := CAL.WA.set_keyword ('weekStarts', self.settings, self.s_weekStarts.ufl_value);
                          self.settings := CAL.WA.set_keyword ('timeFormat', self.settings, self.s_timeFormat.ufl_value);
                          self.settings := CAL.WA.set_keyword ('dateFormat', self.settings, self.s_dateFormat.ufl_value);
                          self.settings := CAL.WA.set_keyword ('daylight', self.settings, self.s_daylight.ufl_value);

                          CAL.WA.remove_keyword ('timeZone', self.settings);
                          CAL.WA.remove_keyword ('timeZoneName', self.settings);
                          if (not is_empty_or_null (self.s_timeZone.ufl_value))
                          {
                            self.settings := CAL.WA.set_keyword ('timeZoneName', self.settings, self.s_timeZone.ufl_value);
                            self.settings := CAL.WA.set_keyword ('timeZone', self.settings, CAL.WA.tz_value (self.s_timeZone.ufl_value));
                          }
                          self.settings := CAL.WA.set_keyword ('showTasks', self.settings, self.s_showTasks.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('mailAttendees', self.settings, self.s_attendees.ufl_selected);

                          self.settings := CAL.WA.set_keyword ('conv', self.settings, s_conv);
                          self.settings := CAL.WA.set_keyword ('conv_init', self.settings, s_conv_init);

                          self.settings := CAL.WA.set_keyword ('event_E_UPDATED',  self.settings, self.s_e_column_1.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('event_E_CREATED',  self.settings, self.s_e_column_2.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('event_E_LOCATION', self.settings, self.s_e_column_3.ufl_selected);

                          self.settings := CAL.WA.set_keyword ('task_E_STATUS',    self.settings, self.s_t_column_1.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('task_E_PRIORITY',  self.settings, self.s_t_column_5.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('task_E_START',     self.settings, self.s_t_column_6.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('task_E_END',       self.settings, self.s_t_column_7.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('task_E_COMPLETED', self.settings, self.s_t_column_2.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('task_E_UPDATED',   self.settings, self.s_t_column_3.ufl_selected);
                          self.settings := CAL.WA.set_keyword ('task_E_CREATED',   self.settings, self.s_t_column_4.ufl_selected);

                          declare statusNames, fieldName any;
                          
                          statusNames := vector ('Not Started', 'In Progress', 'Completed', 'Waiting', 'Deferred');
                          foreach (varchar statusName in statusNames) do
                          {
                            fieldName := self.colorFieldName (statusName);
                            self.settings := CAL.WA.set_keyword (fieldName, self.settings, get_keyword (fieldName, params, '#000'));
                          }  

                          insert replacing CAL.WA.SETTINGS (S_DOMAIN_ID, S_DATA, S_ACCOUNT_ID)
                            values(self.domain_id, serialize (self.settings), self.account_id);
                          commit work;

                          tmp := CAL.WA.settings_usedTimeZone (self.domain_id, self.owner_id);
                          CAL.WA.set_keyword ('usedTimeZone', self.settings, tmp);

                          self.cWeekStarts := CAL.WA.settings_weekStarts (self.settings);
                          self.cTimeZone := CAL.WA.settings_timeZone (self.settings);
                          self.cTimeFormat := CAL.WA.settings_timeFormat (self.settings);
                          self.cDateFormat := CAL.WA.settings_dateFormat (self.settings);

                          -- CAL.WA.domain_gems_create (self.domain_id, self.account_id);
                      		if (CAL.WA.discussion_check ())
                        {
                					  CAL.WA.nntp_update (self.domain_id, null, null, conv, s_conv);
                     				if (s_conv and s_conv_init)
                					    CAL.WA.nntp_fill (self.domain_id);
                        }

                          commit work;
                          self.initData ();

                        self.vc_data_bind(e);
                      ]]>
                    </v:on-post>
                  </v:button>
                    <v:button name="sp_clear" action="simple" value="Clear" xhtml_onclick="javascript: return confirm (\'Do you want to reset settings to default?\');" xhtml_class="form-button">
                    <v:on-post>
                      <![CDATA[
                          declare tmp any;

                          delete from CAL.WA.SETTINGS where S_DOMAIN_ID = self.domain_id;
                          CAL.WA.nntp_update (self.domain_id, null, null, 1, 0);
                          commit work;

                          self.settings := CAL.WA.settings (self.domain_id);
                          CAL.WA.settings_init (self.settings);
                          self.settings := CAL.WA.set_keyword ('app', self.settings, DB.DBA.WA_USER_APP_ENABLE (self.account_id));
                          tmp := CAL.WA.settings_usedTimeZone (self.domain_id, self.owner_id);
                          CAL.WA.set_keyword ('usedTimeZone', self.settings, tmp);

                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        </div>
                </v:template>

                <v:template type="simple" enabled="--case when self.cSubAction = 'bookmarklet' then 1 else 0 end">
                  <v:after-data-bind>
                    <![CDATA[
                      self.s_url := sprintf('<a onClick="alert(''To drag the button to your toolbar, left click the link and while holding the mouse button down, drag it to the browser toolbar and release the button.''); return false;" href="javascript:location.href=''%shome.vspx?URL=''+location.href+''&amp;TITLE=''+document.title">Import with Calendar</a>', CAL.WA.calendar_url (self.domain_id));
                    ]]>
                  </v:after-data-bind>
                  <table class="form-body" cellspacing="0">
                    <tr>
                      <td>
                         <br />
                         You can bookmark URL from anywhere with the Calendar Bookmark button.
                         <h3>Internet Explorer Users</h3>
                         <ol>
                           <li>To install the button, right click on this url <?vsp http(self.s_url); ?> and select the 'Add to Favorites' link. You may see a warning dialog -- click 'OK' to continue.</li>
                           <li>To subscribe to the site you're currently viewing in your browser, just click the <b>Import with Calendar</b> button from within your Favorites menu.</li>
                         </ol>
                         <h3>Firefox Users</h3>
                         <ol>
                           <li>To install the button on your browser, first make sure that the 'Bookmarks Toolbar' toolbar is visible in your browser. Click 'View'->'Toolbars' and verify that the 'Bookmarks Toolbar' item is checked.</li>
                           <li>Drag this url <?vsp http(self.s_url); ?> to the 'Bookmarks Toolbar' toolbar.</li>
                           <li>A <b>Import with Calendar</b> button should now appear in your 'Bookmarks Toolbar'.</li>
                           <li>To subscribe to the site you're currently viewing in your browser, just click the button.</li>
                        </ol>
                        <h3>Mozilla/Netscape Users</h3>
                        <ol>
                          <li>To install the button on your browser, first make sure that the 'Personal Toolbar' toolbar is visible in your browser. Click 'View'->'Show/Hide' and verify that the 'Personal Toolbar' item is checked.</li>
                          <li>Drag this url <?vsp http(self.s_url); ?> to the 'Personal Toolbar' toolbar.</li>
                          <li>A <b>Import with Calendar</b> button should now appear in your 'Personal Toolbar'.</li>
                          <li>To subscribe to the site you're currently viewing in your browser, just click the button.</li>
                        </ol>
                        <h3>Safari Users</h3>
                        <ol>
                          <li>To install the button on your browser, first make sure that the 'Bookmark Bar' toolbar is visible in your browser. Click 'View'->'Menu' and verify that the 'Bookmark Bar' item is checked.</li>
                          <li>Drag this url <?vsp http(self.s_url); ?> to the 'Bookmark Bar' toolbar.</li>
                          <li>A <b>Import with Calendar</b> button should now appear in your 'Bookmark Bar'. </li>
                          <li>To subscribe to the site you're currently viewing in your browser, just click the button.</li>
                        </ol>
                        <h3>Chrome Users</h3>
                        <ol>
                          <li>To install the button on your browser, first make sure that the 'Bookmark Bar' toolbar is visible in your browser. Click the wrench icon in the upper right and then check 'Always show bookmarks bar'.</li>
                          <li>Drag this url <?vsp http(self.s_url); ?> to the 'Bookmark Bar' toolbar.</li>
                          <li>A <b>Import with Calendar</b> button should now appear in your 'Bookmark Bar'. </li>
                          <li>To subscribe to the site you're currently viewing in your browser, just click the button.</li>
                        </ol>
                      </td>
                    </tr>
                  </table>
                </v:template>

                <v:template type="simple" enabled="--case when self.cSubAction = 'upstreamBrowse' then 1 else 0 end">
                  <v:button value="--'New Upstream'" action="simple" xhtml_class="button">
                    <v:on-post>
                      <![CDATA[
                        commit work;
                        self.cSubAction := 'upstreamCreate';
                        self.vc_data_bind(e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <v:button value="Delete" action="simple" xhtml_onclick="--'javascript: return confirmAction(\'Are you sure that you want to delete the selected item(s)?\', document.F1, \'cb_item\', \'No items were selected for deletion.\');'" xhtml_class="button">
                    <v:on-post>
                      <![CDATA[
                        declare N, L integer;
                        declare params any;

                        params := e.ve_params;
                        L := length (params);
                        for (N := 0; N < L; N := N + 4)
                          if (params[N] = 'cb_item')
                            delete from CAL.WA.UPSTREAM where U_ID = cast (params[N+1] as integer);

                        commit work;
                        self.vc_data_bind(e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <v:data-set name="ds_upstreams" sql="select * from CAL.WA.UPSTREAM where U_DOMAIN_ID = :p0 order by U_NAME" nrows="0" scrollable="1">
                    <v:param name="p0" value="--self.domain_id" />

                    <v:template name="ds_upstreams_header" type="simple" name-to-remove="table" set-to-remove="bottom">
                      <table class="ODS_grid" style="border: 0px;">
                        <thead>
                          <tr>
                            <th class="checkbox">
                              <input type="checkbox" name="cb_all" value="Select All" onclick="selectAllCheckboxes(this, 'cb_item')" />
                            </th>
                            <th>Name</th>
                            <th>Path</th>
                            <th>In Queue</th>
                            <th class="action">Action</th>
                          </tr>
                        </thead>
                      </table>
                    </v:template>
                    <v:template name="ds_upstreams_repeat" type="repeat">

                      <v:template type="if-not-exists" name-to-remove="table" set-to-remove="both">
                        <table>
                        </table>
                      </v:template>

                      <v:template name="ds_upstreams_browse" type="browse" name-to-remove="table" set-to-remove="both">
                        <table>
                          <tr>
                            <td class="checkbox">
                              <input type="checkbox" name="cb_item" value="<?V (control as vspx_row_template).te_column_value('U_ID') ?>" onclick="selectCheck(this, 'cb_item')" />
                            </td>
                            <td nowrap="nowrap">
                              <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('U_NAME')" />
                            </td>
                            <td nowrap="nowrap">
                              <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('U_URI')" />
                            </td>
                            <td nowrap="nowrap">
                        		  <?vsp
                                http (cast ((select count(*) from CAL.WA.UPSTREAM_EVENT where UE_UPSTREAM_ID = (control as vspx_row_template).te_column_value('U_ID')) as varchar));
                        		  ?>
                            </td>
                            <td class="action">
                              <v:button value="Edit" action="simple" xhtml_class="button">
                                <v:on-post>
                                  <![CDATA[
                                    self.vu_id := (control.vc_parent as vspx_row_template).te_column_value('U_ID');
                                    self.cSubAction := 'upstreamUpdate';
                                    self.vc_data_bind(e);
                                  ]]>
                                </v:on-post>
                              </v:button>
                              <?vsp
                                if ((select count(*) from CAL.WA.UPSTREAM_LOG where UL_UPSTREAM_ID = (control as vspx_row_template).te_column_value('U_ID')))
                                  http (self.windowOpen(sprintf ('logs.vspx?oid=%d', (control as vspx_row_template).te_column_value('U_ID')), 'Error Log', 'Error Log', 'button'));
                              ?>
                            </td>
                          </tr>
                        </table>
                      </v:template>

                    </v:template>

                    <v:template type="simple" name-to-remove="table" set-to-remove="top">
                      <table>
                      </table>
                    </v:template>

                  </v:data-set>
                </v:template>

                <v:template type="simple" enabled="--case when self.cSubAction in ('upstreamCreate', 'upstreamUpdate') then 1 else 0 end">
                  <v:before-data-bind>
                    <![CDATA[
                      declare params any;
                      params := self.vc_page.vc_event.ve_params;

                      if (isnull (get_keyword ('su_name', params)))
                      {
                        declare exit handler for not found goto _end3;

                        if (self.cSubAction = 'upstreamUpdate')
                        {
                          declare tmp any;

                          select U_NAME,
                                 U_URI,
                                 U_USER,
                                 U_PASSWORD,
                                 U_INCLUDE,
                                 U_EXCLUDE
                            into self.vu_name,
                                 self.vu_uri,
                                 self.vu_user,
                                 self.vu_password,
                                 self.vu_include,
                                 self.vu_exclude
                            from CAL.WA.UPSTREAM
                           where U_ID = self.vu_id;

                           return;
                        }
                      _end3:;

                        self.vu_name := '';
                        self.vu_uri := '';
                        self.vu_user := '';
                        self.vu_password := '';
                        self.vu_include := '';
                        self.vu_exclude := '';
                      }
                    ]]>
                  </v:before-data-bind>
                  <div class="new-form-body">
                    <table cellspacing="0">
                      <tr>
                        <th width="30%">
                          Name
                        </th>
                        <td>
                          <v:text name="su_name" value="--self.vu_name" xhtml_size="60" />
                        </td>
                      </tr>
                      <tr>
                        <th>
                          URI
                        </th>
                        <td>
                          <v:text name="su_uri" value="--self.vu_uri" xhtml_size="60" />
                        </td>
                      </tr>
                      <tr>
                        <th>
                          User
                        </th>
                        <td>
                          <v:text name="su_user" value="--self.vu_user" xhtml_class="" />
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Password
                        </th>
                        <td>
                          <v:text name="su_password" type="password" value="--self.vu_password" xhtml_class="" />
                        </td>
                      </tr>
                      <tr>
                        <th>
                          <v:label for="su_include" value="Include with tags (comma-separated)" />
                        </th>
                        <td>
                          <v:text name="su_include" null-value="''" value="--self.vu_include" xhtml_class="textbox" xhtml_size="60" />
                          <input type="button" value="Clear" onclick="javascript: document.F1.elements['su_include'].value = ''" class="button" />
                        </td>
                      </tr>
                      <?vsp self.myTags ('su_include'); ?>
                      <tr>
                        <th>
                          <v:label for="su_exclude" value="Exclude with tags (comma-separated)" />
                        </th>
                        <td>
                          <v:text name="su_exclude" null-value="''" value="--self.vu_exclude" xhtml_class="textbox" xhtml_size="60" />
                          <input type="button" value="Clear" onclick="javascript: document.F1.elements['su_exclude'].value = ''" class="button" />
                        </td>
                      </tr>
                      <?vsp self.myTags ('su_exclude'); ?>
                    </table>
                  </div>
                  <div class="form-footer">
                    <v:button action="simple" value="--case when self.cSubAction = 'upstreamCreate' then 'Create' else 'Update' end" name="su_save" xhtml_class="form-button">
                      <v:on-post>
                        <![CDATA[
                          declare tmp, params any;

                          declare exit handler for SQLSTATE '*'
                          {
                            if (__SQL_STATE = 'TEST')
                            {
                              self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
                              self.vc_is_valid := 0;
                              return;
                            }
                            resignal;
                          };

                          params := self.vc_page.vc_event.ve_params;

                          self.vu_name     := trim (self.su_name.ufl_value);
                          self.vu_uri      := trim (self.su_uri.ufl_value);
                          self.vu_user     := trim (self.su_user.ufl_value);
                          self.vu_password := trim (self.su_password.ufl_value);
                          self.vu_include  := trim (self.su_include.ufl_value);
                          self.vu_exclude  := trim (self.su_exclude.ufl_value);

                          CAL.WA.test (self.vu_name, vector('name', 'Upstream Name', 'class', 'varchar', 'minLength', 1, 'maxLength', 255));
                          CAL.WA.test (self.vu_uri, vector('name', 'Upstream URI', 'class', 'varchar', 'minLength', 1, 'maxLength', 255));
                          CAL.WA.test (self.vu_user, vector('name', 'Upstream User', 'class', 'varchar', 'minLength', 1, 'maxLength', 255));
                          CAL.WA.test (self.vu_password, vector('name', 'Upstream Password', 'class', 'varchar', 'minLength', 1, 'maxLength', 255));
                          CAL.WA.test (self.vu_include, vector ('name', 'Include Tags', 'class', 'tags'));
                          tmp := CAL.WA.tags2vector (self.vu_include);
                          tmp := CAL.WA.vector_unique (tmp);
                          self.vu_include := CAL.WA.vector2tags (tmp);
                          CAL.WA.test (self.vu_exclude, vector ('name', 'Exclude Tags', 'class', 'tags'));
                          tmp := CAL.WA.tags2vector (self.vu_exclude);
                          tmp := CAL.WA.vector_unique (tmp);
                          self.vu_exclude := CAL.WA.vector2tags (tmp);

                          if (self.cSubAction = 'upstreamCreate')
                          {
                            insert into CAL.WA.UPSTREAM (U_DOMAIN_ID, U_NAME, U_URI, U_USER, U_PASSWORD, U_INCLUDE, U_EXCLUDE)
                              values (self.domain_id, self.vu_name, self.vu_uri, self.vu_user, self.vu_password, self.vu_include, self.vu_exclude);
                          } else {
                            update CAL.WA.UPSTREAM
                               set U_NAME = self.vu_name,
                                   U_URI = self.vu_uri,
                                   U_USER = self.vu_user,
                                   U_PASSWORD = self.vu_password,
                                   U_INCLUDE = self.vu_include,
                                   U_EXCLUDE = self.vu_exclude
                             where U_ID = self.vu_id;
                          }

                          commit work;
                          self.cSubAction := 'upstreamBrowse';
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                    <v:button action="simple" value="Cancel" name="su_cancel" xhtml_class="form-button">
                      <v:on-post>
                        <![CDATA[
                          commit work;
                          self.cSubAction := 'upstreamBrowse';
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                  </div>
                </v:template>

                <v:template type="simple" enabled="--case when self.cSubAction = 'grantBrowse' then 1 else 0 end">
                  <v:button value="--'New Share'" action="simple" xhtml_class="button">
                    <v:on-post>
                      <![CDATA[
                        commit work;
                        self.cSubAction := 'grantCreate';
                        self.vc_data_bind(e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <v:button value="Delete" action="simple" xhtml_onclick="--'javascript: return confirmAction(\'Are you sure that you want to delete the selected item(s)?\', document.F1, \'cb_item\', \'No items were selected for deletion.\');'" xhtml_class="button">
                    <v:on-post>
                      <![CDATA[
                        declare N, L integer;
                        declare params any;

                        params := e.ve_params;
                        L := length (params);
                        for (N := 0; N < L; N := N + 4)
                          if (params[N] = 'cb_item')
                            delete from CAL.WA.GRANTS where G_ID = cast (params[N+1] as integer);

                        commit work;
                        self.vc_data_bind(e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <v:data-set name="ds_grant" sql="select a.*, b.U_NAME from CAL.WA.GRANTS a, DB.DBA.SYS_USERS b where a.G_DOMAIN_ID = :p0 and a.G_ACCOUNT_ID = b.U_ID order by b.U_NAME" nrows="0" scrollable="1">
                    <v:param name="p0" value="--self.domain_id" />

                    <v:template name="ds_grant_header" type="simple" name-to-remove="table" set-to-remove="bottom">
                      <table class="ODS_grid" style="border: 0px;">
                        <thead>
                          <tr>
                            <th class="checkbox">
                              <input type="checkbox" name="cb_all" value="Select All" onclick="selectAllCheckboxes(this, 'cb_item')" />
                            </th>
                            <th nowrap="nowrap">User</th>
                            <th nowrap="nowrap" width="5%">Enabled/Disabled</th>
                            <th nowrap="nowrap" width="5%">Share Mode</th>
                            <th class="action">Action</th>
                          </tr>
                        </thead>
                      </table>
                    </v:template>
                    <v:template name="ds_grant_repeat" type="repeat">

                      <v:template name="ds_grant_browse" type="browse" name-to-remove="table" set-to-remove="both">
                        <table>
                          <tr>
                            <td class="sheckbox">
                              <input type="checkbox" name="cb_item" value="<?V (control as vspx_row_template).te_column_value('G_ID') ?>" onclick="selectCheck(this, 'cb_item')" />
                            </td>
                            <td nowrap="nowrap">
                              <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('U_NAME')" />
                            </td>
                            <td nowrap="nowrap">
                              <?vsp
                                http (case when (control as vspx_row_template).te_column_value('G_ENABLE') = 1 then 'Enable' else 'Disable' end);
                              ?>
                            </td>
                            <td nowrap="nowrap">
                              <?vsp
                                http (case when (control as vspx_row_template).te_column_value('G_MODE') = 'R' then 'Read Only' else 'Read/Write' end);
                              ?>
                            </td>
                            <td nowrap="nowrap">
                              <v:button value="Edit" action="simple" xhtml_class="button">
                                <v:on-post>
                                  <![CDATA[
                                    self.vg_id := (control.vc_parent as vspx_row_template).te_column_value('G_ID');
                                    self.cSubAction := 'grantUpdate';
                                    self.vc_data_bind(e);
                                  ]]>
                                </v:on-post>
                              </v:button>
                            </td>
                          </tr>
                        </table>
                      </v:template>

                    </v:template>

                    <v:template type="simple" name-to-remove="table" set-to-remove="top">
                      <table>
                      </table>
                    </v:template>

                  </v:data-set>
                </v:template>

                <v:template type="simple" enabled="--case when self.cSubAction in ('grantCreate', 'grantUpdate') then 1 else 0 end">
                  <v:before-data-bind>
                    <![CDATA[
                      declare params any;
                      params := self.vc_page.vc_event.ve_params;

                      if (isnull (get_keyword ('sg_account', params)))
                      {
                        declare exit handler for not found goto _end;

                        if (self.cSubAction = 'grantUpdate')
                        {
                          select b.U_NAME,
                                 a.G_ENABLE,
                                 a.G_MODE
                            into self.vg_account,
                                 self.vg_enable,
                                 self.vg_mode
                            from CAL.WA.GRANTS a,
                                 DB.DBA.SYS_USERS b
                           where a.G_ID = self.vg_id
                             and a.G_ACCOUNT_ID = b.U_ID;

                           return;
                        }
                      _end:;

                        self.vg_id := null;
                        self.vg_account_id := null;
                        self.vg_account := '';
                        self.vg_enable := 1;
                        self.vg_mode := 'R';
                      }
                    ]]>
                  </v:before-data-bind>
                  <div class="new-form-body">
                    <table cellspacing="0">
                      <tr>
                        <th width="30%">
                          <v:label for="sg_account" value="User" />
                        </th>
                        <td>
                          <v:text name="sg_account" null-value="--''" value="--self.vg_account" xhtml_class="textbox" />
                          <input type="button" value="Select" onclick="javascript: windowShow('/ods/users_select.vspx?mode=u&params=sg_account:s1;&nrows=<?V CAL.WA.settings_rows (self.settings) ?>')" class="button" />
                        </td>
                      </tr>
                      <tr>
                        <th valign="top">
                          Share access
                        </th>
                        <td>
                          <?vsp
                            http(sprintf('<label><input type="radio" name="sg_enable" id="sg_enable_0" value="0" %s />Disable</label>', CAL.WA.checkedAttribute (self.vg_enable, 0)));
                            http('<br />');
                            http(sprintf('<label><input type="radio" name="sg_enable" id="sg_enable_1" value="1" %s />Enable</label>', CAL.WA.checkedAttribute (self.vg_enable, 1)));
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <th valign="top">
                          Share mode
                        </th>
                        <td>
                          <?vsp
                            http(sprintf('<label><input type="radio" name="sg_mode" id="sg_mode_0" value="R" %s />Read Only</label>', CAL.WA.checkedAttribute (self.vg_mode, 'R')));
                            http('<br />');
                            http(sprintf('<label><input type="radio" name="sg_mode" id="sg_mode_1" value="W" %s />Read/Write</label>', CAL.WA.checkedAttribute (self.vg_mode, 'W')));
                          ?>
                        </td>
                      </tr>
                    </table>
                  </div>
                  <div class="form-footer">
                    <v:button action="simple" value="Share" name="sg_save" xhtml_class="form-button">
                      <v:on-post>
                        <![CDATA[
                          declare tmp, params any;

                          declare exit handler for SQLSTATE '*'
                          {
                            if (__SQL_STATE = 'TEST')
                            {
                              self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
                              self.vc_is_valid := 0;
                              return;
                            }
                            resignal;
                          };
                          params := self.vc_page.vc_event.ve_params;

                          self.vg_account    := trim (self.sg_account.ufl_value);
                          self.vg_enable     := cast (get_keyword ('sg_enable', params, '0') as integer);
                          self.vg_mode       := get_keyword ('sg_mode', params, 'R');
                          self.vg_account_id := (select U_ID from DB.DBA.SYS_USERS where U_NAME = self.vg_account);
                          if (isnull (self.vg_account_id))
                          {
                            self.vc_error_message := 'User does not exist!';
                            self.vc_is_valid := 0;
                            return;
                          }
                          if (
                              (
                               (self.cSubAction = 'grantCreate') and
                               (exists (select 1 from CAL.WA.GRANTS where G_DOMAIN_ID = self.domain_id and G_ACCOUNT_ID = self.vg_account_id))
                              ) or
                              (
                               (self.cSubAction = 'grantUpdate') and
                               (exists (select 1 from CAL.WA.GRANTS where G_DOMAIN_ID = self.domain_id and G_ACCOUNT_ID = self.vg_account_id and G_ID <> self.vg_id))
                              )
                             )
                          {
                            self.vc_error_message := 'Another share for the same user already exists!';
                            self.vc_is_valid := 0;
                            return;
                          }

                          if (self.cSubAction = 'grantCreate')
                          {
                            insert into CAL.WA.GRANTS (G_DOMAIN_ID, G_ACCOUNT_ID, G_ENABLE, G_MODE)
                              values (self.domain_id, self.vg_account_id, self.vg_enable, self.vg_mode);
                          } else {
                            update CAL.WA.GRANTS
                               set G_ACCOUNT_ID = self.vg_account_id,
                                   G_ENABLE = self.vg_enable,
                                   G_MODE = self.vg_mode
                             where G_DOMAIN_ID = self.domain_id
                               and G_ID = self.vg_id;
                          }

                          commit work;
                          self.cSubAction := 'grantBrowse';
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                    <v:button action="simple" value="Cancel" name="sg_cancel" xhtml_class="form-button">
                      <v:on-post>
                        <![CDATA[
                          commit work;
                          self.cSubAction := 'grantBrowse';
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                  </div>
                </v:template>

                <v:template type="simple" enabled="--case when self.cSubAction = 'sharedBrowse' then 1 else 0 end">
                  <v:button value="--'Accept'" action="simple" xhtml_class="button">
                    <v:on-post>
                      <![CDATA[
                        self.cSubAction := 'sharedCreate';
                        self.vc_data_bind(e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <v:button value="Delete" action="simple" xhtml_onclick="--'javascript: return confirmAction(\'Are you sure that you want to delete the selected item(s)?\', document.F1, \'cb_item\', \'No items were selected for deletion.\');'" xhtml_class="button">
                    <v:on-post>
                      <![CDATA[
                        declare N, L integer;
                        declare params any;

                        params := e.ve_params;
                        L := length(params);
                        for (N := 0; N < L; N := N + 4)
                          if (params[N] = 'cb_item')
                            delete from CAL.WA.SHARED where S_ID = cast (params[N+1] as integer);

                        commit work;
                        self.vc_data_bind(e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <input class="button" type="button" title="Help" alt="Help" value="Help" onclick="javascript: return windowShow('<?V CAL.WA.page_url (self.domain_id, 'help.vspx?page=proba') ?>');"/>
                  <v:data-set name="ds_shared" sql="select a.*, b.WAI_NAME from CAL.WA.SHARED a, DB.DBA.WA_INSTANCE b where a.S_DOMAIN_ID = :p0 and a.S_CALENDAR_ID = b.WAI_ID order by b.WAI_NAME" nrows="0" scrollable="1">
                    <v:param name="p0" value="--self.domain_id" />

                    <v:template name="ds_shared_header" type="simple" name-to-remove="table" set-to-remove="bottom">
                      <table class="ODS_grid" style="border: 0px;">
                        <thead>
                          <tr>
                            <th class="checkbox">
                              <input type="checkbox" name="cb_all" value="Select All" onclick="selectAllCheckboxes(this, 'cb_item')" />
                            </th>
                            <th>Calendar</th>
                            <th width="5%">Type</th>
                            <th width="5%">Visible</th>
                            <th width="5%">Mode</th>
                            <th width="5%">Color</th>
                            <th class="action">Action</th>
                          </tr>
                        </thead>
                      </table>
                    </v:template>
                    <v:template name="ds_shared_repeat" type="repeat">

                      <v:template name="ds_shared_browse" type="browse" name-to-remove="table" set-to-remove="both">
                        <table>
                          <tr>
                            <td class="checkbox">
                              <input type="checkbox" name="cb_item" value="<?V (control as vspx_row_template).te_column_value('S_ID') ?>" onclick="selectCheck(this, 'cb_item')" />
                            </td>
                            <td nowrap="nowrap">
                              <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('WAI_NAME')" />
                            </td>
                            <td nowrap="nowrap">
                              <?vsp
                                http (case when isnull ((control as vspx_row_template).te_column_value('S_GRANT_ID')) then 'Public' else 'Shared' end);
                              ?>
                            </td>
                            <td nowrap="nowrap">
                              <?vsp
                                http (case when (control as vspx_row_template).te_column_value('S_VISIBLE') = 1 then 'Yes' else 'No' end);
                              ?>
                            </td>
                            <td nowrap="nowrap">
                              <?vsp
                                declare calendar_id integer;

                                calendar_id := (control as vspx_row_template).te_column_value('S_CALENDAR_ID');
                                for (select a.WAI_IS_PUBLIC,
                                            b.S_GRANT_ID,
                                            c.G_ENABLE,
                                            c.G_MODE
                                       from DB.DBA.WA_INSTANCE a,
                                            CAL.WA.SHARED b
                                              left join CAL.WA.GRANTS c on c.G_ID = b.S_GRANT_ID
                                      where a.WAI_ID = b.S_CALENDAR_ID
                                        and b.S_DOMAIN_ID = self.domain_id
                                        and b.S_CALENDAR_ID = calendar_id
                                        and b.S_VISIBLE = 1) do
                                {
                                  if (isnull (S_GRANT_ID))
                                  {
                                    if (WAI_IS_PUBLIC)
                                    {
                                      http ('Read Only');
                                    } else {
                                      http ('Disabled');
                                    }
                                  } else {
                                    if (G_ENABLE)
                                    {
                                      if (G_MODE = 'R')
                                      {
                                        http ('Read Only');
                                      } else {
                                        http ('Read/Write');
                                      }
                                    } else {
                                      http ('Disabled');
                                    }
                                  }
                                }
                              ?>
                            </td>
                            <td nowrap="nowrap">
                              <?vsp
                                http (sprintf ('<div id="ss_color_div" class="ss_color" style="background-color: %s;"></div>', (control as vspx_row_template).te_column_value('S_COLOR')));
                              ?>
                            </td>
                            <td nowrap="nowrap">
                              <v:button value="Edit" action="simple" xhtml_class="button">
                                <v:on-post>
                                  <![CDATA[
                                    self.vs_id := (control.vc_parent as vspx_row_template).te_column_value('S_ID');
                                    self.cSubAction := 'sharedUpdate';
                                    self.vc_data_bind(e);
                                  ]]>
                                </v:on-post>
                              </v:button>
            </td>
          </tr>
        </table>
                      </v:template>

                    </v:template>

                    <v:template type="simple" name-to-remove="table" set-to-remove="top">
                      <table>
                      </table>
                    </v:template>

                  </v:data-set>
                </v:template>

                <v:template type="simple" enabled="--case when self.cSubAction in ('sharedCreate', 'sharedUpdate') then 1 else 0 end">
                  <v:before-data-bind>
                    <![CDATA[
                      declare params any;
                      params := self.vc_page.vc_event.ve_params;

                      if (isnull (get_keyword ('ss_calendar', params)))
                      {
                        declare exit handler for not found goto _end2;

                        if (self.cSubAction = 'sharedUpdate')
                        {
                          select b.WAI_NAME,
                                 a.S_GRANT_ID,
                                 a.S_CALENDAR_ID,
                                 a.S_VISIBLE,
                                 a.S_COLOR
                            into self.vs_calendar,
                                 self.vs_grant_id,
                                 self.vs_calendar_id,
                                 self.vs_visible,
                                 self.vs_color
                            from CAL.WA.SHARED a,
                                 DB.DBA.WA_INSTANCE b
                           where a.S_ID = self.vs_id
                             and a.S_CALENDAR_ID = b.WAI_ID;

                           return;
                        }
                      _end2:;

                        self.cSubAction := 'sharedCreate';
                        self.vs_id := null;
                        self.vs_grant_id := null;
                        self.vs_calendar_id := null;
                        self.vs_calendar := '';
                        self.vs_visible := 1;
                        self.vs_color := '#888';
                      }
                    ]]>
                  </v:before-data-bind>
                  <div class="new-form-body">
                    <table cellspacing="0">
                      <tr>
                        <td colspan="2" align="center">
                          <?vsp
                            http (self.windowOpen('help.vspx?page=proba', 'Learn more about public and shared calendars', 'Learn more about public and shared calendars', 'link'));
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <th width="30%" valign="top">
                          Calendar type
                        </th>
                        <td nowrap="nowrap">
                          <?vsp
                            http (sprintf ('<input type="radio" name="ss_type" id="ss_type_0" value="0" %s onchange="javascript: calendarsHelp(1);" /> <label for="ss_type_0">Public</label>', case when isnull (self.vs_grant_id) then 'checked="checked"' else '' end));
                            http ('<br />');
                            http (sprintf ('<input type="radio" name="ss_type" id="ss_type_1" value="1" %s onchange="javascript: calendarsHelp(1);" /> <label for="ss_type_1">Shared to Me</label>', case when not isnull (self.vs_grant_id) then 'checked="checked"' else '' end));
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <th >
                          Calendar name
                        </th>
                        <td>
                          <v:text name="ss_calendar" xhtml_id="ss_calendar" value="--self.vs_calendar" xhtml_size="60" />
                          <input id="ss_type_button" type="button" value="Select" onclick="javascript: calendarsShow('calendars.vspx?params=ss_calendar:s1;',520)" class="button" />
                        </td>
                      </tr>
                      <tr>
                        <th></th>
                        <td>
                          <?vsp
                            http (sprintf ('<input type="checkbox" value="1" name="ss_visible" id="ss_visible" %s />', CAL.WA.checkedAttribute (self.vs_visible)));
                          ?>
                          <vm:label for="ss_visible" value="Visible"/>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Color
                        </th>
                        <td>
                          <input type="hidden" id="ss_color" name="ss_color" value="<?V self.vs_color ?>" />
                          <div id="ss_color_div" class="ss_color" style="cursor: pointer; background-color: <?V self.vs_color ?>;"></div>
                        </td>
                      </tr>
                    </table>
                    <script type="text/javascript">
                      <![CDATA[
                     		OAT.Event.attach("ss_color_div", "click", function (){CAL.colorRef('ss_color');});
                      ]]>
                    </script>
                  </div>
                  <div class="form-footer">
                    <v:button action="simple" value="--case when self.cSubAction = 'sharedCreate' then 'Accept' else 'Update' end" name="ss_save" xhtml_class="form-button">
                      <v:on-post>
                        <![CDATA[
                          declare tmp, vs_type, params any;

                          declare exit handler for SQLSTATE '*'
                          {
                            if (__SQL_STATE = 'TEST')
                            {
                              self.vc_error_message := CAL.WA.test_clear(__SQL_MESSAGE);
                              self.vc_is_valid := 0;
                              return;
                            }
                            resignal;
                          };
                          params := self.vc_page.vc_event.ve_params;

                          vs_type             := get_keyword ('ss_type', params, '');
                          self.vs_calendar    := trim (self.ss_calendar.ufl_value);
                          self.vs_visible     := cast (get_keyword ('ss_visible', params, '0') as integer);
                          self.vs_color       := get_keyword ('ss_color', params, '#888');
                          self.vs_calendar_id := (select WAI_ID from DB.DBA.WA_INSTANCE where WAI_NAME = self.vs_calendar and WAI_ID <> self.domain_id);
                          if (isnull (self.vs_calendar_id))
                          {
                            self.vc_error_message := 'Calendar does not exist!';
                            self.vc_is_valid := 0;
                            return;
                          }
                          if ((vs_type = '0') and not CAL.WA.domain_is_public (self.vs_calendar_id))
                          {
                            self.vc_error_message := 'Calendar is not public!';
                            self.vc_is_valid := 0;
                            return;
                          }
                          if (
                              (
                               (self.cSubAction = 'sharedCreate') and
                               (exists (select 1 from CAL.WA.SHARED where S_DOMAIN_ID = self.domain_id and S_CALENDAR_ID = self.vs_calendar_id))
                              )
                              or
                              (
                               (self.cSubAction = 'sharedUpdate') and
                               (exists (select 1 from CAL.WA.SHARED where S_DOMAIN_ID = self.domain_id and S_CALENDAR_ID = self.vs_calendar_id and S_ID <> self.vs_id))
                              )
                             )
                          {
                            self.vc_error_message := 'Calendar with the same name is already accepted!';
                            self.vc_is_valid := 0;
                            return;
                          }
                          if (vs_type = '0')
                          {
                            self.vs_grant_id := null;
                          } else {
                            self.vs_grant_id := (select b.G_ID from DB.DBA.WA_INSTANCE a, CAL.WA.GRANTS b where a.WAI_TYPE_NAME = 'Calendar' and a.WAI_NAME = self.vs_calendar and a.WAI_ID = b.G_DOMAIN_ID and b.G_ACCOUNT_ID = self.account_id);
                            if (isnull (self.vs_grant_id))
                            {
                              self.vc_error_message := 'Calendar with this name is not shared to you!';
                              self.vc_is_valid := 0;
                              return;
                            }
                          }

                          if (self.cSubAction = 'sharedCreate')
                          {
                            insert into CAL.WA.SHARED (S_DOMAIN_ID, S_GRANT_ID, S_CALENDAR_ID, S_VISIBLE, S_COLOR)
                              values (self.domain_id, self.vs_grant_id, self.vs_calendar_id, self.vs_visible, self.vs_color);
                          } else {
                            update CAL.WA.SHARED
                               set S_GRANT_ID = self.vs_grant_id,
                                   S_CALENDAR_ID = self.vs_calendar_id,
                                   S_VISIBLE = self.vs_visible,
                                   S_COLOR = self.vs_color
                             where S_DOMAIN_ID = self.domain_id
                               and S_ID = self.vs_id;
                          }

                          commit work;
                          self.cSubAction := 'sharedBrowse';
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                    <v:button action="simple" value="Cancel" name="ss_cancel" xhtml_class="form-button">
                      <v:on-post>
                        <![CDATA[
                          commit work;
                          self.cSubAction := 'sharedBrowse';
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                  </div>
                </v:template>
                <script type="text/javascript">
                  <![CDATA[
                    calendarsHelp();
                  ]]>
                </script>
      </vm:if>
      
      <div id="reminderDiv" style="display: none;">
        <div style="height: 200px; overflow: auto;">
                  <table class="ODS_grid">
                    <thead>
              <tr>
                        <th class="checkbox">
                  <input type="checkbox" name="cbr_all" value="Select All" onclick="selectAllCheckboxes2(this, 'cbr_item')" />
                </th>
                <th>
                  Name
                </th>
                        <th nowrap="nowrap" width="10%">
                  Start At
                </th>
              </tr>
            </thead>
            <tbody id="reminderBody">
            </tbody>
          </table>
        </div>
                <div class="form-footer">
          <input type="button" value="Dismiss Selected" onclick="javascript: dismissReminder ('cbr_item', false);" title="Dismiss Selected" class="button" />
          <input type="button" value="Dismiss All"      onclick="javascript: dismissReminder ('cbr_item', true);"  title="Dismiss All"      class="button" />
        </div>
      </div>
      <vm:if test="self.cScope in ('day', 'week', 'month')">
        <div id="deleteDiv" style="display: none;">
                  Are you sure that you want to delete the selected item?
      	</div>
        <div id="deleteDiv2" style="display: none;">
                  Do you want to delete all occurrences of the repeatable item, or just this one?<br /><br />
          <input type="radio" name="e_delete" id="e_delete_0" value="0" checked="checked" style="margin-left: 110px;" /><label for="e_delete_0">Delete this occurrence</label><br />
          <input type="radio" name="e_delete" id="e_delete_1" value="1" style="margin-left: 110px;" /><label for="e_delete_1">Delete the series</label><br />
        </div>
      </vm:if>
            </div>
          </td>
        </tr>
      </table>
    </vm:pagebody>
  </vm:pagewrapper>
</v:page>
