/*
===========================================================
フォントサイズ変更スクリプト（タイプB）

Last Updated:08/21/2001
　　　10/23/2001最終更新版より下記のURIのみ変更

insomnia!
http://insomnia.jp/
http://insomnia.jp/workshop/

Customized by 316
===========================================================
*/


/*
========== ::: ブラウザ判別時に使用する変数 ::: ==========
*/
uaName = navigator.userAgent;
appName = navigator.appVersion;


/*
========== ::: 初期設定 ::: ==========
*/

// 値の単位を設定（必ずダブルクオートかクオートで括る）
var fontSizeUnit = "px";

// 一回の操作で変化させる値を設定（ダブルクオートやクオートで括らない）
var perOrder = 2;

// 初期状態の値を設定（ダブルクオートやクオートで括らない）
var defaultSize = 15;

// 最大サイズ
var maxsize = 50;

// 最小サイズ
var minsize = 9;

// クッキーの名前（必ずダブルクオートかクオートで括る）
var ckName = "egoneorgfontsize";

// クッキーの有効期限（日）（ダブルクオートやクオートで括らない）
var ckDays = 30;

// クッキーのパス（必ずダブルクオートかクオートで括る。指定がいらない場合は"/"にする）
var ckPath = "/"


var ckNamefont = "egoneorgfontfamily";
var defaultfont = "Tahoma";

var fwName = "egoneorgfontweight";
var defaultfw = 'bold';
/*
========== :::ページ読み込み時の値を設定::: ==========
*/

// クッキー読み出し
var fsCK = GetCookie(ckName);
var fsCKfont = GetCookie(ckNamefont);
var fsCKfw = GetCookie(fwName);

if ( fsCK == null ) {
  currentSize = defaultSize;      //クッキーが無ければ現在の値を初期状態の値に設定
}
else{
  currentSize = Number(fsCK);      //クッキーがあれば現在の値をクッキーの値に設定
}

if ( fsCKfont == null ) {
  currentFont = defaultfont;      //クッキーが無ければ現在の値を初期状態の値に設定
}
else{
  currentFont = fsCKfont;      //クッキーがあれば現在の値をクッキーの値に設定
}

if ( fsCKfw == null ) {
  currentFw = defaultfw;      //クッキーが無ければ現在の値を初期状態の値に設定
}
else{
  currentFw = fsCKfw;      //クッキーがあれば現在の値をクッキーの値に設定
}

// クッキー保存
SetCookie( ckName ,currentSize);
SetCookie( ckNamefont ,currentFont);
SetCookie( fwName ,currentFw);

/*===================================
  [関数 fscRef]
  BODY要素のイベントハンドラ"onload"ならびに関数fscから呼び出される。
  変数"currentSize"の値に従って
  オブジェクトのfontStyleプロパティを変更する
====================================*/

function fscRef(count){

  // === ::: 変更を加えるオブジェクトの判定 ::: ===
  //
  //  NN4もしくはMacIE4.0の場合、エラーメッセージを回避
  if (( document.layers )||(( appName.indexOf("Mac",0) != -1 ) && ( uaName.indexOf("MSIE 4.0",0) != -1 ))){
    return false;
  }

  else if( document.body ){
    for (i=0;i<count;i++){
      if (document.getElementById('fs'+i)){
        document.getElementById('fs'+i).style.fontSize = currentSize + fontSizeUnit;
        document.getElementById('fs'+i).style.fontFamily = "'" + currentFont + "'";
        document.getElementById('fs'+i).style.fontWeight = currentFw;
      }
    }
  }
}

// _______________________________________ end of function fscRef() ___ 


/*===================================
  [関数 fsc]
  引数CMDに渡される値に応じて
  変更後の値を算出しクッキーに書き込む。
====================================*/

