﻿///<reference path="UzaiCalendarGlobal.js" />

/*
*悠哉旅游网javascript日期控件
*功能：根据displayDate(要显示的日期)和jsonArrayay(Ajax获取的数据)生成日历控件
*版权所有：悠哉旅游网
*代码编写：李俊
*时间：2009-2-11
*版本：2.0
*/

function changeMonth(theobject) {
    ///<summary>鼠标经过翻页格切换CSS</summary>
    ///<param name="theobject">需要切换CSS的对象</param>
    return function() {
        if (theobject.className != "nomonth") {
            theobject.className = "changemonth";
        }
    }

}

function changeMonthOver(theobject) {
    ///<summary>鼠标移开翻页格切换CSS</summary>
    ///<param name="theobject">需要切换CSS的对象</param>
    return function() {
        if (theobject.className != "nomonth") {
            theobject.className = "hasmonth";
        }
    }
}

function changeMonthDownOver(theobject, theobject2, theobject3, theobject4) {
    ///<summary>鼠标按下时翻页格切换CSS</summary>
    ///<param name="theobject" >需要禁用的对象,加载不能向前翻页的CSS样式</param>
    ///<param name="theobject2">需要禁用的对象,加载不能向前翻页的CSS样式</param>
    ///<param name="theobject3">需要启用的对象,加载可以向前翻页的CSS样式</param>
    ///<param name="theobject4">需要启用的对象,加载可以向前翻页的CSS样式</param>
    return function() {
        theobject.className = "nomonth";
        theobject2.className = "nomonth";
        theobject3.className = "hasmonth";
        theobject4.className = "hasmonth";
    }
}

function changeDateMouseOver(theobject) {
    ///<summary>点击和鼠标经过时，切换有价格的日期单元格的样式</summary>
    ///<param name="theobject">需要切换CSS的对象</param>
    return function() {
        theobject.className = "selectprice";
    }
}

function changeDateMouseOut(theobject) {
    ///<summary>鼠标移开时，切换有价格的日期单元格的样式</summary>
    ///<param name="theobject">需要切换CSS的对象</param>
    return function() {
        theobject.className = "hasprice";
    }
}

function preMonth() {
    ///<summary>上翻2个月</summary>
    return function() {
        if (document.getElementById("leftPre").className != "nomonth") {
            displayDate = new Date(displayDate.getFullYear(), displayDate.getMonth() - 2, 1);
            setDate(displayDate);
            document.getElementById("leftPre").className = "nomonth";
            document.getElementById("rightPre").className = "nomonth";
            document.getElementById("leftNext").className = "hasmonth";
            document.getElementById("rightNext").className = "hasmonth";
        }
        else {
            return false;
        }
    }
}

function nextMonth() {
    ///<summary>下翻2个月</summary>
    return function() {
        if (document.getElementById("leftNext").className != "nomonth") {
            displayDate = new Date(displayDate.getFullYear(), displayDate.getMonth() + 2, 1);
            setDate(displayDate);
            document.getElementById("leftPre").className = "hasmonth";
            document.getElementById("rightPre").className = "hasmonth";
            document.getElementById("leftNext").className = "nomonth";
            document.getElementById("rightNext").className = "nomonth";
        }
        else {
            return false;
        }
    }
}
function takeValue(displayyear, displaymonth, displayday, bookprice, bookchild) {
    ///<summary>将在日历中取得的行程信息存入文本框</summary>
    ///<param name="displayyear">年</param>
    ///<param name="displaymonth">月</param>
    ///<param name="displayday">日</param>
    ///<param name="bookprice">价格</param>
    return function() {
        //document.getElementById("_hidSDate").value = displayyear + "-" + (displaymonth + 1) + '-' + displayday;
        window.location.href = "#_dingWeiForm";
        if (displaymonth + 1 < 10 && displayday < 10) {
            document.getElementById("0" + (displaymonth + 1) + "-" + "0" + displayday).selected = true;
        }
        else if (displaymonth + 1 < 10 && displayday >= 10) {
            document.getElementById("0" + (displaymonth + 1) + "-" + displayday).selected = true;
        }
        else if (displaymonth + 1 >= 10 && displayday < 10) {
            document.getElementById((displaymonth + 1) + "-" + "0" + displayday).selected = true;
        }
       else {
        document.getElementById((displaymonth + 1) + "-"+ displayday).selected = true;
       	 }
        document.getElementById("_hidChenRen").value = bookprice;
        document.getElementById("_hidErTong").value = bookchild;
	}
}

