var basicDatePickerCulture_en_US = {monthNames:new Array("January","February","March","April","May","June","July","August","September","October","November","December"), monthNamesAbbr:new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"), dayNames:new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"), dayNamesAbbr:new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"), firstDayOfWeek:0};
var dateParams = {xOffset:0,yOffset:-1,dateFormat:"Default",otherMonthDayWeekendDayStyle:"",otherMonthDayWeekendDayStyleCssClass:"onuscOtherMonthDay onuscWeekendDay onuscDay",selectedDayTodayDayStyle:"",selectedDayTodayDayStyleCssClass:"onuscTodayDay onuscSelectedDay onuscDay",selectedDayWeekendDayStyle:"",selectedDayWeekendDayStyleCssClass:"onuscSelectedDay onuscWeekendDay onuscDay",todayDayWeekendDayStyle:"",todayDayWeekendDayStyleCssClass:"onuscTodayDay onuscWeekendDay onuscDay",dateFormat:"M/d/yyyy",firstDayOfWeek:"Sunday",nextMonthImageUrl:"images/arrow_right.gif",prevMonthImageUrl:"images/arrow_left.gif",culture:"basicDatePickerCulture_en_US"};
var onusCal;

function onusCalButtonElementClick(b, v, l, params, stayOpen) {
    if (!onusCal) {onusCal = new OnusCal();}
    
    onusCal.stayOpen = stayOpen;
    onusCal.showPopUp(b, v, l, params);
}

OnusCal = function(suppressInit) {
    if (!suppressInit) this.init();
    var today = new Date();
    
    this.todayDate = today.getDate();
    this.todayMonth = today.getMonth();
    this.todayYear = today.getFullYear();
    this.dateCounts = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    this.viewingYear;
    this.viewingMonth;
    this.selectedYear;
    this.selectedMonth;
    this.selectedDay;
    this.buttonElement;
    this.valueElement;
    this.yearInc;
    this.params;
    this.timeout;
    this.interval;
    this.popUp;
    this.popUpShim;
    this.stayOpen = false;
    this.isIE;
    this.isIEWin;
    this.isOpera;
    this.isSafari;
    this.isNS6;
    this.isIEMac;
};

OnusCal.prototype.init = function() {
    var ua = navigator.userAgent.toLowerCase();
    var isMac = (ua.indexOf("mac") != -1);
    this.isIE = (ua.indexOf("ie") != -1);
    this.isOpera = (ua.indexOf("opera") != -1);
    this.isSafari = (ua.indexOf("safari") != -1);
    this.isNS6 = (ua.indexOf("netscape6/") != -1);
    this.isIEWin = (this.isIE && !isMac && !this.isOpera);
    this.isIEMac = (this.isIE && isMac && !this.isOpera);
};

OnusCal.prototype.showPopUp = function(buttonElement, valueElement, labelElement, params) {
    this.inputFocusValue = valueElement.value;
    
    if (this.params != null && (this.params != params)) {
        this.hidePopUp();
    }
    else if (this.params == params && this.buttonElement == buttonElement && this.valueElement == valueElement) {
        this.hidePopUp();
        return false;
    }
    
    this.buttonElement = buttonElement;
    this.valueElement = valueElement;
    this.params = this.loadParams(params);
    
    if (!this.popUp) {
        this.popUp = document.createElement("DIV");
        
        with (this.popUp) {
            id = "onusCalPopUp";
            style.position = "absolute";
            style.visibility = "hidden";
            style.zIndex = "1000";
        }
        
        this.popUp.onclick = this.ehPopUpClick;
        document.body.appendChild(this.popUp);
    }
    
    this.parseDate(this.valueElement.value);
    this.buildCalendar();
    
    var buttonPosition = this.findPosition(this.buttonElement);
    var leftPosition = this.params.xOffset + buttonPosition.x;
    var topPosition = this.params.yOffset + buttonPosition.y;
    this.popUp.style.left = (leftPosition + this.buttonElement.offsetWidth - this.popUp.offsetWidth) + "px";
    this.popUp.style.top = (topPosition + this.buttonElement.offsetHeight) + "px";
    
    if (parseInt(this.popUp.style.left) < 0) {
        this.popUp.style.left = 0;
    }
    
    if (parseInt(this.popUp.style.top) < 0) {
        this.popUp.style.top = 0;
    }
    
    this.popUpShim = this.showShim(this.popUpShim, this.popUp);
    this.popUp.style.visibility = "visible";
    document.onclick = this.ehDocumentClick;
    document.onkeydown = this.ehKeyPress;
};

