﻿LMA_CONST = {
    vistaDateURL: '/order.aspx',
    defaultInputUser: '用户名',
    defaultInputPass: ''
}

LMA_calendar = function (d) {
    var obj = this;
    this.year = -1;
    this.month = -1;
    this.day = -1;
    this.maxDay = -1;

    this.mDays = new Array(31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31);

    this.isLeap = function (year) {
        return (year % 100 == 0 ? res = (year % 400 == 0 ? 1 : 0) : res = (year % 4 == 0 ? 1 : 0));
    }

    this.pad = function (str, len) {
        str = String(str);
        if (str.length < len) {
            for (n = 0; n < len - str.length; n++) {
                str = '0' + str;
            }
        }
        return str;
    }

    this.set = function (y, m, d) {
        this.year = parseInt(y);
        this.month = parseInt(m) - 1;
        this.day = parseInt(d);
        if (this.year < 2010 || this.month < 0 || this.month > 11) {
            this.year = 2010;
            this.month = 0;
            this.day = -1;
            return false;
        }

        this.maxDay = this.mDays[this.month];

        if (this.month == 1) {
            this.maxDay = this.maxDay + this.isLeap(this.year);
        }

        var temp = new Date(this.year, this.month, 1);
        this.firstDay = temp.getDay();
    }

    this.setDaysDom = function () {
        var countRow = 6;
        var calendarDom = $('<table></table>');

        var hdDom = $('<th colspan="7"></th>');

        $('#' + d + '-m').html(this.year + '年' + this.pad(this.month + 1, 2) + '月');
        calendarDom.append($('<tr></tr>').append(hdDom));
        calendarDom.append('<tr class="day"><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>');
        for (i = 0; i < countRow; i++) {
            var rowDom = $('<tr></tr>');
            for (k = 0; k < 7; k++) {
                var dayDom = $('<td></td>');
                var thisday = i * 7 + k - this.firstDay + 1;
                if (thisday > 0 && thisday <= this.maxDay) {
                    dayDom.html(thisday);
                    if (thisday == this.day) {
                        dayDom.addClass("true");
                        dayDom.click(function () {
                            window.location = LMA_CONST['vistaDateURL'].replace('{y}', obj.year).replace('{m}', obj.month + 1).replace('{d}', obj.day);
                        });

                    }
                } else {
                    dayDom.html('&nbsp;');
                }

                rowDom.append(dayDom);
            }
            calendarDom.append(rowDom);

        }

        $('#' + d).append(calendarDom);
    }
}

$(document).ready(function () {
    $('#nav li').hover(
		function () {
		    $(this).children('a').css('background', 'url(/content/images/bg/nav_hover.png) no-repeat');
		    $('#nav li dl').hide();
		    var list = $(this).children('dl');
		    list.show();
		    list.children('dt').hover(
				function () {
				    $('#nav li dl dt p').hide();
				    $(this).children('p').show();
				},
				function () {
				    $('#nav li dl dt p').hide();
				}
			)
		},
		function () {
		    $(this).children('a').css('background', '');
		    $(this).children('dl').hide();
		}
	);

    $('.input-user').val(LMA_CONST['defaultInputUser']);
    $('.input-user').focus(function () {
        this.value = this.value == LMA_CONST['defaultInputUser'] ? '' : this.value;
    });
    $('.input-user').blur(function () {
        this.value = this.value || LMA_CONST['defaultInputUser'];
    });
    $('.input-pass').val(LMA_CONST['defaultInputPass']);
    $('.input-pass').focus(function () {
        this.value = this.value == LMA_CONST['defaultInputPass'] ? '' : this.value;
    });
    $('.input-pass').blur(function () {
        this.value = this.value || LMA_CONST['defaultInputPass'];
    });
    $('.con-nobg ol li:odd').addClass('light');
});



