var chgBBAd = new Array();
var seenBBAd = 1;
chgBBAd.push('<a href="http://px.a8.net/svt/ejp?a8mat=CG523+CSTJ02+2Z8+5ZMCI" target="_blank">海外格安航空券の24時間自動予約　イーツアー</a><img border="0" width="1" height="1" src="http://www15.a8.net/0.gif?a8mat=CG523+CSTJ02+2Z8+5ZMCI" alt="" />');
chgBBAd.push('<a href="http://px.a8.net/svt/ejp?a8mat=1I6WLQ+3MDY9E+1ZPY+I05C2" target="_blank">会員登録無料のNHKオンデマンド！</a><img border="0" width="1" height="1" src="http://www14.a8.net/0.gif?a8mat=1I6WLQ+3MDY9E+1ZPY+I05C2" alt="" />');
chgBBAd.push('<a href="http://hb.afl.rakuten.co.jp/hsc/0858b12e.a22abcfa.04becbd5.df3f59ca/" target="_blank">楽天国際配送－ご購入商品を海外にお届け！－</a>');
chgBBAd.push('<a href="http://www.amazon.co.jp/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.co.jp%2Fgp%2Ffeature.html%3Fie%3DUTF8%26ref%255F%3Damb%255Flink%255F84107516%255F3%26docId%3D1000252936&tag=javascriptkow-22&linkCode=ur2&camp=247&creative=7399">村上春樹作品に登場するクラシック音楽</a><img src="https://www.assoc-amazon.jp/e/ir??t=javascriptkow-22&l=ur2&o=9" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />');

var BBchgContent = chgBBAd[0]; // デフォルトで表示されるもの（クッキーをオフにしている場合など）
var BBcExpires;
var nowDate = new Date();
nowDate.setMonth(nowDate.getDate()+14); //２週間後にクッキー消滅
BBcExpires = nowDate.toGMTString();
var cookieValue = document.cookie;
var startOfValue = cookieValue.indexOf(" seenBBAd=");
if (startOfValue == -1) {
   startOfValue = cookieValue.indexOf("seenBBAd=");
   if (startOfValue == -1) {
      seenBBAd = 0;
      chgContent = chgBBAd[seenBBAd];
   }
}
if (seenBBAd) {
   startOfValue = cookieValue.indexOf("=", startOfValue) + 1;
   var endOfValue = cookieValue.indexOf(";", startOfValue);
   if (endOfValue == -1) {
      endOfValue = cookieValue.length;
   }
   seenBBAd = Number(cookieValue.substring(startOfValue, endOfValue));
   seenBBAd = (seenBBAd<chgBBAd.length-1) ? seenBBAd+1 : 0;
   BBchgContent = chgBBAd[seenBBAd];
}
document.cookie = "seenBBAd=" + seenBBAd + ";expires=" + BBcExpires + ";"
function chgvotemsg(num) {
   	var commentId = "comment_" + num;
   	document.getElementById("votemsg").innerHTML = document.getElementById(commentId).innerHTML;
}
function nkName(nkdate, description) {
   	this.nkdate = nkdate;
   	this.description = description;
	return this;
}
function nikkinavi() {
	var nknav = "<select onchange='chgnikki(this.value)'>";
	nknav += "<option selected='selected'>他の日の日記を読む</option>";
	if(nikkis) {
		for(i=0;i<nikkis.length;i++) nknav += "<option value='" + nikkis[i].nkdate + "'>" + nikkis[i].nkdate + "</option>";
		nknav += "</select>";
	}
	document.getElementById("nikkinavimenu").innerHTML = nknav;
}
function chgnikki(nikkidate) {
	for(i=0;i<nikkis.length;i++) {
		document.getElementById(nikkis[i].nkdate).style.display = "none";
	}
	document.getElementById("subtitles").style.display = "none";
	document.getElementById("comments").innerHTML = null;
	nikkidate = (isNaN(nikkidate)) ? nikkis[nikkis.length-1].nkdate : nikkidate;
	document.getElementById(nikkidate).style.display = "block";
	window.scrollTo(0,0);
}
function crsub() { // 日記サブタイトル一覧作成
	var sublist = "<div>日記サブタイトル一覧</div>";
	for(i=0;i<nikkis.length;i++) {
		sublist += "<span class='subdate'><a href='javascript:chgnikki(" + nikkis[i].nkdate + ")'>";
		sublist += nikkis[i].nkdate + "</a></span><span class='subdescript'>";
		sublist += nikkis[i].description + "</span>"; 
	}
	document.getElementById("subtitles").innerHTML = sublist;
}

