////cookie設定//////////////////////////////////////////////////////////////////////////////
function getCookie(){
	//text
	zoom = "";
	siteName = "kyotango-beText=";
	tmpCookie = document.cookie + ";";
	start = tmpCookie.indexOf(siteName);
	if (start != -1)
	{
		end = tmpCookie.indexOf(";", start);
		zoom = tmpCookie.substring(start + siteName.length, end);
		setFontSize(document.getElementsByTagName('body'),zoom);
		if(checkBrowser()=="ie6"){
			setFontSize(document.getElementsByTagName('th'),zoom);
			setFontSize(document.getElementsByTagName('td'),zoom);
			setFontSize(document.getElementsByTagName('caption'),zoom);
		}
	} else {
		//document.body.style.fontSize = "100%";
	}
	//color
	var p;
	pName = "kyotango-beColor=";
	tmpCookie = document.cookie + ";";
	start = tmpCookie.indexOf(pName);
	if (start != -1)
	{
		end = tmpCookie.indexOf(";", start);
		p = tmpCookie.substring(start + pName.length, end);
		changeCSS(p);
	}
}
////文字拡大・縮小//////////////////////////////////////////////////////////////////////////////
function setSize(s){
	siteName = "kyotango-beText=";
	exp = new Date();
	exp.setTime(exp.getTime() + 31536000000);
	document.cookie = siteName + s + "; path=/; expires=" + exp.toGMTString();
}
//
function textSizeUp(){
	var currentSize = "90%";
	var selectSize = "";
	currentSize = document.body.style.fontSize;
	if(!currentSize) currentSize = "90%";
	if ( currentSize=="90%"){
		selectSize = "110%";
	} else if(currentSize=="110%") {
		selectSize = "130%";
	} else if(currentSize=="130%") {
		alert("これ以上文字を拡大することはできません。");
		selectSize = "130%";
	} else {
		selectSize = "90%";
	}

	setFontSize(document.getElementsByTagName('body'),selectSize);
	if(checkBrowser()=="ie6"){
		setFontSize(document.getElementsByTagName('th'),selectSize);
		setFontSize(document.getElementsByTagName('td'),selectSize);
		setFontSize(document.getElementsByTagName('caption'),selectSize);
	}

	setSize(selectSize);
	return false;
}
//
function textSizeDown(){
	var currentSize = "90%";
	var selectSize = "";
	currentSize = document.body.style.fontSize;
	if(!currentSize) currentSize = "90%";
	if ( currentSize=="130%"){
		selectSize = "110%";
	} else if(currentSize=="110%") {
		selectSize = "90%";
	} else if(currentSize=="90%") {
		selectSize = "80%";
	} else if(currentSize=="80%") {
		alert("これ以上文字を縮小することはできません。");
		selectSize = "80%";
	} else {
		selectSize = "90%";
	}

	setFontSize(document.getElementsByTagName('body'),selectSize);
	if(checkBrowser()=="ie6"){
		setFontSize(document.getElementsByTagName('th'),selectSize);
		setFontSize(document.getElementsByTagName('td'),selectSize);
		setFontSize(document.getElementsByTagName('caption'),selectSize);
	}

	setSize(selectSize);
	return false;
}
//
function setFontSize(target,size){
	for(var i=0; i<target.length; i++){
		target[i].style.fontSize = size;	
	}
}

////色合いの変更　//////////////////////////////////////////////////////////////////////////////
var targetLINK  = "changecss";
var css_keyword = "color";
var dir_path = "/cms8341/kyotango-be/shared/style/color/";
//
function setColorCookie(s){
	siteName = "kyotango-beColor=";
	exp = new Date();
	exp.setTime(exp.getTime() + 31536000000);
	document.cookie = siteName + 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) return;
	if(!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 searchText(){
	if(!document.getElementById("query")) return;
	var obj = document.getElementById("query");
	obj.onfocus = function() {
		if(this.value == 'キーワードを入力') {
			this.value = '';
		}
	}
	obj.onblur=function() {
		if(this.value == '') {
			this.value = 'キーワードを入力';
		}
	}
}

//// onload //////////////////////////////////////////////////////////////////////////

window.onload = function() {
		getCookie();
		searchText();
}

function checkBrowser(){
	var uName = navigator.userAgent;
	if (uName.indexOf("MSIE 6.0") > -1)	return "ie6";
}
