/*
===========================================================
文字サイズ変更スクリプト
===========================================================
*/

// 文字サイズ変更機能の使用有無を設定（ダブルクオートやクオートで括らない）
// ※必ず小文字で設定して下さい。（true=利用する、false=利用しない）
var useFontChange = true;


// 一回の操作で変化させる値を設定（ダブルクオートやクオートで括らない）
var perOrder = 2;

// 値の単位を設定（必ずダブルクオートかクオートで括る）
var fontSizeUnit = "%";

// 初期状態の値を設定（ダブルクオートやクオートで括らない）
var defaultSize = 100;

// 最大値を設定（ダブルクオートやクオートで括らない）
var maxSize = 200;

// クッキーの名前（必ずダブルクオートかクオートで括る）
var ckName = "SerlsFontSize";

// クッキーの有効期限（日）（ダブルクオートやクオートで括らない）
// 0を指定した場合、ブラウザ終了時に初期化する
var ckDays = 0;

// クッキーのパス（必ずダブルクオートかクオートで括る。指定が不要の場合は"/"にする）
var ckPath = "/"

// フォントサイズを変更するタグ
var tags_disp    = new Array('div','td','tr','th','font','span','h1','h2','h3','h4','h5','h6','p','input');


// フラグ：オンの間は文字拡大しない
var flg_Mojistop = false;


// ========== ::: ページ読み込み時の値を設定 ::: ==========
var currentSize ;
// クッキー読み出し
var ckSize = GetCookie(ckName);

addEvent(window,"load",function(){
	if ( ckSize != null && !isNaN(ckSize) ) {
	  //クッキーがあれば現在の値をクッキーの値に設定
	  currentSize = parseInt(ckSize);
	  FontChange('body',0);
	} else {
	  //クッキーが無ければデフォルトの値を初期状態の値に設定
	  currentSize = defaultSize;
	}

});
function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}

//*************************************************
// 文字サイズ拡大
//*************************************************
function FontLarge(target) {
  // currentSizeがmaxSize以上は無効
  if( currentSize + perOrder > maxSize ) return;

  FontChange(target, 0 + perOrder);
}

//*************************************************
// 文字サイズ縮小関数
//*************************************************
function FontSmall(target) {
  // currentSizeが0以下は無効
  if( currentSize - perOrder <= 0 ) return;
  FontChange(target, 0 - perOrder);
}

//*************************************************
// 文字サイズ標準関数
//*************************************************
function FontDefault(target) {
  //FontChange(target, null);
  DeleteCookie(ckName);
  window.location.reload();
}

