//ロールオーバースクリプト------------------

function cngimg(n){
	var imgsrc = document.images[n].src;
	if(imgsrc.indexOf("-on") < 0){
		document.images[n].src=imgsrc.substring(0,imgsrc.length-4) +"-on.jpg";
	}
	else{
		document.images[n].src=imgsrc.substring(0,imgsrc.length-7) +".jpg";
	}
}


//文字サイズ変更追加スクリプト
//クッキー発行------------------

function setCookie(name, value, domain, path, expires, secure) {

	var str = name + "=" + escape(value);
	domain = document.domain.replace(/^[^\.]*/, "");
	str += "; domain=" + domain;

	path = "/";
	str += "; path=" + path;

	expires = new Date();
	expires.setTime(expires.getTime() + (30 * 1000 * 60 * 60 * 24));
	expires2 = expires.toGMTString();
	str += "; expires=" + expires2;

	if(secure && location.protocol == "https:") {
		str += "; secure";
	}

	str += ";";
	document.cookie = str;

}

//クッキー取得------------------
function getCookie(name) {

	var cookies = document.cookie.split(';');
	for (var i=0; i<cookies.length; i++) {
		var cookieList = cookies[i].split('=');
		var cookieName = cookieList[0];
		var cookieVal = cookieList[1];
		if (cookieName.indexOf(name,0)!=-1) {
			return unescape(cookieVal);
		}
	}
	return null;

}

function checkCookie() {

	if (window.navigator.cookieEnabled) {
		return true;
	}	else {
		return false;
	}

}


//切り替え------------------
function fontSizeSwitch(n) {

	document.getElementById('btn').innerHTML = "";

	if(n == "l") {
		applyCSS(document,"/common/css/font-l.css");
	} else if(n == "m") {
		applyCSS(document,"/common/css/font-m.css");
	} else if(n == "s"){
		applyCSS(document,"/common/css/font-s.css");
	}

	//ボタン生成
	if(document.getElementById('areaLeft')){
		btnCreate(n);
	}

	//クッキー発行
	setCookie('fontsize', n);

}


//ボタン生成------------------

function btnSet(n) {

	//linkエレメント生成
	var id = 'areaLeft';
	var target = document.getElementById(id);
	var container = document.createElement('div');
	container.setAttribute('id', 'btn');
	target.insertBefore(container, target.firstChild);
	var btn = document.getElementById('btn');

	var ua=navigator.userAgent;
	if(ua.indexOf("MSIE 6")>-1){
		document.getElementById("btn").style.height="28px";
	}else{
		document.getElementById("btn").style.minHeight="28px";
	}
}


