// JavaScript Document

document.write();
// クッキーのパス(サイト全体で有効にするため)
var ckPath = "/";

var setDay = new Date();  //　現在の日時を取得
var theDay = 30;  //　Cookie の保存期間を「30日間」とする

var changeSize=0;
var fontSizeDef = 13;	//デフォルトのフォントサイズの13px
var strcssBody = "font:"+ fontSizeDef +"px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;";
//---------------------------------------------------------------------------



//--------------------------------------------------------------------------
//　ページ読み込み時にフォントサイズに関するCSSをHEAD内で書き出す関数
//--------------------------------------------------------------------------
function CssFontWrite (n) {
var strcss = "body {font:"+n+"px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}";
var strcss2 = "font:"+n+"px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;";
var uai = new UAIdentifier();
if ( uai.ie >= 5.0 ){//Internet Explorer 5.0 or later
document.write("<body>");
fontCssChg("n");
if(eval(getCookie ("totalSize")) == 0){
setCookie("totalSize" , 0);
}
}
else{
strcss = "<style type='text/css' id='cssFontSize'>" +strcss + "</style>";
document.open();
document.write(strcss);
document.close();
}
}



//クッキーがあれば文字サイズのCSSを書き込む
//
/**/
if(eval(getCookie ("totalSize")) > 0){
CssFontWrite(fontSizeDef + getCookie("totalSize")*2);
}else{
CssFontWrite(fontSizeDef);
}



function insetRule(selector,declarations){
var sheets=document.styleSheets;

if(sheets){
var tSheet=sheets[sheets.length-1];  // 一番最後のスタイルシート
// MacIE4: styleSheets.item(sheets.length-1)は不可

if(document.all){
tSheet.addRule(selector,declarations);
// reserved value addRule(sSelector, sStyle [, iIndex])
// iIndexは省略可。省略するとスタイルシートの最後に追加。 
}
else{
tSheet.insertRule(selector+"{"+declarations+"}"
,tSheet.cssRules.length);
/* unsigned long insertRule(in DOMString rule
, in unsigned long index) */
// raises(DOMException);
// ruleはセレクタと宣言ブロック。被挿入規則のインデックスが返る。
}
}
}



//--------------------------------------------------------------------------
//　クリックでフォントサイズをリセットする（初期化する）関数
//--------------------------------------------------------------------------
function fontCssReset() {
if (document.all || document.getElementsByTagName("BODY")) {
var coll = document.getElementsByTagName("BODY");
coll = coll[0];
} else {
location.reload();
return;
}
var uai = new UAIdentifier();	//ブラウザ判別オブジェクト
if ( uai.ie >= 5.0){//Internet Explorer 5.0 or later or Netscape
document.body.setAttribute("style",strcssBody);
coll.style.fontSize = "13px";
}
else if(uai.opera){	//Opera
coll.style.fontSize = "13px";
}
else{
document.getElementById("cssFontSize").innerHTML = "";
//document.body.setAttribute("style",strcssBody);
coll.style.fontSize = "";
}
changeSize = 0;
return 0;
}



//--------------------------------------------------------------------------
//　クリックでフォントサイズを変更する関数
//--------------------------------------------------------------------------
function fontCssChg(changeStatus) {
if (document.all || document.getElementsByTagName("BODY")) {
var coll = document.getElementsByTagName("BODY");
coll = coll[0];
} else {
location.reload();
return;
}
if(eval(getCookie ("totalSize"))>0){
changeSize = getCookie ("totalSize");
}
//リセットが押された時
if (changeStatus == 0) {
fontCssReset();
} else {
if (changeStatus == 1) {
if(changeSize<2){changeSize ++;}
}else if (changeStatus == -1) {
if(changeSize>-2){changeSize --;}
}
textSize = fontSizeDef + changeSize * 2; // 2pxずつ拡大
if(textSize<9){textSize=9;}
if(textSize>17){textSize=17;}
//if (textSize < 2) {textSize = 2;}
coll.style.fontSize = textSize + "px";
}
//クッキーに記録
setCookie("totalSize" , changeSize);
}



