var ds = {};

function getAnchorPosition(a) {
    var c = {},
        b = 0,
        f = 0,
        e = f = b = false;
    if (document.getElementById) b = true;
    else if (document.all) f = true;
    else if (document.layers) e = true;
    if (b && document.all) {
        b = AnchorPosition_getPageOffsetLeft(document.all[a]);
        f = AnchorPosition_getPageOffsetTop(document.all[a])
    } else if (b) {
        a = document.getElementById(a);
        b = AnchorPosition_getPageOffsetLeft(a);
        f = AnchorPosition_getPageOffsetTop(a)
    } else if (f) {
        b = AnchorPosition_getPageOffsetLeft(document.all[a]);
        f = AnchorPosition_getPageOffsetTop(document.all[a])
    } else if (e) {
        for (f =
        b = 0; f < document.anchors.length; f++) if (document.anchors[f].name == a) {
            b = 1;
            break
        }
        if (b == 0) {
            c.x = 0;
            c.y = 0;
            return c
        }
        b = document.anchors[f].x;
        f = document.anchors[f].y
    } else {
        c.x = 0;
        c.y = 0;
        return c
    }
    c.x = b;
    c.y = f;
    return c
}

function getAnchorWindowPosition(a) {
    a = getAnchorPosition(a);
    var c = 0,
        b = 0;
    if (document.getElementById) if (isNaN(window.screenX)) {
        c = a.x - document.body.scrollLeft + window.screenLeft;
        b = a.y - document.body.scrollTop + window.screenTop
    } else {
        c = a.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
        b = a.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset
    } else if (document.all) {
        c = a.x - document.body.scrollLeft + window.screenLeft;
        b = a.y - document.body.scrollTop + window.screenTop
    } else if (document.layers) {
        c =
        a.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
        b = a.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset
    }
    a.x = c;
    a.y = b;
    return a
}
function AnchorPosition_getPageOffsetLeft(a) {
    for (var c = a.offsetLeft;
    (a = a.offsetParent) != null;) c += a.offsetLeft;
    return c
}
function AnchorPosition_getWindowOffsetLeft(a) {
    return AnchorPosition_getPageOffsetLeft(a) - document.body.scrollLeft
}

function AnchorPosition_getPageOffsetTop(a) {
    for (var c = a.offsetTop;
    (a = a.offsetParent) != null;) c += a.offsetTop;
    return c
}
function AnchorPosition_getWindowOffsetTop(a) {
    return AnchorPosition_getPageOffsetTop(a) - document.body.scrollTop
}
var MONTH_NAMES = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"),
    DAY_NAMES = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

function LZ(a) {
    return (a < 0 || a > 9 ? "" : "0") + a
}
function isDate(a, c) {
    if (getDateFromFormat(a, c) == 0) return false;
    return true
}

function compareDates(a, c, b, f) {
    a = getDateFromFormat(a, c);
    b = getDateFromFormat(b, f);
    if (a == 0 || b == 0) return -1;
    else if (a > b) return 1;
    return 0
}

function cp_formatDate(a, c) {
    c += "";
    var b = "",
        f = 0,
        e = "",
        d = "";
    e = a.getYear() + "";
    d = a.getMonth() + 1;
    var p = a.getDate(),
        m = a.getDay(),
        k = a.getHours(),
        h = a.getMinutes(),
        i = a.getSeconds(),
        g = {};
    if (e.length < 4) e = "" + (e - 0 + 1900);
    g.y = "" + e;
    g.yyyy = e;
    g.yy = e.substring(2, 4);
    g.M = d;
    g.MM = LZ(d);
    g.MMM = MONTH_NAMES[d - 1];
    g.NNN = MONTH_NAMES[d + 11];
    g.d = p;
    g.dd = LZ(p);
    g.E = DAY_NAMES[m + 7];
    g.EE = DAY_NAMES[m];
    g.H = k;
    g.HH = LZ(k);
    g.h = k == 0 ? 12 : k > 12 ? k - 12 : k;
    g.hh = LZ(g.h);
    g.K = k > 11 ? k - 12 : k;
    g.k = k + 1;
    g.KK = LZ(g.K);
    g.kk = LZ(g.k);
    g.a = k > 11 ? "PM" : "AM";
    g.m = h;
    g.mm = LZ(h);
    g.s = i;
    for (g.ss = LZ(i); f < c.length;) {
        e = c.charAt(f);
        for (d = ""; c.charAt(f) == e && f < c.length;) d += c.charAt(f++);
        b = g[d] != null ? b + g[d] : b + d
    }
    return b
}
function _isInteger(a) {
    for (var c = 0; c < a.length; c++) if ("1234567890".indexOf(a.charAt(c)) == -1) return false;
    return true
}
function _getInt(a, c, b, f) {
    for (f = f; f >= b; f--) {
        var e = a.substring(c, c + f);
        if (e.length < b) return null;
        if (_isInteger(e)) return e
    }
    return null
}

