/* 
 文字サイズ・背景色変更スクリプト StyleChange.js


/* ----------------- 変数宣言 -------------------*/
var FontSize;
var BGColor;
var Unit;
var Obj;
Units = new Array('%','px','pt','em');

/* ----------------- 初期設定 -------------------*/
/* IDの指定 */
//文字サイズを変更したい要素のID
Obj = 'container';
footer = 'footermenu';

/* サイズの単位（0 = %、1 = px、2 = pt, 3= em） */
Unit = 0;

/* Cookieの有効期限（日数） */
ExpireDays = 30;


/* -------------------- 実　行 ---------------------*/
ReadCookie();
CheckButton();

/* -------------------- 関　数 ---------------------*/
/* ラジオボタン書き出し */
function CheckButton() {
	SelectS = "";
	SelectM = "";
	SelectL = "";
	SelectW = "";
	SelectB = "";

	switch (FontSize) {
		case "90":
			SelectS = "checked";
			break;
		case "115":
			SelectL = "checked";
			break;
		default:
			SelectM = "checked";
			break;
	}

	switch (BGColor) {
		case "#000000":
			SelectB = "checked";
			break;
		default:
			SelectW = "checked";
			break;
	}

	document.write ('<form method="get" id="Style" name="Style">');
	document.write ('<input type="radio" name="fontsize" value="90"' + SelectS + '>小');
	document.write ('<input type="radio" name="fontsize" value="100"' + SelectM + '>中');
	document.write ('<input type="radio" name="fontsize" value="115"' + SelectL + '>大　　');
	document.write ('<input type="radio" name="bgcolor" value="#FFFFFF"' + SelectW + '>標準');
	document.write ('<input type="radio" name="bgcolor" value="#000000"' + SelectB + '>黒　　');
	document.write ('<input type="button" id="set" value="設定" onClick="Set();">');
	document.write ('</form>');
}

function Set(){
	for(i=0; i<document.Style.fontsize.length; i++){
		if(document.Style.fontsize[i].checked){
			FontSize = document.Style.fontsize[i].value;
			break;
		}
	}
	for(i=0; i<document.Style.bgcolor.length; i++){
		if(document.Style.bgcolor[i].checked){
			BGColor = document.Style.bgcolor[i].value;
			break;
		}
	}

	Write(FontSize, BGColor);
}

/* Cookie呼出 */
function ReadCookie() {
	if (document.cookie) {
		Cookie = document.cookie;
		if (Cookie.match(/FontSize=([\d.]*)/)) {
			FontSize = RegExp.$1;
		}
		i = j = 0;
		tmp1 = " " + document.cookie + ";";
		while (i < tmp1.length) {
			j = tmp1.indexOf(";", i);
			tmp2 = tmp1.substring(i + 1, j);
			k = tmp2.indexOf("=");
			if (tmp2.substring(0, k) == "BGColor") {
				BGColor = unescape(tmp2.substring(k + 1, j - i - 1));
			}
			i = j + 1;
		}
	}
}

/* スタイル変更 */
function SetStyle() {
	if (FontSize != null) {
		document.getElementById(Obj).style.fontSize = FontSize + Units[Unit];
	}

	//背景色を黒に指定した場合
	if (BGColor != null) {
		if(BGColor=="#000000"){

			//背景色は黒
			document.getElementById(Obj).style.backgroundColor = BGColor;

			//文字色は白
			document.getElementById(Obj).style.color = "#FFFFFF";

			//フッターの文字色は黒
			document.getElementById(footer).style.color = BGColor;

			//ジャンル、コンテンツのタイトル名は黒
			var gcname = new Array('gtitle','ctitle');

			for(var k=0; k<gcname.length; k++){
				if(document.getElementById(gcname[k])){
					document.getElementById(gcname[k]).style.color = BGColor;
				}
			}

			/*infoタイトルの文字色変更(関連情報等)*/
			var title = document.all.tags("div");
			for( var i=0; i<title.length; i++){
				if(title[i].className=="infotitle"){
					title[i].style.color = "#FFFFFF";
				}
			/*基本テンプレートタイプのブロックタイトルの文字色変更*/
				if(title[i].className=="blocktitle"){
					title[i].style.color = BGColor;
				}
			}

			/*自由入力は背景色が白、文字色が黒*/
			if(document.getElementById("ctext")){
				if(document.getElementById("ctext").innerHTML.indexOf("mso-width-source") != -1){
					document.getElementById("ctext").style.backgroundColor = "#FFFFFF";
					document.getElementById("ctext").style.color = "#000000";
				}
			}

			//リンクの文字色変更（変更したい文字は、class名をlinkcolorにする）
			for(var i=0; i<document.links.length; i++) {
				if(document.links[i].className == "linkcolor"){
					document.links[i].style.color="#000000";
				}else{
					document.links[i].style.color="#FFFFFF";
				}
			}

			//各タイトルの色を変更
			var titlename = new Array('phototitle','outlinetitle','populationtitle',
																'nicetitle','posttitle','foreigntitle',
																'mobiletitle','businesstitle','parenttitle',
																'infotitle');

			for(var j=0; j<titlename.length; j++){
				if(document.getElementById(titlename[j])){
					document.getElementById(titlename[j]).style.color = "#FFFFFF";
				}
			}

		}
	}
}

/* Cookie書込 */
function Write(Size,Color) {
	// 日付の計算
	var toDay = new Date;
	var xDay = new Date;
	parseInt(ExpireDays);
	xDay.setDate(toDay.getDate()+ExpireDays);
	ExpireText = xDay.toGMTString();
	// 書込
	document.cookie = "FontSize = " + Size + ";";
	document.cookie = "BGColor =" + Color + ";";
	document.cookie = "expires =" + ExpireText + ";";
	// 再読込
	location.reload();
}

