/**
 * フォントサイズ調整
 */
var fntSize = 1;
var fntSizeCookieKey = "site_font";

function fntSizeChg(a){
	fntSize = a;
	setCookie(fntSizeCookieKey, a);
	location.reload()
}

function FSChanger(){
	var size = getCookie(fntSizeCookieKey);
	if (!size) {
		fntSize = 1;
	} else {
		fntSize = size;
	}
	document.write('<div id="f-size" class="clearfix"><dl>');
	document.write('<dt>文字の大きさ</dt>');
	document.write('<dd id="sz-bttn-1" class="bttn_off"><a href="#.html" onClick="fntSizeChg(1);return false">小</a></dd>');
	document.write('<dd id="sz-bttn-2" class="bttn_off"><a href="#.html" onClick="fntSizeChg(2);return false">中</a></dd>');
	document.write('<dd id="sz-bttn-3" class="bttn_off"><a href="#.html" onClick="fntSizeChg(3);return false">大</a></dd>');
	document.write('</dl></div>');
	document.getElementById('sz-bttn-'+fntSize).className = "bttn_on";
	document.getElementById('container').className = "fsize-"+fntSize;
}

/**
 * ブラウザ画面領域の幅を取得
 */
function getWidth(win)
{
	var tmp_width;
    
	if (win.document.documentElement) { 
		tmp_width = win.document.documentElement.clientWidth;
		if (tmp_width > 0) {
			return(tmp_width);
		}
	}
    if (win.document.all) {
		return(win.document.body.clientWidth);
	}
	return(win.innerWidth);
}
       
/**
 * ブラウザ画面領域の高さを取得
 */
function getHeight(win)
{
	var tmp_height;
    
	if (win.document.documentElement) {
		tmp_height = win.document.documentElement.clientHeight;
		if (tmp_height > 0) {
			return(tmp_height);
		}
	}
    if (win.document.all) {
		return(win.document.body.clientHeight);
	}
	return(win.innerHeight);
}

/**
 * Windowを中心に移動
 */
function moveWindowToCenter(win) {
	x = (screen.width  - getWidth(win)) / 2;
	y = (screen.height - getHeight(win)) / 2 - 50;
	win.moveTo(x,y);
}
var clicked = false;
function openPermLink(url, isPopup) {
	if (clicked) { return false; }
	
	if (isPopup) {
		nw_width = 620;
		nw_height = 550;
		nw_left = (screen.width  - nw_width) / 2;
		nw_top = (screen.height - nw_height) / 2 - 50;
		openWindow(url, 'subwin', nw_height, nw_width, 'yes', 'yes', 'no', nw_left, nw_top);
	} else {
		location.href = url;
	}
	clicked = true;
	setTimeout('setFalseClicked()', 1000);
	return false;
}

function setFalseClicked() {
	clicked = false;
}

function setWindowSize(width, height)
{
	WINDOW_WIDTH = width;
	WINDOW_HEIGHT = height;
}

function adjustWindow()
{
	if (null == WINDOW_WIDTH || null == WINDOW_HEIGHT) {
		return;
	}
	
	// window.opener.location.hostにアクセスするとエラーが起こる場合があるので･･･
	var ok = false;
	try {
		var test = window.opener.location.host;
		ok = true;
	} catch (e) {}
	
	if (ok && window.opener && window.opener.location.host == window.location.host) {
		resizeTo(WINDOW_WIDTH, WINDOW_HEIGHT);
		moveWindowToCenter(window);
		focus();
	}
}

/**
 * ウィンドウを開く
 */
function openPopup(url, width, height)
{
	if (null == width) {
		width = 550;
	}
	if (null == height) {
		height = 600;
	}
	subWindow = window.open(url, "_popup", "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes,toolbar=no,status=no");
	return void(0);
}

function styleChangeOnMouseOver(id, className) {
	var obj, obj_top, obj_middle, obj_bottom, obj_left, obj_right, obj_text;
	if (document.all) {
		obj = document.all(id);
		obj_top = document.all(id + "_top");
		obj_middle = document.all(id + "_middle");
		obj_bottom = document.all(id + "_bottom");
		obj_left = document.all(id + "_left");
		obj_right = document.all(id + "_right");
		obj_text = document.all(id + "_text");
	} else if(document.getElementById) {
		obj = document.getElementById(id);
		obj_top = document.getElementById(id + "_top");
		obj_middle = document.getElementById(id + "_middle");
		obj_bottom = document.getElementById(id + "_bottom");
		obj_left = document.getElementById(id + "_left");
		obj_right = document.getElementById(id + "_right");
		obj_text = document.getElementById(id + "_text");
	}
	if (obj) {
		obj.className = className + "_hover";
	}		
	if (obj_top) {
		obj_top.className = className + "_hover_top";
	}		
	if (obj_middle) {
		obj_middle.className = className + "_hover_middle";
	}		
	if (obj_bottom) {
		obj_bottom.className = className + "_hover_bottom";
	}		
	if (obj_left) {
		obj_left.className = className + "_hover_left";
	}		
	if (obj_right) {
		obj_right.className = className + "_hover_right";
	}		
	if (obj_text) {
		obj_text.className = className + "_hover_text";
	}		
}

