/*==============================
htmlのbodyタグの中に
onload="init()"
の記述が必須
==============================*/
/*========初回ページ読み込み時の設定========*/
function init(f) {
  if (f == true || load('fontsize') == null) {
    save('fontsize', '100');                 //フォントサイズを%で指定
  }
  document.body.style.fontSize = load('fontsize') + '%';
  return null;
}

/*
===============フォントサイズ変更の設定===============
*/
function view(r) {
  s = (load('fontsize') - 0) + (r - 0);
  if (s < 70) {
     s = 70;
  }           //フォントの限界縮小値を%で指定
  document.body.style.fontSize = s + '%';
  save('fontsize', s);
  return null;
}

/*
===============リセットの設定===============
*/
function reset() {
  document.body.style.fontSize = "100%";           //フォントサイズ100%
  save('fontsize', 85);
  history.go(0);
  return null;
}

function getRuleBySelector (selector) {
  for (var i = 0, sheet; sheet = document.styleSheets[i++]; ) {
    if (sheet.disabled) continue;
    for (var j = 0, rule; rule = sheet.rules[j++]; ) {
      if (rule.selectorText == selector) {
        return rule;
      }
    }
  }
}

/*==============================
クッキーの有効期限（3日）
==============================*/
function save(n, v) {
  var key = new Date();
  key.setTime(key.getTime() + 24 * 60 * 60 * 3 * 1000);
  var exp = key.toGMTString();
  document.cookie = n + '=' + v + ';expires=' + exp + ';path=/';
  return null;
}

/*
===============クッキーの読み出し===============
*/
function load(n) {
  n = n + '=';
  var s = null;
  var x = document.cookie.length;
  var l = n.length;
  for (i = 0; i < x; i++) {
    if (document.cookie.substring(i, i + l) == n) {
      if (document.cookie.indexOf (";", i + l) == -1) {
        s = document.cookie.substring(i + l, document.cookie.length);
      } else {
        s = document.cookie.substring(i + l, document.cookie.indexOf (";", i + l));
      }
    }
  }
  return s;
}
