/* 目次関連のスクリプト */
/* All Rights Reserved,Copyright(C) FUJITSU LIMITED 2007 */

/* ---------------------------目次の折りたたみ--------------------------- */

function change(e){

	var source=document.getElementById&&!document.all? e.target:event.srcElement;

	if (source.className=="bullet_folding1"){
		var source2=document.getElementById&&!document.all? source.parentNode.parentNode.childNodes:source.parentElement.parentElement.all;
		level1(source2);
	}

	if (source.className=="bullet_folding2"){
		var source2=document.getElementById&&!document.all? source.parentNode.childNodes:source.parentElement.all;
		level2(source2);
	}

	if(source.className=="allopen" || source.className=="allclose"){
		if (source.className=="allopen"){
			source.firstChild.nodeValue="目次を折りたたむ";
			source.className="allclose";
			var cState=getCookie();
			var cState2="";
			var objDiv=document.getElementsByTagName("div");
			for(var i=0;i<objDiv.length;i++){
				if(objDiv[i].className=="toclevel2fold" || objDiv[i].className=="toclevel3fold"){
					var idValue=objDiv[i].id;
					for(var j=0;j<cState.length;j++){
						cState2+="0";
					}
					var idNum=idValue.substring(1,3);
					var cArray=cState2.match(/[01]/g);
					objDiv[i].style.display=(cArray[idNum]=="0")?"block":"none";
					objDiv[i].parentNode.childNodes[0].src=(cArray[idNum]=="0")?"images/bullet_open.gif":"images/bullet_fold.gif";
				}
			}
			cState2="";
			for(var k=0;k<cState.length;k++){
				cState2+="1";
			}
			setCookie(cState2);
		}

		else if (source.className=="allclose"){
			source.firstChild.nodeValue="目次をすべて展開";
			source.className="allopen";

			var cState=getCookie();
			var cState2="";
			var objDiv=document.getElementsByTagName("div");
			for(var i=0;i<objDiv.length;i++){
				if(objDiv[i].className=="toclevel2fold" || objDiv[i].className=="toclevel3fold"){
					var idValue=objDiv[i].id;
					for(var j=0;j<cState.length;j++){
						cState2+="1";
					}
					var idNum=idValue.substring(1,3);
					var cArray=cState2.match(/[01]/g);
					objDiv[i].style.display=(cArray[idNum]=="0")?"block":"none";
					objDiv[i].parentNode.childNodes[0].src=(cArray[idNum]=="0")?"images/bullet_open.gif":"images/bullet_fold.gif";
				}
			}
			cState2="";
			for(var k=0;k<cState.length;k++){
				cState2+="0";
			}
			setCookie(cState2);
		}
	}

}

function level1(src){
	if (src[0].childNodes[2].className=="toclevel2fold"){
		var idValue=src[0].childNodes[2].id;
		var cState=getCookie();
		var idNum=idValue.substring(1,3);
		var cArray=cState.match(/[01]/g);
		src[0].childNodes[2].style.display=(cArray[idNum]=="0")?"block":"none";
		src[0].childNodes[0].src=(cArray[idNum]=="0")?"images/bullet_open.gif":"images/bullet_fold.gif";
	}


	cArray[idNum]=""+((eval(cArray[idNum]))^1);
	cState="";
	for(i=0;i<cArray.length;i++){
		cState+=cArray[i];
	}
	setCookie(cState);
}

function level2(src){
	if (src[0].parentNode.childNodes[2].className=="toclevel3fold"){
		var idValue=src[0].parentNode.childNodes[2].id;
		var cState=getCookie();
		var idNum=idValue.substring(1,3);
		var cArray=cState.match(/[01]/g);

		src[0].parentNode.childNodes[2].style.display=(cArray[idNum]=="0")?"block":"none";
		src[0].parentNode.childNodes[0].src=(cArray[idNum]=="0")?"images/bullet_open.gif":"images/bullet_fold.gif";
		cArray[idNum]=""+((eval(cArray[idNum]))^1);
		cState="";
		for(i=0;i<cArray.length;i++){
			cState+=cArray[i];
	}
	setCookie(cState);
}
}

