var MaxDay = new Array();

MaxDay[0] = 31;
MaxDay[1] = 28;
MaxDay[2] = 31;
MaxDay[3] = 30;
MaxDay[4] = 31;
MaxDay[5] = 30;
MaxDay[6] = 31;
MaxDay[7] = 31;
MaxDay[8] = 30;
MaxDay[9] = 31;
MaxDay[10]= 30;
MaxDay[11]= 31;		

function FFremoveAllSelectOptionDate(obj){
	 var size   = obj.length;
	 for(i=0; i < size; i++){
		obj.options[0] = null;
	}
}
function FFsetIndexByValueDate(obj,selvalue){
	var tempValue = "";
	var size = obj.length;

	for (var i=0; i<size; i++){
		tempValue = obj.options[i].value;
		if(tempValue == null) return;
		if (selvalue == tempValue){		
			obj.selectedIndex=i;	
			break;
		}		
	}
}


function FFmakeSelectOptionYear( obj , defaultValue , startyear, endyear){
	if(startyear==null) startyear	= 2001
	if(endyear == null) endyear		= 2010
		
	for(i=startyear;i<=endyear;i++){
		var new_option = new Option(i,i); //name,value
		obj.options[i-startyear] = new_option;
	}
	obj.selctedIndex=0;

	if(defaultValue!=null){
		FFsetIndexByValueDate(obj,defaultValue);
	}				
}
function FFmakeSelectOptionMonth( obj , defaultValue){
	for(i=0;i<12;i++){
		var new_option = new Option(i+1,i+1); //name,value
		obj.options[i] = new_option;
	}
	obj.selctedIndex=0;

	if(defaultValue!=null){
		FFsetIndexByValueDate(obj,defaultValue);
	}				
}
function FFredefineSelectOptionDay( yearobj , monthobj , obj,defaultValue ){
	var year  = yearobj.options[yearobj.selectedIndex].value;
	var month = monthobj.options[monthobj.selectedIndex].value;
	var curDay = obj.options[obj.selectedIndex].value;
	var curMaxDay = obj.options[obj.options.length-1].value;
	var tmpMaxDay = MaxDay[month-1];

	if(month==2 && year%4 == 0){
		tmpMaxDay ++;
	}

	if(tmpMaxDay != curMaxDay){
		FFmakeSelectOptionDay( yearobj , monthobj , obj );
	}	
	FFsetIndexByValueDate(obj,curDay);

}
function FFmakeSelectOptionDay( yearobj, monthobj , obj ,defaultValue){		
	var year  = yearobj.options[yearobj.selectedIndex].value;
	var month = monthobj.options[monthobj.selectedIndex].value;
	var tmpMaxDay = MaxDay[month-1];

	if(month==2 && year%4 == 0){
		tmpMaxDay ++;
	}

	var curDay = 1;
	if(obj.options.length>0){
		curDay = obj.options[obj.selectedIndex].value;
	}

	FFremoveAllSelectOptionDate(obj);
	for(i=0;i<tmpMaxDay;i++){
		var new_option = new Option(i+1,i+1); //name,value
		obj.options[i] = new_option;
	}

	if(defaultValue!=null){
		FFsetIndexByValueDate(obj,defaultValue);
	}else{
//		alert(curDay);
		FFsetIndexByValueDate(obj,curDay);	
	}				
}
