var commmsgId,commresponseId;
var xmls;
function initSocket(){	
	if (config["enableSocketServer"]!=true)
		return;
	commmsgId=0;
	commresponseId=0;
	//config["enableSocketServer"]=false;
	//SocketClose();
	SocketConnect(config["socketServer"]["host"],config["socketServer"]["port"]);	
}

function SocketConnect(host,port){
	function connect() {
		xmls.onConnect = function(success) {
			if(success){
				//alert("connection OK");		
			}else{
				alert("Socket connection error!");	
				config["enableSocketServer"]=false;
			}			
		};
		xmls.onClose = function() {
			//alert("server has gone away");
		};
		
		xmls.onData = function(data) {
			if (xmlDOMObj==null)
				xmlDOMObj = new crossBrowserXMLDoc ();			
			//var xmlobject = (new DOMParser()).parseFromString(data, "text/xml");
			var xmlobject = xmlDOMObj.parseXMLString (data);
			//alert(data);
			xmlDecoder(xmlobject, data);
		};
		
		xmls.connect(host, port);		
	};
	connect();	
}		
		
function composeRequestXML(data){
	if(!data)
		return;
	var str="<request";
	for (var key in data) {
		if (key!="t")
			str+=" " + key + "=\"" + data[key] + "\"";      
    }
    if (data)
    	if (data["t"])	    	
    		str+="><t>" + escapeHTML(data["t"].toString()) + "</t></request>";
    	else
    		str+="></request>";
    xmls.send(str);
    //alert(str);
}
