/*
-- ------ chooseDay ------ --
unionNets.com
2009
*/
function netsDay(){}
//-- ------ #Parameters ------ --
netsDay.prototype.sName="tmpDay";
netsDay.prototype.sControlName="CONTROL";

netsDay.prototype.sysDate=new Date();
netsDay.prototype.sysToday=new Date();
netsDay.prototype.sysSelectedDay=new Date();
netsDay.prototype.sysYear=2009;
netsDay.prototype.sysMonth=9;
netsDay.prototype.sysDay=30;
netsDay.prototype.sysWeek=30;
netsDay.prototype.sysHour=0;
netsDay.prototype.sysMin=0;
netsDay.prototype.sysSecond=0;
netsDay.prototype.sysValueTypeIndex=1;
netsDay.prototype.sysValueTypes=new Array();
netsDay.prototype.sysValueType="Y-M-D h:m:s";
netsDay.prototype.sysDateSPLIT="-";
netsDay.prototype.sysDateTimeSPLIT=" ";
netsDay.prototype.sysTimeSPLIT=":";
	
netsDay.prototype.sysYearBox="";
netsDay.prototype.sysMonthBox="";
netsDay.prototype.sysValueTypeBox="";
netsDay.prototype.sysBox="";
netsDay.prototype.sysOption="";
netsDay.prototype.sysOptionsHead="dayOptions_";
netsDay.prototype.sysOptionsBoxHead="dayOptions_Box_";
netsDay.prototype.sysOptionsInputHead="dayOptionsInput_";
netsDay.prototype.sysOptionSelected=0;

