﻿﻿// JavaScript Document

var access = GetCookie("ACCESS");
var date   = GetCookie("DATE");

if(access == ""){access = 0;}

var ndate = new Date();
var year  = ndate.getYear();
var month = ndate.getMonth() + 1;
var day   = ndate.getDate();
var hour  = ndate.getHours();
var min   = ndate.getMinutes();
var sec   = ndate.getSeconds();
if(year < 1900){year += 1900;}
if(month < 10){month = "0" + month;}
if(day < 10){day = "0" + day;}
if(hour < 10){hour = "0" + hour;}
if(min < 10){min = "0" + min;}
if(sec < 10){sec = "0" + sec;}

SetCookie("ACCESS", ++access);
SetCookie("DATE", year + "/" + month + "/" + day + " " + hour + ":" + min + ":" + sec);


if(access == 1){
	var fdate = new Date();
	var fyear  = fdate.getYear();
	var fmonth = fdate.getMonth() + 1;
	var fday   = fdate.getDate();
	fdate.setDate(fday-1);
	var fday   = fdate.getDate();
	var fhour  = fdate.getHours();
	fdate.setHours(fhour-2);
	var fhour  = fdate.getHours();
	var fmin   = fdate.getMinutes();
	var fsec   = fdate.getSeconds();
	if(fyear < 1900){fyear += 1900;}
	if(fmonth < 10){fmonth = "0" + fmonth;}
	if(fday < 10){fday = "0" + fday;}
	if(fhour < 10){fhour = "0" + fhour;}
	var firsttime = fyear + "年" + fmonth + "月" + fday + "日 " + fhour + "時";
	document.write(firsttime , '現在、募集枠は18名');
}else if(access == 2){
	var secondtime = year + "年" + month + "月" + day + "日 " + hour + "時";
	document.write(secondtime , '現在、募集枠は16名');
}else if(access == 3){
	var thirdtime = year + "年" + month + "月" + day + "日 " + hour + "時";
	document.write(thirdtime , '現在、募集枠は11名');
}else if(access == 4){
	var fourthtime = year + "年" + month + "月" + day + "日 " + hour + "時";
	document.write(fourthtime , '現在、募集枠は9名');
}else{
	var losstime = year + "年" + month + "月" + day + "日 " + hour + "時";
	document.write(losstime , '現在、募集枠は3名');
}


function GetCookie(key){
	var tmp = document.cookie + ";";
	var index1 = tmp.indexOf(key, 0);
	if(index1 != -1){
		tmp = tmp.substring(index1,tmp.length);
		var index2 = tmp.indexOf("=",0) + 1;
		var index3 = tmp.indexOf(";",index2);
		return(unescape(tmp.substring(index2,index3)));
	}
	return("");
}

function SetCookie(key, val){
	document.cookie = key + "=" + escape(val) + ";expires=Fri, 31-Dec-2030 23:59:59;";
}
