//-----------------------------------------------------------
// COMMON JAVASCRIPT FILE
//-----------------------------------------------------------

//*************** Cookie **************
function readCookie(name){
	var cookieValue = "";
	var val;
	var clist = document.cookie.split(';');
	for(var i=0; i<clist.length;i++){
		val = clist[i].split('=');
		if(val[0].replace(/\s/g, "") == name) cookieValue = val[1];
	}
  return cookieValue;
}
function writeCookie(name, value) {
	var today = new Date();
	yy = today.getYear();
	if (yy < 2000) { yy += 1900; }
	var expDate = new Date(yy+15, today.getMonth()+1,1,0,0,0,0); // modified 2007.4.27
	expDate.setTime(expDate.getTime() - 1000);	// end of mont 2007.03.05
	expDate = "; expires=" + expDate.toGMTString();
	document.cookie = name + "=" + escape(value) + expDate + "; path=/";
}

//*************** FONT SIZE CHANGE **************
// parameter Set
//var host = "/";
//var css_dir = host + "css/";
//var img_dir = host + "img/";

var css_dir = "/css/";
var img_dir = "/img/";

// button Img Off
font_btn_img_off	= new Array("font01.gif","font02.gif","font03.gif");
font_btn_img_on		= new Array("font01o.gif","font02o.gif","font03o.gif");
font_btn_txt		= new Array("小さい","通常","大きい");

//---# Font First Setting
//---# default txtsize = 1
var fontcssMax = 2;
var txtsize = eval(readCookie("t-size"));
if(!txtsize && txtsize != 0) txtsize = 1;
var cssrel;
for (var i=0;i<=fontcssMax;i++){
	if(i==txtsize) cssrel = "stylesheet";else cssrel = "alternate stylesheet";
	document.write ('<link rel="' +cssrel+ '" type="text/css" href="' +css_dir+ 'txtsize' +i+ '.css"  title="txtsize' +i+ '" />');
}
//---# Font Change Btn Html Tag
function setTxtSizeBtn(){
	document.write('<span id="Design_textsize">');
	document.write(getTxtSizeBtnTxt());
	document.write('</span>');
}
//---# Font Change Btn Html Txt
//---# Call setTxtSizeBtn()
function getTxtSizeBtnTxt(){
	var txt = "";
	for(var i=0;fontcssMax>=i; i++) {
		var img_src = (i ==  txtsize) ? font_btn_img_on[i]:font_btn_img_off[i];
		txt += '<a href="javascript:void(0);" onclick="setTxtSize('+i+')">';
		txt += '<img src="'+img_dir+img_src+'" alt="'+font_btn_txt[i]+'" width="16" height="16">';
		txt += '</a>';
	}
	return txt;
}

//---# Font Set Function
//---# num = fontsize(0-MAX)
function setTxtSize(num){
	txtsize = num;
	if(txtsize < 0) {txtsize=0;}
	if(txtsize > fontcssMax) {txtsize=fontcssMax;}
	writeCookie("t-size", txtsize);
	var i,a;
	for(var i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == "txtsize" + txtsize) a.disabled = false;
		}
	}
	//$("Design_textsize").innerHTML = getTxtSizeBtnTxt();
	//--- write
	var txtId = "Design_textsize";
	if(document.all){ 
		document.all(txtId).innerHTML = getTxtSizeBtnTxt();
	} else if (document.getElementById) {
		document.getElementById(txtId).innerHTML = getTxtSizeBtnTxt();
	} else if (document.layers) {
		with(document.layers[txtId]){ //with
			document.open();
			document.write(getTxtSizeBtnTxt());
			document.close();
		} 
	}
}