OnusCal.prototype.showShim = function(v, o) {
    if (this.isIEWin) {
        if (!v) {
            v = document.createElement("IFRAME");
            with (v) {
                src = "javascript:false;";
                style.position = "absolute";
                style.visibility = "hidden";
                style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
            }
            document.body.appendChild(v);
        }
        
        with (v) {
            style.width = o.offsetWidth;
            style.height = o.offsetHeight;
            style.top = o.style.top;
            style.left = o.style.left;
            style.zIndex = o.style.zIndex - 1;
            style.visibility = "visible";
        }
    }
    
    return v;
};

OnusCal.prototype.hideShim = function(v) {
    if (this.isIEWin) {
        if (v) {
            v.style.visibility = "hidden";
        }
    }
};

OnusCal.prototype.hidePopUp = function() {
    onusCal.clearTimers();
    this.hideShim(this.popUpShim);
    this.popUp.style.visibility = "hidden";
    this.reset();
    document.onclick = null;
    document.onkeydown = null;
};

OnusCal.prototype.clearTimers = function() {
    if (this.timeout) {
        clearTimeout(this.timeout);
    }
    if(this.interval) {
        clearInterval(this.interval);
    }
};

OnusCal.prototype.buildCalendar = function() {
    if (this.viewingMonth == null || this.viewingYear == null) {
        (this.params.visibleDate) ? this.viewingMonth = this.params.visibleDate.getMonth() : this.viewingMonth = this.todayMonth;
        (this.params.visibleDate) ? this.viewingYear = this.params.visibleDate.getFullYear() : this.viewingYear = this.todayYear;
    }
    /* previous/next month */
    var viewingPrevMonth = this.viewingMonth - 1;
    var viewingPrevMonthYear = this.viewingYear;
    
    if (viewingPrevMonth == -1) {
        viewingPrevMonth = 11;
        viewingPrevMonthYear--;
    }
    
    var viewingNextMonth = this.viewingMonth + 1;
    var viewingNextMonthYear = this.viewingYear;
    
    if (viewingNextMonth == 12) {
        viewingNextMonth = 0;
        viewingNextMonthYear++;
    }
    
    var o = "";
    o += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"onuscPopUp\">";
    o += "<tr><td>";
    o += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"onuscTitle\">";
    o += "<tr>";
    
    var monthAndYear = "<th>";
    var monthName = this.params.culture.monthNames[this.viewingMonth];
    
    monthAndYear += monthName;
    monthAndYear += " ";
    monthAndYear += this.viewingYear;
    monthAndYear += "</th>";
    
    var prevMonth = "<img src=\"" + this.params.prevMonthImageUrl + "\" border=\"0\" />";
    var nextMonth = "<img src=\"" + this.params.nextMonthImageUrl + "\" border=\"0\" />";
    
    o += "<td onclick=\"onusCal.viewPrevMonth()\" onmousedown=\"onusCal.clearTimers();onusCal.timeout=setTimeout('onusCal.ehPrevMonthMouseDown()', 400);\" onmouseup=\"onusCal.clearTimers();\" onmouseout=\"onusCal.clearTimers();\" class=\"onuscNextPrev\">";
    o += prevMonth;
    o += "</td>";
    o += monthAndYear;
    o += "<td onclick=\"onusCal.viewNextMonth()\" onmousedown=\"onusCal.clearTimers();onusCal.timeout=setTimeout('onusCal.ehNextMonthMouseDown()', 400);\" onmouseup=\"onusCal.clearTimers();\" onmouseout=\"onusCal.clearTimers();\" class=\"onuscNextPrev\">";
    o += nextMonth;
    o += "</td>";
    o += "</tr>";
    o += "</table>";
    
    /* leap year check */
    if (((this.viewingYear % 4 == 0) && (this.viewingYear % 100 != 0)) || (this.viewingYear % 400 == 0)) {
        this.dateCounts[1] = 29;
    }
    else {
        this.dateCounts[1] = 28;
    }
    
    /* calendar table */
    o += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"onuscCalendar\">";
    
    /* week number header */
    o += "<thead><tr>";
    
    /* day of week headers */
    var dayPointer = this.params.firstDayOfWeek;
    for (var i=0; i<7; i++, dayPointer++) {
        if (dayPointer == 7) {
            dayPointer = 0;
        }
        o += "<th class=\"onuscDayHeader\">";
        
        switch (this.params.dayNameFormat) {
            case "Short":
                o += this.params.culture.dayNamesAbbr[dayPointer];
                break;
            case "Full":
                o += this.params.culture.dayNames[dayPointer];
                break;
            case "FirstTwoLetters":
                o += this.params.culture.dayNames[dayPointer].substring(0,2);
                break;
            case "FirstLetter":
            default:
                o += this.params.culture.dayNames[dayPointer].substring(0,1);
                break;
        }
        
        o += "</th>";
    }
    
    o += "</tr></thead>";
    o += "<tbody><tr>";
    
    var column = 0;
    var startOfMonth = new Date(this.viewingYear,this.viewingMonth,1).getDay();
    startOfMonth = startOfMonth - this.params.firstDayOfWeek;
    
    if (startOfMonth < 0) {
        startOfMonth = 7 + startOfMonth;
    }
    
    /* prev month days */
    for (var i=0; i<startOfMonth; i++, column++) {
        o += this.buildDayCell(viewingPrevMonthYear, viewingPrevMonth, this.dateCounts[viewingPrevMonth] - startOfMonth + i + 1, "prev");
    }
        
    var row = 0;
    
    /* month days */
    for (var i=1; i<=this.dateCounts[this.viewingMonth]; i++, column++) {
        o += this.buildDayCell(this.viewingYear, this.viewingMonth, i, "current");
        if (column == 6) {
            if (i < this.dateCounts[this.viewingMonth]) {
                o += "</tr><tr>";
                row++;
                column = -1;
            }
        }
    }
    
    /* next month days */
    if (column > 0) {
        for (var i=1; column<7; i++, column++) {
            o += this.buildDayCell(viewingNextMonthYear, viewingNextMonth, i, "next");
        }
    }
    
    /* insure 6th row */
    for (var y = row; y < 5; y++) {
        o += "</tr><tr>";
        for (var x=0; x < 7; x++, i++) {
            o += this.buildDayCell(viewingNextMonthYear, viewingNextMonth, i, "next");
        }
    }
    
    o += "</tr></tbody>";
    o += "</table>";
    o += "</td></tr>";
    o += "</table>";
    
    this.popUp.innerHTML = o;
};

