
function oxc_RPC(){ // Synchronous JavaScript and XML
	this.returnType = false; // false, header, text, body, xml, status, statusText
	this.utf8Sign = true; // force get method using encodeURI with "&rpcCharset=utf8"
    this.httpConnect=function(){
        var http;
		try {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			try {
				http  = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try {
					http = new XMLHttpRequest();
				}catch(e){
					http = false;
				}
			}
		}
		return http;
	}
	this.http = this.httpConnect();
	
	this.returnValue = function(type){
		if (type=='header') return this.http.getAllResponseHeaders();// header as string
		else if (type=='text') return this.http.responseText; // string
		else if (type=='xml') return this.http.responseXML; // XML DOM object
		else if (type=='body') return this.http.responseBody; // unsined bytes array
		else if (type=='status') return this.http.status; // 200 is ok
		else if (type=='statusText') return this.http.statusText; // 'OK' is ok
		else return '';// void
	}
	this.httpGet=function(url){ // string url
		if (this.utf8Sign) {
			if (url.match(/\?/)=='?') url += '&rpcCharset=utf8';
			else url += '?rpcCharset=utf8';
			url = encodeURI(url);
		}
		this.http.open("GET", url,false);
		this.http.setRequestHeader("Content-Type", "text/xml");
        //this.http.setRequestHeader("Cache-Control", "no-cache, must-revalidate");
        //this.http.setRequestHeader("Pragma","no-cache");
        //this.http.setRequestHeader("Expires","0");

		this.http.send(null);
		return this.returnValue(this.returnType);
	}
	this.httpPost = function(url,data){ // string url, string or object data
        var oData = new String();
		if (this.utf8Sign) {
			if (url.match(/\?/)=='?') url += '&rpcCharset=utf8';
			else url += '?rpcCharset=utf8';
			url = encodeURI(url);
		}
		this.http.open("POST", url,false);
		this.http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");// "EUC-KR"); 
        if (typeof(data)=='object') {
            for (var x in data) oData +=(oData.length>0 ? '&':'')+ encodeURIComponent(x)+'='+encodeURIComponent(data[x]);
        }else {
            oData = encodeURI(data);
        }        
		this.http.send(oData);
		return this.returnValue(this.returnType);
	}
	this.text2xml = function(data) {
		var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(data);
		return xmlDoc.documentElement;
	}
	this.xml2obj = function(obj){
		var child = obj.childNodes;
		var i = 0;
		var tmp = new Object(),tmp2;
		var val, val2;
		while (i < child.length) {
			val = child(i);
			if (val.nodeName.toLowerCase()=='#text') return val.text;
			else  val2=this.xml2obj(val);

			if (tmp.hasOwnProperty(val.nodeName)) {
				if (tmp[val.nodeName] instanceof Array) tmp[val.nodeName][tmp[val.nodeName].length] = val2;
				else tmp[val.nodeName] = new Array(tmp[val.nodeName],val2);
			}else {
				tmp[val.nodeName] = val2;
			}
			i++;
		}
		return tmp;
	}
    this.code2obj = function(objCode) {
        var newObj;
        try{
            eval('newObj = '+objCode+';');
            return newObj;
        }catch(e){
            return false;
        }
    }
	this.obj2code = function(obj) {
		var buf = '',childType='';
		for (child in obj) {
            childType = (obj[child]===null) ? 'null' : typeof(obj[child]);
            if (childType=='function') continue;
            buf += '"'+child +'":';  
			if (childType=='string') buf += '"'+this.escapeChar(obj[child].toString())+'"';
			else if (childType=='number') buf += this.escapeChar(obj[child].toString());
            else if (childType=='boolean') buf += this.escapeChar(obj[child].toString());
            else if (childType=='null') buf += 'null';
            else buf += this.obj2code(obj[child]); // object
			buf += ",";
		}

		if (buf.length > 0) buf = buf.substr(0,buf.length-1);
		return '{'+buf+'}';
	}
	this.obj2phpArray = function(obj,keyName) {// keyName must begin with '&'
		var buf = '',key='';
		for (child in obj) {
			key = "&["+child.toString() +"]";
			if (typeof(obj[child])!='object') buf += key+"="+  this.eqaulAND(obj[child].toString());
			//else buf += this.changeAND(this.obj2phpArray(obj[child]),key);
			else buf += this.obj2phpArray(obj[child],key);
			
		}    
		
		return this.changeAND(buf,keyName);
	}
/*
	this.obj2xml = function(obj){ // convert to XML DOM object
		return text2xml(obj2xmlText(obj));
	}
	this.obj2xmlText = function(obj,name) { // conver to XML text : obj(object) , name(objectName)
		var buf = '';
		if (typeof(obj)!='object') return obj;
		for (child in obj) {
			buf += '<'+name.toString() +'>';
			if (typeof(obj[child])!='object') buf += '<'+child.toString()+'>'+ this.escapeChar(obj[child].toString()) +'</'+child.toString()+'>';
			else buf += this.obj2xmlText(obj[child],child.toString());
			buf += '</'+name.toString() +'>';
		} 
		return buf;
	}
*/
	this.escapeChar = function(objV){
	/*  \\  \"  \n  \r  \t  -----  \/  \b  \f  */
		objV = objV.replace(/\\/g,"\\\\");
		objV = objV.replace(/\"/g,'\\"');
		//objV = objV.replace(/\b/g,"\\b");
		//objV = objV.replace(/\f/g,"\\f");
		objV = objV.replace(/\n/g,"\\n");
		objV = objV.replace(/\r/g,"\\r");
		objV = objV.replace(/\t/g,"\\t");
		return objV;
	}

	this.eqaulAND = function(objV) {
	    objV = objV.replace(/(=)/g, "%3D");
	    objV = objV.replace(/(\+)/g, "%2B");
	    return objV.replace(/(&)/g, "%26");
	}
	this.changeAND = function(va11,val2) {
	    return va11.replace(/(&)/g, val2);
	}
}