﻿var site;
var zone;
var keyValues;
var sponsoredLogoDisplay;
var leaderBoardDisplay;

function GetOrd()
{
    return ord;
}

function GetNewOrd()
{
    SetNewOrd();
    return GetOrd();
}

function SetNewOrd()
{
    ord = Math.floor(Math.random()*1000001);
}

function GetTile()
{
    return incrementalTile;
}

function OpenDocInParent(url)
{
    if(window.opener && !window.opener.closed) 
    {
        window.opener.location.href=url; 
        window.opener.focus();
        window.blur();
    } 
    else 
    { 
        window.open(url, "_blank", "", false); 
    }
}

/*function MoveSponsorAd()
{
    var i = 0;
    for(var i = 0; i < document.styleSheets.length; ++i)
    {
        if(document.styleSheets[i])
        {
            var sl = document.getElementById('Xaml1');
            var ruleSet = null;
            if(document.styleSheets[i].rules != null)
            {
                ruleSet = document.styleSheets[i].rules;
            }
            else if (document.styleSheets[i].cssRules != null)
            {
                ruleSet = document.styleSheets[i].cssRules;
            }
            
            for(var j = 0; j < ruleSet.length; ++j)
            {
                if(ruleSet[j].selectorText == ".cbstv_module_sponsor_right")
                {
                    ruleSet[j].style.left = (((sl.clientWidth + (parseInt(document.documentElement.clientWidth - sl.clientWidth) /2)) - 360) + "px");
                    ruleSet[j].style.position = 'absolute';
                    ruleSet[j].style.visibility = 'visible';
                    ruleSet[j].style.display = 'inline';
                    break;
                }
            }
        }
    }
}*/

/*function CenterLeaderBoard()
{
    for (var i=0;i<document.getElementsByTagName("iframe").length;i++) 
    {
		iFrameID=document.getElementsByTagName("iframe")[i].id;
		//if the iFrame is for a Double Click ad...
		if (iFrameID.substring(0,2)=="dc")
		{
		    var iframe = document.getElementById(iFrameID);				
			if (iframe)
			{
			    iframe.style.left = parseInt((((document.documentElement.clientWidth /2) - (iframe.width / 2)))) + "px";
			    break;
            }
         } 
     }
}*/

/*window.onresize = MoveAds;

function MoveAds()
{
    CenterLeaderBoard();
    MoveSponsorAd();
}*/

function UpdateLeaderBoard(keyValues, newOrd, companionId)
{
    resetAdsWithKeyValues(newOrd, companionId, keyValues);
}

function GetSponsoredLogoDisplay()
{
    return sponsoredLogoDisplay;
}

function GetLeaderBoardDisplay()
{
    return leaderBoardDisplay;
}

function MakeLeaderBoardVisible()
{
    var leaderFrame = document.getElementsByTagName('iframe')[0];
    if(leaderFrame)
    {
        //leaderFrame.style.top = '10px';
        //leaderFrame.style.position = 'absolute';
        leaderFrame.style.visibility = 'visible';
        //leaderFrame.style.display = 'inline';
        //CenterLeaderBoard();
    }
}

function addStyle(ruleSet, doc)
{
    if (doc.styleSheets) 
    {
        if (doc.styleSheets.length == 0) 
        {
            var styleElement = doc.createElement('style');
            if(styleElement)
            {
                styleElement.type = 'text/css';
                var headElement = doc.getElementsByTagName('head')[0];
                headElement.appendChild(styleElement);
            }
        }
        
        if (doc.styleSheets.length > 0) 
        {
            if (doc.styleSheets[0].insertRule) 
            {
                doc.styleSheets[doc.styleSheets.length -1].insertRule(ruleSet, doc.styleSheets[doc.styleSheets.length - 1].cssRules.length);
            }
            else if (doc.styleSheets[0].addRule) 
            {
                var ruleSetPattern = /(.*)({([^}]*)})/;
                var match = ruleSetPattern.exec(ruleSet);
                if (match) 
                {
                    var selector = match[1];
                    var declarations = match[3];
                    doc.styleSheets[doc.styleSheets.length-1].addRule(selector, declarations);
                }
            }
        }
    }
}

/*function renderSponsorAd(leaderboardVisible)
{
    var i = 0;
    for(var i = 0; i < document.styleSheets.length; ++i)
    {
        var ruleSet = null;
        if(document.styleSheets[i].rules != null)
        {
            ruleSet = document.styleSheets[i].rules;
        }
        else if (document.styleSheets[i].cssRules != null)
        {
            ruleSet = document.styleSheets[i].cssRules;
        }
        
        for(var j = 0; j < ruleSet.length; ++j)
        {
            if(ruleSet[j].selectorText == ".cbstv_module_sponsor_right")
            {
                if(leaderboardVisible)
                {
                    ruleSet[j].style.top = '114px'; 
                }
                else
                {
                    ruleSet[j].style.top = '4px';
                }
                ruleSet[j].style.visibility = 'visible';
                MoveSponsorAd();
                break;
            }
        }
    }
}*/