
function GenerateDateCombination(frmname,selyearname,selmonthname,seldatename,the1stOptValue,the1stOptText,classname,ftsize,beginyear,endyear,theyear,themonth,thedate,theDisp){

	//Parameters		Description

	//-------------------------------------------------------------------------------------------------

	//frmname		:	Required , The name of form where the selectbox belong .		
	//selyearname	:	Required , The selectbox's name of year part .
	//selmonthname	:	Required , The selectbox's name of month part .
	//seldatename	:	Required , The selectbox's name of date part .
	//nullvalue		:	Optional , show '請選擇' at the first option which value=0 and omit the entire arguments left if true .
	//classname		:	Optional , Set the CSS class of the select box .
	//ftsize		:	Optional , Set the font size of the select box in 'pt' , default is 10pt .
	//beginyear		:	Optional , The start year of the selectbox's year part , if omitted , default is 10 years less then this year .
	//endyear		:	Optional , The end year of the selectbox's year part , if omitted , default is 10 years more then this year .
	//theyear		:	Optional , The default selected year you wished , if omitted , default is this year .
	//themonth		:	Optional , The default selected month you wished , if omitted , default is this month .
	//thedate		:	Optional , The default selected date you wished , if omitted , default is today .

	if(!frmname||!selyearname||!selmonthname||!seldatename){	//If not specify the form name ,and each select box's name .
		document.write('參數不完整，請檢查 FormName , Year Select Name , Month Select Name , Date Select Name');
		return false;
	}
	if(!ftsize) ftsize=11
	if(beginyear&&!isNaN(beginyear))parseInt(beginyear)<0?0:beginyear;
	else beginyear=false;

	if(endyear&&!isNaN(endyear))parseInt(endyear)<0?0:endyear;
	else endyear=false;

	if(theyear&&!isNaN(theyear))parseInt(theyear)<0?0:theyear;
	else theyear=false;
	
	if(themonth&&!isNaN(themonth)){
		if(parseInt(themonth)<1){
			themonth=1;
		}
		else if(parseInt(themonth)>12){
			themonth=parseInt(themonth)%12
			themonth=0?1:themonth;
		}
	}
	else themonth=false;

	if(thedate&&!isNaN(thedate)){
		if(parseInt(thedate)<1){
			thedate=1;
		}
		else if(parseInt(thedate)>31){
			thedate=determinedate(theyear,themonth);
		}
	}
	else thedate=false;

	var today=new Date();									//Create object today
	var yyyy=(theyear)?theyear:today.getFullYear();			//Get the current year
	var mm=(themonth)?themonth:today.getMonth()+1;			//Get the current month
	var dd=(thedate)?thedate:today.getDate();				//Get the current date
	var bgnyr=(beginyear)?beginyear:today.getFullYear()-10;
	var endyr=(endyear)?endyear:today.getFullYear()+10;
	var aryDisp=theDisp.split(":");

	if(bgnyr>endyr){
		var tempyr=bgnyr;
		bgnyr=endyr;
		endyr=tempyr;
	}

	if(yyyy<bgnyr||yyyy>endyr)yyyy=bgnyr;

	var yrsel;
	var mnsel;
	var daysel;
	var opt1stAssigned=the1stOptText!="";

	//************ The year select box contains this year to 10 years later ****************

	yrsel="<select name=\""+selyearname+"\" id=\""+selyearname+"\" class=\""+classname+"\" style=\"font-size: "+ftsize+"px; font-family:Tahoma;\" onchange=\"switchthedays('"+frmname+"','"+selyearname+"','"+selmonthname+"','"+seldatename+"','"+the1stOptValue+"','"+the1stOptText+"')\">";
	if(opt1stAssigned) yrsel+="<option value=\""+the1stOptValue+"\">"+the1stOptText+"</option>";
	for(i=bgnyr;i<=endyr;i++){
		if(!opt1stAssigned&&i==yyyy||theyear&&i==yyyy)yrsel+="<option value=\""+i+"\" selected>"+i+"</option>";
		else yrsel+="<option value="+i+">"+i+"</option>";
	}
	yrsel=yrsel+"</select> 年 ";

	//************ The month select box contains 12 months and this month was default selected ****************

	mnsel="<select name=\""+selmonthname+"\" id=\""+selmonthname+"\" class=\""+classname+"\" style=\"font-size: "+ftsize+"px; font-family: Tahoma;\" onchange=\"switchthedays('"+frmname+"','"+selyearname+"','"+selmonthname+"','"+seldatename+"','"+the1stOptValue+"','"+the1stOptText+"')\">";
	if(opt1stAssigned) mnsel+="<option value=\""+the1stOptValue+"\">"+the1stOptText+"</option>";
	for(i=1;i<=12;i++){
		if(!opt1stAssigned&&i==mm||themonth&&i==mm)mnsel+="<option value=\""+i+"\" selected>"+i+"</option>";
		else mnsel+="<option value=\""+i+"\">"+i+"</option>";
	}
	mnsel=mnsel+"</select> 月 ";
	if(aryDisp[1]=="0") mnsel="<span style=\"display: none;\">"+mnsel+"</span>";

	//************ The data select box contains the days taht depends on *******************
	//************ this year and this month and today was default selected ****************

	daysel="<select name=\""+seldatename+"\" id=\""+seldatename+"\" class=\""+classname+"\" style=\"font-size: "+ftsize+"px; font-family: Tahoma;\">";
	if(opt1stAssigned) daysel+="<option value=\""+the1stOptValue+"\">"+the1stOptText+"</option>";
	for(i=1;i<=determinedate(yyyy,mm);i++){
		if(!opt1stAssigned&&i==dd||thedate&&i==dd)daysel+="<option value=\""+i+"\" selected>"+i+"</option>";
		else daysel+="<option value=\""+i+"\">"+i+"</option>";
	}
	daysel=daysel+"</select>";
	if(aryDisp[2]=="0") daysel="<span style=\"display: none;\">"+daysel+" 日</span>";

	//*************** Show in the document *********************

	document.write (yrsel+mnsel+daysel);
}

