////---------------------滚动条适配------------------------- 
(function($) {
    var updateWindow = function() {//alert(1)
        var friendsInfo = $(".linkman");
        if (friendsInfo.attr("class") != undefined) {
            var leftPage = $(".side_bar");
            var leftLastWinHeight = $(document).height();
            leftPage.height(leftLastWinHeight - 44);
            friendsInfo.height(leftPage.height() - 6);
        }
        var viewInfo = $(".his_chat");
        if (viewInfo.attr("class") != undefined) {
            var rightPage = $(".his_ct_m");
            var rightLastWinHeight = $(document).height();
            if (rightLastWinHeight != 100) {//361+30+44=435 406   29
                rightPage.height(rightLastWinHeight - 70 - 37);
                viewInfo.height(rightPage.height() - 20);
                var paging = $(".paging");
                paging.css("top", (rightLastWinHeight - 70) + "px");
            }
        }
    }
    updateWindow();
    $(window).bind("resize", function() {
        updateWindow();
    });
})(jQuery);

$(document).ready(function() {
    //fxInter.InitLoad();
    // 禁止右键
    //    $(document).bind("contextmenu", function () {
    //        return false;
    //    });
    var ctrlKey = false;  //  是否按下ctrl键
    //禁止F5刷新
    document.onkeydown = function(e) {
        e = e || event;
        if (e.keyCode == 116) {

            e.keyCode = 0;
            e.cancelBubble = true;

            return false;
        }

        if (ctrlKey && e.keyCode == 67) {
            var range = document.selection.createRange();
            //alert(range.htmlText);
            //                alert(range.text);
            //                window.clipboardData.setData('Text',range.text+"123");
        }

        if (e.ctrlKey) {
            ctrlKey = true;
        }
    };
    document.onkeyup = function(e) {
        e = e || event;
        if (e.ctrlKey) {
            ctrlKey = false;
        }
    };

    String.prototype.replaceAll = function(s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
    };
    String.prototype.endWith = function(str) {
        if (str == null || str == "" || this.length == 0 || str.length > this.length)
            return false;
        if (this.substring(this.length - str.length) == str)
            return true;
        else
            return false;
        return true;
    };
    //setEnableDatesFun(["2013-11-13", "2013-11-14", "2013-11-15", "2013-11-16", "2013-11-17"]);
    //$('.text_2').datePicker({ clickInput: true });
});

////---------------------滚动条结束-------------------------日期函数开始---------------------

Date.dayNames = ['日', '一', '二', '三', '四', '五', '六'];

Date.abbrDayNames = ['日', '一', '二', '三', '四', '五', '六'];

Date.monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];

Date.abbrMonthNames = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];

Date.firstDayOfWeek = 0;

Date.format = 'yyyy-mm-dd';

Date.fullYearStart = '20';

