// JavaScript Document
document.write("<style type=\"text/css\">");
document.write("#itemsBG{background:url(http://news.53mq.com/images/newsmsg_tit.jpg) no-repeat;padding-top:21px;width:235px;}");
document.write("#itemsNR{background-color:#000;filter:Alpha(Opacity=80);width:233px; text-align:left; color:#fff;line-height:16px; border:1px solid #1756bf;}");
document.write("#itemsNR p{padding:3px 6px;}");
document.write("#itemsNR h1{ font-size:12px; font-weight:normal; color:#a8e700; padding:3px 3px; margin:0 3px 5px 3px;border-bottom:1px dashed #277090; }");
document.write("#itemsNR p,#itemsNR div,#itemsNR h1{position:relative;}");
document.write("#itemsNR img{ margin-right:6px;}");
document.write("</style>");
var timeObj = null;
function left(mainStr,lngLen) { 
if (lngLen>0) {return mainStr.substring(0,lngLen)} 
else{return null} 
} 
function getDefineX(objectId)  
{  
	var iPositionX=objectId.offsetLeft;  
	while(objectId=objectId.offsetParent)  
	{  
		iPositionX+=objectId.offsetLeft;  
	}  
	return iPositionX;  
}  
function getDefineY(objectId)  
{  
	var iPositionY=objectId.offsetTop;  
	while(objectId=objectId.offsetParent)  
	{  
		iPositionY+=objectId.offsetTop;  
	}  
	return iPositionY;  
}
function sItem(){
	var o=new Object();
	o.ItemObj=false;
	o.mTimer = "";
	o.showItem=function(str){
		o.ItemObj = $('itemsBG');
		if(o.ItemObj == null){
			o.ItemObj = document.createElement("div");
			o.ItemObj.id = "itemsBG";
			o.ItemObj.style.position="absolute";
			o.ItemObj.style.zIndex = "100";
			o.ItemObj.style.fontSize = "12px";
			document.body.insertBefore(o.ItemObj,document.body.lastChild);
		}else{
			o.vObj(o.ItemObj,'visible');	
		}
		o.ItemObj.innerHTML = '<div id="itemsNR" >'+ str +'</div>';	
	}
	o.lookItem=function(str){
		o.showItem(str);
		if(o.ItemObj && timeObj != null){
			//o.getData(GetLink("loaditem")+"?type="+cla+"&OnlyID="+id);
			//document.onmousemove = o.mouseover;
			o.ItemObj.style.left = getDefineX(timeObj) + 18 + "px";
			o.ItemObj.style.top = getDefineY(timeObj) + 16 + "px";
		}
	};
	o.vObj=function(obj,value){
		obj.style.visibility = value;
		return true;
	}
	o.exit=function(){
		if(o.ItemObj){
			clearTimeout(o.mTimer);
			o.mTimer = setTimeout("ShowItem.vObj(ShowItem.ItemObj,'hidden');",5000);
			timeObj = null;
			//o.vObj(o.ItemObj,'hidden');
			//document.onmousemove = "";
		}
	}
	return o;
}
var ShowItem = new sItem();
var SelectDate = "";
Ajax.prototype.displaydatenews = function(obj)
{
	var str = "";
	var num = 0;
	str += "<h1>"+ SelectDate +" 活动日程如下:</h1>";
	var _all = obj.getElementsByTagName("items");
	if(_all.length > 0){
		for(var i=0;i<_all.length;i++){
			var times = _all[i].getElementsByTagName("date")[0].childNodes[0].nodeValue;
			if(times == SelectDate){
				num++;
				var links = _all[i].getElementsByTagName("link")[0].childNodes[0].nodeValue;
				var title = _all[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
				if(title.length > 15){title = left(title,15) + "...";}
				str += "<p><a href=\"http://news.53mq.com/news/"+ links +"\" target=\"_blank\">"+ title +"</a></p>";
			}
		}
	}
	if(num == 0){
		str += "<p>没有查询到任何活动.</p>";
	}
	//alert(_all.length);
	//alert(str);
	ShowItem.lookItem(str);
}
var DateNewsAjax = new Ajax();

function DateNewsShow(day,obj){
	timeObj = obj;
	ShowItem.lookItem("<h1><img align=\"absmiddle\" src=\"http://news.53mq.com/images/loading.gif\" />正在查询,请稍后.</h1>");
	SelectDate = day;
	var geturl = GetLink("getUrl");
	var file = "/Lists/";
	if(geturl.indexOf('paycenter') > 0)file = "/faq_list/";
	
	var url = file +'newscalendar.xml?xz='+ Math.random();

	DateNewsAjax.runAJAX(url,url,'get',30);
}
function HS_calender(){
	var lis = "";
	var now;
	if (typeof(arguments[0])=="string"){
			selectDate = arguments[0].split("-");
			var year = selectDate[0];
			var month = parseInt(selectDate[1])-1+"";
			var date = selectDate[2];
			now = new Date(year,month,date);
		}
		else if (typeof(arguments[0])=="object"){
			now = arguments[0];
	}
	var lastMonthEndDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+now.getMonth()+"-01").getDate();
	var lastMonthDate = HS_WeekDay(now.getFullYear()+"-"+now.getMonth()+"-01");
	var thisMonthLastDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-01");
	var thisMonthEndDate = thisMonthLastDate.getDate();
	var thisMonthEndDay = thisMonthLastDate.getDay();
	var todayObj = new Date();
	today = todayObj.getFullYear()+"-"+todayObj.getMonth()+"-"+todayObj.getDate();

	for (i=0; i<lastMonthDate; i++){ // Last Month's Date
		lis = "<li class='lastMonthDate'>"+lastMonthEndDate+"</li>" + lis;
		lastMonthEndDate--;
	}
	for (i=1; i<=thisMonthEndDate; i++){ // Current Month's Date
	var todayString = now.getFullYear()+"-"+((parseInt(now.getMonth())+1) < 10 ? ("0" + (parseInt(now.getMonth())+1)) : (parseInt(now.getMonth())+1)).toString() +"-"+(i<10?("0"+i):i);
	if(today == now.getFullYear()+"-"+now.getMonth()+"-"+i){
		 lis += "<li class='thisday' ><a href=\"javascript:void(0);\" onmouseout=\"ShowItem.exit();\" onmouseover=\"DateNewsShow('"+todayString+"',this)\" >"+i+"</a></li>";
	}
	else{
		 lis += "<li><a href=\"javascript:void(0);\" onmouseout=\"ShowItem.exit();\" onmouseover=\"DateNewsShow('"+todayString+"',this)\">"+i+"</a></li>";
	}

	}
	var j=1;
	for (i=thisMonthEndDay; i<6; i++){ // Next Month's Date
		lis += "<li class='nextMonthDate'>"+j+"</li>";
		j++;
	}
	var CalenderTitle = "<a href='javascript:void(0)' class='NextMonth'  style='color:#fff;' onclick=HS_calender(HS_DateAdd('m',1,'"+now.getFullYear()+"-"+now.getMonth()+"-"+now.getDate()+"'),this) title='下一月'>&raquo;</a>";
	CalenderTitle += "<a href='javascript:void(0)' class='LastMonth'  style='color:#fff;' onclick=HS_calender(HS_DateAdd('m',-1,'"+now.getFullYear()+"-"+now.getMonth()+"-"+now.getDate()+"'),this) title='上一月'>&laquo;</a>";
	CalenderTitle += "<span class='selectThisYear'><a href='javascript:void(0)' style='color:#fff;' onclick='CalenderselectYear(this)' title='单击后可更改年份.' >"+now.getFullYear()+"</a></span>年<span class='selectThisMonth'><a href='javascript:void(0)' style='color:#fff;' onclick='CalenderselectMonth(this)' title='单击后可更改月份'>"+(parseInt(now.getMonth())+1).toString()+"</a></span>月";
	if (arguments.length>1){
		arguments[1].parentNode.parentNode.getElementsByTagName("ul")[1].innerHTML = lis;
		arguments[1].parentNode.innerHTML = CalenderTitle;
	}else{
		var CalenderBox = "<div id='calender' class='pub2'><p class='tittle'>活动日历</p><p id='year'>"+CalenderTitle+"</p><ul id='week'><li>日</li><li>一</li><li>二</li><li>三</li><li>四</li><li>五</li><li>六</li></ul><ul class='date' id='thisMonthDate'>"+lis+"</ul><div style='clear:both'></div><p class='kuan_law'></p></div>";
		return CalenderBox;
	}
}


