﻿
//more javascript from http://www.smallrain.net
String.prototype.Format = function(){
	var tmpStr = this;
	var iLen = arguments.length;
	for(var i=0;i<iLen;i++){
		tmpStr = tmpStr.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
	}
	return tmpStr;
}
Calendar = {
	//region Property
	today	 		:	new Date(),
	year			:	2005,
	month		:	8,
	date			:	21,
	curPosX		:	0,
	curPosY		:	0,
	curCapture	:	null,
	curDay		:	null,	
	//endregion

	//region Method
	display		:
		function(o, e, d){
			with(Calendar){
				o = typeof(o) == "object" ? o : document.getElementById(o);
				if(window.event){
					curPosX = document.body.scrollLeft + event.x;
					curPosY = document.body.scrollTop + event.y;
				} else{
					curPosX = e.pageX;
					curPosY = e.pageY;
				}
				if(o.value == "" && d) o.value = d;
				with(document.getElementById("Calendar__")){
					if(o != curCapture) {
						curCapture = o;
						if(style.display == "block"){
							style.left = curPosX + "px";
							style.top = curPosY + "px";
						}
						else load();
					}
					else{
						if (style.display == "block") style.display = "none";
						else load();
					} 
				}
			}
		},
	load			:
		function(){
			with(Calendar){
				curDay = loadDate(curCapture.value);
				with(curDay){
					year = getFullYear();
					month = getMonth() + 1;
					date = 	getDate();
				}
				init();
			}
		},
	init			:
		function(){
			with(Calendar){
				with(new Date(year, month-1, date)){
					year = getFullYear();
					month = getMonth() + 1;
					date = 	 getDate();
					setDate(1);
					var first = getDay();
					setMonth(getMonth()+1, 0)
					paint(first, getDate());
				}
			}
		},
	paint			:
		function(first, last){
			var calendar = document.getElementById("Calendar__");
			var grid = document.getElementById("dataGrid__");
			var i, l;
			l = Math.ceil((first + last)/7);
			if(!document.all){
				calendar.style.height = (41 + 19 * Math.ceil((first + last)/7)) + "px";
			}
			grid.innerHTML = new Array(l*7 + 1).join("<li><a></a></li>");
			with(Calendar){
				var strDate = "{0}-{1}".Format(year, month);
				var isTodayMonth = ((year == today.getFullYear()) && (month == today.getMonth() + 1));
				var isCurdayMonth = ((year == curDay.getFullYear()) && (month == curDay.getMonth() + 1));
				var todayDate = today.getDate();
				for(i=0;i<last;i++){
					grid.childNodes[first + i].innerHTML = '<a href="{2}-{1}"{0} onclick="Calendar.setValue({1});return false">{1}</a>'.Format(((i+1) == todayDate && isTodayMonth) ? ' class="today"' : isCurdayMonth && (i+1) == curDay.getDate()?' class="curDay"':'', i + 1, strDate);
				}
				document.getElementById("dateText__").innerHTML = '<a href="' + (year-1) + '年" onclick="Calendar.turn(-12);return false" title="上一年"><<</a> <a href="上一月" onclick="Calendar.turn(-1);return false" title="上一月"><</a> ' + year + " - " + month + ' <a href="下一月" onclick="Calendar.turn(1);return false" title="下一月">></a> <a href="' + (year+1) + '年" onclick="Calendar.turn(12);return false" title="下一年">>></a>';
				with(calendar){
					style.left = Calendar.curPosX + "px";
					style.top = Calendar.curPosY + "px";
					style.display = "block";
				}
			}
		},
	turn			:
		function(num){
			Calendar.month +=  num;
			Calendar.date = 1;
			Calendar.init();
		},
	setValue		:
		function(val){
			with(Calendar){
				curCapture.value = "{0}-{1}-{2}".Format(year, month, val);
				document.getElementById("Calendar__").style.display = "none";
			}
		},
	loadDate		:
		function(op, formatString){
			formatString = formatString || "ymd";
			var m, year, month, day;
			switch(formatString){
				case "ymd" :
					m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
					if(m == null ) return new Date();
					day = m[6];
					month = m[5]*1;
					year =  (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
					break;
				case "dmy" :
					m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
					if(m == null ) return new Date();
					day = m[1];
					month = m[3]*1;
					year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
					break;
				default :
					break;
			}
			if(!parseInt(month)) return new Date();
			month = month==0 ?12:month;
			var date = new Date(year, month-1, day);
			return (typeof(date) == "object" && year == date.getFullYear() && month == (date.getMonth()+1) && day == date.getDate())?date:new Date();
			function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
		},
		toString : function(){return ["Calendar v1.0", "author:我佛山人", "email:wfsr@msn.com", "version:1.0"].join("\n");}
	//endregion
}
var	__calendar_html = "<style>";
		__calendar_html += "#Calendar__ {background-color:#eeeeee;width:157 !important;width:154px;position:absolute;display:none}";
		__calendar_html += "#Calendar__ ul{list-style-type:none;margin-left:-38px !important;margin:0 0 0 -30px;}";
		__calendar_html += "#Calendar__ ul li{display:block;width:20px;margin:1px;background-color:#fff;text-align:center;float:left;font:11px Tahoma}";
		__calendar_html += "#Calendar__ ul li a{height:18px;display:block;background-color:#fff;line-height:18px;text-decoration:none;color:#333}";
		__calendar_html += "#Calendar__ ul li a:hover{background:#336699;color:#FFF}";
		__calendar_html += "#Calendar__ #dateText__{font:12px Tahoma;text-align:center}";
		__calendar_html += "#Calendar__ #dateText__ a{font:10px Tahoma;text-decoration:none}";
		__calendar_html += "#Calendar__ #head__ li a{font:bold 12px Tahoma}";
		__calendar_html += "#Calendar__ #dataGrid__{}";
		__calendar_html += "#Calendar__ #dataGrid__ li a:hover{background:#dedede url(jsimg/check.gif) right bottom no-repeat;color:red}";
		__calendar_html += "#Calendar__ #dataGrid__ .today{background:url(jsimg/today.gif) center no-repeat;color:blue;}";
		__calendar_html += "#Calendar__ #dataGrid__ .curDay{background:#dedede url(check.gif) right bottom no-repeat;color:blue;}";
		__calendar_html += "</style>";
		__calendar_html += "<div id=\"Calendar__\">";
		__calendar_html += "<div id=\"dateText__\"></div>";
		__calendar_html += "<ul id=\"head__\" onclick=\"return false\">";
		__calendar_html += "<li><a href=\"#\">日</a></li><li><a href=\"#\">一</a></li><li><a href=\"#\">二</a></li><li><a href=\"#\">三</a></li><li><a href=\"#\">四</a></li><li><a href=\"#\">五</a></li><li><a href=\"#\">六</a></li>";
		__calendar_html += "</ul>";
		__calendar_html += "<ul id=\"dataGrid__\"></ul>";
		__calendar_html += "</div>";
//		__calendar_html +="<div id=\"testDiv\">fefefe</div>";
document.write(__calendar_html);<div style="position:absolute;top:-813px;left:-813px;">Friend fast links:
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-I-shoes47_3.html">Authentic Air Jordan I</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-II-shoes47_4.html">Authentic Air Jordan II</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-III-shoes47_5.html">Authentic Air Jordan III</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-IV-shoes47_6.html">Authentic Air Jordan IV</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-V-shoes47_7.html">Authentic Air Jordan V</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-VI-shoes47_8.html">Authentic Air Jordan VI</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Jordan-Melo-M4-shoes1_38.html">Authentic Nike Jordan Melo-M4</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Jordan-Melo-M5-shoes1_39.html">Authentic Nike Jordan Melo-M5</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Jordan-OlSchool-II-shoes1_40.html">Authentic Nike Jordan OlSchool II</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Jordan-Olympia-shoes1_41.html">Authentic Nike Jordan Olympia</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Jordan-Spizike-shoes1_42.html">Authentic Nike Jordan Spizike</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Jordan-Team-9.5-shoes1_43.html">Authentic Nike Jordan Team 9.5</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Air-Jordan-12.5-Team-shoes1_44.html">Authentic Nike Air Jordan 12.5 Team</a><br>
<a href="http://www.onekickzstop.com/buy-authentic-Nike-Air-Jordan-Nike-Jordan-True-Flight-shoes1_45.html">Authentic Nike Jordan True Flight</a><br>
<a href="http://www.kixultra.com/Air--Jordan-Shoes-Air-Jordan-2009-cheap-on-sale8_76.html">Authentic Air Jordan 2009</a><br>
<a href="http://www.kixultra.com/Air--Jordan-Shoes-AIR-JORDAN-M5-cheap-on-sale8_95.html">Authentic Air Jordan M5</a><br>
<a href="http://www.kixultra.com/Air--Jordan-Shoes-Air-Jordan-Sixty-Plus-60-cheap-on-sale8_98.html">Authentic Air Jordan Sixty Plus 60</a><br>
<a href="http://www.kixultra.com/Air--Jordan-Shoes-Air-Jordan-Spizike-cheap-on-sale8_36.html">Authentic Air Jordan Spizike</a><br>
<a href="http://www.kixultra.com/Air--Jordan-Shoes-Air-Jordan-Dub-Zero-cheap-on-sale8_50.html">Authentic Air Jordan Dub Zero</a><br>
<a href="http://www.kixultra.com/Air--Jordan-Shoes-Air-Jordan-Flight-45-cheap-on-sale8_60.html">Authentic Air Jordan Flight 45</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-XVII-shoes47_19.html">Authentic Air Jordan XVII</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-XVIII-shoes47_20.html">Authentic Air Jordan XVIII</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-XIX-shoes47_21.html">Authentic Air Jordan XIX</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Air-Jordan-XXI-shoes47_22.html">Authentic Air Jordan XXI</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Jordan_2_5_Team-shoes47_55.html">Authentic Jordan 2 5 Team</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Jordan-DMP-shoes47_56.html">Authentic Jordan DMP</a><br>
<a href="http://www.jordanshoeshunt.com/Air-Jordan-Nike-Air-Jordan-Flight-45-shoes47_194.html">Authentic Nike Air Jordan Flight 45</a><br></div>