function getDateFromFormat(a, c) {
    a += "";
    c += "";
    var b = 0,
        f = 0,
        e = "",
        d = "",
        p, m, k = new Date,
        h = k.getYear(),
        i = k.getMonth() + 1,
        g = 1,
        j = k.getHours(),
        n = k.getMinutes();
    k = k.getSeconds();
    for (var l = ""; f < c.length;) {
        e = c.charAt(f);
        for (d = ""; c.charAt(f) == e && f < c.length;) d += c.charAt(f++);
        if (d == "yyyy" || d == "yy" || d == "y") {
            if (d == "yyyy") m = p = 4;
            if (d == "yy") m = p = 2;
            if (d == "y") {
                p = 2;
                m = 4
            }
            h = _getInt(a, b, p, m);
            if (h == null) return 0;
            b += h.length;
            if (h.length == 2) h = h > 70 ? 1900 + (h - 0) : 2E3 + (h - 0)
        } else if (d == "MMM" || d == "NNN") {
            for (e = i = 0; e < MONTH_NAMES.length; e++) {
                var o =
                MONTH_NAMES[e];
                if (a.substring(b, b + o.length).toLowerCase() == o.toLowerCase()) if (d == "MMM" || d == "NNN" && e > 11) {
                    i = e + 1;
                    if (i > 12) i -= 12;
                    b += o.length;
                    break
                }
            }
            if (i < 1 || i > 12) return 0
        } else if (d == "EE" || d == "E") for (e = 0; e < DAY_NAMES.length; e++) {
            d = DAY_NAMES[e];
            if (a.substring(b, b + d.length).toLowerCase() == d.toLowerCase()) {
                b += d.length;
                break
            }
        } else if (d == "MM" || d == "M") {
            i = _getInt(a, b, d.length, 2);
            if (i == null || i < 1 || i > 12) return 0;
            b += i.length
        } else if (d == "dd" || d == "d") {
            g = _getInt(a, b, d.length, 2);
            if (g == null || g < 1 || g > 31) return 0;
            b += g.length
        } else if (d == "hh" || d == "h") {
            j = _getInt(a, b, d.length, 2);
            if (j == null || j < 1 || j > 12) return 0;
            b += j.length
        } else if (d == "HH" || d == "H") {
            j = _getInt(a, b, d.length, 2);
            if (j == null || j < 0 || j > 23) return 0;
            b += j.length
        } else if (d == "KK" || d == "K") {
            j = _getInt(a, b, d.length, 2);
            if (j == null || j < 0 || j > 11) return 0;
            b += j.length
        } else if (d == "kk" || d == "k") {
            j = _getInt(a, b, d.length, 2);
            if (j == null || j < 1 || j > 24) return 0;
            b += j.length;
            j--
        } else if (d == "mm" || d == "m") {
            n = _getInt(a, b, d.length, 2);
            if (n == null || n < 0 || n > 59) return 0;
            b += n.length
        } else if (d == "ss" || d == "s") {
            k = _getInt(a, b, d.length, 2);
            if (k == null || k < 0 || k > 59) return 0;
            b += k.length
        } else if (d == "a") {
            if (a.substring(b, b + 2).toLowerCase() == "am") l = "AM";
            else if (a.substring(b, b + 2).toLowerCase() == "pm") l = "PM";
            else
            return 0;
            b += 2
        } else if (a.substring(b, b + d.length) != d) return 0;
        else b += d.length
    }
    if (b != a.length) return 0;
    if (i == 2) if (h % 4 == 0 && h % 100 != 0 || h % 400 == 0) {
        if (g > 29) return 0
    } else if (g > 28) return 0;
    if (i == 4 || i == 6 || i == 9 || i == 11) if (g > 30) return 0;
    if (j < 12 && l == "PM") j = j - 0 + 12;
    else if (j > 11 && l == "AM") j -= 12;
    return (new Date(h, i - 1, g, j, n, k)).getTime()
}

function parseDate(a) {
    var c = arguments.length == 2 ? arguments[1] : false;
    generalFormats = Array("y-M-d", "MMM d, y", "MMM d,y", "y-MMM-d", "d-MMM-y", "MMM d");
    monthFirst = Array("M/d/y", "M-d-y", "M.d.y", "MMM-d", "M/d", "M-d");
    dateFirst = Array("d/M/y", "d-M-y", "d.M.y", "d-MMM", "d/M", "d-M");
    c = Array("generalFormats", c ? "dateFirst" : "monthFirst", c ? "monthFirst" : "dateFirst");
    for (var b = null, f = 0; f < c.length; f++) for (var e = window[c[f]], d = 0; d < e.length; d++) {
        b = getDateFromFormat(a, e[d]);
        if (b != 0) return new Date(b)
    }
    return null
}

