/***************************************************************************************************
	creatDate.jsp - Tao ra 3 select ngay thang nam
***************************************************************************************************/
function setSelectDate(form, date, month, year) {
		for (i=0; i<100; i++){
			form.cmbYear.options[i] = new Option(i+1920,i+1920);
			if (year == i+1920) form.cmbYear.options[i].selected = true;
		}

		for (i=1; i<32; i++){
			if (i<10)
				form.cmbDay.options[i-1] = new Option("0"+i,"0"+i);
			else
				form.cmbDay.options[i-1] = new Option(i,i);
			if (date == i) form.cmbDay.options[i-1].selected = true;
		}	

		for (i=0; i<12; i++){
			if (month == i+1) form.cmbMonth.options[i].selected = true;
		}
	}

	function setDateToForm(form, date, month, year) {	//Dat cac combo box ngay,thang,nam ve ngay can dat
		for (i=0; i<100; i++) if (year == i+1920) form.cmbYear.options[i].selected = true;
		for (i=1; i<32; i++) if (date == i) form.cmbDay.options[i-1].selected = true;
		for (i=0; i<12; i++) if (month == i+1) form.cmbMonth.options[i].selected = true;
	}
	function setDateToForm(form, date) {	//Dat cac combo box ngay,thang,nam ve ngay can dat (date=dd/mm/yyyy)
		year = date.substring(6,10);
		month = date.substring(3,5);
		date = date.substring(0,2);

		for (i=0; i<100; i++) if (parseInt(year) == i+1920) form.cmbYear.options[i].selected = true;
		for (i=1; i<32; i++) if (parseInt(date) == i) form.cmbDay.options[i-1].selected = true;
		for (i=0; i<12; i++) if (parseInt(month) == i+1) form.cmbMonth.options[i].selected = true;
	}

	function checkDate(form){
		var date = form.cmbDay.value;
		var month = form.cmbMonth.value;
		var year = form.cmbYear.value;
		var number_of_month = getDayOfMonth(month,year);
		if (date<number_of_month) form.cmbDay.options[0].selected;
		form.cmbDay.options[28] = new Option(29,29);
		form.cmbDay.options[29] = new Option(30,30);
		form.cmbDay.options[30] = new Option(31,31);
		for (i=number_of_month; i<32; i++) form.cmbDay.options[number_of_month] = null
		if (date>number_of_month) {
			document.form.cmbDay.options[number_of_month-1].selected=true;
		} else {
			document.form.cmbDay.options[date-1].selected=true;
		}
	}

	function getDayOfMonth(month,year){
		var result=0;
		if ((month==1) || (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12)) result=31;
		if ((month==4) || (month==6) || (month==9) || (month==11)) result=30;
		if (month==2) {
			if (leapYear(year)==true) result=29
			else result = 28;
		}
		return result;		
	}

	function leapYear(year){
		var result = false;
		if (year % 4 == 0) result = true;
		if ((year % 100 == 0)&&(year % 400 != 0)) result = false;
		return result;
	}

