strConfBin = "ConferencingBin";

L_DateFormat_Text = 1; //1 = mm/dd/yyyy, 2 = dd/mm/yyyy, 3 = yyyy/dd/mm, 4 = yyyy/mm/dd
L_TimeFormat_Text = 2; //1 = 24:60, 2 = 12:60 AM/PM, 3 = AM/PM 12:60
L_DateFirst_Text  = 1; //1 = Date Time, 2 = Time Date
    
L_TimeLabelAM_Text   = "AM";
L_TimeLabelPM_Text   = "PM";
L_DateSeparator_Text = "/"; //US time is MM/DD/YYYY, but GER is DD.MM.YYYY
L_TimeSeparator_Text = ":"; //US time is HH:MM:SS, but Faeroese is HH.MM.SS

var INVALID_TIMEZONE_VALUE = 9999;

function TimeZoneDelta(objStartTime, objEndTime)
{
    var DHTMLSupport = (navigator.appName == "Microsoft Internet Explorer");
    var nTZD = INVALID_TIMEZONE_VALUE;
    
    if (DHTMLSupport)
    {       
        var nTZDStart, nTZDEnd;
        
        nTZDStart = objStartTime.getTimezoneOffset();
        nTZDEnd = objEndTime.getTimezoneOffset();
        
        if(nTZDStart == nTZDEnd)
        {
            nTZD = nTZDStart;
        }
    }
           
    return nTZD;
}

function WriteTableTop(strText, cols)
{
    var DHTMLSupport = (navigator.appName == "Microsoft Internet Explorer");
    if (DHTMLSupport)
        document.writeln('<TABLE ID=tableMain BORDER=0 CELLPADDING=0 CELLSPACING=0 STYLE="width:100%">');
    else
        document.writeln('<TABLE ID=tableMain BORDER=0 CELLPADDING=0 CELLSPACING=0>');

    document.writeln("<TR>");
    document.writeln('    <TD><IMG SRC="/' + strConfBin + '/spacer.gif" HEIGHT=18></TD>');
    document.writeln("</TR>");
    document.writeln("<TR>");
    document.writeln("    <TD>");

    if (DHTMLSupport)
        document.writeln('        <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 BGCOLOR=#0099FF STYLE="width:100%">');
    else
        document.writeln('        <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 BGCOLOR=#0099FF WIDTH=552>');

    document.writeln("        <TR>");
    document.writeln("            <TD VALIGN=top ALIGN=left WIDTH=13>");
    document.writeln('                <IMG SRC="/' + strConfBin + '/sched_topleft.gif" WIDTH=13 HEIGHT=13></TD>');
    document.writeln("            <TD COLSPAN=2>");
    document.writeln('                <IMG SRC="/' + strConfBin + '/spacer.gif"></TD>');
    document.writeln("            <TD VALIGN=top ALIGN=right WIDTH=13>");
    document.writeln('                <IMG SRC="/' + strConfBin + '/sched_topright.gif" WIDTH=13 HEIGHT=13></TD>');
    document.writeln("        </TR>");
    document.writeln("        <TR>");
    document.writeln("            <TD>&nbsp;</TD>");
    document.writeln("            <TD>");
    document.writeln('                <FONT SIZE=3 CLASS="header">' + strText + "</FONT>");
    document.writeln("            </TD>");
    document.writeln('            <TD ALIGN=right><FONT SIZE=1 CLASS="hdtext">');
    document.writeln('                <SCRIPT LANGUAGE="JavaScript">WriteDate();</SCRIPT>');
    document.writeln("                </FONT></TD>");
    document.writeln("            <TD>&nbsp;</TD>");
    document.writeln("        </TR>");
    document.writeln("        <TR>");
    document.writeln('            <TD COLSPAN=4><IMG SRC="/' + strConfBin + '/spacer.gif" HEIGHT=7></TD>');
    document.writeln("        </TR>");
    document.writeln("        </TABLE>");
    document.writeln("    </TD>");
    document.writeln("</TR>");
    document.writeln("<TR>");
    document.writeln("    <TD>");

    if (DHTMLSupport)
        document.writeln('        <TABLE ID=tableInfo BGCOLOR=white BORDER=0 CELLPADDING=0 CELLSPACING=0 VALIGN=top STYLE="width:100%">');
    else
        document.writeln('        <TABLE ID=tableInfo BGCOLOR=white BORDER=0 CELLPADDING=0 CELLSPACING=0 VALIGN=top WIDTH=552>');

    document.writeln("        <TR>");
    document.writeln('            <TD ROWSPAN=300 WIDTH=1 BGCOLOR=#0099FF><IMG SRC="/' + strConfBin + '/spacer.gif" WIDTH=1 HEIGHT=11></TD>');
    document.writeln('            <TD ROWSPAN=300 WIDTH=15><IMG SRC="/' + strConfBin + '/spacer.gif" WIDTH=15 HEIGHT=1></TD>');
    document.writeln('            <TD COLSPAN=' + cols +'><IMG SRC="/' + strConfBin + '/spacer.gif" WIDTH=1 HEIGHT=11></TD>');
    document.writeln('            <TD ROWSPAN=300 WIDTH=15><IMG SRC="/' + strConfBin + '/spacer.gif" WIDTH=15 HEIGHT=1></TD>');
    document.writeln('            <TD ROWSPAN=300 WIDTH=1 BGCOLOR=#0099FF><IMG SRC="/' + strConfBin + '/spacer.gif" WIDTH=1 HEIGHT=11></TD>');
    document.writeln("        </TR>");
}

