RegisterNamespace("Arland");

var nextField = '';
var BC = null;

var Cookie = {
	data: {},
	options: {expires: 1, domain: "", path: "", secure: false},

	init: function(options, data) {
		Cookie.options = Object.extend(Cookie.options, options || {});

		var payload = Cookie.retrieve();
		if(payload) {
			Cookie.data = payload.toQueryParams();
		}
		else {
			Cookie.data = data || {};
		}
		Cookie.store();
	},
	getData: function(key) {
		return Cookie.data[key];
	},
	setData: function(key, value) {
		Cookie.data[key] = value;
		Cookie.store();
	},
	removeData: function(key) {
		delete Cookie.data[key];
		Cookie.store();
	},
	retrieve: function() {
		var start = document.cookie.indexOf(Cookie.options.name + "=");

		if(start == -1) {
			return null;
		}
		if(Cookie.options.name != document.cookie.substr(start, Cookie.options.name.length)) {
		return null;
	}

	var len = start + Cookie.options.name.length + 1;   
	var end = document.cookie.indexOf(';', len);

	if(end == -1) {
		end = document.cookie.length;
	} 
		return unescape(document.cookie.substring(len, end));
	},
	store: function() {
		var expires = '';

		if (Cookie.options.expires) {
			var today = new Date();
			expires = Cookie.options.expires * 86400000;
			expires = ';expires=' + new Date(today.getTime() + expires);
		}
		var jsonData = $H(Cookie.data).toQueryString();
		document.cookie = Cookie.options.name + '=' + escape(jsonData) + Cookie.getOptions() + expires;
	},
	erase: function() {
		document.cookie = Cookie.options.name + '=' + Cookie.getOptions() + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	},
	getOptions: function() {
		return (Cookie.options.path ? ';path=' + Cookie.options.path : '') + (Cookie.options.domain ? ';domain=' + Cookie.options.domain : '') + (Cookie.options.secure ? ';secure' : '');      
	}
};

// Console
Arland.Console =
{
	Log: function(msg)
	{
		if (!DEBUG) return;
		if ("console" in window) console.log(msg);
		if (top.debugWindow)
		{
			var line = top.document.createElement("div");
			line.className = "line";
			line.appendChild(top.document.createTextNode(new Date() + ": " + msg));
			top.debugWindow.appendChild(line);
		}
	},
	Init: function()
	{
		if (!DEBUG) return;
		if (top != window) return;
		return;
		if (top.debugWindow) return;

		Cookie.init({name: "debug", expires: 90});
		top.debugWindow = $(top.document.createElement("div"));
		top.debugWindow.className = "arlandDebugWindow";
		var caption = top.document.createElement("div");
		caption.className = "caption";
		caption.appendChild(top.document.createTextNode("Console"));
		top.debugWindow.appendChild(caption);
		top.document.body.appendChild(top.debugWindow);

		var posX = Cookie.getData("positionX");
		var posY = Cookie.getData("positionY");
		if(posX || posY)
			top.debugWindow.setStyle({ "left": posX + "px", "top": posY + "px" });

		Arland.Console._drag = false;
		Arland.Console._pos = Position.positionedOffset(top.debugWindow);
		Event.observe(caption, "mousedown", this.OnCaptionMouseDown);
		Event.observe(caption, "mouseup", this.OnCaptionMouseUp);
		Event.observe(caption, "mousemove", this.OnCaptionMouseMove);
		Event.observe(top, "scroll", this.OnWindowScroll);
		Event.observe(top, "unload", this.OnWindowUnload);
	},
	Hide: function()
	{
		top.debugWindow.hide();
	},
	OnCaptionMouseDown: function(e)
	{
		Arland.Console._drag = true;
		Arland.Console._mousePos = { x:e.clientX, y:e.clientY };
		Arland.Console._pos = Position.positionedOffset(top.debugWindow);
	},
	OnCaptionMouseMove: function(e)
	{
		if(!Arland.Console._drag)
			return;

		var left = Arland.Console._pos[0] + (e.clientX - Arland.Console._mousePos.x);
		var t = Arland.Console._pos[1] + (e.clientY - Arland.Console._mousePos.y);

		top.debugWindow.setStyle({ "left": left + "px", "top": t + "px" });
		Arland.Console._mousePos = { x:e.clientX, y:e.clientY };
		Arland.Console._pos = Position.positionedOffset(top.debugWindow);
	},
	OnCaptionMouseUp: function()
	{
		Arland.Console._drag = false;
		Arland.Console._pos = Position.positionedOffset(top.debugWindow);
	},
	OnWindowScroll: function()
	{
		var offset = Arland.Window.ScrollOffset();
	},
	OnWindowUnload: function()
	{
		Cookie.setData("positionX", Arland.Console._pos[0]);
		Cookie.setData("positionY", Arland.Console._pos[1]);
	}
};

