function loadXMLFile(fName){
	httpObj = createXMLHttpRequest(displayData);
	if (httpObj){
		httpObj.open("GET",fName,true);
		httpObj.send(null);
	}
}
/* --------------------------------------------------- */
/*        トップページ　インフォメーション　           */
/* --------------------------------------------------- */
function displayData(){

	max_row = 5;          //表示する行数
	max_col = 24;         //最大文字数（日付は含まない）
	
	if ((httpObj.readyState == 4) && (httpObj.status == 200)){
		xmlData = httpObj.responseXML;

		entryListTags  = xmlData.getElementsByTagName("entry");

//		titleLen         = titleListTags.length; // 登録されているデータ数

		resultText = "<ul>";
		for(i=0; i<max_row; i++){
			node = entryListTags[i];
			title_value = "";
			pubdate_value = "";
			link_value = "";
			icontype = "";
			iconalt = "";
			srch = 0;
			items = node.childNodes;
			for (j = 0; j < items.length; j++) {
    			para = items[j];
				if(para.nodeName =="title"){    //タイトル
					title_value = para.firstChild.nodeValue;
					//タイトルで文字数が多いものはカットする。
//					if( title_value.length > max_col ){ 
//						title_value = title_value.substring(0,max_col) + "....";
//					}
				}
				if(para.nodeName =="published"){  //投稿日
					pubdate_value = reformat_date( para.firstChild.nodeValue );
				}
				if(para.nodeName =="link"){  //リンク
//					link_value = para.getNamedItem('href').nodeValue;
					link_value = para.getAttribute('href');
				}
				srch = link_value.indexOf("/karimokujp/info/",0);
				if(srch >= 0){
					icontype = "icon_info.gif";
					iconalt = "お知らせ";
				}else{
					icontype = "icon_event.gif";
					iconalt = "展示情報";
				}
			}
			resultText = resultText + "<li><dl>";
			resultText = resultText + "<dt>" + pubdate_value + "<img src='../images/common/" + icontype + "' alt='" + iconalt + "' />" + "</dt>";
			resultText = resultText + "<dd>" + "<a href='" + link_value + "'>" + title_value + "</a></dd>";
			resultText = resultText + "</dl></li>";
		}
		resultText = resultText + "</ul>";
		$("result").innerHTML = resultText;

	}else{

		$("result").innerHTML = "<b>Loading...</b>";

	}
}

/* --------------------------------------------------- */
/*        　　　　　　関　数　群　　　　　　           */
/* --------------------------------------------------- */

function reformat_date(base_date){
//  機能　　　　：2009-10-13T06:17:07Z   --> 2009.10.14に変換
//  　　　　　　：９時間加算して日を算出する。
/////////////////////////////////////////////////////////
	hiduke = "";

	if(base_date!=""){
		if(base_date.length == 20){
			hiduke = replace_all(base_date.substr(0,10),"-","/");
			jikoku = base_date.substr(11,8);
			
			hosei_hh = parseInt(jikoku.substr(0,2))+9;  //9時間加算
			if(hosei_hh >= 24){
				hiduke = DateAdd("d",1,hiduke,"yyyy/mm/dd")   //1日加算
			}
			hiduke = replace_all(hiduke,"/",".");
		}
	}

	return hiduke;
}

