// Global variables
var DEBUG=true;
var nextField='';
var BC= null;

RegisterNamespace("Arland.Configuration.Casino");
RegisterNamespace("Arland.Configuration");


var Console = {
	Log: function(msg)
	{
		if("console" in window)
			console.log(msg);

		var cons = document.getElementById("console");
		if (cons)
		{
			cons.appendChild(document.createTextNode(msg));
			cons.appendChild(document.createElement("br"));
		}
	}
}


Arland.Configuration.SportLeaguebrowser = {
  SportTippCountDelay: 500,
  LeagueTippCountDelay: 500
};

Arland.Configuration.BetCounter = {
  Refresh: 20,
  Enabled: true
}

// Debugger stub
Arland.Debugger = 
{
	Log: function(msg){}
};

// 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.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");
			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: " + t);
	}
});

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();

//--------------------------------------------------------------------------------------------
Arland.Configuration.BetCounter = {
  Refresh: 20,
  Enabled: true
}

var BetCounter= Class.create(Arland.Control,
{
	initialize: function($super, id, sid)
  	{
		$super(id);
  		try
    	{
			if(this.container!=null)
			{
	    		this.counter= this.container.getElementsByTagName('span')[0];
	    		this.sessionID= sid;
	    		this.updateExecutor=null;
				if("BetCounter" in Arland.Configuration)
				{
					if(Arland.Configuration.BetCounter.Enabled)
					{
						this.cycleTime= Arland.Configuration.BetCounter.Refresh;
						this.init();
					}
					else
						this.cycleTime= 0;
				}
	    	}
		}
		
		catch(ex)
		{
			signal('Exception in constructor of BetStatistics ' + id + ': ' + ex.message);
		}
    	
	},
	
	
	init: function()
	{
    	if(this.cycleTime >0)
    		this.Start();
    	else
    		this.Stop();
	},
	
	
	Start: function()
  	{
  		if(this.updateExecutor==null)
  		{
  			this.updateExecutor= new PeriodicalExecuter((function() {this.Refresh()}).bind(this), this.cycleTime);
  		}
  	},
  	
  	
  	Stop: function()
  	{
  		if(this.updateExecutor!=null)
  		{
  			this.updateExecutor.stop();
  			this.updateExecutor= null;
  		}  		
  	},
	
	
	Refresh: function()
	{
		try
		{
			var queryString= 'cmd=getbetcount&sid=' + this.sessionID; 
			new Ajax.Request('default.aspx',{method:'post', parameters: queryString, onComplete:this.requestComplete.bind(this), onTimeout:this.requestFailure.bind(this), onFailure:this.requestFailure.bind(this)});
		}
		
		catch(ex)
		{
			signal('Refresh: ' + ex.message);
		}
	},
	
	
	requestComplete: function(request)
	{
		try
		{
			
			var response= request.responseText;
      		if (response!=null)
      		{
      			if(response=='refresh')
      			{
      				this.Stop();
      				this.counter.innerHTML= 'N/A';
      				signal('timeout detected');
      				reloadContent('default.aspx');
      			}
      			
      			var newValue= parseInt(response);
      			var oldValue= parseInt(this.counter.innerHTML);
      			
      			//signal('new value: ' + newValue + ', old value= ' + oldValue);					
      			if(!isNaN(newValue))
      			{ 
      				if(newValue != oldValue)
      				{
      					this.counter.innerHTML= newValue;
      					new Effect.Highlight(this.container, {duration: 4.5, startcolor:'#aa1f27'});
      				}
      				
      				if(newValue>0)
      					this.counter.className= 'highlight';
					else
      					this.counter.className= '';
      			}
      		}
      	}
      	
      	catch(ex)
      	{
      		signal('requestComplete: ' + ex.message);
      	}
	},
	
	
	requestFailure: function()
	{
		this.counter.innerHTML= 'N/A';
	}
});

// 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 + "={};");
	}
}

//--------------------------------------------------------------------------------------------
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.message);
	}							
}

//--------------------------------------------------------------------------------------------
function timeOut()
{
	try
	{
		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.message);
	}
}

function refreshCustomer(sessionID)
{
	try
	{						
		parent.document.location.href = 'default.aspx?cmd=refreshcustomer&sid=' + sessionID;
	}	
	catch(ex)
	{
		signal('refreshCustomer: ' + ex.message);
	}
}



//--------------------------------------------------------------------------------------------
function updateSaldo (saldoString)
{
	try
	{
		var saldo= parent.document.getElementById('saldo');
		if(saldo!=null && saldoString !=null)
			saldo.innerHTML= saldoString;
	}
	
	catch(ex)
	{
		signal('updateSaldo: ' + ex.message);
	}
}

//--------------------------------------------------------------------------------------------
function updateOpenBets(betCount)
{

	try
	{
		var openBets= parent.document.getElementById('openBets');
		if(openBets != null)
			openBets.innerHTML=betCount;
		
	}	
	catch(ex)
	{
		signal('updateSaldo: ' + ex.message);
	}
}


//--------------------------------------------------------------------------------------------
function setFocus(id) {
	
	try
	{
		if (document.getElementById) {
			
			try {
				var el= document.getElementById(id);
				el.focus();
			}
			catch(ex) {}
		}
	}
	
	catch(ex)
	{
		signal('setFocus: ' + ex.message);
	}
}