function HS_DateAdd(interval,number,date){
	
	number = parseInt(number);
	if (typeof(date)=="string"){var date = new Date(date.split("-")[0],date.split("-")[1],date.split("-")[2])}
	if (typeof(date)=="object"){var date = date}
	switch(interval){
		case "y":return new Date(date.getFullYear()+number,date.getMonth(),date.getDate()); break;
		case "m":return new Date(date.getFullYear(),date.getMonth()+number,HS_checkDate(date.getFullYear(),date.getMonth()+number,date.getDate())); break;
		case "d":return new Date(date.getFullYear(),date.getMonth(),date.getDate()+number); break;
		case "w":return new Date(date.getFullYear(),date.getMonth(),7*number+date.getDate()); break;
	}
}
function HS_checkDate(year,month,date){
	var enddate = ["31","28","31","30","31","30","31","31","30","31","30","31"];
	var returnDate = "";
	if (year%4==0){enddate[1]="29"}
	if (date>enddate[month]){returnDate = enddate[month]}else{returnDate = date}
	return returnDate;
}
function HS_WeekDay(date){
	var theDate;
	if (typeof(date)=="string"){theDate = new Date(date.split("-")[0],date.split("-")[1],date.split("-")[2]);}
	if (typeof(date)=="object"){theDate = date}
	return theDate.getDay();
}
function CalenderselectYear(obj){
	var opt = "";
	var thisYear = obj.innerHTML;
	for (i=1970; i<=2020; i++){
		if (i==thisYear){
			opt += "<option value="+i+" selected>"+i+"</option>";
		}else{
			opt += "<option value="+i+">"+i+"</option>";
		}
	}
	opt = "<select onblur='selectThisYear(this)' onchange='selectThisYear(this)' style='font-size:11px'>"+opt+"</select>";
	obj.parentNode.innerHTML = opt;
}
function CalenderselectMonth(obj){
	var opt = "";
	var thisMonth = obj.innerHTML;
	for (i=1; i<=12; i++){
		if (i==thisMonth){
			opt += "<option value="+i+" selected>"+i+"</option>";
		}else{
			opt += "<option value="+i+">"+i+"</option>";
		}
	}
	opt = "<select onblur='selectThisMonth(this)' onchange='selectThisMonth(this)' style='font-size:11px'>"+opt+"</select>";
	obj.parentNode.innerHTML = opt;
}
function selectThisYear(obj){
	HS_calender(obj.value+"-"+obj.parentNode.parentNode.getElementsByTagName("span")[1].getElementsByTagName("a")[0].innerHTML+"-1",obj.parentNode);
}
function selectThisMonth(obj){
	HS_calender(obj.parentNode.parentNode.getElementsByTagName("span")[0].getElementsByTagName("a")[0].innerHTML+"-"+obj.value+"-1",obj.parentNode);
}
document.write(HS_calender(new Date()));