// AJax Sample
//window.onload = function() {
//	var httpObj = new HttpRequest();
//	httpObj.send("http://www.triumphspaces.jp/", function(responseText) {
//		var element = document.getElementById("p");	
//		element.innerHTML = responseText;
//	}, true);
//}

//
// HttpRequestクラス
//

// コンストラクタ
var HttpRequest = function() {
	this._httpObj = this.create();
};

// プロトタイプ
HttpRequest.prototype = {
	// XMLHttpRequestオブジェクト生成
	create: function() {
		try {
			if (window.XMLHttpRequest) {
				return new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				try {
					return new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					return new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
		} catch (e) {
			return null;
		}
		return null;
	},

	// Request送信
	send: function(method, target, listener, async) {
		var obj = this._httpObj;
		var postData = target.split("?")[1];
		obj.open(method, target, async);
		obj.onreadystatechange = function() {
			if (obj.readyState == 4 && obj.status == 200) {
				listener(obj.responseText);
			}
		}

		if ("POST" == method) {
			obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			obj.send(postData);
		} else {
			obj.send(null);
		}
	}
};


