/**********************************************************************

  入力内容チェック

**********************************************************************/

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;
}

/**********************************************************************

  処理開始

**********************************************************************/

//読み込み完了時
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);
		};
	}
};

//ポップアップ用 flg 0:HTML 1:ビデオ 2:画像
var sw; var str; var Astr;
function pop(url, w, h, flg){
sw = 0; wi = 640; hi = 480;
if(!!window.screen){
ScreenWIDTH = screen.width;
} else {
ScreenWIDTH = 0;
}
if(!!window.screen){
ScreenHEIGHT = screen.height;
} else {
ScreenHEIGHT = 0;
}
if(w <= ScreenWIDTH){
Pwscr = (ScreenWIDTH - w) / 2;
} else {
sw = 1; w = wi;
}
if(h <= ScreenHEIGHT){
Phscr = (ScreenHEIGHT - h) / 2;
} else {
sw = 1; h = hi;
}
if(sw){
str = ",left=0,top=0,screenX=0,screenY=0,scrollbars=yes,resizable=yes";
} else {
str = ",left=" + Pwscr + ",top=" + Phscr + ",screenX=0,screenY=0,scrollbars=no,resizable=no";
}
Astr = "width=" + w + ",height=" + h + str;
if (flg == 0) {
//HTML
subwin = window.open(url,'window1',Astr);
if(sw){ subwin.window.scrollTo(0, 0); }
} else if (flg == 1) {
//ビデオ
subwin = window.open('','',Astr);
subwin.document.open();
subwin.document.write( "<ht" + "ml><he" + "ad>\n");
subwin.document.write( "<title></title>\n");
subwin.document.write( "<style type='text/css'>\n");
subwin.document.write( "<!--\n");
subwin.document.write( "body { margin: 0px }\n");
subwin.document.write( "-->\n");
subwin.document.write( "</style>\n");
//「X」キーを押下時、ウィンドウをクローズ
subwin.document.write( "<script type='text/javascript'>\n");
subwin.document.write( "<!--\n");
subwin.document.write( "listenKey()\n");
subwin.document.write( "function getKey(e) {\n");
subwin.document.write( " if (e == null) { keycode = event.keyCode }\n");
subwin.document.write( " else { keycode = e.which }\n");
subwin.document.write( " key = String.fromCharCode(keycode).toLowerCase()\n");
subwin.document.write( " if (key == 'x') { window.close() }\n");
subwin.document.write( "}\n");
subwin.document.write( "function listenKey() {\n");
subwin.document.write( " document.onkeypress = getKey\n");
subwin.document.write( "}\n");
subwin.document.write( "//-->\n");
subwin.document.write( "</script>\n");
subwin.document.write( "</he" + "ad>\n");
subwin.document.write( "<body bgcolor='#000000' oncontextmenu='return false'>\n");
subwin.document.write( "<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'>\n");
subwin.document.write( "<tr><td align='center'>\n");
//ビデオサイズ
subwin.document.write( "<object id='player' width='" + w + "' height='" + h + "' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'>\n");
//ビデオファイル
subwin.document.write( "<param name='URL' value='" + url + "'>\n");
//オートスタート
subwin.document.write( "<param name='autoStart' value='true'>\n");
//再生回数
subwin.document.write( "<param name='PlayCount' value='1'>\n");
//プレイメニュー表示
subwin.document.write( "<param name='enableContextMenu' value='false'>\n");
subwin.document.write( "<param name='uiMode' value='full'>\n");
subwin.document.write( "<param name='stretchToFit' value='false'>\n");
subwin.document.write( "<param name='windowlessvideo' value='false'>\n");
subwin.document.write( "</object>\n");
subwin.document.write( "</td></tr>\n");
subwin.document.write( "</table>\n");
subwin.document.write( "");
subwin.document.write( "</bo" + "dy></ht" + "ml>");
subwin.document.close();
} else {
//画像
subwin = window.open('','',Astr);
subwin.document.open();
subwin.document.write( "<ht" + "ml><he" + "ad>\n");
subwin.document.write( "<meta http-equiv='imagetoolbar' content='no'>\n");
subwin.document.write( "<title></title>\n");
subwin.document.write( "<style type='text/css'>\n");
subwin.document.write( "<!--\n");
subwin.document.write( "body { margin: 0px }\n");
subwin.document.write( "-->\n");
subwin.document.write( "</style>\n");
//「X」キーを押下時、ウィンドウをクローズ
subwin.document.write( "<script type='text/javascript'>\n");
subwin.document.write( "<!--\n");
subwin.document.write( "listenKey()\n");
subwin.document.write( "function getKey(e) {\n");
subwin.document.write( " if (e == null) { keycode = event.keyCode }\n");
subwin.document.write( " else { keycode = e.which }\n");
subwin.document.write( " key = String.fromCharCode(keycode).toLowerCase()\n");
subwin.document.write( " if (key == 'x') { window.close() }\n");
subwin.document.write( "}\n");
subwin.document.write( "function listenKey() {\n");
subwin.document.write( " document.onkeypress = getKey\n");
subwin.document.write( "}\n");
subwin.document.write( "//-->\n");
subwin.document.write( "</script>\n");
subwin.document.write( "</he" + "ad>\n");
subwin.document.write( "<body bgcolor='#000000' oncontextmenu='return false'>\n");
subwin.document.write( "<center>\n");
subwin.document.write( "<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'>\n");
subwin.document.write( "<tr>\n");
subwin.document.write( "<td align='center'><img src='" + url + "' width='" + w + "' height='" + h + "' border='0' onClick='window.close()' alt='クリックすると閉じます'></td>\n");
subwin.document.write( "</tr>\n");
subwin.document.write( "</table>\n");
subwin.document.write( "</center>\n");
subwin.document.write( "");
subwin.document.write( "</bo" + "dy></ht" + "ml>");
subwin.document.close();
}
}

