﻿// 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)
{  
    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("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") != -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;
		default:		    
			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 addbet365tofav(sURL, name, product, atString)
{ 
	var title = product + ' ' + atString + ' ' + name;  					 										
    window.external.AddFavorite( sURL, title ); 
};

var cookieHasNotYetBeenChecked = true;
var cookieHasExisted = false;

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();
    
};

function checkCookie()
{
    var openAccountCookie=getCookie('bet365_OpenAccount_Session')
    var recall = true;

    if ((openAccountCookie!=null && openAccountCookie!="") || cookieHasNotYetBeenChecked)
    {
        if(openAccountCookie!=null && openAccountCookie!="" && !cookieHasExisted)
        {
            cookieHasNotYetBeenChecked = false;
            cookieHasExisted = true;
        }
    }
    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";    
}

/* TOOL TIP POP UP */
var selectedID = null;
var oTimer = null;
function showTooltip(sID,e){
	if(selectedID!=null && sID != selectedID){
		hideTooltip();
	}
	selectedID = sID;
	var oDiv = document.getElementById(sID);
	setTooltipPos(e);				
	if(oDiv != null){
		oDiv.style.display = "block";
		oDiv.style.visibility = "visible";				
	}
	if(oTimer != null){
		clearInterval(oTimer);
	}
	oTimer = setInterval("hideTooltip()", 7000)
}

function setTooltipPos(e){
	var xpos;
	var ypos;		
	if(window.event){
		xpos = event.x;
		ypos = event.y;
	}
	else{
		if(e == null){
			return;
		}
		xpos = e.clientX;
		ypos = e.clientY;						
	}
	var st = typeof(document.documentElement.scrollTop) == 'number' ? document.documentElement.scrollTop : 0;
	if(0 === st)	{
		st = document.body.scrollTop;
	}			
	if(0 === st)	{
		st = document.body.scrollTop;
	}			
							
	var oDiv = document.getElementById(selectedID);
	if(oDiv != null){
		oDiv.style.display = "block";
		oDiv.style.visibility = "visible";
		if(xpos+232 >= document.body.scrollWidth){
				oDiv.style.left = document.body.scrollWidth - 232+"px";
				oDiv.style.top = ypos + 20 + st - 111 + "px";									
		}
		else{
			oDiv.style.left =  xpos + 5 + "px";
			oDiv.style.top = ypos + 5  +st - 111 + "px";								
		}				
	}	
	if(oTimer != null){
		clearInterval(oTimer);
	}
	oTimer = setInterval("hideTooltip()", 7000)					
}

function hideTooltip(){
	var oDiv = document.getElementById(selectedID);
	if(oDiv != null){
		oDiv.style.display = "none";
		oDiv.style.visibility = "hidden";
	}
	selectedID = null;
}	
		
/* END OF TOOL TIP POP UP */

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';
        iisreset
        var sWidth = window.innerWidth / 2;
        sWidth = sWidth - (panelDiv.offsetWidth / 2);        
        panelDiv.style.left = sWidth + 'px';             
    }    
}

function RedirectParentWindow(classId, targetURL, widthForPopupIfNeeded, heightForPopupIfNeeded)
{

    var parentWindow = window.opener;
    var useCurrentWindow = true;
    var closeChild = true;
     
    if(parentWindow != null){
        try{
            useCurrentWindow = !setSportsWindowLocation(targetURL);            
        }
        catch(e){          
            useCurrentWindow = true;
        }
    }
    
    if(useCurrentWindow){
        window.location = targetURL;      
    }    
    else{
        if (closeChild){
            if(window.close != undefined){
                window.close();
                if (window != undefined){
                    window.open('','_parent','');
                    window.close();
                }
            }
            else {
                self.close();
            }
        }
    }
    return false;
}

function setSportsWindowLocation(url){
    var success;
    try{        
        if (window.opener==null){
            success = false;
        }
        else {
            if (window.opener.frames.top!=null){
                window.opener.frames.top.location = url;
                success = true;
            }
            if (window.opener.frames.length > 0 && window.opener.frames['top'] != null){
                window.opener.frames['top'].document.location = url;
                success = true;
            }
        }
    }
    catch(e){
        success = false;
    }
    return success;

}
function SportsLink(link){
    RedirectParentWindow(0, link.href, 0,0);
}
