﻿var bannerAdRandomNumber = Math.random() * 10000000000000000;

function detectKeyDown(e) 
{
    var target = (e && e.target) || (window.event && window.event.srcElement);
    var obj = document.getElementById(tbTopSearch);
    var evt = e ? e : window.event;
    var iKeyCode = evt.keyCode;
    if (target == obj) {
        switch (iKeyCode) {
            case 13: //return key                                                                            
                if (evt.preventDefault)
                    evt.preventDefault();
                window.focus();
                window.location = SearchUrl + obj.value;
                return false;
                break;
        }
    }
    return true;
}

function GotoSearch() 
{
    var obj = document.getElementById(tbTopSearch);
    window.location = SearchUrl + obj.value;
}

function AdSwap(position, size) {
    var obj = document.getElementById(position + "_" + size);
    try {
        if (obj != null) {
            var posX = obj.offsetLeft;
            var posY = obj.offsetTop; //size == '300x250' ||
            if (size == '468x75' || position == "articlebanner" || position == "article") {
                //if its an island, only recurse back to the container bkg-fix to find position so that it moves with the dropdown ad                                                                       
                var obj2 = document.getElementById(position + "_" + size + "_script");
                obj2.style.position = "absolute";
                obj2.style.left = posX + "px";
                obj2.style.top = posY + "px";
                obj2.style.display = "block";

                // fix for IE7 bug with offsetLeft
                var IE7 = (navigator.appVersion.indexOf("MSIE 7.") == -1) ? false : true;
                var IE6 = (navigator.appVersion.indexOf("MSIE 6.") == -1) ? false : true;
                if ((IE7 || IE6 || posX == 0) && size == '300x250') {
                    if (document.getElementById("bkg-fix").style.position == "static") {
                        obj2.style.left = document.getElementById("bkg-fix").style.left + 850;
                        posY = posY + obj.offsetParent.offsetTop;
                        obj2.style.top = posY + "px";
                    }
                    else {
                        obj2.style.left = "680px";
                        posY = posY + obj.offsetParent.offsetTop;
                        obj2.style.top = posY + "px";
                    }
                }
                if ((IE7 || IE6) && size == '468x75') obj2.style.left = "20px";
                if ((IE7 || IE6) && position == 'article') {
                    obj2.style.left = "20px";
                    posY = posY + obj.offsetParent.offsetTop;
                    obj2.style.top = posY + "px";
                }

                var obj3 = document.getElementById(position + "_" + size);
                var objHeight = obj2.offsetHeight;
                obj3.style.minheight = objHeight + "px";
                obj3.style.height = objHeight + "px";
            }
            else {
                while (obj.offsetParent) {
                    posX = posX + obj.offsetParent.offsetLeft;
                    posY = posY + obj.offsetParent.offsetTop;
                    if (obj == document.getElementsByTagName('body')[0]) { break }
                    else { obj = obj.offsetParent; }
                }
                var obj2 = document.getElementById(position + "_" + size + "_script");
                obj2.style.position = "absolute";
                obj2.style.left = posX + "px";
                obj2.style.top = posY + "px";
                obj2.style.display = "block";

                var obj3 = document.getElementById(position + "_" + size);
                var objHeight = obj2.offsetHeight;
                obj3.style.minheight = objHeight + "px";
                obj3.style.height = objHeight + "px";
            }
        }
    }
    catch (err) {
    }
}

function AlignAds() {
    AdSwap('topb', '728x90');
    AdSwap('sky', '120x600');
    AdSwap('sto', '300x250');
    AdSwap('sto2', '300x250');
    AdSwap('article', '1x1');
    AdSwap('pushdown', '1000x100');
    AdSwap('footer', '728x90');
}

//Used by Polls etc
function showDiv(id) { if (document.getElementById(id) != null) document.getElementById(id).style.display = ""; }
function hideDiv(id) { if (document.getElementById(id) != null) document.getElementById(id).style.display = "none"; }
