months_31 = new Array();
months_31[0] = 1
months_31[1] = 3
months_31[2] = 5
months_31[3] = 7
months_31[4] = 8
months_31[5] = 10
months_31[6] = 12

months_30 = new Array();
months_30[0] = 4
months_30[1] = 6
months_30[2] = 9
months_30[3] = 11

var bisextil_days = 29;

function febDays(y){
	if ((y%4) == 0) bisextil_days = 29;
	else bisextil_days = 28;
	return bisextil_days;
}

function IsBisextil(obj,id,type){
	febDays(obj.value);
	myFormElement = obj.form["month_" + id];
	if(myFormElement.value == 2) daysInMonth(myFormElement,id,type);
	else setDateForm(obj,id,type);
}

function daysInMonth(obj,id,type){
	var nb_days = 0;
	var myMonth = obj.value;
	for (i=0; i<months_31.length ; i++){
		if (months_31[i]==myMonth) nb_days=31;
	}
	if (!nb_days){
		for (i=0; i<months_30.length ; i++){
			if (months_30[i]==myMonth) nb_days=30;
		}
	}
	if (!nb_days) nb_days = febDays(obj.form["year_" + id].value);

	var myFormElement = obj.form["day_" + id];

	try{
		var check = myFormElement.value;
		myFormElement.options.length = 0;
		for (i=0;i<nb_days;i++){
			myFormElement.options.length = i;
			if(i < 9) tmpVal = "0" + (i+1);
			else tmpVal = (i+1);
			
			myFormElement.options[i] = new Option(tmpVal);
			myFormElement.options[i].value = tmpVal;
		}
		if (myFormElement.options[check-1]) myFormElement.options[check-1].selected = true;
		else myFormElement.options[i-1].selected = true;
	}
	catch(e){}
	setDateForm(obj,id,type);
}
function setDateForm(obj,id,type){
	if (type == "string") obj.form[id].value = obj.form["year_" + id].value + "-" + obj.form["month_" + id].value + "-" + obj.form["day_" + id].value + " " + obj.form["hour_" + id].value + ":" + obj.form["minute_" + id].value +":" + obj.form["second_" + id].value;
	else obj.form[id].value = "{ts '" + obj.form["year_" + id].value + "-" + obj.form["month_" + id].value + "-" + obj.form["day_" + id].value + " " + obj.form["hour_" + id].value + ":" + obj.form["minute_" + id].value +":" + obj.form["second_" + id].value + "'}";
}