
if (!MB) { var MB = new Object(); }

MB.CATEGORY_OVERVIEW_COMPONENT_ID	= "category-overview-component";
MB.CATEGORY_DETAIL_COMPONENT_ID		= "category-detail-component";
MB.EVENT_DETAIL_COMPONENT_ID		= "event-detail-component";
MB.MARKET_DETAIL_COMPONENT_ID		= "market-detail-component";
MB.BET_PROCESS_LOADER_ID 			= "bet-process-loader-component";

MB.SYSTEM_PROPERTIES_TAG = "system-properties";

MB.LOADING_HTML = '<div class="loading-error">' + MB.LOADING_MESSG + '<br></div>';

MB.ODDS_TYPE_US = 'US';
MB.ODDS_TYPE_EURO = 'EU';
MB.ODDS_TYPE_PROB = 'PCT';

MB.USER_PREFS_ODDS_TYPE_DEFAULT = MB.ODDS_TYPE_US;

MB.SCREEN_UPDATE_PAUSE = 25;




MB.TOKEN_EXPIRED_MSG = "token expired";
MB.SESSION_INVALID_MSG = "session expired";

MB.handleResponseError = function(response, json) {
	var msg = (json) ? tx(response.message) : XML.getText(response, "message");
	var status = (json) ? tx(response.status) : XML.getText(response, "status");
	if(msg) msg = msg.toLowerCase();
	if(msg && (msg.indexOf(MB.TOKEN_EXPIRED_MSG) >= 0 || msg.indexOf(MB.SESSION_INVALID_MSG) >= 0)) {
		alert(MB.ERROR_SESSION_EXPIRED);
		MB.logout();
		MB.logToServer('Session expired received: ' + msg, response, json);
	} else if(!isEmpty(msg) && status != "success") {
		alert(msg);
		MB.logToServer('Response error received: ' + msg, response, json);
	}
}

MB.isSuccess = function(xml,json) {
	if (!json) {
		var status = XML.selectOne(xml,"status");
		if (!status || XML.getText(status) != "success") {
			var message = null;
			try { message = XML.toString(xml);
			} catch (e) { message = "xml parse failure: " + e; }

			Remote.displayError("mb-client-framework", message);
			return false;
		}
	} else if (xml && tx(xml.status) != 'success') {
		var message = tx(xml.message);
		if (message && message.length > 0)
			Remote.displayError("mb-client-framework", message);
		return false;
	}

	return true;
}

MB.getResponseDetails = function(xml) { return XML.selectOne(xml,"response"); }
MB.getMessage = function(xml) { return XML.getText(xml,"message"); }
MB.getRequestDetails = function(xml) { return XML.selectFirstChild(XML.selectOne(xml,"request")); }

MB.getComponentId = function(pXML) {
	return XML.getName(pXML) + "_" + XML.getAttribute(pXML, "id");
}

MB.mouseOver = function(element) {
	if (element.nodeName.toUpperCase() == "IMG") {
		var src = element.src +"";
		if(src.indexOf("-on.gif") > 0) return;
		element.src = src.substring(0,src.length-4) + "-on.gif";
	}
	return true;
}

MB.mouseOut = function(element) {
	if (element.nodeName.toUpperCase() == "IMG") {
		var src = element.src +"";
		if(src.indexOf("-on.gif") < 1) return;
		element.src = src.substring(0,src.length-7) + ".gif";
	}
	return true;
}

MB.formatCurrency = function(inNumber, showCents, showCommas) {
	var doCents = 0;
	if(showCents && showCents == true) doCents = 1;
	else if(showCents == false) doCents = -1;

	var num = ('' + inNumber).replace(new RegExp("[\$%,]","g"),'');
	if(num == 'null' || num == '' || isNaN(num)) return ((doCents >= 0)? "0.00" : 0);

	num = Math.round(num*100);
	var sign = (num >= 0);
	num = Math.abs(num);
	var cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;

	var s = '';
	if(showCommas) {
		var commaNum = num;
		while(commaNum > 0) {
			var grp = commaNum % 1000;
			if(commaNum >= 1000) {
				if(grp < 10) grp = '00' + grp;
				else if(grp < 100) grp = '0' + grp;
			}
			commaNum = parseInt(commaNum / 1000);
			s = ((commaNum > 0)? ',': '') + grp + s;
		}
	}

	var ret = (sign?'':'-') + ((s.length == 0)? num : s);
	if(doCents==1 || (doCents==0 && num<1000)) ret += '.' + cents;
	return ret;
}

