/******************************************
文字サイズ変更スクリプト
******************************************/
/*****************************************
選択された(されている)スタイルの適用
この関数を呼び出す際に
setActiveStyleSheet(title)の
「title」を変更するスタイルシートの要素内の
「title」を指定してください。
******************************************/
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")) {
			var img = a.getAttribute("title");
      a.disabled = true;
      if(a.getAttribute("title") == title){
				a.disabled = false;
			}
    }
  }
}

/*****************************************
現在有効になっているスタイルをチェック
******************************************/
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;
}
/*****************************************
HTMLの中からスタイルシートのリンクタグを
探してそのタイトルを返す
******************************************/
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;
}
/*****************************************
ウィンドウを閉じる際にクッキーの保存
******************************************/
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("txtStyle", title, 365);
}
/*****************************************
クッキーの読み込みとスタイルの適用
******************************************/
var cookie = readCookie("txtStyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

