//<%'STANDARD COMPLIANT LINKS %>
function popUp(linkURL,name,attributes) {
	window.open(linkURL,name,attributes);
}

window.onload = function() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (i=0; i < links.length; i++) {
		link = links[i];
		if (link.className == "popup") {
			link.onclick = function() {
			var width = 780;
			var height = 590;
			var name = "popup";
			var resizable = 1;
			var scrollbars = 1;
			var status = 1;
			var newWin = 1;
			if (this.getAttribute("rel")) {
				var rels = this.getAttribute("rel");
				var relSplit = rels.split(" ");
				name = relSplit[0] ? relSplit[0] : name;
				width =  relSplit[1] ? relSplit[1] : width;
				height = relSplit[2] ? relSplit[2] : height;
				resizable = relSplit[3] ? relSplit[3] : resizable;
				scrollbars = relSplit[4] ? relSplit[4] : scrollbars;
				status = relSplit[5] ? relSplit[5] : status;
				newWin = relSplit[6] ? relSplit[6] : newWin;
			}
			attributes = "width="+width+",height="+height+", resizable="+resizable+", scrollbars="+scrollbars+", status="+status+", location="+newWin+",toolbar="+newWin;
			popUp(this.getAttribute("href"),name,attributes);
			return false;
			}
		}
	}
}
//--

function GetQueryString(){
	return location.search;
}
//---
function setCookie (name,value,expires,path,domain,secure)
{
    document.cookie = name + "=" + escape (value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "");
}
//---
function windowExist( winHandle )
{
	if(winHandle)
		return (winHandle.closed) ? 0 : 1;
	else 
		return 0;
}
//---
function RedirectPage(redirectURL)
{
	top.parent.window.location.href = redirectURL;
}
//---
function CloseWindow()
{
	top.parent.window.close();
// functionality to call a close function
//	if (top.parent.window.opener != null)
//		if (top.parent.window.opener.SpClose != null)
//			top.parent.window.opener.SpClose();
}
//---
function CloseWindowRefreshParent()
{
	top.parent.window.close();
	top.opener.location.reload();
}
//---