function fsc( CMD ,cnt ,cfont){

  // 拡大：現時点の値に一回の操作で変化させる値を加えて操作後の値"newSize"に代入
  if( CMD == "larger" ){
    if (currentSize + perOrder <= maxsize){
    var newSize = Number( currentSize + perOrder );
    SetCookie( ckName , newSize );      //クッキー書き込み
    } else {
      newSize = currentSize;
    }
  }

  // 縮小：現時点の値から一回の操作で変化させる値を引き操作後の値に代入
  // 現時点のサイズの値が一回の操作で変化させる値と同じならそのまま操作後の値に代入
  if( CMD == "smaller" ){
    if ( currentSize != perOrder ){
    if (currentSize - perOrder >= minsize){
      var newSize = Number( currentSize - perOrder );
      SetCookie( ckName , newSize );      //クッキー書き込み
     } else {
       newSize = currentSize;
     }
    }
    else{
      var newSize=Number(currentSize);
    }
  }

	//フォントを変更：メイリオ
	if (CMD=="fme"){
		newSize = currentSize;
		SetCookie( ckNamefont ,"%a5%e1%a5%a4%a5%ea%a5%aa");      //クッキー書き込み
		currentFont = "メイリオ";
	}

	//フォントを変更：Meiryo UI
	if (CMD=="fmeu"){
		newSize = currentSize;
		SetCookie( ckNamefont ,"Meiryo UI");      //クッキー書き込み
		currentFont = "Meiryo UI";
	}

	//フォントを変更：Tahoma
	if (CMD=="fta"){
		newSize = currentSize;
		SetCookie( ckNamefont ,"Tahoma");      //クッキー書き込み
		currentFont = "Tahoma";
	}

	//フォントを変更：ＭＳ Ｐゴシック
	if (CMD=="fmsg"){
		newSize = currentSize;
		SetCookie( ckNamefont ,"%a3%cd%a3%d3%20%a3%d0%a5%b4%a5%b7%a5%c3%a5%af");      //クッキー書き込み
		currentFont = "ＭＳ Ｐゴシック";
	}

	//フォントを変更：ＭＳ Ｐ明朝
	if (CMD=="fmsm"){
		newSize = currentSize;
		SetCookie( ckNamefont ,"%a3%cd%a3%d3%20%a3%d0%cc%c0%c4%ab");      //クッキー書き込み
		currentFont = "ＭＳ Ｐ明朝";
	}

	if (CMD=="fmsui"){
		newSize = currentSize;
		SetCookie( ckNamefont ,"MS UI Gothic");      //クッキー書き込み
		currentFont = "MS UI Gothic";
	}

	if (CMD=="fw_normal"){
		newSize = currentSize;
		SetCookie( fwName ,"normal");      //クッキー書き込み
		currentFw = "normal";
	}

	if (CMD=="fw_bold"){
		newSize = currentSize;
		SetCookie( fwName ,"bold");      //クッキー書き込み
		currentFw = "bold";
	}

  // 元に戻す：操作後の値を初期値にする
  if( CMD == "default" ){
    newSize = defaultSize;
	currentFont = defaultfont;
	currentFw   = defaultfw
	DeleteCookie( ckNamefont );
	DeleteCookie( fwName );
    DeleteCookie( ckName );      //クッキー削除
  }

  // NN4もしくはMacIE4.0の場合、エラーメッセージを回避しダイアログを表示する
  // NN4用ダイアログ
  if( document.layers ){
    window.alert( "このスクリプトはNetscape Communicator4.xでは動作しません" );
    return false;
  }

  // MacIE4用ダイアログ
  else if(( appName.indexOf("Mac",0) != -1 ) && ( uaName.indexOf("MSIE 4.0",0) != -1)){
    window.alert( "Sorry! MacIE4.0 is not supported." );
    return false;
  }else{
  // 現在の値を操作後の値に変更
  currentSize = newSize;

  // サイズ変更関数を呼び出す
  fscRef(cnt);
  }
}

// _______________________________________ end of function fsc() ___ 


/*===================================
  [関数 SetCookie]
  クッキーに値を書き込む
====================================*/

function SetCookie(name,value){
  var dobj = new Date();
  dobj.setTime( dobj.getTime() + 24 * 60 * 60 * ckDays * 1000);
  var expiryDate = dobj.toGMTString();
  document.cookie = name + '=' + escape(value)+ ';expires=' + expiryDate + ';path=' + ckPath;
}


/*===================================
  [関数 GetCookie]
  クッキーを取得する
====================================*/
function GetCookie (name){
  var arg  = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen){
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
   return null;
}

/*===================================
  [関数 getCookieVal]
  クッキーの値を抽出する
====================================*/
function getCookieVal (offset){
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset,endstr));
}

/*===================================
  [関数 DeleteCookie]
  クッキーを削除する
====================================*/
function DeleteCookie(name){
  if (GetCookie(name)) {
    document.cookie = name + '=' +
    '; expires=Thu, 01-Jan-70 00:00:01 GMT;path='+ckPath;
  }
}

//EOF