<!-- カレンダー作成開始 -->
function createCalendar(theTime) {
	var zOut = "";
	var theVTime = new Date(theTime)
	var nextMonth = new Date(theTime.getFullYear(), theTime.getMonth()+1,1);
	var theYY = theTime.getFullYear();
	var theMM = theTime.getMonth() + 1;
	var theDofW = theTime.getDay();

	zOut = '<caption id="monthtitle">' + theYY + '年' + theMM + '月</caption>\n';
	zOut += '<tr><th class="red">日</th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th>';
	zOut += '<th class="blue">土</th></tr>\n';
	theVTime.setDate(1);
	zOut += '<tr>';
	for (i=1; i<theDofW+1; i++) {
		zOut += '<td></td>';
	}
	for (i=1; theVTime<nextMonth; i++) {
		var begintd = '<td>', endtd = '</td>';
		if (nikkis != null) {
			for (j=0; j<nikkis.length; j++) {
				if (i == nikkis[j].nkdate.substr(6)) {
					begintd = '<td><a href="javascript:chgnikki(' + nikkis[j].nkdate + ')">';
					endtd = '</a></td>';
				} // end of second if
      			} // end of second for
   		} // end of first if
   		if (theVTime.getDay()<6) {
      			zOut += begintd + i + endtd;
   		} else if(theVTime.setDate(i+1)<nextMonth) {
      			zOut += begintd + i + endtd + '</tr>\n<tr>';
   		} else {
      			zOut += begintd + i + endtd;
   		} // end of third if
   		theVTime.setDate(i+1);
	} // end of first for

	for(j=theVTime.getDay();j<=6;j++) zOut += '<td></td>';

	zOut += '</tr>\n';
	return zOut;
} // function createCalendar 終わり

<!-- カレンダー作成終了 -->

function init() {
	document.getElementById("main").style.display = "block";
	if (nikkis) {
		crsub();
		for(var i=0;i<nikkis.length;i++) {
			document.getElementById(nikkis[i].nkdate).style.display = "none";
		}
	}
	catime(5000);
	nikkinavi();
}
function initnew() {
	init();
	if(document.getElementById("calendar")) {
		if (nikkis) {
			document.getElementById(nikkis[nikkis.length-1].nkdate).style.display = "block";
		}
	} else { // 検索の場合
		if(nikkis) {
			document.getElementById("subtitles").style.display = "block";
		} else {
			document.getElementById("nonefound").style.display = "block";
		}
	}
}
function initarchive() { // 日記リスト表示
	init()
	document.getElementById("subtitles").style.display = "block";
	window.scrollTo(0,0);
}
function initsearch() { // search.php用の初期化バッチ
	init();
	if(nikkis) {
		document.getElementById("subtitles").style.display = "block";
	} else {
		document.getElementById("nonefound").style.display = "block";
	}
}

<!-- カレンダーナビゲーション -->
function showprev(form) { // 前の月
	if ((calyear==styear) && (calmonth==stmonth)) { // 一番古い月からは前に進まない
		return false;
	}
	var newMonth = new Date(calyear, calmonth-2, 1);
	form.theyear.value = newMonth.getFullYear();
	form.themonth.value = newMonth.getMonth()+1;
	return true;
}

function shownext(form) { // 次の月
	var today = new Date();
	var newMonth = new Date(calyear, calmonth, 1);
	if (newMonth<=today) {
		form.theyear.value = newMonth.getFullYear();
		form.themonth.value = newMonth.getMonth()+1;
		return true;
	} else {
		return false;
	}
}

function turnbg(obj,color) { // ボタンの背景色を変える
	obj.style.background=color;
}

function shortcut(form) { // 選択リストからのショートカット
	form.submit();
}

function enterKeyExec(evt,form) {
   evt = (evt) ? evt : event;
   var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
   if(charCode == 13 || charCode == 3) {
      form.submit();
   }
}
var nikkis;