function trim(s) {
	return s.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function checkValidResponse(o)
{
 	try {
	var response = eval('('+o.responseText+')');
	if (response['retcode'] > -1) {
		return response;
	} else {
		alert(response['message']);
		return false;
	}
	} catch(e) {
 		
 		alert("Invalid data returned:\n" + o.responseText);
		return false;
 	}
}

function callAPIMethod(url_vars,data,cb)
{
	var callback = {
		success: function(o) {
 			cb(checkValidResponse(o),o.argument);
		},
		failure: function(o) {
 			cb(false,o.argument);
		},
		argument: data 
	}
	var url = "ws.php?operation=" + url_vars.operation;
	for (var nm in url_vars) {
 		if (nm != "operation") {
 			url = url + "&" + encodeURIComponent(nm) + "=" + encodeURIComponent(url_vars[nm]);
 		}
 	}	
	var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
}
