function hide()
{
	var divs=[];
	if (document.all)
	divs = document.all.tags("div");
	var l = divs.length;
	for(var i = 0; i < l; i++){
             if(divs[i].className=="help-tooltip")
             {
               divs[i].style.display="none";
             }
	}
}

function showHelpTip(e, sHtml, bHideSelects) 
{
	var divs=[];
	if (document.all)
	divs = document.all.tags("div");
	var l = divs.length;
	for(var i = 0; i < l; i++)
         {
           if(divs[i].className=="help-tooltip")
           {
	   divs[i].style.display="";
           }
	}

	// find anchor element
	var el = e.target || e.srcElement;
	while (el.tagName != "A")
		el = el.parentNode;

	// is there already a tooltip? If so, remove it
	if (el._helpTip) {
		helpTipHandler.hideHelpTip(el);
	}

	helpTipHandler.hideSelects = Boolean(bHideSelects);

	// create element and insert last into the body
	helpTipHandler.createHelpTip(el, sHtml);
	
	// position tooltip
	helpTipHandler.positionToolTip(e);

	// add a listener to the blur event.
	// When blurred remove tooltip and restore anchor
	el.onblur = helpTipHandler.anchorBlur;
	el.onkeydown = helpTipHandler.anchorKeyDown;
}

var helpTipHandler = 
	{
		hideSelects:	false,
		
		helpTip:		null,
		
		showSelects:	function (bVisible) {
			if (!this.hideSelects) return;
			// only IE actually do something in here
			var selects = [];
			if (document.all)
				selects = document.all.tags("SELECT");
			var l = selects.length;
			for	(var i = 0; i < l; i++)
				selects[i].runtimeStyle.visibility = bVisible ? "" : "hidden";	
	},
	
	create:	function () {
		var d = document.createElement("DIV");
		d.className = "help-tooltip";
                  d.style.zIndex = 10000 ;//设为最上层
		d.onmousedown = this.helpTipMouseDown;
		d.onmouseup = this.helpTipMouseUp;
		document.body.appendChild(d);		
		this.helpTip = d;
	},
	
	createHelpTip:	function (el, sHtml) {
		if (this.helpTip == null) {
			this.create();
		}

		var d = this.helpTip;
		d.innerHTML = sHtml;
		d._boundAnchor = el;
		el._helpTip = d;
		return d;
	},
	
	// Allow clicks on A elements inside tooltip
	helpTipMouseDown:	function (e) {
		var d = this;
		var el = d._boundAnchor;
		
		if (!e) e = event;
		var t = e.target || e.srcElement;
		while (t.tagName != "A" && t != d)
			t = t.parentNode;
		if (t == d) return;
		
		el._onblur = el.onblur;
		el.onblur = null;
	},
	
	helpTipMouseUp:	function () {
		var d = this;
		var el = d._boundAnchor;
		el.onblur = el._onblur;
		el._onblur = null;
		el.focus();
	},	
	
	anchorBlur:	function (e) {
		var el = this;
		helpTipHandler.hideHelpTip(el);
	},
	
	anchorKeyDown:	function (e) {
		if (!e) e = window.event
		if (e.keyCode == 27) {	// ESC
			helpTipHandler.hideHelpTip(this);
		}
	},
	
	removeHelpTip:	function (d) {
		d._boundAnchor = null;
		d.style.filter = "none";
		d.innerHTML = "";
		d.onmousedown = null;
		d.onmouseup = null;
		d.parentNode.removeChild(d);
		//d.style.display = "none";
	},
	
	hideHelpTip:	function (el) {
		var d = el._helpTip;
		d.style.visibility = "hidden";
		d.style.top = - el.offsetHeight - 100 + "px"
		d._boundAnchor = null;

		el.onblur = null;
		el._onblur = null;
		el._helpTip = null;
		el.onkeydown = null;
		
		this.showSelects(true);
	},
	
	positionToolTip:	function (e) {
		this.showSelects(false);		
		var scroll = this.getScroll();
		var d = this.helpTip;
		
		// width
		if (d.offsetWidth >= scroll.width)
			d.style.width = scroll.width - 10 + "px";
		else
			d.style.width = "";
		
		// left
		if (e.clientX > scroll.width - d.offsetWidth)
			d.style.left = scroll.width - d.offsetWidth + scroll.left + "px";
		else
			d.style.left = e.clientX - 2 + scroll.left + "px";
		
		// top
		if (e.clientY + d.offsetHeight + 18 < scroll.height)
			d.style.top = e.clientY + 18 + scroll.top + "px";
		else if (e.clientY - d.offsetHeight > 0)
			d.style.top = e.clientY + scroll.top - d.offsetHeight + "px";
		else
			d.style.top = scroll.top + 5 + "px";
			
		d.style.visibility = "visible";
	},
	
	// returns the scroll left and top for the browser viewport.
	getScroll:	function () {
		if (document.all && typeof document.body.scrollTop != "undefined") {	// IE model
			var ieBox = document.compatMode != "CSS1Compat";
			var cont = ieBox ? document.body : document.documentElement;
			return {
				left:	cont.scrollLeft,
				top:	cont.scrollTop,
				width:	cont.clientWidth,
				height:	cont.clientHeight
			}
		}
		else {
			return {
				left:	window.pageXOffset,
				top:	window.pageYOffset,
				width:	window.innerWidth,
				height:	window.innerHeight
			}
		}
		
	}

}

