﻿// JScript File

var timerID = null;
var clock = null;
var clockSpan;

function fav(sURL, title) 
{ 
    if (window.sidebar) 
    {
        window.sidebar.addPanel(title, sURL, '');
    } 
    else if (window.external) 
    {        
        window.external.AddFavorite(sURL , title);    
    } 
    else if (window.opera && window.print) 
    {
     
        var e = document.createElement('a');
         e.setAttribute('href',sURL);
         e.setAttribute('title',title);
         e.setAttribute('rel','sidebar');
         e.click();  
    }
};

function addbet365tofav(sURL, title)
{ 	
    window.external.AddFavorite( sURL, title ); 
};

function Start(yy,mo,da,hh,mm,ss)
{

/*

    Removed old version and added one that checks load state (for very slow machines that seem to try to start the js before the page is rendered
             
	clock=new Date(yy,mo,da,hh,mm,ss);
	clockSpan=document.getElementById('clock');
	if(typeof clockSpan!='undefined'){UpdateTimer(1000);}
 
*/ 	
   
    var oDoc = document;
    if(IsDocLoaded(oDoc))
    {
        clock=new Date(yy,mo,da,hh,mm,ss);
	    clockSpan=document.getElementById('clock');	    
	    if(typeof clockSpan!='undefined'){UpdateTimer(1000);}
    }
    else
    {
        setTimeout("Start(" + yy + "," + mo + "," + da + "," + hh + "," + mm + "," + ss + ");", 1000);
    }

};

function UpdateTimer(increase)
{
    var h;
    var m;
    var s;

	if(timerID)
	{
		clearTimeout(timerID);
	};

	clock.setTime(clock.getTime()+increase);
	
	if(clock.getHours()<10)
	{
		h='0'+clock.getHours();
	}
	else
	{
		h=clock.getHours();
	};
	
	if(clock.getMinutes()<10)
	{
		m='0'+clock.getMinutes();
	}
	else
	{
		m=clock.getMinutes();
	};
	
	if(clock.getSeconds()<10)
	{
		s='0'+clock.getSeconds();
	}
	else
	{
		s=clock.getSeconds();
	};
	
	clockSpan.innerHTML=""+h+":"+m+":"+s;
		
	timerID=setTimeout("UpdateTimer(1000)",1000);
	
};

function GetBrowser()
{
	var sBrowser=navigator.userAgent.toLowerCase();

	
	if(sBrowser.indexOf("chrome") != -1)
	{
		return 'CHROME';
	}
	else if(sBrowser.indexOf("opera") != -1)
	{
		return 'OPERA';
	}
	else if(sBrowser.indexOf("netscape") != -1)
	{
		if(sBrowser.indexOf("msie") != -1){return 'IE';}
		else{return 'NETSCAPE';}
	}
	else if(sBrowser.indexOf("firefox") != -1)
	{
		return 'FIREFOX';
	}
	else if(sBrowser.indexOf("safari") != -1)
	{
		return 'SAFARI';
	}
	else if(sBrowser.indexOf("msie 8.") != -1)
	{
		return 'IE8';
	}
	else if(sBrowser.indexOf("msie") != -1)
	{
		return 'IE';
	}
	else
	{
		return 'IE*';
	}
};

function GetScreenRes()
{
	var sHeight = screen.height;

	switch (GetBrowser())
	{
		case 'OPERA' :
			sHeight=(sHeight * 0.70);
			return sHeight;
		case 'NETSCAPE' :
			sHeight=sHeight-200;
			return sHeight;
		case 'IE' :
			sHeight=sHeight-250;
			return sHeight;
		case 'FIREFOX' :
			sHeight=sHeight-250;
			return sHeight;
		case 'IE8' :
			sHeight=sHeight-250;
			return sHeight;
	}
};

function GetScreenWidth()
{
	var sWidth = screen.width;
	sWidth=sWidth - (sWidth * 0.90);
	return Math.round(sWidth);
};

function GetScreenTop()
{
	var sTop = screen.height;
	sTop=sTop - (sTop * 0.88);
	return Math.round(sTop);
};