MB.loadCategoryOverview = function(pCatId) { MB.loadTopBetProcessSelection(pCatId, "overview"); }
MB.loadCategoryDetail = function(pCatId) { MB.loadTopBetProcessSelection(pCatId, "category"); }
MB.loadEventDetail = function(pCatId) { MB.loadTopBetProcessSelection(pCatId, "event"); }
MB.loadMarketDetail = function(pCatId) { MB.loadTopBetProcessSelection(pCatId, "market"); }
MB.loadMyGames = function() { MB.loadTopBetProcessSelection(0, "My Games", "mygames"); }
MB.loadTopBetProcessSelection = function(pId, pType) {
	MB.loadURLIntoContentFrame(Remote.remoteServerURL + "/betProcess/betProcess.jsp?loadId=" + escape(pId) + "&loadType=" + escape(pType));
}

MB.loadURLIntoCurrentFrame = function(url,doIt) {
		if(doIt) document.location = url;
	else setTimeout("MB.loadURLIntoCurrentFrame('" + url + "',true)",0);
}

MB.loadURLIntoContentFrame = function(url,doIt) {
	if (doIt) {
		MBFrame.getContentStep().document.location = url;
		MB.setNavigationState(url);
	} else {
		try { MBFrame.getContentStep().componentRegistry.registryReady = false; }
		catch (e) {}
		setTimeout("MB.loadURLIntoContentFrame('" + url + "',true)",0);
	}
}

MB.pop_window = function(url){
	var w = window.open(url,'console','status,resizable,width=640,height=480');
	w.focus();
}

MB.emergencyScratchCounter = 12345;
MB.getScratchCounter = function() {
	var step = MBFrame.getProcessorFrameStep();
	if(step) return step.MB.getOrderPadCounter();
	else return MB.emergencyScratchCounter++;
}

MB.checkSitePreferences = function(pForceUpdate) {
	try { MBFrame.getProcessorFrameStep().MB.checkSitePreferences(pForceUpdate); }
	catch(e) { return null; }
}

MB.getSitePreference = function(prefName,pForceUpdate) {
	try { return MBFrame.getProcessorFrameStep().MB.getSitePreference(prefName,pForceUpdate); }
	catch(e) { return null; }
}

MB.setSitePreference = function(prefName, prefValue, sync) {
	try { return MBFrame.getProcessorFrameStep().MB.setSitePreference(prefName, prefValue, sync); }
	catch(e) { return null; }
}

MB.setSitePreferenceSynchronously = function(prefName, prefValue) {
	try { return MBFrame.getProcessorFrameStep().MB.setSitePreferenceSynchronously(prefName,prefValue); }
	catch(e) { return null; }
}

MB.hideTopCategoryMenu = function() { MB.showTopCategoryMenu(true); }
MB.showTopCategoryMenu = function(hide) {
	try {
		var step = MBFrame.getHorizontalFrame();
		step.document.body.cols = (hide? "0/*,100%,0" : "114,*,0");	/* */
		MB.setMenuLink(hide? "block" : "none");
	} catch(e) {}
}

MB.setMenuLink = function(display) {
	try { MBFrame.getContentStep().document.getElementById("show-menu-link").style.display=display;	}
	catch(e) {}
}

MB.topMenuLinkShowing = function() {
	return (MBFrame.getHorizontalFrame().document.body.cols != "0/*,100%,0");	/* */
}


