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

  入力内容チェック

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

var sendFlag = false;

//記事入力内容チェック
function checkDiaryForm(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;
}

//カラフルタイトル
function colorfulTitle() {
   //値（色、サイズなど下記プロパティに合わせて指定）
   var colors = ["pink", "skyblue", "orange", "silver"];

   //変更したい要素
   var elements = document.getElementsByTagName("h3");

   //trueにするとランダムに色を決定、しないときはfalse
   var random = true;


   for(var i = 0; i < elements.length; i++){
      var color;
      if (random) {
         color = colors[parseInt(Math.random() * colors.length)];
      } else {
         color = colors[i % colors.length];
      }
   //プロパティの指定
      elements[i].style.backgroundColor = color;
   }
}

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

  処理開始
**********************************************************************/

//読み込み完了時
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_diary_form = document.getElementById('diary_form');
	if (node_diary_form) {
		node_diary_form.onsubmit = function() {
			return checkDiaryForm(node_diary_form);
		};
	}
	var node_comment_form = document.getElementById('comment_form');
	if (node_comment_form) {
		node_comment_form.onsubmit = function() {
			return checkCommentForm(node_comment_form);
		};
	}

colorfulTitle();};
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
 
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