function RunNian(The_Year)
{
 if ((The_Year%400==0) || ((The_Year%4==0) && (The_Year%100!=0)))
  return true;
 else
  return false;
}

function GetWeekday(The_Year,The_Month)
{ 
 return (new Date(The_Year,The_Month-1,1)).getDay();
}

function chooseday(The_Year,The_Month,The_Day)
{
 var Firstday;
 var completely_date;
 var showurl;

 //if (The_Day!=0)
  //{
  //	showurl = "/events/calendar/" + The_Year + "-" + The_Month + "-" + The_Day + ".shtml"
  //	controlWindow=window.open(showurl,"_blank");
  //	completely_date = The_Year + "-" + The_Month + "-" + The_Day;
//	}
 //else
// completely_date = "NO Choice";

 Firstday = GetWeekday(The_Year,The_Month);
 ShowCalender(The_Year,The_Month,The_Day,Firstday);
}


function nextmonth(The_Year,The_Month)
{
 if (The_Month==12)
  chooseday(The_Year+1,1,0);
 else
  chooseday(The_Year,The_Month+1,0);
}

function prevmonth(The_Year,The_Month)
{
 if (The_Month==1)
  chooseday(The_Year-1,12,0);
 else
  chooseday(The_Year,The_Month-1,0);
}

function prevyear(The_Year,The_Month)
{
 chooseday(The_Year-1,The_Month,0);
}

function nextyear(The_Year,The_Month)
{
 chooseday(The_Year+1,The_Month,0);
}


var s_color;
function ch_over(obj){
	s_color = obj.style.backgroundColor;
	obj.style.backgroundColor='#FA8FA6';
}
function ch_out(obj){
	obj.style.backgroundColor=s_color;
}

function something(someyear,somemonth,someday)
{
var year=someyear+"";
var month,day;
if (somemonth<10) month="0"+somemonth; else month=somemonth+"";
if (someday<10) day="0"+someday; else day=someday+"";
var x=year+month+day;
var s="";
if (typeof(arr[x]) != "undefined") 
{
  var   myArray   =   arr[x].split(",");
  myArray.reverse();
  for (j=0;j<myArray.length;j++)
  {
     var my_list = myArray[j].split("|");
     s=s+"<img src='"+my_list[2]+"' width=16 height=16 border=0 alt='"+my_list[0]+"'>&nbsp;";    
  }
}else s="";

return s;
}

