var activeStyle = "fontSizeD";

function CanUseScriptBrowser()
{
    var appname = navigator.appName;
    var ua = navigator.userAgent;
    if(appname == "Microsoft Internet Explorer" && ua.indexOf("Opera")<0){
        var appver = navigator.appVersion;
        var p = appver.indexOf("MSIE",0);
        if(p >= 0){
            var p2 = appver.indexOf(";",p);
            if(p2 >= 0){
                var iever = appver.substring(p + 5, p2);
                // IEのバージョンが抽出できた。
                if(iever >= 6){    // IE6以降
                    return true;
                }
            }
        }
    } else if(ua.indexOf("Gecko/") >= 0){
        var p = ua.indexOf("Gecko/");
        var p2 = ua.indexOf(" ", p);
        if(p2 >= 0){
            var ver = ua.substring(p + 6, p2);
            if(ver >= 20001108){// Netscape6.0以降(メジャーバージョン)
                return true;
            }
        }
    } else if (ua.indexOf("Opera/")>=0) {
        var p = ua.indexOf("Opera/");
        var p2 = ua.indexOf(" ",p);
        if (p2 >= 0) {
            var ver = ua.substring(p + 6, p2);
            if (ver >= 5) { // Opera 5以降（メジャーバージョン）
                return true;
            }
        }
    } else if (ua.indexOf("Opera")>=0) {
        var p = ua.indexOf("Opera");
        var p2 = ua.indexOf(" ",p+6);
        if (p2 >= 0) {
            var ver = ua.substring(p + 6, p2);
            if (ver >= 7) { // Opera 7.0以降（メジャーバージョン）
                return true;
            }
        }
    } else if (navigator.appName=="Netscape") { //safariなど
       var version = navigator.appVersion;
       if (version.match(/^([0-9\.]+).+/i)){
          if (RegExp.$1>=5.0) 
            return true;
       }
    }
    return false;
}

function setFontStyle(targetTitle){
    switch (targetTitle) {
    case "fontSizeD":
	document.getElementById('main').style.fontSize='97%';
	break;
    case "fontSizeS":
	document.getElementById('main').style.fontSize='80%';
	break;
    case "fontSizeL":
	document.getElementById('main').style.fontSize='120%';
	break;
    case "fontSizeM":
	document.getElementById('main').style.fontSize='97%';
	break;
    }
    setCookie("saFontStyle", targetTitle, 365);
    activeStyle = targetTitle;
}

function getActiveStyle() {
    return activeStyle;
}

function setActiveStyle(targetStyle) {
    activeStyle = targetStyle;
}

