class AppModules {

	static open(module) {
		if(!module)
			window.location = AppModules.getRootURL();
		if(module.toLowerCase() == "logout")
			AppModules.logout();
		else if(module.length) {
			module = module.replace("_", "/");
			window.location = AppModules.getRootURL() + module + ".php";
		}
	}
	
	static openLink(linkname, tabname=BRWIN_APPS) {
		window.open(AppModules.getRootURL() + "?link=" + linkname, tabname);
	}
	
	static getRootURL(){
		return app_root_url;
	}
	
	static logout(reason) {
		let current_url = window.location.href.replace(AppModules.getRootURL(), "");
		var page = current_url.replace(".php", "");
		if(page == "")
			page = "index";
		let url = AppModules.getRootURL() + "?logout&return=" + encodeURIComponent(page);
		url += (reason == undefined) ? "" : "&r=" + encodeURIComponent(reason);
		window.location = url;
	}
	
	static requiresAdmin() {
		if(!is_an_admin_user()) {
			window.location = AppModules.getRootURL();
			return false;
		}
		return true;
	}
}