//--------------------------------------------------------------------------------------------
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.message);
	}
}


//--------------------------------------------------------------------------------------------
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.message);
	}
}




//--------------------------------------------------------------------------------------------
//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.message);
	}
}



//--------------------------------------------------------------------------------------------
//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.message);
	}
}


//--------------------------------------------------------------------------------------------
//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.message);
	}
}


//--------------------------------------------------------------------------------------------
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.message);
	}
}


//--------------------------------------------------------------------------------------------
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.message);
	}
}


//--------------------------------------------------------------------------------------------
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.message);
	}
		
}


//--------------------------------------------------------------------------------------------
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.message);
	}
}


//--------------------------------------------------------------------------------------------
function getSpecialGameTipps(originalRequest)
{
	try
	{
		Console.Log("getSpecialGameTipps");
		if(originalRequest.responseText=='refresh')
			timeOut();
		else		
			OnExecResize();
	}
	
	catch(ex)
	{
		signal('getSpecialGameTipps(AJAX): ' + ex.message);
	}
}


//--------------------------------------------------------------------------------------------
function toggleGame(id, rowClass,showAll) {
	
	try
	{
		var gameRow= $("game_" + id);
		var specialsRow= $("specialtipptypes_" + id);
		var gameLink= gameRow.down('.specialCount a');
		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} );
		}
		
		
		if(gameRow.hasClassName('details'))
		{
			specialsRow.style.display= 'none';
			gameLink.className= 'game_show';
			gameRow.removeClassName('details');
		}
		else
		{
			gameRow.addClassName('details');
			specialsRow.style.display= '';
			gameLink.className= 'game_hide';
		}
		
		OnExecResize();
	}
	
	catch(ex)
	{
		signal('toggleGame:' + ex.message);
	}
}


//--------------------------------------------------------------------------------------------
function setOdd(id)
{
	try
	{
		var oddCell= parent.content_frame.document.getElementById('odd_' + id);
		if(oddCell.className=='selected_odd')
			resetOdd(id);
		else
			oddCell.className='selected_odd';
	}
	catch(ex)
	{
		signal('setOdd: ' + ex.message);
	}
	
}


//--------------------------------------------------------------------------------------------
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.message);
	}
}

//--------------------------------------------------------------------------------------------
function resetLiveOdd(id)
{
	try
	{
		var oddCell= parent.content_frame.document.getElementById('odd_' + id);
		oddCell.className='live_odd';
	}
	catch(ex)
	{
		signal('reset Live Odd: ' + ex.message);
	}
}

//--------------------------------------------------------------------------------------------
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 
			{
				Console.Log("notify AddOdd, oddId = " + id);
				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= $A(parent.content_frame.document.getElementsByClassName('selected_odd'));
			
			if(arr!=null)
				arr.each(function(str){str.className='odd';});
		}
	}
	
	catch(ex)
	{
		signal('clearAllSelectedOdds: ' + ex.message);
	}
}


//--------------------------------------------------------------------------------------------
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.message);
	}
} 



//--------------------------------------------------------------------------------------------
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.message);
	}
}


//--------------------------------------------------------------------------------------------
//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.message);
	}
}

//--------------------------------------------------------------------------------------------
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.message);
	}
	
}



//--------------------------------------------------------------------------------------------
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)
{
	if(DEBUG)
	{
		Console.Log(msg);
	}
}



//--------------------------------------------------------------------------------------------
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.message);
	}
}


//--------------------------------------------------------------------------------------------
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
				{
					iframeHeight = document.body.scrollHeight;
				}
				iframe.style.height = iframeHeight + "px";
			}
		}
	}
	
	catch(ex)
	{
		signal('onExecResize: ' + ex.message);
	}
}


//--------------------------------------------------------------------------------------------
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.message);
	}
}


//--------------------------------------------------------------------------------------------
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)
{							
   	var w = createWindow(url,width,height,null);
   	return w;
}
function createWindow(url,width,height,targetName)
{							
 var w = createWindow(url,width,height,targetName,0);
 return w;
}
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';
   var wopen = window.open(url,targetName,features);
   return wopen;    
}

Event.observe(window, "load", function () {
	$$('.hsTarget').each(function(link)
	{
		Event.observe(link,'click',function(e)
		{
			Event.stop(e);
			return hs.htmlExpand(link, {objectType: 'iframe', objectHeight:1600});
		}.bind(this));
	},this);
	
	$$('.ttTarget[rel]').each(function(element)
	{
		var s= element.getAttribute('sel');
		var t= element.getAttribute('title');
		element.setAttribute('title','');
		s= s!=null? s: 'custom';
		new Tip(element,element.getAttribute('rel'),{style: s, title: t});
	},this);
});




function openBetradarStats(matchId, lang)
{
	var url = document.betradarStatsUrl + matchId;
	if (lang) url += "&language=" + lang;
	var w = window.open(url, "betradarstats", "toolbar=no,scrollbars=yes,menubar=no,location=no,resizable=yes,status=no,width=980,height=600");
	w.focus();
}