function PopupWindow_getXYPosition(a) {
    a = this.type == "WINDOW" ? getAnchorWindowPosition(a) : getAnchorPosition(a);
    this.x = a.x;
    this.y = a.y
}
function PopupWindow_setSize(a, c) {
    this.width = a;
    this.height = c
}
function PopupWindow_populate(a) {
    this.contents = a;
    this.populated = false
}
function PopupWindow_setUrl(a) {
    this.url = a
}
function PopupWindow_setWindowProperties(a) {
    this.windowProperties = a
}

function PopupWindow_refresh() {
    if (this.divName != null) if (this.use_gebi) document.getElementById(this.divName).innerHTML = this.contents;
    else if (this.use_css) document.all[this.divName].innerHTML = this.contents;
    else {
        if (this.use_layers) {
            var a = document.layers[this.divName];
            a.document.open();
            a.document.writeln(this.contents);
            a.document.close()
        }
    } else if (this.popupWindow != null && !this.popupWindow.closed) {
        if (this.url != "") this.popupWindow.location.href = this.url;
        else {
            this.popupWindow.document.open();
            this.popupWindow.document.writeln(this.contents);
            this.popupWindow.document.close()
        }
        this.popupWindow.focus()
    }
}

function PopupWindow_showPopup(a) {
    this.getXYPosition(a);
    this.x += this.offsetX;
    this.y += this.offsetY;
    if (!this.populated && this.contents != "") {
        this.populated = true;
        this.refresh()
    }
    if (this.divName != null) if (this.use_gebi) {
        document.getElementById(this.divName).style.left = this.x + "px";
        document.getElementById(this.divName).style.top = this.y + "px";
        document.getElementById(this.divName).style.visibility = "visible"
    } else if (this.use_css) {
        document.all[this.divName].style.left = this.x;
        document.all[this.divName].style.top =
        this.y;
        document.all[this.divName].style.visibility = "visible"
    } else {
        if (this.use_layers) {
            document.layers[this.divName].left = this.x;
            document.layers[this.divName].top = this.y;
            document.layers[this.divName].visibility = "visible"
        }
    } else {
        if (this.popupWindow == null || this.popupWindow.closed) {
            if (this.x < 0) this.x = 0;
            if (this.y < 0) this.y = 0;
            if (screen && screen.availHeight) if (this.y + this.height > screen.availHeight) this.y = screen.availHeight - this.height;
            if (screen && screen.availWidth) if (this.x + this.width > screen.availWidth) this.x =
            screen.availWidth - this.width;
            this.popupWindow = window.open(window.opera || document.layers && !navigator.mimeTypes["*"] || navigator.vendor == "KDE" || document.childNodes && !document.all && !navigator.taintEnabled ? "" : "about:blank", "window_" + a, this.windowProperties + ",width=" + this.width + ",height=" + this.height + ",screenX=" + this.x + ",left=" + this.x + ",screenY=" + this.y + ",top=" + this.y + "")
        }
        this.refresh()
    }
}

function PopupWindow_hidePopup() {
    if (this.divName != null) if (this.use_gebi) document.getElementById(this.divName).style.visibility = "hidden";
    else if (this.use_css) document.all[this.divName].style.visibility = "hidden";
    else {
        if (this.use_layers) document.layers[this.divName].visibility = "hidden"
    } else if (this.popupWindow && !this.popupWindow.closed) {
        this.popupWindow.close();
        this.popupWindow = null
    }
}

function PopupWindow_isClicked(a) {
    if (this.divName != null) {
        if (this.use_layers) {
            var c = a.pageX;
            a = a.pageY;
            var b = document.layers[this.divName];
            return c > b.left && c < b.left + b.clip.width && a > b.top && a < b.top + b.clip.height ? true : false
        } else if (document.all) {
            b = window.event.srcElement;
            try {
                for (; b.parentElement != null;) {
                    if (b.id == this.divName) return true;
                    b = b.parentElement
                }
                return false
            } catch (f) {}
        } else if (this.use_gebi && a) {
            if (a.originalTarget) b = a.originalTarget;
            if (a.target) b = a.target;
            try {
                for (; b.parentNode != null;) {
                    if (b.id == this.divName) return true;
                    b = b.parentNode
                }
                return false
            } catch (e) {}
        }
        return false
    }
    return false
}
function PopupWindow_hideIfNotClicked(a) {
    this.autoHideEnabled && !this.isClicked(a) && this.hidePopup()
}
function PopupWindow_autoHide() {
    this.autoHideEnabled = true
}
function PopupWindow_hidePopupWindows(a) {
    for (var c = 0; c < popupWindowObjects.length; c++) popupWindowObjects[c] != null && popupWindowObjects[c].hideIfNotClicked(a)
}

function PopupWindow_attachListener() {
    document.layers && document.captureEvents(Event.MOUSEUP);
    window.popupWindowOldEventListener = document.onmouseup;
    document.onmouseup = window.popupWindowOldEventListener != null ? new Function("window.popupWindowOldEventListener(); PopupWindow_hidePopupWindows();") : PopupWindow_hidePopupWindows
}

