<!--
/*------ set and check multiple slot ------*/

// check start time and end time
function checkTime(n) {
	if (isNaN(n) || n == null || n==0) {
		alert('Parameter error');
		return false;
	}

	var regempty    = /^\s*$/;

	var dis_slot    = 'Slot ' + n + ' : ';
	var dis_start_time = 'Start Time ';
	var dis_end_time   = 'End Time ';
	var st = document.getElementById('start_time'+n); // Rehearsal start time
	var ed = document.getElementById('end_time'+n); // Rehearsal end time

	if ( regempty.test(st.value) ) {
		alert(dis_slot + dis_start_time + ' field is required!');
		st.focus();
		return false;
	}
	if ( regempty.test(ed.value) ) {
		alert(dis_slot + dis_end_time + ' field is required!');
		ed.focus();
		return false;
	}

	// following check start time and end time
	var start, end;
	start = st.value.split(":");
	start[0] = parseInt(start[0], 10);
	start[1] = parseInt(start[1], 10);
	if (isNaN(start[0]) || isNaN(start[1]) || (start[1]!=0 && start[1]!=30)) {
		alert(dis_slot + dis_start_time + ' field is invalid!');
		st.focus();
		return false;
	}
	end = ed.value.split(":");
	end[0] = parseInt(end[0], 10);
	end[1] = parseInt(end[1], 10);
	if (isNaN(end[0]) || isNaN(end[1]) || (end[1]!=0 && end[1]!=30)) {
		alert(dis_slot + dis_end_time + ' field is invalid!');
		ed.focus();
		return false;
	}
	diff = (end[0] - start[0])*60 + end[1] - start[1];
	if (diff <= 0) {
		alert (dis_slot + dis_end_time + 'must be later than ' + dis_start_time);
		ed.focus();
		return false;
	} else if (diff < 30) { // 30 minuters
		alert (dis_slot + 'time duration must be no less than half an hour.');
		ed.focus();
		return false;
	}
	return true;
} // end checktime(n)

function setAddStatus() {
	// 设置 add more slot 显示状态
	var i;
	for (i = 10; i > 0; i--) {
		if (document.getElementById('mul_slot'+i).style.display == 'block') {
			document.getElementById('add_slot'+i).style.display = 'block';
			break;
		}
	}
}

// more booking dates
function createSlot(n) {
	var i;
 	/* 第一个日期是必须的 (这里不能用 双斜杠 注释，要么会出错)*/
	for (i = 2; i < 11; i++) {
		if (document.getElementById('mul_slot'+i).style.display == '' || document.getElementById('mul_slot'+i).style.display == 'none') {
			document.getElementById('mul_slot'+i).style.display = 'block';
			document.getElementById('valid_item'+i).value = '1';
			break;
		}
	}

	if (n > 0 && n < 10) { // 针对 1 - 9 slot 自身的 add slot link
		document.getElementById('add_slot' + n).style.display = 'none';
	}

	setAddStatus(); // 设置 add more slot 显示状态

	// 判断有多少个slot,若有10个（最大数），则不再显示 添加的链接
	var d, tag;
	tag = 1;
	for (i = 2; i < 11; i++) { // 第一个slot是必须的
		d = document.getElementById('mul_slot'+i).style.display;
		if (d == 'block') {
			tag = tag + 1;
		}
	}
	if (tag == 10) {
		document.getElementById('add_slot10').style.display = 'none';
	}

}

// cancel one item of booking dates

function cancelSlot(n) {
	if (!isNaN(n) && n > 1 && n < 11) {
		document.getElementById('mul_slot'+n).style.display = 'none';
		document.getElementById('valid_item'+n).value = '0';
	}

	// 设置 add more slot 显示状态
	var i;
	for (i = 10; i > 0; i--) {
		if (document.getElementById('mul_slot'+i).style.display == 'block') {
			document.getElementById('add_slot'+i).style.display = 'block';
			break;
		}
	}
}
-->