﻿// 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("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("chrome") != -1)
	{
		return 'CHROME';
	}
	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;
	}
};

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 + '" name="' + 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 closeWindows ()
{
	for (var i in windows) {
		if (windows[i]) {
			windows[i].close();
		}
	}
}


function showMoreInfo(targetName, topPos, Persist, persistName)
{
    var targetControl;
    var persistControl;
	targetControl=document.getElementById(targetName);
	persistControl=document.getElementById(persistName);

    if (Persist == "True") 
    {
        persistControl.value = "True";
    }
    targetControl.style.display = "block";
    targetControl.style.top = topPos + "px";

}

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 showMoreInfoDynamicPos(targetName, parentButtonName, columnNumber, totalColumns, Persist, persistName)
{
    var targetControl;
    var parentControl;
    var persistControl;
	targetControl=document.getElementById(targetName);
	parentControl=document.getElementById(parentButtonName);
	persistControl=document.getElementById(persistName);
   
    if (Persist == "True") 
    {
        persistControl.value = "True";
    }
      
    targetControl.style.display = "block";
    
    var newTopPos = 0;
    var newLeftPos = 0;
    
    if (totalColumns == 3 && columnNumber != 3)
    {
        newTopPos = findTop(parentButtonName) - 110 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) + 1;
    }
    else if (totalColumns == 3 && columnNumber == 3)
    {
        newTopPos = findTop(parentButtonName) - 110 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) - targetControl.offsetWidth + parentControl.offsetWidth;
    }
    else if (totalColumns == 2 && columnNumber == 1)
    {
        newTopPos = findTop(parentButtonName) - 111 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) + 1;
    }
    else if (totalColumns == 2 && columnNumber == 2)
    {
        newTopPos = findTop(parentButtonName) - 111 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) + 1 - targetControl.offsetWidth + parentControl.offsetWidth;
    }
   
    targetControl.style.top = newTopPos + "px";      
    targetControl.style.left = newLeftPos + "px";      
}

function showMoreInfoDynamicPos(targetName, parentButtonName, columnNumber, totalColumns, imageURL, imageClientId, Persist, persistName)
{
    var targetControl;
    var parentControl;
    var persistControl;
	var imageControl;
	
	targetControl=document.getElementById(targetName);
	parentControl=document.getElementById(parentButtonName);
	persistControl=document.getElementById(persistName);
    imageControl=document.getElementById(imageClientId);
    
    if (imageControl.src == null || imageControl.src != imageURL)
    {
        imageControl.src = imageURL
    }
   
    if (Persist == "True") 
    {
        persistControl.value = "True";
    }
      
    targetControl.style.display = "block";
    
    var newTopPos = 0;
    var newLeftPos = 0;
    
    if (totalColumns == 3 && columnNumber != 3)
    {
        newTopPos = findTop(parentButtonName) - 110 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) + 1;
    }
    else if (totalColumns == 3 && columnNumber == 3)
    {
        newTopPos = findTop(parentButtonName) - 110 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) - targetControl.offsetWidth + parentControl.offsetWidth;
    }
    else if (totalColumns == 2 && columnNumber == 1)
    {
        newTopPos = findTop(parentButtonName) - 111 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) + 1;
    }
    else if (totalColumns == 2 && columnNumber == 2)
    {
        newTopPos = findTop(parentButtonName) - 111 - targetControl.offsetHeight;
        newLeftPos = findLeft(parentButtonName) + 1 - targetControl.offsetWidth + parentControl.offsetWidth;
    }
   
    targetControl.style.top = newTopPos + "px";      
    targetControl.style.left = newLeftPos + "px";      
}

function hideMoreInfo(targetName, persistName, overridePersist)
{
    var targetControl;
    var persistControl;
	targetControl=document.getElementById(targetName);
	persistControl=document.getElementById(persistName);

    if (persistControl.value == "False" || overridePersist == "True")
    {
        targetControl.style.display = "none";
        persistControl.value = "False";
    }
}

//window.onresize= resizeIE6;

//function resizeIE6() {
//    if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1)
//    {
//        location.reload(true);
//    }
//}