function PopupWindow() {
    if (!window.popupWindowIndex) window.popupWindowIndex = 0;
    if (!window.popupWindowObjects) window.popupWindowObjects = [];
    if (!window.listenerAttached) {
        window.listenerAttached = true;
        PopupWindow_attachListener()
    }
    this.index = popupWindowIndex++;
    popupWindowObjects[this.index] = this;
    this.popupWindow = this.divName = null;
    this.height = this.width = 0;
    this.parentCaller = this.autoHideEnabled = this.visible = this.populated = false;
    this.url = this.contents = "";
    this.windowProperties = "toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
    if (arguments.length > 0) {
        this.type = "DIV";
        this.divName = arguments[0]
    } else this.type = "WINDOW";
    this.use_layers = this.use_css = this.use_gebi = false;
    if (document.getElementById) this.use_gebi = true;
    else if (document.all) this.use_css = true;
    else if (document.layers) this.use_layers = true;
    else this.type = "WINDOW";
    this.offsetY = this.offsetX = 0;
    this.getXYPosition = PopupWindow_getXYPosition;
    this.populate = PopupWindow_populate;
    this.setUrl = PopupWindow_setUrl;
    this.setWindowProperties = PopupWindow_setWindowProperties;
    this.refresh =
    PopupWindow_refresh;
    this.showPopup = PopupWindow_showPopup;
    this.hidePopup = PopupWindow_hidePopup;
    this.setSize = PopupWindow_setSize;
    this.isClicked = PopupWindow_isClicked;
    this.autoHide = PopupWindow_autoHide;
    this.hideIfNotClicked = PopupWindow_hideIfNotClicked
}
function CP_stop(a) {
    a && a.stopPropagation && a.stopPropagation()
}

function CalendarPopup() {
    var a;
    if (arguments.length > 0) {
        a = new PopupWindow(arguments[0]);
        a.parentCaller = arguments[1]
    } else {
        a = new PopupWindow;
        a.setSize(150, 175)
    }
    a.offsetX = -152;
    a.offsetY = 25;
    a.autoHide();
    a.monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    a.monthAbbreviations = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    a.dayHeaders = Array("S", "M", "T", "W", "T", "F", "S");
    a.returnFunction = "CP_tmpReturnFunction";
    a.returnMonthFunction = "CP_tmpReturnMonthFunction";
    a.returnQuarterFunction = "CP_tmpReturnQuarterFunction";
    a.returnYearFunction = "CP_tmpReturnYearFunction";
    a.weekStartDay = 1;
    a.isShowYearNavigation = false;
    a.displayType = "date";
    a.disabledWeekDays = {};
    a.disabledDatesExpression = "";
    a.yearSelectStartOffset = 2;
    a.currentDate = null;
    a.todayText = "Today";
    a.cssPrefix = "";
    a.isShowNavigationDropdowns = false;
    a.isShowYearNavigationInput = false;
    window.CP_calendarObject = null;
    window.CP_targetInput = null;
    window.CP_dateFormat = "MM/dd/yyyy";
    a.copyMonthNamesToWindow = CP_copyMonthNamesToWindow;
    a.setReturnFunction = CP_setReturnFunction;
    a.setReturnMonthFunction = CP_setReturnMonthFunction;
    a.setReturnQuarterFunction = CP_setReturnQuarterFunction;
    a.setReturnYearFunction = CP_setReturnYearFunction;
    a.setMonthNames = CP_setMonthNames;
    a.setMonthAbbreviations = CP_setMonthAbbreviations;
    a.setDayHeaders = CP_setDayHeaders;
    a.setWeekStartDay = CP_setWeekStartDay;
    a.setDisplayType = CP_setDisplayType;
    a.setDisabledWeekDays = CP_setDisabledWeekDays;
    a.addDisabledDates = CP_addDisabledDates;
    a.setYearSelectStartOffset = CP_setYearSelectStartOffset;
    a.setTodayText = CP_setTodayText;
    a.showYearNavigation = CP_showYearNavigation;
    a.showCalendar = CP_showCalendar;
    a.hideCalendar = CP_hideCalendar;
    a.getStyles = getCalendarStyles;
    a.refreshCalendar = CP_refreshCalendar;
    a.getCalendar = CP_getCalendar;
    a.select = CP_select;
    a.setCssPrefix = CP_setCssPrefix;
    a.showNavigationDropdowns = CP_showNavigationDropdowns;
    a.showYearNavigationInput = CP_showYearNavigationInput;
    a.copyMonthNamesToWindow();
    return a
}

function CP_copyMonthNamesToWindow() {
    if (typeof window.MONTH_NAMES != "undefined" && window.MONTH_NAMES != null) {
        window.MONTH_NAMES = [];
        for (var a = 0; a < this.monthNames.length; a++) window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthNames[a];
        for (a = 0; a < this.monthAbbreviations.length; a++) window.MONTH_NAMES[window.MONTH_NAMES.length] = this.monthAbbreviations[a]
    }
}

