// ratawiki.js

function RataWiki() {
	this.ratax = new ratax();
	this.uri = '';
	this.libbase = '';
	this.version = 'v0.1a';
	this.docID = null;
	
	this.setURI = function(uri) {
		this.uri = uri;
		this.ratax.rpcuri = uri;
	};
	
	
	this.getVersion = function(h) { return this.call('version',null,h); };
	this.whoami = function(h) { return this.call('whoami',null,h); };
	this.validate = function(u,p) { return this.call('validate',{'user':u,'pass':p}); };
	
	this.call = function(fname, param, handler) {
		if ( typeof(handler) == 'function' ) {
			// Asynchronous mode with callback
			return this.ratax.call(fname,param,handler,true);
		}
		else {
			// Synchronous (blocking) mode
			return this.ratax.call(fname,param,null,false);
		}
	};
	
	this.setDoc = function (id){
		this.docID = id;
	};
	
	this.setTitle = function (title) {
		var x = this.call('setTitle',{'id':this.docID,'title':title});
		if ( x != null && typeof(x) != 'undefined' ) {
			alert('Nuevo título: '+x);
		}
		return title;
	};
	
	this.renameSection = function(secID,name) {
		var x = this.call('renameSection',{'docID':this.docID,'secID':secID,'name':name});
		return x;
	};
	this.setSectionTitle = function(secID, title) {
		var x = this.call('setSectionTitle',{'docID':this.docID,'secID':secID,'title':title});
		return x;
	};
	this.setSectionClass = function(secID, className) {
		var x = this.call('setSectionClass',{'docID':this.docID,'secID':secID,'className':className});
		return x;
	};

	this.saveSection = function(secID, content) {
		var x = this.call('saveSection',{'docID':this.docID,'secID':secID,'content':content});
		return x;
	};
	
	this.deleteSection = function(secID) {
		var x = this.call('deleteSection',{'docID':this.docID,'secID':secID});
		return x;
	};
	
	this.libs = new Object();
	
	this.loadLibrary = function(libname) {
		alert('Requesting '+libname);
		
	};
}