function clearBody() {
    ///<summary>清空左右表体</summary>
    if (document.getElementById("leftbodytr1")) {
        for (xi = 0; xi < 6; xi++) {
            var trs = document.getElementById("leftbodytr" + xi + "");
            document.getElementById("leftBody").removeChild(trs);
        }
    }
    if (document.getElementById("rightbodytr1")) {
        for (yi = 0; yi < 6; yi++) {
            var rtrs = document.getElementById("rightbodytr" + yi + "");
            document.getElementById("rightBody").removeChild(rtrs);
        }
    }
}


function setDate(thedate) {
    ///<summary>根据displayDate,jsonArrayay对象生成日历</summary>
    ///<param name="thedate">当前显示日期</param>
    clearBody();   //清空左右日历
    setOneMonth("left", thedate);  //画左边日历
    //右边日历参数赋值
    var rnewDate = new Date(thedate.getFullYear(), thedate.getMonth() + 1, 1); //当前Date加1个月
    setOneMonth("right", rnewDate); //画右边日历
}


function setOneMonth(prefix, newdate) {
    ///<summary>画一个月的日历</summary>
    ///<param name="prefix">日历中所用到的标记的前缀</param>
    var newDate = newdate;                                                                                       //当前Date资讯
    var ynow = newDate.getFullYear();                                                                      //年份
    var mnow = newDate.getMonth();                                                                      //月份
    var monthFirstDay = new Date(ynow, mnow, 1);                                                 //当月第一天Date资讯
    var firstDay = monthFirstDay.getDay();                                                                //当月第一天星期几
    m_days[1] = 28 + is_leap(ynow);                                                                               //如果是闰年，二月份加1天
    var thecalendartitle = document.getElementById(prefix + "Title");
    thecalendartitle.innerHTML = ynow + "&nbsp;年&nbsp;" + (mnow + 1) + "&nbsp;月";

    for (i = 0; i < 6; i++) {
        var bodys = document.getElementById(prefix + "Body");
        var newRow = document.createElement("tr");
        newRow.id = prefix + "bodytr" + i;
        newRow.className = "daterow";
        for (k = 0; k < 7; k++) {             //表格每行的单元格
            idx = i * 7 + k;                       //单元格自然序列号
            date_str = idx - firstDay + 1;  //计算日期
            (date_str <= 0 || date_str > m_days[mnow]) ? date_str = "&nbsp;" : date_str = idx - firstDay + 1; //过滤无效日期（小于等于零的、大于月总天数的）
            var newCell = document.createElement("td");
            if (date_str > 0) {
                newCell.id = prefix + "td" + date_str + "";
                newCell.innerHTML = "<a id='" + prefix + "a" + date_str + "'>" + date_str + "<p class='calendar' id='" + prefix + "p" + date_str + "' /><p class='child' id='child" + prefix + "p" + date_str + "' /></a>";
            }
            else {
                newCell.innerHTML = "" + date_str + "<p class='calendar'></p>";
            }
            newCell.className = "no_date";
            //如果是今天，加上今天的样式类
            if (date_str != "&nbsp;") {
                var thisdate = new Date(ynow, mnow, date_str); if (thisdate > staticDate) { newCell.className = "no_price"; }
                else if (!(thisdate < staticDate)) {
                    newCell.className = "today";
                    newCell.innerHTML = "" + date_str + "<p class='calendar' id='" + prefix + "p" + date_str + "' class='chineseToday' name='" + prefix + "pname" + date_str + "' >今天</p>";
                }
            }
            newRow.appendChild(newCell);
        }
        bodys.appendChild(newRow);
    }

    var jsonLength = 0;
    while (json.getdata[jsonLength]) {
        jsonArrayay = json.getdata[jsonLength].dates.split(",");

        if (jsonArrayay.length > 1) {  //如果该数据中的日期信息超过1个
            for (count = 0; count < jsonArrayay.length; count++) {
                addPrice(prefix, count, newDate, jsonLength);
            }
        }
        else if (jsonArrayay.length < 2) {  //如果该数据中的日期信息小于2个
            addPrice(prefix, jsonLength, newDate, 0);
        }
        jsonLength++;
    }
}