function CP_tmpReturnFunction(a, c, b) {
    window.parentCaller != null ? window.parentCaller.setDPDate(new Date(a, c - 1, b, 0, 0, 0)) : alert("Use setReturnFunction() to define which function will get the clicked results!")
}
function CP_tmpReturnMonthFunction(a, c) {
    alert("Use setReturnMonthFunction() to define which function will get the clicked results!\nYou clicked: year=" + a + " , month=" + c)
}

function CP_tmpReturnQuarterFunction(a, c) {
    alert("Use setReturnQuarterFunction() to define which function will get the clicked results!\nYou clicked: year=" + a + " , quarter=" + c)
}
function CP_tmpReturnYearFunction(a) {
    alert("Use setReturnYearFunction() to define which function will get the clicked results!\nYou clicked: year=" + a)
}
function CP_setReturnFunction(a) {
    this.returnFunction = a
}
function CP_setReturnMonthFunction(a) {
    this.returnMonthFunction = a
}

function CP_setReturnQuarterFunction(a) {
    this.returnQuarterFunction = a
}
function CP_setReturnYearFunction(a) {
    this.returnYearFunction = a
}
function CP_setMonthNames(a) {
    for (var c = 0; c < a.length; c++) this.monthNames[c] = a[c];
    this.copyMonthNamesToWindow()
}
function CP_setMonthAbbreviations() {
    for (var a = 0; a < arguments.length; a++) this.monthAbbreviations[a] = arguments[a];
    this.copyMonthNamesToWindow()
}
function CP_setDayHeaders(a) {
    for (var c = 0; c < a.length; c++) this.dayHeaders[c] = a[c]
}

function CP_setWeekStartDay(a) {
    this.weekStartDay = a
}
function CP_showYearNavigation() {
    this.isShowYearNavigation = arguments.length > 0 ? arguments[0] : true
}
function CP_setDisplayType(a) {
    if (a != "date" && a != "week-end" && a != "month" && a != "quarter" && a != "year") {
        alert("Invalid display type! Must be one of: date,week-end,month,quarter,year");
        return false
    }
    this.displayType = a
}
function CP_setYearSelectStartOffset(a) {
    this.yearSelectStartOffset = a
}

function CP_setDisabledWeekDays() {
    this.disabledWeekDays = {};
    for (var a = 0; a < arguments.length; a++) this.disabledWeekDays[arguments[a]] = true
}

function CP_addDisabledDates(a, c) {
    if (arguments.length == 1) c = a;
    if (!(a == null && c == null)) {
        if (this.disabledDatesExpression != "") this.disabledDatesExpression += "||";
        if (a != null) {
            a = parseDate(a);
            a = "" + a.getFullYear() + LZ(a.getMonth() + 1) + LZ(a.getDate())
        }
        if (c != null) {
            c = parseDate(c);
            c = "" + c.getFullYear() + LZ(c.getMonth() + 1) + LZ(c.getDate())
        }
        this.disabledDatesExpression += a == null ? "(ds<=" + c + ")" : c == null ? "(ds>=" + a + ")" : "(ds>=" + a + "&&ds<=" + c + ")"
    }
}
function CP_setTodayText(a) {
    this.todayText = a
}

function CP_setCssPrefix(a) {
    this.cssPrefix = a
}
function CP_showNavigationDropdowns() {
    this.isShowNavigationDropdowns = arguments.length > 0 ? arguments[0] : true
}
function CP_showYearNavigationInput() {
    this.isShowYearNavigationInput = arguments.length > 0 ? arguments[0] : true
}
function CP_hideCalendar() {
    arguments.length > 0 ? window.popupWindowObjects[arguments[0]].hidePopup() : this.hidePopup()
}

function CP_refreshCalendar(a) {
    var c = window.popupWindowObjects[a];
    arguments.length > 1 ? c.populate(c.getCalendar(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5])) : c.populate(c.getCalendar());
    c.refresh()
}
function CP_showCalendar(a) {
    if (arguments.length > 1) this.currentDate = arguments[1] == null || arguments[1] == "" ? new Date : new Date(parseDate(arguments[1]));
    this.populate(this.getCalendar());
    this.showPopup(a)
}

function CP_select(a, c, b) {
    var f = arguments.length > 3 ? arguments[3] : null;
    if (window.getDateFromFormat) if (this.displayType != "date" && this.displayType != "week-end") alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
    else {
        window.parentCaller = a;
        window.CP_calendarObject = this;
        this.currentDate = null;
        var e = 0;
        if (f != null) e = getDateFromFormat(f, b);
        if (f != null) this.currentDate = new Date(e);
        window.CP_dateFormat = b;
        this.showCalendar(c)
    } else alert("calendar.select: To use this method you must also include 'date.js' for date formatting")
}

