/*-- ------ #chooseDay ------ --*/
function netsDay(){
	var sysDate=new Date();
	var sysToday=new Date();
	var sysSelectedDay=new Date();
	var sysYear=2009;
	var sysMonth=9;
	var sysDay=30;
	var sysWeek=30;
	var sysHour=0;
	var sysMin=0;
	var sysSecond=0;
	var sysValueTypeIndex=1;
	var sysValueTypes=new Array();
	var sysValueType="Y-M-D h:m:s";
	
	var sysYearBox="";
	var sysMonthBox="";
	var sysValueTypeBox="";
	var sysBox="";
	var sysOption="";
	var sysOptionSelected=0;
	
	var sysBoxCell="dayBoxCell";
	var sysOptionCell="dayOptionCell";
}
//Initial
netsDay.prototype.initial=function(pYear,pMonth,pDay,pHour,pMin,pSecond,pValueTypeIndex){
	this.sysDate=new Date(pYear,pMonth,pDay,pHour,pMin,pSecond);
	this.sysToday=new Date();
	this.sysYearBox=document.getElementById("dayYear");
	this.sysMonthBox=document.getElementById("dayMonth");
	this.sysValueTypeBox=document.getElementById("dayFormat");
	this.sysBox=document.getElementById("dayBox");
	this.sysOption=document.getElementById("dayOption");
	this.sysValueTypes=new Array();
	this.sysValueTypes[0]="Y-M-D h:m:s";
	this.sysValueTypes[1]="Y-M-D";
	this.sysValueTypes[2]="Y-M";
	this.sysValueTypes[3]="M-D";
	this.sysValueTypes[4]="h:m:s";
	this.sysValueTypes[5]="h:m";
	this.sysValueTypes[6]="m:s";
	this.sysValueTypeIndex=pValueTypeIndex;
	
	this.sysYear=this.sysDate.getYear();
	this.sysMonth=this.sysDate.getMonth();
	this.sysDay=this.sysDate.getDate();
	this.sysWeek=this.sysDate.getDay();
	this.sysHour=this.sysDate.getHours();
	this.sysMin=this.sysDate.getMinutes();
	this.sysSecond=this.sysDate.getSeconds();
	this.sysValueType=this.sysValueTypes[this.sysValueTypeIndex];
	
	this.set_Year();
	this.set_Month();
	this.set_ValueType();
	this.setDayCell();
}
netsDay.prototype.addYear=function(){
	this.sysYear+=1;
	this.set_Year();
	this.setDayCell();
}
netsDay.prototype.subYear=function(){
	this.sysYear-=1;
	this.set_Year();
	this.setDayCell();
}
netsDay.prototype.selectYear=function(pValue){
	this.sysYear=pValue;
	this.set_Year();
	this.hiddenOption();
	this.setDayCell();
}
netsDay.prototype.addMonth=function(){
	if(this.sysMonth>0 && this.sysMonth<12){
		this.sysMonth+=1;
		this.set_Month();
		this.setDayCell();
	}
}
netsDay.prototype.subMonth=function(){
	if(this.sysMonth>1 && this.sysMonth<13){
		this.sysMonth-=1;
		this.set_Month();
		this.setDayCell();
	}
}
netsDay.prototype.selectMonth=function(pValue){
	this.sysMonth=pValue;
	this.set_Month();
	this.hiddenOption();
	this.setDayCell();
}
netsDay.prototype.addValueType=function(){
	if(this.sysValueTypeIndex>-1 && this.sysValueTypeIndex<6){
		this.sysValueTypeIndex+=1;
		this.set_ValueType();
		this.setDayCell();
	}
}
netsDay.prototype.subValueType=function(){
	if(this.sysValueTypeIndex>0 && this.sysValueTypeIndex<7){
		this.sysValueTypeIndex-=1;
		this.set_ValueType();
		this.setDayCell();
	}
}
netsDay.prototype.selectValueType=function(pValue){
	this.sysValueTypeIndex=pValue;
	this.set_ValueType();
	this.hiddenOption();
	this.setDayCell();
}
netsDay.prototype.set_Year=function(){
	this.sysYearBox.innerHTML=this.sysYear+" 年";
}
netsDay.prototype.set_Month=function(){
	if(this.sysMonth.toString().length<2){
		this.sysMonthBox.innerHTML="0"+this.sysMonth+" 月";
	}else{
		this.sysMonthBox.innerHTML=this.sysMonth+" 月";
	}
}
netsDay.prototype.set_ValueType=function(){
	this.sysValueType=this.sysValueTypes[this.sysValueTypeIndex];
	this.sysValueTypeBox.innerHTML=this.sysValueType;
}
netsDay.prototype.selectToday=function(){
	this.sysYear=this.sysToday.getYear();
	this.set_Year();
	this.sysMonth=this.sysToday.getMonth()+1;
	this.set_Month();
	this.setDayCell();
}
netsDay.prototype.showOption=function(pType){
	if(this.sysOptionSelected==pType){
		this.hiddenOption();
		this.sysOption.innerHTML="";
		this.sysOptionSelected=0;
		return 0;
	}else{
		this.hiddenOption();
		this.sysOption.innerHTML="";
		this.sysOptionSelected=pType;
	}
	//-- #Add option --
	var Coun0=0;
	var tmpStyle="FBlack3";
	
	if(pType==1){
		var tmpINT=this.sysToday.getYear()-30;
		while(Coun0<36){
			if(tmpINT==this.sysYear){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			this.sysOption.innerHTML+="<li class=\"dayOptionCell\"><a href=\"#\" class=\"Link1 "+tmpStyle+"\" onclick=\"sysnetsDay.selectYear("+tmpINT+");\">+ "+tmpINT+"</a></li>";
			tmpINT++;
			Coun0++;
		}
	}else if(pType==2){
		while(Coun0<12){
			tmpINT=Coun0+1
			if(tmpINT==this.sysMonth){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			this.sysOption.innerHTML+="<li class=\"dayOptionCell\"><a href=\"#\" class=\"Link1 "+tmpStyle+"\" onclick=\"sysnetsDay.selectMonth("+tmpINT+");\">+ "+tmpINT+"</a></li>";
			Coun0++;
		}
	}else if(pType==3){
		while(Coun0<7){
			if(tmpINT==this.sysValueTypeIndex){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			this.sysOption.innerHTML+="<li class=\"dayOptionCell\" style=\"width:100px;\"><a href=\"#\" class=\"Link1 "+tmpStyle+"\" onclick=\"sysnetsDay.selectValueType("+Coun0+");\">+ "+this.sysValueTypes[Coun0]+"</a></li>";
			Coun0++;
		}
	}
	//-- #Set style --
	this.sysOption.innerHTML+="<li class=\"CClear\"></li>";
	this.sysOption.className="dayOption";
	if(pType==1){
		this.sysYearBox.parentNode.className="dayYearSelected";
		this.sysOption.style.top=25+sysPx;
		this.sysOption.style.left=10+sysPx;
	}else if(pType==2){
		this.sysMonthBox.parentNode.className="dayYearSelected";
		this.sysOption.style.top=25+sysPx;
		this.sysOption.style.left=10+sysPx;
	}else if(pType==3){
		this.sysValueTypeBox.parentNode.className="dayYearSelected";
		this.sysOption.style.top=25+sysPx;
		this.sysOption.style.left=10+sysPx;
	}
	return 0;
}
netsDay.prototype.hiddenOption=function(){
	this.sysOptionSelected=0;
	this.sysOption.className="DHidden";
	this.sysYearBox.parentNode.className="dayYearCont";
	this.sysMonthBox.parentNode.className="dayYearCont";
	this.sysValueTypeBox.parentNode.className="dayYearCont";
}
netsDay.prototype.setDayCell=function(){
	this.sysBox.innerHTML="";
	var tmpDate=new Date(this.sysYear,this.sysMonth,0);
	var tmpEndDate=tmpDate.getDate();
	tmpDate=new Date(this.sysYear,this.sysMonth-1,0);
	var tmpPrevEndDate=tmpDate.getDate();
	tmpDate=new Date(this.sysYear,this.sysMonth-1,1);
	var tmpFirstWeek=tmpDate.getDay();
	var tmpWheelCount=tmpEndDate+tmpFirstWeek+1;
	if(tmpWheelCount%7!=0){
		tmpWheelCount=(parseInt(tmpWheelCount/7)+1)*7;
	}else{
		tmpWheelCount=(parseInt(tmpWheelCount/7))*7;
	}
	//document.getElementById("message").innerHTML="Month:"+this.sysMonth+",Week:"+tmpFirstWeek+",Pre:"+tmpPrevEndDate+",Now:"+tmpEndDate+",Coun:"+tmpWheelCount+",Object:"+tmpDate;
	//-- ------ # ------ --
	var Coun0=0;
	var Coun1=0;
	var Coun3=0;
	var tmpStyle="dayDayNormal";
	var tmpYear=this.sysYear;
	var tmpMonth=this.sysMonth;
	var tmpDay=0;
	while(tmpWheelCount>Coun0){
		var tmpOtherFlag=0;
		if(tmpFirstWeek>0){
			tmpDay=tmpPrevEndDate-tmpFirstWeek;
			tmpFirstWeek--;
			tmpOtherFlag=1;
		}else{
			tmpDay=Coun1+1;
			Coun1++;
		}
		var tmpClick="chooseDay("+tmpYear+","+tmpMonth+","+tmpDay+","+this.sysHour+","+this.sysMin+","+this.sysSecond+","+this.sysValueTypeIndex+");";
		var tmpLink=" href=\"#\" ";
		
		if(tmpOtherFlag==1){
			tmpStyle="dayDayOtherday";
			tmpClick=tmpLink="";
		}else if(tmpDay>tmpEndDate){
			Coun3++;
			tmpDay=Coun3;
			tmpStyle="dayDayOtherday";
			tmpClick=tmpLink="";
		}else if(this.sysDate.getYear()==this.sysYear && this.sysDate.getMonth()==this.sysMonth && tmpDay==this.sysDay){
			tmpStyle="dayDaySelected";
		}else if(this.sysYear==this.sysToday.getYear() &&this.sysMonth==this.sysToday.getMonth()+1 && tmpDay==this.sysToday.getDate()){
			tmpStyle="dayDayToday";
		}else if(Coun0==0 || (Coun0+1)%7==0 || Coun0%7==0){
			tmpStyle="dayDayWeekend";
		}else{
			tmpStyle="dayDayNormal";
		}
		this.sysBox.innerHTML+="<li class=\""+tmpStyle+"\"><a "+tmpLink+" class=\"Link2\" onclick=\""+tmpClick+"\">"+tmpDay+"</a></li>";
		Coun0++;
	}
	this.sysBox.innerHTML+="<li class=\"CClear\"></li>";
	return 0;
}
//-- ------ #Choose day ------ --
function chooseDay(pYear,pMonth,pDay,pHour,pMin,pSecond,pValueTypeIndex){
	var tmpDate=new Date(pYear,pMonth,pDay,pHour,pMin,pSecond);
	document.getElementById("message").innerHTML=tmpDate;
}