var cookieHasNotYetBeenChecked = true;
var cookieHasExisted = false;

function setCookie(expiryMins)
{
    var exdate=new Date();

    if((expiryMins != null) && 
    (expiryMins > 0))
    {
        exdate.setTime(exdate.getTime() + (expiryMins * 60 * 1000));
    }
    else
    {
        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;

    if ((openAccountCookie!=null && openAccountCookie!="") || cookieHasNotYetBeenChecked)
    {
        if(openAccountCookie!=null && openAccountCookie!="" && !cookieHasExisted)
        {
            cookieHasNotYetBeenChecked = false;
            cookieHasExisted = true;
        }
    }
    else 
    {       
        recall = false;
        var exdate=new Date();
	    exdate.setDate(exdate.getDate() - 1);	
	    document.cookie = "bet365_OpenAccount_Session=;expires="+exdate.toGMTString() + ";path=/";
        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 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 verticalCentreModalPopup(modalPopupBehaviour, panelDivClientId, safariWidth)
{
    var modalPopupObj = $find(modalPopupBehaviour);
    if(modalPopupObj == null)
    {
        setTimeout("verticalCentreModalPopup('" + modalPopupBehaviour + "','" + panelDivClientId + "'," + safariWidth + ");", 500);
    }
    else
    {
        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 ShowNavigationDropDownMenu(divClientId, cellClientId)
{
    var divControl;
    divControl=document.getElementById(divClientId);
	divControl.style.height = "auto";
	divControl.style.opacity = 100;
	divControl.style.filter = 'alpha(opacity=100)';
	
	/*	
	var cellControl;
    cellControl=document.getElementById(cellClientId);
	cellControl.style.borderTopStyle = "solid";
	*/
	
	return false;
}

function HideNavigationDropDownMenu(divClientId, cellClientId)
{
    var divControl;
    divControl=document.getElementById(divClientId);
	divControl.style.height = "1px";
	divControl.style.opacity = 0;
	divControl.style.filter = 'alpha(opacity=0)';
	
	/*
	var cellControl;
    cellControl=document.getElementById(cellClientId);
	cellControl.style.borderTopStyle = "none";
	*/
	
	return false;
}

function showHide(id) {   
    var state = document.getElementById(id).style.display;   
        if (state == 'block') {   
            document.getElementById(id).style.display = 'none';   
        } else {   
            document.getElementById(id).style.display = 'block';   
        }   
    }   
    

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 fixOnMouseOutWithAdditionalElement(mainElement, extraElementClientId, event, JavaScript_code) {
	
	var current_mouse_target = null;
	var extraElement = document.getElementById(extraElementClientId);
	
	if( event.toElement ) 
	{				
		current_mouse_target = event.toElement;
	} 
	else if( event.relatedTarget ) 
	{				
		current_mouse_target = event.relatedTarget;
	}
	
	if( !is_child_of(mainElement, current_mouse_target) && mainElement != current_mouse_target ) 
	{	    
	    if( !is_child_of(extraElement,current_mouse_target) && extraElement != current_mouse_target ) 
	    {		    	       
	        eval(JavaScript_code);
		}
	}
}

function RedirectParentWindow(classId, targetURL, widthForPopupIfNeeded, heightForPopupIfNeeded)
{

    var parentWindow = window.opener;
    var launchPopup = true;
    var browser = GetBrowser();
     
    if(parentWindow != null && classId > 0)
    {
        try
        {
            if(classId == 9999)
            {
                parentWindow.frames.top.main.LaunchInPlay2();
                if(browser == "CHROME")
                {               
                    self.close();
                }
                else
                {
                    window.close();
                }
            }
            else
            {
                parentWindow.frames.top.main.LoadSS(classId);                       
                if(browser == "CHROME")
                {               
                    self.close();
                }
                else
                {
                    window.close();
                }
            }
            launchPopup = false;
        }
        catch(err)
        {            
            launchPopup = true;
        }
    }
    
    if(launchPopup)
    {
        var sHeight = GetScreenRes(); 
        var sLeft = GetScreenWidth(); 
        var sTop = GetScreenTop(); 
        
        if (widthForPopupIfNeeded <= 0 || heightForPopupIfNeeded <= 0)
        {
            window.open(targetURL, '_blank','height=' + screen.height + ',width=' + screen.width + ',status=yes,toolbar=yes,menubar=yes,location=yes,left=' + sLeft + ',top=' + sTop + ',scrollbars=yes,resizable=yes')
            if(!window.name == "")
            {
                if(browser == "CHROME")
                {               
                    self.close();
                }
                else
                {
                    window.close();
                }
            }
        }
        else
        {
            window.open(targetURL, '_blank','height=' + heightForPopupIfNeeded + ',width=' + widthForPopupIfNeeded + ',status=yes,toolbar=yes,menubar=yes,location=yes,left=' + sLeft + ',top=' + sTop + ',scrollbars=yes,resizable=yes')
            if(!window.name == "")
            {
                if(browser == "CHROME")
                {               
                    self.close();
                }
                else
                {
                    window.close();
                }
            }
        }
    }    
}

function RefreshParentWindow()
{
    var parentWindow = window.opener;
    try
    {
        parentWindow.frames.top.main.ReloadME();
    }
    catch(err)
    {    
        return false;
    }
}

function RefreshMe() {
    RefreshParentWindow();
    window.location = window.location;
}

function SetUIDInParentWindow(sData, newPopupURL, widthForPopupIfNeeded, heightForPopupIfNeeded)
{
    var parentWindow = window.opener;
    var launchPopup = true;
    var browser = GetBrowser();
    
    if(parentWindow != null)
    {
        try
        {
            parentWindow.frames.top.main.LoadRHPromo(sData);
            if(browser == "CHROME")
            {               
                self.close();
            }
            else
            {
                window.close();
            }
            launchPopup = false;
        }
        catch(err)
        {    
            launchPopup = true;
        }
    }    
    
    if(launchPopup)    
    {            
        var sHeight = GetScreenRes(); 
        var sLeft = GetScreenWidth(); 
        var sTop = GetScreenTop(); 
        
        if (widthForPopupIfNeeded <= 0 || heightForPopupIfNeeded <= 0)
        {        
            childWindow = window.open(newPopupURL, '_blank','height=' + screen.height + ',width=' + screen.width + ',status=yes,toolbar=yes,menubar=yes,location=yes,left=' + sLeft + ',top=' + sTop + ',scrollbars=yes,resizable=yes')
            if(!window.name == "")
            {
                if(browser == "CHROME")
                {               
                    self.close();
                }
                else
                {
                    window.close();
                }
            }
        }
        else
        {
            childWindow = window.open(newPopupURL, '_blank','height=' + heightForPopupIfNeeded + ',width=' + widthForPopupIfNeeded + ',status=yes,toolbar=yes,menubar=yes,location=yes,left=' + sLeft + ',top=' + sTop + ',scrollbars=yes,resizable=yes')
            if(!window.name == "")
            {
                if(browser == "CHROME")
                {               
                    self.close();
                }
                else
                {
                    window.close();
                }
            }
        }
    }
}

function ResizeCurrentWindow(w, h)
{ 
    var browser = GetBrowser();
    
    try
    {
        if(browser == 'CHROME')
        {   
            window.resizeTo(w + 28, h + 76);        
        }
        else
        {
         
            window.resizeTo(w, h);
            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 diffW = w - myWidth;
            var diffH = h - myHeight;
          
            window.resizeTo(w + diffW, h + diffH);

        }
    }
    catch(err)
    {    
        return false;
    }
}

function ResizeContentTableCell(mainCellId, finalCellId)
{
    var mainCell = document.getElementById(mainCellId);
    var finalCell = document.getElementById(finalCellId);
    ApplyContentTableCellSizes(mainCell, finalCell);
}

function ApplyContentTableCellSizes(mainCell, finalCell)
{
    var browser = GetBrowser();
    if(browser == "SAFARI")
    {
        if(mainCell.offsetHeight > finalCell.offsetHeight + 2)
        {
            var initialMainCellHeight = mainCell.offsetHeight;  
            finalCell.style.height = initialMainCellHeight + "px";   
            var difference = mainCell.offsetHeight - initialMainCellHeight;           
            finalCell.style.height = (finalCell.clientHeight - difference) + "px"; 
        }
    }
    else
    {   
        if(mainCell.clientHeight > finalCell.clientHeight + 2)
        { 
            var initialMainCellHeight = mainCell.clientHeight;  
            finalCell.style.height = initialMainCellHeight + "px";   
            var difference = mainCell.clientHeight - initialMainCellHeight;           
            finalCell.style.height = (finalCell.clientHeight - difference) + "px";
        }       
    }
}

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);
    }
}

/* OPT IN POPUP */

var optIn_resultsMainHeaderId = "";
var optIn_resultsSubHeaderId = "";
var optIn_ctaHeaderId = "";
var optIn_cancelButtonId = "";
var optIn_ctaButtonId = "";
var optIn_closeButtonId = "";
var optIn_cancelImageId = "";
var optIn_ctaImageId = "";
var optIn_closeImageId = "";
var optIn_messaqeContainerId = "";
var optIn_optInResultContainerId = "";
var optIn_optInCTADefaultButtonPanelId = "";
var optIn_errorMessageContainer = "";
var optIn_userNameTextBox = "";
var optIn_emailTextBox = "";

function SetupOptInPopupValues(resultsMainHeaderId,
    resultsSubHeaderId,
    ctaHeaderId,
    cancelButtonId,
    ctaButtonId,
    closeButtonId,
    cancelImageId,
    ctaImageId,
    closeImageId,
    messaqeContainerId,
    optInResultContainerId,
    optInCTADefaultButtonPanelId,
    errorMessageContainer,
    userNameTextBox,
    emailTextBox,
    confirmationText,
    enterDetailsText)
{
    optIn_resultsMainHeaderId = resultsMainHeaderId;
    optIn_resultsSubHeaderId = resultsSubHeaderId;
    optIn_ctaHeaderId = ctaHeaderId;
    optIn_cancelButtonId = cancelButtonId;
    optIn_ctaButtonId = ctaButtonId;
    optIn_closeButtonId = closeButtonId;
    optIn_cancelImageId = cancelImageId;
    optIn_ctaImageId = ctaImageId;
    optIn_closeImageId = closeImageId;
    optIn_messaqeContainerId = messaqeContainerId;
    optIn_optInResultContainerId = optInResultContainerId;
    optIn_optInCTADefaultButtonPanelId = optInCTADefaultButtonPanelId;    
    optIn_errorMessageContainer = errorMessageContainer;
    optIn_userNameTextBox = userNameTextBox;
    optIn_emailTextBox = emailTextBox;
}

function ConfigureOptInPopup(appPath, 
    globalImagePath,
    offerId, 
    languageId,
    result,
    emailValue,
    userNameValue)
{   
    var xmlhttp = new ajaxRequest();
    if(xmlhttp != null)
    {
        var offerDetailsUrl = appPath + "/OptIn/Details.ashx?OfferId=" + offerId + "&LanguageId=" + languageId + "&GlobalImagePath=" + globalImagePath
        xmlhttp.open("GET", offerDetailsUrl, false); 
        xmlhttp.send(null);
        if((xmlhttp.responseText != null) && (xmlhttp.responseText.length > 0))
        {
            var offerValues = xmlhttp.responseText.split("|")
            if((offerValues != null) && (offerValues.length == 7))
            {
                var resultsMainHeader = document.getElementById(optIn_resultsMainHeaderId);
                var resultsSubHeader = document.getElementById(optIn_resultsSubHeaderId);
                var ctaHeader = document.getElementById(optIn_ctaHeaderId);
                var cancelButton = document.getElementById(optIn_cancelButtonId);
                var ctaButton = document.getElementById(optIn_ctaButtonId);
                var closeButton = document.getElementById(optIn_closeButtonId);
                var cancelImage = document.getElementById(optIn_cancelImageId);
                var ctaImage = document.getElementById(optIn_ctaImageId);
                var closeImage = document.getElementById(optIn_closeImageId);
                var messaqeContainer = document.getElementById(optIn_messaqeContainerId);
                var optInResultContainer = document.getElementById(optIn_optInResultContainerId);
                var optInCTADefaultButtonPanel = document.getElementById(optIn_optInCTADefaultButtonPanelId);
                var optIn_OfferId = document.getElementById("OptIn_OfferId");
                var errorMessageContainer = document.getElementById(optIn_errorMessageContainer);
                var userNameTextBox = document.getElementById(optIn_userNameTextBox);
                var emailTextBox = document.getElementById(optIn_emailTextBox);
              
                optIn_OfferId.value = offerId;              
                optInResultContainer.style.display = "none";
                optInCTADefaultButtonPanel.style.display = "none";
              
                var cancelImageValues = offerValues[1].split(",")
                if(cancelImageValues.length = 3)
                {                    
                    cancelImage.src = globalImagePath + cancelImageValues[0];
                    cancelButton.style.height = (cancelImageValues[1] / 2) + "px";
                    cancelButton.style.width = cancelImageValues[2] + "px";   
                    cancelButton.onmouseover = function() 
                    {
                        cancelImage.style.marginTop = "-" + (cancelImageValues[1] / 2) + "px";
                    }
                    cancelButton.onmouseout = function() 
                    {
                        cancelImage.style.marginTop = "0px";
                    }                                
                }
                
                var ctaImageValues = offerValues[2].split(",")
                if(ctaImageValues.length = 3)
                {
                    ctaImage.src = globalImagePath + ctaImageValues[0]
                    ctaButton.style.height = (ctaImageValues[1] / 2) + "px";
                    ctaButton.style.width = ctaImageValues[2] + "px";    
                    ctaButton.onmouseover = function() 
                    {
                        ctaImage.style.marginTop = "-" + (ctaImageValues[1] / 2) + "px";
                    }
                    ctaButton.onmouseout = function() 
                    {
                        ctaImage.style.marginTop = "0px";
                    }              
                }
                
                var closeImageValues = offerValues[3].split(",")
                if(ctaImageValues.length = 3)
                {
                    closeImage.src = globalImagePath + closeImageValues[0]
                    closeButton.style.height = (closeImageValues[1] / 2) + "px";
                    closeButton.style.width = closeImageValues[2] + "px";   
                    closeButton.onmouseover = function() 
                    {
                        closeImage.style.marginTop = "-" + (closeImageValues[1] / 2) + "px";
                    }
                    closeButton.onmouseout = function() 
                    {
                        closeImage.style.marginTop = "0px";
                    }                 
                }
                
                resultsMainHeader.innerHTML = offerValues[0];
                ctaHeader.innerHTML = offerValues[0];
                resultsSubHeader.InnerHTML = "";
                resultsSubHeader.style.display = "none";
                
                switch(result)
                {
                    case "Success":
                        optInResultContainer.style.display = "block";
                        messaqeContainer.innerHTML = offerValues[4];
                        resultsSubHeader.style.display = "block";
                        break;
                    case "UserAlreadyOptedIntoOffer":
                        optInResultContainer.style.display = "block";
                        messaqeContainer.innerHTML = offerValues[5];
                        break;
                    case "ErrorSavingResponse",
                         "InvalidEmailGuid":
                        optInResultContainer.style.display = "block";
                        messaqeContainer.innerHTML = offerValues[6];      
                        break; 
                    case "InvalidCredentials":
                        optInCTADefaultButtonPanel.style.display = "block";
                        errorMessageContainer.style.display = "block";
                        if((emailValue != null) && (emailValue.length > 0))
                        {
                            emailTextBox.value = emailValue;
                        }
                        if((userNameValue != null) && (userNameValue.length > 0))
                        {
                            userNameTextBox.value = userNameValue;
                        }
                        break;       
                    default: 
                    //show enter details screen
                    optInCTADefaultButtonPanel.style.display = "block";
                    errorMessageContainer.style.display = "none";
                    resultsSubHeader.style.display = "block";
                }
            }
        }
    }
}
