﻿// JavaScript Document
document.write("<style>");
document.write("#__calendarSel{width:147px;margin:0;padding:0;}");
document.write("#calendarTableSel{	margin:0;padding:0;border:1px solid #366DC0;background:#ffffff;}");
document.write("th,td{margin:0;padding:0px}");
document.write("#calendarTableSel th ,#calendarTableSel td{font:12px/20px 宋体,Arial,sans-serif;text-align:center;}");
document.write("#calendarTableSel thead th.week{border-top:1px solid #CCC;border-bottom:1px solid #ccc;background:#EEE;}");
document.write("#calendarTableSel thead tr.function th{border:0px none #fff}");
document.write("#calendarTableSel thead tr.top{letter-spacing:1px;}");
document.write("#calendarTableSel thead a{color:#FFFFFF;width:19px;height:18px;text-decoration:none;display:block;background-color: #CB7603;background:url(http://www.ticket2010.com/js/playbill-tabs-hover.gif) repeat-x;border:none;}");
document.write("#calendarTableSel tbody a:hover{color:#990;width:19px;height:18px;text-decoration:none;display:block;border:1px solid #ccc;background:#E1F1FF;}");
document.write("#calendarTableSel thead a.today{width:98% !important;width:100%}");
document.write("#calendarTableSel thead a.today:hover{width:98% !important;width:100%}");
document.write("#calendarTableSel td{width:21px;height:20px;border-bottom:1px solid #E6E6E6;color:#fff;}");
document.write("#calendarTableSel th{height:21px;}");
document.write("#calendarTableSel tr.com{background:#fff;}");
document.write("#calendarTableSel tr.cur{background:#FFFFCC;}");
document.write("#calendarTableSel tbody a{color:#000;width:19px;height:18px;text-decoration:none;display:block;border:1px solid #fff;}");
document.write("#calendarTableSel tbody a:hover{color:#990;width:19px;height:18px;text-decoration:none;border:1px solid #E6E6E6;background:#FFFF33;display:block;}");
document.write("#calendarTableSel tbody a.today{color:#c00;border:1px solid #DBDBDB;background-color: #FFFF33;}");
document.write("#calendarTableSel tbody a.today:hover{color:#990;border:1px solid #DBDBDB;background-color: #FFFFCC;}");
document.write("#calendarTableSel tbody a.week{color:#c00;}");
document.write("#menu_iframe{position:absolute; visibility:inherit; top:0px; left:0px; width:500px; z-index:-1; filter: Alpha(Opacity=0);}");
document.write("</style>");
document.write("<div id='__calendarSel' style='position:absolute;display:none; z-index:10000;'><iframe id='menu_iframe'src=''></iframe></div>");
document.write("<table cellspacing=\"0\" cellpadding=\"0\" id=\"calendarTableSel\" style=\"z-index:1000;\"><thead><tr class=\"top\"><th>&nbsp;</th><th colspan=\"5\" id=\"sohwdateSel\"></th><th><a href=\"javascript:void(0);\" title=\"close\" onclick=\"shutSel()\">×</a></th></tr><tr class=\"function\"><th><a href=\"javascript:void(0);\" title=\"向前翻1年\" onclick=\"preYearSel()\">&lt;&lt;</a></th><th><a href=\"javascript:void(0);\" title=\"向前翻1月\" onclick=\"preMonthSel()\">&lt;</a></th><th colspan=\"3\"><a href=\"javascript:void(0);\" class=\"today\" title=\"今天\" onclick=\"getDateSel('0')\">今天</a></th><th><a href=\"javascript:void(0);\" title=\"向后翻1月\" onclick=\"nextMonthSel()\">&gt;</a></th><th><a href=\"javascript:void(0);\" title=\"向后翻1年\" onclick=\"nextYearSel()\">&gt;&gt;</a></th></tr><tr><th class=\"week\">日</th><th class=\"week\">一</th><th class=\"week\">二</th><th class=\"week\">三</th><th class=\"week\">四</th><th class=\"week\">五</th><th class=\"week\">六</th></thead><tbody id=\"calendarTbodySel\"></tbody></table>");

var objouterSel;
var objInputSel;
var isShowSel = true;
objouterSel=document.getElementById("__calendarSel"); 
var calendarTableSel = document.getElementById("calendarTableSel");
objouterSel.appendChild(calendarTableSel);

function selday(obj){objInputSel = obj;writeDateSel();sohwDateSel();objouterSel.style.top =getAbsoluteHeightSel(objInputSel)+getAbsoluteTopSel(objInputSel)+"px";objouterSel.style.left =getAbsoluteLeftSel(objInputSel)+"px";objouterSel.style.display = "block";}
function getAbsoluteHeightSel(ob){return ob.offsetHeight;}
function getAbsoluteWidthSel(ob){return ob.offsetWidth;}
function getAbsoluteLeftSel(ob){var s_el=0;el=ob;while(el){s_el=s_el+el.offsetLeft;el=el.offsetParent;}; return s_el}
function getAbsoluteTopSel(ob){var s_el=0;el=ob;while(el){s_el=s_el+el.offsetTop ;el=el.offsetParent;}; return s_el}



