
var ServerConnector = function() {}

ServerConnector.prototype.createXmlHttpObject = 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;
}

ServerConnector.prototype.sendCommand = function(url, params, callBackFunction, isPost)
{
	var xmlHttp = this.createXmlHttpObject();
	if (!xmlHttp) {
		return;
	}
	
	if ('boolean' != typeof(isPost)) {
		isPost = false;
	}
		
	var sendUrl = url;
	
	var param = 'ajax=1';
	if (params) {
		for (key in params) {
			var val = params[key];
			if (true == isPost) {
				val = encodeURIComponent(val);
			}
			param = param + '&' + key + '=' + val;
		}
	}

	var method = 'GET';
	var paramData = null;
	if (true == isPost) {
		method = 'POST';
		paramData = param;
	} else {
		sendUrl = sendUrl + '?' + param;
	}

	xmlHttp.open(method, sendUrl, true);
	
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			if ((xmlHttp.status != 200 && xmlHttp.status != 304 ) || xmlHttp.responseXML == null) {
				// エラー時処理記述
		//		window.location.replace( SYSTEM_URL + '/common/system_error.php' );
		//		return;
			}
			
			
			var httpResponse = new Object();
			httpResponse.Xml = xmlHttp.responseXML;
			httpResponse.Text = xmlHttp.responseText;

			if ("function" == typeof(callBackFunction)) {
				callBackFunction(httpResponse);
			}
		}
	}

	xmlHttp.send(paramData);
}