OnusCal.prototype.buildDayCell = function(y, m, d, type) {
    var curDate = new Date(y, m, d);
    var dayOfWeek = curDate.getDay(), dayClassName = "";
    var isWeekDay = (dayOfWeek != 0 && dayOfWeek != 6);
    var styleCssClassToUse = null;
    
    switch(type) {
        case "current":
            var isSelectedDay = (this.selectedYear == y && this.selectedMonth == m && this.selectedDay == d);
            var isTodayDay = (this.viewingYear == this.todayYear && this.viewingMonth == this.todayMonth && this.todayDate == d);
            
            if (isSelectedDay && isTodayDay) {
                if (isWeekDay) {
                    styleCssClassToUse = "onuscTodayDay onuscSelectedDay onuscDay";
                }
                else {
                    styleCssClassToUse = "onuscSelectedDay onuscWeekendDay onuscDay";
                }
            }
            else if (isSelectedDay) {
                if (isWeekDay) {
                    styleCssClassToUse = "onuscSelectedDay onuscDay";
                }
                else {
                    styleCssClassToUse = "onuscSelectedDay onuscWeekendDay onuscDay";
                }
            }
            else if (isTodayDay) {
                if (isWeekDay) {
                    styleCssClassToUse = "onuscTodayDay onuscDay";
                }
                else {
                    styleCssClassToUse = "onuscTodayDay onuscWeekendDay onuscDay";
                }
            }
            else {
                if (isWeekDay) {
                    styleCssClassToUse = "onuscDay";
                }
                else {
                    styleCssClassToUse = "onuscWeekendDay onuscDay";
                }
            }
            break;
        case "prev":
        case "next":
            if (isWeekDay) {
                styleCssClassToUse = "onuscOtherMonthDay onuscDay";
            }
            else {
                styleCssClassToUse = "onuscOtherMonthDay onuscWeekendDay onuscDay";
            }
            break;
    }
    
    var o = "";
    o += "<td class=\"" + styleCssClassToUse + "\"";
    var statusText = this.formatDate(curDate);
    
    o += " onmouseover=\"window.status = '" + statusText + "';return true;\"";
    o += " onmouseout=\"window.status = '';return true;\"";
    o += ">";
    
    var onClick = "onusCal.selectDate(" + this.viewingYear + "," + this.viewingMonth + "," + d + ", true)";
    
    if (type == "prev" || type == "next") {
        onClick = "onusCal.selectDate(" + y + "," + m + "," + d + ", true)";
    }
    onClick = onClick + ";";
    o += "<a href=\"javascript:void(0);\" onclick=\"" + onClick.replace("{0}",d) + "\">" + d + "</a>";
    o += "</td>";
    return o;
};

