// JavaScript Document

function loadXMLFile(fName,topicNum){
	
	topicLength = topicNum;
	var cacheTime=(new Date()).getTime();
	fName=fName+"?cachetime="+cacheTime;
	httpObj = createXMLHttpRequest();
	if (httpObj){
		httpObj.onreadystatechange = displayData;
		httpObj.open("GET",fName,true);
		httpObj.send(null);
	}
}

function displayData(){
	if ((httpObj.readyState == 4) && (httpObj.status == 200)){
		xmlData = httpObj.responseXML;
		itemListTags = xmlData.getElementsByTagName("item");
		titleListTags = xmlData.getElementsByTagName("title");
		linkListTags = xmlData.getElementsByTagName("link");
		dateListTags = xmlData.getElementsByTagName("pubDate");
		descListTags = xmlData.getElementsByTagName("description");
		
		if(!topicLength){//ロードするnewsの数
			topicLength = itemListTags.length;
		}else if(topicLength>itemListTags.length){
			topicLength = itemListTags.length;
		}
				
		resultText = "" ;//表示するデータ
	
		for(i=1; i<topicLength+1; i++){
			stitle = titleListTags[i].childNodes[0].nodeValue;
			sLink = linkListTags[i].childNodes[0].nodeValue;
			sdate = dateListTags[i].childNodes[0].nodeValue;
			sdesc = descListTags[i].childNodes[0].nodeValue;
			
			resultText = resultText + "<li><a href='"+sLink+"' title='"+ stitle + "'>" + stitle +"</a><span class='date'>["+sdate+ "]</span></li><li class='newsbody'>"+sdesc+"</li>";
		}
		$("news").innerHTML = "<ul>"+resultText+"</ul>";
	}else{
		$("news").innerHTML = "<p class='center'><img src='http://www.matecland.jp/jscript/loading/loader_f.gif' alt='loading...' /></p>";
		}
	}

/*本文を開く・閉じるファンクション*/
function openNews(Num){
	var target ="desc"+Num;
	$(target).innerHTML = descListTags[Num].childNodes[0].nodeValue+"<p class='close'><a href='javascript:closeThis("+Num+");' title='閉じる'>×閉じる</a></p> ";
	$(target).style.display="block";
}
function closeThis(Num){
	var target ="desc"+Num;
	$(target).innerHTML = "";
	$(target).style.display="none";
}
	