function styleChangeOnMouseOut(id, className, isSelected) {
	var obj, obj_top, obj_middle, obj_bottom, obj_left, obj_right, obj_text;
	if (document.all) {
		obj = document.all(id);
		obj_top = document.all(id + "_top");
		obj_middle = document.all(id + "_middle");
		obj_bottom = document.all(id + "_bottom");
		obj_left = document.all(id + "_left");
		obj_right = document.all(id + "_right");
		obj_text = document.all(id + "_text");
	} else if(document.getElementById) {
		obj = document.getElementById(id);
		obj_top = document.getElementById(id + "_top");
		obj_middle = document.getElementById(id + "_middle");
		obj_bottom = document.getElementById(id + "_bottom");
		obj_left = document.getElementById(id + "_left");
		obj_right = document.getElementById(id + "_right");
		obj_text = document.getElementById(id + "_text");
	}
	var onText = isSelected ? "_on" : "";
	if (obj) {
		obj.className = className + onText;
	}		
	if (obj_top) {
		obj_top.className = className + onText + "_top";
	}		
	if (obj_middle) {
		obj_middle.className = className + onText + "_middle";
	}		
	if (obj_bottom) {
		obj_bottom.className = className + onText + "_bottom";
	}		
	if (obj_left) {
		obj_left.className = className + onText + "_left";
	}		
	if (obj_right) {
		obj_right.className = className + onText + "_right";
	}		
	if (obj_text) {
		obj_text.className = className + onText + "_text";
	}		
}

function sidemenuOnMouseOver(id) {
	if (document.all) {
		if (document.all(id + "_table")) document.all(id + "_table").className = "sidemenu_table_hover";
		if (document.all(id + "_top")) document.all(id + "_top").className = "sidemenu_hover_top";
		if (document.all(id + "_mdl")) document.all(id + "_mdl").className = "sidemenu_hover_mdl";
		if (document.all(id + "_btm")) document.all(id + "_btm").className = "sidemenu_hover_btm";
	} else if(document.getElementById) {
		if (document.getElementById(id + "_table")) document.getElementById(id + "_table").className = "sidemenu_table_hover";
		if (document.getElementById(id + "_top")) document.getElementById(id + "_top").className = "sidemenu_hover_top";
		if (document.getElementById(id + "_mdl")) document.getElementById(id + "_mdl").className = "sidemenu_hover_mdl";
		if (document.getElementById(id + "_btm")) document.getElementById(id + "_btm").className = "sidemenu_hover_btm";
	}
}

function sidemenuOnMouseOut(id, isSelected) {
	if (isSelected) {
		if (document.all) {
			if (document.all(id + "_table")) document.all(id + "_table").className = "sidemenu_table_on";
			if (document.all(id + "_top")) document.all(id + "_top").className = "sidemenu_on_top";
			if (document.all(id + "_mdl")) document.all(id + "_mdl").className = "sidemenu_on_mdl";
			if (document.all(id + "_btm")) document.all(id + "_btm").className = "sidemenu_on_btm";
		} else if(document.getElementById) {
			if (document.getElementById(id + "_table")) document.getElementById(id + "_table").className = "sidemenu_table_on";
			if (document.getElementById(id + "_top")) document.getElementById(id + "_top").className = "sidemenu_on_top";
			if (document.getElementById(id + "_mdl")) document.getElementById(id + "_mdl").className = "sidemenu_on_mdl";
			if (document.getElementById(id + "_btm")) document.getElementById(id + "_btm").className = "sidemenu_on_btm";
		}

	} else {
		if (document.all) {
			if (document.all(id + "_table")) document.all(id + "_table").className = "sidemenu_table";
			if (document.all(id + "_top")) document.all(id + "_top").className = "sidemenu_top";
			if (document.all(id + "_mdl")) document.all(id + "_mdl").className = "sidemenu_mdl";
			if (document.all(id + "_btm")) document.all(id + "_btm").className = "sidemenu_btm";
		} else if(document.getElementById) {
			if (document.getElementById(id + "_table")) document.getElementById(id + "_table").className = "sidemenu_table";
			if (document.getElementById(id + "_top")) document.getElementById(id + "_top").className = "sidemenu_top";
			if (document.getElementById(id + "_mdl")) document.getElementById(id + "_mdl").className = "sidemenu_mdl";
			if (document.getElementById(id + "_btm")) document.getElementById(id + "_btm").className = "sidemenu_btm";
		}
	}
}

/**
 * adjustWindow()で使用する、Windowのサイズを変更する定数
 * どちらかがnullの場合は変更しない。
 */
WINDOW_WIDTH = null;
WINDOW_HEIGHT = null;

/**
 * WINDOW_WIDTH,WINDOW_HEIGHTが指定されている場合、
 * onloadでサイズを変更する。
 */
UtilKit.addhook(window, 'onload', adjustWindow);