OnusCal.prototype.findPosition = function(eElement, stopElement) {
    var pLeft = 0, pTop = 0;
    var org = eElement;
    
    while (eElement) {
        var aLeft = (eElement.scrollLeft && !this.isOpera) ? eElement.offsetLeft-eElement.scrollLeft : eElement.offsetLeft;
        var standardsMode = (document.compatMode && document.compatMode != "BackCompat") ? true : false;
        
        if (standardsMode && aLeft < 0) {
            aLeft += aLeft *-1;
        }
        pLeft += aLeft;
        
        var aTop = (eElement.scrollTop && !this.isOpera) ? eElement.offsetTop-eElement.scrollTop : eElement.offsetTop;
        
        if (standardsMode && aTop < 0) {
            aTop += aTop *-1;
        }
        
        pTop += aTop;
        eElement = eElement.offsetParent;
        
        if (eElement == stopElement) {
            break;
        }
    }
    
    if (stopElement == null) {
        if (!document.all) {
            while (org) {
                if (org.scrollLeft) {pLeft -= org.scrollLeft;}
                if (org.scrollTop) {pTop -= org.scrollTop;}
                org = org.parentNode;
            }
            if (self.pageYOffset && !this.isNS6) {
                pLeft += self.pageXOffset;
                pTop += self.pageYOffset;
            }
        }
        if (!this.isOpera && !this.isNS6) {
            pLeft += document.body.scrollLeft;
            pTop += document.body.scrollTop;
        }
        if (this.isIEMac) {
            var mmLeft = document.body.currentStyle.marginLeft;
            var mmTop = document.body.currentStyle.marginTop;
            
            if (mmLeft.indexOf("%") != -1) {
                var mpWidth = parseInt(document.body.offsetWidth);
                var mpHeight = parseInt(document.body.offsetHeight);
                mmLeft = (parseInt(mmLeft)/100) * mpWidth;
                mmTop = (parseInt(mmTop)/100) * mpHeight;
            }
            pLeft += parseInt(mmLeft);
            pTop += parseInt(mmTop);
        }
    }
    return {x:pLeft, y:pTop};
};

