//  03-10-2003
//  12-22-2004
function CreateCalendar(month, year, hour, minute, am_pm)
{
    var today, startMonth, curDate, calendar, i;
    var dayptr = 0;
    var selected = new Array(2);
    
    today = new Date;
    
    //  Current stats
    if (month == null) month = today.getMonth();
    if (year == null) year = today.getYear();
    //  Netscape fix on creation of first calendar
    if (year < 1000) year += 1900;
    
    curDate = 1;
    calendar = '<html><head>\n';
    calendar += STYLE_SHEET + '\n\n\n';

    //  Gets full info regarding first of the month
    startMonth = new Date(year, month, 1);
    
    //  getDay() returns day of the week that the date object has as its
    //  day param. ie (startMonth's day is 1 so startMonth.getDay() returns
    //  the day of the week that the 1 lands on in that month.
    //  This method is what's used in the loop to print out the dates.
    //  (0=Sunday to 6=Saturday) 
    
    var onLoadEvent = DATE_TIME_FIELD ? "self.opener.ChangeTime(\'am_pm\')" : "";
    
    //  Heading
    if (PAGE_TITLE)
    {
      calendar += '<title>' + PAGE_TITLE + '</title>\n';
    }
    else
    {
      calendar += '<title>' + FIELD_NAME.unfix() + '</title>\n';
    }
    
    if (datePickerCharset == 'utf-8')
        calendar += '<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=utf-8\">\n';

    calendar += "<style type='text/css'>\n" +
                "a { text-decoration: none; }\n" + 
                "td.calDate a:hover { font-weight:bold; }\n" +
                "</style>\n";
 
    calendar += '</head>\n';
    calendar += '<body bgcolor = ' + BACKGROUND_COLOR + ' onLoad = "' + onLoadEvent + '">\n\n';



    //  Starts table
    if (DATE_TIME_FIELD) calendar += TABLE_TOP + '\n\n<form name = "cal"><table border = "0"><tr><td valign= "top">\n';
    calendar += '<center><table border = "1" cellpadding = "3" cellspacing = "0" bgcolor = ' + TABLE_COLOR + '>\n';
    calendar += '<tr><th colspan = "7">\n';

    //  BEGIN Calendar Header - BEGIN TABLE
    calendar += '<table border = "0" cellpadding = "0" cellspacing = "0" width = "100%"><tr>\n';
    //  Left arrows
    calendar += '<th width = "12%" align = "left"><a href = \'javascript:self.opener.ChangeDate("<<", ' + month + ', ' + year + ')\'><<</a></th>\n';
    calendar += '<th width = "12%">&nbsp;&nbsp;&nbsp;<a href = \'javascript:self.opener.ChangeDate("<", ' + month + ', ' + year + ')\'><</a></th>\n';
    // Month Name       
    calendar += '<th width = "52%" align = "center">' + monthNames[month] + ' ' + year + '</th>\n';
    //  Right arrows
    calendar += '<th width = "12%"><a href = \'javascript:self.opener.ChangeDate(">", ' + month + ', ' + year + ')\'>></a></th>\n';
    calendar += '<th width = "12%" align = "right">&nbsp;&nbsp;&nbsp;<a href = \'javascript:self.opener.ChangeDate(">>", ' + month + ', ' + year + ')\'>>></a></th>\n';
    calendar += '</tr></table>\n';
    //  End Calendar Header - END TABLE
    
    calendar += '</th></tr><tr>\n';
    //  Days of the week
    for (i = 0; i < dayNames.length; i++)
    {
        calendar += '<td align="center" width="25">' + dayNames[i] + '</td>\n';
    }
    calendar += '</tr><tr>\n';

    //  Pads for the beginning - Since the week can start on a monday
    //  a special check needs to be made where the new first of the month is
    if (START_WEEK == 'mon')
        startDayValue = startMonth.getDay() == 0 ? 6 : startMonth.getDay() - 1;
    else
        startDayValue = startMonth.getDay(); 

    for (i = 1; i <= startDayValue; i++)
    {
        calendar += '<td>&nbsp;</td>\n';
        dayptr++;
    }
    var todayYear = (today.getYear()>1000)?today.getYear():today.getYear()+1900;
    //  Print date
    while (startMonth.getMonth() == month)
    {
        var fontColor = ((today.getDate() == curDate) && (today.getMonth() == month) && (todayYear == year)) ? HIGHLIGHTED_COLOR : REGULAR_COLOR;
        calendar += '<td class="calDate" align = "center" style="cursor: pointer;" onclick="self.opener.SelectDate(' + month + ', ' + curDate + ', ' + year + ')"><a href=javascript:void(0); ><font color = "' + fontColor + '">' + curDate + '</font></a></td>\n';
        if (dayptr == 6)
        {
            calendar += '</tr><tr>\n';
            dayptr = -1;
        }
        startMonth.setDate(++curDate);
        dayptr++;
    }
    
    //  Pads for the end (only if needed) - Since the week can start on a monday
    //  a special check needs to be made where the new first of the month is    
    if (START_WEEK == 'mon')
        startMonthValue = startMonth.getDay() == 0 ? 6 : startMonth.getDay() - 1;
    else
        startMonthValue = startMonth.getDay();

    if (startMonthValue > 0)
    {
        for (i = startMonthValue; i <= 6; i++)
        {
            calendar += '<td>&nbsp;</td>\n';
        }
    }
    calendar += '</tr></table>\n';

    if (DATE_TIME_FIELD == 1)
    {
        var dispStyleNone;
        if (HIDE_END_TIME == 1)
            dispStyleNone = 'style = "display:none"';

        //calendar += '</td><td valign = \"top\" bgcolor = \"$tablecolor\">
        calendar += '<br>' + DATE_WORDS + ': <input name = "date" type = "text" size = "14" onFocus = "document.cal.minute.focus()" onClick = "document.cal.minute.focus()" value = "' + DATE + '">\n';
        //  Time Section starts here
        calendar += '</td><td valign = "top"><table border = "0">\n';
        //  Start Time
        calendar += '<tr><td align = "right" valign = "top"><b>' + START_TIME_WORDS + ':</b><td valign = "top">\n';
        calendar += '<input name = "time" type = "text" size = "9" onFocus = "document.cal.minute.focus()" onClick = "document.cal.minute.focus()" valign = "top">';
        calendar += '<input ' + dispStyleNone + ' name = "sOrE" value = "START" type = "radio" onClick = "self.opener.ToggleStartEndTime();" CHECKED></td>\n';

        //  Hour selection
        calendar += '<td rowspan = "4" valign = "top"><select name = "hour" size = "12" width = "3" onChange = "self.opener.ChangeTime(\'hour\')">\n';
        if (TIME_24 == 1)
        {
            startHour = 0;
            endHour = 23;
        }
        else
        {
            startHour = 1;
            endHour = 12;        
        }
        for (i = startHour; i <= endHour; i++)
        {
            selected[0] = i == HOUR ? "selected" : "";
            calendar += '<option value = "' + i + '" ' + selected[0] + '>' + i + '\n';
        }
        calendar += '</select>\n';

        //  Minute selection
        calendar += '<select name = "minute" size = "12" width = "3" onChange = "self.opener.ChangeTime(\'minute\')">\n';
        for (i = 0; i <= 55; i = i + 5)
        {
            selected[0] = ((i == MINUTE) && (HOUR > 0)) ? "selected" : "";
            calendar += '<option value = "' + AddZero(i) + '" ' + selected[0] + '>' + AddZero(i) + '\n';
        }
        calendar += '</select> &nbsp;</td>\n';
        calendar += '';
        
        //  AM/PM selection
        if (SUFFIX == "AM")
            selected[0] = "selected";
        else if (SUFFIX == "PM")
            selected[1] = "selected";
        dispStyle = TIME_24 == 1 ? "none" : "";
        calendar += '<td rowspan = "4" valign = "top" style = "display:' + dispStyle + '"><select name = "am_pm" size = "2" onChange = "self.opener.ChangeTime(\'am_pm\')">\n';
        calendar += '<option value = "AM" ' + selected[0] + '>AM\n';
        calendar += '<option value = "PM" ' + selected[1] + '>PM\n';
        calendar += '</select>\n';
		// AA-12066
		/*if( TIMEZONE_MSG )
		{
			calendar += '<br>\n';
			calendar += '<b>' + TIMEZONE_MSG + '</b>\n';
		}*/
        //  End time 
        calendar += '<tr ' + dispStyleNone + '><td align = "right"><b>' + END_TIME_WORDS + ':</b></td><td valign = "top"><input name = "END_TIME" type = "text" size = "9" onFocus = "document.cal.minute.focus()" onClick = "document.cal.minute.focus()" valign = "top">';
        calendar += '<input name = "sOrE" value = "END" type = "radio" onClick = "self.opener.SetEndTime();"></td></tr>\n';
    
        //  No Time check box
        if (!TIME_IS_MAND)
        {
            calendar += '<tr><td align = "right"><b>' + NO_TIME_WORDS + ':</b></td><td><input name = "noTime" type = "checkbox" onClick = "self.opener.ToggleTime()" CHECKED> </tr>\n';
        }

        if (!(HIDE_LINK_OPTIONS))
        {
            var checkedLink = new Array();
            if (SEND_TO_CAL_VALUE == 0) checkedLink[0] = "CHECKED";
            if (SEND_TO_CAL_VALUE == 1) checkedLink[1] = "CHECKED";
            if (SEND_TO_CAL_VALUE == 2) checkedLink[2] = "CHECKED";
            //  Send to Calendar
            calendar += '<tr><td align = "right" valign = "top"><b>' + CALENDAR_WORDS + ':</b></td><td valign = "top">\n';
    
            calendar += '<input name = "SendToCalendar" type = "radio" value = "0" ' + checkedLink[0] + ' onClick = "self.opener.ChangeCalendarOption(0)">' + DONT_SEND_WORDS + '<br>\n';
            calendar += '<input name = "SendToCalendar" type = "radio" value = "1" ' + checkedLink[1] + ' onClick = "self.opener.ChangeCalendarOption(1)">' + PERSONAL_WORDS + '<br>\n';
            if (CREATE_APTS_IN_PROJ == 1) calendar += '<input name = "SendToCalendar" type = "radio" value = "2" ' + checkedLink[2] + ' onClick = "self.opener.ChangeCalendarOption(2)">' + PERSONAL_AND_PROJECT_WORDS;
            calendar += '</td></tr>\n';
        }
        //calendar += '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n';
        calendar += '<td colspan = "2" align = "center">' + CLEAR_BUTTON + '</td>\n';
        calendar += '</td></tr></table><BR><a href = "javascript:void(0)"></table>\n';
        calendar += '<br>' + GO_BUTTON;
        if (TIME_ZONE && DATE_TIME_FIELD == 1)
            calendar += '<BR><BR>' + TIME_ZONE;        
        calendar += TABLE_BOTTOM + '</form>' ;
    }

    calendar += '</center>';
    calendar += '</body></html>\n';
    var width = DATE_TIME_FIELD == 1 ? 675 : 300;
    var height = DATE_TIME_FIELD == 1 ? 375 : 200;
    popup = window.open('', 'popup', 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,screenX=150,screenY=150,top=150,left=150,status=no');                    
    popup.document.clear();
    popup.document.writeln(calendar);
    if (TIME_IS_MAND)
    {
	    if (popup.document.cal.hour.selectedIndex == -1)
            popup.document.cal.hour.selectedIndex = 0;
        ChangeTime('hour');
    }
    popup.document.close();
}

//  03-10-2003
//  03-11-2003
function ChangeDate (symbol, mon, year)
{
    if (symbol == "<")
    {
        if (mon == 0)
        {
            mon = 11;
            year--;
        }
        else
        {
            mon--;
        }
    }
    if (symbol == "<<")
        year--;
 
    if (symbol == ">")
    {
        if (mon == 11)
        {
            mon = 0;
            year++;
        }
        else
            mon++;
    }
    if (symbol == ">>")
        year++;
    CreateCalendar(mon, year)
}

//  03-11-2003
//  12-11-2003
function SelectDate (mon, day, year)
{
    mon++;
    if (DATE_TIME_FIELD) 
    {
        if (DATE_STYLE == 0) // American
            finalDate = mon + '/' + day + '/' + year;
        else if (DATE_STYLE == 1) // European
            finalDate = day + '/' + mon + '/' + year;
        else // ISO
            finalDate = year + '-' + mon + '-' + day;
        popup.document.cal.date.value = finalDate;
        DATE = finalDate;
    }
    else
    {
        eval('document.' + FORM_NAME + '.MonthInput_' + FIELD_NAME + '.value = mon;'); 
        eval('document.' + FORM_NAME + '.DayInput_' + FIELD_NAME + '.value = day;'); 
        eval('document.' + FORM_NAME + '.YearInput_' + FIELD_NAME + '.value = year;'); 
        if (REFRESH_AVAILABILITY_SCREEN)
            RefreshPage();
        popup.close();
    }
}

function AddZero (num)
{
    return (num < 10) ? '0' + num : num ;
}
             
//  Last Edited: 01-20-2006 by Sharone                   
function ChangeTime(whichUnit)
{
    //  Minute can't be selected first
    if (popup.document.cal.minute.selectedIndex == -1)
        popup.document.cal.minute.selectedIndex = 0;
    
    //  If minute selected and hour is not selected, set others to blank
    if (popup.document.cal.hour.selectedIndex == -1 && whichUnit == 'minute')
        popup.document.cal.minute.selectedIndex = -1;
    
    //  If am/pm selected and hour is not selected, set others to blank
    if (popup.document.cal.hour.selectedIndex == -1 && whichUnit == 'am_pm')
    {
        popup.document.cal.minute.selectedIndex = -1;
        popup.document.cal.am_pm.selectedIndex = -1;
    }              
    
    //  Both hour and minute have been selected
    if (popup.document.cal.hour.selectedIndex >= 0 && popup.document.cal.minute.selectedIndex >= 0)
    {
        //  Set am/pm to am if not selected yet
        if (popup.document.cal.am_pm.selectedIndex == -1)
            popup.document.cal.am_pm.selectedIndex = 0;
        
        //  Display the time in the time box
        //  Start Time
        if (popup.document.cal.sOrE[0].checked)
        {
            HOUR = popup.document.cal.hour.selectedIndex;
            if (TIME_24 == 0) HOUR++;
            MINUTE = popup.document.cal.minute.options[popup.document.cal.minute.selectedIndex].value;
            SUFFIX = popup.document.cal.am_pm.options[popup.document.cal.am_pm.selectedIndex].value
        }
        //  End Time
        else
        {
            E_HOUR = popup.document.cal.hour.selectedIndex;
            if (TIME_24 == 0) E_HOUR++;
            E_MINUTE = popup.document.cal.minute.options[popup.document.cal.minute.selectedIndex].value;
            E_SUFFIX = popup.document.cal.am_pm.options[popup.document.cal.am_pm.selectedIndex].value
        }
        if ((TIME_24 == 0 && HOUR && MINUTE && SUFFIX) || (TIME_24 == 1 && MINUTE))
            popup.document.cal.time.value = TIME_24 == 1 ? HOUR + ':' + MINUTE : HOUR + ':' + MINUTE + ' ' + SUFFIX;
        if ((TIME_24 == 0 && E_HOUR && E_MINUTE && E_SUFFIX) || (TIME_24 == 1 && E_MINUTE))
            popup.document.cal.END_TIME.value = TIME_24 == 1 ? E_HOUR + ':' + E_MINUTE : E_HOUR + ':' + E_MINUTE + ' ' + E_SUFFIX;
    }
  
    //  If no time was checked but an hour was selected, uncheck the no time box
    if (!TIME_IS_MAND)
        if (popup.document.cal.noTime.checked == true && popup.document.cal.hour.selectedIndex >= 0)
            popup.document.cal.noTime.checked = false;
}

//  Last Edited: 01-20-2006 by Sharone
function ToggleTime()
{
    if (!TIME_IS_MAND && popup.document.cal.noTime.checked == true)
    {
        popup.document.cal.hour.selectedIndex = -1;
        popup.document.cal.minute.selectedIndex = -1;
        popup.document.cal.am_pm.selectedIndex = -1;
        popup.document.cal.time.value = '';
        popup.document.cal.END_TIME.value = '';
        popup.document.cal.sOrE[0].checked = true;
        HOUR = '';
        MINUTE = '';
        SUFFIX = '';
        E_HOUR = '';
        E_MINUTE = '';
        E_SUFFIX = '';
    }
    else
    {
        popup.document.cal.hour.selectedIndex = 0;
        ChangeTime('hour');
    }
}

//  Last Edited: 05-13-2003
function ChangeCalendarOption(calOption)
{
    eval('document.' + FORM_NAME + '.SendToCalendar_' + FIELD_NAME + '.value = ' + calOption + ';');
    SEND_TO_CAL_VALUE = calOption;
}


//  Last Edited: 01-23-2006
function CloseWindow(changeDate)
{
    eval('var inputFromOtherWindow = document.' + FORM_NAME + '.' + FIELD_NAME + '_datetime;');
    eval('var endTimeMainWindow = document.' + FORM_NAME + '.END_TIME_' + FIELD_NAME);
    if (popup.document.cal.date.value == '' && popup.document.cal.time.value != '')
    {
        popup.alert(NEED_DATE_WORDS);
    }
    else
    {
        if (E_HOUR && E_MINUTE && E_SUFFIX)
            if (!IsEndTimeAfterStart())
                return;
        inputFromOtherWindow.value = popup.document.cal.date.value;
        if (popup.document.cal.time.value != '')
            inputFromOtherWindow.value = inputFromOtherWindow.value + ' ' + popup.document.cal.time.value;
        
        //  Sets the end time in the hidden from the main screen
        if (E_SUFFIX == 'PM' && E_HOUR != 12)
            E_HOUR += 12;
        if (E_SUFFIX == 'AM' && E_HOUR == 12)
        E_HOUR = 0;
        endTimeMainWindow.value = E_HOUR + ':' + E_MINUTE;
        
        FORM_NAME = null;
        FIELD_NAME = null;
        DATE_TIME_FIELD = null;
        HIDE_LINK_OPTIONS = null;
        DATE = null;
        HOUR = null;
        MINUTE = null;
        SUFFIX = null;
        E_HOUR = null;
        E_MINUTE = null;
        E_SUFFIX = null;
        SEND_TO_CAL_VALUE = null;
        popup.close();
    }
}

//  Instead of passing these values around to every function, they 
//  are made global for the duration of date processing
//  Created: 04-14-2003 Sharone
//  Last Edited: 12-11-2003
function InitializeVariables(formName, fieldName, dateTimeField, hideLinkOptions, timeIsMand, pageTitle, refreshAvailabilityScreen, timezoneMsg, hideEndTime)
{
    var month, year;
    
    FORM_NAME = formName;
    FIELD_NAME = fieldName;
    DATE_TIME_FIELD = dateTimeField;
    HIDE_LINK_OPTIONS = hideLinkOptions;
    TIME_IS_MAND = timeIsMand;
    PAGE_TITLE = pageTitle;
    REFRESH_AVAILABILITY_SCREEN = refreshAvailabilityScreen;
    HIDE_END_TIME = hideEndTime;


	// AA-12066
	TIMEZONE_MSG = timezoneMsg;

    if (DATE_TIME_FIELD)
    {
        var dateObject = ParseDateTime();
        if (dateObject.month > 0) month = --dateObject.month
        if (dateObject.year > 0) year = dateObject.year;
    }
    CreateCalendar(month, year);
}

//  01-23-2006
function ParseDateTime()
{
    var data, month, year, day, asSec;

    DATE = "";
    eval('data = document.' + FORM_NAME + '.' + FIELD_NAME + '_datetime.value;');
    if (data)
    {
        dateTimeParts = data.split(' ');
        DATE = dateTimeParts[0];
        //  Gets the month and year values
        if (DATE_STYLE == 0)
        {
            dateParts = DATE.split('/');
            month = dateParts[0];
            day = dateParts[1];
            year = dateParts[2];
        }
        else if (DATE_STYLE == 1)
        {   
            dateParts = DATE.split('/');
            day = dateParts[0];
            month = dateParts[1];
            year = dateParts[2];
        }
        else
        {
            dateParts = DATE.split('-');
            month = dateParts[1];
            year = dateParts[0];
            day = dateParts[2];
        }

       //  Sets the time values
        if (dateTimeParts.length > 1)
        {
            var timeParts = dateTimeParts[1].split(':');
            HOUR = timeParts[0]; 
            MINUTE = timeParts[1];
            SUFFIX = dateTimeParts[2];
        }

        // get seconds 
        if (year > 0 && month > 0 && day > 0 && HOUR != null && MINUTE != null)
        {
           var month0 = month - 1;

           // convert to military time.
           // absence of suffix means we already are in mil time           
           var hourMil = HOUR;
           if (SUFFIX == "PM" && HOUR != 12)
           {
                hourMil = Number(HOUR) + 12;
           }                       
           else if (SUFFIX == "AM" && HOUR == 12)
           {
               hourMil = 0;
           }

           var secDate = new Date(year, month0, day, hourMil, MINUTE, 0, 0);
           asSec = Math.floor(secDate.getTime() / 1000);   
        }

        if (!HIDE_LINK_OPTIONS)
            eval('SEND_TO_CAL_VALUE = document.' + FORM_NAME + '.SendToCalendar_' + FIELD_NAME + '.value');

        //  Get end time
        eval('var endTime = document.' + FORM_NAME + '.END_TIME_' + FIELD_NAME + '.value');
        if (endTime)
        {
            var endTimeParts = endTime.split(':');
            E_MINUTE = endTimeParts[1];
            if (endTimeParts[0] >= 0 && endTimeParts[0] < 1)
            {
                E_HOUR = 12;
                E_SUFFIX = "AM";
            }
            else if (endTimeParts[0] < 12)
            {
                E_HOUR = endTimeParts[0];
                E_SUFFIX = "AM";
            }
            else // if (endTimeParts[0] >= 12)
            {
                E_SUFFIX = "PM";
                if (endTimeParts[0] >= 13)
                    E_HOUR = endTimeParts[0] - 12;
                else
                    E_HOUR = endTimeParts[0];
            }
        }
    }
    //Julia; jan-19-2006; turn the calendar link on even if the date is not there yet.
    // moved here  out of prev if
    if (!HIDE_LINK_OPTIONS)
      {
        eval('SEND_TO_CAL_VALUE = document.' + FORM_NAME + '.SendToCalendar_' + FIELD_NAME + '.value');
      }
    if (!SEND_TO_CAL_VALUE) SEND_TO_CAL_VALUE = 0;

    if (asSec == null)
        asSec = 0;
    return {month:month, year:year, asSeconds: asSec};
}

//  Erases the date and time that's in the window
//  06-04-2004
function ClearData()
{
    popup.document.cal.date.value = "";
    if (!TIME_IS_MAND)
    {
	    popup.document.cal.noTime.checked = true;
    }
    ToggleTime();
}


function DateToSeconds(formName, fieldName)
{
    FORM_NAME = formName;
    FIELD_NAME = fieldName;

    // make sure these globals are zeroed out before we parse
    HOUR = null;
    MINUTE = null;
    HIDE_LINK_OPTIONS = true;

    var parseReturn = ParseDateTime();

    // clean up . The rest of the globals we used get reset
    // the next time someone calls InitializeVariables
    DATE = null;
    SUFFIX = null;

    return parseReturn.asSeconds;
}

//  Created: 01-20-2006
function SetEndTime()
{
    if (!HOUR && !MINUTE && !SUFFIX)
    {
        popup.document.cal.sOrE[0].checked = true;
        popup.alert(SELECT_START_FIRST_WORDS);
    }
    else
        ToggleStartEndTime();
}

//  Created: 01-20-2006
//  Last Edited: 05-02-2006
function IsEndTimeAfterStart()
{
    var returnVal;
    var hour = HOUR;
    var eHour = E_HOUR;

    if (SUFFIX == E_SUFFIX)
    {
        //  Adjust the hours for correct tests
        if (SUFFIX == "PM")
        {
            if (hour != 12) hour += 12;
            if (eHour != 12) eHour += 12;
        }
        else
        {
            if (hour == 12) hour -= 12;
            if (eHour == 12) eHour -= 12;
        }

        if (hour > eHour)
            returnVal = 0;
        if (hour == eHour)
            if (MINUTE >= E_MINUTE)
                returnVal = 0;
    }
    else
        if (SUFFIX == "PM")
            returnVal = 0;
    
    if (returnVal == 0)
        popup.alert(TIMES_NOT_GOOD);
    else
        returnVal = 1;

    return returnVal;
}

//  Created: 01-23-2006
function ToggleStartEndTime()
{
    var which = popup.document.cal.sOrE[0].checked ? "S" : "E";

    if (which == "S")
    {
        if (HOUR && MINUTE && SUFFIX)
        {
            popup.document.cal.hour.options[HOUR - 1].selected = true;
            popup.document.cal.minute.options[MINUTE / 5].selected = true;
            selectedSuffix = SUFFIX == "AM" ? 0 : 1;
            popup.document.cal.am_pm.options[selectedSuffix].selected = true;
        }
    }
    else
    {
        if (E_HOUR && E_MINUTE && E_SUFFIX)
        {
            popup.document.cal.hour.options[E_HOUR - 1].selected = true;
            popup.document.cal.minute.options[E_MINUTE / 5].selected = true;
            selectedSuffix = E_SUFFIX == "AM" ? 0 : 1;
            popup.document.cal.am_pm.options[selectedSuffix].selected = true;
        }
        else
        {   
            popup.document.cal.hour.options.selectedIndex = -1;
            popup.document.cal.minute.options.selectedIndex = -1;
            popup.document.cal.am_pm.options.selectedIndex = -1;
        }
    }
}
