
function emBusSharedConn() {
	
    dojox.cometd.init("/emBusAdmin/cometd");  
		
	this.subscribe = function(channel,subject,tagList,rgtagList,emBusMsgHandler) {

		var jsonArgs = { "action": 2,
						 "channel": channel,
						 "subject": subject,
						 "tagList": tagList,
						 "rgtagList": rgtagList
				 	   };
		
		dojox.cometd.subscribe(channel,emBusMsgHandler);

		return(this.doAjax(jsonArgs));
	};
	
	this.unsubscribe = function(channel,subject,emBusMsgHandler) {
 		
		var jsonArgs = { "action": 3,
						 "channel": channel,
						 "subject": subject
				 	   };

		return(this.doAjax(jsonArgs));
	};
	
	this.publish = function(sendTo,msg) {
		 
		var jsonArgs = { "action": 4,
				 		"sendTo": sendTo,
				 		 "msg": msg	
	 	   			   };

		return(this.doAjax(jsonArgs));
	};
	
	this.sendTo = function(sendTo,msg) {
 		
		var jsonArgs = { "action": 5,
		 				 "sendTo": sendTo,
		 				 "msg": msg		
					   };
	
		return(this.doAjax(jsonArgs));
	};
	
		
	this.doAjax = function(jsonArgs) {
		
		dojo.xhrGet({
			url: "/emBusAdmin/emBusSharedServlet",
			content: jsonArgs,
			timeout: 1000,
			handleAs: "json",
			load: function(response, ioArgs) {
					return true;
					},
			error: function(response, ioArgs){
					dojox.cometd.unsubscribe("/fix/X");
					dojox.cometd.disconnect();
					return false;
					},
			timeout: function(response, ioArgs){
						dojox.cometd.unsubscribe("/fix/X");
						dojox.cometd.disconnect();
					return false;
					}
			});
			return true;
	};
} 


