// 現在の文字の大きさ global変数
currentFontSize = getFontSize();

// 文字変更用のHTML作成
function fontSizeHtml(){
	if(document.getElementById){
		var rooturl  = document.getElementById("linkHomePage").href;
		var html  = '<p id="fontsize"><img src="'+rooturl+'/img/fontsize/fontsize.gif" width="64" height="18" alt="文字サイズ" />';

			html += '<a href="#" onClick="changeFontSize(90);return false;"><img src="'+rooturl+'/img/fontsize/smaller.gif" width="40" height="18" alt="小さく" /></a>';
		    html += '<a href="#" onClick="changeFontSize(0);return false;"><img src="'+rooturl+'/img/fontsize/reset.gif" width="40" height="18" alt="標準" /></a>';
		    html += '<a href="#" onClick="changeFontSize(111.11111);return false;"><img src="'+rooturl+'/img/fontsize/larger.gif" width="40" height="18" alt="大きく" /></a>';
		    html += '</p>';
		//document.getElementById(elmID).innerHTML = html;
		document.write(html);
	}
	setFontSize();
}

// 現在の文字サイズ
function getFontSize(){
	if(!document.getElementById){
		return 100;
	}
	var cookieFontSize = getCookie("fontSize");
	if (cookieFontSize) {
		//クッキーがあれば現在の値をクッキーの値に設定
		cookieFontSize = Number(cookieFontSize);
	}else{
		//クッキーが無ければ現在の値を初期状態の値に設定
		cookieFontSize = 100;
	}
	return (cookieFontSize);
}

// bodyのstyle.fontSizeを書き換える
function setFontSize(){
	if(document.getElementById){
		document.body.style.fontSize = currentFontSize + "%";
		/*
		var frameElm = document.getElementById("iframe01");
		if(frameElm){//フレームがあればそれにも対応する
			if (document.all){//IE
				frameElm.contentWindow.document.body.style.fontSize = currentFontSize + "%";
			}else{//MZ
				frameElm.contentDocument.body.style.fontSize = currentFontSize + "%";
			}
		}
		*/
	}
}

//フォントサイズ変更（%）
//changeFontSize(125);現在より25%up
//changeFontSize(0); デフォルトに戻す
function changeFontSize(val){
	if(!document.getElementById){
		return null;
	}
	if(val > 0){
		var newFontSize = Number( currentFontSize * val / 100 );
		setCookie( "fontSize" , newFontSize ,"/",30 );//クッキー書き込み
	// 元に戻す：操作後の値を初期値にする、クッキー削除
	}else{
			var newFontSize = 100;
		setCookie( "fontSize" , 100 ,"/",30 );//クッキー書き込み
		//deleteCookie( "fontSize" ,"/");
	}
	currentFontSize = newFontSize;
	setFontSize();
}

//クッキー関連ここから
// setCookie(key,val,path,days)
// 基本的に path は "/" でOK
// days は、31[日]とか
function setCookie(key,val,path,days){
	var newDate = new Date();
	newDate.setTime(newDate.getTime() + days * 24 * 60 * 60* 1000);
	var expiresDate = newDate.toGMTString();
	document.cookie = key + '=' + escape(val)+ ';expires=' + expiresDate + ';path=' + path;
}

//クッキー：keyから値を取り出す
function getCookie(key){
	var cookieStr = document.cookie+";";
	var strMatch = cookieStr.indexOf(key,0);
	if(strMatch == -1){
		return null;
	}
	var str = cookieStr.substring(strMatch,cookieStr.length);
	var fromStrlength = str.indexOf("=",0);
	var toStrlength   = str.indexOf(";",fromStrlength);
	var retStr = str.substring(fromStrlength + 1,toStrlength);
	return(unescape(retStr));
}

//クッキーを削除する
function deleteCookie(key,path){
	if (getCookie(key)) {
		document.cookie = key + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT;path='+path;
	}
}
