// COOKIE取得(とほほのCookieより)
function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len) {
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);
		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) {
			return (unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
		}
		xx1 = xx2 + 1;
	}
	return("");
}

// COOKIE設定(とほほのCookieより)
function setCookie(key, val, tmp) {
	tmp = key + "=" + escape(val) + "; ";
	tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
	document.cookie = tmp;
}

// COOKIE削除(とほほのCookieより)
function clearCookie(key) {
	document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}


function VanaDecodeDate( vanatime ){

	this.year	= Math.floor(vanatime/60/60/24/360);
	this.days	= Math.floor(vanatime/60/60/24)-886*360;
	this.month	= Math.floor(vanatime/60/60/24/30) % 12+1;
	this.day	= Math.floor(vanatime/60/60/24) % 30+1;
	this.hour	= Math.floor(vanatime/60/60) % 24;
	this.minute	= Math.floor(vanatime/60) % 60;
}

function VanaNow(){
	dd = new Date();

	var ret = Math.floor( (dd.getTime() - Date.UTC( 2001, 11, 31, 15, 0, 0 ) )/1000 );
	ret = ret*25 + 886*360*24*60*60;

	return (ret);
}

function VanaGetDayOfWeek( vanadatetime ){

	return ( Math.floor( vanadatetime/60/60/24 ) % 8 );
}

function VanaGetSeconds( vanadatetime ){

	return Math.floor( vanadatetime/25 );
}

function Sec2String( sec ){
	var s;
	var i;

	s = "";

	i = Math.floor(sec/3600);
	if ( i<10 ) s = s + "0";
	s = s + i + ":";

	i = Math.floor(sec/60) % 60;
	if ( i<10 ) s = s + "0";
	s = s + i + ":";

	i = sec % 60;
	if ( i<10 ) s = s + "0";
	s = s + i;

	return (s);
}

var TimeTbl = new Array(3);
TimeTbl[0] = new Array ( 3, 1, 2 );
TimeTbl[1] = new Array ( 0, 2, 3 );
TimeTbl[2] = new Array ( 1, 3, 0 );

var Days = new Array("火","土","水","風","氷","雷","光","闇");

function ShowTime(){
	var dtime = VanaNow();
	var dt = new VanaDecodeDate(dtime);
	var s;
	var cells = new Array(3);

	for ( var i=0; i<3; i++ ) cells[i] = new Array(4);

	s = dt.year + "/" + dt.month + "/" + dt.day + "(" + Days[VanaGetDayOfWeek(dtime)] + ") ";
	if ( dt.hour<10 ) s = s + "0";
	s = s + dt.hour + ":";
	if ( dt.minute<10 ) s = s + "0";
	s = s + dt.minute;
	document.form.vanatime.value = s;

	var step = dt.day % 3;
	var dt2 = Math.floor( dtime/60/60/24 + 1 )*60*60*24 - dtime;
	var dt3 = Math.floor( dtime/60/60/24 + 2 )*60*60*24 - dtime;
	var sec2 = VanaGetSeconds(dt2);
	var sec3 = VanaGetSeconds(dt3);
	var time2 = Sec2String(sec2);
	var time3 = Sec2String(sec3);

	for ( var i=0; i<3; i++ ){
		cells[i][TimeTbl[i][step]] = "受付中";
		cells[i][TimeTbl[i][(step+1) % 3]] = time2;
		cells[i][TimeTbl[i][(step+2) % 3]] = time3;
	}
	document.form.snd_bas.value = cells[0][1];
	document.form.snd_win.value = cells[0][2];
	document.form.snd_jue.value = cells[0][3];

	document.form.bas_snd.value = cells[1][0];
	document.form.bas_win.value = cells[1][2];
	document.form.bas_jue.value = cells[1][3];

	document.form.win_snd.value = cells[2][0];
	document.form.win_bas.value = cells[2][1];
	document.form.win_jue.value = cells[2][3];

	switch (step){
		case 0:
			document.form.kzm_nrg.value = time2;
			document.form.kzm_n_a.value = "受付中";
		break;
		case 1:
			document.form.kzm_nrg.value = "受付中";
			document.form.kzm_n_a.value = time2;
		break;
		case 2:
			document.form.kzm_nrg.value = time3;
			document.form.kzm_n_a.value = "受付中";
		break;
	}
	window.setTimeout("ShowTime()", 1000);
}

//	クッキーからターゲットの表示/非表示を設定
function setup0( target ){

	if ( getCookie( target )!=0 ){
		document.getElementById(target).style.display = 'block';
	} else {
		document.getElementById(target).style.display = 'none';
	}
}

function Setup(){
	setup0("sand");
	setup0("bas");
	setup0("win");
	setup0("kzm");
	ShowTime();
}


function Toggle(tgt){
	if(document.getElementById(tgt).style.display == 'none'){
		document.getElementById(tgt).style.display = 'block';
		setCookie(tgt, 1);
	} else {
		document.getElementById(tgt).style.display = 'none';
		setCookie(tgt, 0);
	}
}