function drawFullWidthFlashMovie(sClassID, iHeight, sMovie, sBase, sColor, sQuality, sWMode, sID, sIDEmbed, sScale)
{
	if(typeof(sIDEmbed) === "undefined" || sIDEmbed === null)
	{
		sIDEmbed = sID;
	}
	if(typeof(sScale) === "undefined" || sScale === null)
	{
		sScale = "showall";
	}
	
	var sText =
		'<object id="' + sID + '" classid="' + sClassID + '" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100%" height="' + iHeight+ '"> ' +
			'<param name="movie" value="' + sMovie + '"> ' +
			'<param name="base" value="' + sBase + '"> ' +
			'<param name="quality" value="' + sQuality + '"/> ' +
			'<param name="bgcolor" value="' + sColor + '"/> ' +
			'<param name="wmode" value="' + sWMode + '"/> ' +
			'<param name="menu" value="false"/> ' +
			'<param name="scale" value="' + sScale + '"/> ' +
			'<param name="allowScriptAccess" value="true"/> ' +	
			'<embed id="' + sIDEmbed + '" name="' + sIDEmbed + '" wmode="' + sWMode + '" quality="high" bgcolor="' + sColor + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="100%" height="' + iHeight+ '" src="' + sMovie + '" base="' + sBase + '" menu="false" swLiveConnect="true" scale="' + sScale + '" allowScriptAccess="Always"></embed> ' +
		'</object>';
	document.write(sText);
};

function drawFlashMovie(sClassID, iHeight, iWidth, sMovie, sBase, sColor, sQuality, sWMode, sID, sIDEmbed, sScale)
{
	if(typeof(sIDEmbed) === "undefined" || sIDEmbed === null)
	{
		sIDEmbed = sID;
	}
	if(typeof(sScale) === "undefined" || sScale === null)
	{
		sScale = "showall";
	}
	
	var sText =
		'<object id="' + sID + '" classid="' + sClassID + '" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + iWidth + '" height="' + iHeight+ '"> ' +
			'<param name="movie" value="' + sMovie + '"> ' +
			'<param name="base" value="' + sBase + '"> ' +
			'<param name="quality" value="' + sQuality + '"/> ' +
			'<param name="bgcolor" value="' + sColor + '"/> ' +
			'<param name="wmode" value="' + sWMode + '"/> ' +
			'<param name="menu" value="false"/> ' +
			'<param name="scale" value="' + sScale + '"/> ' +
			'<param name="allowScriptAccess" value="true"/> ' +	
			'<embed id="' + sIDEmbed + '" name="' + sIDEmbed + '" wmode="' + sWMode + '" quality="high" bgcolor="' + sColor + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="' + iWidth + '" height="' + iHeight+ '" src="' + sMovie + '" base="' + sBase + '" menu="false" swLiveConnect="true" scale="' + sScale + '" allowScriptAccess="Always"></embed> ' +
		'</object>';
	document.write(sText);
};

function addbet365tofav(sURL, name, product, atString)
{ 
	var title = product + ' ' + atString + ' ' + name;  					 										
    window.external.AddFavorite( sURL, title ); 
};

function setCookie()
{
    var exdate=new Date();
        
    var currenthours = exdate.getHours();      
    currenthours += 3;
        
    if(currenthours > 23)
    {
        currenthours = currenthours - 24;     
        exdate.setDate(exdate.getDate() + 1);  
    }   
               
    exdate.setHours(currenthours);
    document.cookie= "bet365_OpenAccount_Session=True;expires="+exdate.toGMTString() + ";path=/";
    
};

function checkCookie()
{
var openAccountCookie=getCookie('bet365_OpenAccount_Session')
var recall = true;
var sBsr = GetBrowser();

if ((openAccountCookie!=null && openAccountCookie!="") || sBsr =='OPERA')
  {
    
  }
else 
  { 
    recall = false;
    window.location = window.location;
  }
  
  if(recall)
  {
     setTimeout("checkCookie();", 1000);
  }

};

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 IsDocLoaded(oDoc)
{
    var sBsr = GetBrowser();
    var sState = false;

    if (sBsr =='FIREFOX')
    {
          sState = true;
    }
    else if (sBsr =='SAFARI')
    {
          if (/loaded|complete/.test(document.readyState))
          {
                sState = true;
          }
    }
    else
    {
          if(oDoc.readyState=="complete" || oDoc.readyState=="interactive")
          {
                sState = true;
          }
    }

    return sState;

};

function findTop(htmlElementId) {
    var obj;
	obj=document.getElementById(htmlElementId);	
    var curtop = 0;
    
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return curtop;
}

function findLeft(htmlElementId) {
    var obj;
	obj=document.getElementById(htmlElementId);	
    var curleft = 0;
    
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	}
	return curleft;
}