MB.getNavigationStateXml = function(id) {
	if(!MB.loggedIn() || !id) return null;
	var lNavStateXML = XML.selectById(MB.getNavigationStates(id),id);

	if(lNavStateXML) return XML.selectFirstChild(lNavStateXML);
	else return null;
}

MB.setNavigationStateXml = function(id, xml) {
	var req = MB.getNavigationStateTemplate();
	var nav = XML.selectOne(req, "navigation-state");

	XML.setAttribute(nav, "id", id);
	XML.setText(req, "action", "update");
	XML.addContent(nav, xml);
	var r = Remote.machineCall("matchbook.com/operation/business/session/NavigationStateManagerMachine",req);

	if(MB.isSuccess(r)) {
		var lResponseXML = XML.selectOne(r,"response");
		var newStates = XML.selectOne(lResponseXML,"navigation-states");
		if(newStates && XML.hasKids(newStates)) MB.setPersistenceCache(newStates);
		return true;
	}
	return false;
}

MB.getNavigationStateTemplate = function() {
	return XML.parse('<request><action/><navigation-state id="" /></request>');
}

MB.setNavigationState = function(location) {
	var url = unescape(location);
	if(!url || url.length == 0) url = MBFrame.getContentStep().document.location;

	var catId = MB.getLoadedTopCategoryId();
	MB.doNavigationStateChange("update",url,catId);
}

MB.removeNavigationState = function() {
	MB.doNavigationStateChange("delete", "", "");
}

MB.deleteNavigationState = function(id){
	var req = MB.getNavigationStateTemplate();
	var nav = XML.selectOne(req, "navigation-state");

	XML.setText(req, "action", "delete");
	XML.setAttribute(nav, "id", id);
	var r = Remote.machineCall("matchbook.com/operation/business/session/NavigationStateManagerMachine",req);
	if(MB.isSuccess(r)) {
		var newStates = XML.selectOne(XML.selectOne(r,"response"),"navigation-states");
		if(newStates && XML.hasKids(newStates)) MB.setPersistenceCache(newStates);
		return true;
	}
	return false;
}

MB.doNavigationStateChange = function(action, url, catId) {
	try { MBFrame.getProcessorFrameStep().MB.setNavState(url,catId); }
	catch(e) {}
}

MB.getPersistenceCache = function() {
	try { MBFrame.getProcessorFrameStep().MB.NAVIGATION_STATE_CACHE; }
	catch(e) { return null; }
}

MB.setPersistenceCache = function(navXml) {
	try { MBFrame.getProcessorFrameStep().MB.NAVIGATION_STATE_CACHE = navXml; }
	catch(e) {}
}

MB.getNavigationStates = function(id) {
	if(!MB.loggedIn() || !id) return null;
	var states = MB.getPersistenceCache();

	if(!states) {
		var req = MB.getNavigationStateTemplate();
		var nav = XML.selectOne(req, "navigation-state");

		XML.setText(req, "action", "get");
		XML.setAttribute(nav, "id", id);
		var r = Remote.machineCall("matchbook.com/operation/business/session/NavigationStateManagerMachine",req);

		states = XML.selectOne(XML.selectOne(r,"response"),"navigation-states");
		if(states) MB.setPersistenceCache(states);
	}
	return states;
}

MB.getCountriesListTemplate = function() {
	return XML.parse('<countries-list-with-regions-request><countries /></countries-list-with-regions-request>');
}
MB.getCountriesList = function(pXml)	{
	return Remote.machineCall("matchbook.com/operation/business/registration/CountriesListWithRegionsMachine",pXml);
}

MB.getRegionsOfCountryTemplate = function() {
	return XML.parse('<region-details-based-on-country-chosen-request><region id="" country-id="" /></region-details-based-on-country-chosen-request>');
}
MB.getRegionsOfCountry  = function(pXml)	{
	return Remote.machineCall("matchbook.com/operation/business/registration/RegionDetailsBasedOnCountryChosenMachine",pXml);
}