(function() {

    function add(name, method) {
        if (!Date.prototype[name]) {
            Date.prototype[name] = method;
        }
    };

    add("isLeapYear", function() {
        var y = this.getFullYear();
        return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
    });

    add("isWeekend", function() {
        return this.getDay() == 0 || this.getDay() == 6;
    });

    add("isWeekDay", function() {
        return !this.isWeekend();
    });

    add("getDaysInMonth", function() {
        return [31, (this.isLeapYear() ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()];
    });

    add("getDayName", function(abbreviated) {
        return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
    });

    add("getMonthName", function(abbreviated) {
        return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
    });

    add("getDayOfYear", function() {
        var tmpdtm = new Date("1/1/" + this.getFullYear());
        return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
    });

    add("getWeekOfYear", function() {
        return Math.ceil(this.getDayOfYear() / 7);
    });

    add("setDayOfYear", function(day) {
        this.setMonth(0);
        this.setDate(day);
        return this;
    });

    add("addYears", function(num) {
        this.setFullYear(this.getFullYear() + num);
        return this;
    });

    add("addMonths", function(num) {
        var tmpdtm = this.getDate();

        this.setMonth(this.getMonth() + num);

        if (tmpdtm > this.getDate())
            this.addDays(-this.getDate());

        return this;
    });

    add("addDays", function(num) {
        this.setDate(this.getDate() + num);
        return this;
    });

    add("addHours", function(num) {
        this.setHours(this.getHours() + num);
        return this;
    });

    add("addMinutes", function(num) {
        this.setMinutes(this.getMinutes() + num);
        return this;
    });

    add("addSeconds", function(num) {
        this.setSeconds(this.getSeconds() + num);
        return this;
    });

    add("zeroTime", function() {
        this.setMilliseconds(0);
        this.setSeconds(0);
        this.setMinutes(0);
        this.setHours(0);
        return this;
    });

    add("asString", function() {
        var today = new Date();
        return Date.format
                        .split('yyyy').join(this.getFullYear())
                        .split('yy').join((this.getFullYear() + '').substring(2))
                        .split('mmm').join(this.getMonthName(true))
                        .split('mm').join(_zeroPad(this.getMonth() + 1))
                        .split('dd').join(_zeroPad(this.getDate()))
                        .split('h').join(_zeroPad(today.getHours()))
                        .split('i').join(_zeroPad(today.getMinutes()))
                        .split('s').join(_zeroPad(today.getSeconds()));
    });


    Date.fromString = function(s) {
        var f = Date.format;
        var d = new Date('01/01/1977');
        var iY = f.indexOf('yyyy');
        if (iY > -1) {
            d.setFullYear(Number(s.substr(iY, 4)));
        } else {
            // TODO - this doesn't work very well - are there any rules for what is meant by a two digit year?
            d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('yy'), 2)));
        }
        var iM = f.indexOf('mmm');
        if (iM > -1) {
            var mStr = s.substr(iM, 3);
            for (var i = 0; i < Date.abbrMonthNames.length; i++) {
                if (Date.abbrMonthNames[i] == mStr) break;
            }
            d.setMonth(i);
        } else {
            d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1);
        }
        d.setDate(Number(s.substr(f.indexOf('dd'), 2)));
        if (isNaN(d.getTime())) {
            return false;
        }
        return d;
    };

    // utility method
    var _zeroPad = function(num) {
        var s = '0' + num;
        return s.substring(s.length - 2)
        //return ('0'+num).substring(-2); // doesn't work on IE :(
    };

})();

