/*<input onfocus="setday(this)" /><input onfocus="setday(this,'1999-2050')" />*/
document.write("<style>");
document.write("#__calendar,#__calendar_iframe{width:205px;margin:0;padding:0;}");
document.write("#calendarTable{margin:0;padding:0;border:1px solid #000;width:205px;background:#FFF;}");
document.write("#calendarTable .top{background:#ccc;}");
document.write("#calendarTable .top a{font-size:16px;}");
document.write("#calendarTable th,#calendarTable td{margin:0;padding:0px;}");
document.write("#calendarTable thead,#calendarTable thead th{font-weight:100;line-height:20px;}");
document.write("#calendarTable th ,#calendarTable td{font-size:12px;text-align:center;}");
document.write("#calendarTable thead th.week{background:#f5f5f5;color:#000;width:14.3%;}");
document.write("#calendarTable tr #sohwdate{color:#000;cursor:pointer;font-weight:900;}");
document.write("#calendarTable thead a{color:#000;text-decoration:none;}");
document.write("#calendarTable tbody a:hover{color:#990;background:#f5f5f5;}");
document.write("#calendarTable thead a.today{width:98% !important;width:100%}");
document.write("#calendarTable thead a.today:hover{width:98% !important;width:100%}");
document.write("#calendarTable td{width:24px;height:20px;border-bottom:1px solid #E6E6E6;color:#fff;}");
document.write("#calendarTable th{height:24px;}");
document.write("#calendarTable tbody a{text-align:center;color:#000;width:24px;height:20px;text-decoration:none;display:block;border:1px solid #fff;}");
document.write("#calendarTable tbody a:hover{color:#990;width:24px;height:20px;text-decoration:none;border:1px solid #000;background:#EEE;}");
document.write("#calendarTable tbody a.today{color:#fff;background:#f60;}");
document.write("#calendarTable tbody a.today:hover{color:#990;background:#f60;}");
document.write("#calendarTable tbody a.week{color:#a00;background:#FFF5E1;border:1px solid #FFF5E1;}");
document.write("#calendarTable tbody a.week:hover{color:#a00;background:#EEE;border:1px solid #000;}");
document.write("#calendarTable thead th #pressbt0,#calendarTable thead th #pressbt1{float:left;width:30px;}");
document.write("#calendarTable thead th #pressbt1{float:right;width:30px;}");
document.write("#calendarTable thead th .sltym{float:left;padding-left:25px;}");
document.write("#calendarTable thead th .box1{float:left;border:1px solid #999;overflow:hidden;margin-top:0px!important;margin-top:1px;}");
document.write("#calendarTable thead th .box2{float:left;border:1px solid #f4f4f4;overflow:hidden;}");
document.write("#calendarTable thead th .change_year{margin-right:2px;}");
document.write("#calendarTable thead th select{margin:-2px -3px -3px -3px;color:#666;}");
document.write("#calendarTable thead th #change_year{width:60px!important;width:65px;}");
document.write("#calendarTable thead th #change_month{width:40px!important;width:45px;}");
document.write("</style>");
document.write("<div id='__calendar' style='position:absolute;display:none;'></div>");
document.write("<iframe id='__calendar_iframe' scrolling=\"no\" frameborder=\"0\" style='position:absolute;display:none;'></iframe>");
document.write("<table cellspacing=\"0\" cellpadding=\"0\" id=\"calendarTable\"><thead>");
document.write("<tr class=\"top\">");
document.write("<th colspan=\"7\"><div id='pressbt0'><a href=\"javascript:void(0);\" title=\"Prev Year\" onclick=\"__selectYear(1)\">&#171;</a>&nbsp;<a href=\"javascript:void(0);\" title=\"Prev Month\" onclick=\"__selectMonth(1)\">&#139;</a></div>");
document.write("<div class='sltym'><div class=\"box1\"><div class=\"box2\"><select id=\"change_year\" onchange='_change_date(this.value,tempMonth);' onclick='isShow=false;'></select></div></div>");
document.write("<div style='float:left'>&nbsp;</div>");
document.write("<div class=\"box1\"><div class=\"box2\"><select id=\"change_month\" onchange='_change_date(tempYear,this.value);' onclick='isShow=false;'></select></div></div></div>");
document.write("<div id='pressbt1'><a href=\"javascript:void(0);\" title=\"Next Month\" onclick=\"__selectMonth(0)\">&#155;</a>&nbsp;<a href=\"javascript:void(0);\" title=\"Next Year\" onclick=\"__selectYear(0)\">&#187;</a></div></th>");
document.write("</tr>");
document.write("<tr><th class=\"week\">Sun</th><th class=\"week\">Mon</th><th class=\"week\">Tue</th><th class=\"week\">Wed</th><th class=\"week\">Thu</th><th class=\"week\">Fri</th><th class=\"week\">Sat</th></tr>");
document.write("</thead><tbody id=\"calendarTbody\"></tbody>");
document.write("<tr><th colspan=\"7\" id=\"sohwdate\" title=\"Today\" onclick=\"getDate('0')\"></th></tr>");
document.write("</table>");
var weekNames = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
var objouter=$("__calendar");
var objouter_iframe=$("__calendar_iframe");
var objInput;
var isShow = true;
var calendarTable = $("calendarTable");
objouter.appendChild(calendarTable);
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
var toDay;
var tempYear;
var tempMonth;
var tempTime="";
var temp_minyear=1940;
var temp_maxyear=2030;
var NowDate=new Date();
var __diydate=false;
var __prevmin;
var __prevmax;
var __systemdate=false;
var tbody = $("calendarTbody");
var sohwId = $("sohwdate");
var changer_year = $("change_year");
var changer_month = $("change_month");
__month_appendChild();
function setday(obj,setyear){
	if(obj!=objInput){
		var datepare = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
		objInput = obj;
		if(datepare.test(obj.value)){
			dates=obj.value.split(/\s/)[0].split("-");
			toDay = new Date(dates[0],dates[1]-1,dates[2]);
		}else{
			var datepare1 = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/;
			if(datepare1.test(obj.value)){
				dates=obj.value.split(/\s/)[0].split("-");
				tempTime=" "+obj.value.split(/\s/)[1];
				toDay = new Date(dates[0],dates[1]-1,dates[2]);
			}else{
				toDay = NowDate;
			}
		}
		tempYear = toDay.getFullYear();
		tempMonth = toDay.getMonth();
		if(setyear){
			try{
				__min=parseInt(setyear.split("-")[0]);
				__min=__min<temp_minyear?temp_minyear:__min;
				__min=__min>temp_maxyear?temp_minyear:__min;
				__min=tempYear<__min?tempYear:__min;
				__max=parseInt(setyear.split("-")[1]);
				__max=__max>temp_maxyear?temp_maxyear:__max;
				__max=__max<temp_minyear?temp_maxyear:__max;
				__max=tempYear>__max?tempYear:__max;
				__min=__min>__max?__max:__min;
				__diydate=true;
			}catch (e){}
		}else{
			__diydate=false;
		}
		if(__diydate){
			if(__prevmin!=__min||__prevmax!=__max){
				__reset_year_options(__min,__max);
				__prevmin=__min;__prevmax=__max;
				temp_minyear=__min;temp_maxyear=__max;
				__systemdate=false;
			}
		}else{
			if(!__systemdate){
				__reset_year_options(temp_minyear,temp_maxyear);
				__systemdate=true;
				__prevmin=null;__prevmax=null;
			}
		}
		sohwDate();
		writeDate();
		var __objouter_s=objouter.style;
		with(__objouter_s){
			top =objInput.offsetHeight+getAbsTop(objInput)+"px";
			left =getAbsLeft(objInput)+"px";
			zIndex = 10000;
			display = "block";
		}
		changer_year.style.zIndex = __objouter_s.zIndex;
		changer_month.style.zIndex = __objouter_s.zIndex;
		if(document.getElementById&&document.all){
			var __if_s=objouter_iframe.style;
			with(__if_s){
				filter = "alpha(opacity=0)";
				opacity = 0;
				top = parseInt(__objouter_s.top.replace("px",""))-1+"px";
				left = parseInt(__objouter_s.left.replace("px",""))-1+"px";
				width = objouter.offsetWidth+1;
				height = objouter.offsetHeight+1;
				zIndex = __objouter_s.zIndex-1;
				display = "block";
			}
		}
	}
};
function getDays(month,year){ 	
	if (1 == month){return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28; }
	else{return daysInMonth[month];}
};