OnusCal.prototype.viewNextMonth = function() {
    var nextMonth = this.viewingMonth + 1;
    var nextMonthYear = this.viewingYear;
    
    if (nextMonth > 11) {
        nextMonth = 0;
        nextMonthYear++;
    }
    
    this.viewingMonth = nextMonth;
    this.viewingYear = nextMonthYear;
    this.buildCalendar();
};

OnusCal.prototype.viewPrevMonth = function() {
    var prevMonth = this.viewingMonth - 1;
    var prevMonthYear = this.viewingYear;
    
    if (prevMonth < 0) {
        prevMonth = 11;
        prevMonthYear--;
    }
    
    this.viewingMonth = prevMonth;
    this.viewingYear = prevMonthYear;
    this.buildCalendar();
};

OnusCal.prototype.clearSelectedDate = function() {
    var prevFormattedDate = this.valueElement.value;
    
    if (prevFormattedDate != this.params.nullDateText) {
        this.valueElement.value = this.params.nullDateText;
        this.clearDate = false;
        
        if (this.params.autoPostBack) {
            if (onusCal.parseDate(onusCal.valueElement.value) != null) {
                eval(this.params.postBackFunction);
            }
        }
    }
    
    if (this.valueElement.style.display != "none" && !this.valueElement.disabled) {this.valueElement.focus();}
    
    this.hidePopUp();
};

OnusCal.prototype.selectDate = function(y, m, d, hide) {
    this.selectedYear = y, this.selectedMonth = m, this.selectedDay = d;
    this.viewingYear = y, this.viewingMonth = m;
    
    var prevFormattedDate = this.valueElement.value;
    var formattedDate = this.formatDate(new Date(this.selectedYear, this.selectedMonth, this.selectedDay));
    
    if (prevFormattedDate != formattedDate) {
        this.valueElement.value = formattedDate;
        this.clearTimers();
        
        if (this.params.autoPostBack && hide) {
            eval(this.params.postBackFunction);
        }
        
        if (this.valueElement.style.display != "none" && !this.valueElement.disabled) {
            this.valueElement.focus();
        }
    }
    
    if (hide) {
        this.hidePopUp();
    }
};

OnusCal.prototype.padWithZero = function(num) {
    return (num < 10) ? "0" + num : num;
};

OnusCal.prototype.trim = function(string) {
    while ((string.substring(0,1) == ' ') || (string.substring(0,1) == '\n') || (string.substring(0,1) == '\r')) {
        string = string.substring(1,string.length);
    }
    while ((string.substring(string.length-1,string.length) == ' ') || (string.substring(string.length-1,string.length) == '\n') || (string.substring(string.length-1,string.length) == '\r')) {
        string = string.substring(0,string.length-1);
    }
    return string;
};

/* Date Formatting / Parsing ---------------------------------------- */
OnusCal.prototype.formatDate = function(date) {
    if (date) {
        var y = date.getFullYear(), m = date.getMonth(), d = date.getDate(), dow = date.getDay();
        var finalDate = this.params.dateFormat;
        
        finalDate = finalDate.replace("yyyy",y);
        finalDate = finalDate.replace("yy",this.padWithZero(y%100));
        finalDate = finalDate.replace("dddd","{0}");
        finalDate = finalDate.replace("ddd","{1}");
        finalDate = finalDate.replace("dd","{2}");
        finalDate = finalDate.replace("d","{3}");
        finalDate = finalDate.replace("MMMM","{4}");
        finalDate = finalDate.replace("MMM","{5}");
        finalDate = finalDate.replace("MM","{6}");
        finalDate = finalDate.replace("M","{7}");
        finalDate = finalDate.replace("{0}",this.params.culture.dayNames[dow]);
        finalDate = finalDate.replace("{1}",this.params.culture.dayNamesAbbr[dow]);
        finalDate = finalDate.replace("{2}",this.padWithZero(d));
        finalDate = finalDate.replace("{3}",d);
        finalDate = finalDate.replace("{4}",this.params.culture.monthNames[m]);
        finalDate = finalDate.replace("{5}",this.params.culture.monthNamesAbbr[m]);
        finalDate = finalDate.replace("{6}",this.padWithZero(m+1));
        finalDate = finalDate.replace("{7}",m+1);
        
        return finalDate;
    }
    else {
        return null;
    }
};

