﻿<!--

var cld;
var STARTYEAR = 1949;//报纸日期的开始时间
var showallMonthDay = true;//是否显示一个用的所有日期 true 显示 false 不显示

//年份下拉列表
function yearList()
{
  
  for(i=STARTYEAR;i<2051;i++)
	document.write('<option>'+i+'</option>')	
}

$(document).ready(function(){
	initialize();
});	

function initialize() {
   //dStyle = detail.style;
   //从连接中获取年月
   var pos1,pos2;
   var curUrl;
   curUrl = window.location.href;
  
   var re = /\/(\d{4})-(\d{2})\/(\d{2})\/node_(\d+).htm/im;
   
   if(curUrl.match(re))
   {
   	tY = RegExp.$1 - 0;
   	tM = RegExp.$2 - 1;
   	tD = RegExp.$3;
	//alert(firstPageid);
   	//alert(tM);
	//alert(tD);
   }
   else
   {
	re = /\/(\d{4})-(\d{2})\/(\d{2})\/.*.htm/im;
        if(curUrl.match(re))
        {
		tY = RegExp.$1 - 0;
   		tM = RegExp.$2 - 1;
   		tD = RegExp.$3;
		//alert(firstPageid);
   		//alert("aa" + tY);
        }
   }
   //////////////////////
   //var objSY = document.getElementById("SY");
   //var objSM = document.getElementById("SM");   
   //objSY.selectedIndex=tY - STARTYEAR;
   //objSM.selectedIndex=tM;  
  
   $("#SY").val(tY);
   $("#SM").val(tM+1);
   drawCld(tY,tM +1);

}

function changeMPCld()
{
   var y,m;
   //y=CLD.SY.selectedIndex+STARTYEAR;
   //$("#SY").val(2011);
   //y = parseInt10($("#SY").val()) + STARTYEAR;
   y = parseInt10($("#SY").val());
   //alert(y);
   m = parseInt10($("#SM").val());
   //alert(m);
   //m=CLD.SM.selectedIndex;
   drawCld(y,m);

}

function turnpage(src,mode){

  //currPos = src.selectedIndex;
  var y,m;
  y = parseInt10($("#" + src).val());

  if(mode==0)
  {//前翻
  	$("#" + src).val(y-1);
	 changeMPCld();
  }else
  {
      $("#" + src).val(y+1);
	  changeMPCld();
  }
}
/*
function turnpage(src,mode){

  //currPos = src.selectedIndex;
  var y,m;
  y = parseInt10($("#" + src).val());

  if(mode==0)
  {//前翻
  	if(currPos==0) return;  
    else {
	  //src.selectedIndex = currPos -1;
	  //src.onchange();
	  $("#" + src).val(y-1);
	  changeMPCld();
     }  
  }else{
     if(currPos == src.length-1) return;
	 else {
	   //src.selectedIndex = currPos +1;
	   //src.onchange();
	   $("#" + src).val(y+1);
	   changeMPCld();
	 }
  }
}
*/

function drawCld(SY,SM)
{
   var dataStr = SY + "-" + appendZero(SM);
   //alert(dataStr);
//   var now = new Date(); 
//   var time1 = now.getSeconds()*1000 + now.getMilliseconds();
//   now = new Date(); 
//   var time2 = now.getSeconds()*1000 + now.getMilliseconds();
//   alert(time2-time1);
   var xmlStr = goMonthXMLData(dataStr);
   if(xmlStr == "@"){
    xmlStr = goMonthXMLDataOld(dataStr);
   }

   //alert(xmlStr);
   var xmlArr = xmlStr.split("@");
   if(xmlArr.length < 2)
   {
	   alert("输出日历时，读取的XML数据有错误");
	   return;
   }
   var period_dateArr = xmlArr[0].split("!");
   var front_pageArr = xmlArr[1].split("!");
   
   var sdateStart = new Date(parseInt10(SY),parseInt10(SM)-1,1);//输入时间月份第一天日期
   var sdateEnd = new Date(parseInt10(SY),parseInt10(SM),0);//输入时间的月份最后一天日期
   
   var startIndex = sdateStart.getDay();
   var ts = sdateEnd.getDate();
   
   var x = 0;
   var nowdate = new Date();
   var noewDateStr = nowdate.getFullYear() + "-" + appendZero(nowdate.getMonth() + 1) + "-" + appendZero(nowdate.getDate());
   var wz = 0;
   var cObjArr = new Array();
   var sObjArr = new Array();
   var cObj,sObj;
   for(i=0;i<42;i++)
   {
	  //cObj = $("CD" + i); 
	  //sObj = $("SD" + i); 
	  cObjArr[i] = $("#CD" + i); 
	  sObjArr[i] = $("#SD" + i); 
	  cObjArr[i].attr("href","#"); 
	  sObjArr[i].text("");
	}
	
	if(showallMonthDay)
	{
	   for(i=1;i<=ts;i++)
       {
	     wz = startIndex + i - 1;
	     sObjArr[wz].text(i);
	     sObjArr[wz].attr("color","#EEEED1"); 
	    }
	}
	
	var localUrl = location.href;
    var re = /(http:\/\/[\s\S]+?)\/html/i;
    var r = localUrl.match(re);
    //var findDataArr = findData.split("-");
    var sUrl = r[0] + "/" + SY + "-" + appendZero(SM) + "/";
	
	for(i=0;i<period_dateArr.length;i++)
	{
		if(period_dateArr[i] != "")
		{
		  var rq = parseInt10(period_dateArr[i].split("-")[2]);
		  var nodeUrl = "";
		  //alert("period_dateArr["+i+"]=" + period_dateArr[i] + " rq=" + period_dateArr[i].split("-")[2] + " nodeUrl=" + nodeUrl);
		  nodeUrl = sUrl + period_dateArr[i].split("-")[2] + "/" + front_pageArr[i];
		  wz = startIndex + rq - 1;
		  cObjArr[wz].attr("href",nodeUrl);
		  sObjArr[wz].attr("cursor","hand"); 
		  sObjArr[wz].attr("color","#000");
		  sObjArr[wz].text(rq);
		  var tempdataStr = dataStr + "-" + appendZero(rq);
		
		  //高亮显示当天的日期
		  if(tempdataStr == noewDateStr)
		  {
		     sObjArr[wz].attr("color","#9F0000");
		  }
	   }
		
	}
	
}


//-->