Event.observe(window, "load", function()
{
	Arland.Console.Init();
});

// Arland Selection
Arland.Selection =
{
	InputSelectionStart: function(elem)
	{
		if (document.selection)
		{
			var stored_range = document.selection.createRange().duplicate();
			stored_range.moveEnd("character", elem.value.length);
			if (stored_range.text == "") return elem.value.length;
			res = elem.value.length - stored_range.text.length;
			return res;
		}
		else
		{
			return elem.selectionStart;
		}
	},
	InputSelectAll: function(elem)
	{
		if (document.selection)
		{
			elem.createTextRange().select();
		}
		else
		{
			elem.select();
		}
	}
};

Arland.Window = 
{
	ScrollOffset: function(w)
	{
		w = w || window;
		var x =  w.pageXOffset
					|| w.document.documentElement.scrollLeft
					|| w.document.body.scrollLeft
					|| 0;
		var y =  w.pageYOffset
					|| w.document.documentElement.scrollTop
					|| w.document.body.scrollTop
					|| 0;
		return {"x": x, "y": y};
	}
}

Arland.BrowserInfo =
{
	Browser: null,
	Version: null,
	Init: function()
	{
		for (var browser in Arland.BrowserInfo.Data)
		{
			browserData = Arland.BrowserInfo.Data[browser];
			if (browserData.property.match(browserData.browserMatch))
			{
				Arland.BrowserInfo.Version = browserData.property.match(browserData.versionMatch)[1];
				Arland.BrowserInfo.Browser = browser;
				break;
			}
		}
	},
	Browsers: {
		MSIE: "MSIE",
		Firefox: "Firefox",
		Safari: "Safari"
	},
	Data: {
		"MSIE": {
			property: navigator.userAgent,
			browserMatch: /MSIE/,
			versionMatch: /.*MSIE ([0-9\.]*).*/
		},
		"Firefox": {
			property: navigator.userAgent,
			browserMatch: /Firefox/,
			versionMatch: /.*/
		},
		"Safari": {
			property: navigator.userAgent,
			browserMatch: /Safari/,
			versionMatch: /.*/
		}
	}
};
Arland.BrowserInfo.Init();
Arland.Application =
{
	Location: "home",
	ChangeLocation: function(loc)
	{
		if (Arland.Application.Location != loc)
		{
			var cmenu = $("customerMenu");
			if(cmenu)
			{
				var menuItems = cmenu.getElementsByTagName("li");
				for (var i = 0; i < menuItems.length; i++)
				{
					var menuItem = $(menuItems[i]);
					menuItem.removeClassName("selected");
					if (menuItem.getAttribute("location") == loc) menuItem.addClassName("selected");
				}
			}
		}
		Arland.Application.Location = loc;
	}
};
Arland.Control = Class.create({
	initialize: function(id) {
		this.id = id;
		this.container = $(id);
	}
	,
	onAjaxFailure: function(t)
	{
		signal("Unable to finish request");
	}
});

Arland.NotificationCenter = Class.create({
	initialize: function()
	{
		this.notifications = $H();
	}
	,
	observe: function(eventName, observer)
	{
		if(!this.notifications[eventName])
			this.notifications[eventName] = $A();
		var observers = this.notifications[eventName];
		observers.push(observer);
	}
	,
	unobserve: function(eventName, observer)
	{
		if(!this.notifications[eventName])
			this.notifications[eventName] = $A();
		var observers = this.notifications[eventName];
		var idx = observers.indexOf(observer);
		if(idx != -1)
			observers.splice(idx, 1);
	}
	,
	notify: function(eventName, ctx)
	{
		var observers = this.notifications[eventName];
		if(observers == null)
			return;

		for(var i=0; i < observers.length; i++) {
			var observer = observers[i];
			try {
				observer(ctx);
			}
			catch(e)
			{
				signal(e);
			}
		}
	}
});

