/**
 * NlsCalendar Pro 1.0
 * Copyright 2005-2007, addobject.com. All Rights Reserved
 * Author Jack Hermanto, www.addobject.com
 */
AOCAL.showXY = function (x, y) {
    ao$show(this, "dts");
    var oC = $aoGE(this.cId).style;
    if (x) oC.left = x + "px";
    if (y) oC.top = y + "px";
    oC.visibility = "visible";
    oC.display = ""
};
AOCAL.show = function (dir, elm, ctl, f, dl) {
    if (this.onShow(elm) == false) return;
    this.bindControl(ctl, f, (dl ? dl : "\n"));
    var l = 0,
        t = 0,
        w = elm.offsetWidth,
        h = elm.offsetHeight,
        tmp = elm;
    while (tmp) {
        l += tmp.offsetLeft;
        t += tmp.offsetTop;
        tmp = tmp.offsetParent
    }
    switch (dir) {
    case "NE":
        this.showXY(l + w, t - this.rt.cH + h);
        break;
    case "NW":
        this.showXY(l - this.rt.cW, t - this.rt.cH + h);
        break;
    case "SW":
        this.showXY(l - this.rt.cW, t);
        break;
    default:
        this.showXY(l + w, t);
    }
};
AOCAL.bindControl = function (ctl, f, dl) {
    var c = this,
        o = c.opt;
    if (ctl) {
        var dtCtl = $aoGE(ctl),
            fmt = (f ? f : o.dtFormat);
        c.rt.dtCtl = dtCtl;
        var fn = function () {
            c.rt.dtCtl.value = AOCalendar.formatSelDates(c, dl, fmt);
        };
        if (!o.autoClose && o.autoUpdate) c.$onChange = fn;
        else c.$onSelect = fn;
        if (dtCtl.value != "") {
            if (this.opt.multiSel) {
                this.clearSelections();
                var dv = dtCtl.value.split(dl);
                for (var i = 0; i < dv.length; i++) {
                    dt = AOCalendar.parseDate(dv[i], fmt);
                    c.addSelection(dt);
                }
            } else {
                c.setDate(AOCalendar.parseDate(dtCtl.value, fmt));
            }
        }
    }
};
AOCAL.hide = function () {
    $aoGE(this.cId).style.display = "none";
    this.onHide();
};
