
//alert ('AppManager.asp');

function appManager(){
	this.apps = new Array();
	this.CG = function (){
		for(var _i = 0; _i < this.apps.length; _i++){
			if(this.apps[_i].appWin.closed)
				this.closeAppID(_i)
		}
		if(CollectGarbage) CollectGarbage()
	}
	this.openApp = function(appName, pageURL, width, height){
		var _tmp = this.appIsOpen(appName, pageURL, width, height)
		if(!_tmp)
			this.apps[this.apps.length] = new this.App(appName, pageURL, width, height)
		else
			_tmp.appWin.focus();
		if(CollectGarbage) CollectGarbage()
	};
	this.closeAppID = function(appID){
		if(this.apps[appID] && this.apps[appID].appWin != null){
			if(!this.apps[appID].appWin.closed) this.apps[appID].appWin.close();
			this.apps[appID].appWin = null;
			this.apps[appID] = undefined;
			var _tmp = this.apps.splice(appID, 1)
			_tmp = null;
		}
		if(CollectGarbage) CollectGarbage()
	};
	this.closeAll = function(){
		for(var _i = 0; _i < this.apps.length; _i++)
			this.closeAppID(_i)
		if(CollectGarbage) CollectGarbage()
		return true;
	}
	this.appIsOpen = function(appName, pageURL, width, height){
		for(var _i = 0; _i < this.apps.length; _i++){
			if(this.apps[_i].appName == appName && this.apps[_i].appWin.closed){
				this.closeAppID(_i)
				return false;
			}
			if(this.apps[_i] != null && this.apps[_i].appName == appName)
				return this.apps[_i];
		}
		return false;
	}
	this.App = function (appName, pageURL, width, height){
		this.width = width;
		this.height = height;
		this.appName = appName;
		this.pageURL = pageURL;
		if(this.width==0) this.width = scr.availWidth-20
		if(this.height==0) this.height = scr.availHeight-20
		var _top = parseInt(((scr.availHeight-this.height)/2))-5;
		var _left = parseInt(((scr.availWidth-this.width-10)/2));
		this.height-=20; // start bar.
		try {
			this.appWin = win.open(pageURL, appName, "copyhistory=no,status=no,location=no,directories=no,scrollbars=no,toolbar=no,menubar=no,resizable=no,top="+_top+",left="+_left+",width="+this.width+",height="+this.height);
		}
		catch (ex) {
			this.appWin = win.open("about:blank", appName, "copyhistory=no,status=no,location=no,directories=no,scrollbars=no,toolbar=no,menubar=no,resizable=no,top="+_top+",left="+_left+",width="+this.width+",height="+this.height);
			this.appWin.document.location = pageURL;
		};
		this.appWin.focus();
		this.appWin.onunload = function(){
			closeApp(appID)
		}
		return this;
	}
}
