﻿/**
 * HTMLLoader
 *
 * サーバ上のHTMLファイルを特定のID内のInnerHTMLに展開する
 *
 * LICENSE: 
 *
 * @copyright  Copyright (c) 2009 SeedC,Inc. All Rights Reserved.
 * @license    
 * @version    
 * @link       
 * @since      
 */
 
 // HTTPオブジェクト
 var htmlloader_httpObject  = new Array();
 
 
 // WebからHTMLを読み込み特定のタグ内に埋め込む
 function htmlLoad( id, method, url, queryString) {
 
    htmlloader_httpObject[id] = Ajax.getTransport();
	htmlloader_httpObject[id].open(method, url, true);
	htmlloader_httpObject[id].onreadystatechange = function() {
	    if (htmlloader_httpObject[id].readyState == 4) {
            switch (htmlloader_httpObject[id].status)  {
				case 404:
                    alert('エラー: ' + url + 'が見つかりません。');
                    break;
				case 500:
					alert('エラー: ' + htmlloader_httpObject[id].responseText);
					break;
				default:					
					htmlCallback(id, htmlloader_httpObject[id].responseText);
				break;
			}
    	}
	}
    htmlloader_httpObject[id].setRequestHeader('Content-type','application/x-www-form-urlencoded');
	htmlloader_httpObject[id].setRequestHeader('Content-length', queryString.length);
	htmlloader_httpObject[id].setRequestHeader('Connection', 'close');
	htmlloader_httpObject[id].send(queryString);
}

// Htmlデータを特定タグ内に適用
function htmlCallback( id, htmlText) {
	if( $(id) == null)	return;
 	$(id).innerHTML = htmlText;
}


// イベントハンドラ追加（IE/FireFox対応 Ver）
function addEvent(obj, eventName,funcName,bFlag) {
	if(window.addEventListener) {
		obj.addEventListener(eventName,funcName,bFlag);
	}else{
		obj.attachEvent("on"+eventName,funcName);
	}
}