//SSL対応
var HostAddress;
if(document.location.protocol == "https:"){
	HostAddress = 'https://www1.hankyu-hotel.com/';
}else{
	HostAddress = 'http://www.hankyu-hotel.com/';
}


//文字サイズ変更追加スクリプト
//クッキー発行------------------

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() + (365 * 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,"https://www1.hankyu-hotel.com/hhd-group/common/css/font-l.css");
	} else if(n == "m") {
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/common/css/font-m.css");
	} else if(n == "s"){
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/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="width:930px;">';
		html += '<ul style="width:180px; list-style:none; margin-left:720px;">';
		html += '<li style="float:left; margin-right:8px;">';
		html += '<a href="' + HostAddress + 'hhd-group/common/font.html" onclick="window.open(\'https://www1.hankyu-hotel.com/hhd-group/common/font.html\', \'\', \'width=550,height=450,status=yes,resizable=yes,scrollbars=yes\'); return false;" /><img src="' + HostAddress + 'hhd-group/common/images/mds_size.gif" border="0" width="85" height="22" title="文字サイズの変更" alt="文字サイズの変更" /></a></li>';
		html += '<li style="margin-right:4px; float:left;"><a href="javascript:fontSizeSwitch(\'l\');" title="大" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/l-in.gif" width="22" height="22" alt="大" id="size_l" border="0" /></a></li>';
		html += '<li style="margin-right:4px; float:left;"><a href="javascript:fontSizeSwitch(\'m\');" title="中" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/m.gif" width="22" height="22" alt="中" id="size_m" border="0" /></a></li>';
		html += '<li style="float:left;"><a href="javascript:fontSizeSwitch(\'s\');" title="小" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/s.gif" width="22" height="22" alt="小" id="size_s" border="0" /></a></li>';
		html += '</ul>';
		html += '<div style="clear:left;"></div><div style="clear:both;"></div></div>';
	}
	if(n == "m"){
		html += '<div style="width:930px;">';
		html += '<ul style="width:180px; list-style:none; margin-left:720px;">';
		html += '<li style="float:left; margin-right:8px;">';
		html += '<a href="' + HostAddress + 'hhd-group/common/font.html" onclick="window.open(\'https://www1.hankyu-hotel.com/hhd-group/common/font.html\', \'\', \'width=550,height=450,status=yes,resizable=yes,scrollbars=yes\'); return false;" /><img src="' + HostAddress + 'hhd-group/common/images/mds_size.gif" border="0" width="85" height="22" title="文字サイズの変更" alt="文字サイズの変更" /></a></li>';
		html += '<li style="margin-right:4px; float:left;"><a href="javascript:fontSizeSwitch(\'l\');" title="大" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/l.gif" width="22" height="22" alt="大" id="size_l" border="0" /></a></li>';
		html += '<li style="margin-right:4px; float:left;"><a href="javascript:fontSizeSwitch(\'m\');" title="中" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/m-in.gif" width="22" height="22" alt="中" id="size_m" border="0" /></a></li>';
		html += '<li style="float:left;"><a href="javascript:fontSizeSwitch(\'s\');" title="小" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/s.gif" width="22" height="22" alt="小" id="size_s" border="0" /></a></li>';
		html += '</ul>';
		html += '<div style="clear:left;"></div><div style="clear:both;"></div></div>';
	}
	if(n == "s"){
		html += '<div style="width:930px;">';
		html += '<ul style="width:180px; list-style:none; margin-left:720px;">';
		html += '<li style="float:left; margin-right:8px;">';
		html += '<a href="' + HostAddress + 'hhd-group/common/font.html" onclick="window.open(\'https://www1.hankyu-hotel.com/hhd-group/common/font.html\', \'\', \'width=550,height=450,status=yes,resizable=yes,scrollbars=yes\'); return false;" /><img src="' + HostAddress + 'hhd-group/common/images/mds_size.gif" border="0" width="85" height="22" title="文字サイズの変更" alt="文字サイズの変更" /></a></li>';
		html += '<li style="margin-right:4px; float:left;"><a href="javascript:fontSizeSwitch(\'l\');" title="大" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/l.gif" width="22" height="22" alt="大" id="size_l" border="0" /></a></li>';
		html += '<li style="margin-right:4px; float:left;"><a href="javascript:fontSizeSwitch(\'m\');" title="中" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/m.gif" width="22" height="22" alt="中" id="size_m" border="0" /></a></li>';
		html += '<li style="float:left;"><a href="javascript:fontSizeSwitch(\'s\');" title="小" tabindex="200">';
		html += '<img src="' + HostAddress + 'hhd-group/common/images/s-in.gif" width="22" height="22" alt="小" id="size_s" border="0" /></a></li>';
		html += '</ul>';
		html += '<div style="clear:left;"></div><div style="clear:both;"></div></div>';
	}
	btn.innerHTML = html;
}


//HTMLエスケープ------------------
function eH(str) {
	str = str.replace(/&/, '&amp;');
	str = str.replace(/</, '&lt;');
	str = str.replace(/>/, '&gt;');
	str = str.replace(/"/, '&quot;');
	return str;
}

function fontSizeInit() {
	//クッキー取得
	var n = getCookie('fontsize');
	if (n === null) {
			n = 'm';
	}
	if(n == "l") {
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/common/css/font-l.css");
	} else if(n == "m") {
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/common/css/font-m.css");
	} else if(n == "s"){
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/common/css/font-s.css");
	}

	if(document.getElementById('areaLeft')){
		//ボタン生成
		btnSet(n);
		btnCreate(n);
	}
}

function fontSizeInitBase() {
	//クッキー取得
	var n = getCookie('fontsize');
	if (n === null) {
		n = 'm';
	}
	if(n == "l") {
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/common/css/font-l.css");
	} else if(n == "m") {
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/common/css/font-m.css");
	} else if(n == "s"){
		applyCSS(document,"https://www1.hankyu-hotel.com/hhd-group/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;
}
