function analyzeUA(){
	var ua = navigator.userAgent;
	var browser = "";
	//Safari 1.2
	if( ua.toUpperCase().indexOf("SAFARI") > -1 ){
		browser = "safari";
	//Firefox
	} else if( ua.toUpperCase().indexOf("FIREFOX") > -1 ){
		browser = "firefox";
	//Opera 3, 4, 5, 6, 7, 8, 9
	} else if( ua.toUpperCase().indexOf("OPERA") > -1 ){
		browser = "opera";
	//Netscape 6, 7, 8
	} else if( ua.toUpperCase().indexOf("NETSCAPE") > -1 ){
		//Win
		if(ua.toUpperCase().indexOf("WIN") > -1 ){
			browser = "win-nn";
		//Mac
		} else if(ua.toUpperCase().indexOf("MAC") > -1 ){
			browser = "mac-nn";
		}
	//IE 4, 5, 6, 7
	} else if( ua.toUpperCase().indexOf("MSIE") > -1 ){
		//except ver.4
		if(navigator.appVersion.match(/MSIE 4/)) {
			location.href = rootPath + "netscape.html";
			return false;
		}
		
		//Win
		if(ua.toUpperCase().indexOf("WIN") > -1 ){
			browser = "win-ie";
		//Mac
		} else if(ua.toUpperCase().indexOf("MAC") > -1 ){
			browser = "mac-ie";
		}
	//Netscape 4
	} else if( ua.toUpperCase().indexOf("MOZILLA/4") > -1 ){
		//except ver.4
		location.href = rootPath + "netscape.html";
		return false;
	//Mozilla 1
	} else if( ua.toUpperCase().indexOf("MOZILLA") > -1 ){
		browser = "mozilla";
	}
	
	if( browser == "" ){
		browser = "point";
	}
	return browser;
}

function setActiveStyleSheet(title) {
	var i, a, main;
	var objCngTxt;
	var objImg;
	var baseImg = new Array("small", "medium", "large");
	
	if( title == "" || title == null || title == "null" ){
		title = "medium";
	}
	
	//set CSS
	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;
		}
	}
	
	
	objCngTxt = document.getElementById("size");
	if( objCngTxt != null && objCngTxt != "" ){

		//init Image
		objImg = objCngTxt.getElementsByTagName("img");
		for( i = 1; i < objImg.length; i++ ){
			objImg[i].src = rootPath + "/b_txt_" + baseImg[i-1] + ".gif";
		}
	
		//set active Image
		if( title != "" && title != null && title != "null" ){
			objCngTxt = document.getElementsByName("txt_" + title);
			objCngTxt[0].src = rootPath + "/b2_txt_" + title + ".gif";
		} else {
			objCngTxt = document.getElementsByName("txt_medium");
			objCngTxt[0].src = rootPath + "/b2_txt_medium.gif";
		}
	}
}

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 loadCSS(){
	var csslink	= '<link title="large" rel="alternate stylesheet" type="text/css" href="' + rootPath + "/" + browser + '_l.css">';
	   csslink += '<link title="medium" rel="stylesheet" type="text/css" href="' + rootPath + "/" + browser + '_m.css">';
	   csslink += '<link title="small" rel="alternate stylesheet" type="text/css" href="' + rootPath + "/" + browser + '_s.css">';
	document.write(csslink);
}

function writeSwitch(){
	var html = '<div id="change">';
	   html += '<p class="s">文字サイズ変更 ： <a href="javascript:;" name="txt_small" onClick="setActiveStyleSheet(\'small\'); return false;">小</a>　<a href="javascript:;" name="txt_medium" onClick="setActiveStyleSheet(\'medium\'); return false;">中</a>　<a href="javascript:;" name="txt_large" onClick="setActiveStyleSheet(\'large\'); return false;">大</a></p>';
	   html += '</div>';
	document.write(html);
}

//window.onload = function(e) {
//	var cookie = readCookie("style");
//	var title = cookie ? cookie : getPreferredStyleSheet();
//	setActiveStyleSheet(title);
//}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

