﻿var ODAAppointment = new Class.create();
var loadingAppointments = new Hash();
var loadedAppointments = new Hash();

ODAAppointment.prototype = {
    initialize: function(container, appointmentID, _aliasName, _anchorID, _supportOnCall) {
        this.supportOnCall = _supportOnCall == null ? false : _supportOnCall;

        if (loadedAppointments.keys().indexOf(appointmentID) > -1) {
            var loadedApp = loadedAppointments.get(appointmentID);
            if (window.top.$(loadedApp.container.id + "_window")) {
                window.top.$(loadedApp.container.id + "_window").show();
            }
            else {
                loadedAppointments.get(appointmentID).container.show();
            }

            return;
        }

        this.container = $(container);


        if (this.container == null) {
            var c = new Element("DIV", { id: "appointment_" + appointmentID });
            var topWindow = window.top;
            topWindow.document.body.appendChild(c);
            this.container = c;
        }
        else {
            this.container.update("");
        }

        if (window.top.$(this.container.id + '_window') != null) {
            window.top.$(this.container.id + '_window').remove();
        }

        this.initializeVariables();

        if (appointmentID != null && appointmentID.toString().length > 0) {
            this.AppointmentID = appointmentID;
        }
        if (_aliasName != null && _aliasName.length > 0) {
            this.aliasName = _aliasName;
        }

        this.buildControl();
        this.container.appointment = this;

        if (typeof divWindow == 'function') {

            var wrapper = new window.top.divWindow(this.container.id + "_window", 'Appointment');
            this.container.parentNode.replaceChild(wrapper, this.container);
            window.top.$(this.container.id + "_window_content").update(this.container);
        }
        if ($(_anchorID) != null) {
            window.top.$(this.container.id + "_window").clonePosition($(_anchorID), { setHeight: false, setWidth: false });
        }
        loadedAppointments.set(appointmentID, this);
        this.initializeControl();

    },

    initializeControl: function() {
        // initialize controls
        new ODATextBox(this.getElement('txtStartDate'), ValidationTypes.DateTime, DateValidationModes.DateOnly, true);
        new ODATextBox(this.getElement('txtStartTime'), ValidationTypes.Time, DateValidationModes.Time, true);
        new ODATextBox(this.getElement('txtEndTime'), ValidationTypes.Time, DateValidationModes.Time, true);

        new ODATextBox(this.getElement('recurRange_EndByDate'), ValidationTypes.DateTime, DateValidationModes.DateOnly, true);
        window.top.ODATech.initializeLookup(this.getElement('txtLocation'), 'Location');

        if (this.AppointmentID != null && this.AppointmentID.toString().length > 0) {
            window.top.loadingAppointments.set(this.AppointmentID, this);
            window.top.ServerFunction("Odatech.Business.AppointmentFactory.LoadAppointment|" + this.AppointmentID + "|" + this.aliasName, this.AppointmentID);
        }
    },

    initializeVariables: function() {
        this.Name = "";
        this.Description = "";
        this.StartDate = "";
        this.StartTime = "";
        this.EndDate = "";
        this.EndTime = "";
        this.RecurrenceStartDate = "";
        this.RecurrenceEndType = "";
        this.RecurrenceEndAfterX = "";
        this.RecurrenceEndDate = "";
        this.RecurrenceRestart = false;
        this.Interval = 1;
        this.DailyRecurrenceType = "";      //(EveryXDays | EveryWeekday)
        this.DaysOfWeek = "";
        this.MonthlyRecurrenceType = "";    //(DayOfXMonths | XOfEveryMonths)
        this.DaysOfMonth = "";
        this.SkipType = "";                 //(Enum: ScheduleIntervalSkipType)
        this.SkipDayType = "";              //(Enum: ScheduleIntervalSkipDayType)
        this.YearlyRecurrenceType = "";     //(EveryMonthDay | XOfEveryMonths)
        this.DaysOfYear = "";
        this.recurrenceType = "";           //(daily | weekly | monthly | yearly | single)
        this.aliasName = "Default";                //AliasName in config file that points to the current SessionMgr Instance
        this.Working = true;
        this.AllDay = false;
        this.Location = "";
        this.Month = 1;
        this.AppointmentID = "";
        this.ContainerID = this.container.id;
    },

    setVariables: function(args) {
        this.Name = args.Name;
        this.Description = args.Description;
        this.StartDate = args.StartDate;
        this.StartTime = args.StartTime;
        this.EndDate = args.EndDate;
        this.EndTime = args.EndTime;
        this.RecurrenceStartDate = args.RecurrenceStartDate;
        this.RecurrenceEndType = args.RecurrenceEndType;
        this.RecurrenceEndAfterX = args.RecurrenceEndAfterX;
        this.RecurrenceEndDate = args.RecurrenceEndDate;
        this.RecurrenceRestart = args.RecurrenceRestart;
        this.Interval = args.Interval;
        this.DailyRecurrenceType = args.DailyRecurrenceType;
        this.DaysOfWeek = args.DaysOfWeek;
        this.MonthlyRecurrenceType = args.MonthlyRecurrenceType;
        this.DaysOfMonth = args.DaysOfMonth;
        this.SkipType = args.SkipType;
        this.SkipDayType = args.SkipDayType;
        this.YearlyRecurrenceType = args.YearlyRecurrenceType;
        this.DaysOfYear = args.DaysOfYear;
        this.recurrenceType = args.recurrenceType;
        this.aliasName = args.aliasName;
        this.Working = args.Working;
        this.AllDay = args.AllDay;
        this.Location = args.Location;
        this.Month = args.Month;
        this.AppointmentID = args.AppointmentID;
        this.ContainerID = this.container.id;
    },

    buildControl: function() {
        var html = "<input type=\"hidden\" id=\"" + this.container.id + "_appointmentID\" />";
        html += "<table style=\"width:99%;\">";
        html += "        <tr>";
        html += "            <td valign=\"top\">What:</td>";
        html += "            <td><input type=\"text\" id=\"" + this.container.id + "_txtName\" style=\"width:100%;\" /></td>";
        html += "        </tr>";
        html += "        <tr>";
        html += "            <td valign=\"top\">When:</td>";
        html += "            <td>";
        html += "                <table>";
        html += "                    <tr>";
        html += "                        <td>Start Time:</td>";
        html += "                        <td>";
        html += "                            <input type=\"text\" id=\"" + this.container.id + "_txtStartDate\" />&nbsp;<input type=\"text\" id=\"" + this.container.id + "_txtStartTime\" />";
        html += "                        </td>";
        html += "                    </tr>";
        html += "                    <tr>";
        html += "                        <td>End Time:</td>";
        html += "                        <td>";
        html += "                           <input type=\"text\" id=\"" + this.container.id + "_txtEndTime\" />";
        html += "                           &nbsp;<a href='javascript:void(0);' onclick='makeAllDay(\"" + this.container.id + "\");'>All day event</a>";
        html += "                        </td>";
        html += "                    </tr>";
        html += "                </table>";
        html += "            </td>";
        html += "        </tr>";
        html += "        <tr>";
        html += "            <td valign=\"top\">Repeats:</td>";
        html += "            <td>";
        html += "            <select id=\"" + this.container.id + "_ddlRecurrenceType\" onchange=\"showRecurrence(this,'" + this.container.id + "');\">";
        html += "                <option value=\"Single\" selected=\"selected\">Does not repeat</option>";
        html += "                <option value=\"Daily\">Daily</option>";
        html += "                <option value=\"Weekly\">Weekly</option>";
        html += "                <option value=\"Monthly\">Monthly</option>";
        html += "                <option value=\"Yearly\">Yearly</option>";
        html += "            </select>";
        html += "                <div id=\"" + this.container.id + "_divRecurrenceContainer\" class=\"recurrencePanel\" style=\"display:none;\">";
        html += "                    <div id=\"" + this.container.id + "_tblDailyRecurrence\" style=\"display:none;\">";
        html += "                        <input type=\"radio\" id=\"" + this.container.id + "_dr_chkEveryXDays\" name=\"" + this.container.id + "_dailyR_chkEvery\" value=\"EveryXDays\" checked=\"checked\" /> ";
        html += "                            <label for=\"" + this.container.id + "_dr_chkEveryXDays\">Every </label><input type=\"text\" size=\"4\" id=\"" + this.container.id + "_dailyR_txtEvery\" /> day(s)<br />";
        html += "                        <input type=\"radio\" id=\"" + this.container.id + "_dr_chkEveryWeekday\" name=\"" + this.container.id + "_dailyR_chkEvery\" value=\"EveryWeekday\" /> ";
        html += "                            <label for=\"" + this.container.id + "_dr_chkEveryWeekday\">Every Weekday</label>";
        html += "                    </div>";
        html += "                    <div id=\"" + this.container.id + "_tblWeeklyRecurrence\" style=\"display:none;\">";
        html += "                        Recurs every <input type=\"text\" size=\"4\" id=\"" + this.container.id + "_weekR_txtEvery\" /> week(s) on<br />";
        html += "                        <input type=\"checkbox\" value=\"Saturday\" id=\"" + this.container.id + "_weekR_saturday\" name=\"" + this.container.id + "_weekR_dayofweek\" /><label for=\"" + this.container.id + "_weekR_saturday\">Saturday</label>";
        html += "                        <input type=\"checkbox\" value=\"Monday\" id=\"" + this.container.id + "_weekR_monday\" name=\"" + this.container.id + "_weekR_dayofweek\" /><label for=\"" + this.container.id + "_weekR_monday\">Monday</label>";
        html += "                        <input type=\"checkbox\" value=\"Tuesday\" id=\"" + this.container.id + "_weekR_tuesday\" name=\"" + this.container.id + "_weekR_dayofweek\" /><label for=\"" + this.container.id + "_weekR_tuesday\">Tuesday</label>";
        html += "                        <input type=\"checkbox\" value=\"Wednesday\" id=\"" + this.container.id + "_weekR_wednesday\" name=\"" + this.container.id + "_weekR_dayofweek\" /><label for=\"" + this.container.id + "_weekR_wednesday\">Wednesday</label><br />";
        html += "                        <input type=\"checkbox\" value=\"Thursday\" id=\"" + this.container.id + "_weekR_thursday\" name=\"" + this.container.id + "_weekR_dayofweek\" /><label for=\"" + this.container.id + "_weekR_thursday\">Thursday</label>";
        html += "                        <input type=\"checkbox\" value=\"Friday\" id=\"" + this.container.id + "_weekR_friday\" name=\"" + this.container.id + "_weekR_dayofweek\" /><label for=\"" + this.container.id + "_weekR_friday\">Friday</label>";
        html += "                        <input type=\"checkbox\" value=\"Sunday\" id=\"" + this.container.id + "_weekR_sunday\" name=\"" + this.container.id + "_weekR_dayofweek\" /><label for=\"" + this.container.id + "_weekR_sunday\">Sunday</label>";
        html += "                    </div>";
        ///#########
        /// Month Recurrence
        html += "                    <div id=\"" + this.container.id + "_tblMonthlyRecurrence\" style=\"display:none;\">";
        html += "                        <input type=\"radio\" name=\"" + this.container.id + "_monthR_monthlyRecurrenceType\" id=\"" + this.container.id + "_monthR_DayOfXMonths\" value=\"DayOfXMonths\" checked=\"checked\" />";
        html += "                        <label for=\"" + this.container.id + "_monthR_DaysOfXMonth\">Day(s)</label>";
        html += "                        <input type=\"text\" size=\"8\" id=\"" + this.container.id + "_monthR_txtDay\" title=\"Enter comma seperated list of days for multiples.\" /> of every ";
        html += "                        <input type=\"text\" size=\"4\" id=\"" + this.container.id + "_monthR_txtMonth\" /> month(s)<br />";
        html += "                        ";
        html += "                        <input type=\"radio\" name=\"" + this.container.id + "_monthR_monthlyRecurrenceType\" id=\"" + this.container.id + "_monthR_XOfEveryMonths\" value=\"XOfEveryMonths\" />";
        html += "                        <label for=\"" + this.container.id + "_monthR_XOfEveryMonth\">The</label>";
        html += "                        <select id=\"" + this.container.id + "_monthR_XInstance\">";
        html += "                            <option value=\"First\">first</option>";
        html += "                            <option value=\"Second\">second</option>";
        html += "                            <option value=\"Third\">third</option>";
        html += "                            <option value=\"Fourth\">fourth</option>";
        html += "                            <option value=\"Last\">last</option>";
        html += "                        </select>";
        html += "                        <select id=\"" + this.container.id + "_monthR_XInstanceDay\">";
        html += "                            <option value=\"Day\">day</option>";
        html += "                            <option value=\"Weekday\">weekday</option>";
        html += "                            <option value=\"Weekend_Day\">weekend day</option>";
        html += "                            <option value=\"Sunday\">Sunday</option>";
        html += "                            <option value=\"Monday\">Monday</option>";
        html += "                            <option value=\"Tuesday\">Tuesday</option>";
        html += "                            <option value=\"Wednesday\">Wednesday</option>";
        html += "                            <option value=\"Thursday\">Thursday</option>";
        html += "                            <option value=\"Firday\">Firday</option>";
        html += "                            <option value=\"Saturday\">Saturday</option>";
        html += "                        </select>";
        html += "                        &nbsp;of every&nbsp;";
        html += "                        <input type=\"text\" size=\"4\" id=\"" + this.container.id + "_monthR_XInstanceMonth\" /> month(s)";
        html += "                    </div>";
        ///#########
        /// Yearly Recurrence
        html += "                    <div id=\"" + this.container.id + "_tblYearlyRecurrence\" style=\"display:none;\">";
        html += "                        <input type=\"radio\" name=\"" + this.container.id + "_yearR_yearlyRecurrenceType\" id=\"" + this.container.id + "_yearR_EveryMonthDay\" value=\"EveryMonthDay\" checked=\"checked\" />";
        html += "                        <label for=\"" + this.container.id + "_yearR_EveryMonthDay\">Every</label>";
        html += "                        <select id=\"" + this.container.id + "_yearR_EveryMonth\">";
        html += "                            <option value=\"1\">January</option>";
        html += "                            <option value=\"2\">February</option>";
        html += "                            <option value=\"3\">March</option>";
        html += "                            <option value=\"4\">April</option>";
        html += "                            <option value=\"5\">May</option>";
        html += "                            <option value=\"6\">June</option>";
        html += "                            <option value=\"7\">July</option>";
        html += "                            <option value=\"8\">August</option>";
        html += "                            <option value=\"9\">September</option>";
        html += "                            <option value=\"10\">October</option>";
        html += "                            <option value=\"11\">November</option>";
        html += "                            <option value=\"12\">December</option>";
        html += "                        </select> ";
        html += "                        <input type=\"text\" size=\"4\" id=\"" + this.container.id + "_yearR_EveryDay\" title=\"Enter comma seperated list of days for multiples.\" /> ";
        html += "                        of every <input type=\"text\" size=\"4\" id=\"" + this.container.id + "_yearR_EveryYear\" /> year(s)<br />";
        html += "                        ";
        html += "                        <input type=\"radio\" name=\"" + this.container.id + "_yearR_yearlyRecurrenceType\" id=\"" + this.container.id + "_yearR_EveryXDayOfMonth\" value=\"XOfEveryMonths\" />";
        html += "                        <label for=\"" + this.container.id + "_yearR_EveryXDayOfMonth\">The</label>";
        html += "                        <select id=\"" + this.container.id + "_yearR_EveryX\">";
        html += "                            <option value=\"First\">first</option>";
        html += "                            <option value=\"Second\">second</option>";
        html += "                            <option value=\"Third\">third</option>";
        html += "                            <option value=\"Fourth\">fourth</option>";
        html += "                            <option value=\"Last\">last</option>";
        html += "                        </select>";
        html += "                        <select id=\"" + this.container.id + "_yearR_EveryXDay\">";
        html += "                            <option value=\"Day\">day</option>";
        html += "                            <option value=\"Weekday\">weekday</option>";
        html += "                            <option value=\"Weekend_Day\">weekend day</option>";
        html += "                            <option value=\"Sunday\">Sunday</option>";
        html += "                            <option value=\"Monday\">Monday</option>";
        html += "                            <option value=\"Tuesday\">Tuesday</option>";
        html += "                            <option value=\"Wednesday\">Wednesday</option>";
        html += "                            <option value=\"Thursday\">Thursday</option>";
        html += "                            <option value=\"Firday\">Firday</option>";
        html += "                            <option value=\"Saturday\">Saturday</option>";
        html += "                        </select>";
        html += "                        &nbsp;of &nbsp;";
        html += "                        <select id=\"" + this.container.id + "_yearR_EveryXMonth\">";
        html += "                            <option value=\"1\">January</option>";
        html += "                            <option value=\"2\">February</option>";
        html += "                            <option value=\"3\">March</option>";
        html += "                            <option value=\"4\">April</option>";
        html += "                            <option value=\"5\">May</option>";
        html += "                            <option value=\"6\">June</option>";
        html += "                            <option value=\"7\">July</option>";
        html += "                            <option value=\"8\">August</option>";
        html += "                            <option value=\"9\">September</option>";
        html += "                            <option value=\"10\">October</option>";
        html += "                            <option value=\"11\">November</option>";
        html += "                            <option value=\"12\">December</option>";
        html += "                        </select> ";
        html += "                        of every <input type=\"text\" size=\"4\" id=\"" + this.container.id + "_yearR_EveryXYear\" /> year(s)";
        html += "                    </div>";
        ///#########
        /// Recurrence Range
        html += "                    <fieldset>";
        html += "                        <legend>Recurrence Range</legend>";
        html += "                    ";
        html += "                        <div id=\"" + this.container.id + "_divRecurRange\">";
        html += "                            <input type=\"radio\" id=\"" + this.container.id + "_recurRange_EndDateNone\" name=\"" + this.container.id + "_recurRange_EndDateType\" value=\"NONE\" onchange=\"$('" + this.container.id + "_RecurrenceRestartDiv').hide();\" checked=\"checked\" /><label for=\"" + this.container.id + "_recurRange_EndDateNone\">No end date</label><br />";
        html += "                            <input type=\"radio\" id=\"" + this.container.id + "_recurRange_EndDateAfterX\" name=\"" + this.container.id + "_recurRange_EndDateType\" value=\"EndAfterX\" onchange=\"$('" + this.container.id + "_RecurrenceRestartDiv').show();\" /><label for=\"" + this.container.id + "_recurRange_EndDateAfterX\">End after: </label>";
        html += "                                <input type=\"text\" size=\"4\" id=\"" + this.container.id + "_recurRange_EndAfterOccur\" /> occurrences<br />";
        html += "                            <input type=\"radio\" id=\"" + this.container.id + "_recurRange_EndDateByDate\" name=\"" + this.container.id + "_recurRange_EndDateType\" value=\"EndByDate\" onchange=\"$('" + this.container.id + "_RecurrenceRestartDiv').show();\" /><label for=\"" + this.container.id + "_recurRange_EndDateByDate\">End By: </label>";
        html += "                                <input type=\"text\" id=\"" + this.container.id + "_recurRange_EndByDate\" />";
        html += "                        </div>";
        html += "                        <div id=\"" + this.container.id + "_RecurrenceRestartDiv\" style=\"display:none;\">";
        html += "                            <input type=\"checkbox\" id=\"" + this.container.id + "_RecurrenceRestart\" /><label for=\"" + this.container.id + "_RecurrenceRestart\">Restart this recurrence cycle each year</label>";
        html += "                        </div>";
        html += "                    </fieldset>";
        html += "                </div>";
        html += "            </td>";
        html += "        </tr>";
        ///#########
        /// Working or AllDay
        html += "        <tr>";
        html += "            <td>&nbsp;</td>";
        html += "            <td>Schedule as: <select id=\"" + this.container.id + "_ddlWorking\" />";
        html += "                   <option value=\"0\">Off</option>";
        html += "                   <option value=\"1\">Working</option>";
        if (this.supportOnCall) {
            html += "                   <option value=\"2\">On Call</option>";
        }
        html += "               </select>";
        html += "            </td>";
        html += "        </tr>";
        html += "        <tr>";
        html += "            <td valign=\"top\">Where:</td>";
        html += "            <td style=\"white-space:nowrap;\"><input type=\"text\" id=\"" + this.container.id + "_txtLocation\" style=\"width:95%;\" /></td>";
        html += "        </tr>";
        html += "        <tr>";
        html += "            <td valign=\"top\">Description:</td>";
        html += "            <td><textarea id=\"" + this.container.id + "_txtDescription\" rows=\"10\" cols=\"60\" style=\"width:100%;\"></textarea></td>";
        html += "        </tr>";
        html += "    </table>";
        ///#########
        /// Save Appointments
        html += "    <input type=\"button\" value=\"Save Appointment\" onclick=\"saveAppointment($('" + this.container.id + "'));\" />";
        html += "    <input type=\"button\" value=\"Cancel\" onclick=\"cancelAppointment($('" + this.container.id + "'));\" />";

        this.container.update(html);
    },

    getElement: function(id) {
        id = this.container.id + "_" + id;
        return window.top.$(id);
    },

    saveToServer: function() {
        showLoading("Saving...");
        window.top.ServerFunction("Odatech.Business.AppointmentFactory.SaveAppointment|" + Object.toJSON(this), Object.toJSON(this));
    },

    getValues: function() {
        this.AppointmentID = window.top.$F(this.container.id + '_appointmentID');
        this.Name = window.top.$F(this.container.id + '_txtName');
        this.Description = window.top.$F(this.container.id + '_txtDescription');
        this.StartDate = window.top.$F(this.container.id + '_txtStartDate');
        this.StartTime = window.top.$F(this.container.id + '_txtStartTime');
        this.EndDate = window.top.$F(this.container.id + '_txtStartDate');
        this.EndTime = window.top.$F(this.container.id + '_txtEndTime');
        this.recurrenceType = window.top.$F(this.container.id + '_ddlRecurrenceType');
        this.Working = window.top.$F(this.container.id + '_ddlWorking');
        this.AllDay = false;
        this.Location = window.top.$F(this.container.id + '_txtLocation');


        // Range of Recurrence
        this.RecurrenceStartDate = this.StartDate + ' ' + this.StartTime;
        this.RecurrenceEndType = window.top.protoda.$RF(this.container.id + '_recurRange_EndDateType');
        this.RecurrenceEndAfterX = window.top.$F(this.container.id + '_recurRange_EndAfterOccur');
        this.RecurrenceEndDate = window.top.$F(this.container.id + '_recurRange_EndByDate');
        this.RecurrenceRestart = window.top.$(this.container.id + '_RecurrenceRestart').checked;


        if (this.recurrenceType.toLowerCase() == "daily") {
            this.DailyRecurrenceType = window.top.protoda.$RF(this.container.id + '_dailyR_chkEvery');
            if (this.DailyRecurrenceType == 'EveryXDays') {
                this.Interval = window.top.$F(this.container.id + '_dailyR_txtEvery');
            }
        }
        else if (this.recurrenceType.toLowerCase() == "weekly") {
            this.Interval = window.top.$F(this.container.id + "_weekR_txtEvery");
            this.DaysOfWeek = window.top.protoda.$CF(this.container.id + '_weekR_dayofweek').join(',');
        }
        else if (this.recurrenceType.toLowerCase() == "monthly") {
            this.MonthlyRecurrenceType = window.top.protoda.$RF(this.container.id + "_monthR_monthlyRecurrenceType");
            if (this.MonthlyRecurrenceType.toLowerCase() == "dayofxmonths") {
                this.Interval = window.top.$F(this.container.id + "_monthR_txtMonth");
                this.DaysOfMonth = window.top.$F(this.container.id + "_monthR_txtDay");
            }
            else if (this.MonthlyRecurrenceType.toLowerCase() == "xofeverymonths") {
                this.Interval = window.top.$F(this.container.id + "_monthR_XInstanceMonth");
                this.SkipType = window.top.$F(this.container.id + "_monthR_XInstance");
                this.SkipDayType = window.top.$F(this.container.id + "_monthR_XInstanceDay");
            }
        }
        else if (this.recurrenceType.toLowerCase() == "yearly") {
            this.YearlyRecurrenceType = window.top.protoda.$RF(this.container.id + "_yearR_yearlyRecurrenceType");
            if (this.YearlyRecurrenceType.toLowerCase() == "EveryMonthDay".toLowerCase()) {
                this.Interval = window.top.$F(this.container.id + "_yearR_EveryYear");
                this.Month = window.top.$F(this.container.id + "_yearR_EveryMonth");
                this.DaysOfYear = window.top.$F(this.container.id + "_yearR_EveryDay");
            }
            else if (this.YearlyRecurrenceType.toLowerCase() == "XOfEveryMonths".toLowerCase()) {
                this.Interval = window.top.$F(this.container.id + "_yearR_EveryXYear");
                this.SkipType = window.top.$F(this.container.id + "_yearR_EveryX");
                this.SkipDayType = window.top.$F(this.container.id + "_yearR_EveryXDay");
                this.Month = window.top.$F(this.container.id + "_yearR_EveryXMonth");
            }
        }
    },

    initForm: function() {
        window.top.$S(this.container.id + '_appointmentID', this.AppointmentID);
        window.top.$S(this.container.id + '_txtName', this.Name);
        window.top.$S(this.container.id + '_txtDescription', this.Description);
        window.top.$S(this.container.id + '_txtStartDate', this.StartDate);
        window.top.$S(this.container.id + '_txtStartTime', this.StartTime);
        window.top.$S(this.container.id + '_txtEndTime', this.EndTime);
        window.top.$S(this.container.id + '_ddlRecurrenceType', this.recurrenceType);
        window.top.$S(this.container.id + '_ddlWorking', this.Working);
        window.top.$S(this.container.id + '_txtLocation', this.Location);

        // Range of Recurrence
        window.top.protoda.$RS(this.container.id + '_recurRange_EndDateType', this.RecurrenceEndType);
        window.top.$S(this.container.id + '_recurRange_EndAfterOccur', this.RecurrenceEndAfterX);
        window.top.$S(this.container.id + '_recurRange_EndByDate', this.RecurrenceEndDate);
        window.top.$S(this.container.id + '_RecurrenceRestart', this.RecurrenceRestart);


        if (this.recurrenceType.toLowerCase() == "daily") {
            window.top.protoda.$RS(this.container.id + '_dailyR_chkEvery', this.DailyRecurrenceType);
            if (this.DailyRecurrenceType == 'EveryXDays') {
                window.top.$S(this.container.id + '_dailyR_txtEvery', this.Interval);
            }
        }
        else if (this.recurrenceType.toLowerCase() == "weekly") {
            window.top.$S(this.container.id + "_weekR_txtEvery", this.Interval);
            window.top.protoda.$CS(this.container.id + '_weekR_dayofweek', this.DaysOfWeek.split(','));
        }
        else if (this.recurrenceType.toLowerCase() == "monthly") {
            window.top.protoda.$RS(this.container.id + "_monthR_monthlyRecurrenceType", this.MonthlyRecurrenceType);
            if (this.MonthlyRecurrenceType.toLowerCase() == "dayofxmonths") {
                window.top.$S(this.container.id + "_monthR_txtMonth", this.Interval);
                window.top.$S(this.container.id + "_monthR_txtDay", this.DaysOfMonth);
            }
            else if (this.MonthlyRecurrenceType.toLowerCase() == "xofeverymonths") {
                window.top.$S(this.container.id + "_monthR_XInstanceMonth", this.Interval);
                window.top.$S(this.container.id + "_monthR_XInstance", this.SkipType);
                window.top.$S(this.container.id + "_monthR_XInstanceDay", this.SkipDayType);
            }
        }
        else if (this.recurrenceType.toLowerCase() == "yearly") {
            window.top.protoda.$RS(this.container.id + "_yearR_yearlyRecurrenceType", this.YearlyRecurrenceType);
            if (this.YearlyRecurrenceType.toLowerCase() == "EveryMonthDay".toLowerCase()) {
                window.top.$S(this.container.id + "_yearR_EveryYear", this.Interval);
                window.top.$S(this.container.id + "_yearR_EveryMonth", this.Month);
                window.top.$S(this.container.id + "_yearR_EveryDay", this.DaysOfYear);
            }
            else if (this.YearlyRecurrenceType.toLowerCase() == "XOfEveryMonths".toLowerCase()) {
                window.top.$S(this.container.id + "_yearR_EveryXYear", this.Interval);
                window.top.$S(this.container.id + "_yearR_EveryX", this.SkipType);
                window.top.$S(this.container.id + "_yearR_EveryXDay", this.SkipDayType);
                window.top.$S(this.container.id + "_yearR_EveryXMonth", this.Month);
            }
        }
    },

    validAppointment: function() {
        if (this.Name.length == 0) {
            alert("Schedule must have a name");
            return false;
        }

        var dateRE = /^\d{1,2}[\/-\\]\d{1,2}[\/-\\]\d{4}$/gi;
        var timeRE = /^\d{1,2}:\d{2}(?::\d{2})?(?:\s+(?:a|p|AM|PM))?$/gi;

        if (!this.StartDate.match(dateRE)) {
            alert("Invalid start date.");
            return false;
        }

        if (!this.StartTime.match(timeRE)) {
            alert("Invalid start time.");
            return false;
        }

        if (!this.EndTime.match(timeRE)) {
            alert("Invalid end time.");
            return false;
        }

        if (this.RecurrenceEndType == 'EndByDate') {
            if (!this.RecurrenceEndDate.match(dateRE)) {
                alert("Invalid recurrence end date.");
                return false;
            }
        }

        return true;
    }
};