function setElementPositionWithinMultiBanner(targetName, parentName, XPos, YPos) 
{
    var targetControl;
    var parentControl;
    
    targetControl=document.getElementById(targetName);
	parentControl=document.getElementById(parentName);
	
    var newTopPos = 0;
    var newLeftPos = 0;
   
    newTopPos = findTop(parentName) + YPos - 111;
    newLeftPos = findLeft(parentName) + XPos;
    
    targetControl.style.top = newTopPos + "px";      
    targetControl.style.left = newLeftPos + "px";    
}

function setElementPositionWithinMultiBannerOnDownloadClient(targetName, parentName, XPos, YPos) 
{
    var targetControl;
    var parentControl;
    
    targetControl=document.getElementById(targetName);
	parentControl=document.getElementById(parentName);
	
    var newTopPos = 0;
    var newLeftPos = 0;
   
    newTopPos = findTop(parentName) + YPos;
    newLeftPos = findLeft(parentName) + XPos;
    
    targetControl.style.top = newTopPos + "px";      
    targetControl.style.left = newLeftPos + "px";    
}

function setElementPositionWithinMultiBannerOnHomePage(targetName, parentName, XPos, YPos, headerOffset) 
{    
    var within2003 = false;
    if(navigator.userAgent.toLowerCase().indexOf("windows nt 5.2") > -1)
    {
        within2003 = true;
    }
    
    var targetControl;
    var parentControl;
    
    targetControl=document.getElementById(targetName);
	parentControl=document.getElementById(parentName);
	
    var newTopPos = 0;
    var newLeftPos = 0;
    
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth - 17;
    myHeight = window.innerHeight - 17;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;    
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    
    var browser = GetBrowser();    
    var mainDiv=document.getElementById("ctl00_MainPageContainer");
	var leftMargin = 0;
    
    if(myWidth > 990)
    {
        if(myWidth % 2 != 0)
        {                      
            if(browser == 'SAFARI' || browser == 'CHROME')
            {                    
                if(document.height > window.innerHeight)
                {                    
                    myWidth -= 1;
                }                    
            }    
            if(browser == 'OPERA')
            {                    
                if((mainDiv.offsetHeight + headerOffset) > window.innerHeight)
                {        
                    myWidth -= 1;  
                }                    
            }      
            if(browser == 'FIREFOX')
            {                    
                if((mainDiv.offsetHeight + headerOffset) < window.innerHeight)
                {        
                    myWidth -= 1;  
                }                    
            }      
            if(browser == 'IE')
            {      
                myWidth -= 1;               
            }     
            if(browser == 'IE8' && !within2003)
            {
                myWidth -= 1;
            }    
        }                     
               
        leftMargin = Math.round((myWidth - 990) / 2);
        
        if (browser == 'SAFARI')
        {
            leftMargin += 1;
        }
    }
    
    if(browser == 'IE')
    {  
        leftMargin -= 3;
        headerOffset -= 3;
    }
           
    if(browser == 'SAFARI' && document.height <= window.innerHeight)
    {
        leftMargin += 7;
    }    
    
    if(browser == 'CHROME' && document.height <= window.innerHeight)
    {
        leftMargin += 8;
    }
    
    if(browser == 'OPERA' && (mainDiv.offsetHeight + headerOffset) <= window.innerHeight)
    {        
        leftMargin += 8;
    }
    
    if(browser == 'FIREFOX' && (mainDiv.offsetHeight + headerOffset) <= window.innerHeight)
    {        
        leftMargin += 9;
    }
       
    newTopPos = findTop(parentName) + YPos - headerOffset;
    newLeftPos = findLeft(parentName) + XPos - leftMargin;
    
    targetControl.style.top = newTopPos + "px";      
    targetControl.style.left = newLeftPos + "px";    
}