function DateAdd(flg,n,nDate,fmt){
//  機能　　　　：指定日の過去または未来の日を求める関数
//  関数名　　　：DateAdd()
//  引数　　　　：flg     "y","m","d"      加算単位（文字属性）
//  　　　　　　：n      ｎ日後またはｎ日前（数値属性）前の時は－値とする
//  　　　　　　：nDate  指定日（文字属性：yyyy/m/d or yyyy/mm/dd）
//	　　　　：fmt    戻り値の形式 "yyyy/m/d" "yyyy/mm/dd" "yyyymmdd"
//  戻り値　　　：日付形式（yyyy/m/d）
//
//  呼出例　　　：DatedAdd("d",100,"","yyyy/m/d")  当日の10日後の日付を求める
//  　　　　　　：DatedAdd("d",-25,"2003/1/20","yyyymmdd") 2003/1/20の25日前の日付を求める
//
//  2005/07/20 12月の月末を求める処理修正
//

	if (nDate == ""){
		var wDate = new Date();
	}else{
		var wymd = nDate.split("/");
		if (wymd[1].length == 1){wymd[1] = "0" + wymd[1]};
		if (wymd[2].length == 1){wymd[2] = "0" + wymd[2]};
		if (ValidDate(wymd[0] + "/" + wymd[1] + "/" + wymd[2])){
			var wDate = new Date(nDate);
		}else{
			return "<FONT COLOR='red'>日付形式エラー(" + nDate + ")</FONT>";
		}
	}
	if (isNaN(n)){
		return "<FONT COLOR='red'>加算数値エラー(" + n + ")</FONT>";
	}
	if (fmt == "yyyy/m/d" || fmt == "yyyy/mm/dd" || fmt == "yyyymmdd"){
		wfmt = fmt;
	}else{
		wfmt = "yyyy/m/d";
	}
	switch (flg.toLowerCase()){
		case "d":
			var wY = wDate.getFullYear();
			var wM = wDate.getMonth() + 1;
			var wD = wDate.getDate();
			return DateDAdd(n,wY + "/" + wM + "/" + wD,wfmt);
			break;
		
		case "m":
			var tYear = wDate.getFullYear();
			var tMonth = wDate.getMonth() + 1 + n;
			if (tMonth >= 13){ 
				var value = Math.floor(parseFloat(tMonth / 12));
				tYear += value;
				if(tMonth == value * 12){
					tYear -= 1;
					tMonth = 12;
				}else{
					tMonth -= (12 * value);
				}
			}else{
				if (tMonth <= 0) {
				var value = Math.ceil(parseFloat(tMonth / 12)) - 1;
				tYear += value;
				tMonth += (12 * Math.abs(value));
				}
			}
			var tDate = wDate.getDate();
			if (tMonth == 2){
				if (tDate > 28){
					return DateDAdd(-1,tYear + "/3/1",wfmt)  
				}else{
					if (wfmt == "yyyy/m/d"){
						return tYear + "/" + tMonth + "/" + tDate;
					}else{
						if (tMonth < 10){tMonth = "0" + tMonth};
						if (tDate < 10){tDate = "0" + tDate};
						if(wfmt == "yyyy/mm/dd"){
							return tYear + "/" + tMonth + "/" + tDate;
						}else{
							return tYear + "" + tMonth + "" + tDate;
						}
					}
				}
			}else{
				if (tMonth == 4 || tMonth == 6 || tMonth == 9 || tMonth == 11){
					if (tDate == 31){
						tDate = 30;
					}
				}else{
					if (tMonth >= 13){
						tYear += 1;
						tMonth -= 12;
					}
				}
				if (wfmt == "yyyy/m/d"){
					return (tYear + "/" + tMonth + "/" + tDate);
				}else{
					if (tMonth < 10){tMonth = "0" + tMonth};
					if (tDate < 10){tDate = "0" + tDate};
					if (wfmt == "yyyy/mm/dd"){
						return (tYear + "/" + tMonth + "/" + tDate);
					}else{
						return (tYear + "" + tMonth * "" + tDate);
					}
				}
			}
			break;
		
		case "y":
			var tYear = wDate.getFullYear()+n;
			var tMonth = wDate.getMonth()+1;
			var tDate = wDate.getDate();
			if (tMonth == 2){
				if (tDate > 28){
					return DateDAdd(-1,tYear + "/3/1",wfmt)  
				}else{
					if (wfmt == "yyyy/m/d"){
						return (tYear + "/" + tMonth + "/" + tDate);
					}else{
						if (tMonth < 10){tMonth = "0" + tMonth};
							if (tDate < 10){tDate = "0" + tDate};
							if (wfmt == "yyyy/mm/dd"){
								return (tYear + "/" + tMonth + "/" + tDate);
							}else{
								return (tYear + "" + tMonth + "" + tDate);
							}
						}
				}
			}else{
				if (wfmt == "yyyy/m/d"){
					return (tYear + "/" + tMonth + "/" + tDate);
				}else{
					if (tMonth < 10){tMonth = "0" + tMonth};
					if (tDate < 10){tDate = "0" + tDate};
					if (wfmt == "yyyy/mm/dd"){
						return (tYear + "/" + tMonth + "/" + tDate);
					}else{
					   	return (tYear + "" + tMonth + "" + tDate);
					}
				}
			}
			break;
		
		default:
			return "<FONT COLOR='red'>加算単位エラー（" + flg + ")</FONT>";
			break;
	}
}

