﻿
        // JScript File

    // This function gets called when the end-user clicks on some date.
    function jsCalendarSelected(cal, date) {
        if (cal.dateClicked) {
            cal.sel.value = date; // just update the date in the input field.
            if (typeof cal.sel.onchange == "function")
            {
                if (cal.sel.fireEvent)
                {
                    cal.sel.fireEvent("onchange");
                }
                else
                {
                    var ev = document.createEvent("HTMLEvents");
                    ev.initEvent("change", true, false);
                    cal.sel.dispatchEvent(ev);
                    //cal.sel.onchange();
                }
            }
            cal.callCloseHandler();
        }
    }

    // And this gets called when the end-user clicks on the _selected_ date,
    // or clicks on the "Close" button.  It just hides the calendar without
    // destroying it.
    function jsCalendarCloseHandler(cal) {
        cal.hide();                        // hide the calendar
    }

    // This function shows the calendar under the element having the given id.
    // It takes care of catching "mousedown" signals on document and hiding the
    // calendar if the click was outside.
    function jsCalendarShowCalendar(inputField) {
        var format = '%Y/%m/%d';
        return jsCalendarShowCalendarFormat(inputField, format);
    }
    
    function jsCalendarShowCalendarFormat(inputField, format) {
        var el = inputField;        
        
        // first-time call, create the calendar.
        var cal = new Calendar(false, null, jsCalendarSelected, jsCalendarCloseHandler);
        
        // uncomment the following line to hide the week numbers
        // cal.weekNumbers = false;
        calendar = cal;                  // remember it in the global var
        cal.setRange(1900, 2070);        // min/max year allowed.
        cal.create();

        calendar.setDateFormat(format);    // set the specified date format
        calendar.parseDate(el.value);      // try to parse the text in field
        calendar.sel = el;                 // inform it what input field we use
        calendar.showAtElement(el);        // show the calendar below it

        return false;
    }
    
    function jsCalendarShowTime(inputField) {
        var el = inputField;
        var format = '%Y/%m/%d %H:%M:%S';
        
        // first-time call, create the calendar.
        var cal = new Calendar(false, null, jsCalendarSelected, jsCalendarCloseHandler);
        
        // uncomment the following line to hide the week numbers
        // cal.weekNumbers = false;
        calendar = cal;                  // remember it in the global var
        cal.setRange(1900, 2070);        // min/max year allowed.
        cal.showsTime = true;
        cal.create();
        
        calendar.setDateFormat(format);    // set the specified date format
        calendar.parseDate(el.value);      // try to parse the text in field
        calendar.sel = el;                 // inform it what input field we use
        calendar.showAtElement(el);        // show the calendar below it

        return false;
    }
