function BannerClicked(result, ui_id)
{
    if (result.status == Http.Status.OK)
    {
        var url = result.responseText;
        if (url != null && url != undefined)
        {
            if (url.indexOf("http") > -1)
                window.open(url);
            else
                location.href = url;        
        }
    }
}
function ClickBanner(url, itemID, zone, bannerID)
{

    Http.get(
    {
    url: "/BannerTrack.aspx?URL=" + encodeURIComponent(url) + "&BannerID=" + bannerID + 
     "&ItemID=" + itemID + "&Zone=" + zone,
    callback: BannerClicked,
    cache: Http.Cache.GetNoCache
    },  [url]);
}


function BannerClickedCR(result, prmUrl, prmTitle) {
    if (result.status == Http.Status.OK) {
        if (prmUrl != null && prmUrl != undefined) {
            if (prmTitle != null && prmTitle != undefined && prmTitle.length > 1 && prmTitle.toLowerCase().indexOf("_login") > -1) {
                if (ShowLoginDiv(prmUrl))
                    return;
            }
            
            if (prmUrl.indexOf("http") > -1)
                window.open(prmUrl);
            else
                location.href = prmUrl;
        }
    }
}
function ClickBannerCR(url, itemID, zone, bannerID, title) {
    Http.get(
        {
            url: "/BannerTrack.aspx?URL=" + encodeURIComponent(url) + "&BannerID=" + bannerID +
         "&ItemID=" + itemID + "&Zone=" + zone,
            callback: BannerClickedCR,
            cache: Http.Cache.GetNoCache
        }, [url, title]);
}
function ShowLoginDiv(formUrl) {
    var isLoginShown = false;
    var size = getAvailableSize();

    var CRLoginForm = document.getElementById("CRLoginForm");
    if (CRLoginForm != null && CRLoginForm != undefined) {
        CRLoginForm.action = formUrl;
        isLoginShown = true;
    }
    else
        isLoginShown = false;

    var BGHideDiv = document.getElementById("BGHideDiv");
    if (BGHideDiv != null && BGHideDiv != undefined) {
        BGHideDiv.style.display = "";
        
        //make the background div cover the whole window
        BGHideDiv.style.width = size.width + "px";
        BGHideDiv.style.height = size.height + "px";
    }

    var CRLoginDiv = document.getElementById("CRLoginDiv");
    if (CRLoginDiv != null && CRLoginDiv != undefined) {
        CRLoginDiv.style.display = "";

        //center the login div in the browser window
        var divHeight = parseInt(CRLoginDiv.style.height);
        if (isNaN(divHeight))
            divHeight = 0;
        var divWidth = parseInt(CRLoginDiv.style.width);
        if (isNaN(divWidth))
            divWidth = 0;
        if (divHeight > 0)
            CRLoginDiv.style.top = (size.height / 2) - (divHeight / 2) + "px";
        if (divWidth > 0)
            CRLoginDiv.style.left = (size.width / 2) - (divWidth / 2) + "px";
    }
    return isLoginShown;
}
function CloseLoginDiv() {
    var CRLoginDiv = document.getElementById("CRLoginDiv");
    if (CRLoginDiv != null && CRLoginDiv != undefined) {
        CRLoginDiv.style.display = "none";
    }

    var BGHideDiv = document.getElementById("BGHideDiv");
    if (BGHideDiv != null && BGHideDiv != undefined) {
        BGHideDiv.style.display = "none";
    }
}


