﻿// HTTP通信用、共通関数
function createXMLHttpRequest(cbFunc)
{
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
	return XMLhttpObject;
}

// document.getElementById
function $(tagId)
{
	return document.getElementById(tagId);
}

// Title専用
function tloadDataFile(fName1)
{
	httpObj1 = createXMLHttpRequest(displayData1);
	if (httpObj1)
	{
		httpObj1.open("GET",fName1,true);
		httpObj1.send(null);
	}
	return false;
}

// 汎用
function loadDataFile(fName1,fName2)
{
	httpObj1 = createXMLHttpRequest(displayData1);
	if (httpObj1)
	{
		httpObj1.open("GET",fName1,true);
		httpObj1.send(null);
	}
	httpObj2 = createXMLHttpRequest(displayData2);
	if (httpObj2)
	{
		httpObj2.open("GET",fName2,true);
		httpObj2.send(null);
	}
	return false;
}

// メニュー用
function displayData1()
{
	if ((httpObj1.readyState == 4) && (httpObj1.status == 200))
	{
		$("remenu").innerHTML = parseTabText(httpObj1.responseText);
	}else{
		$("remenu").innerHTML = "<b>Loading...</b>";
	}
}

// 内容用
function displayData2()
{
	if ((httpObj2.readyState == 4) && (httpObj2.status == 200))
	{
		$("result").innerHTML = parseTabText(httpObj2.responseText);
	}else{
		$("result").innerHTML = "<b>Loading...</b>";
	}
}

// HTMLファイルを解析して表示
function parseTabText(tabText)
{
	var resultText = "";
	var CR = String.fromCharCode(13)+String.fromCharCode(10);	// 改行コード (CR+LF)
	lineData = tabText.split(CR);
	for (var i=0; i<lineData.length; i++)
	{
		resultText += lineData[i];
	}
	resultText += "";
	return resultText;
}

function Display(id){
	if(document.all){
		if(document.all.item(id).style.display == "block"){
			document.all.item(id).style.display = "none";
		}else if(document.all.item(id).style.display == "none"){
			document.all.item(id).style.display = "block";
		}
	}else if(document.getElementById){
		if(document.getElementById(id).style.display == "block"){
			document.getElementById(id).style.display = "none";
		}else if(document.getElementById(id).style.display == "none"){
			document.getElementById(id).style.display = "block";
		}
	}
}
