function PlaySound(url) {
  document.all.sound.src = url;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function HideShowChild(x)
{
	if (document.getElementById(x).style.display=="none")
	{
		document.getElementById(x).style.display="";
		setCookie(x,1,1)
	}
	else
	{
		document.getElementById(x).style.display="none";
		setCookie(x,0,1)
	}
}

function LoadChild(x)
{
	var ChildState=getCookie(x);
	{
		if (ChildState==1)
		{
			document.getElementById(x).style.display="";
		}
	}
}


function NoBet()
{
	alert("Please note that under Australian law,\n\nthis game is now live in running and being controlled by our Australian license,\n\nyou can only bet over the telephone on 1300 801 901.")
}

function ResetCoupon()
{
	IsCoupon=0;
	BetSubmitted=0;
}

function XmasBet()
{
	alert("Legislation prohibits betting on Christmas Day.\n\nPlease telephone our office tomorrow.")
}

function ClearUser()
{
	if (document.LoginForm.UserID.value=="Enter Account ID")
	{
		document.LoginForm.UserID.value=""
	}
	else if (document.LoginForm.UserID.value=="")
	{
		document.LoginForm.UserID.value="Enter Account ID"
	}
}

function ClearPass()
{
	if (document.LoginForm.Password.value=="Password")
	{
		document.LoginForm.Password.value=""
	}
	else if (document.LoginForm.Password.value=="")
	{
		document.LoginForm.Password.value="Password"
	}
}

function callServer(thescript,theold)
{
	var head = document.getElementsByTagName('head').item(0);
	var old  = document.getElementById(theold);
	if (old) head.removeChild(old);
	script = document.createElement('script');
	script.src = thescript;
	script.type = 'text/javascript';
	script.defer = true;
	script.id = theold;
	void(head.appendChild(script));
}


function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}


function HideBalance()
{
	var HideBal=getCookie('HideBalance');
	if (HideBal==null || HideBal=="" || HideBal==0)
	{
		setCookie('HideBalance',1,365);
		document.getElementById('BalanceBox').style.color="#BCBCBC";
		document.getElementById('AvailableBox').style.color="#BCBCBC";
	}
	else
	{
		setCookie('HideBalance',0,365)
		document.getElementById('BalanceBox').style.color="black";
		document.getElementById('AvailableBox').style.color="black";
	}
}


function DisplayBalance()
{
	var HideBal=getCookie('HideBalance');
	if (HideBal==null || HideBal=="" || HideBal==0)
	{
		document.getElementById('BalanceBox').style.color="black";
		document.getElementById('AvailableBox').style.color="black";
		document.getElementById('HideText').checked=true;
	}
	else
	{
		document.getElementById('BalanceBox').style.color="#BCBCBC";
		document.getElementById('AvailableBox').style.color="#BCBCBC";
		document.getElementById('HideText').checked=false;
	}
}


function ShowBets(e)
{
	if (document.getElementById('TheBets').style.visibility == "visible")
	{
		document.getElementById('TheBets').style.visibility="hidden"; 
	}
	else
	{
		if (document.all)
		{
			MouseX=window.event.clientX
			MouseY=window.event.clientY + document.body.scrollTop
		}
		else
		{
			MouseX=e.pageX
			MouseY=e.pageY
		}
	    
		callServer("show_bets.asp?eventid="+e)
		document.getElementById('TheBets').style.left=MouseX+50;
		document.getElementById('TheBets').style.top=MouseY-20;
		document.getElementById('TheBets').style.visibility="visible";
	}
}

function FlashCell(x)
{
	if (cellcolour=="black")
	{
		cellcolour="red";
	}
	else
	{
		cellcolour="black";
	}
	document.getElementById(x).style.color=cellcolour;
	flashcount=flashcount+1;

	if (flashcount>=6)
	{
		window.clearInterval(StartFlash);
		flashcount=0;
	}
}


function ClearBoxes(x)
{
	var elem=document.forms['LiveForm'].elements
	for (i=0; i<elem.length; i++)
	{
		if (elem[i].name!==x && !(elem[i].name.substring(0,8)=="TotalLow") && !(elem[i].name.substring(0,9)=="TotalHigh"))
		{
			if (elem[i].type=="text")
			{
				elem[i].value="";
			}
		}
	}
}
function CancelBet()
{
	document.getElementById('couponcell_1').innerHTML="";
	document.getElementById('couponcell_2').innerHTML="";
	document.getElementById('couponcell_3').innerHTML="";
	document.getElementById('content_right1').style.display="";
	document.getElementById('coupondiv').style.display="none";
	BetSubmitted=0;
}

