/* ---------------------------------------------------------*/
/* HTML読み込み完了時に実行させる処理 by hide    2007/12/19 */
/* ---------------------------------------------------------*/
dom.event.addEventListener(window, 'load', initDocument);
function initDocument() {
  var topInfo = document.getElementById('topInfo');
  loadText();
}

/* ---------------------------------------------------------*/
/* テキストファイルロード & 表示指示 */
/* ---------------------------------------------------------*/
function loadText() {
  /* ローディング中メッセージ */
  var topInfo = document.getElementById('topInfo');
  dom.core.removeChildNodes(topInfo);
  topInfo.appendChild( document.createTextNode('now loading...') );
  /* HTTPリクエスト送信 */
  var url = './data/data.txt';
  var oHttp = dom.ajax.httpGetRequest(url, printText);
  if( ! oHttp) {
    dom.core.removeChildNodes(topInfo);
    topInfo.appendChild( document.createTextNode('エラー') );
  }
}

/* ---------------------------------------------------------*/
/* 表示 */
/* ---------------------------------------------------------*/
function printText(oHttp) {
  var topInfo = document.getElementById('topInfo');
  dom.core.removeChildNodes(topInfo);
  /* HTTPレスポンスステータス 200(OK)? */
  if(oHttp.status == 200) {
    text = oHttp.responseText;
    text = text.replace(/\r\n|\r|\n/g,"<br>");
    var str = "<p>";
    str += text;
    str += "</p>";
	  topInfo.innerHTML = str;
/*    topInfo.appendChild( document.createTextNode(text) );*/
  } else {
    var msg = "エラー";
    msg += "[" + oHttp.status + ":" + oHttp.statusText + "]";
    topInfo.appendChild( document.createTextNode(msg) );
  }
}