function setElementPositionWithinMultiBannerOnLandingPage(targetName, parentName, XPos, YPos, headerOffset) 
{

    var within2003 = false;
    if(navigator.userAgent.toLowerCase().indexOf("windows nt 5.2") > -1)
    {
        within2003 = true;
    }
    
    var targetControl;
    var parentControl;
    
    targetControl=document.getElementById(targetName);
	parentControl=document.getElementById(parentName);
	
    var newTopPos = 0;
    var newLeftPos = 0;
   
    var browser = GetBrowser();    
    
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) 
    {
        //Non-IE        
        if(browser == 'OPERA')
        {
            myWidth = window.innerWidth - 17;
            myHeight = window.innerHeight - 17; 
        }
        else
        {
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;     
        }
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;    
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    
    var leftMargin = 0;
    var mainDiv=document.getElementById("ctl00_MainPageContainer");
	
    if(myWidth > 960)
    {         
        if(myWidth % 2 != 0)
        {                    
            if(browser == 'SAFARI' || browser == 'CHROME')
            {                    
                if(document.height <= window.innerHeight)
                {                    
                    myWidth -= 1;
                }                    
            }    
            if(browser == 'OPERA')
            {                    
                if((mainDiv.offsetHeight + headerOffset) > window.innerHeight)
                {        
                    myWidth -= 1;  
                }                    
            }      
            if(browser == 'FIREFOX')
            {                    
                if((mainDiv.offsetHeight + headerOffset) > window.innerHeight)
                {        
                    myWidth -= 1;  
                }                    
            }      
            if(browser == 'IE')
            {      
                myWidth -= 1;               
            }
            if(browser == 'IE8' && !within2003)
            {
                myWidth -= 1;
            }
        }       
        leftMargin = Math.round((myWidth - 960) / 2);
    }    
   
    if(browser == 'SAFARI' && document.height > window.innerHeight)
    {
        leftMargin -= 8;
    }    
    
    if(browser == 'CHROME' && document.height > window.innerHeight)
    {
        leftMargin -= 9;
    }    
        
    if(browser == 'OPERA' && (mainDiv.offsetHeight + headerOffset) <= window.innerHeight)
    {        
        leftMargin += 8;
    }
    
    if(browser == 'FIREFOX' && (mainDiv.offsetHeight + headerOffset) > window.innerHeight)
    {        
        leftMargin -= 8;
    }   
           
    //Dont need to use header offset on landing page as whole page is in 1 main absolute div
    
    newTopPos = findTop(parentName) + YPos;
    newLeftPos = findLeft(parentName) + XPos - leftMargin;
    
    targetControl.style.top = newTopPos + "px";      
    targetControl.style.left = newLeftPos + "px";    
    
}

function setElementPositionWithinMultiBannerOnLandingPageVersion2(targetName, parentName, XPos, YPos, headerOffset) 
{
    var within2003 = false;
    if(navigator.userAgent.toLowerCase().indexOf("windows nt 5.2") > -1)
    {
        within2003 = true;
    }
    
    var targetControl;
    var parentControl;
    
    targetControl=document.getElementById(targetName);
	parentControl=document.getElementById(parentName);
	
    var newTopPos = 0;
    var newLeftPos = 0;
            
    //Dont need to use header offset on landing page as whole page is in 1 main absolute div
    
    var outerTopPos = findTop("ctl00_SectionAPlaceHolder_SectionAControl_SectionAOuterCountainer")
    var outerLeftPos = findLeft("ctl00_SectionAPlaceHolder_SectionAControl_SectionAOuterCountainer")
    
    newTopPos = findTop(parentName) + YPos - outerTopPos;
    newLeftPos = findLeft(parentName) + XPos - outerLeftPos;
          
    var browser = GetBrowser();    
    if(browser == 'OPERA')
    {        
        newLeftPos -= 3;
        newTopPos -= 3;
    }    
    else if(browser == 'IE8' && !within2003)
    {
        newLeftPos -= 3;
        newTopPos -= 3;
    }
    
    targetControl.style.top = newTopPos + "px";      
    targetControl.style.left = newLeftPos + "px";    
}

function verticalCentreModalPopup(modalPopupBehaviour, panelDivClientId, safariWidth)
{
    var modalPopupObj = $find(modalPopupBehaviour);
    modalPopupObj.show();
    
    var browser = GetBrowser();
    if(browser == 'OPERA')
    {         
        var sheight = window.innerHeight / 2;
        var panelDiv = document.getElementById(panelDivClientId);
        sheight = sheight - (panelDiv.offsetHeight / 2);        
        panelDiv.style.top = sheight + 'px';
    }  
    if(browser == 'SAFARI')
    {  
        var panelDiv = document.getElementById(panelDivClientId);
        panelDiv.style.width = safariWidth + 'px';
        
        var sWidth = window.innerWidth / 2;
        sWidth = sWidth - (panelDiv.offsetWidth / 2);        
        panelDiv.style.left = sWidth + 'px';             
    }    
}

function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}

function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}

function ajaxRequest()
{
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    { 
        // code for IE6, IE5
        return  new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        return null;
    }
}

function LogTrackingEvent(appPath, linkType, originatingLinkPath)
{   
    var xmlhttp = new ajaxRequest();
    if(xmlhttp != null)
    {
        var trackingURL = appPath + "/Tracker/ClickThruTracker2.aspx?LinkType=" + linkType + "&OriginatingLinkPath=" + originatingLinkPath
        xmlhttp.open("GET", trackingURL, true); 
        xmlhttp.send(null);
    }
}