function preloadImage(imageSources)
{
	for(var i=0; i<imageSources.length; i++)
	{
		var image=new Image();
		image.src=imageSources[i];
	}
}

function swapImage(img,state)
{
	img.src=img.src.replace(/_[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)$/,"_"+state+"$1");
}

var currentFontSize="m";

function swapFontSizeButton(img,state,fontSize)
{
	if(fontSize!=currentFontSize)
	{
		swapImage(img,state);
	}
}

function changeFontSize(fontSize)
{
	var img=document.getElementById("fontSizeButton"+currentFontSize.toUpperCase());
	swapImage(img,"off");
	currentFontSize=fontSize;
	img=document.getElementById("fontSizeButton"+currentFontSize.toUpperCase());
	swapImage(img,"on");
	var links=document.getElementsByTagName("link");
	for(var i=0; i<links.length; i++)
	{
		var href=links[i].getAttribute("href");
		var title=links[i].getAttribute("title");
		if(href.indexOf("font_size")!=-1 && !title)
		{
			links[i].setAttribute("href","/css/font_size_"+fontSize+".css");
			setCookie("fontSize",fontSize,365);
			break;
		}
	}
}

var currentBgColor="1";

function swapBgColorButton(img,state,bgColor)
{
	if(bgColor!=currentBgColor)
	{
		swapImage(img,state);
	}
}

function changeBgColor(bgColor)
{
	var img=document.getElementById("bgColorButton"+currentBgColor);
	swapImage(img,"off");
	currentBgColor=bgColor;
	img=document.getElementById("bgColorButton"+currentBgColor);
	swapImage(img,"on");
	var links=document.getElementsByTagName("link");
	for(var i=0; i<links.length; i++)
	{
		var href=links[i].getAttribute("href");
		var title=links[i].getAttribute("title");
		if(href.indexOf("bg_color")!=-1 && !title)
		{
			links[i].setAttribute("href","/css/bg_color_"+bgColor+".css");
			setCookie("bgColor",bgColor,365);
			break;
		}
	}
}

function printLinkHTML()
{
	currentFontSize=getCookie("fontSize");
	if(currentFontSize=="")
	{
		currentFontSize="m";
	}
	currentBgColor=getCookie("bgColor");
	if(currentBgColor=="")
	{
		currentBgColor="1";
	}
	document.writeln
	(
		'<link rel="'+(currentFontSize=="m" ? "" : "alternate ")+'stylesheet" href="/css/font_size_m.css" type="text/css" charset="UTF-8" media="screen,print"'+(currentFontSize=="m" ? "" : ' title="Medium Text"')+' />'+
		'<link rel="'+(currentFontSize=="s" ? "" : "alternate ")+'stylesheet" href="/css/font_size_s.css" type="text/css" charset="UTF-8" media="screen,print"'+(currentFontSize=="s" ? "" : ' title="Small Text"')+' />'+
		'<link rel="'+(currentFontSize=="l" ? "" : "alternate ")+'stylesheet" href="/css/font_size_l.css" type="text/css" charset="UTF-8" media="screen,print"'+(currentFontSize=="l" ? "" : ' title="Large Text"')+' />'+
		'<link rel="'+(currentBgColor=="1" ? "" : "alternate ")+'stylesheet" href="/css/bg_color_1.css" type="text/css" charset="UTF-8" media="screen,print"'+(currentBgColor=="1" ? "" : ' title="White Background Color"')+' />'+
		'<link rel="'+(currentBgColor=="2" ? "" : "alternate ")+'stylesheet" href="/css/bg_color_2.css" type="text/css" charset="UTF-8" media="screen,print"'+(currentBgColor=="2" ? "" : ' title="Blue Background Color"')+' />'+
		'<link rel="'+(currentBgColor=="3" ? "" : "alternate ")+'stylesheet" href="/css/bg_color_3.css" type="text/css" charset="UTF-8" media="screen,print"'+(currentBgColor=="3" ? "" : ' title="Yellow Background Color"')+' />'+
		'<link rel="'+(currentBgColor=="4" ? "" : "alternate ")+'stylesheet" href="/css/bg_color_4.css" type="text/css" charset="UTF-8" media="screen,print"'+(currentBgColor=="4" ? "" : ' title="Black Background Color"')+' />'
	);
}