function WriteTableBottom()
{
    var DHTMLSupport = (navigator.appName == "Microsoft Internet Explorer");
    document.writeln("        </TABLE>");
    document.writeln("    </TD>");
    document.writeln("</TR>");
    document.writeln("    <TD>");

    if (DHTMLSupport)
        document.writeln('        <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 BGCOLOR=#FFFFFF STYLE="width:100%">');
    else
        document.writeln('        <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 BGCOLOR=#FFFFFF WIDTH=552>');

    document.writeln("        <TR>");
    document.writeln("            <TD VALIGN=top ALIGN=left WIDTH=13>");
    document.writeln('                <IMG SRC="/' + strConfBin + '/sched_botleft.gif" WIDTH=13 HEIGHT=13></TD>');
    document.writeln("            <TD>");

    if (DHTMLSupport)
        document.writeln('                <IMG SRC="/' + strConfBin + '/sched_botmid.gif" HEIGHT=13 STYLE="width:100%"></TD>');
    else
        document.writeln('                <IMG SRC="/' + strConfBin + '/sched_botmid.gif" HEIGHT=13 WIDTH=526></TD>');

    document.writeln("            <TD VALIGN=top ALIGN=right WIDTH=13>");
    document.writeln('                <IMG SRC="/' + strConfBin + '/sched_botright.gif" WIDTH=13 HEIGHT=13></TD>');
    document.writeln("        </TR>");
    document.writeln("        </TABLE>");
    document.writeln("    </TD>");
    document.writeln("</TR>");
    document.writeln("<TR>");
    document.writeln('    <TD><IMG SRC="/' + strConfBin + '/spacer.gif" HEIGHT=18></TD>');
    document.writeln("</TR>");
    document.writeln("</TABLE>");
}

function WriteDate()
{
    var d = new Date();
    document.write(FormatDateTime(d));
    delete d;
}

function FormatDate(years, months, days)
{
    var format        = L_DateFormat_Text;
    var dateSeparator = L_DateSeparator_Text;
                
    switch(format)
    {
        case 1: // MM/DD/YYYY
            return (months + dateSeparator + days + dateSeparator + years);
        case 2: // DD/MM/YYYY
            return (days + dateSeparator + months + dateSeparator + years);
        case 3: // YYYY/DD/MM
            return (years + dateSeparator + days + dateSeparator + months);
        case 4: // YYYY/MM/DD
            return (years + dateSeparator + months + dateSeparator + days);
        default:
            alert("Formatting date with unknown format: " + format);
    }
}