function setCookie(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 getCookie(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;
}

window.onload = function(e) {
    if(document.getElementsByTagName){
	var cookie = getCookie("saFontStyle");
	var title = cookie ? cookie : getActiveStyle();
	setActiveStyle(title);
	if (CanUseScriptBrowser())
	    setFontCtlBtn(title);
    }
}

window.onunload = function(e) {
    if(document.getElementsByTagName){
	var title = getActiveStyle();
	//有効期限設定付(日指定)
	setCookie("saFontStyle", title, 365);
    }
}

var gRootPath="/";
var gBtnOn;
var pre_img1 = new Image();
var pre_img2 = new Image();
var pre_img3 = new Image();
pre_img1.src = gRootPath+"shared/images/button_fch-on-02.gif";
pre_img2.src = gRootPath+"shared/images/button_fch-on-03.gif";
pre_img3.src = gRootPath+"shared/images/button_fch-on-04.gif";
function setFontCtlBtn(myStyle){
	gBtnOn=myStyle;
	gRootPath = "/";
	if(myStyle=="fontSizeS"){
	    document.getElementById("changeM").src = gRootPath+"shared/images/button_fch-03.gif";
	    document.getElementById("changeL").src = gRootPath+"shared/images/button_fch-04.gif";
	    document.getElementById("changeS").src = gRootPath+"shared/images/button_fch-on-02.gif";

	}else if((myStyle=="fontSizeM")||(gBtnOn=="fontSizeD")){
	    document.getElementById("changeS").src = gRootPath+"shared/images/button_fch-02.gif";
	    document.getElementById("changeL").src = gRootPath+"shared/images/button_fch-04.gif";
	    document.getElementById("changeM").src = gRootPath+"shared/images/button_fch-on-03.gif";
	}else if(myStyle=="fontSizeL"){
	    document.getElementById("changeS").src = gRootPath+"shared/images/button_fch-02.gif";
	    document.getElementById("changeM").src = gRootPath+"shared/images/button_fch-03.gif";
	    document.getElementById("changeL").src = gRootPath+"shared/images/button_fch-on-04.gif";
	}else{
	    document.getElementById("changeS").src = gRootPath+"shared/images/button_fch-02.gif";
	    document.getElementById("changeM").src = gRootPath+"shared/images/button_fch-03.gif";
	    document.getElementById("changeL").src = gRootPath+"shared/images/button_fch-04.gif";
	}
}


function overFontCtlBtn(myID,myFlag){
	if(gBtnOn=="fontSizeS"){
	    BtnSOverSrc= gRootPath+"shared/images/button_fch-on-02.gif";
	    BtnMOverSrc= gRootPath+"shared/images/button_fch-over-03.gif";
	    BtnLOverSrc= gRootPath+"shared/images/button_fch-over-04.gif";

	    BtnSOutSrc= gRootPath+"shared/images/button_fch-on-02.gif";
	    BtnMOutSrc= gRootPath+"shared/images/button_fch-03.gif";
	    BtnLOutSrc= gRootPath+"shared/images/button_fch-04.gif";

	}else if((gBtnOn=="fontSizeM")||(gBtnOn=="fontSizeD")){
		BtnSOverSrc= gRootPath+"shared/images/button_fch-over-02.gif";
		BtnMOverSrc= gRootPath+"shared/images/button_fch-on-03.gif";
		BtnLOverSrc= gRootPath+"shared/images/button_fch-over-04.gif";

		BtnSOutSrc= gRootPath+"shared/images/button_fch-02.gif";
		BtnMOutSrc= gRootPath+"shared/images/button_fch-on-03.gif";
		BtnLOutSrc= gRootPath+"shared/images/button_fch-04.gif";

	}else if(gBtnOn=="fontSizeL"){
		BtnSOverSrc= gRootPath+"shared/images/button_fch-over-02.gif";
		BtnMOverSrc= gRootPath+"shared/images/button_fch-over-03.gif";
		BtnLOverSrc= gRootPath+"shared/images/button_fch-on-04.gif";

		BtnSOutSrc= gRootPath+"shared/images/button_fch-02.gif";
		BtnMOutSrc= gRootPath+"shared/images/button_fch-03.gif";
		BtnLOutSrc= gRootPath+"shared/images/button_fch-on-04.gif";

	}else{
		BtnSOverSrc= gRootPath+"shared/images/button_fch-over-02.gif";
		BtnMOverSrc= gRootPath+"shared/images/button_fch-over-03.gif";
		BtnLOverSrc= gRootPath+"shared/images/button_fch-over-04.gif";

		BtnSOutSrc= gRootPath+"shared/images/button_fch-02.gif";
		BtnMOutSrc= gRootPath+"shared/images/button_fch-03.gif";
		BtnLOutSrc= gRootPath+"shared/images/button_fch-04.gif";

	}

	if(myFlag=='over'){
	    if(myID=="fontSizeS"){
		document.getElementById("changeS").src = BtnSOverSrc;
	    }else if(myID=="fontSizeM"){
		document.getElementById("changeM").src = BtnMOverSrc;
	    }else if(myID=="fontSizeL"){
		document.getElementById("changeL").src = BtnLOverSrc;
	    }
	}else{
	    if(myID=="fontSizeS"){
		document.getElementById("changeS").src = BtnSOutSrc;
	    }else if(myID=="fontSizeM"){
		document.getElementById("changeM").src = BtnMOutSrc;
	    }else if(myID=="fontSizeL"){
		document.getElementById("changeL").src = BtnLOutSrc;
	    }
	}
}

function setCallFontStyle(targetTitle) {
    setFontStyle(targetTitle);
    setFontCtlBtn(targetTitle);
}