if(!top.MainNotificationCenter)
	top.MainNotificationCenter = new Arland.NotificationCenter();

// registers namespace in current window
function RegisterNamespace(ns)
{
	parts = ns.split(".");
	for (var i = 0; i < parts.length; i++)
	{
		var nspart = parts.slice(0, i + 1).join(".");
		eval("if(!window." + nspart + ") window." + nspart + "={};");
	}
}
document.getElementsByExactClassName = function(className, parentElement)
{
	var children = ($(parentElement) || document.body).getElementsByTagName('*');
	return $A(children).inject([], function(elements, child)
	{
		if (child.className.match(new RegExp("^\\s?" + className + "\\s?$"))) elements.push(Element.extend(child));
		return elements;
	});
}
document.getElementByClassName = function(className, parentElement)
{
	var res = document.getElementsByClassName(className, parentElement);
	return res ? (res.length > 0 ? res[0] : null) : null;
}
//--------------------------------------------------------------------------------------------
function setFrame(name, url)
{
	try
	{
		var iframe = document.getElementById(name);
		if (iframe == null) iframe = parent.document.getElementById(name);
		if (iframe != null) iframe.src = url;
	}
	catch (ex)
	{
		signal('setFrame', ex);
	}
}
//--------------------------------------------------------------------------------------------
function timeOut()
{
	try
	{
		//parent.document.location.href = 'default.aspx';
		signal('reloading');
		if (parent != window) top.document.location.href = parent.document.location.href; //reload doen't work
		else top.document.location.href = "default.aspx";
	}
	catch (ex)
	{
		signal('timeOut', ex);
	}
}