function DateDAdd(n,nDate,fmt){
//  機能　　　　：指定日にｎ日を加算する
//  関数　　　　：DateDAdd()
//  引数　　　　：加算日数（過去日はマイナス数値)
//  　　　　　　：指定日(文字形式：yyyy/m/d or yyyy/mm/dd）
//	　　　　：fmt 戻り値の形式 "yyyy/m/d" "yyyy/mm/dd" "yyyymmdd"
//  戻り値　　　：加算日数した年月日(文字形式：yyyy/m/d）
//

	if (nDate == ""){
		var wDate = new Date();
	}else{
		var wymd = nDate.split("/");
		if (wymd[1].length == 1){wymd[1] = "0" + wymd[1]};
		if (wymd[2].length == 1){wymd[2] = "0" + wymd[2]};
		if (ValidDate(wymd[0] + "/" + wymd[1] + "/" + wymd[2])){
			var wDate = new Date(nDate);
		}else{
			return "<FONT COLOR='red'>日付形式エラー(" + nDate + ")</FONT>";
		}
	}
	if (fmt == "yyyy/m/d" || fmt == "yyyy/mm/dd" || fmt == "yyyymmdd"){
		wfmt = fmt;
	}else{
		wfmt = "yyyy/m/d";
	}

	var wdaysMS = n * 1000 * 60 * 60 * 24;
	var DateMS = wDate.getTime();
	DateMS += wdaysMS;
	wDate.setTime(DateMS);
	var tYear = wDate.getFullYear();
	var tMonth = wDate.getMonth() + 1;
	var tDate = wDate.getDate();

	if (wfmt == "yyyy/m/d"){
		return (tYear + "/" + tMonth + "/" + tDate);
	}else{
		if (tMonth < 10){tMonth = "0" + tMonth};
		if (tDate < 10){tDate = "0" + tDate};
		if (wfmt == "yyyy/mm/dd"){
			return (tYear + "/" + tMonth + "/" + tDate);
		}else{
			return (tYear + "" + tMonth + "" + tDate);
		}
	}
}

function ValidDate(dateStr) {
// Checks for the following valid date formats:
// YYYY/MM/DD

var datePat = /^(\d{4})(\/)(\d{2})\2(\d{2})$/;
var DateArray = dateStr.match(datePat);

	if (DateArray == null) {
		return false;
	}

	wyear = dateStr.substr(0,4);
	wmonth = eval(dateStr.substr(5,2));
	wday = eval(dateStr.substr(8,2));

	if (mon_chk(wmonth)){
	}else{
		return false;
	}

	dd = daymonth(wyear,wmonth);
	if (wday > dd){
		return false;
	}
    
	return true;
}

/* 日付の範囲チェック */
function daymonth(year,month){
	day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if(month==2 && leapyear(year)) return 29;
	return day[month-1];
}
/* うるう年のチェック */
function leapyear(year){
	return year%4==0 && (year%100!=0 || year%400==0);
}

/* 月の範囲チェック */
function mon_chk(month){	
	if((month >= 1) && (month <= 12)) return true;
	return false;
}


/*  文字列置換  */
function replace_all(str,key,rstr){
  while(str.indexOf(key,0)!=-1){
     str=str.replace(key,rstr);
  }
  return str;
}

