define("$calendar",["$s"],function(){

	/*******************************************************************************
	 * 日期资料
	 ******************************************************************************/
	
	var g_monthName = new Array("正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月");
	
	var tInfo = new Array(0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950,
		0x16554, 0x056a0, 0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250,
		0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0,
		0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,
		0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,
		0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0,
		0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0,
		0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50,
		0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0,
		0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540,
		0x0b6a0, 0x195a6, 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50,
		0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3,
		0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, 0x0d954,
		0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,
		0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176,
		0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6,
		0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7,
		0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0,
		0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0,
		0x14b63);
		
	var minYear = 1901;
	var maxYear = 2049;
	var solarMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var Gan = new Array("甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸");
	var Zhi = new Array("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥");
	var Animals = new Array("鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗",
			"猪");
	var solarTerm = new Array("小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏",
			"小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬",
			"小雪", "大雪", "冬至");
	var sTermInfo = new Array(0, 21208, 42467, 63836, 85337, 107014, 128867,
			150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033,
			353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758);
	var nStr1 = new Array('日', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十');
	var nStr2 = new Array('初', '十', '廿', '卅', '□');

	var sFtv = new Array("0101*元旦&元旦(新年)", "0106 &中国第13亿人口日", "0108 &周恩来逝世纪念日",
		"0121 &列宁逝世纪念日 国际声援南非日", "0202 &世界湿地日", "0207 &京汉铁路罢工纪念日(1923)",
		"0210 &国际气象节", "0214 情人节&西方情人节(圣瓦伦丁节)", "0215 &中国12亿人口日(1995)",
		"0219 &邓小平逝世纪念日(1997)", "0221 &国际母语日(2000) 反对殖民制度斗争日(1949)",
		"0224 &第三世界青年日", "0228 &世界居住条件调查日(2003)", "0301 &国际海豹日(1983)",
		"0303 &全国爱耳日(2000) 桃花节(日本女孩节)",
		"0305 &学雷锋纪念日(1963) 中国青年志愿者服务日(2000) 周恩来诞辰纪念日(1898)",
		"0308 妇女节&国际劳动妇女节(1910)", "0309 &保护母亲河日", "0311 &国际尊严尊敬日",
		"0312 植树节&中国植树节(1979) 孙中山逝世纪念日(1925)",
		"0314 &国际警察日 白色情人节 马克思逝世纪念日(1883)", "0315 &国际消费者权益日(1983)",
		"0316 &手拉手情系贫困小伙伴全国统一行动日", "0317 &中国国医节(1929) 国际航海日 爱尔兰圣帕特里克节",
		"0318 &全国科技人才活动日",
		"0321 &世界森林日(1972) 消除种族歧视国际日(1966) 世界儿歌日(1976) 世界睡眠日(2001)",
		"0322 &世界水日(1993)", "0323 &世界气象日(1960)", "0324 &世界防治结核病日(1996)",
		"0329 &中国黄花岗七十二烈士殉难纪念", "0330 &巴勒斯坦国土日(1962)",
		"0401 愚人节&国际愚人节 全国爱国卫生运动月(四月) 税收宣传月(四月)", "0402 &国际儿童图书日",
		"0407 &世界卫生日(1955)", "0411 &世界帕金森病日", "0421 &全国企业家活动日(1994)",
		"0422 &世界地球日(1970) 世界法律日 列宁诞辰纪念日(1870)", "0423 &世界图书和版权日(1995)",
		"0424 &亚非新闻工作者日 世界青年反对殖民主义日(1957)", "0425 &全国儿童预防接种宣传日(1986)",
		"0426 &世界知识产权日(2001)", "0430 &世界交通安全反思日", "0501*劳动节&国际劳动节(1889)",
		"0503 &世界新闻自由日", "0504 青年节&中国五四青年节(1939) 科技传播日",
		"0505 &碘缺乏病防治日 日本男孩节 马克思诞辰纪念日(1818) 全国爱眼日(1992)",
		"0508 &世界微笑日 世界红十字日(1948)", "0512 &国际护士节 汶川大地震纪念(2008)",
		"0515 &国际家庭日(1994) 全国碘缺乏病防治日(1994)", "0517 &国际电信日(1969)",
		"0518 &国际博物馆日(1977)", "0520 &全国学生营养日(1990) 全国母乳喂养宣传日(1990)",
		"0522 &生物多样性国际日(2000)", "0525 &非洲解放日(1963)", "0526 &世界向人体条件挑战日",
		"0530 &“五卅”反对帝国主义运动纪念日(1925)", "0531 &世界无烟日(1988) 英国银行休假日",
		"0601 儿童节&国际儿童节(1949)", "0605 &世界环境保护日(1974)", "0606 &世界爱眼日（1996）",
		"0611 &中国人口日（1974）", "0614 &世界献血者日(2005)", "0617 &防治荒漠化和干旱日(1995)",
		"0620 &世界难民日(2001)", "0622 &中国儿童慈善活动日", "0623 &国际奥林匹克日(1948)",
		"0625 &全国土地日(1991)",
		"0626 &国际禁毒日(1987) 国际宪章日(1945) 禁止药物滥用和非法贩运国际日(1987) 支援酷刑受害者国际日(1997)",
		"0630 &世界青年联欢节", "0701 建党节&中国共产党诞辰日(1921) 香港回归纪念日(1997) 国际建筑日(1985)",
		"0702 &国际体育记者日", "0706 &朱德逝世纪念日", "0707 &中国人民抗日战争纪念日(1937)",
		"0711 &世界人口日(1987) 中国航海节", "0726 &世界语创立日", "0728 &第一次世界大战爆发(1914)",
		"0730 &非洲妇女日(1962)", "0801 建军节&中国人民解放军建军节(1927)",
		"0805 &恩格斯逝世纪念日(1895)", "0806 &国际电影节(1932)", "0808 &中国男子节(爸爸节)(1988)",
		"0812 &国际青年日", "0813 &国际左撇子日(1976)", "0815 &日本正式宣布无条件投降日(1945)",
		"0822 &邓小平诞辰纪念日(1904)", "0823 &贩卖黑奴及其废除的国际纪念日", "0826 &全国律师咨询日(1993)",

		"0902 &日本签署无条件投降书日(1945)", "0903 &中国抗日战争胜利纪念日(1945)",
		"0908 &世界扫盲日(1966) 国际新闻工作者日(1958)", "0909 &毛泽东逝世纪念日(1976)",
		"0910 教师节&中国教师节(1985) 世界预防自杀日(2003)", "0914 &世界清洁地球日",
		"0916 &国际臭氧层保护日(1994) 中国脑健康日", "0918 &九·一八事变纪念日(1931)",
		"0920 &国际爱牙日(1989)", "0921 &国际和平日(1981) 世界预防老年性痴呆宣传日(1994)",
		"0927 &世界旅游日(1980)", "0928 &孔子诞辰纪念日", "0930 &国际翻译日(1991)",

		"1001*国庆节&国庆节(1949) 国际音乐日(1980) 国际老人节(1990)",
		"1002*&国庆节假日 国际和平与民主自由斗争日", "1003*&国庆节假日", "1004 &世界动物日",
		"1005 &世界教师日(1944)", "1008 &全国高血压日(1998) 世界视觉日", "1009 &世界邮政日",
		"1010 &辛亥革命纪念日(1911) 世界心理健康日(1992) 世界居室卫生日", "1011 &世界镇痛日(2004)",
		"1012 &世界60亿人口日(1999)",
		"1013 &世界保健日(1950) 中国少年先锋队诞辰日(1949) 世界保健日(1950)", "1014 &世界标准日(1969)",
		"1015 &国际盲人节(白手杖节)", "1016 &世界粮食日", "1017 &世界消除贫困日",
		"1020 &世界骨质疏松日(1997)", "1022 &世界传统医药日", "1024 &联合国日 世界发展新闻日",
		"1025 &抗美援朝纪念日(1950)", "1028 &中国男性健康日(2000)", "1031 &世界勤俭日",
		"1101 万圣节&万圣节 植树造林日", "1106 &防止战争和武装冲突糟蹋环境国际日(2001)",
		"1107 &十月社会主义革命纪念日(1917)", "1108 &中国记者节", "1109 &全国消防安全宣传日",
		"1110 &世界青年节", "1111 光棍节&光棍节 国际科学与和平周",
		"1112 &孙中山诞辰纪念日(1866) 刘少奇逝世纪念日(1969)", "1114 &世界糖尿病日(1995)",
		"1116 &国际宽容日(1995)", "1117 &国际大学生节", "1120 &国际儿童日",
		"1121 &世界问候日(1973) 世界电视日", "1125 &消除对妇女的暴力行为国际日(1999)",
		"1128 &恩格斯诞辰纪念日(1820)", "1129 &声援巴勒斯坦人民国际日(1977)",

		"1201 &世界艾滋病日", "1202 &废除奴隶制世界日", "1203 &世界残疾人日", "1204 &全国法制宣传日",
		"1205 &国际经济和社会发展志愿人员日 世界强化免疫日 世界弱能人士日", "1207 &国际民航日", "1208 &国际儿童电视日",
		"1209 &一二·九运动纪念日(1935) 世界足球日(1863) 国际反腐败日", "1210 &世界人权日(1950)",
		"1211 &世界防治哮喘日(2001)", "1212 &西安事变纪念日(1935)", "1213 &南京大屠杀纪念日(1937)",
		"1215 &世界强化免疫日", "1218 &国际移徙者日(2000)", "1220 &澳门回归纪念日(1999)",
		"1221 &国际篮球日(1981)", "1224 平安夜&平安夜", "1225 圣诞节&圣诞节",
		"1226 &毛泽东诞辰纪念日(1893)", "1229 &国际生物多样性日(1994)")

	// 农历节日 *表示放假日
	var lFtv = new Array("0101*春节&春节 大年初一 弥勒佛诞辰",
			//, "0102*初二&大年初二",
			"0115 元宵节&元宵节", "0505*端午节&端午节", "0707 七夕节&七夕情人节",
			"0715 中元节&中元节", "0815*中秋节&中秋节", "0909 重阳节&重阳节",
			"1208 腊八节&腊八节(释迦如来成道日)", "1223 小年&小年", "0100*除夕&除夕")

	// 某月的第几个星期几
	var wFtv = new Array(
			"0150 &世界麻风日", // 一月的最后一个星期日（月倒数第一个星期日）
			"0351 &全国中小学生安全教育日(1996)", "0440 &世界儿童日(1986)", "0453 &秘书节",
			"0512 &国世界哮喘日(1998)", "0520 母亲节&国际母亲节 救助贫困母亲日", "0530 &全国助残日(1990)",
			"0532 &国际牛奶日(1961)", "0626 &中国文化遗产日(2006)", "0630 父亲节&国际父亲节(1934)",
			"0716 &国际合作节(1995)", "0932 &国际和平日(1981)", "0936 &全民国防教育日(2001)",
			"0940 &国际聋人节(1958)", "0950 &世界海事日 世界心脏病日(2000)", "1011 &国际住房日(1986)",
			"1024 &世界视觉日", "1023 &国际减轻自然灾害日(1990)", "1144 感恩节&感恩节",
			"1220 &国际儿童电视广播日")
	var constellationArr = new Array("水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座",   
		 "天蝎座", "射手座", "摩羯座");
	

	var constellationLinkArr = new Array(	
		"http://astro.women.sohu.com/aquarius.shtml",
		"http://astro.women.sohu.com/pisces.shtml",
		"http://astro.women.sohu.com/aries.shtml",
		"http://astro.women.sohu.com/taurus.shtml",
		"http://astro.women.sohu.com/gemini.shtml",
		"http://astro.women.sohu.com/cancer.shtml",
		"http://astro.women.sohu.com/leo.shtml",
		"http://astro.women.sohu.com/virgo.shtml",
		"http://astro.women.sohu.com/libra.shtml",
		"http://astro.women.sohu.com/scorpius.shtml",
		"http://astro.women.sohu.com/sagittarius.shtml ",
		"http://astro.women.sohu.com/capricornus.shtml");
	
	var constellationEdgeDay = new Array (21, 19, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22);
	
	
	function Ajax(args) {
		this.url = args.url || "";
		this.params = args.params || "";
		this.mime = args.mime || "text/html";
		this.onComplete = args.onComplete || this.defaultOnCompleteFunc;
		this.onLoading= args.onLoading || this.defaultOnLoadingFunc;
		this.onError = args.onError || this.defaultOnErrorFunc;
		this.method = args.method || "post";
		this.loadData();
	}

	Ajax.prototype = {
		READY_STATE_COMPLETE : 4,
		getRequest : function () {
		var funcs = [
			function() {return new ActiveXObject('Msxml2.XMLHTTP')},
			function() {return new ActiveXObject('Microsoft.XMLHTTP')},
			function() {return new XMLHttpRequest()}
		];

		var req = null;
		for (var i = 0; i < funcs.length; i++) {
			var f = funcs[i];
			try {
			req = f();
			break;
			} catch (e) {}
		}

		return req || false;
		},

		parseParams : function () {
		if (typeof (this.params) == "string") {
			return this.params;
		} else {
			var s = "";
			for (var k in this.params) {
			s += k + "=" + this.params[k] + "&";
			}
			return s;
		}
		},

		loadData : function () {
		this.req = this.getRequest();
		
		if (this.req) {
			this.onLoading();
			try {
			var loader = this;
			this.req.onreadystatechange = function () {
				if (loader.req.readyState == loader.READY_STATE_COMPLETE) {
					loader.onComplete.call(loader, loader.req);
				}
			}
			this.req.open(this.method, this.url, true);

			if (this.method == "post") {
				this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			}

			if (this.req.overrideMimeType) {
				this.req.overrideMimeType(this.mime);
			}
			//this.req.send(this.method == "post" ? this.parseParams(this.params) : null);
			} catch (e) {
			// throw e
			this.onError.call(this, e);
			}
		}
		},

		defaultOnCompleteFunc : function () {
		alert(this.req.responseText);
		},

		defaultOnLoadingFunc : function () {
		},

		defaultOnErrorFunc : function (error) {
		alert(error);
		}
	}
	
	/*******************************************************************************
	 * 日期计算
	 ******************************************************************************/

	// ====================================== 根据月份和日期返回星座
	function constellate(month , day ) {
		if (day < constellationEdgeDay[month]) {   
			month = month - 1;   
		}   
		if (month >= 0) {   
			return new Array(constellationArr[month],constellationLinkArr[month]);   
		}   
		return new Array(constellationArr[11],constellationLinkArr[11]);
	}
	// ====================================== 返回农历 y年的总天数
	function lYearDays(y) {
		var i, sum = 348;
		for (i = 0x8000; i > 0x8; i >>= 1)
			sum += (tInfo[y - 1900] & i) ? 1 : 0;
		return (sum + leapDays(y));
	}

	// ====================================== 返回农历 y年闰月的天数
	function leapDays(y) {
		if (leapMonth(y))
			return ((tInfo[y - 1900] & 0x10000) ? 30 : 29);
		else
			return (0);
	}

	// ====================================== 返回农历 y年闰哪个月 1-12 , 没闰返回 0
	function leapMonth(y) {
		return (tInfo[y - 1900] & 0xf);
	}

	// ====================================== 返回农历 y年m月的总天数
	function monthDays(y, m) {
		return ((tInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29);
	}

	// ====================================== 算出农历, 传入日期控件, 返回农历日期控件
	// 该控件属性有 .year .month .day .isLeap
	function Lunar(objDate) {

		var i, leap = 0, temp = 0;
		var offset = (Date.UTC(objDate.getFullYear(), objDate.getMonth(), objDate
				.getDate()) - Date.UTC(1900, 0, 31)) / 86400000;

		for (i = 1900; i <= maxYear && offset > 0; i++) {
			temp = lYearDays(i);
			offset -= temp;
		}

		if (offset < 0) {
			offset += temp;
			i--;
		}

		this.year = i;

		leap = leapMonth(i); // 闰哪个月
		this.isLeap = false;

		for (i = 1; i < 13 && offset > 0; i++) {
			// 闰月
			if (leap > 0 && i == (leap + 1) && this.isLeap == false) {
				--i;
				this.isLeap = true;
				temp = leapDays(this.year);
			} else {
				temp = monthDays(this.year, i);
			}

			// 解除闰月
			if (this.isLeap == true && i == (leap + 1))
				this.isLeap = false;

			offset -= temp;
		}

		if (offset == 0 && leap > 0 && i == leap + 1)
			if (this.isLeap) {
				this.isLeap = false;
			} else {
				this.isLeap = true;
				--i;
			}

		if (offset < 0) {
			offset += temp;
			--i;
		}

		this.month = i;
		this.day = offset + 1;
	}

	// ==============================返回公历 y年某m+1月的天数
	function solarDays(y, m) {
		if (m == 1)
			return (((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0)) ? 29 : 28);
		else
			return (solarMonth[m]);
	}
	// ============================== 传入 offset 返回干支, 0=甲子
	function cyclical(num) {
		return (Gan[num % 10] + Zhi[num % 12]);
	}

	// ============================== 阴历属性
	function calElement(sYear, sMonth, sDay, week, lYear, lMonth, lDay, isLeap,
			cYear, cMonth, cDay) {

		this.isToday = false;
		// 瓣句
		this.sYear = sYear; // 公元年4位数字
		this.sMonth = sMonth; // 公元月数字
		this.sDay = sDay; // 公元日数字
		this.week = week; // 星期, 1个中文
		// 农历
		this.lYear = lYear; // 公元年4位数字
		this.lMonth = lMonth; // 农历月数字
		this.lDay = lDay; // 农历日数字
		this.isLeap = isLeap; // 是否为农历闰月?
		// 八字
		this.cYear = cYear; // 年柱, 2个中文
		this.cMonth = cMonth; // 月柱, 2个中文
		this.cDay = cDay; // 日柱, 2个中文

		this.color = '';

		this.lunarFestival = ''; // 农历节日
		this.solarFestival = ''; // 公历节日

		this.estDayFestival = ''; // 右侧显示的复活节
		this.weekFestival = ''; // 右侧显示的周相关的节日
		this.dateFestival = '';// 右侧显示的日相关的公历节日
		this.lliFestival = '';// 右侧显示的日相关的农历节日

		this.solarTerms = ''; // 节气
	}

	// ===== 某年的第n个节气为几日(从0小寒起算)
	var fixsTerm={"19091":21, "19102":5, "19106":6, "19118":7, "19120":7, "191218":9, "191221":23, "191317":24, "19179":21, "192716":8, "192811":21, "193510":6, "19421":21, "19432":5, "19436":6, "19450":6, "194723":23, "19507":20, "195022":8, "195123":23, "19525":21, "195513":23, "19563":20, "195720":8, "195812":7, "195815":23, "196016":7, "196111":21, "19738":5, "197421":23, "19751":21, "197517":23, "19762":5, "19774":6, "197714":7, "19780":6, "197821":23, "19799":21, "19802":5, "198023":22, "19814":6, "19820":6, "198322":8, "198413":22, "198423":22, "19855":21, "198712":7, "198813":22, "19893":19, "198916":7, "199011":21, "199020":8, "199112":7, "199115":23, "199411":21, "199710":5, "20068":5, "200614":7, "200721":23, "20081":21, "200817":22, "20092":4, "20104":6, "201014":7, "20110":6, "201121":23, "20121":21, "20129":20, "201222":7, "20132":4, "201313":22, "201323":22, "20144":6, "20150":6, "201622":7, "201713":22, "201723":22, "20183":19, "20185":21, "201911":21, "202012":6, "202015":22, "202022":7, "20223":19, "202216":7, "202311":21, "202319":24, "202320":8, "202415":22, "202610":5, "203010":5, "20358":5, "203514":7, "20371":20, "203914":7, "20400":6, "204018":8, "204021":22, "20411":20, "20419":20, "20422":4, "20434":6, "204314":7, "20440":6, "204421":22, "20451":20, "20457":19, "20459":20, "204522":7, "20462":4, "204613":22, "204623":22, "20474":6, "20480":6, "204811":20, "204912":6, "204915":22, "204922":7};
	function sTerm(y, n) {
		if (fixsTerm[y+""+n]){
			return fixsTerm[y+""+n];
		}
		var offDate = new Date((31556925974.7 * (y - 1900) + sTermInfo[n] * 60000)
				+ Date.UTC(1900, 0, 6, 2, 5));
		return (offDate.getUTCDate());
	}

	// ============================== 返回阴历控件 (y年,m+1月)
	/*
	 * 功能说明: 返回整个月的日期资料控件
	 * 
	 * 使用方式: OBJ = new calendar(年,零起算月);
	 * 
	 * OBJ.length 返回当月最大日 OBJ.firstWeek 返回当月一日星期 OBJ.lastWeek 返回当月最后一日星期
	 * 
	 * 由 OBJ[日期].属性名称 即可取得各项值
	 * 
	 * OBJ[日期].isToday 返回是否为今日 true 或 false
	 * 
	 * 其他 OBJ[日期] 属性参见 calElement() 中的注解
	 */
	function calendar(y, m, tY, tM, tD) {

		var sDObj, lDObj, lY, lM, lD = 1, lL, lX = 0, tmp1, tmp2, tmp3, tmp4, tmp5;
		var cY, cM, cD; // 年柱,月柱,日柱
		var lDPOS = new Array(3);
		var n = 0;
		var firstLM = 0;

		sDObj = new Date(y, m, 1, 0, 0, 0, 0); // 当月一日日期

		this.length = solarDays(y, m); // 公历当月天数
		this.firstWeek = sDObj.getDay(); // 公历当月1日星期几
		this.lastWeek = new Date(y, m, this.length, 0, 0, 0, 0).getDay();

		// //////年柱 1900年立春后为庚子年(60进制36)
		if (m < 2)
			cY = cyclical(y - 1900 + 36 - 1);
		else
			cY = cyclical(y - 1900 + 36);
		var term2 = sTerm(y, 2); // 立春日期

		// //////月柱 1900年1月小寒以前为 丙子月(60进制12)
		var firstNode = sTerm(y, m * 2) // 返回当月「节」为几日开始
		cM = cyclical((y - 1900) * 12 + m + 12);

		// 当月一日与 1900/1/1 相差天数
		// 1900/1/1与 1970/1/1 相差25567日, 1900/1/1 日柱为甲戌日(60进制10)
		var dayCyclical = Date.UTC(y, m, 1, 0, 0, 0, 0) / 86400000 + 25567 + 10;

		for ( var i = 0; i < this.length; i++) {

			if (lD > lX) {
				sDObj = new Date(y, m, i + 1); // 当月一日日期
				lDObj = new Lunar(sDObj); // 农历
				lY = lDObj.year; // 农历年
				lM = lDObj.month; // 农历月
				lD = lDObj.day; // 农历日
				lL = lDObj.isLeap; // 农历是否闰月
				lX = lL ? leapDays(lY) : monthDays(lY, lM); // 农历当月最后一天

				if (n == 0)
					firstLM = lM;
				lDPOS[n++] = i - lD + 1;
			}

			// 依节气调整二月分的年柱, 以立春为界
			if (m == 1 && (i + 1) == term2)
				cY = cyclical(y - 1900 + 36);
			// 依节气月柱, 以「节」为界
			if ((i + 1) == firstNode)
				cM = cyclical((y - 1900) * 12 + m + 13);
			// 日柱
			cD = cyclical(dayCyclical + i);

			// sYear,sMonth,sDay,week,
			// lYear,lMonth,lDay,isLeap,
			// cYear,cMonth,cDay
			this[i] = new calElement(y, m + 1, i + 1,
					nStr1[(i + this.firstWeek) % 7], lY, lM, lD++, lL, cY, cM, cD);
		}

		// 节气
		tmp1 = sTerm(y, m * 2) - 1;
		tmp2 = sTerm(y, m * 2 + 1) - 1;
		this[tmp1].solarTerms = solarTerm[m * 2];
		this[tmp2].solarTerms = solarTerm[m * 2 + 1];

		if (m == 3)
			this[tmp1].color = 'red'; // 清明颜色

		// 复活节只出现在3或4月
		if (m == 2 || m == 3) {
			var estDay = new easter(y);
			if (m == estDay.m) {
				this[estDay.d - 1].solarFestival = '复活节';
				this[estDay.d - 1].estDayFestival = "复活节";
			}
		}

		// 月周节日
		for (i in wFtv)
			if (wFtv[i].match(/^(\d{2})(\d)(\d)([\s\*])(.+)$/))
				if (Number(RegExp.$1) == (m + 1)) {
					tmp1 = Number(RegExp.$2);
					tmp2 = Number(RegExp.$3);
					tmp4 = RegExp.$5;
					tmp5 = tmp4.split('&');
					if (tmp5[0].length > 0) {
					if (tmp1 < 5) {
						this[((this.firstWeek > tmp2) ? 7 : 0) + 7 * (tmp1 - 1)
								+ tmp2 - this.firstWeek].solarFestival = tmp5[0];
						this[((this.firstWeek > tmp2) ? 7 : 0) + 7 * (tmp1 - 1)
								+ tmp2 - this.firstWeek].weekFestival = tmp5[1];
					} else {
						tmp1 -= 5;
						tmp3 = (this.firstWeek + this.length - 1) % 7; // 当月最后一天星期?
						this[this.length - tmp3 - 7 * tmp1 + tmp2
								- (tmp2 > tmp3 ? 7 : 0) - 1].solarFestival = tmp5[0];
						this[this.length - tmp3 - 7 * tmp1 + tmp2
								- (tmp2 > tmp3 ? 7 : 0) - 1].weekFestival = tmp5[1];
					}
					}
				}

		// 公历节日
		for (i in sFtv)
			if (sFtv[i].match(/^(\d{2})(\d{2})([\s\*])(.+)$/)){
				tmp4 = RegExp.$4;
				if (Number(RegExp.$1) == (m + 1)) {
					var tmpDay = Number(RegExp.$2) - 1;
					var tmpStar = RegExp.$3;
					tmp5 = tmp4.split('&');
					if (tmp5[0].length >0) {
					this[tmpDay].solarFestival = tmp5[0];
					
					if (tmpStar == '*')
						this[tmpDay].color = 'red';
					}
					if(tmp5[1].length>0)
						this[tmpDay].dateFestival = tmp5[1];
			}
		}

		// 农历节日
		for (i in lFtv)
			if (lFtv[i].match(/^(\d{2})(.{2})([\s\*])(.+)$/)) {
				tmp1 = Number(RegExp.$1) - firstLM;
				if (tmp1 == -11)
					tmp1 = 1;
				if (tmp1 >= 0 && tmp1 < n) {
					tmp2 = lDPOS[tmp1] + Number(RegExp.$2) - 1;
					if (tmp2 >= 0 && tmp2 < this.length
							&& this[tmp2].isLeap != true) {
						tmp4 = RegExp.$4;
						var tmpStar = RegExp.$3;
						tmp5 = tmp4.split('&');
						this[tmp2].lunarFestival += tmp5[0];
						this[tmp2].lliFestival += tmp5[1];
						if (tmpStar == '*')
							this[tmp2].color = 'red';
					}
				}
			}

		// 今日
		//alert(y+","+tY+" -- "+m+","+tM);
		//alert(tD)
		if (y == tY && m == tM)
			this[tD - 1].isToday = true;
	}

	// ======================================= 返回该年的复活节(春分后第一次满月周后的第一主日)
	function easter(y) {

		var term2 = sTerm(y, 5); // 取得春分日期
		var dayTerm2 = new Date(Date.UTC(y, 2, term2, 0, 0, 0, 0)); // 取得春分的公历日期控件(春分一定出现在3月)
		var lDayTerm2 = new Lunar(dayTerm2); // 取得取得春分农历

		if (lDayTerm2.day < 15) // 取得下个月圆的相差天数
			var lMlen = 15 - lDayTerm2.day;
		else
			var lMlen = (lDayTerm2.isLeap ? leapDays(y) : monthDays(y,
					lDayTerm2.month))
					- lDayTerm2.day + 15;

		// 一天等于 1000*60*60*24 = 86400000 毫秒
		var l15 = new Date(dayTerm2.getTime() + 86400000 * lMlen); // 求出第一次月圆为公历几日
		var dayEaster = new Date(l15.getTime() + 86400000 * (7 - l15.getUTCDay())); // 求出下个周日

		this.m = dayEaster.getUTCMonth();
		this.d = dayEaster.getUTCDate();

	}

	// ====================== 中文日期
	function cDay(d) {
		var s;

		switch (d) {
		case 10:
			s = '初十';
			break;
		case 20:
			s = '二十';
			break;
		case 30:
			s = '三十';
			break;
		default:
			s = nStr2[Math.floor(d / 10)];
			s += nStr1[d % 10];
		}
		return (s);
	}
	
	
	/****************************************************************/
	
	function GC(elem,cn,tag){
		if(!elem)	return [];
		tag = tag || "*";
		var list = elem.getElementsByTagName(tag);
		var arr = [];
		for(var i=0;i<list.length;i++){
			var item = list[i];
			var classNames = " "+item.className+" ";
			if(classNames.indexOf(" "+cn+" ") > -1)
				arr.push(item);
		}
		return arr;
	}
	
	function jumpMonth(step,year,month){
		month = +month;
		year = +year;
		month = month + step;
		if(month < 1) return {year:year-1,month:12};
		else if(month > 12) return {year:year+1,month:1};
		return {year:year,month:month};
	}
	
	function cutFestival(str){
		if(str.length <= 4) return str;
		return str.substring(0,3)+"...";
	}
	
	//获取农历日期或节日
	function getLunarDay(src){
		var item = {};
		if(src.solarTerms) item.fest = src.solarTerms;
		else if(src.solarFestival) item.fest = src.solarFestival;
		else if(src.lunarFestival) item.fest = src.lunarFestival;
		else {item.fest = cDay(src.lDay); item.className="";}
		if(item.className !== "") item.className = "calendar_jie";
		return item;
	}
	
	function getAnimal(year){
		var index = (year-1900)%12;
		return Animals[index];
	}
	
	/*******渲染日历HTML*******/
	function renderCalendar(){
		var html = [];
		html.push('<div class="datebox cf" id="'+this.id+'">');
		html.push(renderLeft.call(this));
		html.push(renderRight.call(this));
		html.push('</div>');
		return html.join('');
	}
	
//	function renderRightCont(src){
//		var right = $s.$(this.rightId);
//		var year = this.year;
//		var month = this.month;
//		var day = this.day;
//		if(!src){
//			var tmp = new calendar(year,month-1,2000,1,1);
//			src = tmp[day-1];
//		}
//		if(src){
//			year = src.sYear;
//			month = src.sMonth;
//			day = src.sDay;
//		}
//		
//		var animal = getAnimal(src.lYear);
//		var xingzuo = constellate(month-1,day)[0];
//		
////		var html = [];
////		html.push('<div class="top_txt">');
////		html.push('<div>天气预报</div>');
////		html.push('<h2>'+year+'年'+month+'月</h2>');
////		html.push('<p class="calendar_right_day">'+day+'</p>');
////		html.push('<p class="calendar_right_lunar">');
////		html.push('<span>星期'+src.week+'</span>');
////		html.push('<span>'+src.cYear+'年【'+animal+'年】</span>');
////		html.push('<span>'+g_monthName[src.lMonth-1]+cDay(src.lDay)+'</span>');
////		html.push('<span>'+xingzuo+'</span>');
////		html.push('</p>');
////		html.push('</div>');
////		html.push('<div id="'+this.fitId+'" class="calendar_right_yi cf"></div>');
////		html.push('<div id="'+this.badId+'" class="calendar_right_yi cf"></div>');
////		right.innerHTML = html.join('');
//		gethuangli.call(this,year,month,day);
//	}
	
	/*****渲染右侧*****/
	function renderRight(){
		var html = [];
		html.push('<div id="'+this.rightId+'" class="calendar_right">');
		html.push('</div>');
		return html.join('');
	}
	
	/*******渲染左边********/
	function renderLeft(){
		var html  = [];
		html.push('<div class="calendar_left">');
		html.push(renderTop.call(this));
		html.push(renderCenter.call(this));
		html.push('</div>')
		return html.join('');
	}
	
	/************获取攻略数组*************/
	function getGuide(holidays){
		var guides = [];
		for(var i=0;i<holidays.length;i++){
			var item = holidays[i].guide;
			guides = guides.concat(item);
		}
		return guides;
	}
	
	/************判断攻略*************/
	function testGuide(year,month,day){
		var guide = this.guide;
		var txt = {vacation:"休",work:"班",leave:"请"};
		for(var i=0;i<guide.length;i++){
			var item = guide[i];
			if(item.year == year && item.month == month && item.day == day){
				return {className:"calendar_"+item.type,txt:txt[item.type],type:item.type};
			}
		}
		return "";
	}
	
	/************获取日期类名*************/
	function getClass(src){
		var opts = this.options;
		var month = this.month;
		var cls = [];
		if(src.sMonth != month) cls.push('calendar_other');
		else if( "六日".indexOf(src.week) != -1 ) cls.push('calendar_red');
		var c = testGuide.call(this,src.sYear,src.sMonth,src.sDay);
		if(c) cls.push(c.className);
		if(src.sYear == opts.nyear && src.sMonth == opts.nmonth && src.sDay == opts.nday){
			cls.push('calendar_today');
		}
		if(src.sYear == this.year && src.sMonth == this.month && src.sDay == this.day)
			cls.push('on_date');
		return cls.join(' ');
	}
	
	
	function getCellHTML(item){
		var inner = [];
		inner.push('<div style="width:42px;height:36px;overflow:hidden;" class="calendar_new">');
		inner.push('<a class="'+getClass.call(this,item)+'" href="#" data-year="'+item.sYear+'" data-month="'+item.sMonth+'" data-day="'+item.sDay+'">');
		var guide = testGuide.call(this,item.sYear,item.sMonth,item.sDay);
		if(guide) inner.push('<em class="'+guide.type+'_icon">'+guide.txt+'</em>');
		inner.push('<span class="calendar_new_daynumber">'+item.sDay+'</span>')
		var festObj = getLunarDay(item);
		var festival = festObj.fest;
		inner.push('<span title="'+(festival.length>4?festival:'')+'" class="calendar_new_almanac '+festObj.className+'">'+cutFestival(festival)+'</span>')
		inner.push('</a>')
		inner.push('</div>');
		return inner.join('');
	}
	
	/******渲染日期表格*****/
	function renderTable(flag){
	
		var year = this.year;
		var month = this.month;
		var day = this.day;
		var opt = this.options;
		var nyear = opt.nyear;
		var nmonth = opt.nmonth;
		var nday = opt.nday;
	
	
		var week = "一二三四五六日".split("");
		week[5] = "<span id=\"vocation_week_title\">六</span>";
		week[6] = "<span id=\"vocation_week_title\">日</span>";
	
		var table = $s.$(this.tableId);
		var children = table.childNodes;
		for(var i=children.length-1;i>=0;i--){
			if(children[i].nodeType == 1){
				table.removeChild(children[i]);
			}
		}
		
		var tbody = document.createElement("tbody");
		table.appendChild(tbody);
		
		var tr = document.createElement("tr");
		for(var i=0;i<week.length;i++){
			var th = document.createElement("th");
			th.innerHTML = '<span>'+week[i]+'</span>';
			tr.appendChild(th);
		}
		tbody.appendChild(tr);
		
		var rows = 0;
		var curMonth = new calendar(year,month-1,nyear,nmonth-1,nday);
		this.day = this.day<curMonth.length?this.day:curMonth.length;
		tr = document.createElement("tr");
		tr.className = "pd";
		if(curMonth.firstWeek != 1){
			var prev = jumpMonth(-1,year,month);
			var lastMonth = new calendar(prev.year,prev.month-1,nyear,nmonth-1,nday);
			for(var i=0;i<lastMonth.lastWeek;i++){
				var len = lastMonth.length;
				var item = lastMonth[len-lastMonth.lastWeek+i];
				var td = document.createElement("td");
				td.innerHTML = getCellHTML.call(this,item);
				tr.appendChild(td);
			}
		}
		
		for(var i=0;i<curMonth.length;i++){
			var item = curMonth[i];
			var td = document.createElement("td");
			td.innerHTML = getCellHTML.call(this,item);
			tr.appendChild(td);
			if(item.week == "日"){
				tbody.appendChild(tr);
				rows++;
				tr = document.createElement("tr");
			}
		}
		
		var sy = 7;
		if(curMonth.lastWeek == 0 && rows > 4) sy = 0;
		
		var tableClass = (rows>5||(rows==5&&sy==7))?"calenda_table":"calenda_table calenda_table_mr";
		table.parentNode.className = tableClass;
		
		var current_nextMonth_day = 1;
		var next = jumpMonth(1,year,month);
		var nextMonth = new calendar(next.year,next.month-1,nyear,nmonth-1,nday);
		if(sy > 0){
			for(var i=0;i<7-curMonth.lastWeek;i++){
				var item = nextMonth[i];
				current_nextMonth_day = i;
				var td = document.createElement("td");
				td.innerHTML = getCellHTML.call(this,item);
				tr.appendChild(td);
				if(item.week == "日"){
					tbody.appendChild(tr);
					
					rows++;
					tr = document.createElement("tr");
				}
			}
		}
		
		if(rows < 6){
			//再增加一行，避免只有五行的日历
			for(var j=0;j<7;j++){
				i = ++current_nextMonth_day;
				var item = nextMonth[i];
				var td = document.createElement("td");
				td.innerHTML = getCellHTML.call(this,item);
				tr.appendChild(td);
				if(item.week == "日"){
					tbody.appendChild(tr);
				}
			}
		}
			
		var holidayName = getHolidayName.call(this);
		renderTipCont.call(this,holidayName);
		if(flag){
			renderHolidayHTML.call(this,year);
			renderSelect(this.yselId,"data-year",year);
		}
		renderSelect(this.mselId,"data-month",month);
	}
	
	/****渲染中间部分***/
	function renderCenter(){
		var html = [];
		html.push('<div class="calenda_table calenda_table_mr">');
		html.push('<table id="'+this.tableId+'" width="100%" border="0">');
		html.push('</table>');
		html.push('</div>');
		return html.join('');
	}
	
	function renderHolidayHTML(year){
		
		var html = [];
		var holi = [];
		var elem = $s.$(this.holiId);
		
		var holidays = this.options.holiday;
		for(var i=0;i<holidays.length;i++){
			var item = holidays[i];
			var date = item.date.substring(0,4);
			if(date == year) holi.push(item);
		}
		if(holi.length == 0){
			elem.parentNode.style.visibility = "hidden";
			return;
		}
		elem.parentNode.style.visibility = "visible";
		var span = $s.$$(elem,"span")[0];
		
		span.innerHTML = "假期";
		var ul = $s.$$(elem.parentNode,"ul")[0];
		html.push('<li><a href="#">假期</a></li>');
		for(var i=0;i<holi.length;i++){
			html.push('<li><a href="#" data-holi="'+holi[i].content+'" data-date="'+holi[i].date+'">'+holi[i].content+'</a></li>');
		}
		ul.innerHTML = html.join('');
	}
	
	/*渲染头部*/
	function renderTop(){
		var year = this.year;
		var month = this.month;
		var holidays = this.options.holiday;
		var sYear = this.sYear;
		var eYear = this.eYear;
		
		var html = [];
		
		html.push('<div id="'+this.topId+'" class="calendar_top cf">');
		/*****************************/
		html.push('<div class="ca_tag">');
		html.push('<p class="ca_tagT _ySelect" style="*font-size:12px;cursor:pointer;width:72px;overflow:hidden;"><span data-year="'+year+'">'+year+'年</span><i></i></p>');
		html.push('<ul id="'+this.yselId+'" class="ca_taglist" style="width:72px;display:none;">');
		for(var i=sYear;i<=eYear;i++){
			var cls = i==year?"on":"";
			html.push('<li class="'+cls+'"><a data-year="'+i+'" href="#">'+i+'年</a></li>');
		}
		html.push('</ul>');
		html.push('</div>');
		/*****************************/
		html.push('<div class="ca_tag ca_tag2 cf" style="">');
		html.push('<a class="left_btn" href="#"></a>');
		html.push('<a class="right_btn" href="#"></a>');
		html.push('<p class="ca_tagT _mSelect" style=""><span data-month="'+month+'">'+month+'月</span><i></i></p>');
		html.push('<ul id="'+this.mselId+'" class="ca_taglist" style="display:none;">');
		for(var i=1;i<=12;i++){
			var cls = i==month?"on":"";
			html.push('<li class="'+cls+'"><a data-month="'+i+'" href="#">'+i+'月</a></li>');
		}
		html.push('</ul>');
		html.push('</div>');
		/*****************************/
		html.push('<div class="black_td" style="cursor:pointer">今天</div>');
		html.push('<div class="ca_tag ca_tag3 cf">');
		html.push('<p id="'+this.holiId+'" class="ca_tagT _hSelect" style=""><span style="*height:18px;overflow:hidden;">放假安排</span><i style="*height:18px;overflow:hidden;"></i></p>');
		html.push('<ul class="ca_taglist" style="width:70px;display:none;">');
		html.push('<li><a href="#">假期</a></li>');
		for(var i=0;i<holidays.length;i++){
			var item = holidays[i];
			html.push('<li><a data-date='+item.date+' href="#">'+item.content+'</a></li>');
		}
		html.push('</ul>');
		html.push('</div>');
		html.push('</div>');
		
		return html.join('');
	}
	
	function renderTip(){
		var tip = document.createElement("div");
		tip.id = this.tipId;
		tip.className = "calendar_text";
		tip.style.display = "none";
		var main = $s.$(this.id);
		var parent = main.parentNode;
		parent.appendChild(tip);
	}
	
	function renderTipHtml(item){
		var tip = item.tips;
		var tipBox = $s.$(this.tipId);
		var html = [];
		for(var i=0;i<tip.length;i++){
			var t = tip[i];
			html.push('<dl>');
			html.push('<dt>'+t.col1+'</dt>');
			if(t.col2) html.push('<dd>'+t.col2+'</dd>');
			html.push('</dl>');
		}
		tipBox.innerHTML = html.join('');
		tipBox.style.display = "";
	}
	
	function renderTipCont(name){
		var holiday = this.options.holiday;
		$s.$(this.tipId).style.display = "none";
		for(var i=0;i<holiday.length;i++){
			var item = holiday[i];
			var _name = item.content;
			if(_name == name){
				renderTipHtml.call(this,item);
				break;
			}
		}
	}
	
	function renderSelect(id,attr,val){
		var sel = $s.$(id);
		var list = $s.$$(sel,"li");
		for(var i=0;i<list.length;i++){
			var v = $s.$$(list[i],"a")[0].getAttribute(attr);
			if(v == val) list[i].className = "on";
			else list[i].className = "";
		}
	}
	
	
	/*
		options:{
			year:2013,
			month:12,
			day:1,
			nyear:2013,
			nmonth:12,
			nday:13,
			holiday:[
				{
					content:"国庆节",
					date:"2013-10-1",
					tips:[
							{col1:"",col2:""}
						],
					guide:[
						{year:2013,month:10,day:1,type:"vacation"},
						{year:2013,month:10,day:2,type:"work"},
						{year:2013,month:10,day:3,type:"leave"}
					]
				}
			],
			dateClick:function(){
				//this表示被点击日期元素
			},
			yearClick:function(){
				//this表示被点击年下拉框元素
			},
			monthClick:function(){
				//this表示被点击月份元素
			},
			backClick:function(){
				//this表示被点击元素
			},
			holidayClick:function(){
				//this表示被点击假期元素
			},
			jumpClick:function(){
				//this表示被点击按钮元素
			}
		}
	*/
	function $calendar(id,options){
		this.id = id;
		this.options = options || {};
		var opt = this.options;
		opt.holiday = opt.holiday || {};
		this.guide = getGuide(opt.holiday);
		//set id
		this.topId = id+"_top";
		this.cenId = id+"_cenId";
		this.rightId = id+"_rId";
		this.tableId = id+"_table";
		this.fitId = id+"_fit";
		this.badId = id+"_bad";
		this.tipId = id+"_tip";
		this.holiId = id+"_holi";
		this.yselId = id+"_ysel";
		this.mselId = id+"_msel";
		
		//set time
		this.sYear = 1901;
		this.eYear = 2049;
		this.year = opt.year;
		this.month = opt.month;
		this.day = opt.day || 1;
		
		var html = renderCalendar.call(this);
		$s.$(this.id).outerHTML = html;
		
		renderTip.call(this);
		renderTable.call(this,true);
//		renderRightCont.call(this);
		
		bindEvent.call(this);
	}
	
	/**************/
	var _sel = "1223";
	
	function selClick(sel){
		return function(){
			var parent = this.parentNode;
			var list = GC(parent,"ca_taglist","ul")[0];
			list.style.display = list.style.display != "none"?"none":"";
			_sel = sel;
			if(sel == "_ySelect"){
				var year = $s.$$(this,"span")[0].getAttribute("data-year");
				var diff = year-1900-3;
				diff = diff>0?diff:0;
				setTimeout(function(){
					list.scrollTop = diff*22;
				},50);
			}
			return false;
		}
	}
	
	function yliClick(cal){
		return function(){
			
			if(this.className == "on") return false;
			
			var link = $s.$$(this,"a")[0];
			var year = +link.getAttribute("data-year");
			var span = $s.$$(this.parentNode.parentNode,"span")[0];
			span.innerHTML = year+"年";
			span.setAttribute("data-year",year);
			var flag = cal.year==year?false:true;
			cal.year = year;
			this.parentNode.style.display = "none";
			renderTable.call(cal,flag);
            //alert(123); return;
//			renderRightCont.call(cal);
			if(typeof cal.options.yearClick == "function") cal.options.yearClick.call(this);
			return false;
		}
	}
	
	function mliClick(cal){
		return function(){
			if(this.className == "on") return false;
			
			var link = $s.$$(this,"a")[0];
			var month = +link.getAttribute("data-month");
			var span = $s.$$(this.parentNode.parentNode,"span")[0];
			span.innerHTML = month+'月';
			span.setAttribute("data-month",month);
			cal.month = month;
			this.parentNode.style.display = "none";
			renderTable.call(cal);
//			renderRightCont.call(cal);
			if(typeof cal.options.monthClick == "function") cal.options.monthClick.call(this);
			return false;
		}
	}
	
	
	
	function hliClick(cal){
		return function(e){
			e = e || window.event;
			var target = e.target || e.srcElement;
//			var link = $s.$$(this,"a")[0];
			var link = target;
			var date = link.getAttribute("data-date");
			if(!date) { // 2014-03-27 20:06 modify by formal 
                $("#sogou_vr_20008605_calendar_0_holi").children("span").text('假期');
                return false;
            }
			var list = date.split("-");
			cal.year = +list[0];
			cal.month = +list[1];
			cal.day = +list[2];
			var span = $s.$$(this.parentNode,"span")[0];
			var holiday = link.getAttribute("data-holi")
			span.innerHTML = holiday;
			this.style.display = "none";
			
			var li = link.parentNode;
			var lis = $s.$$(li.parentNode,"li");
			for(var i=0;i<lis.length;i++){
				if(lis[i] == li) lis[i].className = "on";
				else lis[i].className = "";
			}
			
			var main = $s.$(cal.id);
			var ys = GC(main,"_ySelect","p")[0];
			ys = $s.$$(ys,"span")[0];
			ys.innerHTML = list[0]+"年";
			ys.setAttribute("data-year",list[0]);
			var ms = GC(main,"_mSelect","p")[0];
			ms = $s.$$(ms,"span")[0];
			ms.innerHTML = list[1]+"月";
			ms.setAttribute("data-month",list[1]);
			
			renderTable.call(cal);
//			renderRightCont.call(cal);
			renderTipCont.call(cal,link.innerHTML);
			if(typeof cal.options.holidayClick == "function") cal.options.holidayClick.call(link);
			return false;
		}
	}
	
	function backToday(cal){
		return function(){
			var ops = cal.options;
			var flag = cal.year==ops.nyear?false:true;
			cal.year = ops.nyear;
			cal.month = ops.nmonth;
			cal.day = ops.nday;
			
			var main = $s.$(cal.id);
			var ys = GC(main,"_ySelect","p")[0];
			ys = $s.$$(ys,"span")[0];
			ys.innerHTML = ops.nyear+"年";
			ys.setAttribute("data-year",ops.nyear);
			var ms = GC(main,"_mSelect","p")[0];
			ms = $s.$$(ms,"span")[0];
			ms.innerHTML = ops.nmonth+"月";
			ms.setAttribute("data-month",ops.nmonth);
			
			renderTable.call(cal,flag);
//			renderRightCont.call(cal);
			if(typeof cal.options.backClick == "function") cal.options.backClick.call(this);
			return false;
		}
	}
	
	function isCell(dom){
		if(!dom) return null;
		while(dom){
			if(dom.className === "calendar_new") return dom;
			dom = dom.parentNode;
		}
		return null;
	}
	
	function getHolidayName(){
		var year = this.year,
			month = this.month,
			day = this.day,
			holidays = this.options.holiday;
		for(var i=0;i<holidays.length;i++){
			var guides = holidays[i].guide;
			var name = holidays[i].content;
			for(var j=0;j<guides.length;j++){
				var guide = guides[j];
				if(guide.year == year && guide.month == month && guide.day == day)
					return name;
			}
		}
		return "";
	}
	
	function cellClick(cal){
		return function(e){
			
			var e = e || window.event;
			var target = e.target || e.srcElement;
			
			var dom = isCell(target);
			if(dom == null) return;
			
			var link = $s.$$(dom,"a")[0];
			
			var year = link.getAttribute("data-year");
			var month = link.getAttribute("data-month");
			var day = link.getAttribute("data-day");
			
			var flag = cal.year==year?false:true;
			cal.year = year;
			cal.month = month;
			cal.day = day;
			
			
			var main = $s.$(cal.id);
			var ys = GC(main,"_ySelect","p")[0];
			ys = $s.$$(ys,"span")[0];
			ys.innerHTML = year+"年";
			ys.setAttribute("data-year",year);
			var ms = GC(main,"_mSelect","p")[0];
			ms = $s.$$(ms,"span")[0];
			ms.innerHTML = month+"月";
			ms.setAttribute("data-month",month);
			
			renderTable.call(cal,flag);
//			renderRightCont.call(cal);
			if(typeof cal.options.dateClick == "function") cal.options.dateClick.call(link);
			return false;
		}
	}
	
	function jump(cal,step){
		return function(){
			var year = cal.year;
			var month = cal.month;
			var d = jumpMonth(step,year,month);
			var flag = cal.year==d.year?false:true;
			cal.year = d.year;
			cal.month = d.month;
			
			var main = $s.$(cal.id);
			var ys = GC(main,"_ySelect","p")[0];
			ys = $s.$$(ys,"span")[0];
			ys.innerHTML = d.year+"年";
			ys.setAttribute("data-year",d.year);
			var ms = GC(main,"_mSelect","p")[0];
			ms = $s.$$(ms,"span")[0];
			ms.innerHTML = d.month+"月";
			ms.setAttribute("data-month",d.month);
			
			renderTable.call(cal,flag);
//			renderRightCont.call(cal);
			if(typeof cal.options.jumpClick == "function") cal.options.jumpClick.call(this,step);
			return false;
		}
	}
	
	function bind(elem,type,cb){
		if(!elem) return;
		if(elem.addEventListener) elem.addEventListener(type,cb,false);
		else if(elem.attachEvent) elem.attachEvent("on"+type,cb);
	}
	
	function windowClick(cal){
		return function(){
			var main = $s.$(cal.id);
			var select = GC(main,"ca_tagT","p");
			for(var i=0;i<select.length;i++){
				var className = select[i].className;
				if(className.indexOf(_sel)==-1){
					var ul = $s.$$(select[i].parentNode,"ul")[0];
					ul.style.display = "none";
				}
			}
			_sel = "1234";
			
		}
	}
	
	function bindEvent(){
		var main = $s.$(this.id);
		var ysel = GC(main,"_ySelect","p")[0];
		ysel.onclick = selClick("_ySelect");
		var lis = $s.$$(ysel.parentNode,"li");
		for(var i=0;i<lis.length;i++){
			lis[i].onclick = yliClick(this);
		}
		var msel = GC(main,"_mSelect","p")[0];
		msel.onclick = selClick("_mSelect");
		lis = $s.$$(msel.parentNode,"li");
		for(var i=0;i<lis.length;i++){
			lis[i].onclick = mliClick(this);
		}
		var hsel = GC(main,"_hSelect","p")[0];
		hsel.onclick = selClick("_hSelect");
		lis = $s.$$(hsel.parentNode,"ul")[0];
		lis.onclick = hliClick(this);
/*		for(var i=0;i<lis.length;i++){
			lis[i].onclick = hliClick(this);
		}
*/		var today = GC(main,"black_td")[0];
		today.onclick = backToday(this);
		
		var table = $s.$(this.tableId);
		table.onclick = cellClick(this);
		
		var leftBtn = GC(main,"left_btn","a")[0];
		var rightBtn = GC(main,"right_btn","a")[0];
		leftBtn.onclick = jump(this,-1);
		rightBtn.onclick = jump(this,1);
		
		bind(document,"click",windowClick(this));
	}

	function filterArray(arr){
		var res = [],r = [],score = 0,max = 7;
		for(var i=0;i<arr.length;i++){
			if(arr[i].length<=3 && arr[i].length>=2) res.push(arr[i]);
		}
		res = sortArray(res);
		for(var i=0;i<res.length;i++){
			score++;
			if(score <= max) r.push(res[i]);
		}
		return r;
	}
	
	function sortArray(arr){
		return arr.sort(function(a,b){return a.length-b.length;});
	}
	
	function gethuangli(y,m,d) {
		var that = this;
		if (m<10) m="0"+m;
		if (d<10) d="0"+d;
		str = y+"%C4%EA"+m+"%D4%C2"+d+"%C8%D5";
		new Ajax({
			url : "/websearch/features/baibao/calendar_ajax.jsp?query="+str,
			method : "get",
			onComplete : function (request) {
				var result = request.responseText;
				eval("result=(" + result+")");
				if (result['error']) {
					$s.$(that.fitId).innerHTML="";
					$s.$(that.badId).innerHTML="";
				} else {
					var fit = result['fit'];
					var bad= result['bad'];
					fit = filterArray(fit.split(/\s+/));
					bad = filterArray(bad.split(/\s+/));
					var fitHtml = [];
					fitHtml.push('<span class="tt">宜</span>');
					for(var i=0;i<fit.length;i++){
						fitHtml.push('<span>'+fit[i]+'</span>');
					}
					
					var badHtml = [];
					badHtml.push('<span class="tt">忌</span>');
					for(var i=0;i<bad.length;i++){
						badHtml.push('<span>'+bad[i]+'</span>');
					}
					
					$s.$(that.fitId).innerHTML = fitHtml.join('');
					$s.$(that.badId).innerHTML = badHtml.join('');;
				}
			},
			onError : function(request) {
				//alert("error");
			}
		});
		return false;
	}

	
	return $calendar;
});