// events
saveAppointment = function(container) {
    var appointment = window.top.$(container).appointment;
    appointment.getValues();
    if (ensureEndTimeIsAfterStartTime(appointment.StartTime, appointment.EndTime) && appointment.validAppointment()) {
        appointment.saveToServer();
    }
};

cancelAppointment = function (container){
    if(window.top.$(container.id + "_window")){
        window.top.$(container.id + "_window").hide();
    }
    else{
        window.top.$(container).hide();
    }
};

ensureEndTimeIsAfterStartTime = function(startTime, endTime) {
    var sStartTime = parseODATextboxTimeString(startTime);
    var sEndTime = parseODATextboxTimeString(endTime);
    if(sStartTime == null || sEndTime == null){
        return false;
    }
    
    if(sStartTime > sEndTime){
        $S(sEndTime, "");
        alert("End Time cannot be before Start Time");
        return false;
    }
    
    return true;
};

parseODATextboxTimeString = function(timeString) {
    timeString = timeString.toString();
    if (timeString.indexOf('x', 0) > -1) {
        return null;
    }

    var myDate = new Date('January 1 2009 ' + timeString);
    return myDate;
};

makeAllDay = function(controlID) {
    $S(controlID + "_txtStartTime", "12:00 AM");
    $S(controlID + "_txtEndTime", "11:59 PM");
}