function ShowCalender(The_Year,The_Month,The_Day,Firstday)
{
 var showstr;
 var Month_Day;
 var ShowMonth;
 var today;
 today = new Date();
 
 var month_array=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
 
 switch (The_Month)
 {
  case 1 : ShowMonth = month_array[0]; Month_Day = 31; break;
  case 2 :
   ShowMonth = month_array[1];
   if (RunNian(The_Year))
    Month_Day = 29;
   else
    Month_Day = 28;
   break;
  case 3 : ShowMonth = month_array[2]; Month_Day = 31; break;
  case 4 : ShowMonth = month_array[3]; Month_Day = 30; break;
  case 5 : ShowMonth = month_array[4]; Month_Day = 31; break;
  case 6 : ShowMonth = month_array[5]; Month_Day = 30; break;
  case 7 : ShowMonth = month_array[6]; Month_Day = 31; break;
  case 8 : ShowMonth = month_array[7]; Month_Day = 31; break;
  case 9 : ShowMonth = month_array[8]; Month_Day = 30; break;
  case 10 : ShowMonth = month_array[9]; Month_Day = 31; break;
  case 11 : ShowMonth = month_array[10]; Month_Day = 30; break;
  case 12 : ShowMonth = month_array[11]; Month_Day = 31; break;
   
 }
 
 showstr  ="<table width=166 border=0 cellspacing=0 cellpadding=0>";
 showstr +="<tr>";
 showstr +="<td><img src=/images_wow/calendar/small/content_1.gif width=143 height=6></td>";
 showstr +="</tr>";
 showstr +="<tr>";
 showstr +="<td height=16 align=center background=/images_wow/calendar/small/content_back1.gif class=calendarText>"+ The_Year+"年 "+ShowMonth+"</td>";
 showstr +="</tr>";
 showstr +="<tr>";
 showstr +="<td><img src=/images_wow/calendar/small/content_2.gif width=143 height=5></td>";
 showstr +="</tr>";
 showstr +="</table>";


 showstr +="<table width=166 border=0 cellpadding=0 cellspacing=1>";
 showstr +="<tr align=center valign=middle class=calendarText>";
 showstr +="<td width=14% height=16% bgcolor=E4D8A8>日</td>";
 showstr +="<td width=14% bgcolor=E4D8A8>一</td>";
 showstr +="<td width=14% bgcolor=E4D8A8>二</td>";
 showstr +="<td width=14% bgcolor=E4D8A8>三</td>";
 showstr +="<td width=14% bgcolor=E4D8A8>四</td>";
 showstr +="<td width=14% bgcolor=E4D8A8>五</td>";
 showstr +="<td width=16% bgcolor=E4D8A8>六</td>";
 showstr +="</tr>";

 showstr +="<tr align=center valign=middle class=dayNoAction";
 
     for (i=1; i<=Firstday+1; i++)
	 {
		 showstr += "<Td height=16% bgColor = #FFFFFF></Td>";
     }
 
	 for (i=1; i<=Month_Day; i++)
	 {
	  if ((The_Year==today.getYear()) && (The_Month==today.getMonth()+1) && (i==today.getDate()))
	   bgColor = "#FF9900";
	  else
	   bgColor = "#FFFFFF";

	  if(something(The_Year,The_Month,i)=="")
	  {
		showstr += "<td height=16% align=center bgcolor=" + bgColor + " style='cursor:hand' class=calendarText onMouseover='ch_over(this)' onMouseout='ch_out(this)' onclick=chooseday(" + The_Year + "," + The_Month + "," + i + ")><a href=/include_wow/calendar_page_file.htm target=_blank class=news_txt>"+i+"</a></td>";
	  }
	  else
	  {
		showstr += "<td height=16% align=center bgcolor=" + bgColor + " style='cursor:hand' class=calendarText onMouseover='ch_over(this)' onMouseout='ch_out(this)' onclick=chooseday(" + The_Year + "," + The_Month + "," + i + ")><a href=/include_wow/calendar_page_file.htm target=_blank onMouseOver=\"showHelpTip(event,something("+The_Year+","+The_Month+","+i+"))\" onMouseout=\"hide()\" >"+i+"</a></td>";
	  }
	  Firstday = (Firstday + 1)%7;
	  if ((Firstday==0) && (i!=Month_Day)) showstr += "</tr><tr>";
	 }
 if (Firstday!=0) 
 {
  for (i=Firstday; i<7; i++) 
   showstr += "<td height=16% align=center bgcolor=#FFFFFF></td>";
  showstr += "</tr>";
 }
  
 showstr += "</tr></table></td></tr></table>";

 cc.innerHTML = showstr;
}

