﻿//*Created By MaNing on Christmas Day, 2008, ^_^*/
document.writeln("<TABLE width=\"100%\" border=0 cellPadding=1 cellSpacing=0>");
document.writeln("<TR>");
document.writeln("<TD align=\"center\" valign=\"top\">");
document.writeln("<span style=\"color: #003399;font-size:12px;\">");
document.writeln("<select onChange=\"refill()\" id=\"year\"><\/select>年 ");
document.writeln("<select onChange=\"refill()\" id=\"month\"><\/select>月");
document.writeln("<select id=\"date\"><\/select>日<\/span><\/TD>");
document.writeln("<TD align=\"center\" valign=\"top\"><A href=\"#\" onClick=\"javaScript:goHistory();return false;\" target=_blank><IMG height=18 src=\"http:\/\/img.aqsc.cn\/templates\/102020\/images\/newshg.gif\" width=35 border=0><\/A><\/TD>");
document.writeln("<\/TR><\/TABLE>");

var today = new getToday();
var months = new Array("00","01", "02", "03","04", "05", "06", "07", "08", "09","10", "11", "12");
var dim=[-1,31,0,31,30,31,30,31,31,30,31,30,31];
var dayline=0;     

var yearSelect = document.getElementById("year");
var monthSelect = document.getElementById("month");
var dateSelect = document.getElementById("date");
                               
var posttarget = "http://cms.aqsc.cn/cms/HistoryNews/go.jsp?d=";
var todaydate = new Date();
var curmonth = todaydate.getMonth()+1 ;
var curyear = todaydate.getFullYear();
var curday = todaydate.getDate();

function getToday() {
	this.now = new Date();
	this.year = this.now.getFullYear();
	this.month = this.now.getMonth();
	this.day = this.now.getDate();
	this.hours=this.now.getHours();
}

function numFix(num){
	var n_fix="";
	if (num<10)
	{n_fix="0"+num;
	return n_fix;
	}else{
	return num;
	}
}
function goHistory(){                                           
	var cye = yearSelect.options[yearSelect.selectedIndex].text;
	var cmo = monthSelect.options[monthSelect.selectedIndex].text;
	var cda = dateSelect.options[dateSelect.selectedIndex].text;
	if((cye<2008)){alert("往日新闻是从2008年1月1日开始的"); return false;}
	else
	{window.open(posttarget + cye + numFix(cmo) + numFix(cda));}

}
function refill(){
	var cye = yearSelect.options[yearSelect.selectedIndex].text;
	var cmo = monthSelect.options[monthSelect.selectedIndex].text;
	var cda = dateSelect.options[dateSelect.selectedIndex].text;
	fillSelect(cye,cmo,cda);
	
}
function fillSelect(year,month,day){                               
	var i=0;                                      
	var selectIndex = 0;

	//create year list
	yearSelect.options.length = 0;
	for (var intLoop = curyear-2; intLoop <= curyear;intLoop++){
		if(year == intLoop){
			selectIndex = i;
		} 		
		yearSelect.options[i]=new Option(intLoop,intLoop);
		i++;
	}
	yearSelect.selectedIndex = selectIndex;   
	
	//create month list  
	monthSelect.options.length =0 ;   
	i=0;                                        
	var monthlen = (year == curyear)?curmonth:12;  
	month = (year == curyear && month>curmonth)?curmonth:month
	for (var intLoop = 1;intLoop <= monthlen ;intLoop++){
		if(month == intLoop){
			selectIndex = i;
		}
		monthSelect.options[i] = new Option(intLoop,intLoop);		
		i++;
	}                                                  
	monthSelect.selectedIndex = selectIndex;     
	
	dim[2]=(((year%100!=0)&&(year%4==0))||(year%400==0))?29:28;
	dateSelect.options.length=0;      
	i=0;      
	var daylen = (year == curyear && curmonth ==month)?curday:dim[month];


	day = (year == curyear && curmonth ==month && day>curday)?curday:day;
	for (var intLoop = 1;intLoop <= dim[month];intLoop++){
		if(day == intLoop){
			selectIndex = i;
		}
		dateSelect.options[i] = new Option(intLoop,intLoop);		
		i++;
	}                                                  
	dateSelect.selectedIndex = selectIndex;   
}                                    
fillSelect(curyear,curmonth,curday)