function getCalendarStyles() {
    var a = "",
        c = "";
    if (this != null && typeof this.cssPrefix != "undefined" && this.cssPrefix != null && this.cssPrefix != "") c = this.cssPrefix;
    a += "<STYLE>\n";
    a += "." + c + "cpYearNavigation,." + c + "cpMonthNavigation { background-color:#C0C0C0; text-align:center; vertical-align:center; text-decoration:none; color:#000000; font-weight:bold; }\n";
    a += "." + c + "cpDayColumnHeader, ." + c + "cpYearNavigation,." + c + "cpMonthNavigation,." + c + "cpCurrentMonthDate,." + c + "cpCurrentMonthDateDisabled,." + c + "cpOtherMonthDate,." + c + "cpOtherMonthDateDisabled,." + c + "cpCurrentDate,." + c + "cpCurrentDateDisabled,." + c + "cpTodayText,." + c + "cpTodayTextDisabled,." + c + "cpText { font-family:arial; font-size:8pt; }\n";
    a += "TD." + c + "cpDayColumnHeader { text-align:right; border:solid thin #C0C0C0;border-width:0px 0px 1px 0px; }\n";
    a += "." + c + "cpCurrentMonthDate, ." + c + "cpOtherMonthDate, ." + c + "cpCurrentDate  { text-align:right; text-decoration:none; }\n";
    a += "." + c + "cpCurrentMonthDateDisabled, ." + c + "cpOtherMonthDateDisabled, ." + c + "cpCurrentDateDisabled { color:#D0D0D0; text-align:right; text-decoration:line-through; }\n";
    a += "." + c + "cpCurrentMonthDate, .cpCurrentDate { color:#000000; }\n";
    a += "." + c + "cpOtherMonthDate { color:#808080; }\n";
    a += "TD." + c + "cpCurrentDate { color:white; background-color: #C0C0C0; border-width:1px; border:solid thin #800000; }\n";
    a += "TD." + c + "cpCurrentDateDisabled { border-width:1px; border:solid thin #FFAAAA; }\n";
    a += "TD." + c + "cpTodayText, TD." + c + "cpTodayTextDisabled { border:solid thin #C0C0C0; border-width:1px 0px 0px 0px;}\n";
    a += "A." + c + "cpTodayText, SPAN." + c + "cpTodayTextDisabled { height:20px; }\n";
    a += "A." + c + "cpTodayText { color:black; }\n";
    a += "." + c + "cpTodayTextDisabled { color:#D0D0D0; }\n";
    a += "." + c + "cpBorder { border:solid thin #808080; }\n";
    a += "</STYLE>\n";
    return a
}

