﻿DateTimeSelector = function() {
    var Level = "";

    var minYear = 10;
    var maxYear = 10;

    var monthWidth = "40px";
    var dayWidth = "40px";
    var yearWidth = "66px";

    var isDDL = false;

    var addBlanks = false;

    DateTimeSelector.prototype.SetLevel = function(value) {
        Level = value;
    }

    DateTimeSelector.prototype.SetMinYear = function(value) {
        if (!isNaN(value)) {
            minYear = Math.abs(value);
        }
    }

    DateTimeSelector.prototype.SetMaxYear = function(value) {
        if (!isNaN(value)) {
            maxYear = Math.abs(value);
        }
    }

    DateTimeSelector.prototype.IsDDL = function(value) {
        isDDL = value;
    }

    DateTimeSelector.prototype.SetWidths = function(month, day, year) {
        monthWidth = parseInt(month) + "px";
        dayWidth = parseInt(day) + "px";
        yearWidth = parseInt(year) + "px";
    }

    DateTimeSelector.prototype.AddBlanks = function(value) {
        addBlanks = value;
    }

    DateTimeSelector.prototype.CreateDateSelector = function(commonId, width) {
        if (isDDL) {
            return CreateDateSelector_DDL(commonId, width);
        }
        else {
            return CreateDateSelector_Text(commonId, width);
        }
    }

    var CreateDateSelector_DDL = function(commonId, width) {
        var NowDate = new Date();

        var NewDDL = new DropDownList();
        NewDDL.SetLevel(Level);

        var MainTable = document.createElement("table");
        MainTable.border = "0";
        MainTable.cellSpacing = "0";
        MainTable.cellPadding = "0";
        MainTable.id = commonId;
        //MainTable.className = "DateSelector_MainTable";

        if (width)
            MainTable.style.width = parseInt(width) + "px";

        var MainTR = document.createElement("tr");

        var MonthTD = document.createElement("td");

        var MonthSelect = NewDDL.CreateDDL(commonId + "_Month", monthWidth);

        if (addBlanks)
            MonthSelect.options.add("--", "-1");

        for (var i = 1; i <= 12; i++) {
            MonthSelect.options.add(i, i);
        }

        if (!addBlanks)
            MonthSelect.selectedValue(NowDate.getMonth() + 1);

        MonthTD.appendChild(MonthSelect);

        var DayTD = document.createElement("td");
        DayTD.style.paddingLeft = "8px";

        var DaySelect = NewDDL.CreateDDL(commonId + "_Day", dayWidth);

        var EndMonthStartValue = 32;

        var TempDate = new Date(NowDate.getFullYear(), NowDate.getMonth(), EndMonthStartValue);

        while (TempDate.getMonth() != NowDate.getMonth()) {
            TempDate = null;
            EndMonthStartValue--;

            TempDate = new Date(NowDate.getFullYear(), NowDate.getMonth(), EndMonthStartValue);
        }

        TempDate = null;

        if (addBlanks)
            DaySelect.options.add("--", "-1");

        for (var i = 1; i <= EndMonthStartValue; i++) {
            DaySelect.options.add(i, i);
        }

        if (!addBlanks)
            DaySelect.selectedValue(NowDate.getDate());

        DayTD.appendChild(DaySelect);

        var YearTD = document.createElement("td");
        YearTD.style.paddingLeft = "8px";

        var YearSelect = NewDDL.CreateDDL(commonId + "_Year", yearWidth);

        if (addBlanks)
            YearSelect.options.add("--", "-1");

        for (var i = NowDate.getFullYear() + maxYear; i >= NowDate.getFullYear() - minYear; i--) {
            YearSelect.options.add(i, i);
        }

        //YearSelect.frontLoadOptions();


        if (!addBlanks)
            YearSelect.selectedValue(NowDate.getFullYear());

        YearTD.appendChild(YearSelect);

        MainTR.appendChild(MonthTD);
        MainTR.appendChild(DayTD);
        MainTR.appendChild(YearTD);

        if (DetermineBrowser() == Browsers.IE) {
            var MainTBody = document.createElement("tbody");

            MainTBody.appendChild(MainTR);

            MainTable.appendChild(MainTBody);
        }
        else {
            MainTable.appendChild(MainTR);
        }

        NewDDL = null;
        NowDate = null;


        isDateSelected = function() {
            if (YearSelect.options[YearSelect.selectedIndex].value != "-1" && MonthSelect.options[MonthSelect.selectedIndex].value != "-1" && DaySelect.options[DaySelect.selectedIndex].value != "-1")
                return true;
            else
                return false;
        }

        MonthSelect.onchange = function() {

            if (isDateSelected()) {

                var EndMonthStartValue = 32;

                var CurrentDate = new Date(parseInt(YearSelect.options[YearSelect.selectedIndex].value), parseInt(MonthSelect.options[MonthSelect.selectedIndex].value) - 1, 1);
                var TempDate = new Date(parseInt(YearSelect.options[YearSelect.selectedIndex].value), parseInt(MonthSelect.options[MonthSelect.selectedIndex].value) - 1, EndMonthStartValue);

                while (TempDate.getMonth() != CurrentDate.getMonth()) {
                    TempDate = null;
                    EndMonthStartValue--;

                    TempDate = new Date(parseInt(YearSelect.options[YearSelect.selectedIndex].value), parseInt(MonthSelect.options[MonthSelect.selectedIndex].value) - 1, EndMonthStartValue);
                }

                var DayPreviousValue = DaySelect.options[DaySelect.selectedIndex].value;

                DaySelect.options.length = 0;

                if (addBlanks)
                    DaySelect.options.add("--", "-1");

                for (var i = 1; i <= EndMonthStartValue; i++) {
                    DaySelect.options.add(i, i);
                }

                if (DayPreviousValue > EndMonthStartValue) DayPreviousValue = EndMonthStartValue;

                DaySelect.selectedValue(DayPreviousValue);

                MainTable.onchange();
            }
        }

        DaySelect.onchange = function() {
            MainTable.onchange();
        }

        YearSelect.onchange = function() {
            if (isDateSelected()) {
                var EndMonthStartValue = 32;

                var CurrentDate = new Date(parseInt(YearSelect.options[YearSelect.selectedIndex].value), parseInt(MonthSelect.options[MonthSelect.selectedIndex].value) - 1, 1);
                var TempDate = new Date(parseInt(YearSelect.options[YearSelect.selectedIndex].value), parseInt(MonthSelect.options[MonthSelect.selectedIndex].value) - 1, EndMonthStartValue);

                while (TempDate.getMonth() != CurrentDate.getMonth()) {
                    TempDate = null;
                    EndMonthStartValue--;

                    TempDate = new Date(parseInt(YearSelect.options[YearSelect.selectedIndex].value), parseInt(MonthSelect.options[MonthSelect.selectedIndex].value) - 1, EndMonthStartValue);
                }

                var DayPreviousValue = DaySelect.options[DaySelect.selectedIndex].value;

                DaySelect.options.length = 0;

                if (addBlanks)
                    DaySelect.options.add("--", "-1");

                for (var i = 1; i <= EndMonthStartValue; i++) {
                    DaySelect.options.add(i, i);
                }

                if (DayPreviousValue > EndMonthStartValue) DayPreviousValue = EndMonthStartValue;

                DaySelect.selectedValue(DayPreviousValue);

                MainTable.onchange();
            }
        }

        MainTable.onchange = function() {
        }

        MainTable.ChangeDate = function(Month, Day, Year) {
            //if (isDateSelected()) {
                if (Month == -1 && Day == -1 && Year == -1) {
                    MonthSelect.selectedValue(Month);
                    YearSelect.selectedValue(Year);
                    DaySelect.selectedValue(Day);
                } else {
                    var CurrentDate = new Date(Year, Month, Day);

                    var EndMonthStartValue = 32;
                    var TempDate = new Date(CurrentDate.getFullYear(), CurrentDate.getMonth(), EndMonthStartValue);

                    while (TempDate.getMonth() != CurrentDate.getMonth()) {
                        TempDate = null;
                        EndMonthStartValue--;

                        TempDate = new Date(CurrentDate.getFullYear(), CurrentDate.getMonth(), EndMonthStartValue);
                    }

                    DaySelect.options.length = 0;

                    for (var i = 1; i <= EndMonthStartValue; i++) {
                        DaySelect.options.add(i, i);
                    }

                    MonthSelect.selectedValue(CurrentDate.getMonth() + 1);
                    YearSelect.selectedValue(CurrentDate.getFullYear());
                    DaySelect.selectedValue(CurrentDate.getDate());

                    TempDate = null;
                    CurrentDate = null;


                }
                MainTable.onchange();
            //}
        }

        MainTable.GetDate = function() {

            if (isDateSelected())
                return new Date(YearSelect.options[YearSelect.selectedIndex].value, parseInt(MonthSelect.options[MonthSelect.selectedIndex].value) - 1, DaySelect.options[DaySelect.selectedIndex].value);
            else
                return null;
        }

        MainTable.GetDate.ToShortDateString = function() {
            if (isDateSelected())
                return MonthSelect.options[MonthSelect.selectedIndex].value + "/" + DaySelect.options[DaySelect.selectedIndex].value + "/" + YearSelect.options[YearSelect.selectedIndex].value;
            else
                return null;
        }

        return MainTable;
    }

    var CreateDateSelector_Text = function(commonId, width) {
        var NowDate = new Date();

        var MainTable = document.createElement("table");
        MainTable.id = commonId;
        MainTable.border = "0";
        MainTable.cellSpacing = "0";
        MainTable.cellPadding = "0";
        MainTable.className = "DateSelector_MainTable";
        MainTable.currentInput = 1;
        MainTable.style.width = (width ? width : "100px");

        var MainTR = document.createElement("tr");

        var DateTD = document.createElement("td");
        DateTD.align = "left";
        DateTD.vAlign = "top";
        DateTD.style.padding = "1px 1px 1px 3px";

        var InnerDateTable = document.createElement("table");
        InnerDateTable.border = "0";
        InnerDateTable.cellSpacing = "0";
        InnerDateTable.cellPadding = "0";
        InnerDateTable.style.height = "16px";

        var InnerDateTR = document.createElement("tr");

        var MonthTD = document.createElement("td");
        MonthTD.align = "left";

        var MonthInput = document.createElement("input");
        MonthInput.className = "DateSelector_Input";
        MonthInput.type = "text";
        MonthInput.style.height = "14px";
        //MonthInput.readOnly = true;
        //MonthInput.style.cursor = "pointer";
        MonthInput.inputNumber = 1;
        MonthInput.maxValue = 12;
        MonthInput.minValue = 1;

        MonthInput.value = parseInt(NowDate.getMonth()) + 1;

        if (parseInt(MonthInput.value) >= 10) {
            MonthInput.style.width = "13px";
        }
        else {
            MonthInput.style.width = "8px";
        }

        MonthTD.appendChild(MonthInput);

        var Slash1TD = document.createElement("td");
        Slash1TD.style.fontSize = "11px";
        Slash1TD.innerHTML = "&nbsp;/&nbsp;";

        var DateInputTD = document.createElement("td");
        DateInputTD.align = "left";

        var DateInput = document.createElement("input");
        DateInput.className = "DateSelector_Input";
        DateInput.type = "text";
        DateInput.style.height = "14px";
        //DateInput.readOnly = true;
        //DateInput.style.cursor = "pointer";
        DateInput.inputNumber = 2;

        var EndMonthStartValue = 32;

        var TempDate = new Date(NowDate.getFullYear(), NowDate.getMonth(), EndMonthStartValue);

        while (TempDate.getMonth() != NowDate.getMonth()) {
            TempDate = null;
            EndMonthStartValue--;

            TempDate = new Date(NowDate.getFullYear(), NowDate.getMonth(), EndMonthStartValue);
        }

        DateInput.minValue = 1;
        DateInput.maxValue = EndMonthStartValue;

        TempDate = null;

        DateInput.value = NowDate.getDate();

        if (parseInt(DateInput.value) >= 10) {
            DateInput.style.width = "13px";
        }
        else {
            DateInput.style.width = "8px";
        }

        DateInputTD.appendChild(DateInput);

        var Slash2TD = document.createElement("td");
        Slash2TD.style.fontSize = "11px";
        Slash2TD.innerHTML = "&nbsp;/&nbsp;";

        var YearTD = document.createElement("td");

        var YearInput = document.createElement("input");
        YearInput.className = "DateSelector_Input";
        YearInput.type = "text";
        YearInput.style.height = "14px";
        YearInput.style.width = "26px";
        //YearInput.readOnly = true;
        //YearInput.style.cursor = "pointer";        
        YearInput.inputNumber = 3;
        YearInput.maxValue = NowDate.getFullYear() + maxYear;
        YearInput.minValue = NowDate.getFullYear() - minYear;

        YearInput.value = NowDate.getFullYear();

        YearTD.appendChild(YearInput);

        InnerDateTR.appendChild(MonthTD);
        InnerDateTR.appendChild(Slash1TD);
        InnerDateTR.appendChild(DateInputTD);
        InnerDateTR.appendChild(Slash2TD);
        InnerDateTR.appendChild(YearTD);

        if (DetermineBrowser() == Browsers.IE) {
            var InnerDateTBody = document.createElement("tbody");

            InnerDateTBody.appendChild(InnerDateTR);

            InnerDateTable.appendChild(InnerDateTBody);
        }
        else {
            InnerDateTable.appendChild(InnerDateTR);
        }

        DateTD.appendChild(InnerDateTable);

        var IconTD = document.createElement("td");
        IconTD.align = "left";
        IconTD.vAlign = "top";
        IconTD.style.width = "15px";
        IconTD.style.padding = "1px";

        var IconTable = document.createElement("table");
        IconTable.border = "0";
        IconTable.cellSpacing = "0";
        IconTable.cellPadding = "0";
        IconTable.style.width = "15px";
        IconTable.style.height = "16px";

        var ArrowUpTR = document.createElement("tr");

        var ArrowUpTD = document.createElement("td");
        ArrowUpTD.style.height = "8px";

        var ArrowUpIMG = document.createElement("img");
        ArrowUpIMG.id = commonId + "_IconArrowUp";
        ArrowUpIMG.style.cursor = "pointer";
        ArrowUpIMG.style.width = "15px";
        ArrowUpIMG.style.height = "8px";

        //ArrowUpIMG.src = Level + "images/SplitArrowUp.gif";
        top.SI.src("SplitArrowUp.gif", ArrowUpIMG, top.SiteImagesType.Base);

        ArrowUpTD.appendChild(ArrowUpIMG);

        ArrowUpTR.appendChild(ArrowUpTD);

        var ArrowDownTR = document.createElement("tr");

        var ArrowDownTD = document.createElement("td");
        ArrowDownTD.style.height = "8px";

        var ArrowDownIMG = document.createElement("img");
        ArrowDownIMG.id = commonId + "_IconArrowDown";
        ArrowDownIMG.style.height = "8px";
        ArrowDownIMG.style.width = "15px";
        ArrowDownIMG.style.cursor = "pointer";

        //ArrowDownIMG.src = Level + "images/SplitArrowDown.gif";
        top.SI.src("SplitArrowDown.gif", ArrowDownIMG, top.SiteImagesType.Base);

        ArrowDownTD.appendChild(ArrowDownIMG);

        ArrowDownTR.appendChild(ArrowDownTD);

        if (DetermineBrowser() == Browsers.IE) {
            var IconTBody = document.createElement("tbody");

            IconTBody.appendChild(ArrowUpTR);
            IconTBody.appendChild(ArrowDownTR);

            IconTable.appendChild(IconTBody);
        }
        else {
            IconTable.appendChild(ArrowUpTR);
            IconTable.appendChild(ArrowDownTR);
        }

        IconTD.appendChild(IconTable);

        MainTR.appendChild(DateTD);
        MainTR.appendChild(IconTD);

        if (DetermineBrowser() == Browsers.IE) {
            var MainTBody = document.createElement("tbody");

            MainTBody.appendChild(MainTR);

            MainTable.appendChild(MainTBody);
        }
        else {
            MainTable.appendChild(MainTR);
        }

        MainTable.onchange = function() {

        }

        MainTable.ChangeDate = function(Month, Day, Year) {
            var CurrentDate = new Date(Year, Month, Day);

            MonthInput.value = parseInt(CurrentDate.getMonth()) + 1;
            DateInput.value = CurrentDate.getDate();
            YearInput.value = CurrentDate.getFullYear();

            var EndMonthStartValue = 32;
            var TempDate = new Date(CurrentDate.getFullYear(), CurrentDate.getMonth(), EndMonthStartValue);

            while (TempDate.getMonth() != CurrentDate.getMonth()) {
                TempDate = null;
                EndMonthStartValue--;

                TempDate = new Date(CurrentDate.getFullYear(), CurrentDate.getMonth(), EndMonthStartValue);
            }

            DateInput.maxValue = parseInt(EndMonthStartValue);

            if (parseInt(DateInput.value) > DateInput.maxValue) DateInput.value = DateInput.maxValue;

            if (parseInt(MonthInput.value) >= 10) {
                MonthInput.style.width = "13px";
            }
            else {
                MonthInput.style.width = "8px";
            }

            if (parseInt(DateInput.value) >= 10) {
                DateInput.style.width = "13px";
            }
            else {
                DateInput.style.width = "8px";
            }

            TempDate = null;
            CurrentDate = null;
        }

        MonthInput.onfocus = function() {
            MainTable.currentInput = 1;
            this.select();
        }

        DateInput.onfocus = function() {
            MainTable.currentInput = 2;
            this.select();
        }

        YearInput.onfocus = function() {
            MainTable.currentInput = 3;
            this.select();
        }

        MainTable.GetDate = function() {
            return new Date(YearInput.value, parseInt(MonthInput.value) - 1, DateInput.value);
        }

        MainTable.GetDate.ToShortDateString = function() {
            return MonthInput.value + "/" + DateInput.value + "/" + YearInput.value;
        }

        ArrowDownIMG.onclick = function() {
            switch (MainTable.currentInput) {
                case 1:
                    var newValue = parseInt(MonthInput.value) - 1;

                    if (newValue < MonthInput.minValue) newValue = MonthInput.maxValue;

                    MonthInput.value = newValue;

                    if (parseInt(MonthInput.value) >= 10) {
                        MonthInput.style.width = "13px";
                    }
                    else {
                        MonthInput.style.width = "8px";
                    }

                    MonthInput.focus();
                    MonthInput.select();

                    var EndMonthStartValue = 32;

                    var CurrentDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, 1);
                    var TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);

                    while (TempDate.getMonth() != CurrentDate.getMonth()) {
                        TempDate = null;
                        EndMonthStartValue--;

                        TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);
                    }

                    DateInput.maxValue = EndMonthStartValue;

                    if (parseInt(DateInput.value) > DateInput.maxValue) DateInput.value = DateInput.maxValue;

                    TempDate = null;
                    CurrentDate = null;
                    break;
                case 2:
                    var newValue = parseInt(DateInput.value) - 1;

                    if (newValue < DateInput.minValue) newValue = DateInput.maxValue;

                    DateInput.value = newValue;

                    if (parseInt(DateInput.value) >= 10) {
                        DateInput.style.width = "13px";
                    }
                    else {
                        DateInput.style.width = "8px";
                    }

                    DateInput.focus();
                    DateInput.select();
                    break;
                case 3:
                    var newValue = parseInt(YearInput.value) - 1;

                    if (newValue < YearInput.minValue) newValue = YearInput.maxValue;

                    YearInput.value = newValue;

                    YearInput.focus();
                    YearInput.select();

                    var EndMonthStartValue = 32;

                    var CurrentDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, 1);
                    var TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);

                    while (TempDate.getMonth() != CurrentDate.getMonth()) {
                        TempDate = null;
                        EndMonthStartValue--;

                        TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);
                    }

                    DateInput.maxValue = EndMonthStartValue;

                    if (parseInt(DateInput.value) > DateInput.maxValue) DateInput.value = DateInput.maxValue;

                    TempDate = null;
                    CurrentDate = null;
                    break;
            }

            MainTable.onchange();
        }

        ArrowUpIMG.onclick = function() {
            switch (MainTable.currentInput) {
                case 1:
                    var newValue = parseInt(MonthInput.value) + 1;

                    if (newValue > MonthInput.maxValue) newValue = MonthInput.minValue;

                    MonthInput.value = newValue;

                    if (parseInt(MonthInput.value) >= 10) {
                        MonthInput.style.width = "13px";
                    }
                    else {
                        MonthInput.style.width = "8px";
                    }

                    MonthInput.focus();
                    MonthInput.select();

                    var EndMonthStartValue = 32;

                    var CurrentDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, 1);
                    var TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);

                    while (TempDate.getMonth() != CurrentDate.getMonth()) {
                        TempDate = null;
                        EndMonthStartValue--;

                        TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);
                    }

                    DateInput.maxValue = EndMonthStartValue;

                    if (parseInt(DateInput.value) > DateInput.maxValue) DateInput.value = DateInput.maxValue;

                    TempDate = null;
                    CurrentDate = null;
                    break;
                case 2:
                    var newValue = parseInt(DateInput.value) + 1;

                    if (newValue > DateInput.maxValue) newValue = DateInput.minValue;

                    DateInput.value = newValue;

                    if (parseInt(DateInput.value) >= 10) {
                        DateInput.style.width = "13px";
                    }
                    else {
                        DateInput.style.width = "8px";
                    }

                    DateInput.focus();
                    DateInput.select();
                    break;
                case 3:
                    var newValue = parseInt(YearInput.value) + 1;

                    if (newValue > YearInput.maxValue) newValue = YearInput.minValue;

                    YearInput.value = newValue;

                    YearInput.focus();
                    YearInput.select();

                    var EndMonthStartValue = 32;

                    var CurrentDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, 1);
                    var TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);

                    while (TempDate.getMonth() != CurrentDate.getMonth()) {
                        TempDate = null;
                        EndMonthStartValue--;

                        TempDate = new Date(parseInt(YearInput.value), parseInt(MonthInput.value) - 1, EndMonthStartValue);
                    }

                    DateInput.maxValue = EndMonthStartValue;

                    if (parseInt(DateInput.value) > DateInput.maxValue) DateInput.value = DateInput.maxValue;

                    TempDate = null;
                    CurrentDate = null;
                    break;
            }

            MainTable.onchange();
        }

        Date_Input_onkeydown = function(e, evt, month, date, year, mt) {
            if (!evt) evt = window.event;

            if ((evt.keyCode ? evt.keyCode : evt.which) == 38) //Up Arrow
            {
                var newValue = parseInt(e.value) + 1;

                if (newValue > e.maxValue) newValue = e.minValue;

                e.value = newValue;

                if (e.inputNumber != 3) {
                    if (parseInt(e.value) >= 10) {
                        e.style.width = "13px";
                    }
                    else {
                        e.style.width = "8px";
                    }
                }

                e.focus();
                e.select();

                if (e.inputNumber != 2) {
                    var EndMonthStartValue = 32;

                    var CurrentDate = new Date(parseInt(year.value), parseInt(month.value) - 1, 1);
                    var TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);

                    while (TempDate.getMonth() != CurrentDate.getMonth()) {
                        TempDate = null;
                        EndMonthStartValue--;

                        TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);
                    }

                    date.maxValue = EndMonthStartValue;

                    if (parseInt(date.value) > date.maxValue) date.value = date.maxValue;

                    TempDate = null;
                    CurrentDate = null;
                }

                mt.onchange();

                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
            else if ((evt.keyCode ? evt.keyCode : evt.which) == 40) //Down Arrow
            {
                var newValue = parseInt(e.value) - 1;

                if (newValue < e.minValue) newValue = e.maxValue;

                e.value = newValue;

                if (e.inputNumber != 3) {
                    if (parseInt(e.value) >= 10) {
                        e.style.width = "13px";
                    }
                    else {
                        e.style.width = "8px";
                    }
                }

                e.focus();
                e.select();

                if (e.inputNumber != 2) {
                    var EndMonthStartValue = 32;

                    var CurrentDate = new Date(parseInt(year.value), parseInt(month.value) - 1, 1);
                    var TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);

                    while (TempDate.getMonth() != CurrentDate.getMonth()) {
                        TempDate = null;
                        EndMonthStartValue--;

                        TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);
                    }

                    date.maxValue = EndMonthStartValue;

                    if (parseInt(date.value) > date.maxValue) date.value = date.maxValue;

                    TempDate = null;
                    CurrentDate = null;
                }

                mt.onchange();

                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
            else if ((evt.keyCode ? evt.keyCode : evt.which) == 37) //Left Arrow
            {
                var currentInput = e.inputNumber;

                currentInput--;

                if (currentInput < 1) currentInput = 3;

                switch (currentInput) {
                    case 1:
                        month.focus();
                        month.select();
                        break;
                    case 2:
                        date.focus();
                        date.select();
                        break;
                    case 3:
                        year.focus();
                        year.select();
                        break;
                }

                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
            else if ((evt.keyCode ? evt.keyCode : evt.which) == 39) //Right Arrow
            {
                var currentInput = e.inputNumber;

                currentInput++;

                if (currentInput > 3) currentInput = 1;

                switch (currentInput) {
                    case 1:
                        month.focus();
                        month.select();
                        break;
                    case 2:
                        date.focus();
                        date.select();
                        break;
                    case 3:
                        year.focus();
                        year.select();
                        break;
                }
                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
        }

        Date_Input_onkeyup = function(e, evt, month, date, year, mt) {
            if (e.inputNumber != 3) {
                if (e.value.length > 2) {
                    e.value = e.value.substr(1, 2);
                }
                else if (parseInt(e.value.length) == 2) {
                    e.style.width = "13px";
                }
                else {
                    e.style.width = "8px";
                }
            }
            else {
                if (e.value.length > 4) {
                    e.value = e.value.substr(1, 4);
                }
            }
        }

        Date_Input_onblur = function(e, evt, month, date, year, mt) {
            switch (e.inputNumber) {
                case 1:
                    if (isNaN(e.value)) {
                        e.value = "1";
                    }
                    else {
                        if (parseInt(e.value) > 12) {
                            e.value = "12";
                        }
                        else if (parseInt(e.value) < 1) {
                            e.value = "1";
                        }
                    }

                    e.value = parseInt(e.value);

                    if (e.inputNumber != 3) {
                        if (parseInt(e.value) >= 10) {
                            e.style.width = "13px";
                        }
                        else {
                            e.style.width = "8px";
                        }
                    }

                    if (e.inputNumber != 2) {
                        var EndMonthStartValue = 32;

                        var CurrentDate = new Date(parseInt(year.value), parseInt(month.value) - 1, 1);
                        var TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);

                        while (TempDate.getMonth() != CurrentDate.getMonth()) {
                            TempDate = null;
                            EndMonthStartValue--;

                            TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);
                        }

                        date.maxValue = EndMonthStartValue;

                        if (parseInt(date.value) > date.maxValue) date.value = date.maxValue;

                        TempDate = null;
                        CurrentDate = null;
                    }

                    mt.onchange();

                    break;
                case 2:
                    if (isNaN(e.value)) {
                        e.value = "1";
                    }
                    else {
                        if (parseInt(e.value) > date.maxValue) {
                            e.value = date.maxValue;
                        }
                        else if (parseInt(e.value) < 1) {
                            e.value = "1";
                        }
                    }

                    e.value = parseInt(e.value);

                    if (e.inputNumber != 3) {
                        if (parseInt(e.value) >= 10) {
                            e.style.width = "13px";
                        }
                        else {
                            e.style.width = "8px";
                        }
                    }

                    mt.onchange();
                    break;
                case 3:
                    var nowDate = new Date();

                    if (isNaN(e.value)) {
                        e.value = year.maxValue;
                    }
                    else if (e.value.length != 4) {
                        var CurrentFullYear = nowDate.getFullYear();
                        var CurrentFullYearLastTwo = CurrentFullYear - 2000;

                        e.value = parseInt(e.value);
                        e.value = Math.abs(e.value);

                        if (e.value.length == 2 || e.value.length == 1) {
                            if (parseInt(e.value) > CurrentFullYearLastTwo) {
                                e.value = "19" + (e.value.length == 1 ? "0" + e.value : e.value);
                            }
                            else {
                                e.value = "20" + (e.value.length == 1 ? "0" + e.value : e.value);
                            }
                        }
                        else {
                            e.value = year.maxValue;
                        }
                    }
                    else {
                        if (parseInt(e.value) > year.maxValue) {
                            e.value = year.maxValue;
                        }
                        else if (parseInt(e.value) < year.minValue) {
                            e.value = year.minValue;
                        }
                    }

                    e.value = parseInt(e.value);

                    nowDate = null;

                    if (e.inputNumber != 2) {
                        var EndMonthStartValue = 32;

                        var CurrentDate = new Date(parseInt(year.value), parseInt(month.value) - 1, 1);
                        var TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);

                        while (TempDate.getMonth() != CurrentDate.getMonth()) {
                            TempDate = null;
                            EndMonthStartValue--;

                            TempDate = new Date(parseInt(year.value), parseInt(month.value) - 1, EndMonthStartValue);
                        }

                        date.maxValue = EndMonthStartValue;

                        if (parseInt(date.value) > date.maxValue) date.value = date.maxValue;

                        TempDate = null;
                        CurrentDate = null;
                    }

                    mt.onchange();

                    break;
            }
        }

        MonthInput.addEventListener ? MonthInput.addEventListener("keydown", function(evt) { Date_Input_onkeydown(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : MonthInput.onkeydown = function() { Date_Input_onkeydown(this, event, MonthInput, DateInput, YearInput, MainTable); };
        DateInput.addEventListener ? DateInput.addEventListener("keydown", function(evt) { Date_Input_onkeydown(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : DateInput.onkeydown = function() { Date_Input_onkeydown(this, event, MonthInput, DateInput, YearInput, MainTable); };
        YearInput.addEventListener ? YearInput.addEventListener("keydown", function(evt) { Date_Input_onkeydown(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : YearInput.onkeydown = function() { Date_Input_onkeydown(this, event, MonthInput, DateInput, YearInput, MainTable); };

        MonthInput.addEventListener ? MonthInput.addEventListener("keyup", function(evt) { Date_Input_onkeyup(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : MonthInput.onkeyup = function() { Date_Input_onkeyup(this, event, MonthInput, DateInput, YearInput, MainTable); };
        DateInput.addEventListener ? DateInput.addEventListener("keyup", function(evt) { Date_Input_onkeyup(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : DateInput.onkeyup = function() { Date_Input_onkeyup(this, event, MonthInput, DateInput, YearInput, MainTable); };
        YearInput.addEventListener ? YearInput.addEventListener("keyup", function(evt) { Date_Input_onkeyup(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : YearInput.onkeyup = function() { Date_Input_onkeyup(this, event, MonthInput, DateInput, YearInput, MainTable); };

        MonthInput.addEventListener ? MonthInput.addEventListener("blur", function(evt) { Date_Input_onblur(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : MonthInput.onblur = function() { Date_Input_onblur(this, event, MonthInput, DateInput, YearInput, MainTable); };
        DateInput.addEventListener ? DateInput.addEventListener("blur", function(evt) { Date_Input_onblur(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : DateInput.onblur = function() { Date_Input_onblur(this, event, MonthInput, DateInput, YearInput, MainTable); };
        YearInput.addEventListener ? YearInput.addEventListener("blur", function(evt) { Date_Input_onblur(this, evt, MonthInput, DateInput, YearInput, MainTable); }, false) : YearInput.onblur = function() { Date_Input_onblur(this, event, MonthInput, DateInput, YearInput, MainTable); };

        NowDate = null;

        return MainTable;
    }

    DateTimeSelector.prototype.CreateTimeSelector = function(commonId, width) {
        var NowDate = new Date();

        var MainTable = document.createElement("table");
        MainTable.className = "DateSelector_MainTable";
        MainTable.border = "0";
        MainTable.cellSpacing = "0";
        MainTable.cellPadding = "0";
        MainTable.style.width = (width ? width : "100px");
        MainTable.currentInput = 1;
        MainTable.id = commonId;

        var MainTR = document.createElement("tr");

        var TimeTD = document.createElement("td");
        TimeTD.align = "left";
        TimeTD.vAlign = "top";
        TimeTD.style.padding = "1px 1px 1px 3px";

        var InnerTimeTable = document.createElement("table");
        InnerTimeTable.border = "0";
        InnerTimeTable.cellSpacing = "0";
        InnerTimeTable.cellPadding = "0";
        InnerTimeTable.style.height = "16px";

        var InnerTimeTR = document.createElement("tr");

        var InnerTimeTD = document.createElement("td");
        InnerTimeTD.align = "left";
        InnerTimeTD.vAlign = "top";
        InnerTimeTD.style.fontSize = "11px";
        InnerTimeTD.style.paddingRight = "5px";

        var HourInput = document.createElement("input");
        HourInput.className = "DateSelector_Input";
        HourInput.type = "text";
        HourInput.style.height = "14px";
        HourInput.readOnly = true;
        //HourInput.style.cursor = "pointer";
        HourInput.inputNumber = 1;
        HourInput.maxValue = 12;
        HourInput.minValue = 1;

        if (NowDate.getHours() == 0) {
            HourInput.value = 12;
        }
        else if (NowDate.getHours() > 12) {
            HourInput.value = NowDate.getHours() - 12;
        }
        else {
            HourInput.value = NowDate.getHours();
        }

        if (parseInt(HourInput.value) >= 10) {
            HourInput.style.width = "13px";
        }
        else {
            HourInput.style.width = "8px";
        }

        var MinuteInput = document.createElement("input");
        MinuteInput.className = "DateSelector_Input";
        MinuteInput.type = "text";
        MinuteInput.style.height = "14px";
        MinuteInput.style.width = "13px";
        MinuteInput.readOnly = true;
        //MinuteInput.style.cursor = "pointer";
        MinuteInput.inputNumber = 2;
        MinuteInput.maxValue = 4;
        MinuteInput.minValue = 1;
        MinuteInput.currentValue = 1;

        MinuteInput.value = "00";

        var TimeOfDayInput = document.createElement("input");
        TimeOfDayInput.className = "DateSelector_Input";
        TimeOfDayInput.type = "text";
        TimeOfDayInput.style.height = "14px";
        TimeOfDayInput.style.width = "15px";
        TimeOfDayInput.readOnly = true;
        //TimeOfDayInput.style.cursor = "pointer";
        TimeOfDayInput.inputNumber = 3;
        TimeOfDayInput.maxValue = 2;
        TimeOfDayInput.minValue = 1;

        if (NowDate.getHours() > 12) {
            TimeOfDayInput.currentValue = 2;
            TimeOfDayInput.value = "PM";
        }
        else {
            TimeOfDayInput.currentValue = 1;
            TimeOfDayInput.value = "AM";
        }

        InnerTimeTD.appendChild(HourInput);
        InnerTimeTD.appendChild(document.createTextNode(" : "))
        InnerTimeTD.appendChild(MinuteInput);
        InnerTimeTD.appendChild(document.createTextNode(" "))
        InnerTimeTD.appendChild(TimeOfDayInput);

        InnerTimeTR.appendChild(InnerTimeTD);

        if (DetermineBrowser() == Browsers.IE) {
            var InnerTimeTBody = document.createElement("tbody");

            InnerTimeTBody.appendChild(InnerTimeTR);

            InnerTimeTable.appendChild(InnerTimeTBody);
        }
        else {
            InnerTimeTable.appendChild(InnerTimeTR);
        }

        TimeTD.appendChild(InnerTimeTable);

        var IconTD = document.createElement("td");
        IconTD.align = "left";
        IconTD.vAlign = "top";
        IconTD.style.width = "15px";
        IconTD.style.padding = "1px";

        var IconTable = document.createElement("table");
        IconTable.border = "0";
        IconTable.cellSpacing = "0";
        IconTable.cellPadding = "0";
        IconTable.style.width = "15px";
        IconTable.style.height = "16px";

        var ArrowUpTR = document.createElement("tr");

        var ArrowUpTD = document.createElement("td");
        ArrowUpTD.style.height = "8px";

        var ArrowUpIMG = document.createElement("img");
        ArrowUpIMG.id = commonId + "_IconArrowUp";
        ArrowUpIMG.style.cursor = "pointer";
        ArrowUpIMG.style.width = "15px";
        ArrowUpIMG.style.height = "8px";

        //ArrowUpIMG.src = Level + "images/SplitArrowUp.gif";
        top.SI.src("SplitArrowUp.gif", ArrowUpIMG, top.SiteImagesType.Base);

        ArrowUpTD.appendChild(ArrowUpIMG);

        ArrowUpTR.appendChild(ArrowUpTD);

        var ArrowDownTR = document.createElement("tr");

        var ArrowDownTD = document.createElement("td");
        ArrowDownTD.style.height = "8px";

        var ArrowDownIMG = document.createElement("img");
        ArrowDownIMG.id = commonId + "_IconArrowDown";
        ArrowDownIMG.style.height = "8px";
        ArrowDownIMG.style.width = "15px";
        ArrowDownIMG.style.cursor = "pointer";

        ArrowDownIMG.src = Level + "images/SplitArrowDown.gif";

        ArrowDownTD.appendChild(ArrowDownIMG);

        ArrowDownTR.appendChild(ArrowDownTD);

        if (DetermineBrowser() == Browsers.IE) {
            var IconTBody = document.createElement("tbody");

            IconTBody.appendChild(ArrowUpTR);
            IconTBody.appendChild(ArrowDownTR);

            IconTable.appendChild(IconTBody);
        }
        else {
            IconTable.appendChild(ArrowUpTR);
            IconTable.appendChild(ArrowDownTR);
        }

        IconTD.appendChild(IconTable);

        MainTR.appendChild(TimeTD);
        MainTR.appendChild(IconTD);

        if (DetermineBrowser() == Browsers.IE) {
            var MainTBody = document.createElement("tbody");

            MainTBody.appendChild(MainTR);

            MainTable.appendChild(MainTBody);
        }
        else {
            MainTable.appendChild(MainTR);
        }

        MainTable.onchange = function() {

        }

        MainTable.shrink = function() {
            InnerTimeTD.style.whiteSpace = "nowrap";
            InnerTimeTD.style.paddingRight = "0px";
            HourInput.width = "13";
            HourInput.style.margin = "0px";
            HourInput.style.padding = "0px";
            MinuteInput.style.width = "13px";
            MinuteInput.style.margin = "0px";
            MinuteInput.style.padding = "0px";
            TimeOfDayInput.style.padding = "0px";
            TimeOfDayInput.style.paddingLeft = "1px";

            InnerTimeTD.innerHTML = "";

            InnerTimeTD.appendChild(HourInput);
            InnerTimeTD.appendChild(document.createTextNode(":"))
            InnerTimeTD.appendChild(MinuteInput);
            InnerTimeTD.appendChild(TimeOfDayInput);
        }


        MainTable.ChangeTime = function(Hour, Minute) {
            if (parseInt(Hour) == 0) {
                HourInput.value = 12;
                TimeOfDayInput.currentValue = 1;
            }
            else if (parseInt(Hour) > 12) {
                HourInput.value = parseInt(Hour) - 12;
                TimeOfDayInput.currentValue = 2;
            }
            else {
                HourInput.value = parseInt(Hour);

                if (parseInt(Hour) == 12) {
                    TimeOfDayInput.currentValue = 2;
                }
                else {
                    TimeOfDayInput.currentValue = 1;
                }
            }

            if (parseInt(Minute) < 15) {
                MinuteInput.currentValue = 1;
            }
            else if (parseInt(Minute) >= 15 && parseInt(Minute) < 30) {
                MinuteInput.currentValue = 2;
            }
            else if (parseInt(Minute) >= 30 && parseInt(Minute) < 45) {
                MinuteInput.currentValue = 3;
            }
            else {
                MinuteInput.currentValue = 4;
            }

            if (parseInt(HourInput.value) >= 10) {
                HourInput.style.width = "13px";
            }
            else {
                HourInput.style.width = "8px";
            }

            switch (MinuteInput.currentValue) {
                case 1:
                    MinuteInput.value = "00";
                    break;
                case 2:
                    MinuteInput.value = "15";
                    break;
                case 3:
                    MinuteInput.value = "30";
                    break;
                case 4:
                    MinuteInput.value = "45";
                    break;
            }

            switch (TimeOfDayInput.currentValue) {
                case 1:
                    TimeOfDayInput.value = "AM";
                    break;
                case 2:
                    TimeOfDayInput.value = "PM";
                    break;
            }
        }

        HourInput.onfocus = function() {
            MainTable.currentInput = 1;
            this.select();
        }

        MinuteInput.onfocus = function() {
            MainTable.currentInput = 2;
            this.select();
        }

        TimeOfDayInput.onfocus = function() {
            MainTable.currentInput = 3;
            this.select();
        }

        MainTable.GetTime = function() {
            var TempDate = new Date();

            var setHours = "";

            if (TimeOfDayInput.currentValue == 2) {
                if (parseInt(HourInput.value) != 12) {
                    setHours = parseInt(HourInput.value) - 12;
                }
                else {
                    setHours = parseInt(HourInput.value);
                }
            }
            else {
                if (parseInt(HourInput.value) == 12) {
                    setHours = parseInt(HourInput.value) - 12;
                }
                else {
                    setHours = parseInt(HourInput.value);
                }
            }

            TempDate.setHours(setHours, parseInt(MinuteInput.value), 0, 0);

            return TempDate;
        }

        MainTable.GetTime.ToShortTimeString = function() {
            return HourInput.value + ":" + MinuteInput.value + " " + TimeOfDayInput.value;
        }

        ArrowUpIMG.onclick = function() {
            switch (MainTable.currentInput) {
                case 1:
                    var newValue = parseInt(HourInput.value) + 1;

                    if (newValue > HourInput.maxValue) newValue = HourInput.minValue;

                    HourInput.value = newValue;

                    if (parseInt(HourInput.value) >= 10) {
                        HourInput.style.width = "13px";
                    }
                    else {
                        HourInput.style.width = "8px";
                    }

                    HourInput.focus();
                    HourInput.select();
                    break;
                case 2:
                    var newValue = parseInt(MinuteInput.currentValue) + 1;

                    if (newValue > MinuteInput.maxValue) newValue = MinuteInput.minValue;

                    MinuteInput.currentValue = newValue

                    switch (MinuteInput.currentValue) {
                        case 1:
                            MinuteInput.value = "00";
                            break;
                        case 2:
                            MinuteInput.value = "15";
                            break;
                        case 3:
                            MinuteInput.value = "30";
                            break;
                        case 4:
                            MinuteInput.value = "45";
                            break;
                    }

                    MinuteInput.focus();
                    MinuteInput.select();
                    break;
                case 3:
                    var newValue = parseInt(TimeOfDayInput.currentValue) + 1;

                    if (newValue > TimeOfDayInput.maxValue) newValue = TimeOfDayInput.minValue;

                    TimeOfDayInput.currentValue = newValue

                    switch (TimeOfDayInput.currentValue) {
                        case 1:
                            TimeOfDayInput.value = "AM";
                            break;
                        case 2:
                            TimeOfDayInput.value = "PM";
                            break;
                    }

                    TimeOfDayInput.focus();
                    TimeOfDayInput.select();
                    break;
            }

            MainTable.onchange();
        }

        ArrowDownIMG.onclick = function() {
            switch (MainTable.currentInput) {
                case 1:
                    var newValue = parseInt(HourInput.value) - 1;

                    if (newValue < HourInput.minValue) newValue = HourInput.maxValue;

                    HourInput.value = newValue;

                    if (parseInt(HourInput.value) >= 10) {
                        HourInput.style.width = "13px";
                    }
                    else {
                        HourInput.style.width = "8px";
                    }

                    HourInput.focus();
                    HourInput.select();
                    break;
                case 2:
                    var newValue = parseInt(MinuteInput.currentValue) - 1;

                    if (newValue < MinuteInput.minValue) newValue = MinuteInput.maxValue;

                    MinuteInput.currentValue = newValue;

                    switch (parseInt(MinuteInput.currentValue)) {
                        case 1:
                            MinuteInput.value = "00";
                            break;
                        case 2:
                            MinuteInput.value = "15";
                            break;
                        case 3:
                            MinuteInput.value = "30";
                            break;
                        case 4:
                            MinuteInput.value = "45";
                            break;
                    }

                    MinuteInput.focus();
                    MinuteInput.select();
                    break;
                case 3:
                    var newValue = parseInt(TimeOfDayInput.currentValue) - 1;

                    if (newValue < TimeOfDayInput.minValue) newValue = TimeOfDayInput.maxValue;

                    TimeOfDayInput.currentValue = newValue;

                    switch (parseInt(TimeOfDayInput.currentValue)) {
                        case 1:
                            TimeOfDayInput.value = "AM";
                            break;
                        case 2:
                            TimeOfDayInput.value = "PM";
                            break;
                    }

                    TimeOfDayInput.focus();
                    TimeOfDayInput.select();
                    break;
            }

            MainTable.onchange();
        }

        Time_Input_onkeydown = function(e, evt, hour, minute, timeofday, mt) {
            if (!evt) evt = window.event;

            if ((evt.keyCode ? evt.keyCode : evt.which) == 38) //Up Arrow
            {
                switch (e.inputNumber) {
                    case 1:
                        var newValue = parseInt(e.value) + 1;

                        if (newValue > e.maxValue) newValue = e.minValue;

                        e.value = newValue;

                        if (parseInt(e.value) >= 10) {
                            e.style.width = "13px";
                        }
                        else {
                            e.style.width = "8px";
                        }
                        break;
                    case 2:
                        var newValue = parseInt(e.currentValue) + 1;

                        if (newValue > e.maxValue) newValue = e.minValue;

                        e.currentValue = parseInt(newValue);

                        switch (e.currentValue) {
                            case 1:
                                e.value = "00";
                                break;
                            case 2:
                                e.value = "15";
                                break;
                            case 3:
                                e.value = "30";
                                break;
                            case 4:
                                e.value = "45";
                                break;
                        }
                        break;
                    case 3:
                        var newValue = parseInt(e.currentValue) + 1;

                        if (newValue > e.maxValue) newValue = e.minValue;

                        e.currentValue = parseInt(newValue);

                        switch (e.currentValue) {
                            case 1:
                                e.value = "AM";
                                break;
                            case 2:
                                e.value = "PM";
                                break;
                        }
                        break;
                }

                e.focus();
                e.select();

                mt.onchange();

                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
            else if ((evt.keyCode ? evt.keyCode : evt.which) == 40) //Down Arrow
            {
                switch (e.inputNumber) {
                    case 1:
                        var newValue = parseInt(e.value) - 1;

                        if (newValue < e.minValue) newValue = e.maxValue;

                        e.value = newValue;

                        if (parseInt(e.value) >= 10) {
                            e.style.width = "13px";
                        }
                        else {
                            e.style.width = "8px";
                        }
                        break;
                    case 2:
                        var newValue = parseInt(e.currentValue) - 1;

                        if (newValue < e.minValue) newValue = e.maxValue;

                        e.currentValue = parseInt(newValue);

                        switch (e.currentValue) {
                            case 1:
                                e.value = "00";
                                break;
                            case 2:
                                e.value = "15";
                                break;
                            case 3:
                                e.value = "30";
                                break;
                            case 4:
                                e.value = "45";
                                break;
                        }
                        break;
                    case 3:
                        var newValue = parseInt(e.currentValue) - 1;

                        if (newValue < e.minValue) newValue = e.maxValue;

                        e.currentValue = parseInt(newValue);

                        switch (e.currentValue) {
                            case 1:
                                e.value = "AM";
                                break;
                            case 2:
                                e.value = "PM";
                                break;
                        }
                        break;
                }

                e.focus();
                e.select();

                mt.onchange();

                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
            else if ((evt.keyCode ? evt.keyCode : evt.which) == 37) //Left Arrow
            {
                var currentInput = e.inputNumber;

                currentInput--;

                if (currentInput < 1) currentInput = 3;

                switch (currentInput) {
                    case 1:
                        hour.focus();
                        hour.select();
                        break;
                    case 2:
                        minute.focus();
                        minute.select();
                        break;
                    case 3:
                        timeofday.focus();
                        timeofday.select();
                        break;
                }

                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
            else if ((evt.keyCode ? evt.keyCode : evt.which) == 39) //Right Arrow
            {
                var currentInput = e.inputNumber;

                currentInput++;

                if (currentInput > 3) currentInput = 1;

                switch (currentInput) {
                    case 1:
                        hour.focus();
                        hour.select();
                        break;
                    case 2:
                        minute.focus();
                        minute.select();
                        break;
                    case 3:
                        timeofday.focus();
                        timeofday.select();
                        break;
                }
                if (evt.preventDefault)
                    evt.preventDefault();

                evt.returnValue = false;
            }
        }

        HourInput.addEventListener ? HourInput.addEventListener("keydown", function(evt) { Time_Input_onkeydown(this, evt, HourInput, MinuteInput, TimeOfDayInput, MainTable); }, false) : HourInput.onkeydown = function() { Time_Input_onkeydown(this, event, HourInput, MinuteInput, TimeOfDayInput, MainTable); };
        MinuteInput.addEventListener ? MinuteInput.addEventListener("keydown", function(evt) { Time_Input_onkeydown(this, evt, HourInput, MinuteInput, TimeOfDayInput, MainTable); }, false) : MinuteInput.onkeydown = function() { Time_Input_onkeydown(this, event, HourInput, MinuteInput, TimeOfDayInput, MainTable); };
        TimeOfDayInput.addEventListener ? TimeOfDayInput.addEventListener("keydown", function(evt) { Time_Input_onkeydown(this, evt, HourInput, MinuteInput, TimeOfDayInput, MainTable); }, false) : TimeOfDayInput.onkeydown = function() { Time_Input_onkeydown(this, event, HourInput, MinuteInput, TimeOfDayInput, MainTable); };

        NowDate = null;

        return MainTable;
    }

    var Browsers = { IE: 0, FireFox: 1, Other: 2 }

    function DetermineBrowser(isShow) {
        if (/msie/i.test(navigator.userAgent)) return Browsers.IE;
        if (/firefox/i.test(navigator.userAgent)) return Browsers.FireFox;
        return Browsers.Other;
    }
}
