
function collapseAllQuestions() {
	changeDisplayByClassName('exam exam_collapse', 'block');
	changeDisplayByClassName('exam exam_expand', 'none');
}

function expandAllQuestions() {
	changeDisplayByClassName('exam exam_collapse', 'none');
	changeDisplayByClassName('exam exam_expand', 'block');
}

function collapseQuestion(n) {
	changeDisplay('exam_' + n + '_collapse', 'block');
	changeDisplay('exam_' + n + '_expand', 'none');
}

function expandQuestion(n) {
	changeDisplay('exam_' + n + '_collapse', 'none');
	changeDisplay('exam_' + n + '_expand', 'block');
}

var date = new Date();
var min_year = date.getFullYear(); 
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();

var days = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function getLastDay(y, m) {
	if(m == 2 && (((y % 4) == 0 && (y % 100) != 0) || (y % 400) == 0) ) {
		return 29;
	} else {
		return days[m - 1];
	}
}

function changeDate() {
	var selectYear = getById('date_year');
	var selectMonth = getById('date_month');
	var selectDay = getById('date_day');
	year = selectYear.options[selectYear.selectedIndex].value;
	month = selectMonth.options[selectMonth.selectedIndex].value;
	day = selectDay.options[selectDay.selectedIndex].value;
	refleshDate();
}

function refleshDate() {
	var selectYear = getById('date_year');
	var selectMonth = getById('date_month');
	var selectDay = getById('date_day');
	var y;
	var m;
	var d;
	
	selectYear.length = 0;
	for(var i = 0; i < 3; i++) {
		y = min_year + i;
		if(y == year) {
			selectYear.options[i] = new Option(y, y, true, true);
		} else {
			selectYear.options[i] = new Option(y, y);
		}
	}
	selectMonth.length = 0;
	for(var i = 0; i < 12; i++) {
		m = i + 1;
		if(m == month) {
			selectMonth.options[i] = new Option(m, m, true, true);
		} else {
			selectMonth.options[i] = new Option(m, m);
		}
	}
	selectDay.length = 0;
	var last = getLastDay(year, month); 
	for(var i = 0; i < last; i++) {
		d = i + 1;
		if( (d == day) || ((d == last) && (day > last)) ) {
			selectDay.options[i] = new Option(d, d, true, true);
		} else {
			selectDay.options[i] = new Option(d, d);
		}
	}
}

function selectDeadline() {
	var deadline = getById('deadline_type');
	var type = deadline.options[deadline.selectedIndex].value;
	if(type == 'date') {
		changeDisplay('date_select', 'block');
		changeDisplay('time_select', 'none');
	} else if(type == 'time') {
		changeDisplay('date_select', 'block');
		changeDisplay('time_select', 'block');
	} else {
		changeDisplay('date_select', 'none');
		changeDisplay('time_select', 'none');
	}
}