// Hours coming in must be based on a 24-hour clock (no longer prints seconds)
function FormatTime(hours, minutes, seconds)
{
    var timeLabel;
    var format = L_TimeFormat_Text;
    var timeSeparator = L_TimeSeparator_Text;

    if (10 > minutes)
        minutes = "0" + minutes;

    switch(format)
    {
        case 1: // 24-hour clock
            return (hours + timeSeparator + minutes);
        case 2: // 12-hour clock with AM/PM after
        case 3: // 12-hour clock with AM/PM before
            if (12 < hours)
            {
                hours     = hours - 12;
                timeLabel = L_TimeLabelPM_Text;
            }
            else if (12 == hours)
                timeLabel = L_TimeLabelPM_Text;
            else
            {
                if (0 == hours)
                    hours = 12; // midnight hour
                            
                timeLabel = L_TimeLabelAM_Text;
            }

            if (2 == format)
                return (hours + timeSeparator + minutes + " " + timeLabel);
            else
                return (timeLabel + " " + hours + timeSeparator + minutes);

        default:
            alert("Formatting time with unknown format: " + format);
    }
}

// Date coming in must be local time
function FormatDateTime(dateVal)
{
    var format = L_DateFirst_Text;
    var years, months, days, hours, minutes, seconds;
    var time, date;

    years   = dateVal.getFullYear();
    months  = dateVal.getMonth()+1;
    days    = dateVal.getDate();
    hours   = dateVal.getHours();
    minutes = dateVal.getMinutes();
    seconds = dateVal.getSeconds();
                
    time = FormatTime(hours, minutes, seconds);
    date = FormatDate(years, months, days);
                
    switch(format)
    {
        case 1: // Date before time
            return (date + " " + time);
        case 2: // Time before date
            return (time + " " + date);
        default:
            alert("Formatting date/time with unknown format: " + format);
    }
}

function DateFromVBSString(vbsString)
{
    var timeArray, date;
    
    timeArray = vbsString.split(":");
    
    if (timeArray.length < 3)
        return null;
    if (3 == timeArray.length)
        date = new Date(Date.UTC(timeArray[0], timeArray[1]-1, timeArray[2]));
    else if (4 == timeArray.length)
        date = new Date(Date.UTC(timeArray[0], timeArray[1]-1, timeArray[2], timeArray[3]));
    else if (5 == timeArray.length)
        date = new Date(Date.UTC(timeArray[0], timeArray[1]-1, timeArray[2], timeArray[3], timeArray[4]));
    else if (6 == timeArray.length)
        date = new Date(Date.UTC(timeArray[0], timeArray[1]-1, timeArray[2], timeArray[3], timeArray[4], timeArray[5]));
    return date;
}

function ValidateDate(DateType, strGlyphDate)
{
    var vItem;

    if (strGlyphDate != "")
        strGlyphDate = " " + strGlyphDate;

    if (eval("!document.forms[0].list" + DateType + "Date"))
        return false;

    if (eval("!document.forms[0].list" + DateType + "Year"))
    {
        var d = new Date();
        //  Create a date that represents the month after the selected month
        eval("ReqDate = new Date(d.getFullYear(), parseInt(document.forms[0].list" + DateType + "Month.selectedIndex, 10) + 1, 1);");
        delete d;
    }
    else
    {
        //  Create a date that represents the month after the selected month
        eval("ReqDate = new Date(parseInt(document.forms[0].list" + DateType + "Year.selectedIndex, 10) + parseInt(document.forms[0].list" + DateType + "Year[0].value, 10), document.forms[0].list" + DateType + "Month.selectedIndex + 1, 1);");
    }
    //  Go back one day (so we know how many days are in the selected month)
    ReqDate.setDate(0);
    //  Get the number of days in the selected  month
    MaxDate = ReqDate.getDate();
    delete ReqDate;
    //  Get the number of entries in the "Dates" drop down
    eval("ListLen = document.forms[0].list" + DateType + "Date.length;");

    //  Make appropriate additions or subtractions to the number of selectable days
    if (MaxDate > ListLen)
    {
        //  Add the necessary number of days
        for (i=ListLen; i < MaxDate; i++)
            eval("document.forms[0].list" + DateType + "Date[i] = new Option((i+1) + strGlyphDate);");
    }
    else if (MaxDate < ListLen)
    {
        //  Reselect (if necessary)...
        if (eval("document.forms[0].list" + DateType + "Date.selectedIndex >= MaxDate"))
            eval("document.forms[0].list" + DateType + "Date.selectedIndex = MaxDate-1;");

        //  ...and delete the necessary number of days
        for (i=0; i < ListLen-MaxDate; i++)
            eval("document.forms[0].list" + DateType + "Date[MaxDate] = null;");
    }
}