function writeDate() { 	
	var curCal = new Date(tempYear,tempMonth ,1);
	var startDay = curCal.getDay();
	var daily = 0;
	var	today = toDay.getDate();
	if(tempYear != toDay.getFullYear() || tempMonth != toDay.getMonth()){today = -1;}
	var todayStyle = "";
	var weekEndStyle = "";
	clear();
	__selected_chager();
	var intDaysInMonth =getDays(curCal.getMonth(), curCal.getFullYear());
	var weeks = (intDaysInMonth + startDay) % 7 == 0 ? (intDaysInMonth + startDay) / 7 : parseInt((intDaysInMonth + startDay ) / 7) + 1;

	for (var intWeek = 1; intWeek <= weeks; intWeek++){ 
		var tr = document.createElement("tr");
		for (var intDay = 0;intDay < 7;intDay++){			
			var td = document.createElement("td");
			if((intDay == startDay) && (0 == daily)){daily = 1;}
			if(today==daily){todayStyle="today";}
			else if (intDay==6||intDay==0){weekEndStyle="week";}
			if ((daily > 0) && (daily <= intDaysInMonth)) 
			{ 
				td.innerHTML = "<a href=\"javascript:void(0);\" class=\""+ weekEndStyle + todayStyle +"\" onclick=\"getDate('"+daily+"')\" title=\""+tempYear+"-"+eval(tempMonth+1)+"-"+daily+"\">" + daily + "</a>";
				todayStyle = "";
				weekEndStyle = "";
				daily++; 
			}else{ 
				td.innerHTML = "&nbsp;"; 
				todayStyle = "";
				weekEndStyle = "";
			}			
			tr.appendChild(td);			
		}
		tbody.appendChild(tr);
	} 
};
function getDate(day){
	var year,month,date;
	if(day == "0"){
		year = NowDate.getFullYear();
		month = eval(NowDate.getMonth()+1) < 10 ? "0"+eval(NowDate.getMonth()+1) : eval(NowDate.getMonth()+1);
		date = NowDate.getDate() < 10 ? "0"+NowDate.getDate() : NowDate.getDate();
	}else{
		year = tempYear;
		month = eval(tempMonth+1) < 10 ? "0"+eval(tempMonth+1) : eval(tempMonth+1);
		date = day < 10 ? "0"+day : day;		
	}
	objInput.value = year + "-" + month +"-"+ date+tempTime;
	close();
};
function sohwDate(){
	sohwId.innerHTML = NowDate.getFullYear() + "-" + eval(NowDate.getMonth()+1) + "-"+NowDate.getDate() +"&nbsp;"+weekNames[NowDate.getDay()];
};
function __selectYear(job){
	isShow = false;
	if(job==1){tempYear--;}
	else{tempYear++;}
	if(tempYear >= temp_minyear && tempYear <= temp_maxyear){
		writeDate();
	}else{
		if(job==1){tempYear++;}
		else{tempYear--;}
		alert("Error:Year in("+temp_minyear+"-"+temp_maxyear+")！");
	}
};
function __selectMonth(job){
	isShow = false;
	if(job==1){
		if(tempMonth >= 1){tempMonth--;}else{tempYear--;tempMonth = 11;}
	}else{
		if(tempMonth == 11){tempYear++;tempMonth = 0;}else{tempMonth++;}
	}
	if(tempYear < temp_minyear || tempYear > temp_maxyear){
		if(job==1){tempYear++;tempMonth = 0;}else{tempYear--;tempMonth = 11;}
		alert("Error:Year in("+temp_minyear+"-"+temp_maxyear+")！");
	}else{
		writeDate();
	}
};
function _change_date(year,month){
	isShow = false;
	tempYear=parseInt(year);
	tempMonth=parseInt(month);
	writeDate();
};
function clear(){
	var nodes = tbody.childNodes;
	var nodesNum = nodes.length; 
	for(var i=nodesNum-1;i>=0;i--) { 
		tbody.removeChild(nodes[i]); 
	}
};
function __reset_year_options(minyear,maxyear){
	var nodes = changer_year.childNodes;
	var nodesNum = nodes.length; 
	for(var i=nodesNum-1;i>=0;i--) { 
		changer_year.removeChild(nodes[i]); 
	}
	var option,node;
	for(i=minyear;i<=maxyear;i++){
		option=document.createElement("option");
		node=document.createTextNode(i);
		option.value=i;
		option.appendChild(node);
		if(tempYear==i){option.setAttribute("selected","true");}
		changer_year.appendChild(option);
	}
	changer_month.selectedIndex = tempMonth;
};
function __selected_chager(){
	changer_month.selectedIndex = tempMonth;
	var __firstyear = parseInt(changer_year.childNodes[0].value);
	changer_year.selectedIndex = tempYear - __firstyear;
};
function __month_appendChild(){
	var option,node;
	for(var i=0;i<12;i++){
		option=document.createElement("option");
		node=document.createTextNode((i+1));
		option.value=i;
		option.appendChild(node);
		changer_month.appendChild(option);
	}
};
function close(){
	objouter.style.display = "none";
	objouter.style.top = 0;
	objouter.style.left = 0;
	objouter_iframe.style.display = "none";
	objouter_iframe.style.top = 0;
	objouter_iframe.style.left = 0;
	objInput=null;
};
function vent(event){
	var event_obj=null;
	if(document.getElementById&&document.all){event_obj=window.event.srcElement;}
	else{event_obj=event.target;}
	if(isShow&&event_obj){
		if(event_obj!=objInput){
			while(event_obj){
				event_obj=event_obj.offsetParent;
				if(event_obj==objouter){isShow = true;return;}
			}
			close();
		}
		isShow = true;
		return;
	}
	isShow = true;
};
addEvent(document,'click',vent);