//
var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf("msie") != -1);
var is_win = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var is_ie5 = (agt.indexOf("msie 5") != -1) || (agt.indexOf("msie 6") != -1) || (agt.indexOf("msie 7") != -1);

var TrapDelay=35;
var TrapTime=0;
var TrapMessage="";

var LoginStarted=0;

var BannerURL=new Array(5);
var BannerHttp=null;
var BannerHTML="";
var BannerTime=0;
var BannerEnabled=1;
var BannerType=0;
var BannerTimer=null;

var ResultsHttp=null;
var ResultsHTML="";

var TooltipID="Tooltip";
var TooltipTimer=0;
var TootipOffTimer=0;
var TooltipDIV=null;
var TooltipOffsetX=8;
var TooltipOffsetY=12;
var TooltipShowDelay=100;
var TooltipHideDelay=200;
var TooltipOffDelay=5000;

var SelectorLastTip="";
var SelectorTimer=0;

var BetSlipTimer=0;
var BetStakeTimer=0;
var BetShopTimer=0;

var ReportPage=0;
var ReportMaxPages=0;

var LiveTimestamp=0;
var LiveSports=0;
var LiveTimer=0;

var MAX = 49;
var mhttp = new Array(MAX);
var bhttp = new Array(MAX);

function Initialize() {
   if (document.createElement && document.body && typeof document.body.appendChild != "undefined") {
		if (!document.getElementById(TooltipID)) {
			var el = document.createElement("DIV");
			el.id = TooltipID; 
			document.body.appendChild(el);
      }
   }

   if (typeof(DoBanner)=="function") {
		DoBanner();
	}
   if (typeof(DoResults)=="function") {
		DoResults();
	}
   if (typeof(DoBetSlip)=="function") {
		DoBetSlip();
	}
	if (typeof(SetFocus)=="function") {
		SetFocus();
	}
	if (typeof(Reposition)=="function") {
		Reposition();
	}
   if (typeof(ShowMessage)=="function") {
		ShowMessage();
	}
   if (typeof(InitPage)=="function") {
		InitPage();
	}	
	
	if (typeof(PartnerLogin)=="function") {
		PartnerLogin();
	}
	
	if (location.href.indexOf("tid=loUs")>0) MenuClick("mnuLi");
}

function TrapClick() {
	var tDate = new Date;
	var localTrapTime = tDate.valueOf();
	var diffTime=localTrapTime - TrapTime;
	if (diffTime > (TrapDelay * 1000)) {
		TrapTime = localTrapTime;
		return true;
	}
	else {
		var timeClick=parseInt(TrapDelay-(diffTime/1000));
		alert(TrapMessage.replace("%D%",timeClick));
		return false;
	}
}