var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
var toDaySel = new Date();
var tempYearSel = toDaySel.getFullYear();
var tempMonthSel = toDaySel.getMonth();
var tbodySel = document.getElementById("calendarTbodySel"); 
var sohwIdSel = document.getElementById("sohwdateSel");
function getDaysSel(month, year)
{ 	
	if (1 == month) return ((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400) ? 29 : 28; 
	else return daysInMonth[month]; 
} 

function writeDateSel() { 	
	var curCal = new Date(tempYearSel,tempMonthSel ,1);
	var startDay = curCal.getDay();
	var daily = 0;
	var	today = toDaySel.getDate();
	if(tempYearSel != toDaySel.getFullYear() || tempMonthSel != toDaySel.getMonth()) today = -1;
	var todayStyle = "";
	var weekEndStyle = "";
	clearSel();
	var intDaysInMonth =getDaysSel(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");
		tr.setAttribute("onmouseover","javascript:this.className='cur'");		
		tr.setAttribute("onmouseout","javascript:this.className='com'");
		tr.onmouseover = function (){this.className = "cur";}
		tr.onmouseout = function (){this.className = "com";}
		for (var intDay = 0;intDay < 7;intDay++){			
			var td = document.createElement("td");
			if ((intDay == startDay) && (0 == daily)) 
				daily = 1; 
				
			if(today == daily) 	todayStyle="today";
			
			if (intDay == 6 || intDay == 0) weekEndStyle = "week" ;
			
			if ((daily > 0) && (daily <= intDaysInMonth)) 
			{ 
				td.innerHTML = "<a href=\"javascript:void(0);\" class=\""+ weekEndStyle + todayStyle +"\" onclick=\"getDateSel('"+daily+"')\" title=\""+eval(tempMonthSel+1)+"月"+daily+"日\">" + daily + "</a>";
				todayStyle = "";
				weekEndStyle = "";
				daily++; 
			}else{ 
				td.innerHTML = "&nbsp;"; 
				todayStyle = "";
				weekEndStyle = "";
			}			
			tr.appendChild(td);			
		}
		tbodySel.appendChild(tr);
	} 
}
function getDateSel(day){
	var year , month ,date;
	var tmp;
	if(day == "0"){
		year = toDaySel.getFullYear();
		month = eval(toDaySel.getMonth()+1) < 10 ? "0"+eval(toDaySel.getMonth()+1) : eval(toDaySel.getMonth()+1);
		date = toDaySel.getDate() < 10 ? "0"+toDaySel.getDate() : toDaySel.getDate();
	}else{
		year = tempYearSel;
		month = eval(tempMonthSel+1) < 10 ? "0"+eval(tempMonthSel+1) : eval(tempMonthSel+1);
		date = day < 10 ? "0"+day : day;		
	}
	objInputSel.value = year + "-" + month +"-"+ date;
	closeSel();
}
function sohwDateSel(){
	sohwIdSel.innerHTML = tempYearSel + "年" + eval(tempMonthSel+1) +"月";
}
function preYearSel(){
	isShowSel = false;
	if(tempYearSel > 999 && tempYearSel < 10000){
		tempYearSel--;
	}else{
		alert("年份超出范围（1000-9999）！");
	}
	sohwDateSel();
	writeDateSel();
}
function nextYearSel(){
	isShowSel = false;
	if(tempYearSel > 999 && tempYearSel < 10000){
		tempYearSel++;
	}else{
		alert("年份超出范围（1000-9999）！");
	}
	sohwDateSel();
	writeDateSel();
}

function preMonthSel(){
	isShowSel = false;
	if(tempMonthSel >= 1){tempMonthSel--}else{tempYearSel--;tempMonthSel = 11;}
	sohwDateSel();
	writeDateSel();
}
function nextMonthSel(){
	isShowSel = false;
	if(tempMonthSel == 11){tempYearSel++;tempMonthSel = 0}else{tempMonthSel++}
	sohwDateSel();
	writeDateSel();
}
function clearSel(){
	var nodes = tbodySel.childNodes;
	var nodesNum = nodes.length; 
	for(var i=nodesNum-1;i>=0;i--) { 
		tbodySel.removeChild(nodes[i]); 
	}
}
function shutSel(){
	closeSel();
}
function closeSel(){
	tempYearSel = toDaySel.getFullYear();
	tempMonthSel = toDaySel.getMonth();
	objouterSel.style.display = "none"
	objouterSel.style.top = 0;
	objouterSel.style.left = 0;
}
function ventSel(event){
	if(document.all){
		if(isShowSel){
			if (window.event.srcElement != objouterSel && window.event.srcElement != objInputSel) closeSel();
			isShowSel = true;
			return;
		}
		isShowSel = true;		
	}else{
		if(isShowSel){
			if(event.target != objouterSel && event.target != objInputSel) closeSel();
			isShowSel = true;
		}
		isShowSel = true;
	}
}
document.onclick = ventSel;