function refreshCustomer(sessionID)
{
	try
	{
		parent.document.location.href = 'default.aspx?cmd=refreshcustomer&sid=' + sessionID;
	}
	catch (ex)
	{
		signal('refreshCustomer', ex);
	}
}
//--------------------------------------------------------------------------------------------
function updateSaldo(saldoString)
{
	try
	{
		var saldo = parent.document.getElementById('saldo');
		if (saldo != null && saldoString != null) saldo.innerHTML = saldoString;
	}
	catch (ex)
	{
		signal('updateSaldo', ex);
	}
}
//--------------------------------------------------------------------------------------------
function updateOpenBets(betCount)
{
	try
	{
		var openBets = parent.document.getElementById('openBets');
		if (openBets != null) openBets.innerHTML = betCount;
	}
	catch (ex)
	{
		signal('updateOpenBets', ex);
	}
}
//--------------------------------------------------------------------------------------------
function setFocus(id)
{
	try
	{
		if (document.getElementById)
		{
			try
			{
				var el = document.getElementById(id);
				el.focus();
			}
			catch (ex)
			{
			}
		}
	}
	catch (ex)
	{
		signal('setFocus', ex);
	}
}
//--------------------------------------------------------------------------------------------
function initGameSearch(gameid, sid)
{
	try
	{
		var url = 'betinput.aspx?cmd=repeat&query=' + gameid + '&sid=' + sid;
		signal(url);
		parent.content_frame.location.href = url;
	}
	catch (ex)
	{
		signal('initGameSearch', ex);
	}
}
//--------------------------------------------------------------------------------------------
function refreshBetslip(gameID, oddID, SID)
{
	try
	{
		url = 'betslip.aspx?cmd=add_odd&odd=' + oddID + '&game=' + gameID + '&sid=' + SID;
		//signal('refresh betslip: game=' + gameID + ' odd='+ oddID + ' sid=' + SID);
		//signal('href: ' + url);
		parent.betslip_frame.location.href = url;
	}
	catch (ex)
	{
		signal('refreshBetslip', ex)
	}
}
//--------------------------------------------------------------------------------------------
//reloads the contentframe with a new session id. (used when session has expired and betslip is updated)
function reloadContent(url)
{
	try
	{
		//signal('reload:' + url);
		parent.window.location.href = url;
	}
	catch (ex)
	{
		signal('reloadContent', ex)
	}
}
//--------------------------------------------------------------------------------------------
//show leagues for given sportid
function showSport(id, isLive)
{
	try
	{
		var sport = $("sport_" + id);
		var sportHeader = $("sportheader_" + id);
		sport.style.display = "";
		sportHeader.style.display = "none";
		setItemCollapsedState('sport_' + id, 0, isLive ? "livebet.aspx" : null);
		OnExecResize();
	}
	catch (ex)
	{
		signal('showSport', ex)
	}
}
//--------------------------------------------------------------------------------------------
//hide leagues for given sportid
function hideSport(id, isLive)
{
	try
	{
		var sport = $("sport_" + id);
		var sportHeader = $("sportheader_" + id);
		sport.style.display = "none";
		sportHeader.style.display = "";
		setItemCollapsedState('sport_' + id, 1, isLive ? "livebet.aspx" : null);
		OnExecResize();
	}
	catch (ex)
	{
		signal('hideSport', ex)
	}
}
//--------------------------------------------------------------------------------------------
function toggleAllLeagues(sportID)
{
	var sport = $("sport_" + sportID);
	var buttons = document.getElementsByClassName("tl_" + sportID);
	try
	{
		if (sport == null || buttons.length == 0) return;
		if (buttons[0].hasClassName('checked'))
		{
			for (var i = 0; i < buttons.length; i++)
			buttons[i].removeClassName('checked');
			setLeagues(sport, false);
		}
		else
		{
			for (var i = 0; i < buttons.length; i++)
			buttons[i].addClassName('checked');
			setLeagues(sport, true);
		}
	}
	catch (ex)
	{
		signal('toggleAllLeagues', ex)
	}
}
//--------------------------------------------------------------------------------------------
function setLeagues(sport, state)
{
	try
	{
		//var sport= $("sport_" + sportID);
		var leagues = sport.getElementsByTagName('input');
		for (var i = 0; i < leagues.length; i++)
		{
			var el = leagues[i];
			if (el.name == 'league') el.checked = state;
		}
	}
	catch (ex)
	{
		signal('setLeagues', ex)
	}
}
//--------------------------------------------------------------------------------------------
function showBet(id)
{
	try
	{
		if (document.getElementById)
		{
			betRowX = document.getElementById("bet_rowx_" + id);
			betRowY = document.getElementById("bet_rowy_" + id);
			betRowZ = document.getElementById("bet_rowz_" + id);
			betRowX.style.display = 'none';
			betRowY.style.display = '';
			betRowZ.style.display = '';
		}
	}
	catch (ex)
	{
		signal('showBet', ex)
	}
}
//--------------------------------------------------------------------------------------------
function hideBet(id)
{
	try
	{
		if (document.getElementById)
		{
			betRowX = document.getElementById("bet_rowx_" + id);
			betRowY = document.getElementById("bet_rowy_" + id);
			betRowZ = document.getElementById("bet_rowz_" + id);
			betRowX.style.display = '';
			betRowY.style.display = 'none';
			betRowZ.style.display = 'none';
		}
	}
	catch (ex)
	{
		signal('hideBet', ex)
	}
}
//--------------------------------------------------------------------------------------------
function getSpecialGameTipps(originalRequest)
{
	try
	{
		if (originalRequest.responseText == 'refresh') timeOut();
		else OnExecResize();
	}
	catch (ex)
	{
		signal('getSpecialGameTipps(AJAX)', ex)
	}
}
//--------------------------------------------------------------------------------------------
function toggleGame(id, rowClass, showAll)
{
	try
	{
		var gameRow = $("game_" + id);
		var specialsRow = $("specialtipptypes_" + id);
		var gameLink = document.getElementByClassName("specialTippTypesToggle", gameRow);
		var specialTippsID = "special_tipps_" + id;
		var specialTippsField = $(specialTippsID);
		showAll = (showAll == null) ? "0" : showAll;
		if (specialsRow.hasClassName('empty'))
		{
			specialsRow.removeClassName('empty');
			var params = 'sid=' + sessionID + '&cmd=load_specials' + '&game=' + id + '&showall=' + showAll;
			var req = new Arland.Updater(
			{
				success: specialTippsID
			}, 'content.aspx', {
				method: 'get',
				parameters: params,
				onFailure: ajaxUpdateFailure,
				onComplete: getSpecialGameTipps
			});
		}
		Arland.Console.Log(gameRow);
		Arland.Console.Log(gameLink);
		if (gameRow.hasClassName('details'))
		{
			Arland.Console.Log("hiding");
			specialsRow.hide();
			gameLink.removeClassName('game_hide');
			gameLink.addClassName('game_show');
			gameRow.removeClassName('details');
		}
		else
		{
			Arland.Console.Log("showing");
			gameRow.addClassName('details');
			specialsRow.show();
			gameLink.addClassName('game_hide');
			gameLink.removeClassName('game_show');
		}
		OnExecResize();
	}
	catch (ex)
	{
		signal('toggleGame', ex);
	}
}
//--------------------------------------------------------------------------------------------
function setOdd(id)
{
	try
	{
		var oddCell = parent.content_frame.document.getElementById('odd_' + id);
		if (oddCell == null) return;
		if (oddCell.className == 'selected_odd') resetOdd(id);
		else oddCell.className = 'selected_odd';
	}
	catch (ex)
	{
		signal('setOdd', ex)
	}
}
//--------------------------------------------------------------------------------------------
function resetOdd(id)
{
	try
	{
		top.MainNotificationCenter.notify("ClearOdd", {
			oddId: id
		});
		var oddCell = parent.content_frame.document.getElementById('odd_' + id);
		if(oddCell)
			oddCell.className = 'odd';
	}
	catch (ex)
	{
		signal('reset Odd', ex)
	}
}
//--------------------------------------------------------------------------------------------
function resetLiveOdd(id)
{
	try
	{
		var oddCell = parent.content_frame.document.getElementById('odd_' + id);
		oddCell.className = 'live_odd';
	}
	catch (ex)
	{
		signal('reset Live Odd', ex)
	}
}
//--------------------------------------------------------------------------------------------
function toggleOdd(id, oddreportId)
{
	try
	{
		var oddCell = $((oddreportId ? oddreportId + "_" : "") + 'odd_' + id);
		//signal(oddCell.className);
		if (oddCell != null)
		{
			if (oddCell.className == 'selected_odd')
			{
				top.MainNotificationCenter.notify("ClearOdd", {
					oddId: id
				});
				oddCell.className = 'odd';
			}
			else
			{
				top.MainNotificationCenter.notify("AddOdd", {
					oddId: id
				});
				oddCell.className = 'selected_odd';
			}
		}
	}
	catch (ex)
	{
		signal('toggleOdd:' + ex.message);
	}
}
//--------------------------------------------------------------------------------------------
function toggleLiveOdd(id)
{
	try
	{
		var oddCell = $('odd_' + id);
		//signal(oddCell.className);
		if (oddCell != null)
		{
			if (oddCell.className == 'selected_odd')
			{
				oddCell.className = 'live_odd';
			}
			else
			{
				oddCell.className = 'selected_odd';
			}
		}
	}
	catch (ex)
	{
		signal('toggleOdd:' + ex.message);
	}
}
//--------------------------------------------------------------------------------------------
function setOddState(oddID, state)
{
	try
	{
		var url = 'content.aspx';
		var pars = 'sid=' + sessionID + '&cmd=toggle_odd' + '&id=' + oddID + '&state=' + state;
		var myAjax = new Ajax.Request(url, {
			method: 'get',
			parameters: pars
		});
	}
	catch (ex)
	{
		signal('setOddState:' + ex.message);
	}
}
//--------------------------------------------------------------------------------------------
function clearAllSelectedOdds()
{
	top.MainNotificationCenter.notify("ClearAllOdds", {
	});
	try
	{
		if (parent.content_frame != null && parent.content_frame.document != null) var arr = parent.content_frame.document.getElementsByClassName('selected_odd');
		if (arr != null) arr.each(function(str)
		{
			str.className = 'odd';
		});
	}
	catch (ex)
	{
		signal('clearAllSelectedOdds', ex)
	}
}
//--------------------------------------------------------------------------------------------
function clearOdd(id)
{
	try
	{
		top.MainNotificationCenter.notify("ClearOdd", {
			oddId: id
		});
		var oddCell = parent.content_frame.document.getElementById('odd_' + id);
		if (oddCell != null) oddCell.className = 'odd';
	}
	catch (ex)
	{
		signal('clearOdd:' + ex.message);
	}
}
//--------------------------------------------------------------------------------------------
function checkBox(id)
{
	try
	{
		var check = $(id);
		check.checked = true;
/*if(check != null)
		{
	  		if (check.checked == false)
	  			check.checked = true;
			else
				 check.checked=false;
		}*/
	}
	catch (ex)
	{
		signal('checkBox', ex)
	}
}
//--------------------------------------------------------------------------------------------
function toggleItem(id)
{
	try
	{
		var boxHeader = $(id + "_header");
		var boxContent = $(id + "_content");
		var boxIcon = $(id + "_icon");
		if (boxHeader != null && boxContent != null)
		{
			if (boxContent.style.display == "")
			{
				boxContent.style.display = "none";
				setItemCollapsedState(id, 1);
				if (boxIcon != null)
				{
					boxIcon.src = 'img/live_arrow_white_down.gif';
				}
			}
			else
			{
				boxContent.style.display = "";
				setItemCollapsedState(id, 0);
				if (boxIcon != null)
				{
					boxIcon.src = 'img/live_arrow_white_up.gif';
				}
			}
			OnExecResize();
		}
	}
	catch (ex)
	{
		signal('toggleItem', ex)
	}
}
//--------------------------------------------------------------------------------------------
//AJAX
function setItemCollapsedState(itemID, state, url)
{
	try
	{
		url = url ? url : 'default.aspx';
		var pars = 'sid=' + sessionID + '&cmd=collapse' + '&id=' + itemID + '&state=' + state;
		var myAjax = new Ajax.Request(url, {
			method: 'get',
			parameters: pars
		});
	}
	catch (ex)
	{
		signal('setItemCollapsedState', ex)
	}
}
//--------------------------------------------------------------------------------------------
function ajaxUpdateFailure(request)
{
	try
	{
		var updater = (parent.liveContentUpdater != null) ? parent.liveContentUpdater : liveContentUpdater;
		if (updater != null && updater.frequency > 0)
		{
			signal('stopping updater');
			updater.stop();
			updater.frequency = 0;
			Element.update('liveslb', '<p>Service not available! Please try again later.</p>');
			var ol = parent.content_frame.document.getElementById('liveoddlist');
			if (ol != null)
			{
				Element.update(ol, '<p>xService not available! Please try again later.</p>');
				parent.content_frame.OnExecResize();
			}
			top.window.document.location.href = 'default.aspx?sid=' + sessionID;
		}
	}
	catch (ex)
	{
		signal('ajaxUpdateFailure', ex)
	}
}
//--------------------------------------------------------------------------------------------
function disableEvents()
{
	try
	{
		top.content_frame.document.onclick = function()
		{
			return false;
		};
		top.document.onclick = function()
		{
			return false;
		};;
		document.onclick = function()
		{
			return false;
		};;
		top.content_frame.document.keypress = function()
		{
			return false;
		};;
		top.document.keypress = function()
		{
			return false;
		};;
		document.keypress = function()
		{
			return false;
		};
		if (parent.liveContentUpdater) parent.liveContentUpdater.stop();
	}
	catch (ex)
	{
		signal('disableEvents:' + ex.message);
	}
	return false;
}
//--------------------------------------------------------------------------------------------
function refreshObject(tagID, url, pars, f)
{
	try
	{
		var req = new Ajax.PeriodicalUpdater(tagID, url, {
			method: 'post',
			asynchronous: true,
			frequency: f,
			parameters: pars,
			onSuccess: successs,
			onSubmit: submitRefresh
		});
	}
	catch (ex)
	{
		signal(ex.message);
	}
}

