// スタイル変更

var sSheet;
sS=document.styleSheets;
expiresDay=90; // cookie有効期限
Gecko=navigator.product=="Gecko";
newGecko=GeckoCheck();

function GeckoCheck(){ // Geckoのバージョンをチェックする関数
	if(!Gecko)
		return;
	ua=navigator.userAgent;
	st=ua.indexOf("rv:");
	if(st==-1)
		return;
	else
		ver=ua.substring(st+3,st+6);
	if(ver>1.0)
		return true; // 1.1以上はtrue
}
function setCookie(name,data,expDay){ // cookie書き込み関数
	dd=new Date();
	dd.setTime(dd.getTime()+1000*60*60*24*expDay);
	dd=dd.toGMTString();
	document.cookie=name+"="+data+";expires="+dd;
}
function getCookie(name){ // cookie読み出し関数
	cookieData=document.cookie+";";
	serch=cookieData.indexOf(name);
	if(serch!=-1){
		start=cookieData.indexOf("=",serch)+1;
		end=cookieData.indexOf(";",start);
		data=cookieData.substring(start,end);
		return data;
	}
	return "";
}
function writeSelecter(){ // スタイルセレクター書き出し
	if(sS){
		if(document.all)
			obj=document.all("chgStyle");
		else
			obj=document.getElementById("chgStyle");
		Select="<div><a href=\"styleChg.htm\">スタイル変更<\/a>：<select onchange=\"changStyle(this)\">"
		for(i=0;i<sS.length;i++){
			Select+="<option";
			if(i==sSheet)
				Select+=" selected";
			Select+=">";
			if(sS[i].title=="")
				Select+="なし";
			else
				Select+=sS[i].title;
			Select+="<\/option>";
		}
		Select+="<\/select><\/div>";
		obj.innerHTML=Select;
	}
}
function changStyle(obj){ // スタイル変更
	sSheet=obj.selectedIndex;
	setCSS(sSheet);
	if(!newGecko)
			// Geckoのバージョン1.0以前はリロードするとうまくいく
		location.reload();
}
function setCSS(Style){ // スタイル設定
	for(i=0;i<sS.length-1;i++){
		if(i==Style)
			sS[i].disabled=false;
		else
			sS[i].disabled=true;
	}
}
function recordCSS(){ // スタイルをcookieに保存
	for(i=0;i<sS.length;i++){
		if(!sS[i].disabled){
			sSheet=i;
			break;
		}
	}
	setCookie("sSheet",sSheet,expiresDay);
}
function loadCSS(){ // 初期スタイルを決定
	sSheet=getCookie("sSheet");
	if(sSheet==""){
		if(document.getElementById)
			sSheet=0;
		else
			sSheet=1;
	}
	setCSS(sSheet);
}

///////////////////////////////

// メニュー説明表示

var obj_mesboad, obj_mes;
minHeight=100;
MaxWidth=570;
marginLR=210;
marginB=10;
upY=20;
function objMes(){ // 説明表示オブジェクト
	obj_mes=document.getElementById("mes");
}
function getWinHeight(){ // ウィンドウの縦幅
	if(document.all)
		wh=document.body.clientHeight;
	else
		wh=window.innerHeight-18; // N6はスクロールバーを含む
	return wh;
}
function getClientY(e){ // ウィンドウ上のマウス位置Y
	if(document.all)
		cy=event.clientY;
	else{
		sy=getScrollY();
		cy=getPageY(e)-sy;
	}
	return cy;
}
function getWinWidth(){ // ウィンドウの横幅
	if(document.all)
		ww=document.body.clientWidth;
	else
		ww=window.innerWidth-20; // N6はスクロールバーを含む
	return ww;
}
function getScrollY(){ // スクロール位置Y
	if(document.all)
		sy=document.body.scrollTop;
	else
		sy=window.scrollY;
	return sy;
}
function getPageY(e){ // ページ上のマウス位置Y
	if(document.all){
		sy=getScrollY();
		py=getClientY(e)+sy;
	}
	else
		py=e.pageY;
	return py;
}
function getWidth(){ // 説明表示枠の横幅
	w=getWinWidth()-marginLR;
	if(w>MaxWidth)
		w=MaxWidth;
	return w;
}
function showMes(e,id){ // 説明表示
	if(obj_mes){
		Y=getPo(e);
		W=getWidth();
		Mes=document.getElementById(id).firstChild.nodeValue;
		obj_mesboad.style.top=Y+"px";
		obj_mesboad.style.width=W+"px";
		obj_mes.innerHTML=Mes;
		obj_mesboad.style.display="block";
	}
}
function hideMes(){ // 説明非表示
	if(obj_mes){
		obj_mesboad.style.display="none";
		obj_mes.innerHTML="";
	}
}
function getPo(e){ // 表示位置Y
	WH=getWinHeight();
	CY=getClientY(e)-upY;
	PY=getPageY(e)-upY-marginB;
	bottomY=CY+minHeight;
	if(bottomY>WH)
		PY=PY-(bottomY-WH);
	return PY;
}

function writeMesBoad(){ // メッセージ表示枠
	ID=new Array("lt","mt","rt","lm","mes","rm","lb","mb","rb");
	sel=0;
	table="";
	table="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	for(i=0;i<3;i++){
		table+="<tr>";
		for(j=0;j<3;j++){
			table+="<td id=\""+ID[sel]+"\">";
			if(ID[sel]!="mes")
				table+="&nbsp;";
			table+="<\/td>";
			sel++;
		}
		table+="<\/tr>";
	}
	table+="<\/table>";
	obj_mesboad=document.getElementById("mesboad");
	obj_mesboad.innerHTML=table;
}

function setMesBoad(){ // メニュー説明表示の初期設定
	if(document.getElementById){
		writeMesBoad();
		objMes();
	}
}

///////////////////////////////

function Load(){ // ページ読みこみ時の初期設定
	if(Gecko) // Geckoはページ読み込み後にスタイル変更
		loadCSS();
	writeSelecter();
	setMesBoad();
}

///////////////////////////////

// 関数実行部分
if(sS){
	if(!Gecko) // Gecko以外はページ読み込み前にスタイル変更
		loadCSS();
	window.onload=Load;
	window.onunload=recordCSS;
}

// メニューでCSSを変更した場合もスタイル保存可能（Gecko）