function ShowPromo()
{
	document.getElementById('couponcell_1').innerHTML=""
	document.getElementById('couponcell_2').innerHTML=""
	document.getElementById('couponcell_3').innerHTML=""
	document.getElementById('confirmcell_1').innerHTML=""
	document.getElementById('confirmcell_2').innerHTML=""
	document.getElementById('confirmcell_3').innerHTML=""
	document.getElementById('confirmcell_4').innerHTML=""
	document.getElementById('content_right1').style.display="";
	document.getElementById('coupondiv').style.display="none";
	document.getElementById('confirmdiv').style.display="none";
	document.getElementById('acceptdiv').style.display="none";
}

function NoBet()
{
	alert("Please note that under Australian law,\n\nthis game is now live in running and being controlled by our Australian license,\n\nyou can only bet over the telephone on 1300 801 901.")
}

function XmasBet()
{
	alert("Legislation prohibits betting on Christmas Day.\n\nPlease telephone our office tomorrow.")
}
	
		
function ClearBoxes(x)
{
	for (i=0; i<elem.length; i++)
	{
		if (elem[i].name!==x && !(elem[i].name.substring(0,8)=="TotalLow") && !(elem[i].name.substring(0,9)=="TotalHigh"))
		{
			if (elem[i].type=="text")
			{
				elem[i].value="";
			}
		}
	}
}


function SubmitBet()
{
    if (BetSubmitted==1)
    {
        return false;
    }
    else
    {
        BetSubmitted=1;
    }
	for (i=0; i<elem.length; i++)
	{
		if (elem[i].type=="text")
		{
			if (!(elem[i].value=="") && !(elem[i].name.substring(0,8)=="TotalLow") && !(elem[i].name.substring(0,9)=="TotalHigh"))
			{
				var k=elem[i].name;
				if (document.getElementById('BetDividend').value !== w.elements[k+'Y'].value)
				{
					alert("Betting on this option has changed.\n\nPlease add the bet to your coupon again.");
					CancelBet();
					BetCost=0;
					BetSubmitted=0;
					return false;
				}

				if (k.substring(0,5) == "Total")
				{
					if (document.getElementById('BetHandicap').value !== w.elements[k+'X'].value)
					{
						alert("Betting on this option has changed.\n\nPlease add the bet to your coupon again.");
						CancelBet();
						BetCost=0;
						BetSubmitted=0;
						return false;
					}
				}
			}
		}
	}

	var theurl =	'public/add_bet.asp?' +
					'BetDividend=' + document.getElementById('BetDividend').value +
					'&TheHandicap=' + document.getElementById('TheHandicap').value +
					'&OptionID=' + document.getElementById('OptionID').value +
					'&EventID=' + document.getElementById('EventID').value +
					'&BetAmount=' + document.getElementById('BetAmount').value +
					'&TotalLow=' + document.getElementById('TotalLow').value +
					'&GapRuns=' + document.getElementById('GapRuns').value


	document.getElementById('couponcell_1').innerHTML=""
	document.getElementById('couponcell_2').innerHTML=""
	document.getElementById('couponcell_3').innerHTML=""
	document.getElementById('confirmcell_1').innerHTML="&nbsp;"
	document.getElementById('confirmcell_2').innerHTML="&nbsp;"
	document.getElementById('confirmcell_3').innerHTML="Please wait for<br />confirmation of bet."
	document.getElementById('confirmcell_4').innerHTML="<img border=0 src=public/images/loading.gif>"
	document.getElementById('content_right1').style.display="none";
	document.getElementById('coupondiv').style.display="none";
	document.getElementById('confirmdiv').style.display="";
	document.getElementById('acceptdiv').style.display="none";

	callServer(theurl,"OldAddBet");
	callServer("public/update_balance.asp","OldBalance");
	var updatebet=setInterval("callServer(\x27public/update_betstatus.asp\x27,\x27OldStatus\x27)", 2000);
	BetCost=0;
	BetSubmitted=1;
}

function ClearTables()
{
	AllTables=document.getElementsByTagName("div");

	for (i=0; i<AllTables.length; i++)
	{
		if (AllTables[i].id.substring(0,5)=="Table")
		{
			var HideIt=1;
			if (EventArray.length>0)
			{
				for (j=0; j<EventArray.length; j++)
				{
					if (AllTables[i].id == "Table"+EventArray[j])
					{
						HideIt=0
					}
				}
			}
			if (HideIt==1)
			{
				AllTables[i].style.display="none";
			}
		}
	}
}