// フォントサイズを変更する対象エリア
var targets = new Array();
targets[0] = "footerArea"; // フッターエリア
targets[1] = "mainArea"; // メインエリア

var fontSizeBtnSOn  = "library/common/small-on.gif";
var fontSizeBtnSOff = "library/common/small-off.gif";
var fontSizeBtnMOn  = "library/common/medium-on.gif";
var fontSizeBtnMOff = "library/common/medium-off.gif";
var fontSizeBtnLOn  = "library/common/big-on.gif";
var fontSizeBtnLOff = "library/common/big-off.gif";

// Cookieから現在選択しているfontSizeを取得
function getCookie(){
 fontSize = "";
 cName = "FontSize=";
 tmpCookie = document.cookie + ";";
 start = tmpCookie.indexOf(cName);
 if (start != -1)
 {
  end = tmpCookie.indexOf(";", start);
  fontSize = tmpCookie.substring(start + cName.length, end);
  // 文字サイズを変更（Cookieに保存されている値）
  changeFontSize(fontSize);
 } else {
  // 文字サイズを変更（デフォルトの文字サイズ）
  fontSize = "100%";
  changeFontSize(fontSize);
 }
 // 文字サイズに応じてアイコンを変更
 changeFontSizeIcon(fontSize);
 //color
 var p;
 pName = "F_Color=";
 tmpCookie = document.cookie + ";";
 start = tmpCookie.indexOf(pName);
 if (start != -1)
 {
  end = tmpCookie.indexOf(";", start);
  p = tmpCookie.substring(start + pName.length, end);
  changeCSS(p);
 }
}

// Cookieへ現在選択しているfontSizeを保存
function setCookie(s){
 cName = "FontSize=";
 exp = new Date();
 exp.setTime(exp.getTime() + 31536000000);
 document.cookie = cName + s + "; path=/; expires=" + exp.toGMTString();
}

// 文字サイズ変更（大）
function textSizeUp(){
 currentSize = document.getElementById(targets[0]).style.fontSize;
 if (!currentSize) {
  currentSize = "120%";
 }
 if(currentSize=="120%") {
  alert("これ以上、文字を大きくすることはできません");
 }
 
 fontSize = "120%";
 changeFontSize(fontSize);
 changeFontSizeIcon(fontSize);
 setCookie(fontSize);
}

// 文字サイズ変更（小）
function textSizeDown(){
 currentSize = document.getElementById(targets[0]).style.fontSize;
 if (!currentSize) {
  currentSize = "80%";
 }
 if(currentSize=="80%") {
  alert("これ以上、文字を小さくすることはできません");
 }
 
 fontSize = "80%";
 changeFontSize(fontSize);
 changeFontSizeIcon(fontSize);
 setCookie(fontSize);
}

// 文字サイズ変更（中）
function textSizeDefault(){
 fontSize = "100%";
 changeFontSize(fontSize);
 changeFontSizeIcon(fontSize);
 setCookie(fontSize);
}

// 文字サイズを変更
function changeFontSize(fontSize) {
 for (i = 0; i < targets.length; i++) {
  document.getElementById(targets[i]).style.fontSize = fontSize;
 }
}

// 文字サイズに応じてアイコンを変更
function changeFontSizeIcon(fontSize) {
 if(fontSize == "80%") {
  document.getElementById("fontSizeBtnS").src = pbGlobalAliasBase + fontSizeBtnSOn;
  document.getElementById("fontSizeBtnM").src = pbGlobalAliasBase + fontSizeBtnMOff;
  document.getElementById("fontSizeBtnL").src = pbGlobalAliasBase + fontSizeBtnLOff;
 }
 else if(fontSize == "100%") {
  document.getElementById("fontSizeBtnS").src = pbGlobalAliasBase + fontSizeBtnSOff;
  document.getElementById("fontSizeBtnM").src = pbGlobalAliasBase + fontSizeBtnMOn;
  document.getElementById("fontSizeBtnL").src = pbGlobalAliasBase + fontSizeBtnLOff;
 }
 else if(fontSize == "120%") {
  document.getElementById("fontSizeBtnS").src = pbGlobalAliasBase + fontSizeBtnSOff;
  document.getElementById("fontSizeBtnM").src = pbGlobalAliasBase + fontSizeBtnMOff;
  document.getElementById("fontSizeBtnL").src = pbGlobalAliasBase + fontSizeBtnLOn;
 }
}

////色合いの変更　//////////////////////////////////////////////////////////////////////////////
var targetLINK  = "changecss";
var css_keyword = "color";
var dir_path = "/library/js/";   //CSSファイルを置いてあるディレクトリを絶対パスで指定すること
//
function setColorCookie(s){
 cName = "F_Color=";
 exp = new Date();
 exp.setTime(exp.getTime() + 31536000000);
 document.cookie = cName + s + "; path=/" + "; expires=" + exp.toGMTString();
}
//
function changeCSS(par) {
 if(!par || par=="") return;
 var target = document.getElementById(targetLINK);
 if(!target) {
  links = document.getElementsByTagName('link');
  for(var i=0;i<links.length;i++) {
   temp = links[i].href;
   chk = temp.indexOf(css_keyword);
   if(chk!=-1) {
    target = links[i];
    break;
   }
  }
 }
 //
 if(!target || !target.cloneNode) {
  alert('ご利用のブラウザでは色合いの変更機能はご利用いただけないようです.\n[Element]or[cloneNode Method] None');
  return;
 }
 //
 var css_path = dir_path + par;
 //
 var newNode = target.cloneNode(true);
 newNode.href = css_path;
 target.parentNode.replaceChild(newNode,target);
 //
 setColorCookie(par);
}
//


//// 讀懃ｴ｢繝輔か繝ｼ繝蛻晄悄蛟､ ///////////////////////////
function setupDefForm() {
	var textarea = document.getElementsByTagName("textarea");
	for (i = 0; i < textarea.length; i++) {
		if (textarea[i].className.search("pbNodef") < 0) {
			if (textarea[i].value == textarea[i].defaultValue) {textarea[i].className += " pbOndef"; }
			textarea[i].onfocus = function() {offDef(this); }
			textarea[i].onblur = function() {onDef(this); }
		}
	}
	var input = document.getElementsByTagName("input");
	for (i = 0; i < input.length; i++) {
		if ((input[i].className.search("pbNodef") < 0) && ((input[i].getAttribute("type") == "text")||(input[i].getAttribute("type") == null))) {
			if (input[i].value == input[i].defaultValue) {input[i].className += " pbOndef"; }
			input[i].onfocus = function() {offDefForm(this); }
			input[i].onblur = function() {onDefForm(this); }
		}
	}
	return;
}

function offDefForm(from) {
	if (from.className.search("pbOndef") < 0) {return 0;}
	from.className = from.className.replace(/pbOndef/, "");
	from.value = "";
	return 1;
}
function onDefForm(from) {
	if (from.value != "") {return 0;}
	from.className += " pbOndef";
	from.value = from.defaultValue;
	return 1;
}
