if (typeof jQuery !== "undefined" && jQuery && (typeof jquery_calendar_check_is_gyb === "undefined" || !jquery_calendar_check_is_gyb)) {
    jquery_calendar_check_is_gyb = true;

    (function() {
        var style = ".calendar_frame {font-size: 11px;font-family :Arial;padding: 0px; margin: 0px; width: 200px; border: 1px solid #7f9db9; position: absolute; background-color: white; color:#000;}";
        style += ".calendar_frame .calendar_top_title { height: 18px; margin: 5px; padding-top: 4px; border: 1px solid #ccc; text-align: center; background-color: #ddd; color: #000; }";
        style += ".calendar_frame .calendar_top_title .change_ym_button {height: 13px;margin-left: 3px;margin-right: 3px;width: 12px; display: inline-block; background-color: #eee; border: 1px solid #ccc; cursor: pointer; }";
        style += ".calendar_frame .calendar_top_title .shwo_ym {margin-right: 15px;margin-left: 15px;}";
        style += ".calendar_frame .calendar { width: 100%; }";
        style += ".calendar_frame .calendar div { text-align: center; margin-bottom: 3px; }";
        style += ".calendar_frame .calendar .week_title span { text-align: center; border: 1px solid #fff; background-color: white; color: #385fb1; }";
        style += ".calendar_frame .calendar span { margin-left: 3px;margin-right: 3px;width: 18px; height: 13px; text-align: right; display: inline-block; border: 1px solid #ccc; background-color: white; padding-top: 2px; padding-left: 2px; cursor: pointer; }";
        style += ".calendar_frame .calendar .day_disabled { background-color: #eee; color: #ccc; cursor: default; }";
        style += ".calendar_frame .calendar .day_today { border: 1px solid dodgerblue; background-color: cornflowerblue; color: white; }";
        style += ".calendar_frame .calendar .day_active { border: 1px solid darkolivegreen; background-color: limegreen; color: white; }";
        style += ".calendar_frame .calendar .day_notInCurrentMonth { border: 1px solid #fff; background-color: #fff; color: #fff; cursor: default; }";
        style += ".calendar_frame .calendar_bottom_bar { height: 18px; margin: 5px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #ccc; text-align: center; background-color: #ddd; color: #000; }";
        style += ".calendar_frame .calendar_bottom_bar .clean_date_button { margin-right: 25px; width: 40px; padding-top: 2px; display: inline-block; background-color: #eee; border: 1px solid #ccc; cursor: pointer; }";
        style += ".calendar_frame .calendar_bottom_bar .today_date_button { margin-left: 25px; padding-top: 2px; width: 40px; display: inline-block; border: 1px solid dodgerblue; background-color: cornflowerblue; color: white; cursor: pointer; }";

        jQuery.createStyle(style);
    })();

    jQuery.calendar = function(input, options) {
        input.calendar = this;
        this.input = input;
        this.$input = jQuery(input);
        this.options = options;

        this.$input.attr("readOnly", options.readOnly);
        this._init();
        this.$input.attr("autocomplete", "off");
    };

    jQuery.calendar.prototype = {
        _init:function() {
            this._initInputEvent();
        },

        _initInputEvent:function() {
            this.$input.focus(function(e) {
                jQuery.calendar.focusInput = this;
                this.calendar.show(jQuery(this));
            });

            this.$input.blur(function(e) {
                jQuery.calendar.hide();
            });
        },

        show:function($input) {
            if (jQuery.calendar.timer) {
                clearTimeout(jQuery.calendar.timer);
            }

            jQuery.calendar.year = new Date().getFullYear();
            jQuery.calendar.month = new Date().getMonth() + 1;

            if (jQuery.calendar.focusInput.calendar.options.prevDayFromInput) {
                var date = jQuery.parseDate(jQuery(jQuery.calendar.focusInput.calendar.options.prevDayFromInput).val());
                if (!jQuery.isDate(date)) {
                    jQuery(jQuery.calendar.focusInput.calendar.options.prevDayFromInput).focus();
                    return;
                } else {
                    jQuery.calendar.year = date.getFullYear();
                    jQuery.calendar.month = date.getMonth() + 1;
                }
            }

            if (jQuery.calendar.focusInput.calendar.options.beginDateFn) {
                var date = jQuery.calendar.focusInput.calendar.options.beginDateFn();
                if (date != null && jQuery.isDate(date)) {
                    jQuery.calendar.year = date.getFullYear();
                    jQuery.calendar.month = date.getMonth() + 1;
                }
            }

            if (jQuery.trim($input.val()) != "") {
                var inputDate = jQuery.parseDate($input.val());
                if (jQuery.isDate(inputDate)) {
                    jQuery.calendar.year = inputDate.getFullYear();
                    jQuery.calendar.month = inputDate.getMonth() + 1;
                }
            }

            var _this = this;
            jQuery.calendar.timer = setTimeout(function() {

                if (jQuery.calendar.focusInput.calendar.options.showSelectTitle) {
                    jQuery.calendar.instance.find("#calendar_title_button").hide();
                    jQuery.calendar.instance.find("#calendar_title_select").show();
                } else {
                    jQuery.calendar.instance.find("#calendar_title_select").hide();
                    jQuery.calendar.instance.find("#calendar_title_button").show();
                }

                jQuery.calendar.instance.attr("className", _this.options.calendarClass);
                var clearButtonHide = false;
                var todayButtonHide = false;
                if (jQuery.calendar.focusInput.calendar.options.showClearButton) {
                    clearButtonHide = false;
                    jQuery.calendar.instance.find(".calendar_bottom_bar .clean_date_button").show();
                } else {
                    clearButtonHide = true;
                    jQuery.calendar.instance.find(".calendar_bottom_bar .clean_date_button").hide();
                }


                if (jQuery.calendar.focusInput.calendar.options.showTodayButton) {
                    todayButtonHide = false;
                    jQuery.calendar.instance.find(".calendar_bottom_bar .today_date_button").show();
                } else {
                    todayButtonHide = true;
                    jQuery.calendar.instance.find(".calendar_bottom_bar .today_date_button").hide();
                }

                if (clearButtonHide && todayButtonHide) {
                    jQuery.calendar.instance.find(".calendar_bottom_bar").hide();
                } else {
                    jQuery.calendar.instance.find(".calendar_bottom_bar").show();
                }

                jQuery.calendar.draw();
                jQuery.calendar.instance.floating($input);
                jQuery.calendar.instance.show();

                if (!jQuery.calendar.isInBody) {
                    jQuery.calendar.isInBody = true;
                    jQuery.calendar.instance.appendTo(jQuery("body"));
                    jQuery(document).mousedown(function() {
                        jQuery.calendar.hide();
                    });
                }

                jQuery.iframeDecorateDiv(jQuery.calendar.instance);
            }, 10);
        },

        hide:function() {
            jQuery.calendar.instance.hide();
        },

        version:"1.0"
    };

    jQuery.fn.calendar = function(options) {
        options = options || {};
        options.calendarClass = options.calendarClass || "calendar_frame";
        options.showPrevDay = jQuery.isBoolean(options.showPrevDay) ? options.showPrevDay : true;
        options.showYesterdayBeforeAmSix = jQuery.isBoolean(options.showYesterdayBeforeAmSix) ? options.showYesterdayBeforeAmSix : false;
        options.readOnly = jQuery.isBoolean(options.readOnly) ? options.readOnly : true;
        options.showClearButton = jQuery.isBoolean(options.showClearButton) ? options.showClearButton : true;
        options.showTodayButton = jQuery.isBoolean(options.showTodayButton) ? options.showTodayButton : true;
        options.onChange = jQuery.isFunction(options.onChange) ? options.onChange : null;
        options.prevDayFromInput = jQuery.isInputText(options.prevDayFromInput) ? options.prevDayFromInput : null;
        options.beginDateFn = jQuery.isFunction(options.beginDateFn) ? options.beginDateFn : null;
        options.endDateFn = jQuery.isFunction(options.endDateFn) ? options.endDateFn : null;
        options.isDisabledFn = jQuery.isFunction(options.isDisabledFn) ? options.isDisabledFn : null;
        options.showSelectTitle = jQuery.isBoolean(options.showSelectTitle) ? options.showSelectTitle : false;

        this.each(function() {
            var input = this;
            new jQuery.calendar(input, options);
        });

        return this;
    };

    jQuery.calendar.instance = null;
    jQuery.calendar.isInBody = false;
    jQuery.calendar.focusInput = null;
    jQuery.calendar.timer = null;
    jQuery.calendar.one_day_time_length = 24 * 60 * 60 * 1000;

    jQuery.calendar.year = new Date().getFullYear();
    jQuery.calendar.month = new Date().getMonth() + 1;

    jQuery.calendar.click = function(day) {
        if (jQuery(day).attr("className").indexOf("day_notInCurrentMonth") < 0 && jQuery(day).attr("className").indexOf("day_disabled")) {
            jQuery.calendar.instance.hide();

            jQuery(day).each(function() {
                jQuery.calendar.fillValue("" + this._year_val, "" + this._month_val, "" + this._day_val);
            });
        }
    };

    jQuery.calendar.isShow = function() {
        return !jQuery.calendar.instance.is(":hidden");
    };

    jQuery.calendar.hide = function() {
        if (jQuery.calendar.isShow()) {
            var div = jQuery.calendar.instance;
            var x1 = div.offset().left;
            var y1 = div.offset().top;

            var x2 = x1 + div.outerWidth();
            var y2 = y1 + div.outerHeight();

            if (jQuery.mouseXY.X >= x1 && jQuery.mouseXY.X <= x2 && jQuery.mouseXY.Y >= y1 && jQuery.mouseXY.Y <= y2) {
                return;
            }

            var div = jQuery(jQuery.calendar.focusInput);
            var x1 = div.offset().left;
            var y1 = div.offset().top;

            var x2 = x1 + div.outerWidth();
            var y2 = y1 + div.outerHeight();

            if (jQuery.mouseXY.X >= x1 && jQuery.mouseXY.X <= x2 && jQuery.mouseXY.Y >= y1 && jQuery.mouseXY.Y <= y2) {
                return;
            }

            jQuery.calendar.instance.hide();
        }
    };

    jQuery.calendar.prevMonth = function() {
        if (jQuery.calendar.month == 1) {
            if (jQuery.calendar.year > 1970) {
                jQuery.calendar.month = 12;
                jQuery.calendar.year = jQuery.calendar.year - 1;
                jQuery.calendar.draw();
            }
        } else {
            jQuery.calendar.month = jQuery.calendar.month - 1;
            jQuery.calendar.draw();
        }
    };

    jQuery.calendar.nextMonth = function() {
        if (jQuery.calendar.month == 12) {
            jQuery.calendar.month = 1;
            jQuery.calendar.year = jQuery.calendar.year + 1;
        } else {
            jQuery.calendar.month = jQuery.calendar.month + 1;
        }
        jQuery.calendar.draw();
    };

    jQuery.calendar.prevYear = function() {
        if (jQuery.calendar.year > 1970) {
            jQuery.calendar.year = jQuery.calendar.year - 1;
            jQuery.calendar.draw();
        }
    };

    jQuery.calendar.nextYear = function() {
        jQuery.calendar.year = jQuery.calendar.year + 1;
        jQuery.calendar.draw();
    };

    jQuery.calendar.changeYear = function(year) {
        jQuery.calendar.year = year - 0;
        jQuery.calendar.draw();
    };

    jQuery.calendar.changeMonth = function(month) {
        jQuery.calendar.month = month - 0;

        jQuery.calendar.draw();
    };

    jQuery.calendar.draw = function() {
        jQuery.calendar.instance.css("zIndex", 999999999);

        var ym_select = jQuery.calendar.instance.find(".calendar_top_title select");
        $(ym_select[0]).val(jQuery.calendar.year);
        $(ym_select[1]).val(jQuery.calendar.month);

        jQuery.calendar.instance.find(".calendar_top_title .shwo_ym").html("" + jQuery.calendar.year + "&nbsp;&#x5e74;&nbsp;" + (jQuery.calendar.month < 10 ? "0" + jQuery.calendar.month : jQuery.calendar.month) + "&nbsp;&#x6708;");

        var inputDate = jQuery.parseDate(jQuery(jQuery.calendar.focusInput).val());
        inputDate = jQuery.isDate(inputDate) ? inputDate : null;

        var today = new Date();
        var todayHours = today.getHours();
        jQuery.formatYMD(today);


        var firstDayOfMonth = new Date("" + jQuery.calendar.year + "/" + jQuery.calendar.month + "/1");

        var day = new Date(firstDayOfMonth.getTime() - (firstDayOfMonth.getDay() * jQuery.calendar.one_day_time_length));

        var beginDate = null;
        if (jQuery.calendar.focusInput.calendar.options.beginDateFn) {
            beginDate = jQuery.calendar.focusInput.calendar.options.beginDateFn();
            if (beginDate != null && jQuery.isDate(beginDate)) {
                jQuery.formatYMD(beginDate);
            }
        }

        var endDate = null;
        if (jQuery.calendar.focusInput.calendar.options.endDateFn) {
            endDate = jQuery.calendar.focusInput.calendar.options.endDateFn();
            if (endDate != null && jQuery.isDate(endDate)) {
                jQuery.formatYMD(endDate);
            }
        }

        var weeks = jQuery.calendar.instance.find(".calendar div");
        for (var i = 1; i < weeks.length; i++) {
            jQuery.calendar.drawOneWeek(weeks[i], day, today, inputDate, firstDayOfMonth, todayHours, beginDate, endDate);
            day = new Date(day.getTime() + 7 * jQuery.calendar.one_day_time_length);
        }

    };

    jQuery.calendar.drawOneWeek = function(weekDiv, day, totay, inputDate, firstDayOfMonth, todayHours, beginDate, endDate) {
        jQuery(weekDiv).show();
        var daySpans = jQuery(weekDiv).find("span");

        for (var i = 0; i < daySpans.length; i++) {
            var isEnabled = true;

            isEnabled = (isEnabled && !jQuery.calendar.focusInput.calendar.options.showPrevDay) ? (day.getTime() >= totay.getTime()) : isEnabled;
            isEnabled = (!isEnabled && jQuery.calendar.focusInput.calendar.options.showYesterdayBeforeAmSix && todayHours < 6) ? ( new Date(day.getTime() + jQuery.calendar.one_day_time_length).getTime() == totay.getTime()) : isEnabled;
            isEnabled = (isEnabled && beginDate) ? (day.getTime() >= beginDate.getTime()) : isEnabled;
            isEnabled = (isEnabled && endDate) ? (day.getTime() <= endDate.getTime()) : isEnabled;
            if (isEnabled && jQuery.calendar.focusInput.calendar.options.isDisabledFn) {
                var v = jQuery.calendar.focusInput.calendar.options.isDisabledFn(day);
                if (jQuery.isBoolean(v)) {
                    isEnabled = !v;
                }
            }

            jQuery.calendar.drawDay(daySpans[i], day, totay, inputDate, isEnabled, firstDayOfMonth);
            day = new Date(day.getTime() + jQuery.calendar.one_day_time_length);
        }
        if (jQuery(weekDiv).find(".day_notInCurrentMonth").length == 7) {
            jQuery(weekDiv).hide();
        }
    };

    jQuery.calendar.drawDay = function(daySpan, day, totay, inputDate, isEnabled, firstDayOfMonth) {
        var _day = jQuery(daySpan);
        _day.each(function() {
            this._year_val = day.getFullYear();
            this._month_val = (day.getMonth() + 1);
            this._day_val = day.getDate();
        });

        _day.html('' + day.getDate());
        _day.removeAttr("className");
        if (!isEnabled) {
            _day.addClass("day_disabled");
        } else {
            if (inputDate && day.getTime() == inputDate.getTime()) {
                _day.addClass("day_active");
            } else if (day.getTime() == totay.getTime()) {
                _day.addClass("day_today");
            }
        }
        if (!(firstDayOfMonth.getFullYear() == day.getFullYear() && firstDayOfMonth.getMonth() == day.getMonth())) {
            _day.addClass("day_notInCurrentMonth");
            _day.html('&nbsp;');
        }
    };

    jQuery.calendar.fillValue = function(y, m, d) {
        m = m.length == 1 ? "0" + m : m;
        d = d.length == 1 ? "0" + d : d;
        jQuery(jQuery.calendar.focusInput).val(y + "-" + m + "-" + d);
        if (jQuery.calendar.focusInput.calendar.options.onChange) {
            jQuery.calendar.focusInput.calendar.options.onChange();
        }
    };

    jQuery.calendar.clear = function() {
        jQuery(jQuery.calendar.focusInput).val("");
        jQuery.calendar.instance.hide();
        if (jQuery.calendar.focusInput.calendar.options.onChange) {
            jQuery.calendar.focusInput.calendar.options.onChange();
        }
    };

    jQuery.calendar.fillToday = function() {
        jQuery.calendar.instance.hide();
        var today = new Date();
        jQuery.calendar.fillValue("" + today.getFullYear(), "" + (today.getMonth() + 1), "" + today.getDate());
    };

    (function() {
        var year_select = "<select style='font-size:11px;' onchange='jQuery.calendar.changeYear(this.value);'>";
        for (var y = 1900; y <= 2100; y++) {
            year_select = year_select + "<option value='" + y + "'>" + y + "</option>";
        }
        year_select = year_select + "</select>";

        var month_select = "<select style='font-size:11px;' onchange='jQuery.calendar.changeMonth(this.value);'>";
        for (var m = 1; m <= 12; m++) {
            month_select = month_select + "<option value='" + m + "'>" + m + "</option>";
        }
        month_select = month_select + "</select>";

        var div = jQuery('<div></div>');
        var titleA = jQuery('<div id="calendar_title_select" style="display:none;" class="calendar_top_title">' + year_select + '年&nbsp;&nbsp;&nbsp;' + month_select + '月</div>');
        var titleB = jQuery('<div id="calendar_title_button" class="calendar_top_title"><span title="&#x4e0a;&#x4e00;&#x5e74;" class="change_ym_button" onclick="jQuery.calendar.prevYear();">&lt;&lt;</span><span title="&#x4e0a;&#x4e00;&#x6708;" class="change_ym_button" onclick="jQuery.calendar.prevMonth();">&lt;</span><span class="shwo_ym"></span><span title="&#x4e0b;&#x4e00;&#x6708;" class="change_ym_button" onclick="jQuery.calendar.nextMonth();">&gt;</span><span title="&#x4e0b;&#x4e00;&#x5e74;" class="change_ym_button" onclick="jQuery.calendar.nextYear();">&gt;&gt;</span></div>');
        var calendar = jQuery('<div class="calendar"></div>');
        var bottom = jQuery('<div class="calendar_bottom_bar"><span class="clean_date_button" onclick="jQuery.calendar.clear();">&#x6e05;&#x7a7a;</span><span class="today_date_button" onclick="jQuery.calendar.fillToday();">&#x4eca;&#x5929;</span></div>');

        jQuery('<div class="week_title"><span>&#x65e5;</span><span>&#x4e00;</span><span>&#x4e8c;</span><span>&#x4e09;</span><span>&#x56db;</span><span>&#x4e94;</span><span>&#x516d;</span></div>').appendTo(calendar);
        for (var i = 0; i < 6; i++) {
            jQuery('<div><span onclick="jQuery.calendar.click(this);">&nbsp;</span><span onclick="jQuery.calendar.click(this);">&nbsp;</span><span onclick="jQuery.calendar.click(this);">&nbsp;</span><span onclick="jQuery.calendar.click(this);">&nbsp;</span><span onclick="jQuery.calendar.click(this);">&nbsp;</span><span onclick="jQuery.calendar.click(this);">&nbsp;</span><span onclick="jQuery.calendar.click(this);">&nbsp;</span></div>').appendTo(calendar);
        }
        titleA.appendTo(div);
        titleB.appendTo(div);
        calendar.appendTo(div);
        bottom.appendTo(div);
        jQuery.calendar.instance = div;
    })();
}