function CP_getCalendar() {
    var a = new Date,
        c = this.type == "WINDOW" ? "window.opener." : "",
        b = "";
    if (this.type == "WINDOW") {
        b += "<HTML><HEAD><TITLE>Calendar</TITLE>" + this.getStyles() + "</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
        b += "<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n"
    } else {
        b += '<TABLE CLASS="' + this.cssPrefix + 'cpBorder" WIDTH=144 BORDER=1 BORDERWIDTH=1 CELLSPACING=0 CELLPADDING=1>\n';
        b += "<TR><TD ALIGN=CENTER>\n";
        b += "<CENTER>\n"
    }
    if (this.displayType == "date" || this.displayType == "week-end") {
        if (this.currentDate == null) this.currentDate = a;
        var f = arguments.length > 0 ? arguments[0] : this.currentDate.getMonth() + 1,
            e = arguments.length > 1 && arguments[1] > 0 && arguments[1] - 0 == arguments[1] ? arguments[1] : this.currentDate.getFullYear(),
            d = Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        if (e % 4 == 0 && e % 100 != 0 || e % 400 == 0) d[2] = 29;
        var p = e,
            m = f,
            k = 1,
            h = (new Date(e, f - 1, 1)).getDay(),
            i = 0;
        i = h >= this.weekStartDay ? h - this.weekStartDay : 7 - this.weekStartDay + h;
        if (i > 0) {
            m--;
            if (m < 1) {
                m = 12;
                p--
            }
            k = d[m] - i + 1
        }
        i = f + 1;
        var g = e;
        if (i > 12) {
            i = 1;
            g++
        }
        var j = f - 1,
            n = e;
        if (j < 1) {
            j = 12;
            n--
        }
        if (this.type != "WINDOW") b += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
        b += "<TR>\n";
        h = c + "CP_refreshCalendar";
        var l = "javascript:" + h;
        if (this.isShowNavigationDropdowns) {
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="78" COLSPAN="3"><select CLASS="' + this.cssPrefix + 'cpMonthNavigation" name="cpMonth" onmouseup="CP_stop(event)" onChange="' + h + "(" + this.index + ",this.options[this.selectedIndex].value-0," + (e - 0) + ');">';
            for (g = 1; g <= 12; g++) {
                i = g == f ? "SELECTED" : "";
                b += '<option value="' + g + '" ' + i + ">" + this.monthNames[g - 1] + "</option>"
            }
            b += "</select></TD>";
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';
            b += '<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="56" COLSPAN="3"><select CLASS="' + this.cssPrefix + 'cpYearNavigation" name="cpYear" onmouseup="CP_stop(event)" onChange="' + h + "(" + this.index + "," + f + ',this.options[this.selectedIndex].value-0);">';
            for (h = e - this.yearSelectStartOffset; h <= e + this.yearSelectStartOffset; h++) {
                i = h == e ? "SELECTED" : "";
                b += '<option value="' + h + '" ' + i + ">" + h + "</option>"
            }
            b += "</select></TD>"
        } else if (this.isShowYearNavigation) {
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="10"><A CLASS="' + this.cssPrefix + 'cpMonthNavigation" HREF="' + l + "(" + this.index + "," + j + "," + n + ');">&lt;</A></TD>';
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="58"><SPAN CLASS="' + this.cssPrefix + 'cpMonthNavigation">' + this.monthNames[f - 1] + "</SPAN></TD>";
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="10"><A CLASS="' + this.cssPrefix + 'cpMonthNavigation" HREF="' + l + "(" + this.index + "," + i + "," + g + ');">&gt;</A></TD>';
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="10">&nbsp;</TD>';
            b += '<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="10"><A CLASS="' + this.cssPrefix + 'cpYearNavigation" HREF="' + l + "(" + this.index + "," + f + "," + (e - 1) + ');">&lt;</A></TD>';
            b += this.isShowYearNavigationInput ? '<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="36"><INPUT NAME="cpYear" CLASS="' + this.cssPrefix + 'cpYearNavigation" SIZE="4" MAXLENGTH="4" VALUE="' + e + '" onBlur="' + h + "(" + this.index + "," + f + ',this.value-0);"></TD>' : '<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="36"><SPAN CLASS="' + this.cssPrefix + 'cpYearNavigation">' + e + "</SPAN></TD>";
            b += '<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="10"><A CLASS="' + this.cssPrefix + 'cpYearNavigation" HREF="' + l + "(" + this.index + "," + f + "," + (e + 1) + ');">&gt;</A></TD>'
        } else {
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="22"><A CLASS="' + this.cssPrefix + 'cpMonthNavigation" HREF="' + l + "(" + this.index + "," + j + "," + n + ');">&laquo;</A></TD>\n';
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="100"><SPAN CLASS="' + this.cssPrefix + 'cpMonthNavigation">' + this.monthNames[f - 1] + " " + e + "</SPAN></TD>\n";
            b += '<TD CLASS="' + this.cssPrefix + 'cpMonthNavigation" WIDTH="22"><A CLASS="' + this.cssPrefix + 'cpMonthNavigation" HREF="' + l + "(" + this.index + "," + i + "," + g + ');">&raquo;</A></TD>\n'
        }
        b += "</TR></TABLE>\n";
        b += "<TABLE WIDTH=120 BORDER=0 CELLSPACING=0 CELLPADDING=1 ALIGN=CENTER>\n";
        b += "<TR>\n";
        for (h = 0; h < 7; h++) b += '<TD CLASS="' + this.cssPrefix + 'cpDayColumnHeader" WIDTH="14%"><SPAN CLASS="' + this.cssPrefix + 'cpDayColumnHeader">' + this.dayHeaders[(this.weekStartDay + h) % 7] + "</TD>\n";
        b += "</TR>\n";
        for (h = 1; h <= 6; h++) {
            b += "<TR>\n";
            for (i = 1; i <= 7; i++) {
                var o = false;
                if (this.disabledDatesExpression != "") {
                    LZ(m);
                    LZ(k);
                    eval("disabled=(" + this.disabledDatesExpression + ")")
                }
                g = "";
                g = m == this.currentDate.getMonth() + 1 && k == this.currentDate.getDate() && p == this.currentDate.getFullYear() ? "cpCurrentDate" : m == f ? "cpCurrentMonthDate" : "cpOtherMonthDate";
                if (o || this.disabledWeekDays[i - 1]) b += '\t<TD CLASS="' + this.cssPrefix + g + '"><SPAN CLASS="' + this.cssPrefix + g + 'Disabled">' + k + "</SPAN></TD>\n";
                else {
                    l = k;
                    j = m;
                    n = p;
                    if (this.displayType == "week-end") {
                        l = new Date(n, j - 1, l, 0, 0, 0, 0);
                        l.setDate(l.getDate() + (7 - i));
                        n = l.getYear();
                        if (n < 1E3) n += 1900;
                        j = l.getMonth() + 1;
                        l = l.getDate()
                    }
                    b += '\t<TD CLASS="' + this.cssPrefix + g + '"><A HREF="javascript:' + c + this.returnFunction + "(" + n + "," + j + "," + l + ");" + c + "CP_hideCalendar('" + this.index + '\');" CLASS="' + this.cssPrefix + g + '">' + k + "</A></TD>\n"
                }
                k++;
                if (k > d[m]) {
                    k = 1;
                    m++
                }
                if (m > 12) {
                    m = 1;
                    p++
                }
            }
            b += "</TR>"
        }
        f = a.getDay() - this.weekStartDay;
        if (f < 0) f += 7;
        b += "<TR>\n";
        b += '\t<TD COLSPAN=7 ALIGN=CENTER CLASS="' + this.cssPrefix + 'cpTodayText">\n';
        if (this.disabledDatesExpression != "") {
            a.getFullYear();
            LZ(a.getMonth() + 1);
            LZ(a.getDate());
            eval("disabled=(" + this.disabledDatesExpression + ")")
        }
        b += o || this.disabledWeekDays[f + 1] ? '\t\t<SPAN CLASS="' + this.cssPrefix + 'cpTodayTextDisabled">' + this.todayText + "</SPAN>\n" : '\t\t<A CLASS="' + this.cssPrefix + 'cpTodayText" HREF="javascript:' + c + this.returnFunction + "('" + a.getFullYear() + "','" + (a.getMonth() + 1) + "','" + a.getDate() + "');" + c + "CP_hideCalendar('" + this.index + "');\">" + this.todayText + "</A>\n";
        b += "\t\t<BR>\n";
        b += "\t</TD></TR></TABLE></CENTER></TD></TR></TABLE>\n"
    }
    if (this.displayType == "month" || this.displayType == "quarter" || this.displayType == "year") {
        e = arguments.length > 0 ? arguments[0] : this.displayType == "year" ? a.getFullYear() - this.yearSelectStartOffset : a.getFullYear();
        if (this.displayType != "year" && this.isShowYearNavigation) {
            b += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
            b += "<TR>\n";
            b += '\t<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="22"><A CLASS="' + this.cssPrefix + 'cpYearNavigation" HREF="javascript:' + c + "CP_refreshCalendar(" + this.index + "," + (e - 1) + ');">&laquo;</A></TD>\n';
            b += '\t<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="100">' + e + "</TD>\n";
            b += '\t<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="22"><A CLASS="' + this.cssPrefix + 'cpYearNavigation" HREF="javascript:' + c + "CP_refreshCalendar(" + this.index + "," + (e + 1) + ');">&raquo;</A></TD>\n';
            b += "</TR></TABLE>\n"
        }
    }
    if (this.displayType == "month") {
        b += "<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n";
        for (a = 0; a < 4; a++) {
            b += "<TR>";
            for (h = 0; h < 3; h++) {
                o = a * 3 + h;
                b += '<TD WIDTH=33% ALIGN=CENTER><A CLASS="' + this.cssPrefix + 'cpText" HREF="javascript:' + c + this.returnMonthFunction + "(" + e + "," + (o + 1) + ");" + c + "CP_hideCalendar('" + this.index + '\');" CLASS="undefined">' + this.monthAbbreviations[o] + "</A></TD>"
            }
            b += "</TR>"
        }
        b += "</TABLE></CENTER></TD></TR></TABLE>\n"
    }
    if (this.displayType == "quarter") {
        b += "<BR><TABLE WIDTH=120 BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n";
        for (a = 0; a < 2; a++) {
            b += "<TR>";
            for (h = 0; h < 2; h++) {
                o = a * 2 + h + 1;
                b += '<TD WIDTH=50% ALIGN=CENTER><BR><A CLASS="' + this.cssPrefix + 'cpText" HREF="javascript:' + c + this.returnQuarterFunction + "(" + e + "," + o + ");" + c + "CP_hideCalendar('" + this.index + '\');" CLASS="undefined">Q' + o + "</A><BR><BR></TD>"
            }
            b += "</TR>"
        }
        b += "</TABLE></CENTER></TD></TR></TABLE>\n"
    }
    if (this.displayType == "year") {
        b += "<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>";
        b += "<TR>\n";
        b += '\t<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="50%"><A CLASS="' + this.cssPrefix + 'cpYearNavigation" HREF="javascript:' + c + "CP_refreshCalendar(" + this.index + "," + (e - 8) + ');">&laquo;</A></TD>\n';
        b += '\t<TD CLASS="' + this.cssPrefix + 'cpYearNavigation" WIDTH="50%"><A CLASS="' + this.cssPrefix + 'cpYearNavigation" HREF="javascript:' + c + "CP_refreshCalendar(" + this.index + "," + (e + 8) + ');">&raquo;</A></TD>\n';
        b += "</TR></TABLE>\n";
        b += "<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n";
        for (a = 0; a < 4; a++) {
            for (h = 0; h < 2; h++) {
                o = e + h * 4 + a;
                b += '<TD WIDTH=50% ALIGN=CENTER><A CLASS="' + this.cssPrefix + 'cpText" HREF="javascript:' + c + this.returnYearFunction + "(" + o + ");" + c + "CP_hideCalendar('" + this.index + '\');" CLASS="undefined">' + o + "</A></TD>"
            }
            b += "</TR>"
        }
        b += "</TABLE></CENTER></TD></TR></TABLE>\n"
    }
    if (this.type == "WINDOW") b += "</BODY></HTML>\n";
    return b
};