function CloseRefresh( pwin, ploc )
{
//alert(ploc);
	top.parent.window.close();
	if (pwin) pwin.location.href = ploc;

//	if (pwin) pwin.location.href = pwin.location.href;
// * pwin.location.href is not allowed from secure to insecure pages *
// * must use pwin.location.href = fully qualified URL but querystring is lost when passing between pages *
// * frames no good as still going from secure to insecure - IE will throw it out *

}
//---
function RefreshPage()
{
	var myURL = document.location.href;
	document.location.href = myURL;
}
//---
function GamesRoomRefresh( pwin, grlink )
{
//alert("GamesRoom Refresh"+grlink);
	top.parent.window.close();
	if (pwin) pwin.location.href = grlink;
}
//---
function LogOff(pUname){
	top.window.subexe.document.location.href = "/SpMain/common/pages/logout.asp?username="+pUname;
}
//---
function showLogin(pSecureURL, pSiteID){
	var wi=340;
	var ht=230;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;

	var loginwin=window.open(pSecureURL + "/SpMain/common/ssl/login.asp?siteID=" + pSiteID + "&srcpg=" + document.location.href,"login", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");
	loginwin.focus;
}
//---
function showRegister(pSecureURL, pSiteID){
	var wi=640;
	var ht=560;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;

	var regwindow=window.open(pSecureURL + "/SpMain/common/ssl/register.asp?siteID=" + pSiteID + "&srcpg=" + document.location.href, "register", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes");
	regwindow.focus();
}
//---
function showMyAccount(pSecureURL, pSiteID, pOption){
	var wi=775;
	var ht=534;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;

	var acctwindow=window.open(pSecureURL + "/SpMain/common/ssl/" + pOption + ".asp?siteID=" + pSiteID + "&srcpg=" + document.location.href, "myaccount", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	acctwindow.focus();
}
//---
var winHelp;
function showHelp( strNodeID ){
	var strNode = "";

	if (showHelp.arguments.length > 0)
		strNode = "?NODEID="+strNodeID

	if (windowExist(winHelp)){
		winHelp.location.href="/SpMain/common/pages/help/help_frameset.asp"+strNode;
		winHelp.focus()
	} else{
		var wi=640;
		var ht=580;
		var xpos=(screen.width - wi)/2;
		var ypos=(screen.height - ht)/2;

		winHelp=window.open("/SpMain/common/pages/help/help_frameset.asp"+strNode,"Help","width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes");
	}
}
//---
function showAffiliateForm(pSiteID){
	var wi=540;
	var ht=580;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var affwindow=window.open("/SpMain/common/pages/forms/affiliateform.asp?siteID="+pSiteID, "affiliatewindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	affwindow.focus();
}
//---
function showSupportForm(pSiteID){
	var wi=410;
	var ht=440;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var suppwindow=window.open("/SpMain/common/pages/forms/supportform.asp?siteID="+pSiteID, "supportwindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes");
	suppwindow.focus();
}
//---
function showQuizForm(pSiteID){
	var wi=700;
	var ht=460;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var quizwindow=window.open("/SpMain/common/pages/forms/quizform.asp?siteID="+pSiteID, "quizwindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
	quizwindow.focus();
}
//---
function showPrizeDrawForm(pSiteID){
	var wi=480;
	var ht=430;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var drawwindow=window.open("/SpMain/common/pages/forms/prizedrawform.asp?siteID="+pSiteID, "drawwindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
	drawwindow.focus();
}
//---
function showPrizeDrawForm02(pSiteID){
	var wi=480;
	var ht=430;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var drawwindow=window.open("/SpMain/common/pages/forms/prizedrawform02.asp?siteID="+pSiteID, "drawwindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
	drawwindow.focus();
}
//---
function showRaceCenter(pSection){
	var wi=665;
	var ht=517;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var rcwindow=window.open("http://www.teamtalk.com/Sportingodds/Racing_Centre_Link/1,8111,"+pSection+",00.html", "rcwindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes");
	rcwindow.focus();
}
//---
function loadVirtualRacing(){
	top.window.subexe.document.location.href = "/SpMain/common/pages/games/virtualracing.asp";
}
//---
var vracing;
function showVirtualRacing(pVRacingURL) {
	if (windowExist(vracing)){
		vracing.focus();
	} else{
		var wi=700;
		var ht=400;
		var xpos=(screen.width - wi)/2;
		var ypos=(screen.height - ht)/2;

		vracing=window.open(pVRacingURL, "VirtualRacing", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=no,resizable=no");
		if (vracing.opener == null) vracing.opener = self;
	}
}
//---
function loadLottery(){
	top.window.subexe.document.location.href = "/SpMain/common/pages/games/lottery.asp";
}
//---
var lottery;
function showLottery(pUsername) {
	if (windowExist(lottery)){
		lottery.focus();
	} else{
		var wi=700;
		var ht=400;
		var xpos=(screen.width - wi)/2;
		var ypos=(screen.height - ht)/2;

		lottery=window.open("/SpMain/common/pages/games/lotterypopup.asp?userName="+pUsername, "Lottery", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=no,resizable=no");
		if (lottery.opener == null) lottery.opener = self;
	}
}
//---
function loadSuperHiLo(){
	top.window.subexe.document.location.href = "/SpMain/common/pages/games/superhilo.asp";
}
//---
function loadGamesRoom(target){
	top.window.document.location.href = "/SpMain/common/pages/games/gamesRoom.asp?target=" + target;
}
//---
function noGamesRoomMsg(target) {
	window.alert("The " + target + " is currently unavailable!")
}
//---
var hilo;
function showSuperHiLo(pHiLoURL) {
	if (windowExist(hilo)){
		hilo.focus();
	} else{
		var wi=700;
		var ht=400;
		var xpos=(screen.width - wi)/2;
		var ypos=(screen.height - ht)/2;

		hilo=window.open(pHiLoURL, "SuperHiLo", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=no,resizable=no");
		if (hilo.opener == null) hilo.opener = self;
	}
}
//---
var casino;
function showCasino(pCasinoURL) {
	if (windowExist(casino)){
		casino.focus();
	} else{
		var wi=630;
		var ht=550;
		var xpos=(screen.width - wi)/2;
		var ypos=(screen.height - ht)/2;

		casino=window.open(pCasinoURL, "Casino", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,titlebar=no,menubar=no,scrollbars=no,resizable=no");
		if (casino.opener == null) casino.opener = self;
	}
}
//---
function showCasinoFreeChips(pSiteID){
	var wi=500;
	var ht=530;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var affwindow=window.open("/SpMain/common/pages/games/casinofreechips.asp?siteID="+pSiteID, "affiliatewindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	affwindow.focus();
}
//---
function showCasinoBonus(pSiteID){
	var wi=500;
	var ht=530;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var affwindow=window.open("/SpMain/common/pages/games/casinobonus.asp?siteID="+pSiteID, "affiliatewindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	affwindow.focus();
}
//---
function showMembersClub(pSiteID){
	var wi=500;
	var ht=530;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var affwindow=window.open("/SpMain/common/pages/games/casinomembersclub.asp?siteID="+pSiteID, "affiliatewindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	affwindow.focus();
}
//---
function showGettingStarted(pSiteID){
	var wi=500;
	var ht=530;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	var affwindow=window.open("/SpMain/common/pages/games/gettingstarted.asp?siteID="+pSiteID, "affiliatewindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
	affwindow.focus();
}
//---
// *** From betfuncs_js ****
//---
// ** If bet display was non SSL then popup window showing bet details, timeout and confirm buttons could be called from here
// bet display confirm button would switch to SSL for confirmation and actually placing the bet
// keypress pick up could be used to speed up bet placement - or should user consciously click Confirm?
// bet display fetches bet details and confirms price, minimum stake etc
// bet confirm checks vs user account
// bet display could offer radio buttons for fixed stakes - so if punter clicked bet with no stake then a seris of radio buttons could
// offer 5, 10, 25, 50 pound bets - adjusted for currency - showing maximum returns for the price

function confirmsingle(nSelID, nStake, nEW, strSiteID, nSubMarket, nMarket, nPrice) {
//window.alert("confirmsingle: You've placed your bet on selection: " + nSelID + " Price: " + nPrice + " Stake: " + nStake + " EW: " + nEW + " SiteID: " + strSiteID + " SubMarketID: " + nSubMarket + " MarketID: " + nMarket);
	var wi=480;
	var ht=400;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;

	var betwindow=window.open("/SpMain/common/pages/betengine/sslbetconfirm.asp?nMkID=" + nMarket + "&nPriceID=" + nPrice.toString() + "&nEach=" + nEW + "&nState=-1&nSelID=" + nSelID.toString() + "&nStake=" + nStake.toString() + "&nSubm=" + nSubMarket.toString() + "&bettype=single", "betconfirm", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");
	betwindow.focus();
}
//---
function confirmSingleBet(nSelID, nStake, nEW, strSiteID, nSubMarket, nPrice) {
///window.alert("confirmSingleBet: You've placed your bet on selection: " + nSelID + ", nStake:" + nStake + ", strSiteID:" + strSiteID + ", nSubMarket:" + nSubMarket);
	var wi=480;
	var ht=400;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;

	var betwindow=window.open("/SpMain/common/pages/betengine/sslbetconfirm.asp?nEach=" + nEW + "&nState=-1&nSelID=" + nSelID.toString() + "&nPriceID=" + nPrice.toString() + "&nStake=" + nStake.toString() + "&nSubm=" + nSubMarket.toString() + "&bettype=single", "betconfirm", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");
	betwindow.focus();
}
//---
function confirmscorecast(strFPSID, strCORID, nStake, nSubMarket) {
//alert("You've placed your bet on selection: " + strFPSID + "\nAnd selection: " + strCORID + "\nStake: " + nStake);
	var wi=480;
	var ht=400;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	
	var betwindow=window.open("/SpMain/common/pages/betengine/sslbetconfirm.asp?nState=-1&nFGSID=" + strFPSID.toString() + "&nCSID=" + strCORID.toString() + "&nStake=" + nStake.toString() + "&nSubm=" + nSubMarket.toString() + "&bettype=sc&nPriceID=", "betconfirm", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");
	betwindow.focus();
}
//---
function confirmfree(nSelID, nSubMarket, nStake, nEW, nProto, strSiteID) {
//alert("You've placed your FREE bet on selection: " + nSelID + " Stake: " + nStake + " Proto: " + nProto + " SubMarket: " + nSubMarket);
	var wi=480;
	var ht=400;
	var xpos=(screen.width - wi)/2;
	var ypos=(screen.height - ht)/2;
	
	var betwindow=window.open("/SpMain/common/pages/betengine/sslbetconfirm.asp?nEach=" + nEW + "&nState=-1&nSelID=" + nSelID.toString() + "&nStake=" + nStake.toString() +  "&nProto="+nProto.toString()     + "&nSubm=" + nSubMarket.toString() +"&bettype=single", "betconfirm", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");
	betwindow.focus();
}
//---
function marketbet(strSelID, strSubMarket, strMkId, strSiteID){
//window.alert("marketbet: Selection = " + strSelID+  ", strSubMarket=" + strSubMarket + ", strMkId=" + strMkId);
	
	var nStake = eval("document.betcoupon.stake" + strSelID + ".value");
	var nPrice = eval("document.betcoupon.price" + strSelID + ".value");
	
	if ((typeof(nStake) == 'undefined') || (nStake == 0)) {
			window.alert("Please enter a valid stake.");
		return false;
	}
	
	var cbEW = eval("document.betcoupon.ew" + strSelID);
	var nEW = 0;
	if (typeof(cbEW) != 'undefined') if (cbEW.checked) nEW = 1;

	confirmsingle(strSelID, nStake, nEW, strSiteID, strSubMarket, strMkId, nPrice);
}
//---
function betSubmitUS(nEvID, strSiteId) {

	var oSelID, nSelID, strSelId;
	var oStake, nStake;
	var ii, nSelected;
	var nEW, intSplit, nPriceId;
	
	nSelected = -1;

	if(document.betcoupon) {
		
		oSelID = eval("document.betcoupon.ev" + nEvID.toString());
		oStake = eval( "document.betcoupon.stev" + nEvID.toString());	
		nStake = oStake.value;
		
		if (oSelID) {
			for (ii=0; ii<oSelID.length;ii++) {
				if (oSelID[ii].checked) {	
					nSelected = ii;
					break;
				}
			}
			
			if (nSelected >= 0)	{
				nSelID = oSelID[nSelected].value;	
				
				intSplit = nSelID.indexOf("_");
				intLength = nSelID.length;
				strSelId = (nSelID.toString()).substring(0, intSplit);
				intSplit = intSplit+1;
				strSubMarket = (nSelID.toString()).substring(intSplit, intLength);
				nPriceId = eval("document.betcoupon.price" + strSelId + ".value");
		 
				if (parseFloat(nSelID) > 0) {															
					if (typeof(cbEW) != 'undefined') if (cbEW.checked) nEW = 1;
					confirmSingleBet(strSelId, nStake, nEW, strSiteId, strSubMarket, nPriceId);					
				}		
			} else {
				window.alert("Please make your selection");
			}
		}
	} 
}
//---
function twoPricesMarketBet(nCPSelID, nSPSelID, nCPSubmID, nSPSubmID, nMkID, strSiteID) {
//window.alert("twoPricesMarketBet: Selection = " + nCPSelID+ ", nCPSubmID=" + nCPSubmID + ", nSPSubmID=" + nSPSubmID + ", nMkID=" + nMkID);
	var nSelID;
	var nSubmID;
	var oSPcheck = eval("document.betcoupon.sp" + nSPSelID.toString());
	var oStake = eval("document.betcoupon.stake" + nCPSelID.toString() + "_" + nSPSelID.toString());
	var oEW = eval("document.betcoupon.ew" + nCPSelID.toString() + "_" + nSPSelID.toString());
	
	var nEW = 0;
	if (typeof(oEW) != 'undefined') if (oEW.checked) nEW = 1;
	var nStake = oStake.value
	
	if ((typeof(nStake) == 'undefined') || (nStake == 0)) {
		window.alert("Please enter a valid stake.");
		return false;
	}

	if (oSPcheck)
	{
		if (oSPcheck.checked) 
		{
			nSelID = nSPSelID;
			nSubmID = nSPSubmID;
		}
		else
		{
			nSelID = nCPSelID;
			nSubmID = nCPSubmID;
		}
	}	
	var nPrice = eval("document.betcoupon.price" + nSelID + ".value");
	
	confirmsingle(nSelID, nStake, nEW, strSiteID, nSubmID, nMkID, nPrice);

}
//---
/* 
//replaced with the below scrbet(nSubmarketID)
//new function picks up the values from the form rather than passing in from the javascript call
	function scrbetOLD(strFPSID, strCORID, strSubMarketId){
	var nStake = eval("document.betcoupon.stake" + strFPSID + strCORID + ".value");
//window.alert("You've placed your Scorecast bet on selections: " + strFPSID + " and " + strCORID + " Stake: " + nStake);
	confirmscorecast(strFPSID, strCORID, nStake, strSubMarketId);
}
*/
// picks up the values directly from the form rather than passing in from the javascript call
function scrbet(nSubmarketID){
	
	var oFGSSelectBox, oCSSelectBox;
	var nFGSSelIndex, nCSSelIndex;
	var nFGSArrayValue,aCSArrayValue,nStake;
	
	nStake = eval("document.betcoupon.stake" + nSubmarketID + ".value");
		
	oFGSSelectBox = eval('document.betcoupon.fgs' + nSubmarketID);
	oCSSelectBox = eval('document.betcoupon.cs' + nSubmarketID);
		
	nFGSSelIndex = oFGSSelectBox.selectedIndex;
	nCSSelIndex = oCSSelectBox.selectedIndex;

	if (nFGSSelIndex == '0' || nCSSelIndex == '0') {
			window.alert("Please make a selection.");
		return false;
	}
	if ((typeof(nStake) == 'undefined') || (nStake == 0)) {
		if (nStake != 'undefined'){
			window.alert("Please enter a valid stake.");
		}
		return false;
	}

	nFGSArrayValue = eval('arrfgs' + nSubmarketID + '[' + nFGSSelIndex + ']');
	aCSArrayValue = eval('arrcs' + nSubmarketID + '[' + nFGSSelIndex + ']');
		
	var aHlp = aCSArrayValue[nCSSelIndex].split('|');
	
	confirmscorecast(nFGSArrayValue, aHlp[0], nStake, nSubmarketID);
	//alert(aCSArrayValue  +  ' --- ' + nStake +  ' --- ' + nSubmarketID);
}
//---
function freebet(strSelID, nSubMarket, strSiteID){
	var nStake = eval("document.betcoupon.stake" + strSelID + ".value");
	var cbEW = eval("document.betcoupon.ew" + strSelID);
	var nEW = 0;
	var nProto = eval("document.betcoupon.proto" + strSelID + ".value");
	
	if (typeof(cbEW) != 'undefined') if (cbEW.checked) nEW = 1;
	confirmfree(strSelID, nSubMarket, nStake, nEW, nProto, strSiteID);
}
//---
/**
 * .:DEPRICATED:. Old function that used deal with players getting selected in the 
 * scorecast. Has been replaced by function setFGS().
 */ 
/*
function refreshscr(objDD) {
	var myURL = document.location.href;
	var pattern = /&fps=\d+/;
	if (myURL.match(pattern)){
		myURL = myURL.replace(pattern, "&fgs=" + objDD.value);
	}
	else {
		myURL = myURL + "&fgs=" + objDD.value;
	}
	var pattern2 = /#ScorecastMarket/;
	if (myURL.match(pattern2)){
	}
	else {
		myURL = myURL + "#ScorecastMarket"
	}
	document.location.href = myURL;
}
*/
//---


//---
// new code for scorecast (with two dropdowns, same as sportingbet)
function fs_GetFormRef(formID) {
	var obj;
	obj = document.forms[formID];

	return obj;
}
function fs_listAdd(sFormName, sSelectName, sText, sValue) {
	var oForm = fs_GetFormRef(sFormName);
	var oSelect = oForm.elements[sSelectName];
	
    var newoption = new Option(sText, sValue, true, true);
    oSelect.options[oSelect.length] = newoption;
}

function fs_UnCheckBox(sFormName, chName, nSelId, nProtoId) {
	var oForm = fs_GetFormRef(sFormName);
	var oCh = oForm.elements[chName];
	var i;	
	var cSelId = nSelId.toString();
	var cProtoId = nProtoId.toString();
	var sChVal;
		
	for(i=0;i<oCh.length;i++) {
		sChVal = oCh[i].value;
		if ((sChVal.substr(3, cSelId.length)!=cSelId) && (sChVal.substr(sChVal.length - cProtoId.length)==cProtoId)){
			oCh[i].checked = false;		
		}
	}
}

function fs_listRemoveAll(sFormName, sSelectName) {
	var oForm = fs_GetFormRef(sFormName);
	var oSelect = oForm.elements[sSelectName];
	var i;

	for(i=0;i<oSelect.length;i++) {
        oSelect.options[i] = null;
		i--;
	}
}

function fs_listUnselectAll(sFormName, sSelectName) {
	var oForm = fs_GetFormRef(sFormName);
	var oSelect = oForm.elements[sSelectName];
	var i;

	for(i=0;i<oSelect.length;i++) {
	    oSelect.options[i].selected = false;
	}
}

function csSetToPreviousCS(oCSSelectBox) {
	for (var j=0; j < oCSSelectBox.length; j++) {
		if (j == 0) oCSSelectBox.options[j].selected = true;
		if (oCSSelectBox.options[j].value == nPreviousCSID) oCSSelectBox.options[j].selected = true;
	}
}

var nPreviousFGSID = 0;
var nPreviousCSID = 0;
function setFGS(nSubmarketID)
{
if (document.betcoupon) {
		var oFGSSelectBox, oCSSelectBox, oOddsTextBox;
		var nFGSSelIndex, nCSSelIndex;
		var nFGSArrayValue, aCSArrayValue;
		var sOldCSOptionText, sNewCSOptionText, sNewPrice, sCSOptionValue;
		
		oFGSSelectBox = eval('document.betcoupon.fgs' + nSubmarketID);
		
		
		oCSSelectBox = eval('document.betcoupon.cs' + nSubmarketID);
		oOddsTextBox = eval('document.betcoupon.odds' + nSubmarketID);
		
		nFGSSelIndex = oFGSSelectBox.selectedIndex;
		
		nFGSArrayValue = eval('arrfgs' + nSubmarketID + '[' + nFGSSelIndex + ']');
		aCSArrayValue = eval('arrcs' + nSubmarketID + '[' + nFGSSelIndex + ']');
		
		if (oCSSelectBox.selectedIndex > -1 && oFGSSelectBox.selectedIndex > -1) {
		
		
			sOldCSOptionText = oCSSelectBox[oCSSelectBox.selectedIndex].text;
		
			if (nPreviousFGSID != nFGSArrayValue) {
				//delete and refill GS select box
				
				fs_listRemoveAll('betcoupon', 'cs' + nSubmarketID);				
				
				for (var i = 0; i < aCSArrayValue.length; i++) {
					
					var aHlp = aCSArrayValue[i].split('|');
					fs_listAdd('betcoupon', 'cs' + nSubmarketID, aHlp[1], aHlp[0]);
					
				}
				
				csSetToPreviousCS(oCSSelectBox);
				
			} 
			//set new price
			for (var i = 0; i < aCSArrayValue.length; i++) {
				
				var aHlp = aCSArrayValue[i].split('|');
				if (parseFloat(aHlp[0]) == parseFloat( oCSSelectBox[oCSSelectBox.selectedIndex].value)) oOddsTextBox.value = aHlp[2];
			}
		
			nPreviousFGSID = nFGSArrayValue;
			if (oCSSelectBox.selectedIndex >= 0)
				nPreviousCSID = oCSSelectBox[oCSSelectBox.selectedIndex].value;
		
		}
	}

}
//---
/*
//replaced by the new setFGS function (above)
function setFGSOLD(nSmID)
{
	var myURL = document.location.href;
	var pattern = /&fgs=\d+/;
	var pattern2 = /#ScorecastMarket/;
	var nFGSID;
	var oDD = eval("document.betcoupon.fgs" + nSmID.toString());
	
	if (myURL.match(pattern)){
		myURL = myURL.replace(pattern, "&scid=" + nSmID + "&fgs=" + oDD.value);
	}
	else {
		myURL = myURL + "&scid=" + nSmID + "&fgs=" + oDD.value;
	}
	
	if (myURL.match(pattern2)){
	}
	else {
		myURL = myURL + "#ScorecastMarket"
	}
	document.location.href = myURL;	
}
*/
//---


//---
function numrunners(pval) {
	return Math.ceil(Math.sqrt(pval));
}
//---
function addForecast(oRadio, sm)
{
	var nRB = oRadio.name.substring(2, 3);
	var nRN = oRadio.value;

// Reset other RBs
	for (var i=1; i <= 2; i++) {
		if (i!=nRB) {
			var rbTmp = eval("document.betcoupon.rn" + i + "[" + (nRN-1) + "]");
			rbTmp.checked = false;
		}
	};

// Determine selection ID
	var selStr = eval("document.betcoupon.sellist.value");
	var selArr = selStr.split(':');
	var nSel = selArr.length;
	
// Number of runners
	var ru = numrunners(nSel);

// Get RB values
// Row r (rn1)
	var r=0;
	for (var i=1; i <= ru; i++) {
		var rbTmp = eval("document.betcoupon.rn1[" + (i-1) + "]");
		if (rbTmp.checked) { r=i };
	};
// Col c (rn2)
	var c=0;
	for (var i=1; i <= ru; i++) {
		var rbTmp = eval("document.betcoupon.rn2[" + (i-1) + "]");
		if (rbTmp.checked) { c=i };
	};

	if (c+r > 2) {
// formula = ru^2-(ru-r)^2-(ru*2-c*2+r+1)
		var selix = 0;
		if (c > r) {
			selix = (ru*ru) - ((ru-r)*(ru-r)) - (ru*2-c*2+r+1);
		}
		else {
			selix = (ru*ru) - ((ru-c)*(ru-c)) - (ru*2-r*2+c+1) + 1;
		};

		var selid = selArr[selix];
		arrSel[sm] = selid;
	}
	else
	{
		delete arrSel[sm];
	};
}
//---
// *** COUPON TEMPLATE functions ***
//---
var arrSel = new Array();

function addtobetbasket(strSelID, strMkId,  strSubMkId, strSiteId) {
//window.alert("addtobetbasket: Selection Id = " + strSelID + ", strSubMkId = " + strSubMkId + ", strMkId = " + strMkId )	
	
	var s = "";
	var sTmp, sAct, strUrl;
	
	if (strSelID == 0) {
		for (var i in arrSel) {
			s = s + arrSel[i] + "; ";
		}
		sAct = "addcoupon"
		sTmp = "selcol"
	}
	else {
		s = strSelID;
		sAct = "addsingle"
		sTmp = "selid"
	}
	
	if (isNaN(parseInt(strSiteId))) {
		strSiteId = "1843"
	}

	strUrl = "/SpMain/common/pages/bettingslip/addtobettingslip.asp?aspaction="+sAct+"&"+sTmp+"="+s+"&smid="+strSubMkId+"&siteid="+strSiteId;
	if (strMkId) {
		if (strMkId != 0) {
		strUrl = strUrl + "&mkid=" + strMkId;	
		}
	}

	if (s != "") {
		var wi=370;
		var ht=210;
		var xpos=(screen.width - wi)/2;
		var ypos=(screen.height - ht)/2;
		AddtoBB = window.open(strUrl, "AddtoBBwindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
		if (AddtoBB.opener == null) AddtoBB.opener = self;
		AddtoBB.focus();
	}
}
//---
function addTwoPricesToBetBasket(nCPSelID, nSPSelID, nCPSubMkId, nSPSubMkId, nMkId, strSiteId) {

	var cTmp;
	var nSelID;
	var nSubmID, strUrl;
	var oSPcheck = eval("document.betcoupon.sp" + nSPSelID.toString());

	if (oSPcheck)
	{
		if (oSPcheck.checked) 
		{
			nSelID = nSPSelID;
			nSubmID = nSPSubMkId;
		}
		else
		{
			nSelID = nCPSelID;
			nSubmID = nCPSubMkId;
		}
	}	
	
	if (isNaN(parseInt(strSiteId))) {
		strSiteId = "1843"
	}
	
	var s = "";
	var sTmp;
	var sAct;
	if (nSelID == 0) {
		for (var i in arrSel) {
			s = s + arrSel[i] + ";";
		}
		sAct = "addcoupon"
		sTmp = "selcol"
	}
	else {
		s = nSelID;
		sAct = "addsingle"
		sTmp = "selid"
	}
	strUrl = "/SpMain/common/pages/bettingslip/addtobettingslip.asp?aspaction="+sAct+"&"+sTmp+"="+s+"&smid="+nSubmID.toString()+"&siteid="+strSiteId;
	
	if (nMkId) {
		strUrl = strUrl + "&mkid=" + nMkId.toString();
	}

	if (s != "") {
		var wi=370;
		var ht=210;
		var xpos=(screen.width - wi)/2;
		var ypos=(screen.height - ht)/2;
		AddtoBB = window.open(strUrl, "AddtoBBwindow", "width="+wi+",height="+ht+",screenX="+xpos+",screenY="+ypos+",top="+ypos+",left="+xpos+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
		if (AddtoBB.opener == null) AddtoBB.opener = self;
		AddtoBB.focus();
	}

}
//---
function btnreset(oRadio) {
	oRadio.checked = false;
	delete arrSel[oRadio.name];
}
//---
function resetall() 
{
	var i;
	var otmp;
	for (i in arrSel)
	{
		delete arrSel[i];
	}
	document.betcoupon.reset();
}
//---
function addSelection(oRadio) {

	if (arrSel[oRadio.name]) {
		if (arrSel[oRadio.name] == oRadio.value) {
			btnreset(oRadio);
		}
		else {
			arrSel[oRadio.name] = oRadio.value
		}
	}
	else {
		arrSel[oRadio.name] = oRadio.value
	}
	
}
//---
function couponbet(strSubMarket, strSiteID){
// determine selId for market
	var sTmp = "sm" + strSubMarket;
	var nStake = eval("document.betcoupon.stake" + strSubMarket + ".value");
	var nSelID = arrSel[sTmp];
	
	if (typeof(nSelID) == 'undefined') {
		if (typeof(nStake) != 'undefined'){
			window.alert("Please make a selection.");
		}
		return false;
	}
	
	if ((typeof(nStake) == 'undefined') || (nStake == 0)) {
		if (nStake != 'undefined'){
			window.alert("Please enter a valid stake.");
		}
		return false;
	}
	
	var intSplit = nSelID.indexOf("_");
	var strSelID = (nSelID.toString()).substring(0, intSplit);
	var nPrice = eval("document.betcoupon.price" + strSelID + ".value");

	confirmsingle(strSelID, nStake, 0, strSiteID, strSubMarket, 0, nPrice);
}
//---
function cpnSel(intSiteID, sportId, eventGroup) {

	var strMktType
	var oMktType = eval(document.betcoupon.cpnselect);
	
	if (oMktType) {
		strMktType = oMktType.value;
		location.href = "main.asp?siteID=" + intSiteID + "&sp=" + sportId + "&evg=" + eventGroup + "&content=americanEvent&mktType=" + strMktType
	}
}

//---
// *** SportingClick Functions ***
//---
function ValidateLogon()
{
	if ( HasLogonForm() )
	{
		var intReturnCode = ValidateLogonForm(intReturnCode);
	
		if (intReturnCode == ValidLogon)
		{
			return true;
		}
		else if ( intReturnCode == InvalidUsername )
		{
			alert("Please enter your user name");
			document.forms.frmBettingSlip.txtUsername.focus();
		}
		else if ( intReturnCode == InvalidPassword )
		{
			alert("Please enter your password");
			document.forms.frmBettingSlip.txtPassword.focus();
		}
		else
		{
			alert("Please enter your Logon information");
		}
		
		return false;
	}
	
	return true;		
}
//---
function HasLogonForm()
{
	return ( typeof(document.forms.frmBettingSlip.txtUsername) == 'object' );
}
//---
function ValidateLogonForm()
{
	with ( document.forms.frmBettingSlip )
	{
		if ( txtUsername.value.length == 0 )
			return InvalidUsername;
		else if ( txtPassword.value.length == 0 )
			return InvalidPassword;
		else
			return ValidLogon;
	}
return true;
}
//---
function IsValidStake()
{
	var nStake = parseFloat( document.forms.frmBettingSlip.txtStake.value );

	if (isNaN(nStake))
		return false;
	else
		return true;
}
//---
function IsValidMultiple()
{
	var nSelectionCount = frmBettingSlip.hdSelectionCount.value;

	if (nSelectionCount < 2)
		return false;
	else
		return true;
}
//---
function OptionSelect()
{
	EnsurePageValid();
	if (parent.mainFrame)
	{
		with (document.frmNavigation)
		{
			var intIndex = parseInt(cmbOptions[cmbOptions.selectedIndex].value);
			switch (intIndex)
			{
			case 1:
				parent.mainFrame.ShowBalance();
				break;
			case 2:
				parent.mainFrame.HideBalance();
				break;
			case 3:
				parent.mainFrame.Deposit();
				break;
			case 4:
				parent.mainFrame.Withdraw();
				break;
			case 5:
				parent.mainFrame.AccountHistory();
				break;
			case 6:
				parent.mainFrame.PersonalDetails();
				break;
			case 7:
				parent.mainFrame.ChangePassword();
				break;
			case 8:
				SetLocation('register.asp');
				break;
			case 9:
				var strQueryString = GetQueryString();
				strQueryString = ReplacePageType(strQueryString, 0);
				parent.mainFrame.location.href = 'bettingslip.asp' + strQueryString;
				location.href = 'VBSnavigation.asp' + strQueryString;
				break;
			case 10:
				parent.mainFrame.CardDetails();
				break;
			case 11:
				parent.mainFrame.DisplayMultiple();
				break;
			}
			cmbOptions.selectedIndex = 0;
		}
	}
}
//---
function RefreshNavigationFrame( intPageType )
{
	if (parent.navigationFrame)
		with (parent.navigationFrame)
		{
			location.href = location.pathname + ReplacePageType(GetQueryString(), intPageType);
		}
}
//---
function ReplacePageType(strQueryString, intPageType)
{
	return ModifyQueryString(strQueryString, 'pt', intPageType);
}
//---
function NavigationRegister()
{
	if (parent.mainFrame)
		SetLocation('register.asp');
}
//---
function GetQueryString()
{
	return location.search;
}
//---
function BackToBet()
{
	var strQueryString = GetQueryString();
	strQueryString = ReplacePageType(strQueryString, 0);
	parent.mainFrame.location.href = 'bettingslip.asp' + strQueryString;
	parent.navigationFrame.location.href = 'VBSnavigation.asp' + strQueryString;
}
//---
function DisplayMultiple()
{
	var strQueryString = GetQueryString();
	strQueryString = ReplacePageType(strQueryString, 4);
	parent.mainFrame.location.href = 'bettingslip.asp' + strQueryString + '&dm=1';
	parent.navigationFrame.location.href = 'VBSnavigation.asp' + strQueryString;	
}
//---
function SetLocation(strPage)
{
	parent.mainFrame.location.href = strPage + GetQueryString();
}
//---
function EnsurePageValid()
{
	//IsValidPage must be prefixed parent.mainFrame.
	if (!(parent.mainFrame.IsValidPage))
	{
		var strQueryString = GetQueryString();
		strQueryString = ReplacePageType(strQueryString, 0);
		parent.mainFrame.location.href = 'bettingslip.asp' + strQueryString;
	}
}
//---
function IsValidPage()
{
	//empty function
	//page is valid if it contains this function
}
//---
function ModifyQueryString(strQueryString, strParameterName, strParameterValue)
{
	var strNewQueryString = strQueryString;

	if (strNewQueryString.length > 0)
	{
		//match param=x&
		var objRE = new RegExp(strParameterName + '=\\d+&', 'gi');
		strNewQueryString = strNewQueryString.replace(objRE, '');
		
		//match &param=x	
		objRE = new RegExp('&' + strParameterName + '=\\d+', 'gi');
		strNewQueryString = strNewQueryString.replace(objRE, '');

		//match param=x at end of line
		var objRE = new RegExp(strParameterName + '=\\d+$', 'gi');
		strNewQueryString = strNewQueryString.replace(objRE, '');

		var strSeparator = '';
		if (strNewQueryString.length != 1)
		{
			strSeparator = '&';
		}
		
		strNewQueryString += strSeparator + strParameterName + '=' + strParameterValue;
	}
	else
	{
		strNewQueryString = '?' + strParameterName + '=' + strParameterValue;
	}

	return strNewQueryString;
}
//---
function FormSubmitted()
{
	PlaceBet();
}
//---
function CheckLogonAndSubmit(strAction)
{
	if ( !ValidateLogon() )
		return;
	else
		SubmitForm(strAction);
}
//---
function IsMultipleSlip()
{
	if (document.forms.frmBettingSlip.hdSelectionCount)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//---
function SelectionChanged()
{
	if (window.CalcAll)
	{
		CalcAll();
	}
	nCalcTimeout = 0;
}
//---
function StakeChanging()
{
	if (nCalcTimeout == 0)
	{
		nCalcTimeout = window.setTimeout('SelectionChanged()', 500);
	}
}
// Site stat function.----

function sitestat(ns_l){
	ns_l+="&ns__t="+(new
	Date()).getTime();ns_pixelUrl=ns_l;ns_0=document.referrer;
	ns_0=(ns_0.lastIndexOf("/")==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf("/"),0):ns_0;
	if(ns_0.length>0)ns_l+="&ns_referrer="+escape(ns_0);
	if(document.images){ns_1=new Image();ns_1.src=ns_l;}else
	document.write("<img src="+ns_l+" width='1' height='1'>");
}