/*
 * 作者：顾燕兵
 * 版本：0.1.0
 *
 * 使用方法：
 * 1：普通方式，无任何限制
 * $("#id").calendar();
 *
 * 2：级联方式，结束日期大于开始日期
 * $("#startDate").calendar({
 onChange:function() {
 if ($("#startDate").val() == '') {
 $("#endDate").val('');
 } else {
 if ($.parseDate($("#startDate").val()).getTime() >= $.parseDate($("#endDate").val()).getTime() || ($.parseDate($("#startDate").val()).getTime() + 30 * 24 * 60 * 60 * 1000) < $.parseDate($("#endDate").val()).getTime()) {
 $("#endDate").val('');
 }

 if ($("#endDate").val() == '') {
 $("#endDate").focus();
 }
 }
 });

 $("#endDate").calendar({showClearButton:false,showTodayButton:false,prevDayFromInput:$("#startDate"),
 beginDateFn:function() {
 var date = $.parseDate($("#startDate").val());
 return new Date(date.getTime() + 24 * 60 * 60 * 1000);
 });
 *
 * 3：参数说明
 * calendarClass：自定义样式名
 * showPrevDay：（true/false）是否显示今天以前的日期，默认为“true”
 * readOnly：（true/false）编辑框是否只读，默认为“true”
 * showClearButton:（true/false）显示清除按钮，默认为“true”
 * showTodayButton:（true/false）显示今天按钮，默认为“true”
 * onChange:（function(){}）日期被改变时候，触发的事件
 * prevDayFromInput:日期从指定次文本框的内容开始
 * beginDateFn:获取开始日期的方法
 * endDateFn:获取结束日期的方法
 * isDisabledFn：调用此方法判断日期是否有效
 * */