function successs()
{
	OnExecResize();
	signal('refreshed:' + originalRequest.responseText);
}

function submitRefresh()
{
	signal('starting refresh');
}
//--------------------------------------------------------------------------------------------
function signal(msg, error)
{
	Arland.Console.Log(msg);
	if (error) Arland.Console.Log(error);
}
//--------------------------------------------------------------------------------------------
function OnExecResizenew()
{
	var iframeWindow = window;
	signal(iframeWindow);
	if (iframeWindow == null) iframeWindow = parent.window;
	if (iframeWindow == null) return;
	try
	{
		if (iframeWindow.document.height) // ns6
		{
			var iframeElement = document.getElementById(iframeWindow.name);
			if (iframeElement.style != null) iframeElement.style.height = iframeWindow.document.height + 'px';
		}
		else if (document.all) //ie
		{
			var iframeElement = document.all[iframeWindow.name];
			if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') //Back ckompliant
			{
				if (iframeElement.style != null) iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 'px';
			}
			else //CSS1compliant
			{
				if (String(iframeElement) != "undefined")
				{
					if (iframeElement.style != null) iframeElement.style.height = iframeWindow.document.body.scrollHeight + 'px';
				}
			}
		}
	}
	catch (ex)
	{
		signal('onexecresizenew', ex)
	}
}
//--------------------------------------------------------------------------------------------
function OnExecResize(height)
{
	try
	{
		if (parent != null && parent.document != null && window.name != '')
		{
			var iframe = parent.document.getElementById(window.name);
			if (iframe != null)
			{
				iframeHeight = null;
				if (height) iframeHeight = height;
				else
				{
					if (Arland.BrowserInfo.Browser == Arland.BrowserInfo.Browsers.MSIE) iframeHeight = document.body.scrollHeight;
					else iframeHeight = document.body.offsetHeight;
				}
				iframe.style.height = iframeHeight + "px";
			}
		}
	}
	catch (ex)
	{
		signal('onExecResize', ex)
	}
}
//--------------------------------------------------------------------------------------------
function showProgress(progressTitle, progressMessage)
{
	try
	{
		if (progressMessage == null || progressMessage == '') progressMessage = 'Loading data...';
		if (progressTitle == null || progressTitle == '') progressTitle = 'Please wait';
		var doc = parent.content_frame.document.body;
		var msg = '<div class="box"><div class="box_header"><h1>&#187; ' + progressTitle + '</h1></div><div class="box_content"><p><img id="pro" class="progress" alt="loading data"  src="img/icon_progress.gif"/>' + progressMessage + '</p></div><div class="box_footer"><div class="footer_corner"></div></div></div>';
		doc.innerHTML = msg;
	}
	catch (ex)
	{
		signal('showProgress', ex)
	}
}
//--------------------------------------------------------------------------------------------
function toggleTempBet(id)
{
	var tbd = $('betdetails_' + id);
	if (tbd != null)
	{
		if (tbd.hasClassName('hidden')) tbd.removeClassName('hidden');
		else tbd.addClassName('hidden');
	}
	OnExecResize();
}
//--------------------------------------------------------------------------------------------
function setMobileBrand(selector)
{
	if (selector != null)
	{
		var button = $('submitButton');
		button.disabled = true;
		button.hide();
		var option = selector.options[selector.selectedIndex];
		document.location.href = 'mobile.aspx?cmd=setbrand&brand=' + option.value;
	}
}
//--------------------------------------------------------------------------------------------
function setMobileLanguage(selector)
{
	if (selector != null)
	{
		var button = $('submitButton');
		button.disabled = true;
		button.hide();
		var option = selector.options[selector.selectedIndex];
		document.location.href = 'mobile.aspx?cmd=setlanguage&lang=' + option.value;
	}
}
//--------------------------------------------------------------------------------------------
function updateChargedAmount(amount)
{
	var label = $('chargedAmountLabel');
	var amountField = $('amount');
	var fee = $('transactionFee');
	if (isNaN(amount) || fee == null)
	{
		Element.update(label, '0.00');
		amountField.value = '0.00';
		amountField.focus();
		return;
	}
	amount = parseFloat(amount);
	if (amount < 0)
	{
		Element.update(label, '0.00');
		amountField.value = '0.00';
		amountField.focus();
		return;
	}
	fee = fee.value;
	var newAmount = (fee / 100) * amount + amount;
	Element.update(label, newAmount.toFixed(2));
}
//--------------------------------------------------------------------------------------------
function createWindow(url, width, height)
{
	return createWindow(url, width, height, null);
}
function createWindow(url, width, height, targetName)
{
	return createWindow(url, width, height, targetName, 0);
}
function createWindow(url, width, height, targetName, scrollbars)
{
	var features = 'toolbar=0,scrollbars=' + scrollbars + ',menubar=0,location=0,resizable=no,directories=0,status=0,left=0,top=0,width=' + width + ',height=' + height;
	var targetName = (targetName != null) ? targetName : 'Popup';
	return window.open(url, targetName, features);
}

function openBetradarStats(matchId, lang)
{
	var url = document.betradarStatsUrl + matchId;
	if (lang) url += "&language=" + lang;
	var w = createWindow(url, 960, 600, "betradarstats", "toolbar=0,scrollbars=0,menubar=0,lcoation=0,resizable=yes,directories=0,status=0");
	w.focus();
}