// save callback from server
function SaveAppointment(args, context) {
    hideLoading();
    alert(args.split('~ARGS~')[0]);

    //var appointment = eval('(' + context + ')');
    var appointment = context;
    if(window.top.$(appointment.ContainerID + "_window")){
        window.top.$(appointment.ContainerID + "_window").remove();
    }
    else{
        window.top.$(appointment.ContainerID).remove();
    }
    
    appointment.AppointmentID = args.split('~ARGS~')[1];
    if(appointmentSave && typeof appointmentSave == 'function'){
        appointmentSave(appointment);
    }
};

function LoadAppointment(args,context){
    appointment = window.top.loadingAppointments.get(context);
    appointment.setVariables(args);
    appointment.initForm();
}

// dom method to show/hide portions of the control
showRecurrence = function(_ddlRecurrence, containerID) {
    if (containerID == null || containerID.length == 0) {
        $("schedule_tblDailyRecurrence").hide();
        $("schedule_tblWeeklyRecurrence").hide();
        $("schedule_tblMonthlyRecurrence").hide();
        $("schedule_tblYearlyRecurrence").hide();
        $("schedule_divRecurrenceContainer").hide();

        if ($F(_ddlRecurrence).toLowerCase() == "daily") {
            $("schedule_tblDailyRecurrence").show();
            $("schedule_divRecurrenceContainer").show();
        }
        if ($F(_ddlRecurrence).toLowerCase() == "weekly") {
            $("schedule_tblWeeklyRecurrence").show();
            $("schedule_divRecurrenceContainer").show();
        }
        if ($F(_ddlRecurrence).toLowerCase() == "monthly") {
            $("schedule_tblMonthlyRecurrence").show();
            $("schedule_divRecurrenceContainer").show();
        }
        if ($F(_ddlRecurrence).toLowerCase() == "yearly") {
            $("schedule_tblYearlyRecurrence").show();
            $("schedule_divRecurrenceContainer").show();
        }
    }
    else {
        $(containerID + "_tblDailyRecurrence").hide();
        $(containerID + "_tblWeeklyRecurrence").hide();
        $(containerID + "_tblMonthlyRecurrence").hide();
        $(containerID + "_tblYearlyRecurrence").hide();
        $(containerID + "_divRecurrenceContainer").hide();

        if ($F(_ddlRecurrence).toLowerCase() == "daily") {
            $(containerID + "_tblDailyRecurrence").show();
            $(containerID + "_divRecurrenceContainer").show();
        }
        if ($F(_ddlRecurrence).toLowerCase() == "weekly") {
            $(containerID + "_tblWeeklyRecurrence").show();
            $(containerID + "_divRecurrenceContainer").show();
        }
        if ($F(_ddlRecurrence).toLowerCase() == "monthly") {
            $(containerID + "_tblMonthlyRecurrence").show();
            $(containerID + "_divRecurrenceContainer").show();
        }
        if ($F(_ddlRecurrence).toLowerCase() == "yearly") {
            $(containerID + "_tblYearlyRecurrence").show();
            $(containerID + "_divRecurrenceContainer").show();
        }
    }
};