function ShowSupport() {
	var w=600;
	var h=550;
	var x=window.document.body.clientWidth/2-w/2;
	var y=window.document.body.clientHeight/2-h/2;
	window.open("MailSupport.aspx","i","scrollbars=yes,width=" + w +",height=" + h + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY="+ y + ",dependent=yes");
	return false;
}

function ShowTooltip(e,txt,w,pa,de) {
	if (TooltipTimer) { 
		clearTimeout(TooltipTimer);
		TooltipTimer = 0; 
	}
   TooltipDIV = document.getElementById(TooltipID);
   if (TooltipDIV == null) return;
   if (txt.length==0) {
		//ToggleTooltip(TooltipID, 'hidden');
		return;
	}
   TooltipDIV.innerHTML="";
   var utxt=unescape(txt)
   TooltipDIV.innerHTML=utxt;
	if (w) 
		TooltipDIV.style.width=w+"px";
	else {
		w=Math.floor(utxt.length*5.5);
		if (w<250) w=250;
		TooltipDIV.style.width=w+"px";
	}
	if (pa!=null) 
		TooltipDIV.style.padding=pa;
	else
		TooltipDIV.style.padding=4;
	
	var width = 0;
	if (window.innerWidth) 
		width = window.innerWidth - 18;
	else if (document.documentElement && document.documentElement.clientWidth) 
		width = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		width = document.body.clientWidth;
  
	var height = 0;
	if (window.innerHeight) 
		height = window.innerHeight - 18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		height = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		height = document.body.clientHeight;
     	
	var scrollX = 0;
  	if (typeof window.pageXOffset == "number") 
  		scrollX = window.pageXOffset;
  	else if (document.documentElement && document.documentElement.scrollLeft)
  		scrollX = document.documentElement.scrollLeft;
  	else if (document.body && document.body.scrollLeft) 
  		scrollX = document.body.scrollLeft; 
  	else if (window.scrollX) scrollX = window.scrollX;
 
   var scrollY = 0;    
   if (typeof window.pageYOffset == "number") 
		scrollY = window.pageYOffset;
   else if (document.documentElement && document.documentElement.scrollTop)
  		scrollY = document.documentElement.scrollTop;
  	else if (document.body && document.body.scrollTop) 
  		scrollY = document.body.scrollTop; 
  	else if (window.scrollY) scrollY = window.scrollY;

   var x = e.pageX? e.pageX: e.clientX + scrollX;
   var y = e.pageY? e.pageY: e.clientY + scrollY;

   if ( x + TooltipDIV.offsetWidth + TooltipOffsetX > width + scrollX ) {
		x = x - TooltipDIV.offsetWidth - TooltipOffsetX;
   if ( x < 0 ) 
		x = 0;
   } 
   else 
		x = x + TooltipOffsetX;
        
   if ( y + TooltipDIV.offsetHeight + TooltipOffsetY > height + scrollY ) {
		y = y - TooltipDIV.offsetHeight - TooltipOffsetY;
		if ( y < scrollY ) y = height + scrollY - TooltipDIV.offsetHeight;
	} 
	else 
		y = y + TooltipOffsetY;
   
   if (!(x>=0)) x=0;
   if (!(y>=0)) y=0;
   TooltipDIV.style.left = x + "px"; TooltipDIV.style.top = y + "px";
   if (de!=null)
		TooltipOffTimer = setTimeout("HideTooltip()", de);
	else
		TooltipOffTimer = setTimeout("HideTooltip()", TooltipOffDelay);
   TooltipTimer = setTimeout("ToggleTooltip('"+TooltipID+"', 'visible')", TooltipShowDelay);
}

function HideTooltip() {
	if (typeof(TooltipOffTimer)=="number") {
		if (TooltipOffTimer) {
			clearTimeout(TooltipOffTimer);
			TooltipOffTimer = 0; 
		}
	}
   if (TooltipTimer) {
		clearTimeout(TooltipTimer);
		TooltipTimer = 0; 
	}
   TooltipTimer = setTimeout("ToggleTooltip('"+TooltipID+"', 'hidden')", TooltipHideDelay);
}

function ToggleTooltip(id, v) {
        var e = document.getElementById(id);
        if (e) e.style.visibility = v;
}

function CenterX(wi,ab) {
	var o=0;
	if (typeof window.screenLeft == "number")
		o=window.screenLeft;
	else if (typeof window.screenX == "number")
		o=window.screenX;
	return window.document.body.clientWidth/2-wi/2+o;
}

function CenterY(he) {
	var o=0;
	if (typeof window.screenTop == "number") 
		o=window.screenTop;
	else if (typeof window.screenY == "number") 
		o=window.screenY;
	return window.document.body.clientHeight/2-he/2+o;
}

function ParseBody(txtIn) {
	var txtOut="";
	var start = txtIn.indexOf("<body");
	var end = txtIn.indexOf("</body>");
	if (start >= 0 && end > 0) {
		start=txtIn.indexOf(">",start)+1;
		txtOut=txtIn.substring(start,end);
	}
	return txtOut;
}

function MenuClick(id) {
	if (LoginStarted!=0) return false;
	var lh=location.href;
	if (id.indexOf("mnuLi")==0 && lh.indexOf("https")==-1) {
		LoginStarted=true;
		lh=lh.replace("http://","https://");
		if (lh.indexOf("?")>0) 
			lh+="&"
		else 
			lh+="?";
		lh+="tid=loUs";
		location.href=lh;
		return false;
	}
	var e=document.getElementById(id);
	if (e==null) {
		if (document.getElementById(id.replace("_",""))==null) {
			if (document.getElementById("_"+id)==null) {
				window.location.href="Default.aspx?mnu="+id;
				return false;
			}
			else id="_"+id;
		}
		else id=id.replace("_","");
	}
	var menus=document.getElementById("mainMenu").getElementsByTagName("*");
	for (i=0;i<menus.length;i++) {
		e=menus[i];
		if (e.id.indexOf("mnu") > 0 && e.id.indexOf("_") == 0 && e.id.indexOf(id)==-1) {
			e.className="menuOff";
			se=document.getElementById("s"+e.id);
			if (se != null) se.style.display="none";
			e.id=e.id.replace("_","");
			se.id="s"+e.id;
			break;
		}
	}
	if (id.indexOf("_")==-1) {
		e=document.getElementById(id);
		eid=e.id;
		e.className="menuOn";
		e.id="_"+e.id;

		se=document.getElementById("s"+eid);
		se.style.display="";
		se.id="s"+e.id;
		
		var firstPass=false;
		menus=se.getElementsByTagName("*");
		for (i=0;i<menus.length;i++) {
			e=menus[i];
			if (e.id.indexOf("mnu") == 0 || e.id.indexOf("_mnu") == 0) {
				if (firstPass) {
					e.className="submenuOff";
				}
				else {
					if (e.id.indexOf("mnuLi")==-1) {
						e.className="submenuOn";
						firstPass=true;
					}
				}
			}
		}
	}
	if (id.indexOf("mnuLi")==-1)	{
		LoginStarted=true;
		return true;
	}
	else {
		if (GetFlashVersion()<9) {
			ShowWindow(300,200,'NoFlash.aspx');
		}
		else {
			setTimeout("FocusLogin()",250);
		}
		return false;
	}
}

function FocusLogin() {
	var el=document.getElementById("OddsLogin");
	if (el) {
		if (is_ie)
			el.focus();
		else {
			if (document.embeds && document.embeds[el.id]) {
				document.embeds[el.id].focus();
			}
		}
	}
}

function MenuSel(id) {
	if (LoginStarted!=0) return;
	if (id.indexOf("_")==-1) {
		document.getElementById(id).className="menuSel";
	}
}

function MenuOff(id) {
	if (LoginStarted!=0) return;
	if (id.indexOf("_")==-1) {
		document.getElementById(id).className="menuOff";
	}	
}

function SubmenuSel(id) {
	if ((id.indexOf("_")>0) || (id.length==4)) {
		document.getElementById("H"+id).className="SubmenuSel";
	}
}

function SubmenuOff(id) {
	if ((id.indexOf("_")>0) || (id.length==4)) {
		document.getElementById("H"+id).className="Submenu";
	}
}

function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { 
     temp = temp.replace(obj, '$2'); 
   }
   return temp;
}