//--------------------------------------------------------------------------
//　Cookieを参照する関数（Cookieから指定されたデータを抜きだす）
//　成功した時はnull以外、失敗した時はfalseを返す
//--------------------------------------------------------------------------
function getCookie (key) {
tmp = document.cookie + "; path=" + ckPath;
tmp1 = tmp.indexOf (key, 0);
if (tmp1 != -1) {
tmp = tmp.substring (tmp1, tmp.length);
start = tmp.indexOf ("=", 0) + 1;
end = tmp.indexOf (";", start);
return (unescape (tmp.substring (start, end)));
} else {
return(0);
}
}



//--------------------------------------------------------------------------
//　Cookieを設定する関数（Cookieにデータを保存する）
//　成功した時はtrue、失敗した時はfalseを返す
//--------------------------------------------------------------------------
function setCookie(theName,theValue)
{
if ((theName != null) && (theValue != null))
{
expDay = new Date(); //　現在の日時を取得
expDay.setTime(expDay.getTime()+(theDay*1000*60*60*24)); //　Cookie期限の設定
expDay = expDay.toGMTString();
//document.cookie = "";
document.cookie = theName + "="+escape(theValue)+";expires="+expDay+ ';path=' + ckPath; // データ保存
//		alert("Set:document.cookie =" + document.cookie);
return true;
}
return false;
}



//--------------------------------------------------------------------------
//　ブラウザ判別関数
//--------------------------------------------------------------------------
// User Agent Identifier
// Copyright (C) 2006-2007 Magicant (v1.9.2 2007-02-02)

