	//ＵＴＦ－８
	if (typeof window.XMLHttpRequest == "undefined") {
		if (typeof window.ActiveXObject == "function") {
			try {
				new ActiveXObject("Msxml2.XMLHTTP");
				window.XMLHttpRequest = function(){
					return new ActiveXObject("Msxml2.XMLHTTP");
				}
			} catch (e) {
				try {
					new ActiveXObject("Microsoft.XMLHTTP");
					window.XMLHttpRequest = function(){
						return new ActiveXObject("Microsoft.XMLHTTP");
					}
				} catch (e) {
				}
			}
		}
	} else {
	}

	function AjaxClient(instanceName) {
		this.instanceName   = instanceName;
		this.gateway    = '';
		this.method     ='POST';
		//this.XMLHttpRequest = getXMLHttpRequest();
		this.lastCall   = {command: undefined, args: undefined, callback: undefined, errorHandler: undefined, debug: undefined};
	}

	AjaxClient.prototype.encodes = function(obj) {
		
		for(var i in obj){
			if (isNaN(obj[i])) {
				if(typeof obj[i] == 'object'){
					obj[i] = this.encodes(obj[i]);
				}else if(typeof obj[i] == 'string'){
					obj[i] = this.encodeURL(obj[i]);
				}
			}
		}
		return obj;
	}

	AjaxClient.prototype.call = function(command, args, callback, errorHandler, debug) {
		this.lastCall.command      = command;
		this.lastCall.args         = args;
		this.lastCall.callback     = callback;
		this.lastCall.errorHandler = errorHandler;
		this.lastCall.debug        = debug;
		/* 090325 kaneko
		for(var i in args){
			if (isNaN(args[i])) {
				args[i] = this.encodeURL(args[i]);
			}
		}
		*/
		args = this.encodes(args);
		
		var lastCall = this.lastCall;
		var sendStr = "";
		sendStr += 'command=' + command;
		sendStr += '&';
		sendStr += 'args=' + encodeURIComponent(serialize(args));
		sendStr += '&';
		sendStr += 'callback=' + callback;
		var xmlhttp = new XMLHttpRequest();
		if (xmlhttp) {
			try {
			    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
			} catch (e) {
			    //alert("Permission UniversalBrowserRead denied.");
			}
			xmlhttp.open(this.method, this.gateway, true);
			xmlhttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
			xmlhttp.send(sendStr);
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4){
					if(xmlhttp.status == 200) {
						//debug
						if(lastCall.debug) alert('-- Ajax Debugger --\nServer Response(limit '+lastCall.debug+' chars):\n\n'+xmlhttp.responseText.substring(0, lastCall.debug));
						eval(xmlhttp.responseText);
					}else{
						if(lastCall.errorHandler) eval(lastCall.errorHandler+'(lastCall.args);');
						else alert('-- Ajax Debugger --\nError occured: '+xmlhttp.status+': '+xmlhttp.statusText);
					}
					return;
				}
			};
		}
	}

/*----encode----*/
	AjaxClient.prototype.encodeURL = function(str){
	    var s0, i, s, u;
	    s0 = "";                // encoded str
	    for (i = 0; i < str.length; i++){   // scan the source
	        s = str.charAt(i);
	        u = str.charCodeAt(i);          // get unicode of the char
	        if (s == " "){s0 += "+";}       // SP should be converted to "+"
	        else {
	            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){     // check for escape
	                s0 = s0 + s;           // don't escape
	            }
	            else {                      // escape
	                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
	                    s = "0"+u.toString(16);
	                    s0 += "%"+ s.substr(s.length-2);
	                }
	                else if (u > 0x1fffff){     // quaternary byte format (extended)
	                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
	                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
	                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
	                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
	                }
	                else if (u > 0x7ff){        // triple byte format
	                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
	                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
	                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
	                }
	                else {                      // double byte format
	                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
	                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
	                }
	            }
	        }
	    }
	    return s0;
	}
/*----encode----*/