//-- ------ #Methods ------ --
//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("day_"+this.sControlName+"_Year");
	this.sysMonthBox=document.getElementById("day_"+this.sControlName+"_Month");
	this.sysDayBox=document.getElementById("day_"+this.sControlName+"_Day");
	this.sysTimeBox=document.getElementById("day_"+this.sControlName+"_Time");
	this.sysValueTypeBox=document.getElementById("day_"+this.sControlName+"_Format");
	this.sysBox=document.getElementById("day_"+this.sControlName+"_Box");
	this.sysOptionsHead="day_"+this.sControlName+"_Options_";
	this.sysOptionsBoxHead="day_"+this.sControlName+"_Options_Box_";
	this.sysOptionsInputHead="day_"+this.sControlName+"_OptionsInput_";
	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()+1;
	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_Day();
	this.set_Time();
	this.set_ValueType();
	this.setDayCell();
}
netsDay.prototype.addYear=function(){
	this.sysYear=parseInt(this.sysYear)+1;
	this.set_Year();
	this.setDayCell();
}
netsDay.prototype.subYear=function(){
	this.sysYear=parseInt(this.sysYear)-1;
	this.set_Year();
	this.setDayCell();
}
netsDay.prototype.selectYear=function(pValue){
	this.sysYear=pValue;
	this.set_Year();
	this.hiddenOption();
	this.setDayCell();
	chooseDay(this.sysYear,this.sysMonth,this.sysDay,this.sysHour,this.sysMin,this.sysSecond,this.sysValueTypeIndex);
}
netsDay.prototype.addMonth=function(){
	if(this.sysMonth>0 && this.sysMonth<12){
		this.sysMonth=parseInt(this.sysMonth)+1;
		this.set_Month();
		this.setDayCell();
	}
}
netsDay.prototype.subMonth=function(){
	if(this.sysMonth>1 && this.sysMonth<13){
		this.sysMonth=parseInt(this.sysMonth)-1;
		this.set_Month();
		this.setDayCell();
	}
}
netsDay.prototype.selectMonth=function(pValue){
	this.sysMonth=pValue;
	this.set_Month();
	this.hiddenOption();
	this.setDayCell();
	chooseDay(this.sysYear,this.sysMonth,this.sysDay,this.sysHour,this.sysMin,this.sysSecond,this.sysValueTypeIndex);
}
netsDay.prototype.addDay=function(){
	if(this.sysDay>0 && this.sysDay<12){
		this.sysDay=parseInt(this.sysDay)+1;
		this.set_Day();
		this.setDayCell();
	}
}
netsDay.prototype.subDay=function(){
	if(this.sysDay>1 && this.sysDay<13){
		this.sysDay=parseInt(this.sysDay)-1;
		this.set_Day();
		this.setDayCell();
	}
}
netsDay.prototype.selectDay=function(pValue){
	this.sysDay=pValue;
	this.set_Day();
	this.hiddenOption();
	this.setDayCell();
	chooseDay(this.sysYear,this.sysMonth,this.sysDay,this.sysHour,this.sysMin,this.sysSecond,this.sysValueTypeIndex);
}
netsDay.prototype.selectTime=function(pHour,pMin,pSecond){
	this.sysHour=pHour;
	this.sysMin=pMin;
	this.sysSecond=pSecond;
	this.set_Time();
	this.hiddenOption();
	chooseDay(this.sysYear,this.sysMonth,this.sysDay,this.sysHour,this.sysMin,this.sysSecond,this.sysValueTypeIndex);
}
netsDay.prototype.addValueType=function(){
	if(this.sysValueTypeIndex>-1 && this.sysValueTypeIndex<6){
		this.sysValueTypeIndex=parseInt(this.sysValueTypeIndex)+1;
		this.set_ValueType();
		this.setDayCell();
	}
}
netsDay.prototype.subValueType=function(){
	if(this.sysValueTypeIndex>0 && this.sysValueTypeIndex<7){
		this.sysValueTypeIndex=parseInt(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+"年";
	
	document.getElementById(this.sysOptionsInputHead+"Year").value=this.sysYear;
	return 0;
}
netsDay.prototype.set_Month=function(){
	if(this.sysMonth.toString().length<2){
		this.sysMonthBox.innerHTML="0"+this.sysMonth+"月";
	}else{
		this.sysMonthBox.innerHTML=this.sysMonth+"月";
	}
	
	document.getElementById(this.sysOptionsInputHead+"Month").value=this.sysMonth;
	return 0;
}
netsDay.prototype.set_Day=function(){
	if(this.sysDay.toString().length<2){
		this.sysDayBox.innerHTML="0"+this.sysDay+"日";
	}else{
		this.sysDayBox.innerHTML=this.sysDay+"日";
	}
	
	document.getElementById(this.sysOptionsInputHead+"Day").value=this.sysDay;
	return 0;
}
netsDay.prototype.set_Time=function(){
	this.sysTimeBox.innerHTML=this.sysHour+this.sysTimeSPLIT+this.sysMin+this.sysTimeSPLIT+this.sysSecond;
	
	document.getElementById(this.sysOptionsInputHead+"Hour").value=this.sysHour;
	document.getElementById(this.sysOptionsInputHead+"Min").value=this.sysMin;
	document.getElementById(this.sysOptionsInputHead+"Second").value=this.sysSecond;
	return 0;
}
netsDay.prototype.set_ValueType=function(){
	this.sysValueType=this.sysValueTypes[this.sysValueTypeIndex];
	this.sysValueTypeBox.innerHTML=this.sysValueType;
}
netsDay.prototype.set_DatetimeByInput=function(pType){
	if(pType=="Year"){
		this.sysYear=document.getElementById(this.sysOptionsInputHead+pType).value;
		this.set_Year();
	}else if(pType=="Month"){
		this.sysMonth=document.getElementById(this.sysOptionsInputHead+pType).value;
		this.set_Month();
	}else if(pType=="Day"){
		this.sysDay=document.getElementById(this.sysOptionsInputHead+pType).value;
		this.set_Day();
	}else if(pType=="Time"){
		this.sysHour=document.getElementById(this.sysOptionsInputHead+"Hour").value;
		this.sysMin=document.getElementById(this.sysOptionsInputHead+"Min").value;
		this.sysSecond=document.getElementById(this.sysOptionsInputHead+"Second").value;
		this.set_Time();
	}
	
	this.setDayCell();
	return 0;
}
netsDay.prototype.selectToday=function(){
	this.sysYear=this.sysToday.getYear();
	this.set_Year();
	this.sysMonth=this.sysToday.getMonth()+1;
	this.set_Month();
	this.sysDay=this.sysToday.getDate();
	this.set_Day();
	this.sysHour=this.sysToday.getHours();
	this.sysMin=this.sysToday.getMinutes();
	this.sysSecond=this.sysToday.getSeconds();
	this.set_Time();
	this.setDayCell();
	
	return 0;
}
netsDay.prototype.showOptions=function(pType){
	if(document.getElementById(this.sysOptionsHead+pType).className!=tmpCommon.sysHidden){
		this.hiddenOption();
		return 1;
	}
	this.hiddenOption();
	document.getElementById(this.sysOptionsHead+pType).className="dayOptionsBox";
	//-- #Input --
	if(pType=="Year"){
		document.getElementById(this.sysOptionsInputHead+pType).value=this.sysYear;
		this.sysYearBox.parentNode.className="dayOptionsCont_Selected";
	}else if(pType=="Month"){
		document.getElementById(this.sysOptionsInputHead+pType).value=this.sysMonth;
		this.sysMonthBox.parentNode.className="dayOptionsCont_Selected";
	}else if(pType=="Day"){
		document.getElementById(this.sysOptionsInputHead+pType).value=this.sysDay;
		this.sysDayBox.parentNode.className="dayOptionsCont_Selected";
	}else if(pType=="Time"){
		document.getElementById(this.sysOptionsInputHead+"Hour").value=this.sysHour;
		document.getElementById(this.sysOptionsInputHead+"Min").value=this.sysMin;
		document.getElementById(this.sysOptionsInputHead+"Second").value=this.sysSecond;
		this.sysTimeBox.parentNode.className="dayOptionsCont_Selected";
	}else if(pType=="ValueType"){
		this.sysValueTypeBox.parentNode.className="dayOptionsCont_Selected";
	}
	
	//-- #Options --
	var Coun0=0;
	var tmpCONTENT="";
	if(pType=="Year"){
		var tmpINT=this.sysToday.getYear()-30;
		while(Coun0<56){
			if(tmpINT==this.sysYear){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			tmpCONTENT+="<li class=\"dayOptionCell\"><a href=\"#Here\" class=\"Link1 "+tmpStyle+"\" onclick=\"tmpDay_"+this.sControlName+".selectYear("+tmpINT+");\">+ "+tmpINT+"</a></li>";
			tmpINT++;
			Coun0++;
		}
	}else if(pType=="Month"){
		while(Coun0<12){
			tmpINT=Coun0+1;
			if(tmpINT==this.sysMonth){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			tmpCONTENT+="<li class=\"dayOptionCell\"><a href=\"#Here\" class=\"Link1 "+tmpStyle+"\" onclick=\"tmpDay_"+this.sControlName+".selectMonth("+tmpINT+");\">+ "+tmpINT+"</a></li>";
			Coun0++;
		}
	}else if(pType=="Day"){
		tmpINT=this.sysMonth+1;
		tmpDatetime=new Date(this.sysYear+"/"+tmpINT+"/0");
		tmpDayCount=tmpDatetime.getDate();
		while(Coun0<tmpDayCount){
			tmpINT=Coun0+1;
			if(tmpINT==this.sysDay){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			tmpCONTENT+="<li class=\"dayOptionCell\"><a href=\"#Here\" class=\"Link1 "+tmpStyle+"\" onclick=\"tmpDay_"+this.sControlName+".selectDay("+tmpINT+");\">+ "+tmpINT+"</a></li>";
			Coun0++;
		}
	}else if(pType=="Time"){
		while(Coun0<24){
			tmpINT=Coun0;
			if(tmpINT==this.sysHour){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			tmpCONTENT+="<li class=\"dayOptionCell\"><a href=\"#Here\" class=\"Link1 "+tmpStyle+"\" onclick=\"tmpDay_"+this.sControlName+".selectTime("+tmpINT+",0,0);\">+ "+tmpINT+":0:0</a></li>";
			Coun0++;
		}
	}else if(pType=="ValueType"){
		while(Coun0<7){
			if(tmpINT==this.sysValueTypeIndex){
				tmpStyle="FRed1";
			}else{
				tmpStyle="FBlack3";
			}
			tmpCONTENT+="<li class=\"dayOptionCell\" style=\"width:100px;\"><a href=\"#Here\" class=\"Link1 "+tmpStyle+"\" onclick=\"tmpDay_"+this.sControlName+".selectValueType("+Coun0+");\">+ "+this.sysValueTypes[Coun0]+"</a></li>";
			Coun0++;
		}
	}
	
	document.getElementById(this.sysOptionsBoxHead+pType).innerHTML=tmpCONTENT;
	return 0;
}
netsDay.prototype.hiddenOption=function(){
	this.sysOptionSelected=0;
	document.getElementById(this.sysOptionsHead+"Year").className=tmpCommon.sysHidden;
	document.getElementById(this.sysOptionsHead+"Month").className=tmpCommon.sysHidden;
	document.getElementById(this.sysOptionsHead+"Day").className=tmpCommon.sysHidden;
	document.getElementById(this.sysOptionsHead+"Time").className=tmpCommon.sysHidden;
	document.getElementById(this.sysOptionsHead+"ValueType").className=tmpCommon.sysHidden;
	
	this.sysYearBox.parentNode.className="dayOptionsCont";
	this.sysMonthBox.parentNode.className="dayOptionsCont";
	this.sysDayBox.parentNode.className="dayOptionsCont";
	this.sysTimeBox.parentNode.className="dayOptionsCont";
	this.sysValueTypeBox.parentNode.className="dayOptionsCont";
	
	return 0;
}
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=\"#Here\" ";
		
		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;
}

