YAHOO.namespace('cn.onemouse.json');

YAHOO.cn.onemouse.conn = function(url, args, callback, type)
{
	var _self = this;
	this.args = args;
	this.url = url;
	this.type = type ? type.toUpperCase() : 'GET';
	this.callback = callback;
	this.add = function(args){
		for(var i in args)
			_self.args[i] = args[i];		
	};
	this.conn = function(){
		var calls = {
			success: function(data){
				var result = '';
				var text = data.responseText;
				try{eval("result = " + text)} catch(e) {alert('There is some wrong!');} 
				_self.callback(result);
			},
			failure: function(){alert('failed');},
			argument: {}
		};
		
		var str = '';
		for(var key in _self.args)
		{
			if(str) str += '&' ;
			str +=	key + '=' + encodeURIComponent(_self.args[key]);
		}
		if(str && _self.type == 'GET') _self.url += (_self.url.indexOf('?') > 7 ? '&' : '?') + str;
		YAHOO.util.Connect.asyncRequest(_self.type, _self.url, calls, str);
	}
}