function UAIdentifier() {
if (typeof(navigator) != "object" || !navigator.userAgent) {
this.unknown = true;
return;
}

var ua = navigator.userAgent;
var match;

if (typeof(RegExp) == "undefined") {
if (ua.indexOf("Opera") >= 0) {
this.opera = true;
} else if (ua.indexOf("Netscape") >= 0) {
this.netscape = true;
} else if (ua.indexOf("Mozilla/") == 0) {
this.mozilla = true;
} else {
this.unknown = true;
}

if (ua.indexOf("Gecko/") >= 0) {
this.gecko = true;
}

if (ua.indexOf("Win") >= 0) {
this.windows = true;
} else if (ua.indexOf("Mac") >= 0) {
this.mac = true;
} else if (ua.indexOf("Linux") >= 0) {
this.linux = true;
} else if (ua.indexOf("BSD") >= 0) {
this.bsd = true;
} else if (ua.indexOf("SunOS") >= 0) {
this.sunos = true;
}
return;
}

/* for Trident/Tasman */
/*@cc_on
@if (@_jscript)
function jscriptVersion() {
switch (@_jscript_version) {
case 3.0:  return "4.0";
case 5.0:  return "5.0";
case 5.1:  return "5.01";
case 5.5:  return "5.5";
case 5.6:
if ("XMLHttpRequest" in window) return "7.0";
return "6.0";
case 5.7:
return "7.0";
default:   return true;
}
}
if (@_win16 || @_win32 || @_win64) {
this.windows = true;
this.trident = jscriptVersion();
} else if (@_mac || navigator.platform.indexOf("Mac") >= 0) {
// '@_mac' may be 'NaN' even if the platform is Mac,
// so we check 'navigator.platform', too.
this.mac = true;
this.tasman = jscriptVersion();
}
if (match = ua.match("MSIE ?(\\d+\\.\\d+)b?;")) {
this.ie = match[1];
}
@else @*/

/* for AppleWebKit */
if (match = ua.match("AppleWebKit/(\\d+(\\.\\d+)*)")) {
this.applewebkit = match[1];
}

/* for Gecko */
else if (typeof(Components) == "object") {
if (match = ua.match("Gecko/(\\d{8})")) {
this.gecko = match[1];
} else if (navigator.product == "Gecko"
&& (match = navigator.productSub.match("^(\\d{8})$"))) {
this.gecko = match[1];
}
}

/*@end @*/

if (typeof(opera) == "object" && typeof(opera.version) == "function") {
this.opera = opera.version();
} else if (typeof(opera) == "object"
&& (match = ua.match("Opera[/ ](\\d+\\.\\d+)"))) {
this.opera = match[1];
} else if (this.ie) {
} else if (match = ua.match("Safari/(\\d+(\\.\\d+)*)")) {
this.safari = match[1];
} else if (match = ua.match("Konqueror/(\\d+(\\.\\d+)*)")) {
this.konqueror = match[1];
} else if (ua.indexOf("(compatible;") < 0
&& (match = ua.match("^Mozilla/(\\d+\\.\\d+)"))) {
this.mozilla = match[1];
if (match = ua.match("\\([^(]*rv:(\\d+(\\.\\d+)*).*?\\)"))
this.mozillarv = match[1];
if (match = ua.match("Firefox/(\\d+(\\.\\d+)*)")) {
this.firefox = match[1];
} else if (match = ua.match("Netscape\\d?/(\\d+(\\.\\d+)*)")) {
this.netscape = match[1];
}
} else {
this.unknown = true;
}

if (ua.indexOf("Win 9x 4.90") >= 0) {
this.windows = "ME";
} else if (match = ua.match("Win(dows)? ?(NT ?(\\d+\\.\\d+)?|\\d+|XP|ME|Vista)")) {
this.windows = match[2];
if (match[3]) {
this.winnt = match[3];
} else switch (match[2]) {
case "2000":   this.winnt = "5.0";  break;
case "XP":     this.winnt = "5.1";  break;
case "Vista":  this.winnt = "6.0";  break;
}
} else if (ua.indexOf("Mac") >= 0) {
this.mac = true;
} else if (ua.indexOf("Linux") >= 0) {
this.linux = true;
} else if (match = ua.match("\\w*BSD")) {
this.bsd = match[0];
} else if (ua.indexOf("SunOS") >= 0) {
this.sunos = true;
}
}

UAIdentifier.prototype.toString = function() {
var r = "";

if (this.opera) {
r += "Opera";
if (this.opera !== true)
r += ":" + this.opera;
} else if (this.ie) {
r += "IE";
if (this.ie !== this)
r += ":" + this.ie;
} else if (this.safari) {
r += "Safari:" + this.safari;
} else if (this.konqueror) {
r += "Konqueror:" + this.konqueror;
} else if (this.mozilla) {
r += "Mozilla";
if (this.mozilla !== true) {
r += ":" + this.mozilla;
if (this.mozillarv)
r += ":" + this.mozillarv;
}
if (this.firefox)
r += ",Firefox:" + this.firefox;
else if (this.netscape)
r += ",Netscape:" + this.netscape;
} else {
r += "Unknown";
}

if (this.trident) {
r += ",Trident";
if (this.iec !== true)
r += ":" + this.trident;
} else if (this.tasman) {
r += ",Tasman";
if (this.iec !== true)
r += ":" + this.tasman;
} else if (this.gecko) {
r += ",Gecko";
if (this.gecko !== true)
r += ":" + this.gecko;
} else if (this.applewebkit) {
r += ",AppleWebKit:" + this.applewebkit;
}

if (this.windows) {
r += ",Win";
if (this.winnt)
r += "NT:" + this.winnt;
else if (this.windows !== true)
r += ":" + this.windows;
} else if (this.mac) {
r += ",Mac";
} else if (this.linux) {
r += ",Linux";
} else if (this.bsd) {
r += "," + ((this.bsd === true) ? "BSD" : this.bsd);
} else if (this.sunos) {
r += ",Solaris";
}
return r;
};

