var _ORG_JOD_JSAPI_ROOT_LIBRARY  = null;
var _ORG_JOD_JSAPI_ROOT_LIBRARY_IMAGES_GUI  = null;

var Builder = {};

var JSAPI = null;

Builder.loadJS = function (url, charset) {
    if (!charset) {
        charset = "UTF-8";
    }
    var charsetProperty = " charset=\"" + charset + "\" ";
    document.write("<script type=\"text/javascript\" src=\"" + url + "\" onerror=\"alert('Error loading ' + this.src);\"" + charsetProperty + "></script>");
};
Builder.loadCSS = function (url, charset) {
    if (!charset) {
        charset = "UTF-8";
    }
    var charsetProperty = " charset=\"" + charset + "\" ";
    document.write("<link href=\"" + url + "\" type=\"text/css\" rel=\"stylesheet\" onerror=\"alert('Error loading ' + this.src);\"" + charsetProperty + "/>");
};


function JSRemoteApi (aRootPath, aRemotePath,  aDebug) {
	
	this._servletContext = "/";
	this._applicationContext= "/";

	this._rootPath = aRootPath + "org/jod/jsapi/";
	this._remotePath = aRemotePath;
	
	_ORG_JOD_JSAPI_ROOT_LIBRARY = this._rootPath;
	_ORG_JOD_JSAPI_ROOT_LIBRARY_IMAGES_GUI  = aRootPath +"images/gui/";
	

	// util
	//Builder.loadJS(this._rootPath + "util/Array.js");
	Builder.loadJS(this._rootPath + "util/List.js");
	Builder.loadJS(this._rootPath + "util/Message.js");
	Builder.loadJS(this._rootPath + "util/Observable.js");
	Builder.loadJS(this._rootPath + "util/Observer.js");
	Builder.loadJS(this._rootPath + "util/String.js");
	Builder.loadJS(this._rootPath + "util/UniqueId.js");
	Builder.loadJS(this._rootPath + "util/JSApiTool.js");
	Builder.loadJS(this._rootPath + "util/JSApiDomTool.js");
	Builder.loadJS(this._rootPath + "util/JSDate.js");	
	Builder.loadJS(this._rootPath + "util/Hashtable.js");		
	
	// dwr system
	Builder.loadJS(this._remotePath + "/engine.js");
	Builder.loadJS(this._remotePath + "/util.js");

	// dwr interface
	Builder.loadJS(this._remotePath + "/interface/UserServiceEntryPoint.js");	

	
	// data store
	Builder.loadJS(this._rootPath + "data/Store.js");			
	Builder.loadJS(this._rootPath + "data/Proxy.js");				
	Builder.loadJS(this._rootPath + "data/Reader.js");					
	Builder.loadJS(this._rootPath + "data/dwr/DwrProxy.js");	
	Builder.loadJS(this._rootPath + "data/dwr/DwrRemoteProxy.js");		
	Builder.loadJS(this._rootPath + "data/dwr/DwrReader.js");	
	Builder.loadJS(this._rootPath + "data/dwr/DwrPagedReader.js");		
	Builder.loadJS(this._rootPath + "data/PagedRecords.js");			

	// functionally interface
	Builder.loadJS(this._rootPath + "AServerEvent.js");
		

	JSAPI  = this;

	this.getRemotePath = function () {
		return this._remotePath;
	};		

	this.addJSResource = function (aJsResource) {
		Builder.loadJS(aJsResource);
	};
	
	this.addCSSResource = function (aCSSResource) {
		Builder.loadCSS(aCSSResource);
	};	

	this.getRootPath = function () {
		return this._rootPath;
	};	
	
	this.getGuiImagesPath = function () {
		
		return this.getRootPath() + "images/gui/";
	};
	
	this.setServletContext = function (aServletContext) {
		this._servletContext = aServletContext;
	};
	
	this.getServletContext = function () {
		return this._servletContext;
	};

	this.setApplicationContext = function (aApplicationContext) {
		this._applicationContext = aApplicationContext;
	};

	this.getApplicationUriContext = function () {

		return this._servletContext + "/" + this._applicationContext;
	};
};