MB.showMenuLink = function(folderDepth) {
	var dirPath = '';
	for(var i=0; i<((folderDepth >= 0)? folderDepth : 1); i++) dirPath += '../';

	return '<div id="show-menu-link" style="z-index:50; display:' + (MB.topMenuLinkShowing()? 'none':'block') + '; top:4; left:4; position:absolute;">'
		 + '<a href="javascript:;" onClick="javascript:MB.doCompactView(false);"><IMG src="' + dirPath + 'images/sport-menu/showMenu.gif" border=0></a></div>';
}

MB.doCompactView = function(isCompact) {
	var step = MBFrame.getProcessorFrameStep();
	if(step && step.MB) step.MB.setCompactView(isCompact);
}

MB.getOddsType = function() {
	try {
		var o = getCookie(MB.getUserName() + "-display-market-prices-using");
		if(o) return o;
	} catch(e) {}

	return MB.USER_PREFS_ODDS_TYPE_DEFAULT;
}

MB.setOddsType = function(type) {
	if(type) {
		try { setCookie(MB.getUserName() + "-display-market-prices-using", type);
		} catch(e) {}
	}
}

MB.setShow2or3Prices = function(val) {
	try { setCookie(MB.getUserName() + "-mb-show2or3", val); }
	catch (e) {}
}

MB.redrawContentMarketView = function() {
	try { MBFrame.getContentStep().MB.redrawMarketView(); }
	catch (e) { MB.logToServer("UI failure: redraw content market view.", null, false, e); }
}

MB.logout = function() {
	try { MBFrame.getProcessorFrameStep().MB.logout(); }
	catch(e) { MB.log("failure: error logging out, no proccessor frame?"); }
}

MB.requiresLogin = function() {
	if(!MB.loggedIn()) {
		alert(MB.uiMsgText(MB.ERROR_LOGIN_REQUIRED));
		return false;
	}
	return true;
}

MB.loggedIn = function() {
	try { return MBFrame.getProcessorFrameStep().MB.loggedIn(); }
	catch(e) {}
}

MB.getUserName = function() { return MBFrame.getProcessorFrameStep().MB.getUserName(); }
MB.getAccountId = function() { return MBFrame.getProcessorFrameStep().MB.getAccountId(); }
MB.getAccountBalance = function() { return MBFrame.getProcessorFrameStep().MB.getAccountBalance(); }
MB.setAccountBalance = function(balance, available, comCredits) {
	return MBFrame.getProcessorFrameStep().MB.setAccountBalance(balance,available,comCredits);
}

MB.setWaitState = function() {
	setWaitState();
	try { MBFrame.getContentStep().setWaitState(); }
	catch(e) {}
}

MB.releaseWaitState = function() {
	releaseWaitState();
	try { MBFrame.getContentStep().releaseWaitState(); }
	catch(e) {}
}

MB.uiMsgText = function(message, args) {
	var msg = message;
	if(args && msg) {
		for(var i=0; i<args.length; i++) {
			if(args[i] != null) msg = msg.replace((new RegExp("\\[" + i + "\\]","g")), args[i] + "");
			if(args[i] != null) msg = msg.replace((new RegExp("\\{" + i + "\\}","g")), args[i] + "");
		}
	}
	return msg;
}

MB.allowDebug = function() {
	return isTrueStr(MB.getSitePreference("sneekee-on"), COMPONENT_DEBUGGING_ON)
}

function debugMBComponent(id) {
	if (MB.allowDebug()) debugComponent(id, true);
}



function sortReportXmlByMarketSortMap(xml, sortNodeName) {
	sortXml(xml, sortNodeName, sortReportMarketSortMap, null);
}

function sortJsonArrayByMarketSortMap(jsonArray) {
	return sortJsonArray(jsonArray, null, sortMarketSortMap);
}