function printButtonHTML()
{
	document.writeln
	(
		'<dl class="buttonList">'+
		'<dt>文字サイズ</dt>'+
		'<dd><a href="javascript:void(0);" title="フォントサイズを小さくします。" onclick="changeFontSize(\'s\');return false;"><img src="/img/font_size_button_s_'+(currentFontSize=="s" ? "on" : "off")+'.gif" width="17" height="17" alt="フォントサイズを小さくします。" id="fontSizeButtonS" onmouseover="swapFontSizeButton(this,\'on\',\'s\');" onmouseout="swapFontSizeButton(this,\'off\',\'s\');" /></a></dd><!--'+
		'--><dd><a href="javascript:void(0);" title="標準的なフォントサイズにします。" onclick="changeFontSize(\'m\');return false;"><img src="/img/font_size_button_m_'+(currentFontSize=="m" ? "on" : "off")+'.gif" width="28" height="17" alt="標準的なフォントサイズにします。" id="fontSizeButtonM" onmouseover="swapFontSizeButton(this,\'on\',\'m\');" onmouseout="swapFontSizeButton(this,\'off\',\'m\');" /></a></dd><!--'+
		'--><dd><a href="javascript:void(0);" title="フォントサイズを大きくします。" onclick="changeFontSize(\'l\');return false;"><img src="/img/font_size_button_l_'+(currentFontSize=="l" ? "on" : "off")+'.gif" width="17" height="17" alt="フォントサイズを大きくします。" id="fontSizeButtonL" onmouseover="swapFontSizeButton(this,\'on\',\'l\');" onmouseout="swapFontSizeButton(this,\'off\',\'l\');" /></a></dd><!--'+
		'--></dl>'+
		'<dl class="buttonList">'+
		'<dt>背景色</dt>'+
		'<dd><a href="javascript:void(0);" title="背景色を白くします。" onclick="changeBgColor(\'1\');return false;"><img src="/img/bg_color_button_1_'+(currentBgColor=="1" ? "on" : "off")+'.gif" width="17" height="17" alt="背景色を白くします。" id="bgColorButton1" onmouseover="swapBgColorButton(this,\'on\',\'1\');" onmouseout="swapBgColorButton(this,\'off\',\'1\');" /></a></dd><!--'+
		'--><dd><a href="javascript:void(0);" title="背景色を青くします。" onclick="changeBgColor(\'2\');return false;"><img src="/img/bg_color_button_2_'+(currentBgColor=="2" ? "on" : "off")+'.gif" width="17" height="17" alt="背景色を青くします。" id="bgColorButton2" onmouseover="swapBgColorButton(this,\'on\',\'2\');" onmouseout="swapBgColorButton(this,\'off\',\'2\');" /></a></dd><!--'+
		'--><dd><a href="javascript:void(0);" title="背景色を黄色くします。" onclick="changeBgColor(\'3\');return false;"><img src="/img/bg_color_button_3_'+(currentBgColor=="3" ? "on" : "off")+'.gif" width="17" height="17" alt="背景色を黄色くします。" id="bgColorButton3" onmouseover="swapBgColorButton(this,\'on\',\'3\');" onmouseout="swapBgColorButton(this,\'off\',\'3\');" /></a></dd><!--'+
		'--><dd><a href="javascript:void(0);" title="背景色を黒くします。" onclick="changeBgColor(\'4\');return false;"><img src="/img/bg_color_button_4_'+(currentBgColor=="4" ? "on" : "off")+'.gif" width="17" height="17" alt="背景色を黒くします。" id="bgColorButton4" onmouseover="swapBgColorButton(this,\'on\',\'4\');" onmouseout="swapBgColorButton(this,\'off\',\'4\');" /></a></dd><!--'+
		'--></dl>'+
		'<dl class="buttonList">'+
		'<dt class="last"><a href="/policy/index.html#accessibility">背景色について</a></dt>'+
		'</dl>'
	);
}

function printPrintCSS()
{
	var bodyLayoutCSS="";
	if(navigator.userAgent.match(/MSIE *6/i))
	{
		bodyLayoutCSS+="zoom:96%;";
	}
	if(location.href.match(/^https?:\/\/www\.tonosho-hospital\.jp\/?$/i))
	{
		bodyLayoutCSS+="width:886px;";
	}
	if(bodyLayoutCSS!="")
	{
		document.writeln
		(
			'<style type="text/css">'+
			'@media print{.bodyLayout{'+bodyLayoutCSS+'}}'+
			'</style>'
		);
	}
}

function setCookie(key,value,days)
{
	var expires="";
	if(days!=undefined)
	{
		var date=new Date();
		date.setTime(date.getTime()+(days*1000*60*60*24));
		expires="expires="+date.toGMTString()+";";
	}
	document.cookie=key+"="+escape(value)+";"+expires+" path=/";
}

function getCookie(key)
{
	var cookies=document.cookie.match(eval("/(?:^|; *)"+key+"=(.*?)(?:;|$)/"));
	if(cookies && cookies[1])
	{
		return unescape(cookies[1]);
	}
	return "";
}

window.onload=function()
{
	preloadImage(
	[
		"/img/bg_color_button_1_off.gif",
		"/img/bg_color_button_1_on.gif",
		"/img/bg_color_button_2_off.gif",
		"/img/bg_color_button_2_on.gif",
		"/img/bg_color_button_3_off.gif",
		"/img/bg_color_button_3_on.gif",
		"/img/bg_color_button_4_off.gif",
		"/img/bg_color_button_4_on.gif",
		"/img/font_size_button_l_off.gif",
		"/img/font_size_button_l_on.gif",
		"/img/font_size_button_m_off.gif",
		"/img/font_size_button_m_on.gif",
		"/img/font_size_button_s_off.gif",
		"/img/font_size_button_s_on.gif",
		"/img/info_box_top_off.gif",
		"/img/info_box_top_on.gif",
		"/img/local_navi_top_off.gif",
		"/img/local_navi_top_on.gif",
		"/img/top_global_navi_about_on.gif",
		"/img/top_global_navi_community_on.gif",
		"/img/top_global_navi_guidance_on.gif",
		"/img/top_global_navi_health_care_on.gif",
		"/img/top_global_navi_home_on.gif",
		"/img/top_global_navi_information_on.gif",
		"/img/top_global_navi_recruit_on.gif"
	]);
};