function parseResponseHeader(key, header) { 
  var lines = header.split("\n"); 
  var re = new RegExp("^" + key + ":\\s");
  for (var i in lines) { 
    if (re.exec(lines[i])) { 
      var returnValue = trim(RegExp.rightContext); 
      return returnValue; 
    } 
  } 
  return ""; 
} 

function HttpReq(handler) {

  var http = null;
  if (is_ie) {
    var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    try {
      http = new ActiveXObject(control);
      http.onreadystatechange = handler;
    } catch (ex) {
      alert("You need to enable active scripting and activeX controls.");  
    }
  } else {
    http = new XMLHttpRequest();
    http.onload = handler;
    http.onerror = handler;
  }
  return http;
}

function HttpGET(http, url) {
  try {
    http.open("GET", url, true);	
    http.send(null);
  } catch (ex) {
  }
}

function format (expr, decplaces) {
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	while (str.length <= decplaces) {
		str = "0" + str
	}
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "," + str.substring(decpoint,str.length);
}

function RunFlash(pSrc,pWid,pHei,pFV, pWM, pQ, pBG, pID) {
var	ht= "\n<OBJECT codeBase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' height='" + pHei + "' width='" + pWid + "' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>\n";
		ht+="<PARAM NAME='FlashVars' VALUE='" + pFV + "'>\n";
		ht+="<PARAM NAME='Movie' VALUE='" + pSrc + "'>\n";
		ht+="<PARAM NAME='Src' VALUE='" + pSrc + "'>\n";
		ht+="<PARAM NAME='WMode' VALUE='" + pWM + "'>\n";
		ht+="<PARAM NAME='Play' VALUE='-1'>\n";
		ht+="<PARAM NAME='Loop' VALUE='-1'>\n";
		ht+="<PARAM NAME='Quality' VALUE='" + pQ + "'>\n";
		ht+="<PARAM NAME='Menu' VALUE='0'>\n";
		ht+="<PARAM NAME='AllowScriptAccess' VALUE='always'>\n";
		ht+="<PARAM NAME='Scale' VALUE='ShowAll'>\n";
		ht+="<PARAM NAME='DeviceFont' VALUE='0'>\n";
		ht+="<PARAM NAME='EmbedMovie' VALUE='0'>\n";
		ht+="<PARAM NAME='BGColor' VALUE='" + pBG + "'>\n";
		ht+="<PARAM NAME='SeamlessTabbing' VALUE='1'>\n";
		var wm="'";
		if ((pWM.length>0) && (pWM.toLowerCase()!="window")) {
			wm="' wmode='"+pWM+"'";
		}
		ht+="<embed src='" + pSrc + wm + " quality='" + pQ + "' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' flashvars='" + pFV + "' width='" + pWid + "' height='" + pHei + "'></embed>\n";
		ht+="</OBJECT>\n";
		if (pID!=null) {
			ht=ht.replace("<OBJECT codeBase","<OBJECT id='"+pID+"' codeBase");
			ht=ht.replace("<embed src","<embed name='"+pID+"' src");
		}
		document.write(ht);
}