function sortMarketSortMap(j1, j2) {
	var json1 = (j1.offer != null)? j1.offer[0] : j1;
	var json2 = (j2.offer != null)? j2.offer[0] : j2;
	var r1 = json1.runner_id;
	var r2 = json2.runner_id;

	if (r1 == r2) {
		var side1 = tx(json1.side);
		var side2 = tx(json2.side);

		if(side1 == side2) {
			var id1 = '' + json1.id;
			var id2 = '' + json2.id;
			if(id1 != null && id1.indexOf("-") > 0) id1 = id1.substr(id1.lastIndexOf("-")+1);
			if(id2 != null && id2.indexOf("-") > 0) id2 = id2.substr(id2.lastIndexOf("-")+1);

			if(id1<id2) return -1;
			if(id1>id2) return 1;
			return 0;
		}
		if(side1 != null && side1.indexOf("win") >= 0) return -1;
		if(side2 != null && side2.indexOf("win") >= 0) return 1;
		return 0;
	}
	return marketSortCompare(r1,r2);
}

function marketSortCompare(r1,r2) {
	var p1 = MB.MarketSortMap['r'+r1];
	var p2 = MB.MarketSortMap['r'+r2];

	if(p1!=null && p2!=null) return (p1<p2? -1:1);
	return 0;
}

function sortReportMarketSortMap(xml1, xml2) {
	var e1 = XML.getText(xml1, "event-name");
	var e2 = XML.getText(xml2, "event-name");

	if (e1 == e2) {
		var m1 = XML.getText(xml1, "market-name");
		var m2 = XML.getText(xml2, "market-name");

		if(m1 == m2) {
			var r1 = XML.getAttribute(xml1, "selection");
			var r2 = XML.getAttribute(xml2, "selection");

			if (r1<r2) return -1;
			if (r1>r2) return 1;
			return 0;
		}
		if(m1<m2) return -1;
		if(m2<m1) return 1;
		return 0;
	}
	return (e1<e2? -1:1);
}



function getBetMonitorPaneHeight() {
	var temp = getDocElementById('sp-column-top');
	var opMin = (temp && temp.style.display == 'none');

	if(opMin) return (getActivityHeight() -getPaneOffsetHeight('order-pad')-3 -getPaneOffsetHeight('bet-monitor'));
	else return getBetMonitorHeight() - getPaneOffsetHeight('bet-monitor');
}

function getActivityPaneHeight() {return getActivityHeight() - getPaneOffsetHeight('activity');}
function getOrderPadPaneHeight() {return getOrderPadHeight() - getPaneOffsetHeight('order-pad');}
function getMarketPaneHeight() {return getMarketHeight() - getPaneOffsetHeight('market');}
function getActivityHeight() {return document.body.clientHeight-1-7;}
function getOrderPadHeight() {return Math.floor((document.body.clientHeight-1-7)/2) + 8;}
function getBetMonitorHeight() {return Math.ceil((document.body.clientHeight-1-7)/2) -8 -3;}
function getMarketHeight() {return document.body.clientHeight-1;}
function getMarketPaneWidth(showNumber) {return (showNumber == 2? 391 : 481);}

function resizePage() {
	var market = getDocElementById('market');
	if(market) {
		var h = getMarketHeight();
		market.style.height = h+1;
		setPaneHeight('market', h);
		resizeAP(null,true);
	}
}

function resizeAP(orderPadMinimized, quick) {
	var activity = getDocElementById('activity');
	if(activity){
		var temp = getDocElementById('sp-column-top');
		var opMin = (orderPadMinimized != null? orderPadMinimized : (temp && temp.style.display == 'none'));
		if(MB.getCurrentPanelId() != MB.SCRATCH_PAD_COMPONENT_ID) opMin = false;

		if(opMin) {
			var act = getActivityHeight();
			var op = getPaneOffsetHeight('order-pad');
			var bm = act-op-3;

			if(!quick) {
				var pane = getDocElementById('order-pad-pane');
				if(pane) pane.style.display = 'none';
			}

			pane = getDocElementById('sp-column-top');
			if(pane) bm += pane.offsetHeight;
			if(pane && !quick) pane.style.display = 'none';
			setBPheights(act,bm,op);

		} else {
			if(!quick) {
				var pane = getDocElementById('order-pad-pane');
				if(pane) pane.style.display = 'block';
				pane = getDocElementById('sp-column-top');
				if(pane) pane.style.display = 'block';
			}
			setBPheights(getActivityHeight(),getBetMonitorHeight(),getOrderPadHeight());
		}
	}
}

