/*
 * DON'T REMOVE THE FOLLOWING LICENSE
 *           INFORMATION!
 * ----------------------------------
 * Copyright by
 * Dennis Ritz
 * Author: Dennis Ritz
 * dennis.ritz@gmx.net
 * 2007-2008
 * ----------------------------------
 */

function CMgr() {
	this.auth	= null;
	this.model	= null;
	
	this.__construct = function __construct() {
		CMgr.components = new Array();	
	}
	
	this.start = function start(p_comp,p_callStack) {
		var cbObj = new Object();
		cbObj.callback = CMgr.startCb;
		cbObj.calldata = new Object();
		cbObj.calldata.comp = p_comp;
		if(typeof p_callStack == "object") {
			cbObj.calldata.callStack = p_callStack;
		} else {
			cbObj.calldata.callStack = "";
		}
		Ajax.request(p_comp,"__init",cbObj);
	}
	
	this.startCb = function startCb(p_cb,p_calldata) {
		if(p_cb instanceof Object) {
			var newStyle = Browser.createElement("style",p_calldata.comp+"Style");
			newStyle.type = "text/css";
			newStyle.media = "all";
			if(newStyle.styleSheet) {
				newStyle.styleSheet.cssText = p_cb[1];
			}else{
				var newStyleText = Browser.createTextNode(p_cb[1]);
				newStyle.appendChild(newStyleText);
			}
			Browser.getElementsByTagName("head")[0].appendChild(newStyle);

			Browser.setScript('text/javascript',p_calldata.comp, p_cb[0]);

			eval(p_cb[2]);
		}
		if(typeof p_calldata.callStack == "object") {
			var argsStr = p_calldata.callStack.args.join('","');
			if(argsStr != "") argsStr = ',"'+argsStr+'"';
			eval('Ajax.request(p_calldata.callStack.comp,p_calldata.callStack.method'+argsStr+',p_calldata.callStack.cbObject)');
	
		}
	}
	
	this.callComp = function callComp(p_comp,p_execute) {
		if(!CMgr.isCompStarted(p_comp)) {
			CMgr.start(p_comp,p_execute);
		} else {
			eval(p_comp+'.'+p_execute);
		}
	}
	
	this.isCompStarted = function isCompStarted(p_comp) {
		if(Browser.getElementById(p_comp+"ODS")) {
			return true;
		}else{
			return false;
		}
	}
	
	this.evalCb = function evalCb(p_cb) {
		for(var i in p_cb) {
			eval(p_cb[i]);
		}
	}
	
	this.setMODEL = function setMODEL(p_comp) {
		this.model = p_comp;
		this.model.__construct();
	}
	
	this.getMODEL = function getMODEL() {
		return this.model;
	}
	
	this.setAUTH = function setAUTH(p_comp) {
		this.auth = p_comp;
		this.auth.__construct();
	}
	
	this.getAUTH = function getAUTH() {
		return this.auth;
	}
}
var CMgr = new CMgr();
CMgr.__construct();