<!--

// validation timeout
if (isNaN(tempCheckTimeout))
{
	var tempCheckTimeout = 1000;
}

function urlencode(str) {
    return escape(str).replace(/\+/g,'%2B').replace(/\//g, '%2F');
}

function SendRequest(sentData, context)
{
    var hashField = document.getElementById('__hash');
	if (hashField != null)
	{
	    sentData += "&__hash=" + urlencode(hashField.innerHTML);
	}

	var url = '/ProcessAjax.aspx';
	var httpRequest = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
	if (!httpRequest) {return false;}	
	httpRequest.open("POST", url, true);
	httpRequest.onreadystatechange= function () {ProcessRequest(httpRequest, sentData, context);};
	httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	httpRequest.send(sentData);
	return true;
}

function ProcessRequest(httpRequest, sentData, context)
{
	if (httpRequest.readyState == 4)
	{		
		if (httpRequest.status != 200)
		{
			if (window.ShowDebugInformation)
			{
				ShowDebugInformation(httpRequest.responseText);
			}
		}
		
		if (httpRequest.status == 200)
		{		
			var parameters = ParseQueryString(sentData);
			if (parameters["cmd"] == null)
			{
				return;
			}
			
			var command = parameters["cmd"];
			
			if (command == 'CouponSubmit')
			{
				var couponContent = document.getElementById("CouponContainer");
				if (couponContent != null)
				{
					couponContent.innerHTML = httpRequest.responseText;
				}

				var resetElement = document.getElementById('ResetAll');
				if (resetElement != null && resetElement.value == 'true')
				{
					UnselectAllTips();
				}
                // refresh vzdy, pri uspesnem i neuspesnem podani sazenky
				window.location.href = window.location.href;
			}
			
			if (command == 'CouponReset')
			{
				var couponContent = document.getElementById("CouponContainer");
				if (couponContent != null)
				{
					couponContent.innerHTML = httpRequest.responseText;
				}

				UnselectAllTips();
				coupon1.removeAll();
			}

			if (command == 'CouponDeleteTip')
			{
				var couponContent = document.getElementById("CouponContainer");
				if (couponContent != null)
				{
					couponContent.innerHTML = httpRequest.responseText;
				}
				
				// dekrement citace aktivnich requestu (pouze akce Pridat/odebrat tip z tiketu)
                oddsAddDeleteTipRequestCount = oddsAddDeleteTipRequestCount > 0 ? oddsAddDeleteTipRequestCount - 1 : 0;
                // pokud jiz neni zadny aktivni request, tak spustime casovac, ktery zajisti volani requestu validace tiketu
                if (oddsAddDeleteTipRequestCount == 0)
                {
                    oddsClickTimerId = setTimeout("ValidateCoupon()", tempCheckTimeout);
                }
                
                // nacteme lineId
                var lineId = null;
				if (parameters["i"] != null)
				{
				    var tipIdentifier = parameters["i"];
				    lineId = coupon.lineID(tipIdentifier);
				}
                
                /////////
                // ve fronte je ulozeny dalsi klik - posleme request a vyprazdnime frontu
                if (lineId != null && oddsClickQueue[lineId] != null && oddsClickQueue[lineId].changed)
                {
                    oddsClickQueue[lineId].changed = false;
                    OddsSetTip(oddsClickQueue[lineId].element);
                }
                // pokud po tomto requestu zadny dalsi klik neprisel, tak frontu k danemu radku vyprazdnime
                else
                {
                    oddsClickQueue[lineId] = null;
                }
                /////////
			}

			if (command == 'CouponAddTip' || command == 'CouponAddTipAndSetTip')
			{
				var couponContent = document.getElementById("CouponContainer");
				if (couponContent != null)
				{
					couponContent.innerHTML = httpRequest.responseText;
				}
				
				/////////
                // dekrement citace aktivnich requestu (pouze akce Pridat/odebrat tip z tiketu)
                oddsAddDeleteTipRequestCount = oddsAddDeleteTipRequestCount > 0 ? oddsAddDeleteTipRequestCount - 1 : 0;
                // pokud jiz neni zadny aktivni request, tak spustime casovac, ktery zajisti volani requestu validace tiketu
                if (oddsAddDeleteTipRequestCount == 0)
                {
                    oddsClickTimerId = setTimeout("ValidateCoupon()", tempCheckTimeout);
                }
                /////////
				
				/////////
				// odznaci se stary tip - v contextu je ulozen identifikator predchoziho tipu
                if (context != null) {
                    SetTipUnselected(document.getElementById('i' + context));
                }

                // nacteme lineId a oznacime tip
                var lineId = null;
				if (parameters["i"] != null)
				{
				    var tipIdentifier = parameters["i"];
				    lineId = coupon.lineID(tipIdentifier);
				    
				    // oznaci se novy tip
                    SetTipSelected(document.getElementById('i' + tipIdentifier));
				}
				/////////
                
                /////////
                // ve fronte je ulozeny dalsi klik - posleme request a vyprazdnime frontu
                if (lineId != null && oddsClickQueue[lineId] != null && oddsClickQueue[lineId].changed)
                {
                    oddsClickQueue[lineId].changed = false;
                    OddsSetTip(oddsClickQueue[lineId].element);
                }
                // pokud po tomto requestu zadny dalsi klik neprisel, tak frontu k danemu radku vyprazdnime
                else
                {
                    oddsClickQueue[lineId] = null;
                }
                /////////
                
			}
			if (command.length > 6 && command.substring(0, 6) == 'Coupon' && command != 'CouponAddTip' && command != 'CouponAddTipAndSetTip')
			{
				var couponContent = document.getElementById("CouponContainer");
				if (couponContent != null)
				{
					couponContent.innerHTML = httpRequest.responseText;
					if (command == 'CouponValidate')
					{
						NumberShieldDown();
					}
				}
				if (command != 'CouponRevalidate' && command != 'CouponValidate')
				{
					ProcessFocus();
				}
			}
			
			if (command == 'CategoryExpand')
			{
				var arrowImage = document.getElementById('cim' + parameters["i"]);
				var subCategoryDiv = document.getElementById('csc' + parameters["i"]);
				if (arrowImage != null && subCategoryDiv != null)
				{
					arrowImage.src = arrowImage.src.replace('ArrowRight', 'ArrowDown');
					subCategoryDiv.innerHTML = httpRequest.responseText;
					subCategoryDiv.style.display = "block"
				}
			}
			
			if (command =='RegionCollapse')
			{
				var subRegionDiv = document.getElementById(parameters["e"]);
				
				if (subRegionDiv != null)
				{
					subRegionDiv.innerHTML = httpRequest.responseText;
					// dotahneme si informace o terminalech ve zvolenem regionu - pokud se to volalo "soubezne", tak to nefungovalo
					SendRequest('cmd=TerminalCollapse&i=' + parameters["i"]);
				}
			}

			if (command =='TerminalCollapse')
			{
				var regionTerminalDiv = document.getElementById("TerminalsContainer");
				
				if (regionTerminalDiv != null)
				{
					regionTerminalDiv.innerHTML = httpRequest.responseText;
				}
			}				
		}
	}
}

function DisableCoupon()
{
	var couponContent = document.getElementById("CouponContainer");	
	var style = "opacity: 0.5;"
	var height = 50;
	var width = 50;

	if (couponContent != null && document.getElementById("workingmodepanel") == null)
	{		
		if (couponContent.style.opacity != null)
		{
			style = "opacity: 0.5;";
		}
		if (couponContent.style.filter != null)
		{
			style = "filter: alpha(opacity=50);";
		}
		if (couponContent.style.MozOpacity != null)
		{
			style = "opacity: 0.5;";
		}
	
		width = couponContent.offsetWidth;
		height = couponContent.offsetHeight;
		
		// kvuli menu musi mit kupon position - static
		// pri spracovani se zmeni na position: relative;
		couponContent.style.position = 'relative';
		
		couponContent.innerHTML += "<div id='workingmodepanel' class=\"workingmode\" style=\"" + style + " width: " + width + "px; height: " + height + "px;z-index: 300; \"><img src=\"/Skins/Default/Images/ajax_icon.gif\" align=\"middle\" style=\"position: absolute; top: 45%; left: 38%;z-index: 300;\"></div>";
	}
}

function SetTipSelected(element)
{
	if (element != null)
	{
		element.className = 'rateSelected';
	}
}

function SetTipUnselected(element)
{
	if (element != null)
	{
		var isNumerical = document.getElementById('numericalOdds');
		
		if (isNumerical != null)
		{
			element.style.color = '#DF7B03';
			element.style.fontWeight = 'bold';
			element.style.backgroundColor = '#EAEFF5';
		}
		else
		{
			element.className = 'rate';
		}
	}
}

function UnselectAllTips()
{
	var anchors = document.getElementsByTagName("td");
	var anchor;
	var elementClientId;
	for (i = 0; i < anchors.length; i++)
	{
		anchor = anchors[i];
		elementClientId = anchor.id.toLowerCase();
		if (elementClientId.substring(0, 1) == 'i')
		{
			SetTipUnselected(anchor);
		}
		else if (elementClientId.substring(0, 1) == 'b')
		{
			NewsSetTipUnselected(anchor);
		}
	}
}

function OddsMouseOver(element)
{
	if (element != null)
	{
	    if (element.className == 'rateSelected')
		{
		    element.className = 'rateSelectedHover';
		}
		else
		{
			element.className = 'rateHover';
		}
	}
}
function OddsMouseOut(element)
{
    if (element != null)
	{
	    if (element.className == 'rateSelectedHover' || element.className == 'rateSelected')
		{
		    element.className = 'rateSelected';
		}
		else
		{
			element.className = 'rate';
		}
	}
}

function ParseQueryString(queryString)
{
	var parameters = queryString.split("&"); 
	var parameterArray = new Array(); 
	for(i = 0; i < parameters.length; i++)
	{
		parameterArray[parameters[i].split("=")[0]] = unescape(parameters[i].split("=")[1]); 
	}
	return parameterArray;
}

function ProcessFocus()
{
	var amount = document.getElementById('amount');
	if (amount != null)
	{
		amount.focus();
		return;
	}

	var username = document.getElementById('username');
	if (username != null)
	{
		username.focus();
		return;
	}

	var pin = document.getElementById('pin');
	if (pin != null)
	{
		pin.focus();
		return;
	}
}

function DisplayBalance()
{
	SendRequest('cmd=PlayerDisplayBalance');
}

////////////////////////////////////////////////////////
// ZACATEK - urychleni pridani/Odebrani tipu na kupon //
////////////////////////////////////////////////////////

// Globalni promnenna, ktera se pouziva ve funkcich:
// AddTip
// DeleteTip
// ValidateCoupon
var oddsClickTimerId = 0;

// Globalni promenna obsahujici pocet aktivnich requestu,
// ktere zajistuji pridani/odebrani tipu z tiketu.
// Pokud proběhne callback posledního aktivniho requestu, tak se spusti casovac.
// Po jeho vyprseni se zavola request validace tiketu.
var oddsAddDeleteTipRequestCount = 0;

// Global variable for timer. Used in:
// OddsClickAndSetTipNumerical
// NumberShieldDown
var numberShieldTimer = 0;

// Globalni promenna, ktera udrzuje frontu kliku na tipy.
// Nutnost pouzit frontu je zalozena na problemu, kdy klikneme ihned po sobe na vice tipu v ramci jedne hry a udalosti
// a vysleme tak temer soucasne nekolik pozadavku na server. Ovsem tyto pozadavky nemusi prijit na server
// ve spravnem poradi.
// Po kliku na tip se tedy neprovede request na server okamzite, ale nejdrive se pomoci teto fronty zkontroluje,
// zda jiz nejaky jiny request v ramci teto hry nebyl vyslan na server. Pokud ano, tak se vlozi do fronty.
// Po skonceni predchoziho requestu se automaticky posle request s poslednim vybranym tipem v ramci hry a udalosti.
var oddsClickQueue = new Array();

// polozka fronty kliku - obsahuje element, od ktere prisel klik. Pokud je changed false, tak patri aktivnimu requestu -
// nebudeme vysilat dalsi request. Pokud je true, tak po odeslani prisel jeste dalsi klik - musime vykonat request.
function OddsClickQueueItem(el, changed)
{
    this.element = el;
    this.changed = changed;
}


function OddsClickAndSetTip(element)
{
    if (element == null) return;

    var tipIdentifier = element.id.substring(1);
    var lineId = coupon.lineID(tipIdentifier);
    
    // jiz byl vyslan request s tipem v ramci tohoto radku (hry a udalosti) - ulozime si posledni tip
    if (oddsClickQueue[lineId] != null)
    {
        oddsClickQueue[lineId] = new OddsClickQueueItem(element, true);
    }
    // zadny request v ramci tohoto radku nyni neni odeslan na server - muzeme poslat request
    else
    {
        oddsClickQueue[lineId] = new OddsClickQueueItem(element, false);
        OddsSetTip(element);
    }
}

function OddsSetTip(element)
{
    if (element == null) return;

    var tipIdentifier = element.id.substring(1);
    var lineId = coupon.lineID(tipIdentifier);

    switch (coupon1.contain(tipIdentifier)) {
        // tento radek na tiketu neni - pridame do seznamu
        case 0:
            {
                // tip se prida do js objektu tiketu
                coupon1.add(tipIdentifier);
                // odeslou se data na server - akce pridat tip
                AddTip(tipIdentifier, coupon1.getLinesInfoString());
                // oznaci se novy tip az v callbacku ajax volani
            }
            break;
            
        // tento radek na tiketu je, ale s jinym tipem - nahradime stary tip novym
        case 1:
            {
                // nahradi se stary tip novym
                var oldItem = coupon1.add(tipIdentifier);
                // stary tip se odznaci v callbacku ajax volani
                // odeslou se data na server - nahradit tip
                AddTip(tipIdentifier, coupon1.getLinesInfoString(), oldItem);
                // oznaci se novy tip az v callbacku ajax volani
            }
            break;
            
        // presne tento tip jiz na tiketu je -> smazeme tip
        case 2:
            {   
                // vyradi se ze seznamu
                var position = coupon1.position(tipIdentifier);
                if (position >= 0) {
                    coupon1.remove(position);
                }
                // odesle se pozadavek na odstraneni z tiketu
                DeleteTip(element);
                // odznaci tip
                SetTipUnselected(element);
            }
            break;
    }
}

function DeleteTipClick(element)
{
    if (element == null) return;

    var tipIdentifier = element.id.substring(1);
    var lineId = coupon.lineID(tipIdentifier);
    
    switch (coupon1.contain(tipIdentifier)) {
        // presne tento tip jiz na tiketu je -> smazeme tip
        case 2:
            {   
                // vyradi se ze seznamu
                var position = coupon1.position(tipIdentifier);
                if (position >= 0) {
                    coupon1.remove(position);
                }
                // odesle se pozadavek na odstraneni z tiketu
                DeleteTip(element);
                // odznaci tip
                SetTipUnselected(document.getElementById('i' + tipIdentifier));
            }
            break;
    }
}


/* Function to operate with box above numerical tips */
function OddsClickAndSetTipNumerical(element)
{
	NumberShieldUp();
	
	numberShieldTimer = setTimeout('NumberShieldDown()', 500);
	
	OddsClickAndSetTip(element);
}

/* Creates box above numerical tips */
function CreateNumericalShield()
{
	var numericalOdds = document.getElementById('numericalOdds');

	if (numericalOdds != null)
	{
		var numberShield = document.createElement('div');
		
		numberShield.style.position = 'absolute';
		numberShield.style.bottom = '0';
		numberShield.style.left = '0';
		numberShield.style.zIndex = '300';
		numberShield.style.width = numericalOdds.offsetWidth + 'px';
		numberShield.style.height = numericalOdds.offsetHeight + 'px';
		numberShield.style.backgroundColor = 'black';
		if (numberShield.style.opacity != null)
		{
			numberShield.style.opacity = '0.1';
		}
		if (numberShield.style.filter != null)
		{
			numberShield.style.filter = "alpha(opacity=10);";
		}
		
		numberShield.setAttribute('id', 'numberShield');	
		
		numericalOdds.appendChild(numberShield);
	}
}

/* Place box above numerical tips */
function NumberShieldUp()
{
	var numberShield = document.getElementById('numberShield');
	if (numberShield != null)
	{
		numberShield.style.visibility = 'visible';
	}
	else
	{
		CreateNumericalShield();
	}
}

/* Hide box above numerical tips */
function NumberShieldDown()
{
	var numberShield = document.getElementById('numberShield');
	if (numberShield != null)
	{
		numberShield.style.visibility = 'hidden';
	}
	
	clearTimeout(numberShieldTimer);
}

function DeleteTip(element)
{
	var identifier = element.id.substring(1);
	// pokud to neni prvni klik na odebrani udalosti, tak znovu nastavime casovac na 2s a az po tom provedem TempCheck
	if (oddsClickTimerId != 0)
	{
	    clearTimeout(oddsClickTimerId);
	}
	// inkrementujeme citac aktivnich requestu
	oddsAddDeleteTipRequestCount++;
	
	SendRequest('cmd=CouponDeleteTip&i=' + identifier);
}

function AddTip(id, linesInfo, oldId)
{
    // z duvodu zrychleni se TempCheck provadi az po 2s od posledniho kliknuti
	if (oddsClickTimerId != 0)
	{
	    clearTimeout(oddsClickTimerId);
	}
	// inkrementujeme citac aktivnich requestu
	oddsAddDeleteTipRequestCount++;
	
	SendRequest('cmd=CouponAddTipAndSetTip&i=' + id + '&lines=' + linesInfo, oldId);
}

function ValidateCoupon()
{
	oddsClickTimerId = 0; // vynulujeme casovac
	SendRequest('cmd=CouponValidate');
}

function StornoAddTipAndValidate(element, image)
{
	clearTimeout(oddsClickTimerId);
	SetTipUnselected(element);
	if (image != null)
	{
		image.setAttribute('onload', '');
	}
}

//////////////////////////////////////////////////////
// KONEC - urychleni pridani/Odebrani tipu na kupon //
//////////////////////////////////////////////////////

function RefreshCoupon()
{
    DisableCoupon();
	SendRequest('cmd=CouponRefresh');
}

function ResetCoupon()
{
    DisableCoupon();
	SendRequest('cmd=CouponReset');
}

function SelectCert(objItem)
{
	var strID = objItem.id.replace('c_', '') ;
	if (objItem.checked == true)
	{ 
		SendRequest('cmd=CouponAddCert&i=' + strID);
	}
	else
	{ 
		SendRequest('cmd=CouponDeleteCert&i=' + strID);
	}
}

function SetGroup(element)
{
	if (element != null)
	{
		var identifier = element.id.substring(1);
		var setGroupValue = element.value;
		if (setGroupValue == 'MarkAsCinch')
		{
			SendRequest('cmd=CouponMarkAsCinch&i=' + identifier);
		}
		else if (setGroupValue == 'RemoveFromGroup')
		{
			SendRequest('cmd=CouponRemoveFromGroup&i=' + identifier);
		}
		else
		{
			SendRequest('cmd=CouponSetGroup&i=' + identifier + '&g=' + setGroupValue);
		}
	}
}

function RevalidateCoupon()
{
	var amount = document.getElementById("amount");

	if (amount != null)
	{
		var amountValue = amount.value.replace(',', '.');
		if (!isNaN(amountValue))
		{
		    DisableCoupon();
			SendRequest('cmd=CouponRevalidate&a=' + amountValue);
		}
	}
	else
	{
	    DisableCoupon();
		SendRequest('cmd=CouponRevalidate');
	}
}

function SetStakeAndRevalidateCoupon()
{
	var amount = document.getElementById("amount");
	var amountOld = document.getElementById("amount_oldamount");
	if (amount != null)
	{
		var amountValue = amount.value.replace(',', '.');
		var amountOldValue = 0;
		if (amountOld != null)
		{
			amountOldValue = amountOld.value.replace(',', '.');
		}
		if (amountOldValue != amountValue) // SendRequest budeme volat, jen pokud se zmenila hodnota
		{
			if (!isNaN(amountValue))
			{
				if (amountOldValue - amountValue != 0)
				{
					SendRequest('cmd=CouponRevalidate&a=' + amountValue);
				}
			}
		}
	}
}

function PrepareCoupon()
{
	var amount = document.getElementById("amount");
	if (amount != null)
	{
		var amountValue = amount.value.replace(',', '.');
		if (!isNaN(amountValue))
		{
		    DisableCoupon();
			SendRequest('cmd=CouponPrepare&a=' + amountValue);
		}
	}
	else
	{   DisableCoupon();
		SendRequest('cmd=CouponPrepare');
	}
}

function BackCoupon()
{
	SendRequest('cmd=CouponBack');
}

function SubmitCoupon()
{    
	var username = document.getElementById("username");
	var password = document.getElementById("password");
	var pin = document.getElementById("pin");
	var guid = document.getElementById("guid");

	var data = '';
	if (username != null)
	{
		data = data + '&u=' + username.value;
	}
	if (password != null)
	{
		data = data + '&p=' + password.value;
	}
	if (pin != null)
	{
		data = data + '&n=' + pin.value;
	}
	if (guid != null)
	{
		data = data + '&g=' + guid.value;
	}
	
	DisableCoupon();
	SendRequest('cmd=CouponSubmit' + data);
}

function SetCouponSimple()
{
	SendRequest('cmd=CouponSetSimple');
}

function SetCouponSetSystemCombinator()
{
	SendRequest('cmd=CouponSetSystemCombinator');
}

function SetMarketingProduct(selectedvalue)
{
	//var mprodid = document.getElementById("MrcProductsList").options[this.selectedIndex].value;
	
	var data = '&m=' + selectedvalue;	
	SendRequest('cmd=CouponSetMarketingProduct' + data);
}

function SetGameType(type)
{
	// Original coupon command
	if (type == 0) 
	{
		SendRequest('cmd=CouponSetFullCombinator');
	}
	else if (type == 1)
	{
		SendRequest('cmd=CouponSetSystemCombinator');
	}

	else if (type > 1)
	{
		var amount = document.getElementById("amount");
		if (amount != null)
		{
			var amountValue = amount.value.replace(',', '.');
			if (!isNaN(amountValue))
			{
				SendRequest('cmd=CouponSetSystemCombinator&t=' + type + '&a=' + amountValue);
			}
		}
		else
		{
			SendRequest('cmd=CouponSetSystemCombinator&t=' + type);
		}
	}
}

function SetCardinalityAmount(type)
{
	var amount = document.getElementById('systemselection_amount_' + type);
	var amountOld = document.getElementById('systemselection_oldamount_' + type);
	if (amount != null)
	{
		var amountValue = amount.value.replace(',', '.');
		var amountOldValue = 0;
		if (amountOld != null)
		{
			amountOldValue = amountOld.value.replace(',', '.');
		}
		if (amountOldValue != amountValue) // SendRequest budeme volat, jen pokud se zmenila hodnota
		{
			if (!isNaN(amountValue))
			{
				if (amountOldValue - amountValue != 0)
				{
					SendRequest('cmd=CouponUpdateCardinalityStake&t=' + type + '&a=' + amountValue);
				}
			}
		}
	}
}

function SystemTypeChange(selectElement)
{
	if (selectElement != null)
	{
		var gameType = selectElement.value;
		SetGameType(gameType);
	}
}

function ShowCouponLoginPanel()
{
	try
	{
		var couponLoginTable = document.getElementById("CouponLoginTable");
		if (couponLoginTable != null)
		{
			couponLoginTable.style.display = "block";
			var couponLoginButtonCell = document.getElementById("CouponLoginButtonCell");
			if (couponLoginButtonCell != null)
			{
				couponLoginButtonCell.style.display = "none";
			}		
			var couponNoLoginButtonCell = document.getElementById("CouponNoLoginButtonCell");
			if (couponNoLoginButtonCell != null)
			{
				if (IsIe6OrLower())
				{
					couponNoLoginButtonCell.style.display = "block";
				}
				else
				{
					couponNoLoginButtonCell.style.display = "table-cell";
				}
			}		
			var loginInput = document.getElementById("login");
			if (loginInput != null)
			{
				loginInput.focus();
			}		
		}
	}
	catch(e)
	{}
}

function HideCouponLoginPanel()
{
	try
	{
		var couponLoginTable = document.getElementById("CouponLoginTable");
		if (couponLoginTable != null)
		{
			couponLoginTable.style.display = "none";
			var form = document.getElementById("form");
			if (form != null)
			{
				form.reset();
			}		
			var couponLoginButtonCell = document.getElementById("CouponLoginButtonCell");
			if (couponLoginButtonCell != null)
			{
				if (IsIe6OrLower())
				{
					couponLoginButtonCell.style.display = "block";
				}
				else
				{
					couponLoginButtonCell.style.display = "table-cell";
				}
			}
			var couponNoLoginButtonCell = document.getElementById("CouponNoLoginButtonCell");
			if (couponNoLoginButtonCell != null)
			{
				couponNoLoginButtonCell.style.display = "none";
			}
		}
	}
	catch(e)
	{}
}

function SetStakeSelection(selector)
{
	var amount = document.getElementById("amount");
	if (amount != null)
	{
		var amountValue = amount.value.replace(',', '.');
		if (!isNaN(amountValue))
		{
			SendRequest('cmd=CouponSetStakeSelection&i=' + selector + '&a=' + amountValue);
		}
		else
		{
			SendRequest('cmd=CouponSetStakeSelection&i=' + selector);
		}
	}
	else
	{
		SendRequest('cmd=CouponSetStakeSelection&i=' + selector);
	}
}

function CountPotentialWin(rate)
{
	var amount = document.getElementById("amount");
	var potentialWin = document.getElementById("spanpotentialwin");
	
	if (potentialWin != null && amount != null && rate != null)
	{
		if (amount.value != null)
		{
			var amountdecimal = amount.value.replace(',','.');
			var ratedecimal = rate.replace(',','.');
			if (!isNaN(amountdecimal) && !isNaN(ratedecimal))
			{
				//VP - zaokrouhlovani na 50 haleru
				var potentialWinValue = ((ratedecimal * amountdecimal) + '');
				var numbers = potentialWinValue.split('.');
				var intpart = numbers[0];
				var decpart = potentialWinValue - intpart;
				
				// je to mensi nez 0,25, tak vratime intpart
				if ((decpart - 0.25) < 0)
				{
					potentialWin.innerHTML = 	intpart + ",00";
				}
				else
				{
					// je to vetsi nez 0,25 a mensi nez 0,75, tak vratime intpart + 0,5
					if ((decpart - 0.75) < 0)
					{
						potentialWin.innerHTML = 	intpart + ",50";
					}
					// je to vetsi nez 0,75, tak vratime intpart + 1
					else
					{
						potentialWin.innerHTML = (intpart - 0 + 1) + ",00";
					}
				}
			}
		}
	}
}

function CountPotentialWinParam(rate, currencyDecimalSeparator, prizeDisplayPrecision, prizeRoundingPrecision, prizeRoundingType, maxStake)
{
	var amount = document.getElementById("amount");
	var potentialWin = document.getElementById("spanpotentialwin");
	var workingPrize;
	var i;
	var numbers;
	var intpart;
	var decpart;

	if (potentialWin != null && amount != null && rate != null && currencyDecimalSeparator != null && prizeDisplayPrecision != null && prizeRoundingPrecision != null && prizeRoundingType != null)
	{
		if (amount.value != null)
		{
			var amountdecimal = amount.value.replace(',','.');
			var ratedecimal = rate.replace(',','.');
			
			// check max stake
			if ( eval(maxStake) > 0)
			{
				if ( amountdecimal > eval(maxStake) )
				{
					amount.value = maxStake;
					amountdecimal = amount.value.replace(',','.');
				}
			}
			
			if (!isNaN(amountdecimal) && !isNaN(ratedecimal))
			{
				var potentialWinValue = ((ratedecimal * amountdecimal) + '');
				
				if ( prizeRoundingType == 1 )
				{
					// zaokrouhli na dany pocet desetinych mist
					workingPrize = potentialWinValue;
					numbers = workingPrize.toString().split('.');
					intpart = numbers[0];
					decpart = workingPrize - eval(intpart);
					var decPartToMove ="";
					var roundingNumber = 0;
					var tempNumberForCarry;
					if ( decpart > 0 )
					{
						decPartToMove = numbers[1];
						if ( decPartToMove.length > prizeRoundingPrecision )
						{
							tempNumberForCarry = eval(intpart.toString()+ decPartToMove.substring(0,prizeRoundingPrecision)+"."+decPartToMove.substring(prizeRoundingPrecision,decPartToMove.length));
							roundingNumber = decPartToMove.substring(0,prizeRoundingPrecision)+"."+decPartToMove.substring(prizeRoundingPrecision,decPartToMove.length);
							roundingNumber = Math.round(tempNumberForCarry);
							intpart = roundingNumber.toString().substring(0,roundingNumber.toString().length - prizeRoundingPrecision);
							roundingNumber = eval(roundingNumber.toString().substring(roundingNumber.toString().length - prizeRoundingPrecision,roundingNumber.toString().length));
							workingPrize = intpart+"."+roundingNumber.toString();
						}
					}
				}
				else if ( prizeRoundingType == 2)
				{
					// urizni na pocet desetinych mist
					workingPrize = potentialWinValue;
					numbers = workingPrize.toString().split('.');
					intpart = numbers[0];
					decpart = workingPrize - eval(intpart);
					var decPartToMove ="";
					if ( decpart > 0 )
					{
						decPartToMove = numbers[1];
						if ( decPartToMove.length > prizeRoundingPrecision )
						{
							decPartToMove = decPartToMove.substring(0,prizeRoundingPrecision);
						}
						workingPrize = intpart +"."+decPartToMove;
					}
				}
				else if ( prizeRoundingType == 3)
				{
					// zaokrouhli na padesatniky za desetinym poctem mist
					// posun na pozadovany pocet desetinych mist napr. z 9,70345 na 970,345
					workingPrize = potentialWinValue;
					numbers = workingPrize.toString().split('.');
					intpart = numbers[0];
					decpart = workingPrize - eval(intpart);
					var decPartToMove ="";
					var decPartToCompare;
					var decPartBase;
					var roundingNumber = 0;
					var tempNumberForCarry;
					if ( decpart > 0 )
					{
						decPartToMove = numbers[1];
						if ( decPartToMove.length > prizeRoundingPrecision )
						{
							// desetine misto je vetsi nez presnost zaokrouhleni
							// vyber cast ktera je za presnosti a porovnej
							decPartBase = decPartToMove.substring(0,prizeRoundingPrecision);
							decPartToCompare = "0."+decPartToMove.substring(prizeRoundingPrecision,decPartToMove.length);
							if (decPartToCompare >= 0.75)
							{
								// vetsi jak 0.75 pridej 1 do vyssiho radu
								tempNumberForCarry = eval(intpart.toString()+decPartBase.toString()) + 1;
								roundingNumber = tempNumberForCarry.toString().substring(tempNumberForCarry.toString().length-decPartBase.length, tempNumberForCarry.toString().length);
								intpart = tempNumberForCarry.toString().substring(0,tempNumberForCarry.toString().length-decPartBase.length);
							}
							else if (decPartToCompare >= 0.25)
							{
								// vetsi jak 0.25 a mensi jak 0.75, pridej "padesatnik"
								roundingNumber = decPartBase.toString() + "5";
							}
							else
							{
								// mensi jak 0.25	pridej nulu
								roundingNumber = decPartBase.toString();
							}
							workingPrize = intpart+"."+roundingNumber.toString();
						}
					}
				}
				// vytvorit cislo a vlozit
				numbers = workingPrize.toString().split('.');
				intpart = numbers[0];
				decpart = workingPrize - eval(intpart);
				var length ;
				var decPartToPrint = "";
				if ( decpart > 0 ) // existuje desetine cislo
				{
					decPartToPrint = numbers[1];
					length = decPartToPrint.length;					
				}
				else
				{
					length = 0;
				}
					// zjisti delku desetineho cisla
					// porovnej s pozadovanou delkou pro zobrazeni
					
					if ( length < prizeDisplayPrecision )
					{
						// dopln nuly
						var c = 0;
						var nuly = "";
						for(c = length;c<prizeDisplayPrecision; c++)
						{
							nuly = nuly + "0";
						}
						workingPrize = intpart + currencyDecimalSeparator + decPartToPrint + nuly;
					}
					else if ( length >= prizeDisplayPrecision )
					{
						// orizni
						workingPrize = intpart + currencyDecimalSeparator + decPartToPrint.substring(0,prizeDisplayPrecision);
					}
				
				potentialWin.innerHTML = workingPrize;
			}
		} 
	}
}

function CountPPrice()
{
	var ratesSum = document.getElementById("ratessum").value.replace(',','.');
	var amount = document.getElementById("amount");
	var stakeSum = document.getElementById("stakesum");
	var ticketsCount = document.getElementById("ticketscount");
	var finalRate = document.getElementById("finalrate");
	var pricePoten = document.getElementById("pricepoten");
	var numericalAlertDiv = document.getElementById("numericalnotice");
	
	if (!isNaN(amount.value))
	{
		if (numericalAlertDiv != null)
		{
			numericalAlertDiv.style.display = "none";
		}
		if (ticketsCount != null && stakeSum != null)
		{
			finalRate.innerHTML = ticketsCount.value + '&nbsp;x&nbsp;' +  amount.value + '&nbsp;=&nbsp;' + (ticketsCount.value * amount.value);
			pricePoten.innerHTML = Math.round(ratesSum * (amount.value));
		}
		else
		{
			pricePoten.innerHTML = Math.round(ratesSum * (amount.value));
		}
	}
	else
	{
		if (numericalAlertDiv != null)
		{
			numericalAlertDiv.style.display = "block";
		}
	}
}

function ExpandCategory(catId)
{
	var arrowImage = document.getElementById('cim' + catId);
	var subCategoryDiv = document.getElementById('csc' + catId);
	if (arrowImage != null && subCategoryDiv != null)
	{
		if (arrowImage.src.indexOf('ArrowRight.gif') != -1)
		{
			SendRequest('cmd=CategoryExpand&i=' + catId);
		}
		else
		{
			arrowImage.src = arrowImage.src.replace('ArrowDown', 'ArrowRight');
			subCategoryDiv.style.display = "none"
			SendRequest('cmd=CategoryCollapse&i=' + catId);
		}
	}
}

function AddNumbers(element)
{
	var identifier = element.id.substring(1);
	var numbers = GetSelectedNumbers();
	var errormessage = document.getElementById("errormessage");
	
	//validation if user select All required items
	if (numbers == "notAllRequiredItems")
	{
		if (errormessage != null)
		{
			errormessage.style.display = "block";
		}
	}
	else
	{
		SendRequest('cmd=CouponAddNumbers&i=' + identifier + '&n=' + numbers);
		if (errormessage != null)
		{
			errormessage.style.display = "none";
		}
	}
}

function GetSelectedNumbers()
{
	var selects = document.getElementsByTagName("select");
	var select;
	var selectId;
	var numbers = '';
	for (i = 0; i < selects.length; i++)
	{
		select = selects[i];
		selectId = select.id.toLowerCase();
		if (selectId.substring(0, 17) == 'numericalgame_row' && select.value.length > 0 && !isNaN(select.value))
		{
			numbers = numbers + select.value + ';';
		}
		else
		{
			//neni vyplnena povinna polozka?
			if (selectId.substring(selectId.length - 4, selectId.length) == '_req')
			{
				return "notAllRequiredItems";
			}
		}
	}
	if (numbers.length > 0 && numbers.substring(numbers.length - 1) == ';')
	{
		numbers = numbers.substring(0, numbers.length - 1);
	}
	return numbers;
}

//
// Regions and terminals

// element - select box, ktery udalost vyvolal
// divid - identifikator divu, do ktereho se budou podregiony vykreslovat
function ExpandRegion(element, divid)
{
	var select = element;
	
	if (select.value.length > 0 && !isNaN(select.value))
	{
		// dotahneme si informace o podregionech
		SendRequest('cmd=RegionCollapse&i=' + select.value + '&e=' + divid);
	}
	else
	{
		// uzivatel zrusil vybrani, takze vymazeme vsechny podregiony
		var subRegionDiv = document.getElementById(divid);
		var regionTerminalDiv = document.getElementById("TerminalsContainer");
		if (subRegionDiv != null)
		{
			subRegionDiv.innerHTML = "";
		}
		if (regionTerminalDiv != null)
		{
			regionTerminalDiv.innerHTML = "";
		}
	}
}

/***** OBSLUHA ODDS V NEWS *****/
function NewsOddsMouseOver(element)
{
	var identifier = element.id.substring(1);

	if (element != null)
	{
	    if (element.className == 'rateSelected')
		{
		    element.className = 'rateSelectedHover';
		}
		else
		{
			element.className = 'rateHover';
		}
	}
}
function NewsOddsMouseOut(element)
{
	var identifier = element.id.substring(1);

	if (element != null)
	{
		if (element.className == 'rateSelectedHover' || element.className == 'rateSelected')
		{
		    element.className = 'rateSelected';
		}
		else
		{
			element.className = 'rate';
		}
	}
}

function NewsSetTipUnselected(element)
{
	if (element != null)
	{
	    element.className = 'rate';
	}
}

function NewsSetTipSelected(element)
{
	if (element != null)
	{
		element.className = 'rateSelected';
	}
}

/* na uvodni strance oznaci typy ktere jsou na sazence */
/* bezne se po refreshi ztraci */
function NewsSelectSelectedTips()
{				
    var anchors = document.getElementsByTagName("td");
    var anchor;
    var elementClientId;
    for (i = 0; i < anchors.length; i++)
   	{
	    anchor = anchors[i];
    	elementClientId = anchor.id.substring(1);
    	
    	if (document.getElementById('c' + elementClientId) != null)
    	{
    	    NewsSetTipSelected(anchor);
    	}
	}
}
/***** KONEC OBSLUHA ODDS V NEWS *****/
-->