function init(){
	setFont();
	var idNum=-1;
	var objDiv=document.getElementsByTagName("div");
	for(i=0;i<objDiv.length;i++){
		if(objDiv[i].className.match("toclevel2|toclevel3") && !objDiv[i].className.match("single")){
			idNum++;
			objDiv[i].setAttribute("id","c"+idNum);
		}
	}
	var cState=getCookie();
	var allopen="";
	var allclose="";
	for(j=0;j<cState.length;j++){
		allopen+=1;
		allclose+=0;
	}
	if(cState==allopen){
		document.all?document.all('allopenclose').children[0].firstChild.nodeValue="目次を折りたたむ":document.getElementById('allopenclose').childNodes[1].firstChild.nodeValue="目次を折りたたむ";
		document.all?document.all('allopenclose').children[0].className="allclose":document.getElementById('allopenclose').childNodes[1].className="allclose";
	}
	else if(cState==allclose){
		document.all?document.all('allopenclose').children[0].firstChild.nodeValue="目次をすべて展開":document.getElementById('allopenclose').childNodes[1].firstChild.nodeValue="目次をすべて展開";
		document.all?document.all('allopenclose').children[0].className="allopen":document.getElementById('allopenclose').childNodes[1].className="allopen";
	}
	var cArray=cState.match(/[01]/g);
	var cSettedDiv;
	for(i=0;i<cArray.length;i++){
		cSettedDiv=(document.all)?document.all('c'+i):((document.getElementById)?document.getElementById('c'+i):null);
		if(cSettedDiv){
			cSettedDiv.style.display=(cArray[i]=="0")?"none":"block";
			var objLi=document.getElementById&&!document.all? cSettedDiv.parentNode:cSettedDiv.parentElement;
			objLi.childNodes[0].src=(cArray[i]=="0")?"images/bullet_fold.gif":"images/bullet_open.gif";
		}
	}
	setTimeout('CurrentTitle()',2000)
}

function getCookie(){
	var allCloseState="";
	var objDiv=document.getElementsByTagName("div");
	for(i=0;i<objDiv.length;i++){
		if(objDiv[i].className.match("toclevel2|toclevel3")){
			allCloseState+="0";
		}
	}

	var tocCookie=document.cookie;
	if(tocCookie.length==0){
		return allCloseState;
	}
	
	if(tocCookie.length!=0){
		var cookie=tocCookie.split("=");
		cValue=cookie[1];
		return unescape(cValue);
	}
}

function setCookie(cValue){
	var cLife=new Date();
	cLife.setTime(cLife.getTime()+(1*24*60*60*1000));
	document.cookie="display="+escape(cValue)+"; expires="+cLife.toGMTString();
}


/* ---------------------------本文タイトルと同期--------------------------- */
function CurrentTitle(){
	var objUserAgent=navigator.userAgent;
	if(objUserAgent.indexOf("MSIE 6.") != -1 || objUserAgent.indexOf("MSIE 7.") != -1){
		var intBrowserName=1;
	}
	else if(objUserAgent.indexOf("Gecko/") != -1){
		if(objUserAgent.indexOf("Netscape6/6.")!= -1){
			var intBrowserName=3;
		}
		else{
			var intBrowserName=2;
		}
	}
	else{
		var intBrowserName=3;
	}

	if(intBrowserName!=3){
		if(parent.main){
			var intTocAlength=document.getElementsByTagName("a").length-1;
			for (i=0;i<intTocAlength;i++){
				var objTocA=document.getElementsByTagName("a")[i];
				if(objTocA.style.backgroundColor="#FFFFCC"){
					objTocA.style.backgroundColor="";
				}
			}
			if(intBrowserName==1){
				var strAname=parent.main.document.childNodes[1].childNodes[0].childNodes[4].content;
			}
			if(intBrowserName==2){
				var strAname=parent.main.document.childNodes[1].childNodes[0].childNodes[7].content;
			}
			for(i=0;i<intTocAlength;i++){
				var charForSlash=new RegExp("/","gi");
				var charForSharp=new RegExp("#","gi");
				var objTocA=document.getElementsByTagName("a")[i];
				if(objTocA.href){
					var strTocAhref=objTocA.getAttribute("href");
					if(intBrowserName==1){
						var result=strTocAhref.match(charForSlash);
						var strTocAhref2=RegExp.rightContext;
						if(charForSharp.test(strTocAhref2)){
							var result=strTocAhref2.match(charForSharp);
							var strTocAhref2=RegExp.leftContext;
						}
					}
					if(intBrowserName==2){
						if(charForSharp.test(strTocAhref)){
							var result=strTocAhref.match(charForSharp);
							var strTocAhref2=RegExp.leftContext;
						}
						else{
							var strTocAhref2=strTocAhref;
						}
					}
					if(strAname==strTocAhref2){
						objTocA.style.backgroundColor="#FFFFCC";
						break;
					}
				}
			}
		}
	}
	else return false;
}