function setBPheights(a,b,o) {
	setPaneHeight('activity',a);
	setPaneHeight('bet-monitor',b);
	setPaneHeight('order-pad',o);
}

checkBlockedWindow = function(objName) {
	try {
		var x = null;
		eval('x = ' + objName + '.closed;');
		if(x == false) return true;
	} catch(e) {}

	alert('Your system seems to be blocking popup windows. Please \nensure your settings allow popup windows for this site.');
	return false;
}

MB.getUIWindowID = function() {
	var step = MBFrame.getProcessorFrameStep();
	if(step && step.MB) return step.getUIWindowId();
	else return 1;
}

 
 
if (!MB) var MB = new Object();
if (!MBFrame) var MBFrame = new Object();

MB.loggedIn = function() {
	return MBFrame.getProcessorFrameStep().MB.loggedIn();
}

MB.storeXMLInSession = function(pId, pObject) {
	var str = null;
	if(pObject != null) str = XML.toString(pObject);
	MBFrame.getProcessorFrameStep().Remote.storeInSession(pId,str);
}

MB.removeXMLFromSession = function(pId) {
	MBFrame.getProcessorFrameStep().Remote.removeFromSession(pId);
}

MB.fetchXMLFromSession = function(pId) {
	var str = MBFrame.getProcessorFrameStep().Remote.fetchFromSession(pId);
	if(str == null) return null;
	return XML.parse(str);
}

MB.storeJsonInSession = function(pId, pObject) {
	MBFrame.getProcessorFrameStep().Remote.storeInSession(pId,Json.toString(pObject));
}

MB.removeJsonFromSession = function(pId) {
	MBFrame.getProcessorFrameStep().Remote.removeFromSession(pId);
}

MB.fetchJsonFromSession = function(pId) {
	var pObject = MBFrame.getProcessorFrameStep().Remote.fetchFromSession(pId);
	if(pObject != null && pObject.length > 0) pObject = eval('(' + pObject + ')');
	return pObject;
}

MB.reloadApplication = function() { MBFrame.getProcessorFrameStep().MB.reloadApplication(); }

MB.logRequest = function(id,msg,qLen) { MBFrame.getProcessorFrameStep().MB.logRequest(id,msg,qLen); }
MB.logResponse = function(id,msg,qLen) { MBFrame.getProcessorFrameStep().MB.logResponse(id,msg,qLen); }
MB.logError = function(id,msg) { MBFrame.getProcessorFrameStep().MB.logError(id,msg); }
MB.logStats = function(dat) { MBFrame.getProcessorFrameStep().MB.logStats(dat); }
MB.log = function(dat) { MBFrame.getProcessorFrameStep().MB.log(dat); }
MB.rrauditRequest = function(machine,bit) { MBFrame.getProcessorFrameStep().MB.rrauditRequest(machine,bit); }

MB.logToServer = function(msg,data,json,ex) { MBFrame.getProcessorFrameStep().MB.logToServer(msg,data,json,ex); }

MB.isCreepeeRunning = function() {
	return MBFrame.getProcessorFrameStep().MB.continueCreepeeLoop;
}

MB.isBetProcessTestRunning = function(){
	return MBFrame.getProcessorFrameStep().MB.continueBetProcessTestLoop;
}

MB.IS_REFRESHING_BP = false;
MB.isRefreshingBP = function() { return MB.IS_REFRESHING_BP; }
MB.setRefreshingBP = function(isIt) { MB.IS_REFRESHING_BP = isIt; }

MB.POLLER_OUT_FOR_LUNCH = false;
MB.isPollerInTransit = function() { return MB.POLLER_OUT_FOR_LUNCH; }
MB.setPollerInTransit = function(lunch) { MB.POLLER_OUT_FOR_LUNCH = lunch; }