function addPrice(prefix, count, thedate, jl) {
    ///<summary>根据JSON数据中单一日期信息是否匹配当前显示日期来标明单价并切换CSS</summary>
    ///<param name="count">计数器</param>
    var strdate = null;
    var leftprice = null;                             //获得该组出行日期的成人价格
    var childprice = null;                              //获得改组出行日期的儿童价格
    if (jsonArrayay.length > 1) {
        strdate = jsonArrayay[count].split("/")                     //将日期拆分
        leftprice = json.getdata[jl].prices;
        childprice = json.getdata[jl].child;
    } else {
        strdate = json.getdata[count].dates.split("/");
        leftprice = json.getdata[count].prices;
        childprice = json.getdata[count].child;
    }
    m_days[1] = 28 + is_leap(strdate[0]);                                            //如果是闰年，更改2月份的天数

    if (!isNumber(strdate[1])) {                                                   //月份不是数字，判断年和日
        if (isAt(strdate[1]))  //月份是@开头的
        {
            if (strdate[0] == thedate.getFullYear()) //如果显示年份和数据年份相同
            {
                for (leftindex = 1; leftindex <= m_days[thedate.getMonth()]; leftindex++)  //获得当前显示月份的天数
                {

                    var dynamicdate = new Date(thedate.getFullYear(), thedate.getMonth(), leftindex);  //遍历当前月份的日期

                    if (dynamicdate > staticDate) //如果比今天大，就加上价格
                    {
                        var lp = document.getElementById(prefix + "p" + leftindex);
			var ttt =""
			if(json.baoernai[dynamicdate.format("yyyy-MM-dd")]!=undefined)
			{
				ttt=json.baoernai[dynamicdate.format("yyyy-MM-dd")];
				if(ttt=="包位已满")
				{
					$(lp).attr("class","");
				}
			}
                        lp.innerHTML = "￥" + leftprice+"<br/>"+ttt;
			
                        var ltdd = document.getElementById(prefix + "td" + leftindex);
                        ltdd.onclick = takeValue(thedate.getFullYear(), thedate.getMonth(), leftindex, leftprice, childprice);
                        ltdd.className = "hasprice";
                        ltdd.onmouseover = changeDateMouseOver(ltdd);
                        ltdd.onmouseout = changeDateMouseOut(ltdd);

                        var la = document.getElementById(prefix + "a" + leftindex);
                        la.setAttribute("href", "javascript:checkform2();");
                        la.style.display = "block";
                        var cp = document.getElementById("child" + prefix + "p" + leftindex);
                        cp.innerHTML = "￥" + childprice;
                    }
                }
            }
        }
        else if (isPlus(strdate[1]))  //月份是+号开头的数字
        {
            if (strdate[0] == thedate.getFullYear()) //如果显示年份和数据年份相同
            {
                var leftplusdate = new Date(thedate.getFullYear(), thedate.getMonth(), strdate[1].substring(1));
                if (leftplusdate > staticDate) {
                    var lpp = document.getElementById(prefix + "p" + strdate[1].substring(1));
                    var ttt =""
			if(json.baoernai[leftplusdate.format("yyyy-MM-dd")]!=undefined)
			{
				ttt=json.baoernai[leftplusdate.format("yyyy-MM-dd")];
				if(ttt=="包位已满")
				{
					$(lpp).attr("class","");
				}
			}
                        lpp.innerHTML = "￥" + leftprice+"<br/>"+ttt;
                    var ltdd = document.getElementById(prefix + "td" + strdate[1].substring(1));
                    ltdd.onclick = takeValue(thedate.getFullYear(), thedate.getMonth(), strdate[1].substring(1), leftprice, childprice);
                    ltdd.className = "hasprice";
                    ltdd.onmouseover = changeDateMouseOver(ltdd);
                    ltdd.onmouseout = changeDateMouseOut(ltdd);

                    var la = document.getElementById(prefix + "a" + strdate[1].substring(1));
                    la.setAttribute("href", "javascript:checkform2();");
                    la.style.display = "block";

                    var cp = document.getElementById("child" + prefix + "p" + strdate[1].substring(1));
                    cp.innerHTML = "￥" + childprice;
                }
            }
        }
        else   //月份是-号开头的数字
        {
            leftminusdate = null;
            if (strdate[0] == thedate.getFullYear())//如果显示年份和数据年份相同
            {
                leftminusdate = new Date(thedate.getFullYear(), thedate.getMonth(), 1);
                leftfirstweekday = strdate[1].substring(1); //数据中是每周几
                if (leftfirstweekday > 6) {
                    leftfirstweekday = 0;
                }
                firstDay = leftminusdate.getDay();  //计算出当月的第一天是星期几
                date_str = 31;  //随便取个比7大的值，跟后面循环里得到的数做比较用。
                //计算出每月的周几
                for (i = 0; i < 6; i++) {
                    for (k = 0; k < 7; k++) {
                        idx = i * 7 + k;
                        if (k == leftfirstweekday && (idx - firstDay + 1) > 0 && (idx - firstDay + 1) <= m_days[thedate.getMonth()]) {
                            date_str = idx - firstDay + 1;
                            if ((new Date(thedate.getFullYear(), thedate.getMonth(), date_str)) > staticDate) {
					var ddd = new Date(thedate.getFullYear(), thedate.getMonth(), date_str);
                                var lpp = document.getElementById(prefix + "p" + date_str);
					 var ttt ="";
			if(json.baoernai[ddd.format("yyyy-MM-dd")]!=undefined)
			{
				ttt=json.baoernai[ddd.format("yyyy-MM-dd")];
				if(ttt=="包位已满")
				{
					$(lpp).attr("class","");
				}
			}
                                lpp.innerHTML = "￥" + leftprice+"<br/>"+ttt;
				
                                var ltdd = document.getElementById(prefix + "td" + date_str);
                                ltdd.onclick = takeValue(thedate.getFullYear(), thedate.getMonth(), date_str, leftprice, childprice);
                                ltdd.className = "hasprice";
                                ltdd.onmouseover = changeDateMouseOver(ltdd);
                                ltdd.onmouseout = changeDateMouseOut(ltdd);

                                var la = document.getElementById(prefix + "a" + date_str);
                                la.setAttribute("href", "javascript:checkform2();");
                                la.style.display = "block";

                                var cp = document.getElementById("child" + prefix + "p" + date_str);
                                cp.innerHTML = "￥" + childprice;

                            }
                        }
                    }
                }
            }
        }
    } //if结束
    else if (isNumber(strdate[1])) {                                   //月份是数字，判断年和日
        if (!isNumber(strdate[2]))  //如果日期不是数字
        {

            if (isAt(strdate[2])) {
                if (strdate[0] == thedate.getFullYear() && strdate[1] == thedate.getMonth() + 1) //如果显示年月和数据年月相同
                {
                    for (leftindex = 1; leftindex <= m_days[thedate.getMonth()]; leftindex++)  //获得当前显示月份的天数
                    {
                        var dynamicdate = new Date(thedate.getFullYear(), thedate.getMonth(), leftindex);  //遍历当前月份的日期

                        if (dynamicdate > staticDate) //如果比今天大，就加上价格
                        {
                            var lpp = document.getElementById(prefix + "p" + leftindex);
				var ttt =""
			if(json.baoernai[dynamicdate.format("yyyy-MM-dd")]!=undefined)
			{
				ttt=json.baoernai[dynamicdate.format("yyyy-MM-dd")];
				if(ttt=="包位已满")
				{
					$(lpp).attr("class","");
				}
			}
                            lpp.innerHTML = "￥" + leftprice+"<br/>"+ttt;
				
                            var ltdd = document.getElementById(prefix + "td" + leftindex);
                            ltdd.onclick = takeValue(thedate.getFullYear(), thedate.getMonth(), leftindex, leftprice, childprice);
                            ltdd.className = "hasprice";
                            ltdd.onmouseover = changeDateMouseOver(ltdd);
                            ltdd.onmouseout = changeDateMouseOut(ltdd);

                            var la = document.getElementById(prefix + "a" + leftindex);
                            la.setAttribute("href", "javascript:checkform2();");
                            la.style.display = "block";
                            var cp = document.getElementById("child" + prefix + "p" + leftindex);
                            cp.innerHTML = "￥" + childprice;
                        }
                    }
                }
            }
            else if (isMinus(strdate[2])) {
                if (strdate[0] == thedate.getFullYear() && strdate[1] == thedate.getMonth() + 1) {
                    leftminusdate = new Date(thedate.getFullYear(), thedate.getMonth(), 1);
                    leftfirstweekday = strdate[2].substring(1); //数据中是每周几
                    if (leftfirstweekday > 6) {
                        leftfirstweekday = 0;
                    }
                    firstDay = leftminusdate.getDay();  //计算出当月的第一天是星期几
                    date_str = 31;  //随便取个比7大的值，跟后面循环里得到的数做比较用。
                    //计算出每月的第一个周几
                    for (i = 0; i < 6; i++) {
                        for (k = 0; k < 7; k++) {
                            idx = i * 7 + k;
                            if (k == leftfirstweekday && (idx - firstDay + 1) > 0 && (idx - firstDay + 1) <= m_days[thedate.getMonth()]) {
                                date_str = idx - firstDay + 1;
                                if ((new Date(thedate.getFullYear(), thedate.getMonth(), date_str)) > staticDate) {
					var ddd=new Date(thedate.getFullYear(), thedate.getMonth(), date_str);
                                    var lpp = document.getElementById(prefix + "p" + date_str);
					var ttt =""
			if(json.baoernai[ddd.format("yyyy-MM-dd")]!=undefined)
			{
				ttt=json.baoernai[ddd.format("yyyy-MM-dd")];
				if(ttt=="包位已满")
				{
					$(lpp).attr("class","");
				}
			}
                                    lpp.innerHTML = "￥" + leftprice+"<br/>"+ttt;
					
                                    var ltdd = document.getElementById(prefix + "td" + date_str);
                                    ltdd.onclick = takeValue(thedate.getFullYear(), thedate.getMonth(), date_str, leftprice, childprice);
                                    ltdd.className = "hasprice";
                                    ltdd.onmouseover = changeDateMouseOver(ltdd);
                                    ltdd.onmouseout = changeDateMouseOut(ltdd);

                                    var la = document.getElementById(prefix + "a" + date_str);
                                    la.setAttribute("href", "javascript:checkform2();"); la.style.display = "block";

                                    var cp = document.getElementById("child" + prefix + "p" + date_str);
                                    cp.innerHTML = "￥" + childprice;

                                }
                            }
                        }
                    }
                }
            }
        }
        else if (isNumber(strdate[2])) {
            if (strdate[0] == thedate.getFullYear() && strdate[1] == thedate.getMonth() + 1) //如果显示年份和数据年份相同
            {
                var leftnumdate = new Date(thedate.getFullYear(), thedate.getMonth(), strdate[2]);
                if (leftnumdate > staticDate) {
                    var lpp = document.getElementById(prefix + "p" + strdate[2]);
var ttt =""
			if(json.baoernai[leftnumdate.format("yyyy-MM-dd")]!=undefined)
			{
				ttt=json.baoernai[leftnumdate.format("yyyy-MM-dd")];
				if(ttt=="包位已满")
				{
					$(lpp).attr("class","");
				}
			}
                    lpp.innerHTML = "￥" + leftprice+"<br/>"+ttt;
			
                    var ltdd = document.getElementById(prefix + "td" + strdate[2]);
                    ltdd.onclick = takeValue(thedate.getFullYear(), thedate.getMonth(), strdate[2], leftprice, childprice);
                    ltdd.className = "hasprice";
                    ltdd.onmouseover = changeDateMouseOver(ltdd);
                    ltdd.onmouseout = changeDateMouseOut(ltdd);

                    var la = document.getElementById(prefix + "a" + strdate[2]);
                    la.setAttribute("href", "javascript:checkform2();"); la.style.display = "block";

                    var cp = document.getElementById("child" + prefix + "p" + strdate[2]);
                    cp.innerHTML = "￥" + childprice;
                }
            }
        }
    } //else if 结束
}