//-----------------------------------以上是日期相关函数，下面是生成日期控件----------------------------------------
var popupTop = 0;
(function($) {

    $.fn.extend({
        renderCalendar: function(s) {
            var dc = function(a) {
                return document.createElement(a);
            };

            s = $.extend({}, $.fn.datePicker.defaults, s);

            if (s.showHeader != $.dpConst.SHOW_HEADER_NONE) {
                var headRow = $(dc('tr'));
                for (var i = Date.firstDayOfWeek; i < Date.firstDayOfWeek + 7; i++) {
                    var weekday = i % 7;
                    var day = Date.dayNames[weekday];
                    headRow.append(
                                                jQuery(dc('th')).attr({ 'scope': 'col', 'abbr': day, 'title': day, 'class': (weekday == 0 || weekday == 6 ? 'weekend' : 'weekday') }).html(s.showHeader == $.dpConst.SHOW_HEADER_SHORT ? day.substr(0, 1) : day)
                                        );
                }
            };

            var calendarTable = $(dc('table'))
                                                                        .attr(
                                                                                {
                                                                                    'cellspacing': 2,
                                                                                    'className': 'jCalendar'
                                                                                }
                                                                        )
                                                                        .append(
                                                                                (s.showHeader != $.dpConst.SHOW_HEADER_NONE ?
                                                                                        $(dc('thead'))
                                                                                                .append(headRow)
                                                                                        :
                                                                                        dc('thead')
                                                                                )
                                                                        );
            var tbody = $(dc('tbody'));

            var today = (new Date()).zeroTime();

            var month = s.month == undefined ? today.getMonth() : s.month;
            var year = s.year || today.getFullYear();

            var currentDate = new Date(year, month, 1);


            var firstDayOffset = Date.firstDayOfWeek - currentDate.getDay() + 1;
            if (firstDayOffset > 1) firstDayOffset -= 7;
            var weeksToDraw = Math.ceil(((-1 * firstDayOffset + 1) + currentDate.getDaysInMonth()) / 7);
            currentDate.addDays(firstDayOffset - 1);

            var doHover = function() {
                if (s.hoverClass) {
                    if ($(this).hasClass("current-month") && !$(this).hasClass("disabled")) {
                        $(this).addClass(s.hoverClass);
                    }

                }
            };
            var unHover = function() {
                if (s.hoverClass) {
                    $(this).removeClass(s.hoverClass);
                }
            };

            var w = 0;
            while (w++ < weeksToDraw) {
                var r = jQuery(dc('tr'));
                for (var i = 0; i < 7; i++) {
                    var thisMonth = currentDate.getMonth() == month;
                    var tdstr = thisMonth ? currentDate.getDate() + '' : "";
                    var d = $(dc('td'))
                        .text(tdstr)
                            .attr('className', (thisMonth ? 'current-month ' : 'other-month ') +
                            (currentDate.isWeekend() ? 'weekend ' : 'weekday ') +
                            (thisMonth && currentDate.getTime() == today.getTime() ? 'today ' : '')
                                                                )
                                                                .hover(doHover, unHover)
                                                        ;
                    if (s.renderCallback) {
                        s.renderCallback(d, currentDate, month, year);
                    }
                    r.append(d);
                    currentDate.addDays(1);
                }
                tbody.append(r);
            }
            calendarTable.append(tbody);

            return this.each(
                                function() {
                                    $(this).empty().append(calendarTable);
                                }
                        );
        },

        datePicker: function(s) {
            if (!$.event._dpCache) $.event._dpCache = [];

            // initialise the date picker controller with the relevant settings...
            s = $.extend({}, $.fn.datePicker.defaults, s);

            return this.each(
                                function() {
                                    var $this = $(this);
                                    var alreadyExists = true;

                                    if (!this._dpId) {
                                        this._dpId = $.event.guid++;
                                        $.event._dpCache[this._dpId] = new DatePicker(this);
                                        alreadyExists = false;
                                    }

                                    if (s.inline) {
                                        s.createButton = false;
                                        s.displayClose = false;
                                        s.closeOnSelect = false;
                                        $this.empty();
                                    }

                                    var controller = $.event._dpCache[this._dpId];

                                    controller.init(s);

                                    if (!alreadyExists && s.createButton) {
                                        // create it!
                                        controller.button = $('<a href="#" class="dp-choose-date" title="' + $.dpText.TEXT_CHOOSE_DATE + '"></a>')
                                                                .bind(
                                                                        'click',
                                                                        function() {
                                                                            $this.dpDisplay(this);
                                                                            this.blur();
                                                                            return false;
                                                                        }
                                                                );
                                        $this.after(controller.button);
                                    }

                                    if (!alreadyExists && $this.is(':text')) {
                                        $this
                                                        .bind(
                                                                'dateSelected',
                                                                function(e, selectedDate, $td) {
                                                                    this.value = selectedDate.asString();
                                                                }
                                                        ).bind(
                                                                'change',
                                                                function() {
                                                                    if (this.value != '') {
                                                                        var d = Date.fromString(this.value);
                                                                        if (d) {
                                                                            controller.setSelected(d, true, true);
                                                                        }
                                                                    }
                                                                }
                                                        );
                                        if (s.clickInput) {
                                            $this.bind(
                                                                'click',
                                                                function() {
                                                                    $this.dpDisplay();
                                                                }
                                                        );
                                        }
                                        var d = Date.fromString(this.value);
                                        if (this.value != '' && d) {
                                            controller.setSelected(d, true, true);
                                        }
                                    }

                                    $this.addClass('dp-applied');

                                }
                        )
        },

        dpSetDisabled: function(s) {
            return _w.call(this, 'setDisabled', s);
        },

        dpSetStartDate: function(d) {
            return _w.call(this, 'setStartDate', d);
        },

        dpSetEndDate: function(d) {
            return _w.call(this, 'setEndDate', d);
        },

        dpGetSelected: function() {
            var c = _getController(this[0]);
            if (c) {
                return c.getSelected();
            }
            return null;
        },

        dpSetSelected: function(d, v, m) {
            if (v == undefined) v = true;
            if (m == undefined) m = true;
            return _w.call(this, 'setSelected', Date.fromString(d), v, m, true);
        },

        dpSetDisplayedMonth: function(m, y) {
            return _w.call(this, 'setDisplayedMonth', Number(m), Number(y), true);
        },

        dpDisplay: function(e) {
            return _w.call(this, 'display', e);
        },

        dpSetRenderCallback: function(a) {
            return _w.call(this, 'setRenderCallback', a);
        },

        dpSetPosition: function(v, h) {
            return _w.call(this, 'setPosition', v, h);
        },

        dpSetOffset: function(v, h) {
            return _w.call(this, 'setOffset', v, h);
        },

        dpClose: function() {
            return _w.call(this, '_closeCalendar', false, this[0]);
        },
        // private function called on unload to clean up any expandos etc and prevent memory links...
        _dpDestroy: function() {
            // TODO - implement this?
        }
    });

    // private internal function to cut down on the amount of code needed where we forward
    // dp* methods on the jQuery object on to the relevant DatePicker controllers...
    var _w = function(f, a1, a2, a3, a4) {
        return this.each(
                        function() {
                            var c = _getController(this);
                            if (c) {
                                c[f](a1, a2, a3, a4);
                            }
                        }
                );
    };

    function DatePicker(ele) {
        this.ele = ele;

        // initial values...
        this.displayedMonth = null;
        this.displayedYear = null;
        this.startDate = null;
        this.endDate = null;
        this.enableDates = null;
        this.showYearNavigation = null;
        this.closeOnSelect = null;
        this.displayClose = null;
        this.selectMultiple = null;
        this.verticalPosition = null;
        this.horizontalPosition = null;
        this.verticalOffset = null;
        this.horizontalOffset = null;
        this.button = null;
        this.renderCallback = [];
        this.selectedDates = {};
        this.inline = null;
        this.context = '#dp-popup';
    };
    $.extend(
                DatePicker.prototype,
                {
                    init: function(s) {
                        if (s.enableDates) {
                            this.setStartDate(s.enableDates[0]);
                            this.setEndDate(s.enableDates[s.enableDates.length - 1]);
                        } else {
                            this.setStartDate(s.startDate);
                            this.setEndDate(s.endDate);
                        }
                        this.selectedDates = {};
                        this.setEnableDates(s.enableDates);
                        if (s.enableDates) {
                            var lastDate1 = GetMsgLastDate();
                            if (lastDate1 == null || lastDate1 == "") {
                                lastDate1 = s.enableDates[s.enableDates.length - 1];
                            } 
                            var d = Date.fromString(lastDate1);
                            var month = d.getMonth();
                            var year = d.getFullYear();
                            this.setDisplayedMonth(month, year); 
                            if( $("#txtTime").val()!=""){
								this.selectedDates[Date.fromString($("#txtTime").val())] = true;
							}else{
								this.selectedDates[d.toString()] = true;
							}
                        } else {
                            this.setDisplayedMonth(Number(s.month), Number(s.year));
                        }
						if( $("#txtTime").val()!=""){
							this.selectedDates[Date.fromString($("#txtTime").val())] = true;
						}
                        this.setRenderCallback(s.renderCallback);
                        this.showYearNavigation = s.showYearNavigation;
                        this.closeOnSelect = s.closeOnSelect;
                        this.displayClose = s.displayClose;
                        this.selectMultiple = s.selectMultiple;
                        this.verticalPosition = s.verticalPosition;
                        this.horizontalPosition = s.horizontalPosition;
                        this.hoverClass = s.hoverClass;
                        this.setOffset(s.verticalOffset, s.horizontalOffset);
                        this.inline = s.inline;
                        if (this.inline) {
                            this.context = this.ele;
                            this.display();
                        }
                    },
                    setStartDate: function(d) {
                        if (d) {
                            this.startDate = Date.fromString(d);
                        }
                        if (!this.startDate) {
                            this.startDate = (new Date()).zeroTime();
                        }
                        this.setDisplayedMonth(this.displayedMonth, this.displayedYear);
                    },
                    setEndDate: function(d) {
                        if (d) {
                            if (d instanceof Date) {
                                this.endDate = d;
                            } else {
                                this.endDate = Date.fromString(d);
                            }
                        }

                        if (!this.endDate) {
                            this.endDate = (new Date('12/31/2999')); // using the JS Date.parse function which expects mm/dd/yyyy
                        }
                        if (this.endDate.getTime() < this.startDate.getTime()) {
                            this.endDate = this.startDate;
                        }
                        this.setDisplayedMonth(this.displayedMonth, this.displayedYear);
                    },
                    setEnableDates: function(d) {
                        this.enableDates = d;
                    },
                    setPosition: function(v, h) {
                        this.verticalPosition = v;
                        this.horizontalPosition = h;
                    },
                    setOffset: function(v, h) {
                        this.verticalOffset = parseInt(v) || 0;
                        this.horizontalOffset = parseInt(h) || 0;
                    },
                    setDisabled: function(s) {
                        $e = $(this.ele);
                        $e[s ? 'addClass' : 'removeClass']('dp-disabled');
                        if (this.button) {
                            $but = $(this.button);
                            $but[s ? 'addClass' : 'removeClass']('dp-disabled');
                            $but.attr('title', s ? '' : $.dpText.TEXT_CHOOSE_DATE);
                        }
                        if ($e.is(':text')) {
                            $e.attr('disabled', s ? 'disabled' : '');
                        }
                    },
                    setDisplayedMonth: function(m, y, rerender) {
                        if (this.startDate == undefined || this.endDate == undefined) {
                            return;
                        }
                        var s = new Date(this.startDate.getTime());
                        s.setDate(1);
                        var e = new Date(this.endDate.getTime());
                        e.setDate(1); 
                        var t;
                        if ((!m && !y) || (isNaN(m) && isNaN(y))) {
                            // no month or year passed - default to current month
                            t = new Date().zeroTime();
                            t.setDate(1);
                        } else if (isNaN(m)) {
                            // just year passed in - presume we want the displayedMonth
                            t = new Date(y, this.displayedMonth, 1);
                        } else if (isNaN(y)) {
                            // just month passed in - presume we want the displayedYear
                            t = new Date(this.displayedYear, m, 1);
                        } else {
                            // year and month passed in - that's the date we want!
                            t = new Date(y, m, 1)
                        }
                        // check if the desired date is within the range of our defined startDate and endDate
                        //if (t.getTime() < s.getTime()) {
                        //    t = s;
                        //} else if (t.getTime() > e.getTime()) {
                        //    t = e;
                        //}
                        var oldMonth = this.displayedMonth;
                        var oldYear = this.displayedYear;
                        this.displayedMonth = t.getMonth();
                        this.displayedYear = t.getFullYear();
                        //zp
                        if (rerender && (this.displayedMonth != oldMonth || this.displayedYear != oldYear)) {
                            this._rerenderCalendar();
                            $(this.ele).trigger('dpMonthChanged', [this.displayedMonth, this.displayedYear]);
                        }
                    },
                    setSelected: function(d, v, moveToMonth, dispatchEvents) {
                        /*if (v == this.isSelected(d)) // this date is already un/selected
                        {
                            return;
                        }*/
                        if (this.selectMultiple == false) {
                            this.selectedDates = {};
                            $('td.selected', this.context).removeClass('selected');
                        }
                        if (moveToMonth && this.displayedMonth != d.getMonth()) {
                            this.setDisplayedMonth(d.getMonth(), d.getFullYear(), true);
                        }
                        this.selectedDates[d.toString()] = v;

                        var selectorString = 'td.';
                        selectorString += d.getMonth() == this.displayedMonth ? 'current-month' : 'other-month';
                        selectorString += ':contains("' + d.getDate() + '")';
                        var $td;
                        $(selectorString, this.ele).each(
                                        function() {
                                            if ($(this).text() == d.getDate()) {
                                                $td = $(this);
                                                $td[v ? 'addClass' : 'removeClass']('selected');
                                            }
                                        }
                                );

                        if (dispatchEvents) {
                            var s = this.isSelected(d);
                            $e = $(this.ele);
                            $e.trigger('dateSelected', [d, $td, s]);
                            $e.trigger('change');
                        }
                    },
                    isSelected: function(d) {
                        return this.selectedDates[d.toString()];
                    },
                    getSelected: function() {
                        var r = [];
                        for (s in this.selectedDates) {
                            if (this.selectedDates[s] == true) {
                                r.push(Date.parse(s));
                            }
                        }
                        return r;
                    },
                    display: function(eleAlignTo) {
                        if ($(this.ele).is('.dp-disabled')) return;

                        eleAlignTo = eleAlignTo || this.ele;
                        var c = this;
                        var $ele = $(eleAlignTo);
                        var eleOffset = $ele.offset();

                        var $createIn;
                        var attrs;
                        var attrsCalendarHolder;
                        var cssRules;

                        if (c.inline) {
                            $createIn = $(this.ele);
                            attrs = {
                                'id': 'calendar-' + this.ele._dpId,
                                'className': 'dp-popup dp-popup-inline'
                            };
                            cssRules = {
                        };
                    } else {
                        $createIn = $('body');
                        attrs = {
                            'id': 'dp-popup',
                            'className': 'dp-popup'
                        };
                        cssRules = {
                            'top': eleOffset.top + c.verticalOffset - 182 - 24,
                            'left': eleOffset.left + c.horizontalOffset + 83
                        };

                        var _checkMouse = function(e) {
                            var el = e.target;
                            var cal = $('#dp-popup')[0];

                            while (true) {
                                if (el == cal) {
                                    return true;
                                } else if (el == document) {
                                    c._closeCalendar();
                                    return false;
                                } else {
                                    el = $(el).parent()[0];
                                }
                            }
                        };
                        this._checkMouse = _checkMouse;

                        this._closeCalendar(true);
                    }


                    $createIn
                                        .append(
                                                $('<div></div>')
                                                        .attr(attrs)
                                                        .css(cssRules)
                                                        .append(
                                                                $('<h2></h2>'),
                                                                $('<div class="dp-nav-prev"></div>')
                                                                        .append(
                                                                                $('<a class="dp-nav-prev-year" href="#" title="' + $.dpText.TEXT_PREV_YEAR + '"></a>')
                                                                                        .bind(
                                                                                                'click',
                                                                                                function() {
                                                                                                    return c._displayNewMonth.call(c, this, 0, -1);
                                                                                                }
                                                                                        ),
                                                                                $('<a class="dp-nav-prev-month" href="#" title="' + $.dpText.TEXT_PREV_MONTH + '"></a>')
                                                                                        .bind(
                                                                                                'click',
                                                                                                function() {
                                                                                                    return c._displayNewMonth.call(c, this, -1, 0);
                                                                                                }
                                                                                        )
                                                                        ),
                                                                $('<div class="dp-nav-next"></div>')
                                                                        .append(
                                                                                $('<a class="dp-nav-next-year" href="#" title="' + $.dpText.TEXT_NEXT_YEAR + '"></a>')
                                                                                        .bind(
                                                                                                'click',
                                                                                                function() {
                                                                                                    return c._displayNewMonth.call(c, this, 0, 1);
                                                                                                }
                                                                                        ),
                                                                                $('<a class="dp-nav-next-month" href="#" title="' + $.dpText.TEXT_NEXT_MONTH + '"></a>')
                                                                                        .bind(
                                                                                                'click',
                                                                                                function() {
                                                                                                    return c._displayNewMonth.call(c, this, 1, 0);
                                                                                                }
                                                                                        )
                                                                        ),
                                                                $('<div></div>')
                                                                        .attr('className', 'dp-calendar')
                                                        )
                                                        .bgIframe()
                                                );

                    var $pop = this.inline ? $('.dp-popup', this.context) : $('#dp-popup');

                    if (this.showYearNavigation == false) {
                        $('.dp-nav-prev-year, .dp-nav-next-year', c.context).css('display', 'none');
                    }
                    if (this.displayClose) {
                        $pop.append(
                                                $('<a href="#" id="dp-close">' + $.dpText.TEXT_CLOSE + '</a>')
                                                        .bind(
                                                                'click',
                                                                function() {
                                                                    c._closeCalendar();
                                                                    return false;
                                                                }
                                                        )
                                        );
                    }
                    c._renderCalendar();

                    $(this.ele).trigger('dpDisplayed', $pop);

                    if (!c.inline) {
                        if (this.verticalPosition == $.dpConst.POS_BOTTOM) {
                            $pop.css('top', eleOffset.top + $ele.height() - $pop.height() + c.verticalOffset - 24);
                        } else {
                            $pop.css('top', eleOffset.top + $ele.height() - $pop.height() + c.verticalOffset - 37);
                        }
                        popupTop = $pop.css('top');
                        if (this.horizontalPosition == $.dpConst.POS_RIGHT) {
                            if ($ele.attr("id") == "txtTime") {
                                $pop.css('left', eleOffset.left + $ele.width() + 111 - $pop.width() + c.horizontalOffset);
                            } else if ($ele.attr("class") == "dp-choose-date") {
                                $pop.css('left', eleOffset.left + $ele.width() + 88 - $pop.width() + c.horizontalOffset);
                            }
                        }
                        if ($('.dp-calendar').height() == 133) {
                            $pop.css('top', popupTop);
                        } else {
                            if (this.displayedMonth == 1 && this.displayedYear == 2015) {
                                $pop.css('top', popupTop);
                            } else {
                                $pop.css('top', parseInt(popupTop) - 22);
                            }
                        }
                        $(document).bind('mousedown', this._checkMouse);
                    }
                },
                setRenderCallback: function(a) {
                    if (a == null) return;
                    if (a && typeof (a) == 'function') {
                        a = [a];
                    }
                    this.renderCallback = this.renderCallback.concat(a);
                },
                cellRender: function($td, thisDate, month, year) {
                    var c = this.dpController;
                    var d = new Date(thisDate.getTime());

                    // add our click handlers to deal with it when the days are clicked...

                    $td.bind(
                                        'click',
                                        function() {
                                            var $this = $(this);
                                            if (!$this.is('.disabled')) {
                                                c.setSelected(d, !$this.is('.selected') || !c.selectMultiple, false, true);
                                                if (c.closeOnSelect) {
                                                    c._closeCalendar();
                                                }
                                            }
                                        }
                                );

                    if (c.isSelected(d)) {
                        $td.addClass('selected');
                    }

                    // call any extra renderCallbacks that were passed in
                    for (var i = 0; i < c.renderCallback.length; i++) {
                        c.renderCallback[i].apply(this, arguments);
                    }


                },
                // ele is the clicked button - only proceed if it doesn't have the class disabled...
                // m and y are -1, 0 or 1 depending which direction we want to go in...
                _displayNewMonth: function(ele, m, y) {

                    if (!$(ele).is('.disabled')) {
                        this.setDisplayedMonth(this.displayedMonth + m, this.displayedYear + y, true);
                    }
                    ele.blur();
                    var $pop = $('#dp-popup');
                    if ($('.dp-calendar').height() == 133) {
                        $pop.css('top', popupTop);
                    } else {
                        if (this.displayedMonth == 1 && this.displayedYear == 2015) {
                            $pop.css('top', popupTop);
                        } else {
                            $pop.css('top', parseInt(popupTop) - 22);
                        }
                    }
                    return false;
                },
                _rerenderCalendar: function() {
                    this._clearCalendar();
                    this._renderCalendar();
                },
                _renderCalendar: function() {
                    // set the title...  修改日历显示时间
                    //$('h2', this.context).html(this.displayedYear + '年 ' + Date.monthNames[this.displayedMonth]);
                    var month = this.displayedMonth + 1 > 12 ? 1 : this.displayedMonth + 1;
                    $('h2', this.context).html(this.displayedYear + '年 ' + month + '月');

                    // render the calendar...
                    $('.dp-calendar', this.context).renderCalendar(
                                        {
                                            month: this.displayedMonth,
                                            year: this.displayedYear,
                                            renderCallback: this.cellRender,
                                            dpController: this,
                                            hoverClass: this.hoverClass
                                        }
                                );

                    // update the status of the control buttons and disable dates before startDate or after endDate...
                    // TODO: When should the year buttons be disabled? When you can't go forward a whole year from where you are or is that annoying?
                    if (this.displayedYear == this.startDate.getFullYear() && this.displayedMonth == this.startDate.getMonth()) {
                        //$('.dp-nav-prev-year', this.context).addClass('disabled');
                        //$('.dp-nav-prev-month', this.context).addClass('disabled');
                        $('.dp-calendar td.other-month', this.context).each(
                                                function() {
                                                    var $this = $(this);
                                                    if (Number($this.text()) > 20) {
                                                        $this.addClass('disabled');
                                                    }
                                                }
                                        );
                        var d = this.startDate.getDate();
                        $('.dp-calendar td.current-month', this.context).each(
                                                function() {
                                                    var $this = $(this);
                                                    if (Number($this.text()) < d) {
                                                        $this.addClass('disabled');
                                                    }
                                                }
                                        );
                    } else {
                        $('.dp-nav-prev-year', this.context).removeClass('disabled');
                        $('.dp-nav-prev-month', this.context).removeClass('disabled');
                        var d = this.startDate.getDate();
                        if (d > 20) {
                            // check if the startDate is last month as we might need to add some disabled classes...
                            var sd = new Date(this.startDate.getTime());
                            sd.addMonths(1);
                            if (this.displayedYear == sd.getFullYear() && this.displayedMonth == sd.getMonth()) {
                                $('dp-calendar td.other-month', this.context).each(
                                                                function() {
                                                                    var $this = $(this);
                                                                    if (Number($this.text()) < d) {
                                                                        $this.addClass('disabled');
                                                                    }
                                                                }
                                                        );
                            }
                        }
                    }
                    if (this.displayedYear == this.endDate.getFullYear() && this.displayedMonth == this.endDate.getMonth()) {
                        //$('.dp-nav-next-year', this.context).addClass('disabled');
                        //$('.dp-nav-next-month', this.context).addClass('disabled');
                        $('.dp-calendar td.other-month', this.context).each(
                                                function() {
                                                    var $this = $(this);
                                                    if (Number($this.text()) < 14) {
                                                        $this.addClass('disabled');
                                                    }
                                                }
                                        );
                        var d = this.endDate.getDate();
                        $('.dp-calendar td.current-month', this.context).each(
                                                function() {
                                                    var $this = $(this);
                                                    if (Number($this.text()) > d) {
                                                        $this.addClass('disabled');
                                                    }
                                                }
                                        );
                    } else {
                        $('.dp-nav-next-year', this.context).removeClass('disabled');
                        $('.dp-nav-next-month', this.context).removeClass('disabled');
                        var d = this.endDate.getDate();
                        if (d < 13) {
                            // check if the endDate is next month as we might need to add some disabled classes...
                            var ed = new Date(this.endDate.getTime());
                            ed.addMonths(-1);
                            if (this.displayedYear == ed.getFullYear() && this.displayedMonth == ed.getMonth()) {
                                $('.dp-calendar td.other-month', this.context).each(
                                                                function() {
                                                                    var $this = $(this);
                                                                    if (Number($this.text()) > d) {
                                                                        $this.addClass('disabled');
                                                                    }
                                                                }
                                                        );
                            }
                        }
                    }
                    if (this.enableDates) {
                        //取出显示的月份日期，
                        var d = new Array();
                        var j = 0;
                        for (var i = 0; i < this.enableDates.length; i++) {
                            if (this.displayedYear == Date.fromString(this.enableDates[i]).getFullYear() && this.displayedMonth == Date.fromString(this.enableDates[i]).getMonth()) {
                                d[j] = Date.fromString(this.enableDates[i]).getDate();
                            }
                            j++;
                        }

                        $('.dp-calendar td.other-month', this.context).each(
                            function() {
                                var $this = $(this);
                                $this.addClass('disabled');
                            }
                        );

                        $('.dp-calendar td.current-month', this.context).each(
                                                function() {

                                                    var $this = $(this);
                                                    $this.addClass('disabled');
                                                    for (var index in d) {
                                                        if (Number($this.text()) == d[index]) {
                                                            $this.removeClass('disabled');
                                                            continue;
                                                        }
                                                    }
                                                }
                                        );
                    }
                },
                _closeCalendar: function(programatic, ele) {
                    if (!ele || ele == this.ele) {
                        $(document).unbind('mousedown', this._checkMouse);
                        this._clearCalendar();
                        $('#dp-popup a').unbind();
                        $('#dp-popup').empty().remove();
                        if (!programatic) {
                            $(this.ele).trigger('dpClosed', [this.getSelected()]);
                        }
                    }
                },
                // empties the current dp-calendar div and makes sure that all events are unbound
                // and expandos removed to avoid memory leaks...
                _clearCalendar: function() {
                    // TODO.
                    $('.dp-calendar td', this.context).unbind();
                    $('.dp-calendar', this.context).empty();
                }
            }
        );

    // static constants
    $.dpConst = {
        SHOW_HEADER_NONE: 0,
        SHOW_HEADER_SHORT: 1,
        SHOW_HEADER_LONG: 2,
        POS_TOP: 0,
        POS_BOTTOM: 1,
        POS_LEFT: 0,
        POS_RIGHT: 1
    };
    // localisable text
    $.dpText = {
        TEXT_PREV_YEAR: '上一年',
        TEXT_PREV_MONTH: '上一月',
        TEXT_NEXT_YEAR: '下一年',
        TEXT_NEXT_MONTH: '下一月',
        TEXT_CLOSE: '关闭',
        TEXT_CHOOSE_DATE: '按日期查看消息记录'
    };
    // version
    $.dpVersion = '$Id: jquery.datePicker.js 15 2008-12-17 04:40:18Z kelvin.luck $';

    $.fn.datePicker.defaults = {
        enableDates: undefined,
        month: undefined,
        year: undefined,
        showHeader: $.dpConst.SHOW_HEADER_SHORT,
        startDate: '2006-01-01',
        endDate: (new Date()),
        inline: false,
        renderCallback: null,
        createButton: true,
        showYearNavigation: true,
        closeOnSelect: true,
        displayClose: false,
        selectMultiple: false,
        clickInput: true,
        verticalPosition: $.dpConst.POS_TOP,
        horizontalPosition: $.dpConst.POS_RIGHT,
        verticalOffset: 20,
        horizontalOffset: 0,
        hoverClass: 'dp-hover'
    };

    function _getController(ele) {
        if (ele._dpId) return $.event._dpCache[ele._dpId];
        return false;
    };

    // make it so that no error is thrown if bgIframe plugin isn't included (allows you to use conditional
    // comments to only include bgIframe where it is needed in IE without breaking this plugin).
    if ($.fn.bgIframe == undefined) {
        $.fn.bgIframe = function() { return this; };
    };

    //window.setEnableDates = setEnableDates;

    // clean-up
    $(window)
                .bind('unload', function() {
                    var els = $.event._dpCache || [];
                    for (var i in els) {
                        $(els[i].ele)._dpDestroy();
                    }
                });


})(jQuery);