﻿// JavaScript Document



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;

}



function deleteCookie() {

	createCookie("id","",0);

	createCookie("date","",0);

	createCookie("title","",0);

	createCookie("ctitle","",0);

	createCookie("cnum","",0);

  document.getElementById("history-table").style.display="none";

}





function showHistory() {

	if(readCookie("id")){

		var id=readCookie("id").split(",");

		var date=readCookie("date").split(",");

		var title=readCookie("title").split(",");

		var ctitle=readCookie("ctitle").split(",");

		var cnum=readCookie("cnum").split(",");

		

		document.write("<table id=\"history-table\">");

		for (i=0;i<id.length;i++) {

			i%2==0 ? document.write("<tr class=\"even\">") : document.write("<tr>");



			document.write("<th><a href=\""+id[i]+"/"+id[i]+".html?chapterID="+cnum[i]+"\"><img src=\""+id[i]+"/img/history_tn"+cnum[i]+".jpg\" alt=\""+decodeURI(title[i])+" "+decodeURI(ctitle[i])+"\" width=\"60\" height=\"45\" /></a></th>");

			document.write("<td>");

			document.write("<div class=\"date\">"+date[i]+"</div>");

			document.write("<div class=\"description\"><a href=\""+id[i]+"/"+id[i]+".html?chapterID="+cnum[i]+"\">"+decodeURI(title[i])+"<br />"+decodeURI(ctitle[i])+"</a></div>");

			document.write("</td>");

			document.write("</tr>");

		}

		document.write("</table>");

	}else{

		document.write("<p>視聴した講演の記録がありません<br />（クッキーが保存される設定でない場合、記録されません）</p>");

	}

}