OnusCal.prototype.parseDate = function(valueString) {
    if (valueString && valueString != this.params.nullDateText) {
        var format = this.params.dateFormat;
        var i_value = 0, i_format = 0;
        var c, token;
        var x,y;
        var year = null, month = null, date = null;
        
        while (i_format < format.length) {
            /* get next token from format string */
            c = format.charAt(i_format);
            token = "";
            
            while ((format.charAt(i_format) == c) && (i_format < format.length)) {
                token += format.charAt(i_format++);
            }
            
            switch (token) {
                case "d":
                case "dd":
                    date = this.getInt(valueString, i_value, token.length, 2);
                    if (!date) {
                        return null;
                    }
                    
                    i_value += date.length;
                    date = this.parsePaddedInt(date);
                    break;
                case "ddd":
                    for (var i=0; i<this.params.culture.dayNamesAbbr.length; i++) {
                        var dayName = this.params.culture.dayNamesAbbr[i];
                        
                        if (valueString.substring(i_value,i_value+dayName.length).toLowerCase() == dayName.toLowerCase()) {
                            i_value += dayName.length;
                            break;
                        }
                    }
                    break;
                case "dddd":
                    for (var i=0; i<this.params.culture.dayNames.length; i++) {
                        var dayName = this.params.culture.dayNames[i];
                        
                        if (valueString.substring(i_value,i_value+dayName.length).toLowerCase() == dayName.toLowerCase()) {
                            i_value += dayName.length;
                            break;
                        }
                    }
                    break;
                case "M":
                case "MM":
                    month = this.getInt(valueString,i_value,token.length,2);
                    
                    if (!month) {
                        return null;
                    }
                                        
                    i_value += month.length;
                    month = this.parsePaddedInt(month)-1;
                    break;
                case "MMM":
                    for (var i=0; i<this.params.culture.monthNamesAbbr.length; i++) {
                        var monthName = this.params.culture.monthNamesAbbr[i];
                        
                        if (valueString.substring(i_value,i_value+monthName.length).toLowerCase() == monthName.toLowerCase()) {
                            month = i;
                            i_value += monthName.length;
                            break;
                        }
                    }
                    break;
                case "MMMM":
                    for (var i=0; i<this.params.culture.monthNames.length; i++) {
                        var monthName = this.params.culture.monthNames[i];
                        
                        if (valueString.substring(i_value,i_value+monthName.length).toLowerCase() == monthName.toLowerCase()) {
                            month = i;
                            i_value += monthName.length;
                            break;
                        }
                    }
                    break;
                case "yy":
                case "yyyy":
                    if (token == "yyyy") {
                        x = 1;
                        y = 4;
                    }
                    
                    if(token == "yy") {
                        x = 2;
                        y = 2;
                    }
                    
                    year = this.getInt(valueString, i_value, x, y);
                    
                    if (year != null) {
                        i_value += year.length;
                        
                        if (year.length==2) {
                            if (year > 50) {
                                year = 1900 + (year-0);
                            }
                            else {
                                year = 2000 + (year-0);
                            }
                        }
                    }
                    break;
                default:
                    i_value += token.length;
            }
        }
        
        if (date == null || month == null || year == null || isNaN(date) || isNaN(month) || isNaN(year)) {
            return null;
        }
        else {
            this.selectDate(year, month, date);
            return new Date(year, month, date);
        }
    }
    else {
        return null;
    }
};