function createTable() {
    ///<summary>根据网页元素创建日历</summary>
    if (document.getElementById(id_div) && !document.getElementById("mainCalendarTable")) {
        var arrWeek = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); //每周几
        var divCalendar = document.getElementById(id_div); //需要显示日期控件的DIV

        //创建主表
        divCalendar.innerHTML = '<table id="mainCalendarTable"><tbody id="mainCalendarBody"></tbody></table>';
        var mainTable = document.getElementById("mainCalendarTable");
        mainTable.className = "package_maincalendar";
        var mainBody = document.getElementById("mainCalendarBody");
        var mainRow = document.createElement("tr");
        var mainCellOne = document.createElement("td");
        var mainCellTwo = document.createElement("td");

        //创建左表
        var lefttable = document.createElement("table");
        lefttable.id = "leftTable";
        lefttable.cellspacing = 0;
        lefttable.cellpadding = 0;
        lefttable.className = "package_calendar";
        var lefttablehead = document.createElement("thead");
        var leftbody = document.createElement("tbody");
        leftbody.id = "leftBody";
        //左表表头
        for (lefttri = 0; lefttri < 2; lefttri++) {
            var leftnewrow = document.createElement("tr");
            leftnewrow.id = "lefttri" + lefttri;
            leftnewrow.className = "titlerow";
            if (lefttri < 1) {
                var leftTheadPre = document.createElement("th");
                leftTheadPre.innerHTML = "←";
                leftTheadPre.id = "leftPre";
                leftTheadPre.className = "nomonth";
                leftTheadPre.onclick = preMonth();

                var leftTheadTitle = document.createElement("th");
                leftTheadTitle.id = "leftTitle";
                leftTheadTitle.innerHTML = "&nbsp;";
                leftTheadTitle.colSpan = 5;
                leftTheadTitle.className = "monthName";
                var leftTheadNext = document.createElement("th");
                leftTheadNext.innerHTML = "→";
                leftTheadNext.id = "leftNext";
                leftTheadNext.className = "hasmonth";
                leftTheadNext.onclick = nextMonth();

                //左表的翻月切换CSS事件--鼠标悬停和移开事件
                leftTheadPre.onmouseover = changeMonth(leftTheadPre);
                leftTheadPre.onmouseout = changeMonthOver(leftTheadPre);
                leftTheadNext.onmouseover = changeMonth(leftTheadNext);
                leftTheadNext.onmouseout = changeMonthOver(leftTheadNext);

                leftnewrow.appendChild(leftTheadPre);
                leftnewrow.appendChild(leftTheadTitle);
                leftnewrow.appendChild(leftTheadNext);
            }
            if (lefttri >= 1) {
                leftnewrow.className = "weekday";
                for (leftweekdays = 0; leftweekdays < 7; leftweekdays++) {
                    var leftWeek = document.createElement("th");
                    leftWeek.innerHTML = arrWeek[leftweekdays];
                    leftWeek.style.cursor = "default";
                    if (leftweekdays == 0) { leftWeek.className = "sunday"; }
                    else if (leftweekdays == 6) { leftWeek.className = "saturday"; }
                    leftnewrow.appendChild(leftWeek);
                }
            }
            lefttablehead.appendChild(leftnewrow);
        }
        lefttable.appendChild(lefttablehead);
        lefttable.appendChild(leftbody);

        //创建右表
        var righttable = document.createElement("table");
        righttable.id = "rightTable";
        righttable.className = "package_calendar";
        var righttablehead = document.createElement("thead");
        var rightbody = document.createElement("tbody");
        rightbody.id = "rightBody";
        //右表表头
        for (righttri = 0; righttri < 2; righttri++) {
            var rightnewrow = document.createElement("tr");
            rightnewrow.id = "righttri" + righttri;
            if (righttri < 1) {
                rightnewrow.className = "titlerow";
                var rightTheadPre = document.createElement("th");
                rightTheadPre.innerHTML = "←";
                rightTheadPre.className = "nomonth";
                rightTheadPre.id = "rightPre";
                rightTheadPre.onclick = preMonth();
                rightTheadPre.onmouseover = changeMonth(rightTheadPre);
                rightTheadPre.onmouseout = changeMonthOver(rightTheadPre);
                var rightTheadTitle = document.createElement("th");
                rightTheadTitle.id = "rightTitle";
                rightTheadTitle.innerHTML = "&nbsp;";
                rightTheadTitle.colSpan = 5;
                rightTheadTitle.className = "monthName";
                var rightTheadNext = document.createElement("th");
                rightTheadNext.innerHTML = "→";
                rightTheadNext.className = "hasmonth";
                rightTheadNext.id = "rightNext";
                rightTheadNext.onclick = nextMonth();
                rightTheadNext.onmouseover = changeMonth(rightTheadNext);
                rightTheadNext.onmouseout = changeMonthOver(rightTheadNext);
                rightnewrow.appendChild(rightTheadPre);
                rightnewrow.appendChild(rightTheadTitle);
                rightnewrow.appendChild(rightTheadNext);
            }
            if (righttri >= 1) {
                rightnewrow.className = "weekday";
                for (rightweekdays = 0; rightweekdays < 7; rightweekdays++) {
                    var rightWeek = document.createElement("th");
                    rightWeek.style.cursor = "default";
                    rightWeek.innerHTML = arrWeek[rightweekdays];
                    if (rightweekdays == 0) { rightWeek.className = "sunday"; }
                    else if (rightweekdays == 6) { rightWeek.className = "saturday"; }
                    rightnewrow.appendChild(rightWeek);
                }
            }
            righttablehead.appendChild(rightnewrow);
        }

        righttable.appendChild(righttablehead);
        righttable.appendChild(rightbody);
        mainCellOne.appendChild(lefttable);
        mainCellTwo.appendChild(righttable);
        mainRow.appendChild(mainCellOne);
        mainRow.appendChild(mainCellTwo);
        mainBody.appendChild(mainRow);
        setDate(displayDate);
    }
    else {
        return;
    }
}