document.writeln('<style TYPE="text/css">');
document.writeln('<!--');
document.writeln('INPUT.readonly { border-width:0px; background-color: transparent; text-align:center; font-family: "HG創英角ﾎﾟｯﾌﾟ体"; font-size:11px; color:#ffffff; }');
document.writeln('TABLE.chococlock { empty-cells: show; table-layout: fixed; background-color:#322f26 }');
document.writeln('TABLE.chococlockTop { empty-cells: show; table-layout: fixed; background-color:transparent }');
document.writeln('div.chococlockTopDiv{ width:160px; height:32px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://suihac.tea-nifty.com/images/clock_top.png); }');
document.writeln('div.chococlockTopDiv img{ display:none; }');
document.writeln('div.chococlockTopDiv>img{ display:block; }');
document.writeln('-->');
document.writeln('</style>');
document.writeln('<form name="form">');
document.writeln('<table class="chococlockTop" width=160 height=32 cellspacing=0 cellpadding=0>');
document.writeln('<!-- ---------------- タイトル部 --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td><div class="chococlockTopDiv"><img src="http://suihac.tea-nifty.com/images/clock_top.png" width=160 height=32 onLoad="Setup();"></div></td>');
document.writeln('	</tr>');
document.writeln('</table>');
document.writeln('<table class="chococlock" width=160 cellspacing=0 cellpadding=0>');
document.writeln('<!-- ---------------- 上部枠 --------------- -->');
document.writeln('	<tr height=12>');
document.writeln('		<td width= 12><img src="http://suihac.tea-nifty.com/images/clock_lt.jpg" width=12 height=12></td>');
document.writeln('		<td width=136><img src="http://suihac.tea-nifty.com/images/clock_t.jpg" width=136 height=12></td>');
document.writeln('		<td width= 12><img src="http://suihac.tea-nifty.com/images/clock_rt.jpg" width=12 height=12></td>');
document.writeln('	</tr>');
document.writeln('<!-- ---------------- 日付表示部 --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td rowspan=10 background="http://suihac.tea-nifty.com/images/clock_l.jpg"></td>');
document.writeln('		<td><input class="readonly" type="text" name="vanatime" size=20></td>');
document.writeln('		<td rowspan=10 background="http://suihac.tea-nifty.com/images/clock_r.jpg"></td>');
document.writeln('	</tr>');
document.writeln('	<!-- ---------------- ライン --------------- -->');
document.writeln('	<tr height=4>');
document.writeln('		<td width=136 background="http://suihac.tea-nifty.com/images/clock_line.jpg"></td>');
document.writeln('	</tr>');
document.writeln('<!-- ---------------- SandOria --------------- -->');
document.writeln('	<!-- ---------------- 名前表示部 --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<table class="chococlock" width=136 cellspacing=0>');
document.writeln('			<tr>');

document.write('				<td><a href="#" onclick="Toggle(');
document.write("'sand'");
document.writeln(');return false;"><img src="http://suihac.tea-nifty.com/images/clock_sand_l.jpg" border=0><a></td>');

