var cssMoji = "Small";
var cssColor = "Color";

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	if(title.indexOf("Small") != -1)
		cssMoji = "Small";
	if(title.indexOf("Middle") != -1)
		cssMoji = "Middle";
	if(title.indexOf("Large") != -1)
		cssMoji = "Large";
	if(title.indexOf("White") != -1)
		cssColor = "White";
	if(title.indexOf("Black") != -1)
		cssColor = "Black";
	if(title.indexOf("Color") != -1)
		cssColor = "Color";
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
		&& a.getAttribute("rel").indexOf("alt") == -1
		&& a.getAttribute("title")
		) return a.getAttribute("title");
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setActiveStyleSheetMixed(){
  setActiveStyleSheet(cssMoji + cssColor);
}

window.onload = function(e) {
	var instPath = '/zsmd/';
	var zoomText = '<a href="'+instPath+'lang/ja/html/index.html" id="btnZoomSight">ズームサイト起動ボタン"</a> ';
	if(chkBrowser()){
		if(document.getElementById("LaunchSettings")==null){
			zoomText = '<xml id="LaunchSettings" src="'+instPath+'launchsetting.xml" charset="UTF-8"></xml><a href="javascript:OpenZoomSight(\'ja\');" id="btnZoomSight">ズームサイト起動ボタン</a>';
		}else{
			zoomText = '';
		}
	}



	$('fontZoom').innerHTML = "\t\t\t\t<div id=\"fontsize\">文字サイズを変更</div>\n\t\t\t\t<a href=\"#\" id=\"btnFontSmall\">文字サイズ小</a>\n\t\t\t\t<a href=\"#\" id=\"btnFontMiddle\">文字サイズ中</a>\n\t\t\t\t<a href=\"#\" id=\"btnFontLarge\">文字サイズ大</a>\n\t\t\t\t<br class=\"clearfloat\">\n\t\t\t\t<div id=\"fontcolor\">背景色を変更</div>\n\t\t\t\t<a href=\"#\" id=\"btnBgWhite\">背景色白</a>\n\t\t\t\t<a href=\"#\" id=\"btnBgBlack\">背景色黒</a>\n\t\t\t\t<a href=\"#\" id=\"btnBgColor\">背景色標準色</a>\n\t\t\t\t<br class=\"clearfloat\">\n\t\t\t\t<div id=\"acSupport\">アクセシビリティサポート</div>\n\t\t\t\t" + zoomText + "\n\t\t\t\t<br class=\"clearfloat\">";


	
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);

	Event.observe($('btnFontSmall') , 'click', function(e){cssMoji='Small' ;setActiveStyleSheetMixed()}, false);
	Event.observe($('btnFontMiddle'), 'click', function(e){cssMoji='Middle';setActiveStyleSheetMixed()}, false);
	Event.observe($('btnFontLarge') , 'click', function(e){cssMoji='Large' ;setActiveStyleSheetMixed()}, false);
	
	Event.observe($('btnBgWhite'), 'click', function(e){cssColor='White';setActiveStyleSheetMixed()}, false);
	Event.observe($('btnBgBlack'), 'click', function(e){cssColor='Black';setActiveStyleSheetMixed()}, false);
	Event.observe($('btnBgColor'), 'click', function(e){cssColor='Color';setActiveStyleSheetMixed()}, false);

	Event.observe($('SearchWord'), 'click', function(e){
		if($('SearchWord').value == 'サイト内検索'){
			$('SearchWord').value = '';
		}
	}, false);
	Event.observe($('SearchWord'), 'blur' , function(e){
		if($('SearchWord').value == ''){
			$('SearchWord').value = 'サイト内検索';
		}
	}, false); 
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);



/* --------------------------------------------------------
	FLASHの枠消
-------------------------------------------------------- */

function showFlash(file,width,height){
	document.write('<object data="'+file+'" type="application/x-shockwave-flash" height="'+height+'" width="'+width+'">');
	document.write('<param name="movie" value="'+file+'">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="quality" value="best">');
	document.write('</object>');
}

