<!--
//+----------------------------------------------------------------------------------------+
//|                                                                                        |
//|################################## AccessServer.js #####################################|
//|                                                                                        |
//|                                           非同期通信ユーティリティー.                         |
//|                                           'GET'データは url に付加して送る.                  |
//|                                           'POST': データは send() の引数に渡す.             |
//|                                                                                        |
//|                                                            created：2007-06-30          |
//|                                                            author ：g.shirazawa         |
//+----------------------------------------------------------------------------------------+

var AccessServer = {

	/**
	 * HTTP通信オブジェクトを作成、返します
	 * @param method   String ⇒ POST | GET
	 * @param url      String ⇒ URL
	 * @param operator Method ⇒ 送受信状態変換時処理メソッド
	 */
	accessDefault: function(method, url, operator) {
		this.access(method, url, null, true, operator);
	},
	
	/**
	 * HTTP通信オブジェクトを作成、返します
	 * @param method   String ⇒ POST | GET
	 * @param url      String ⇒ URL
	 * @param data     String ⇒ サーバー側に渡すデータ
	 * @param operator Method ⇒ 送受信状態変換時処理メソッド
	 */
	accessSendData: function(method, url, data, operator) {
		this.access(method, url, data, true, operator);
	},
	
	/**
	 * HTTP通信オブジェクトを作成、返します
	 * @param method   String  ⇒ POST | GET
	 * @param url      String  ⇒ URL
	 * @param async    boolean ⇒ 非同期通信するか？
	 * @param operator Method  ⇒ 送受信状態変換時処理メソッド
	 */
	accessChoiceSync: function(method, url, async, operator) {
		this.access(method, url, null, async, operator);
	},
	
	/**
	 * HTTP通信オブジェクトを作成、返します
	 * @param method   String  ⇒ POST | GET
	 * @param url      String  ⇒ URL
	 * @param data     String  ⇒ サーバー側に渡すデータ
	 * @param async    boolean ⇒ 非同期通信するか？
	 * @param operator Method  ⇒ 送受信状態変換時処理メソッド
	 */
	access: function(method, url, data, async, operator) {
		httpObj = this.createXMLHttpRequest();
		
		if (httpObj) {
			// onreadystatechange ⇒ 送受信状態が変った時に起動するイベント
			httpObj.onreadystatechange = operator;
		
			// 通信開始
			httpObj.open(method, url, async);
			
			// POST データ送信時は文字コード設定が必須(Ajax では UTF-8 しか扱えない)
			if (method == "POST") {
				httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
			}
			
			// データ送信
			httpObj.send(data);
		}
	},
	
	/**
	 * HTTP通信オブジェクトを作成、返します
	 */
	createXMLHttpRequest: function() {
		var XMLhttpObject = null;
		try{
			XMLhttpObject = new XMLHttpRequest();
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e){
					return null;
				}
			}
		}
		return XMLhttpObject;
	}
}
// -->