document.writeln('			</tr>');
document.writeln('			</table>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('	<!-- ---------------- トグルブロック --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<div id="sand">');
document.writeln('				<table class="chococlock" width=136 cellspacing=0>');
document.writeln('					<tr>');
document.writeln('						<td width=12></td>');
document.writeln('						<td width=56><img src="http://suihac.tea-nifty.com/images/clock_bas_s.jpg" width=56 height=12></td>');
document.writeln('						<td width=68><input class="readonly" type="text" name="snd_bas" size=8></td>');
document.writeln('					</tr>');
document.writeln('					<tr>');
document.writeln('						<td></td>');
document.writeln('						<td><img src="http://suihac.tea-nifty.com/images/clock_win_s.jpg" width=56 height=12></td>');
document.writeln('						<td><input class="readonly" type="text" name="snd_win" size=8></td>');
document.writeln('					</tr>');
document.writeln('					<tr>');
document.writeln('						<td></td>');
document.writeln('						<td><img src="http://suihac.tea-nifty.com/images/clock_jeu_s.jpg" width=56 height=12></td>');
document.writeln('						<td><input class="readonly" type="text" name="snd_jue" size=8></td>');
document.writeln('					</tr>');
document.writeln('				</table>');
document.writeln('			</div>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('');
document.writeln('<!-- ---------------- Bastok --------------- -->');
document.writeln('	<!-- ---------------- 名前表示部 --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<table class="chococlock" width=136 cellspacing=0>');
document.writeln('			<tr>');

document.write('				<td><a href="#" onclick="Toggle(');
document.write("'bas'");
document.writeln(');return false;"><img src="http://suihac.tea-nifty.com/images/clock_bas_l.jpg" border=0><a></td>');

document.writeln('			</tr>');
document.writeln('			</table>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('	<!-- ---------------- トグルブロック --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<div id="bas">');
document.writeln('				<table class="chococlock" width=136 cellspacing=0>');
document.writeln('					<tr>');
document.writeln('						<td width=12></td>');
document.writeln('						<td width=56><img src="http://suihac.tea-nifty.com/images/clock_sand_s.jpg" width=56 height=12></td>');
document.writeln('						<td width=68><input class="readonly" type="text" name="bas_snd" size=8></td>');
document.writeln('					</tr>');
document.writeln('					<tr>');
document.writeln('						<td></td>');
document.writeln('						<td><img src="http://suihac.tea-nifty.com/images/clock_win_s.jpg" width=56 height=12></td>');
document.writeln('						<td><input class="readonly" type="text" name="bas_win" size=8></td>');
document.writeln('					</tr>');
document.writeln('					<tr>');
document.writeln('						<td></td>');
document.writeln('						<td><img src="http://suihac.tea-nifty.com/images/clock_jeu_s.jpg" width=56 height=12></td>');
document.writeln('						<td><input class="readonly" type="text" name="bas_jue" size=8></td>');
document.writeln('					</tr>');
document.writeln('				</table>');
document.writeln('			</div>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('');
document.writeln('<!-- ---------------- Windurst --------------- -->');
document.writeln('	<!-- ---------------- 名前表示部 --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<table class="chococlock" width=136 cellspacing=0>');
document.writeln('			<tr>');

document.write('				<td><a href="#" onclick="Toggle(');
document.write("'win'");
document.writeln(');return false;"><img src="http://suihac.tea-nifty.com/images/clock_win_l.jpg" border=0><a></td>');

document.writeln('			</tr>');
document.writeln('			</table>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('	<!-- ---------------- トグルブロック --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<div id="win">');
document.writeln('				<table class="chococlock" width=136 cellspacing=0>');
document.writeln('					<tr>');
document.writeln('						<td width=12></td>');
document.writeln('						<td width=56><img src="http://suihac.tea-nifty.com/images/clock_sand_s.jpg" width=56 height=12></td>');
document.writeln('						<td width=68><input class="readonly" type="text" name="win_snd" size=8></td>');
document.writeln('					</tr>');
document.writeln('					<tr>');
document.writeln('						<td></td>');
document.writeln('						<td><img src="http://suihac.tea-nifty.com/images/clock_bas_s.jpg" width=56 height=12></td>');
document.writeln('						<td><input class="readonly" type="text" name="win_bas" size=8></td>');
document.writeln('					</tr>');
document.writeln('					<tr>');
document.writeln('						<td></td>');
document.writeln('						<td><img src="http://suihac.tea-nifty.com/images/clock_jeu_s.jpg" width=56 height=12></td>');
document.writeln('						<td><input class="readonly" type="text" name="win_jue" size=8></td>');
document.writeln('					</tr>');
document.writeln('				</table>');
document.writeln('			</div>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('');
document.writeln('<!-- ---------------- Kazham --------------- -->');
document.writeln('	<!-- ---------------- 名前表示部 --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<table class="chococlock" width=136 cellspacing=0>');
document.writeln('			<tr>');

document.writeln('				<td><a href="#" onclick="Toggle(');
document.writeln("'kzm'");
document.writeln(');return false;"><img src="http://suihac.tea-nifty.com/images/clock_kzm_l.jpg" border=0><a></td>');

document.writeln('			</tr>');
document.writeln('			</table>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('	<!-- ---------------- トグルブロック --------------- -->');
document.writeln('	<tr>');
document.writeln('		<td>');
document.writeln('			<div id="kzm">');
document.writeln('				<table class="chococlock" width=136 cellspacing=0>');
document.writeln('					<tr>');
document.writeln('						<td width=12></td>');
document.writeln('						<td width=56><img src="http://suihac.tea-nifty.com/images/clock_nrg_s.jpg" width=56 height=12></td>');
document.writeln('						<td width=68><input class="readonly" type="text" name="kzm_nrg" size=8></td>');
document.writeln('					</tr>');
document.writeln('					<tr>');
document.writeln('						<td></td>');
document.writeln('						<td><img src="http://suihac.tea-nifty.com/images/clock_n_a_s.jpg" width=56 height=12></td>');
document.writeln('						<td><input class="readonly" type="text" name="kzm_n_a" size=8></td>');
document.writeln('					</tr>');
document.writeln('				</table>');
document.writeln('			</div>');
document.writeln('		</td>');
document.writeln('	</tr>');
document.writeln('');
document.writeln('<!-- ---------------- 下部枠 --------------- -->');
document.writeln('	<tr height=12>');
document.writeln('		<td><img src="http://suihac.tea-nifty.com/images/clock_lb.jpg" width=12 height=12></td>');
document.writeln('		<td><img src="http://suihac.tea-nifty.com/images/clock_b.jpg" width=136 height=12></td>');
document.writeln('		<td><img src="http://suihac.tea-nifty.com/images/clock_rb.jpg" width=12 height=12></td>');
document.writeln('	</tr>');
document.writeln('</table>');
document.writeln('</form>');
document.writeln('<div align=right style="font-size:8pt"><a href="http://suihac.tea-nifty.com/blog/2007/05/chococlock_3cd4.html" target="_blank">ChocoClock</a> by 酔伯</div>');
