//XMLHttpRequestオブジェクト生成
//createHttpRequest()
//
// @returns XMLHttpRequestオブジェクト またはnull

function createHttpRequest(){
	if(window.ActiveXObject){
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e2){
				return null;
			}
		 }
	}else if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	}else{
		return null;
	}
}

//		 requestFile( callback , count,  data , method , fileURL , async )

//		 @param callback 受信時に起動する関数名
//		 @param data	 送信するデータ
//		 @param method "POST" or "GET"
//		 @param fileURLリクエストするファイルのURL
//		 @param async	Asyncならtrue Syncならfalse
//		 --@param user A username for authentication if necessary.
//		 --@param password A password for authentication if necessary.
//		 パスワード等はとりあえず省略

function requestFile( callback , count , data , method , fileURL , async ){
	if(fileURL.slice(-4) == ".php" || fileURL.slice(-4) == ".PHP"){		//	PHP の POST は'name'属性が必須
		data = "&test=" + data;															//	送信する data に name 属性(='test')を付与する。
	};

	//--------------------------	XMLHttpRequestオブジェクト生成
	var oj = createHttpRequest()
	if( oj == null ) return null

	//--------------------------	ブラウザ判定-->別関数にした方がすっきりする？
	var ua = navigator.userAgent
	var safari	= ua.indexOf("Safari")!=-1
	var konqueror = ua.indexOf("Konqueror")!=-1
	var mozes	 = ((a=navigator.userAgent.split("Gecko/")[1] )?a.split(" ")[0]:0) >= 20011128 

	//--------------------------	Konquerorはonloadが不安定http://jsgt.org/ajax/ref/test/response/responsetext/try1.php
	if(window.opera || safari || mozes){
		oj.onload = function () { callback(oj , count ) }
	}else{
		oj.onreadystatechange =function (){
			if ( oj.readyState == 4 ){
				callback(oj , count )
			}
		}
	}

	//--------------------------	open メソッド
	oj.open( method , fileURL , async )

	if(method == 'POST'){
	//	if(!window.opera){	//	このメソッドがWin Opera8でエラーになったので、とりあえず分岐2005.5.20
			oj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
	//	}
	}

	//--------------------------	send メソッド
	oj.send(data);

}