MB.pollingRate = function() {
	var err = false;
    var rate = MB.POLLING_RATE_MEDIUM;
	var temp = MB.getSitePreference("odds-refresh-rate");
	if(temp != null) {
		if('low' == temp) rate = MB.POLLING_RATE_LOW;
		else if('high' == temp) rate = MB.POLLING_RATE_HIGH;
		else if('medium' != temp) err = true;
	} else {
		var step = MBFrame.getProcessorFrameStep();
		if( step && step.MB ) rate = step.MB.pollingRate();
		if(!rate || rate < MB.POLLING_RATE_HIGH) {
		    rate = MB.POLLING_RATE_MEDIUM;
			err = true;
		}
	}

	if(err) MB.log('Error fetching polling rate pref, using: ' + rate);
	return rate;
}

MB.polling = function() { return MBFrame.getProcessorFrameStep().MB.polling(); }

MB.pollingTimeout = function() { return MBFrame.getProcessorFrameStep().MB.pollingTimeout(); }

MB.getInRunnerSubmitTimeout = function() { return MBFrame.getProcessorFrameStep().MB.getInRunnerSubmitTimeout(); }
MB.setInRunnerSubmitTimeout = function(pSecs) { return MBFrame.getProcessorFrameStep().MB.setInRunnerSubmitTimeout(pSecs); }

MB.NULL_COMPONENT = "null-component-found";
MB.getContentPanelLoadedComponentId = function() {
	var panel = MBFrame.getContentStep();
	if (panel.componentRegistry) {
		var bpComponent = panel.componentRegistry.getComponent(MB.BET_PROCESS_LOADER_ID);
		if (bpComponent) return bpComponent.getCurrentLoadedComponentId();
	}
	return MB.NULL_COMPONENT;
}

MB.getLoadedTopCategoryId = function() {
	var panel = MBFrame.getCategoryMenuStep();
	if (panel.CatMenu) return panel.CatMenu.currentSelection;
	return -1;
}

MBFrame.processorFrame = null;
MBFrame.menuFrame = null;
MBFrame.categoryFrame = null;
MBFrame.contentFrame = null;
MBFrame.horizontalFrame = null;

MBFrame.getProcessorFrameStep = function() {
	if (MBFrame.processorFrame != null) return MBFrame.processorFrame;

	var f = null;
	try {
		f = parent.processorFrame;
		if (!f) f = parent.parent.processorFrame;
		if (!f) f = parent.parent.parent.processorFrame;
	} catch(e) {}

	if (!f) f = opener;
	MBFrame.processorFrame = f;
	return f;
}

MBFrame.getTopMenuStep = function() {
	if (MBFrame.menuFrame != null) return MBFrame.menuFrame;

	var f = null;
	try {
		f = parent.menuFrame;
		if (!f) f = parent.parent.menuFrame;
		if (!f) f = parent.parent.parent.menuFrame;
	} catch(e) {}

	if (!f) f = opener;
	MBFrame.menuFrame = f;
	return f;
}

MBFrame.getHorizontalFrame = function() {
	if (MBFrame.horizontalFrame != null) return MBFrame.horizontalFrame;

	var f = null;
	try {
		f = parent.horizontalFrame;
		if (!f) f = parent.parent.horizontalFrame;
		if (!f) f = parent.parent.parent.horizontalFrame;
	} catch(e) {}

	MBFrame.horizontalFrame = f;
	return f;
}

MBFrame.getCategoryMenuStep = function() {
	if (MBFrame.categoryFrame != null) return MBFrame.categoryFrame;

	MBFrame.categoryFrame = MBFrame.getHorizontalFrame().categoryFrame;
	return MBFrame.categoryFrame;
}

MBFrame.getContentStep = function() {
	if (MBFrame.contentFrame != null) { return MBFrame.contentFrame; }

	var f = MBFrame.getHorizontalFrame();
	if (f) MBFrame.contentFrame = f.contentFrame;
	else MBFrame.contentFrame = top;

	return MBFrame.contentFrame;
}

MB.extraStateXML = function() { return MBFrame.getProcessorFrameStep().MB.extraStateXML(); }

 
 