var ODASchedule = new Class.create();
ODASchedule.prototype = {
    initialize: function(_parentContainer, _renderSaveCancel, _col1Width) {
        this.col1Width = _col1Width;
        if (this.col1Width == null || this.col1Width.length == 0 || isNaN(this.col1Width)) {
            this.col1Width = 80;
        }
        if (_parentContainer != null && _parentContainer.length > 0) {
            this.parentContainer = _parentContainer;
            this.RenderScheduleHtml(_renderSaveCancel);
        }
        this.initializeVariables();
    },
    initializeVariables: function() {
        this.Name = "";
        this.Description = "";
        this.StartDate = "";
        this.StartTime = "";
        this.RecurrenceStartDate = "";
        this.RecurrenceEndType = "";
        this.RecurrenceEndAfterX = "";
        this.RecurrenceEndDate = "";
        this.RecurrenceRestart = false;
        this.Interval = 1;
        this.DailyRecurrenceType = "";      //(EveryXDays | EveryWeekday)
        this.DaysOfWeek = "";
        this.MonthlyRecurrenceType = "";    //(DayOfXMonths | XOfEveryMonths)
        this.DaysOfMonth = "";
        this.SkipType = "";                 //(Enum: ScheduleIntervalSkipType)
        this.SkipDayType = "";              //(Enum: ScheduleIntervalSkipDayType)
        this.YearlyRecurrenceType = "";     //(EveryMonthDay | XOfEveryMonths)
        this.DaysOfYear = "";
        this.recurrenceType = "";           //(daily | weekly | monthly | yearly | single)
        this.aliasName = "Default";                //AliasName in config file that points to the current SessionMgr Instance
        this.Month = 1;
        this.AppointmentID = "";
    },

    setVariables: function(args) {
        this.Name = args.Name;
        this.StartDate = args.StartDate;
        this.StartTime = args.StartTime;
        this.RecurrenceStartDate = args.RecurrenceStartDate;
        this.RecurrenceEndType = args.RecurrenceEndType;
        this.RecurrenceEndAfterX = args.RecurrenceEndAfterX;
        this.RecurrenceEndDate = args.RecurrenceEndDate;
        this.RecurrenceRestart = args.RecurrenceRestart;
        this.Interval = args.Interval;
        this.DailyRecurrenceType = args.DailyRecurrenceType;
        this.DaysOfWeek = args.DaysOfWeek;
        this.MonthlyRecurrenceType = args.MonthlyRecurrenceType;
        this.DaysOfMonth = args.DaysOfMonth;
        this.SkipType = args.SkipType;
        this.SkipDayType = args.SkipDayType;
        this.YearlyRecurrenceType = args.YearlyRecurrenceType;
        this.DaysOfYear = args.DaysOfYear;
        this.recurrenceType = args.recurrenceType;
        this.aliasName = args.aliasName;
        this.Month = args.Month;
        this.AppointmentID = args.AppointmentID;
    },
    getValues: function() {
    this.Name = window.top.$F('schedule_txtName');
    this.StartDate = window.top.$F('schedule_txtStartDate');
        //this.StartTime = window.top.$F('txtStartTime');
        this.recurrenceType = window.top.$F('schedule_ddlRecurrenceType');


        // Range of Recurrence
        this.RecurrenceStartDate = this.StartDate; // +' ' + this.StartTime;
        this.RecurrenceEndType = window.top.protoda.$RF('recurRange_EndDateType');
        this.RecurrenceEndAfterX = window.top.$F('schedule_recurRange_EndAfterOccur');
        this.RecurrenceEndDate = window.top.$F('schedule_recurRange_EndByDate');
        this.RecurrenceRestart = window.top.$('schedule_RecurrenceRestart').checked;


        if (this.recurrenceType.toLowerCase() == "daily") {
            this.DailyRecurrenceType = window.top.protoda.$RF('dailyR_chkEvery');
            if (this.DailyRecurrenceType == 'EveryXDays') {
                this.Interval = window.top.$F('schedule_dailyR_txtEvery');
            }
        }
        else if (this.recurrenceType.toLowerCase() == "weekly") {
        this.Interval = window.top.$F("schedule_weekR_txtEvery");
            this.DaysOfWeek = window.top.protoda.$CF('weekR_dayofweek').join(',');
        }
        else if (this.recurrenceType.toLowerCase() == "monthly") {
            this.MonthlyRecurrenceType = window.top.protoda.$RF("monthR_monthlyRecurrenceType");
            if (this.MonthlyRecurrenceType.toLowerCase() == "dayofxmonths") {
                this.Interval = window.top.$F("schedule_monthR_txtMonth");
                this.DaysOfMonth = window.top.$F("schedule_monthR_txtDay");
            }
            else if (this.MonthlyRecurrenceType.toLowerCase() == "xofeverymonths") {
            this.Interval = window.top.$F("schedule_monthR_XInstanceMonth");
                this.SkipType = window.top.$F("schedule_monthR_XInstance");
                this.SkipDayType = window.top.$F("schedule_monthR_XInstanceDay");
            }
        }
        else if (this.recurrenceType.toLowerCase() == "yearly") {
            this.YearlyRecurrenceType = window.top.protoda.$RF("yearR_yearlyRecurrenceType");
            if (this.YearlyRecurrenceType.toLowerCase() == "EveryMonthDay".toLowerCase()) {
                this.Interval = window.top.$F("schedule_yearR_EveryYear");
                this.Month = window.top.$F("schedule_yearR_EveryMonth");
                this.DaysOfYear = window.top.$F("schedule_yearR_EveryDay");
            }
            else if (this.YearlyRecurrenceType.toLowerCase() == "XOfEveryMonths".toLowerCase()) {
            this.Interval = window.top.$F("schedule_yearR_EveryXYear");
                this.SkipType = window.top.$F("schedule_yearR_EveryX");
                this.SkipDayType = window.top.$F("schedule_yearR_EveryXDay");
                this.Month = window.top.$F("schedule_yearR_EveryXMonth");
            }
        }
    },

    initForm: function() {
    window.top.$S('schedule_appointmentID', this.AppointmentID);
        window.top.$S('schedule_txtName', this.Name);
        window.top.$S('schedule_txtDescription', this.Description);
        window.top.$S('schedule_txtStartDate', this.StartDate);
        //window.top.$S('txtStartTime', this.StartTime);
        window.top.$S('schedule_txtEndTime', this.EndTime);
        window.top.$S('schedule_ddlRecurrenceType', this.recurrenceType);
        window.top.$S('schedule_ddlWorking', this.Working);
        window.top.$S('schedule_txtLocation', this.Location);

        // Range of Recurrence
        window.top.protoda.$RS('recurRange_EndDateType', this.RecurrenceEndType);
        window.top.$S('schedule_recurRange_EndAfterOccur', this.RecurrenceEndAfterX);
        window.top.$S('schedule_recurRange_EndByDate', this.RecurrenceEndDate);
        window.top.$S('schedule_RecurrenceRestart', this.RecurrenceRestart);


        if (this.recurrenceType.toLowerCase() == "daily") {
            window.top.protoda.$RS('dailyR_chkEvery', this.DailyRecurrenceType);
            if (this.DailyRecurrenceType == 'EveryXDays') {
                window.top.$S('schedule_dailyR_txtEvery', this.Interval);
            }
        }
        else if (this.recurrenceType.toLowerCase() == "weekly") {
        window.top.$S("schedule_weekR_txtEvery", this.Interval);
            window.top.protoda.$CS('weekR_dayofweek', this.DaysOfWeek.split(','));
        }
        else if (this.recurrenceType.toLowerCase() == "monthly") {
            window.top.protoda.$RS("monthR_monthlyRecurrenceType", this.MonthlyRecurrenceType);
            if (this.MonthlyRecurrenceType.toLowerCase() == "dayofxmonths") {
                window.top.$S("schedule_monthR_txtMonth", this.Interval);
                window.top.$S("schedule_monthR_txtDay", this.DaysOfMonth);
            }
            else if (this.MonthlyRecurrenceType.toLowerCase() == "xofeverymonths") {
            window.top.$S("schedule_monthR_XInstanceMonth", this.Interval);
                window.top.$S("schedule_monthR_XInstance", this.SkipType);
                window.top.$S("schedule_monthR_XInstanceDay", this.SkipDayType);
            }
        }
        else if (this.recurrenceType.toLowerCase() == "yearly") {
            window.top.protoda.$RS("yearR_yearlyRecurrenceType", this.YearlyRecurrenceType);
            if (this.YearlyRecurrenceType.toLowerCase() == "EveryMonthDay".toLowerCase()) {
                window.top.$S("schedule_yearR_EveryYear", this.Interval);
                window.top.$S("schedule_yearR_EveryMonth", this.Month);
                window.top.$S("schedule_yearR_EveryDay", this.DaysOfYear);
            }
            else if (this.YearlyRecurrenceType.toLowerCase() == "XOfEveryMonths".toLowerCase()) {
            window.top.$S("schedule_yearR_EveryXYear", this.Interval);
                window.top.$S("schedule_yearR_EveryX", this.SkipType);
                window.top.$S("schedule_yearR_EveryXDay", this.SkipDayType);
                window.top.$S("schedule_yearR_EveryXMonth", this.Month);
            }
        }
    },


    RenderScheduleHtml: function(_renderSaveCancel) {
        var html = "<table id=\"tblSchedule\">";
        html += "    <tr>";
        html += "        <td valign=\"top\" style=\"width: " + this.col1Width.toString() + "px;\">";
        html += "            Schedule Name:";
        html += "        </td>";
        html += "        <td style=\"width: auto;\">";
        html += "            <input type=\"text\" id=\"schedule_txtName\" style=\"width: 90%;\" />";
        html += "        </td>";
        html += "    </tr>";
        html += "    <tr>";
        html += "        <td>";
        html += "            Start Date:";
        html += "        </td>";
        html += "        <td>";
        html += "            <input type=\"text\" id=\"schedule_txtStartDate\" />";
        html += "        </td>";
        html += "    </tr>";
        html += "    <tr>";
        html += "        <td valign=\"top\">";
        html += "            Recurrence:";
        html += "        </td>";
        html += "        <td>";
        html += "            <select id=\"schedule_ddlRecurrenceType\" onchange=\"showRecurrence(this);\">";
        html += "                <option value=\"Single\" selected=\"selected\">Does not repeat</option>";
        html += "                <option value=\"Daily\">Daily</option>";
        html += "                <option value=\"Weekly\">Weekly</option>";
        html += "                <option value=\"Monthly\">Monthly</option>";
        html += "                <option value=\"Yearly\">Yearly</option>";
        html += "            </select>";
        html += "            <div id=\"schedule_divRecurrenceContainer\" class=\"recurrencePanel\" style=\"display: none;\">";
        html += "                <div id=\"schedule_tblDailyRecurrence\" style=\"display: none;\">";
        html += "                    <input type=\"radio\" id=\"schedule_dr_chkEveryXDays\" name=\"dailyR_chkEvery\" value=\"EveryXDays\"";
        html += "                        checked=\"checked\" />";
        html += "                    <label for=\"dr_chkEveryXDays\">";
        html += "                        Every";
        html += "                    </label>";
        html += "                    <input type=\"text\" size=\"4\" id=\"schedule_dailyR_txtEvery\" />";
        html += "                    day(s)<br />";
        html += "                    <input type=\"radio\" id=\"schedule_dr_chkEveryWeekday\" name=\"dailyR_chkEvery\" value=\"EveryWeekday\" />";
        html += "                    <label for=\"dr_chkEveryWeekday\">";
        html += "                        Every Weekday</label>";
        html += "                </div>";
        html += "                <div id=\"schedule_tblWeeklyRecurrence\" style=\"display: none;\">";
        html += "                    Recurs every";
        html += "                    <input type=\"text\" size=\"4\" id=\"schedule_weekR_txtEvery\" />";
        html += "                    week(s) on<br />";
        html += "                    <input type=\"checkbox\" value=\"Saturday\" id=\"schedule_weekR_saturday\" name=\"weekR_dayofweek\" /><label";
        html += "                        for=\"weekR_saturday\">Saturday</label>";
        html += "                    <input type=\"checkbox\" value=\"Monday\" id=\"schedule_weekR_monday\" name=\"weekR_dayofweek\" /><label";
        html += "                        for=\"weekR_monday\">Monday</label>";
        html += "                    <input type=\"checkbox\" value=\"Tuesday\" id=\"schedule_weekR_tuesday\" name=\"weekR_dayofweek\" /><label";
        html += "                        for=\"weekR_tuesday\">Tuesday</label>";
        html += "                    <input type=\"checkbox\" value=\"Wednesday\" id=\"schedule_weekR_wednesday\" name=\"weekR_dayofweek\" /><label";
        html += "                        for=\"weekR_wednesday\">Wednesday</label><br />";
        html += "                    <input type=\"checkbox\" value=\"Thursday\" id=\"schedule_weekR_thursday\" name=\"weekR_dayofweek\" /><label";
        html += "                        for=\"weekR_thursday\">Thursday</label>";
        html += "                    <input type=\"checkbox\" value=\"Friday\" id=\"schedule_weekR_friday\" name=\"weekR_dayofweek\" /><label";
        html += "                        for=\"weekR_friday\">Friday</label>";
        html += "                    <input type=\"checkbox\" value=\"Sunday\" id=\"schedule_weekR_sunday\" name=\"weekR_dayofweek\" /><label";
        html += "                        for=\"weekR_sunday\">Sunday</label>";
        html += "                </div>";
        html += "                <div id=\"schedule_tblMonthlyRecurrence\" style=\"display: none;\">";
        html += "                    <input type=\"radio\" name=\"monthR_monthlyRecurrenceType\" id=\"schedule_monthR_DayOfXMonths\"";
        html += "                        value=\"DayOfXMonths\" checked=\"checked\" />";
        html += "                    <label for=\"monthR_DaysOfXMonth\">";
        html += "                        Day(s)</label>";
        html += "                    <input type=\"text\" size=\"8\" id=\"schedule_monthR_txtDay\" title=\"Enter comma seperated list of days for multiples.\" />";
        html += "                    of every";
        html += "                    <input type=\"text\" size=\"4\" id=\"schedule_monthR_txtMonth\" />";
        html += "                    month(s)<br />";
        html += "                    <input type=\"radio\" name=\"monthR_monthlyRecurrenceType\" id=\"schedule_monthR_XOfEveryMonths\"";
        html += "                        value=\"XOfEveryMonths\" />";
        html += "                    <label for=\"monthR_XOfEveryMonth\">";
        html += "                        The</label>";
        html += "                    <select id=\"schedule_monthR_XInstance\">";
        html += "                        <option value=\"First\">first</option>";
        html += "                        <option value=\"Second\">second</option>";
        html += "                        <option value=\"Third\">third</option>";
        html += "                        <option value=\"Fourth\">fourth</option>";
        html += "                        <option value=\"Last\">last</option>";
        html += "                    </select>";
        html += "                    <select id=\"schedule_monthR_XInstanceDay\">";
        html += "                        <option value=\"Day\">day</option>";
        html += "                        <option value=\"Weekday\">weekday</option>";
        html += "                        <option value=\"Weekend_Day\">weekend day</option>";
        html += "                        <option value=\"Sunday\">Sunday</option>";
        html += "                        <option value=\"Monday\">Monday</option>";
        html += "                        <option value=\"Tuesday\">Tuesday</option>";
        html += "                        <option value=\"Wednesday\">Wednesday</option>";
        html += "                        <option value=\"Thursday\">Thursday</option>";
        html += "                        <option value=\"Firday\">Firday</option>";
        html += "                        <option value=\"Saturday\">Saturday</option>";
        html += "                    </select>";
        html += "                    &nbsp;of every&nbsp;";
        html += "                    <input type=\"text\" size=\"4\" id=\"schedule_monthR_XInstanceMonth\" />";
        html += "                    month(s)";
        html += "                </div>";
        html += "                <div id=\"schedule_tblYearlyRecurrence\" style=\"display: none;\">";
        html += "                    <input type=\"radio\" name=\"yearR_yearlyRecurrenceType\" id=\"schedule_yearR_EveryMonthDay\" value=\"EveryMonthDay\"";
        html += "                        checked=\"checked\" />";
        html += "                    <label for=\"yearR_EveryMonthDay\">";
        html += "                        Every</label>";
        html += "                    <select id=\"schedule_yearR_EveryMonth\">";
        html += "                        <option value=\"1\">January</option>";
        html += "                        <option value=\"2\">February</option>";
        html += "                        <option value=\"3\">March</option>";
        html += "                        <option value=\"4\">April</option>";
        html += "                        <option value=\"5\">May</option>";
        html += "                        <option value=\"6\">June</option>";
        html += "                        <option value=\"7\">July</option>";
        html += "                        <option value=\"8\">August</option>";
        html += "                        <option value=\"9\">September</option>";
        html += "                        <option value=\"10\">October</option>";
        html += "                        <option value=\"11\">November</option>";
        html += "                        <option value=\"12\">December</option>";
        html += "                    </select>";
        html += "                    <input type=\"text\" size=\"4\" id=\"schedule_yearR_EveryDay\" title=\"Enter comma seperated list of days for multiples.\" />";
        html += "                    of every";
        html += "                    <input type=\"text\" size=\"4\" id=\"schedule_yearR_EveryYear\" />";
        html += "                    year(s)<br />";
        html += "                    <input type=\"radio\" name=\"yearR_yearlyRecurrenceType\" id=\"schedule_yearR_EveryXDayOfMonth\"";
        html += "                        value=\"XOfEveryMonths\" />";
        html += "                    <label for=\"yearR_EveryXDayOfMonth\">";
        html += "                        The</label>";
        html += "                    <select id=\"schedule_yearR_EveryX\">";
        html += "                        <option value=\"First\">first</option>";
        html += "                        <option value=\"Second\">second</option>";
        html += "                        <option value=\"Third\">third</option>";
        html += "                        <option value=\"Fourth\">fourth</option>";
        html += "                        <option value=\"Last\">last</option>";
        html += "                    </select>";
        html += "                    <select id=\"schedule_yearR_EveryXDay\">";
        html += "                        <option value=\"Day\">day</option>";
        html += "                        <option value=\"Weekday\">weekday</option>";
        html += "                        <option value=\"Weekend_Day\">weekend day</option>";
        html += "                        <option value=\"Sunday\">Sunday</option>";
        html += "                        <option value=\"Monday\">Monday</option>";
        html += "                        <option value=\"Tuesday\">Tuesday</option>";
        html += "                        <option value=\"Wednesday\">Wednesday</option>";
        html += "                        <option value=\"Thursday\">Thursday</option>";
        html += "                        <option value=\"Firday\">Firday</option>";
        html += "                        <option value=\"Saturday\">Saturday</option>";
        html += "                    </select>";
        html += "                    &nbsp;of &nbsp;";
        html += "                    <select id=\"schedule_yearR_EveryXMonth\">";
        html += "                        <option value=\"1\">January</option>";
        html += "                        <option value=\"2\">February</option>";
        html += "                        <option value=\"3\">March</option>";
        html += "                        <option value=\"4\">April</option>";
        html += "                        <option value=\"5\">May</option>";
        html += "                        <option value=\"6\">June</option>";
        html += "                        <option value=\"7\">July</option>";
        html += "                        <option value=\"8\">August</option>";
        html += "                        <option value=\"9\">September</option>";
        html += "                        <option value=\"10\">October</option>";
        html += "                        <option value=\"11\">November</option>";
        html += "                        <option value=\"12\">December</option>";
        html += "                    </select>";
        html += "                    of every";
        html += "                    <input type=\"text\" size=\"4\" id=\"schedule_yearR_EveryXYear\" />";
        html += "                    year(s)";
        html += "                </div>";
        html += "                <fieldset>";
        html += "                    <legend>Recurrence Range</legend>";
        html += "                    <div id=\"schedule_divRecurRange\">";
        html += "                        <input type=\"radio\" id=\"schedule_recurRange_EndDateNone\" name=\"recurRange_EndDateType\" value=\"NONE\"";
        html += "                            onchange=\"$('schedule_RecurrenceRestartDiv').hide();\" checked=\"checked\" /><label for=\"recurRange_EndDateNone\">No";
        html += "                                end date</label><br />";
        html += "                        <input type=\"radio\" id=\"schedule_recurRange_EndDateAfterX\" name=\"recurRange_EndDateType\" value=\"EndAfterX\"";
        html += "                            onchange=\"$('schedule_RecurrenceRestartDiv').show();\" /><label for=\"recurRange_EndDateAfterX\">End";
        html += "                                after:";
        html += "                            </label>";
        html += "                        <input type=\"text\" size=\"4\" id=\"schedule_recurRange_EndAfterOccur\" />";
        html += "                        occurrences<br />";
        html += "                        <input type=\"radio\" id=\"schedule_recurRange_EndDateByDate\" name=\"recurRange_EndDateType\" value=\"EndByDate\"";
        html += "                            onchange=\"$('schedule_RecurrenceRestartDiv').show();\" /><label for=\"recurRange_EndDateByDate\">End";
        html += "                                By:";
        html += "                            </label>";
        html += "                        <input type=\"text\" id=\"schedule_recurRange_EndByDate\" />";
        html += "                    </div>";
        html += "                    <div id=\"schedule_RecurrenceRestartDiv\" style=\"display: none;\">";
        html += "                        <input type=\"checkbox\" id=\"schedule_RecurrenceRestart\" /><label for=\"RecurrenceRestart\">Restart";
        html += "                            this recurrence cycle each year</label>";
        html += "                    </div>";
        html += "                </fieldset>";
        html += "            </div>";
        html += "        </td>";
        html += "    </tr>";
        if (_renderSaveCancel) {
            html += "    <tr>";
            html += "        <td><input type=\"button\" value=\"Cancel Schedule\" onclick=\"cancelSchedule();\" /></td>";
            html += "        <td align=\"right\">";
            html += "            <input type=\"button\" value=\"Save Schedule\" onclick=\"saveSchedule();\" />";
            html += "        </td>";
            html += "    </tr>";
        }
        html += "</table>";

        $(this.parentContainer).update(html);
        new ODATextBox("schedule_txtStartDate", ValidationTypes.DateTime, DateValidationModes.DateAndOptionalTime, true);
    }
};