//*************************************************
// 文字サイズ変更関数
//*************************************************
function FontChange(target, size) {
  if(!useFontChange) return;
  if (!document.getElementById) return;
  var dore = document,tarS = null,value,su,cTags;

  if( size == null){
    // null指定の場合、初期値にリセット
    currentSize = defaultSize;
  } else {
    // sizeをプラス
    currentSize = currentSize + size;
  }

  // Cookieにフォントサイズをセット
  SetCookie(ckName, currentSize);

  if (!(tarS = dore.getElementById(target))) tarS = dore.getElementsByTagName(target)[0];
  
  tarS.style.fontSize = currentSize + fontSizeUnit;

  // 表示系タグ
  for (value = 0 ; value < tags_disp.length ; value++) {
    cTags = tarS.getElementsByTagName(tags_disp[value]);
    
    for (su = 0 ; su < cTags.length ; su++) {
  
  		//文字拡大の対象外とするタグIDを指定（そのタグ内にあるタグは対象外となる）
  		/*
    	if (cTags[su].id == "map"){
    		flg_Mojistop = true;
    	}
    	*/
  		//停止フラグがオンならば、そのタグは拡大の対象外
      	if (flg_Mojistop) { continue;}
    	
    	/*----------------------
    	 【タグ別】倍率の調整
    	 ----------------------- */
    	//<font>タグ専用処理
    	if (tags_disp[value] == "font") {
    		//<font size="xx">への対応
    		switch(cTags[su].size){
    		case "-2":
    			cTags[su].style.fontSize = currentSize - (currentSize * 0.3) + fontSizeUnit;
    			break;
    		case "-1":
    			cTags[su].style.fontSize = currentSize + fontSizeUnit;
    			break;
    		case "+1":
    			cTags[su].style.fontSize = currentSize + (currentSize * 0.2) + fontSizeUnit;
    			break;
    		case "+2":
    			cTags[su].style.fontSize = currentSize + (currentSize * 0.5) + fontSizeUnit;
    			break;
    		case "+3":
    			cTags[su].style.fontSize = currentSize + (currentSize * 0.8) + fontSizeUnit;
    			break;
    		case "+4":
    			cTags[su].style.fontSize = currentSize + (currentSize * 2.0) + fontSizeUnit;
    			break;
    		default:
    			cTags[su].style.fontSize = currentSize + fontSizeUnit;
    			break;
    		}
    	}
    	
    	//<h1>タグ専用処理
    	else if (tags_disp[value] == "h1"){
    		cTags[su].style.fontSize = currentSize + (currentSize * 0.6) + fontSizeUnit;
    	}
    	//<h2>タグ専用処理
    	else if (tags_disp[value] == "h2"){
    		cTags[su].style.fontSize = currentSize + (currentSize * 0.5) + fontSizeUnit;
    	}
    	//<h3>タグ専用処理
    	else if (tags_disp[value] == "h3"){
    		cTags[su].style.fontSize = currentSize + (currentSize * 0.2) + fontSizeUnit;
    	}
    	
    	//その他、配列tags_disp()にて指定したタグの処理【通常倍率】
    	else {
    		cTags[su].style.fontSize = currentSize + fontSizeUnit;
    		
    	}
    }
  }
}


//*************************************************
// クッキーに値を書き込む
//*************************************************
function SetCookie( name , value ){
  var dobj = new Date();
  var expiryDate = "";
  // クッキーの有効期限が0以上の場合
  if( ckDays > 0){
    dobj.setTime(dobj.getTime() + 24 * 60 * 60 * ckDays * 1000);
    expiryDate = ';expires=' + dobj.toGMTString();
  }
  document.cookie = name + '=' + escape(value) + expiryDate + ';path=' + ckPath;
}

//*************************************************
// クッキーを取得する
//*************************************************
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;
}

//*************************************************
// クッキーの値を抽出する
//*************************************************
function getCookieVal (offset){
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset,endstr));
}

//*************************************************
// クッキーを削除する
//*************************************************
function DeleteCookie(name){
  if (GetCookie(name)){
    document.cookie = name + '=' +
    '; expires=Thu, 01-Jan-70 00:00:01 GMT;path='+ckPath;
  }
}

//*************************************************
// タブ切替え
//*************************************************
function TabChange(num,max) {

	for(i=1;i<=max;i++){
		divId = "Tab" + i.toString();
		aName = "Tablink" + i.toString();

		if(document.getElementById(divId)) {
		  
			OBJ = document.getElementById(divId);
			
			//すべて表示する場合
			if (num == 0) {
				OBJ.style.display="block";	//表示
				if (document.getElementsByName(aName)[0]) {
					document.getElementsByName(aName)[0].style.textDecoration = "underline";
				}
			}
			//指定されたIDである場合
			else if (i == num) {
				OBJ.style.display="block";	//表示
				if (document.getElementsByName(aName)[0]) {
					document.getElementsByName(aName)[0].style.textDecoration = "none";
				}
			}
			//指定されたID以外
			else {
				OBJ.style.display="none";	//隠す
				if (document.getElementsByName(aName)[0]) {
					document.getElementsByName(aName)[0].style.textDecoration = "underline";
				}
			}
		}
	　
	}
	//“すべて表示する”リンク文字の制御
	if (document.getElementsByName("Tablink0")[0]) {
		if(num == 0) {	//すべて表示する場合
			document.getElementsByName("Tablink0")[0].style.textDecoration = "none";
		}
		else {			//ID指定の場合
			document.getElementsByName("Tablink0")[0].style.textDecoration = "underline";
		}
	}
	
}
function TabChangeStart(max) {
	if(location.search.length > 1) {
		var getP = location.search.substr(1);
		
	}
	alert(getP);
}

//EOF