//************ To determine whether this year is bissextile and  *******
//************ how many days should this month contains ****************


function determinedate(yearvalue,monthvalue){
	switch(monthvalue){
		case 2:
			if(yearvalue%400==0 || (yearvalue%4==0 && yearvalue%100!=0))days=29;	//29 days in bissextile February 
			else days=28;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			days=30;
			break;
		default:
			days=31;
	}
	return days;
}

//************ Change the contents of the date select box *****************

function switchthedays(frmname,selyearname,selmonthname,seldatename,the1stOptValue,the1stOptText){
	
	var today=new Date();				//Create object today
	var dd=today.getDate();				//Get the current date
	var objmonth=eval("document."+frmname+"."+selmonthname+".value");
	if(objmonth=="0") objmonth=today.getMonth();
	var objyear=eval("document."+frmname+"."+selyearname+".value");
	if(objyear=="0") objyear=today.getFullYear();
	var objdaysel=eval("document."+frmname+"."+seldatename);

	objdaysel.length=determinedate(parseInt(objyear),parseInt(objmonth));
	if(the1stOptText!=""){
		objdaysel.length+=1;
		objdaysel.options[0].value=the1stOptValue;
		objdaysel.options[0].text=the1stOptText;
		for(i=1;i<objdaysel.length;i++){
			objdaysel.options[i].value=i;
			objdaysel.options[i].text=i;
		}
	} 
	else{
		for(i=0;i<objdaysel.length;i++){
			objdaysel.options[i].value=i+1;
			objdaysel.options[i].text=i+1;
			if(i==dd-1)objdaysel.options[i].selected=true;
		}
	}
}