function btnCreate(n) {

	var btn = document.getElementById('btn');
	var html = '';
	if(n == "l"){
		html += '<div style="margin-bottom:5px;">';
		html += '<div class="left" style="margin-left:3px;"><img src="/common/images/size-text.gif" width="85" height="22" alt="文字サイズの変更" /></div>';
		html += '<ul class="right" style="width:82px;">';
		html += '<li class="left" style="margin-right:8px;"><a href="javascript:fontSizeSwitch(\'l\');" title="大" tabindex="200">';
		html += '<img src="/common/images/l-in.gif" width="22" height="22" alt="大" id="size_l" /></a></li>';
		html += '<li class="left" style="margin-right:8px;"><a href="javascript:fontSizeSwitch(\'m\');" title="中" tabindex="200">';
		html += '<img src="/common/images/m.gif" width="22" height="22" alt="中" id="size_m" /></a></li>';
		html += '<li class="left"><a href="javascript:fontSizeSwitch(\'s\');" title="小" tabindex="200">';
		html += '<img src="/common/images/s.gif" width="22" height="22" alt="小" id="size_s" /></a></li>';
		html += '</ul>';
		html += '<div style="clear:left;"></div><div style="clear:both;"></div></div>';
	}
	if(n == "m"){
		html += '<div style="margin-bottom:5px;">';
		html += '<div class="left" style="margin-left:3px;"><img src="/common/images/size-text.gif" width="85" height="22" alt="文字サイズの変更" /></div>';
		html += '<ul class="right" style="width:82px;">';
		html += '<li class="left" style="margin-right:8px;"><a href="javascript:fontSizeSwitch(\'l\');" title="大" tabindex="200">';
		html += '<img src="/common/images/l.gif" width="22" height="22" alt="大" id="size_l" /></a></li>';
		html += '<li class="left" style="margin-right:8px;"><a href="javascript:fontSizeSwitch(\'m\');" title="中" tabindex="200">';
		html += '<img src="/common/images/m-in.gif" width="22" height="22" alt="中" id="size_m" /></a></li>';
		html += '<li class="left"><a href="javascript:fontSizeSwitch(\'s\');" title="小" tabindex="200">';
		html += '<img src="/common/images/s.gif" width="22" height="22" alt="小" id="size_s" /></a></li>';
		html += '</ul>';
		html += '<div style="clear:left;"></div><div style="clear:both;"></div></div>';
	}
	if(n == "s"){
		html += '<div style="margin-bottom:5px;">';
		html += '<div class="left" style="margin-left:3px;"><img src="/common/images/size-text.gif" width="85" height="22" alt="文字サイズの変更" /></div>';
		html += '<ul class="right" style="width:82px">';
		html += '<li class="left" style="margin-right:8px;"><a href="javascript:fontSizeSwitch(\'l\');" title="大" tabindex="200">';
		html += '<img src="/common/images/l.gif" width="22" height="22" alt="大" id="size_l" /></a></li>';
		html += '<li class="left" style="margin-right:8px;"><a href="javascript:fontSizeSwitch(\'m\');" title="中" tabindex="200">';
		html += '<img src="/common/images/m.gif" width="22" height="22" alt="中" id="size_m" /></a></li>';
		html += '<li class="left"><a href="javascript:fontSizeSwitch(\'s\');" title="小" tabindex="200">';
		html += '<img src="/common/images/s-in.gif" width="22" height="22" alt="小" id="size_s" /></a></li>';
		html += '</ul>';
		html += '<div style="clear:left;"></div><div style="clear:both;"></div></div>';
	}
	var bkdirect=location.pathname;
	if(bkdirect.indexOf("/direct/help",0) != -1){
		html += '<ul class="linkList txtAR"><li><a href="/size/index.html" onclick="window.open(this.href, \'\', \'\'); return false;" onkeypress="window.open(this.href, \'\', \'\'); return false;" title="文字サイズの変更方法" tabindex="200">変更方法</a></li></ul>';
	}else{
		html += '<ul class="linkList txtAR"><li><a href="/size/index.html" title="文字サイズの変更方法" tabindex="200">変更方法</a></li></ul>';
	}
	btn.innerHTML = html;
}


function fontSizeInit() {

	//クッキー取得
	var n = getCookie('fontsize');
	if (n === null) {
		//TBのみ「中」をデフォルト
		if (location.hostname == 'www.mizuho-tb.co.jp') {
			n = 'm';
		} else {
			n = 's';
		}
	}

	if(n == "l") {
		applyCSS(document,"/common/css/font-l.css");
	} else if(n == "m") {
		applyCSS(document,"/common/css/font-m.css");
	} else if(n == "s"){
		applyCSS(document,"/common/css/font-s.css");
	}

	if(document.getElementById('areaLeft')){
		//ボタン生成
		btnSet(n);
		btnCreate(n);
	}
}

function fontSizeInitBase() {

	//クッキー取得
	var n = getCookie('fontsize');
	if (n === null) {
		//TBのみ「中」をデフォルト
		if (location.hostname == 'www.mizuho-tb.co.jp') {
			n = 'm';
		} else {
			n = 's';
		}
	}

	if(n == "l") {
		applyCSS(document,"/common/css/font-l.css");
	} else if(n == "m") {
		applyCSS(document,"/common/css/font-m.css");
	} else if(n == "s"){
		applyCSS(document,"/common/css/font-s.css");
	}
}

function applyCSS(doc, cssfile, overwrite){

	if (typeof overwrite == "undefined") overwrite = 0;      // デフォルト:CSSの切替え

	// 既存のCSSを削除
	if (overwrite && doc.styleSheets.length >= 1) {
		var links = doc.getElementsByTagName("link");
		for (var i = 0 ; i < links.length ; i++) {
			if (links[i].rel == "stylesheet") links[i].parentNode.removeChild(links[i]);
		}
	}

	// CSS追加
	if (document.all) {
		doc.createStyleSheet(cssfile);
	} else {
		var link = doc.createElement("link");
		link.setAttribute("rel", "stylesheet");
		link.setAttribute("href", cssfile);
		link.setAttribute("type", "text/css");
		doc.getElementsByTagName('head')[0].appendChild(link);
	}
}

if (navigator.userAgent.indexOf('Firefox') >= 0) {
	document.addEventListener("DOMContentLoaded", fontSizeInitBase, false);
} else {
	window.onload = fontSizeInitBase;
}