function RunFlash2(pSrc,pWid,pHei,pFV, pWM, pQ, pBG, pID) {
var	ht= "\n<OBJECT codeBase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' height='" + pHei + "' width='" + pWid + "' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>\n";
		ht+="<PARAM NAME='FlashVars' VALUE='" + pFV + "'>\n";
		ht+="<PARAM NAME='Movie' VALUE='" + pSrc + "'>\n";
		ht+="<PARAM NAME='Src' VALUE='" + pSrc + "'>\n";
		ht+="<PARAM NAME='WMode' VALUE='" + pWM + "'>\n";
		ht+="<PARAM NAME='Play' VALUE='-1'>\n";
		ht+="<PARAM NAME='Loop' VALUE='-1'>\n";
		ht+="<PARAM NAME='Quality' VALUE='" + pQ + "'>\n";
		ht+="<PARAM NAME='Menu' VALUE='0'>\n";
		ht+="<PARAM NAME='AllowScriptAccess' VALUE='always'>\n";
		ht+="<PARAM NAME='Scale' VALUE='NoBorder'>\n";
		ht+="<PARAM NAME='DeviceFont' VALUE='0'>\n";
		ht+="<PARAM NAME='EmbedMovie' VALUE='0'>\n";
		ht+="<PARAM NAME='BGColor' VALUE='" + pBG + "'>\n";
		ht+="<PARAM NAME='SeamlessTabbing' VALUE='1'>\n";
		ht+="<PARAM NAME='salign' VALUE='t'>\n";
		ht+="<embed src='" + pSrc + "' wmode='" + pWM + "' quality='" + pQ + "' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' flashvars='" + pFV + "' salign='t' width='" + pWid + "' height='" + pHei + "'></embed>\n";
		ht+="</OBJECT>\n";
		if (pID!=null) {
			ht=ht.replace("<OBJECT codeBase","<OBJECT id='"+pID+"' codeBase");
			ht=ht.replace("<embed src","<embed name='"+pID+"' src");
		}
		document.write(ht);
}

function FlashControlVersion() {
	var version,axo,e;
	try {
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} 
	catch (e) {}

	if (!version)	{
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			version = "WIN 6,0,21,0";
			axo.AllowScriptAccess = "always";
			version = axo.GetVariable("$version");
		} 
		catch (e) {}
	}
	if (!version)	{
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} 
		catch (e) {}
	}
	if (!version)	{
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} 
		catch (e) {}
	}
	if (!version)	{
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} 
		catch (e) {
			version = -1;
		}
	}
	return version;
}

function GetFlashVersion(){
	var flashVer = -1;
	if (navigator.plugins!=null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			} else if (versionRevision[0] == "b") {
				versionRevision = versionRevision.substring(1);
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if (is_ie && is_win) {
		flashVer = FlashControlVersion();
	}
	
	if (flashVer==-1) {
		return 0;
	} 
	else  {
		var va;
		if(is_ie && is_win ) {
			var ta=flashVer.split(" ");
			va=ta[1].split(",");
		} 
		else {
			va=flashVer.split(".");
		}
		return parseFloat(va[0]+"."+va[1]);
	}
}

function ShowWindow(w,h,url) {
	var x=window.document.body.clientWidth/2-w/2;
	var y=window.document.body.clientHeight/2-h/2;
	window.open(url,"i","scrollbars=yes,width=" + w +",height=" + h + ",left=" + x + ",top=" + y + ",screenX=" + x + ",screenY="+ y + ",dependent=yes");
	return false;
}