//格式化日期方法扩展
Date.prototype.format = function(mask) {

    var d = this;

    var zeroize = function(value, length) {

        if (!length) length = 2;

        value = String(value);

        for (var i = 0, zeros = ''; i < (length - value.length); i++) {

            zeros += '0';

        }

        return zeros + value;

    };

    return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function($0) {

        switch ($0) {

            case 'd': return d.getDate();

            case 'dd': return zeroize(d.getDate());

            case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][d.getDay()];

            case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];

            case 'M': return d.getMonth() + 1;

            case 'MM': return zeroize(d.getMonth() + 1);

            case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];

            case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];

            case 'yy': return String(d.getFullYear()).substr(2);

            case 'yyyy': return d.getFullYear();

            case 'h': return d.getHours() % 12 || 12;

            case 'hh': return zeroize(d.getHours() % 12 || 12);

            case 'H': return d.getHours();

            case 'HH': return zeroize(d.getHours());

            case 'm': return d.getMinutes();

            case 'mm': return zeroize(d.getMinutes());

            case 's': return d.getSeconds();

            case 'ss': return zeroize(d.getSeconds());

            case 'l': return zeroize(d.getMilliseconds(), 3);

            case 'L': var m = d.getMilliseconds();

                if (m > 99) m = Math.round(m / 10);

                return zeroize(m);

            case 'tt': return d.getHours() < 12 ? 'am' : 'pm';

            case 'TT': return d.getHours() < 12 ? 'AM' : 'PM';

            case 'Z': return d.toUTCString().match(/[A-Z]+$/);

                // Return quoted strings with the surrounding quotes removed   

            default: return $0.substr(1, $0.length - 2);

        }

    });

};  