OnusCal.prototype.isInteger = function(val) {
    var digits="1234567890";
    
    for (var i=0; i < val.length; i++) {
        if (digits.indexOf(val.charAt(i))==-1) {
            return false;
        }
    }
    return true;
};

OnusCal.prototype.getInt = function(str,i,minlength,maxlength) {
    for (var x=maxlength; x>=minlength; x--) {
        var valuePart = str.substring(i, i + x);
        
        if (valuePart.length < minlength) {
            return null;
        }
        if (this.isInteger(valuePart)) {
            for (var y=0; y<valuePart.length; y++) {
                if (valuePart.charAt(y) != "0") {
                    return valuePart;
                }
                else {
                    break;
                }
            }
        }
    }
    return null;
};

OnusCal.prototype.parsePaddedInt = function(valuePart) {
    if (valuePart.length > 1 && valuePart.substring(0,1) == "0") {
        return valuePart.substring(1, valuePart.length);
    }
    else {
        return valuePart;
    }
};

/* Event Handlers -------------------------------------------------------------- */
OnusCal.prototype.ehKeyPress = function(e) {
    if(!e) {
        e = window.event;
    }
    if(e.keyCode == 9) {
        onusCal.hidePopUp();
    }
};

OnusCal.prototype.ehPopUpClick = function(e) {
    onusCal.stayOpen = true;
};

OnusCal.prototype.ehDocumentClick = function() {
    if (!onusCal.stayOpen) {
        onusCal.hidePopUp();
    }
    else {
        onusCal.stayOpen = false;
    }
};

OnusCal.prototype.ehPrevMonthMouseDown = function() {
    onusCal.interval = setInterval("onusCal.viewPrevMonth()",200);
};

OnusCal.prototype.ehNextMonthMouseDown = function() {
    onusCal.interval = setInterval("onusCal.viewNextMonth()",200);
};

OnusCal.prototype.ehFocus = function(valueElement) {
    this.inputFocusValue = valueElement.value;
};

OnusCal.prototype.ehBlur = function(buttonElement, valueElement, params) {
    if (onusCal) {
    onusCal.buttonElement = buttonElement;
    onusCal.valueElement = valueElement;
    onusCal.params = onusCal.loadParams(params);
    
    if (onusCal.valueElement.value != onusCal.inputFocusValue) {
        if (onusCal.params.autoPostBack) {
            if (onusCal.parseDate(onusCal.valueElement.value) != null) {
                eval(onusCal.params.postBackFunction);
            }
            else {
                alert("Please enter a valid date.");
                onusCal.valueElement.focus();
            }
        }
    }
    onusCal.reset();
    }
};

OnusCal.prototype.reset = function() {
    this.selectedMonth = null;
    this.selectedDay = null;
    this.selectedYear = null;
    this.viewingMonth = null;
    this.viewingYear = null;
    this.params = null;
};

OnusCal.prototype.loadParams = function(params) {
    params.culture = eval(params.culture);
    params.firstDayOfWeek = params.culture.firstDayOfWeek;
    return params;
};

/* (Public) Helper Methods ----------------------------------------------------- */
OnusCal.prototype.getSelectedDate = function(bdplId) {
    var bdpltu = (bdplId) ? OnusCalLoadControl(bdplId) : this;
    
    return bdpltu.parseDate(bdpltu.valueElement.value)
};

function OnusCalLoadControl(bdplId) {
    var bdpl = new OnusCal(true);
    bdpl.params = bdpl.loadParams(eval(bdplId + "Params"));
    bdpl.valueElement = document.getElementById(bdplId + "_textBox");
    bdpl.buttonElement =  document.getElementById(bdplId + "_image");
    return bdpl;
};