/**********************************************************************

  輸入內容檢查

**********************************************************************/

var sendFlag = false;

//作品輸入內容檢查
function checkGalleryForm(form) {
	if (form.subj && !form.subj.value) {
		alert('尚未輸入作品名。');
		return false;
	}
	if (form.text && !form.text.value) {
		alert('尚未輸入介紹文。');
		return false;
	}

	if (sendFlag == true) {
		alert('禁止重複發表。');
		return false;
	} else {
		sendFlag = true;
	}

	return true;
}

//留言輸入內容檢查
function checkCommentForm(form) {
	if (form.name && !form.name.value) {
		alert('尚未輸入暱稱。');
		return false;
	}
	if (form.text && !form.text.value) {
		alert('尚未輸入留言內容。');
		return false;
	}

	if (sendFlag == true) {
		alert('禁止重複發表。');
		return false;
	} else {
		sendFlag = true;
	}

	return true;
}

/**********************************************************************

  月曆

**********************************************************************/

//今日的標示色變更
function setCalendar() {
	var today = new Date();
	var year  = new String(today.getFullYear());
	var month = new String(today.getMonth() + 1);
	var date  = new String(today.getDate());

	while (month.length < 2) {
		month = '0' + month;
	}
	while (date.length < 2) {
		date = '0' + date;
	}

	var node_calendar_cel = document.getElementById('calendar_' + year + month + date);
	if (node_calendar_cel) {
		node_calendar_cel.className = 'today';
	}

	return;
}

/**********************************************************************

  處理開始

**********************************************************************/

//讀取完成時
window.onload = function() {
	//頂部視窗更新用
	if (top.location != self.location) {
		var node_a = document.getElementsByTagName('a');
		for (var i in node_a) {
			if (node_a[i].className == 'top') {
				node_a[i].onclick = function() {
					window.top.location = this.href;
				};
			}
		}
	}

	//月曆用
	setCalendar();

	//輸入內容檢查
	var node_gallery_form = document.getElementById('gallery_form');
	if (node_gallery_form) {
		node_gallery_form.onsubmit = function() {
			return checkGalleryForm(node_gallery_form);
		};
	}
	var node_comment_form = document.getElementById('comment_form');
	if (node_comment_form) {
		node_comment_form.onsubmit = function() {
			return checkCommentForm(node_comment_form);
		};
	}
};
