﻿

var browserName = navigator.appName;
var browserType = 0;

if (browserName.search("Microsoft") != -1)
    browserType = "1";
if (browserName.search("Netscape") != -1)
    browserType = "2";

var isIE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1);



var recRedirectUrl = "";


function LightBoxShowPage(url, width, height, redirectUrl) {
    recRedirectUrl = redirectUrl;

    var bgDiv = document.createElement('div');
    bgDiv.setAttribute('id', 'LightPopupBGDiv');
    bgDiv.setAttribute('class', 'LightPopupBGDiv');

    var pageSizeArray = new Array();
    pageSizeArray = getPageSize();
    var pageWidth = pageSizeArray[0];
    var pageHeight = pageSizeArray[1];

    bgDiv.style.height = pageHeight + "px";
    bgDiv.style.width = pageWidth + "px";
    bgDiv.style.zIndex = 1500;
    document.body.appendChild(bgDiv);

    var centerDiv = document.createElement('div');
    centerDiv.setAttribute('id', 'LightBoxCenterDiv');
    centerDiv.setAttribute('class', 'LightBoxCenterDiv');
    centerDiv.style.position = "absolute";
    centerDiv.style.left = getScreenCenterX() - parseInt(width / 2) + "px";
    centerDiv.style.top = getScreenCenterY() - parseInt(height / 2) + "px";
    centerDiv.style.width = parseInt(width) + 10 + 'px';
    centerDiv.style.height = parseInt(height) + 'px';
    centerDiv.style.overflow = "hidden";
    centerDiv.style.zIndex = 1501;


    var topRoundedDiv = document.createElement('div');
    topRoundedDiv.setAttribute('id', 'LightBoxTopRoundDiv');
    topRoundedDiv.style.height = '20px';
    topRoundedDiv.style.width = parseInt(width) + 10 + 'px';
    //topRoundedDiv.style.background = "White";
    topRoundedDiv.style.zIndex = 1501;




    var topRoundLeftDiv = document.createElement('div');
    topRoundLeftDiv.setAttribute('id', 'LightBoxTopRoundLeftDiv');
    topRoundLeftDiv.style.height = '20px';
    topRoundLeftDiv.style.width = 20 + 'px';
    topRoundLeftDiv.style.position = 'relative';
    topRoundLeftDiv.style.left = 0 + 'px';
    topRoundLeftDiv.style.border = 'solid 0px black';
    topRoundLeftDiv.style.zIndex = 1501;
    //topRoundLeftDiv.style.backgroundImage = "url(Images/roundcorner_topleft.png)";
    topRoundLeftDiv.style.backgroundImage = "url(http://www.ontraz.ie/Images/roundcorner_topleft.png)";
    //        topRoundLeftDiv.style.backgroundImage = "url(http://www.aurusit.com/testserver/OntrazRev/Images/roundcorner_topleft.png)";
    topRoundedDiv.appendChild(topRoundLeftDiv);

    var topRoundCenterDiv = document.createElement('div');
    topRoundCenterDiv.setAttribute('id', 'LightBoxTopRoundCenterDiv');
    topRoundCenterDiv.style.height = '20px';
    topRoundCenterDiv.style.width = parseInt(width) - 30 + 'px';
    topRoundCenterDiv.style.position = 'relative';
    topRoundCenterDiv.style.left = 20 + 'px';
    topRoundCenterDiv.style.top = -20 + 'px';
    topRoundCenterDiv.style.border = 'solid 0px black';
    topRoundCenterDiv.style.zIndex = 1501;
    //    topRoundCenterDiv.style.backgroundImage = "url(Images/1_px_topline.png)";
    topRoundCenterDiv.style.backgroundImage = "url(http://www.ontraz.ie/Images/1_px_topline.png)";
    //        topRoundCenterDiv.style.backgroundImage = "url(http://www.aurusit.com/testserver/OntrazRev/Images/1_px_topline.png)";        
    //topRoundCenterDiv.style.background = "Black";
    topRoundCenterDiv.style.backgroundRepeat = "repeat-x";

    var topRoundRightDiv = document.createElement('div');
    topRoundRightDiv.setAttribute('id', 'LightBoxTopRoundRightDiv');
    topRoundRightDiv.style.height = '20px';
    topRoundRightDiv.style.width = 20 + 'px';
    topRoundRightDiv.style.position = 'relative';
    topRoundRightDiv.style.left = parseInt(width) - 10 + 'px';
    topRoundRightDiv.style.top = -40 + 'px';
    topRoundRightDiv.style.border = 'solid 0px black';
    topRoundRightDiv.style.zIndex = 1501;
    //    topRoundRightDiv.style.backgroundImage = "url(Images/roundcorner_topright.png)";
    topRoundRightDiv.style.backgroundImage = "url(http://www.ontraz.ie/Images/roundcorner_topright.png)";
    //        topRoundRightDiv.style.backgroundImage = "url(http://www.aurusit.com/testserver/OntrazRev/Images/roundcorner_topright.png)";


    topRoundedDiv.appendChild(topRoundLeftDiv);
    topRoundedDiv.appendChild(topRoundCenterDiv);
    topRoundedDiv.appendChild(topRoundRightDiv);


    var topCrossDiv = document.createElement('div');
    topCrossDiv.setAttribute('id', 'LightBoxTopCrossDiv');
    topCrossDiv.style.height = '20px';
    topCrossDiv.style.width = '20px';
    topCrossDiv.style.border = 'solid 0px black';
    topCrossDiv.style.position = 'relative';
    topCrossDiv.style.left = parseInt(width) - 22 + 'px';
    topCrossDiv.style.top = -53 + 'px';
    topCrossDiv.style.zIndex = 1502;
    topCrossDiv.style.cursor = "hand";
    topCrossDiv.setAttribute("onclick", "HidePopup();");
    //    topCrossDiv.innerHTML = "<a style='cursor:pointer;'><img onclick='HidePopup();' height='20' width='20' style='border:none;' src='Images/cross.png' /></a>";
    topCrossDiv.innerHTML = "<a style='cursor:pointer;'><img onclick='HidePopup();' height='20' width='20' style='border:none;' src='http://www.ontraz.ie/Images/cross.png' /></a>";
    //        topCrossDiv.innerHTML = "<a style='cursor:pointer;'><img onclick='HidePopup();' height='20' width='20' style='border:none;' src='http://www.aurusit.com/testserver/OntrazRev/Images/cross.png' /></a>";   

    topRoundedDiv.appendChild(topCrossDiv);


    centerDiv.appendChild(topRoundedDiv)


    var centerContendDiv = document.createElement('div');
    centerContendDiv.setAttribute('id', 'LightBoxCenterContentDiv');
    centerContendDiv.style.width = parseInt(width) + 'px';
    centerContendDiv.style.height = (parseInt(height) - 50) + 'px';
    centerContendDiv.style.zIndex = 1501;

    //Dirty ie6 fix for div space usage therefore disconnecting topRoundedDiv and centerContendDiv
    if (isIE6) {
        centerContendDiv.style.position = 'relative';
        centerContendDiv.style.top = '-60px';
    }

    var centerIframe = document.createElement('iframe');
    centerIframe.style.borderLeft = "solid 2px gray";
    centerIframe.style.borderRight = "solid 2px gray";
    //    centerIframe.setAttribute('src', 'LightPopupPageLoader.aspx?url=' + url + '&height=' + height);
    //alert(document.domain);
    centerIframe.setAttribute('src', 'http://' + document.domain + '/LightPopupPageLoader.aspx?url=' + url + '&height=' + height);
    //        centerIframe.setAttribute('src', 'http://www.aurusit.com/testserver/OntrazRev/LightPopupPageLoader.aspx?url=' + url + '&height=' + height);
    centerIframe.setAttribute('height', (parseInt(height) - 50) + 'px');
    centerIframe.setAttribute('width', (parseInt(width) + 6) + 'px');
    centerIframe.setAttribute("frameborder", "0");
    centerIframe.setAttribute("scrolling", "no");
    centerIframe.setAttribute("allowtransparency", "true");
    centerIframe.style.background = "White";
    centerIframe.style.scroll = "hidden";
    centerIframe.style.overflow = "hidden";


    centerContendDiv.appendChild(centerIframe);
    centerDiv.appendChild(centerContendDiv);

    var bottomRoundedDiv = document.createElement('div');
    bottomRoundedDiv.setAttribute('id', 'LightBoxBottomRoundDiv');
    bottomRoundedDiv.style.height = '25px';
    bottomRoundedDiv.style.width = parseInt(width) + 10 + 'px';
    bottomRoundedDiv.style.background = "transparent";
    bottomRoundedDiv.style.zIndex = 1501;

    var bottomRoundLeftDiv = document.createElement('div');
    bottomRoundLeftDiv.setAttribute('id', 'LightBoxBottomRoundLeftDiv');
    bottomRoundLeftDiv.style.height = '20px';
    bottomRoundLeftDiv.style.width = 20 + 'px';
    bottomRoundLeftDiv.style.position = 'relative';
    bottomRoundLeftDiv.style.left = 0 + 'px';
    bottomRoundLeftDiv.style.border = 'solid 0px black';
    bottomRoundLeftDiv.style.zIndex = 1501;
    //    bottomRoundLeftDiv.style.backgroundImage = "url(Images/roundcorner_leftright.png)";
    bottomRoundLeftDiv.style.backgroundImage = "url(http://www.ontraz.ie/Images/roundcorner_leftright.png)";
    //        bottomRoundLeftDiv.style.backgroundImage = "url(http://www.aurusit.com/testserver/OntrazRev/Images/roundcorner_leftright.png)";


    var bottomRoundCenterDiv = document.createElement('div');
    bottomRoundCenterDiv.setAttribute('id', 'LightBoxBottomRoundCenterDiv');
    bottomRoundCenterDiv.style.height = '20px';
    bottomRoundCenterDiv.style.width = parseInt(width) - 30 + 'px';
    bottomRoundCenterDiv.style.position = 'relative';
    bottomRoundCenterDiv.style.left = 20 + 'px';
    bottomRoundCenterDiv.style.top = -20 + 'px';
    bottomRoundCenterDiv.style.border = 'solid 0px black';
    bottomRoundCenterDiv.style.zIndex = 1501;
    //    bottomRoundCenterDiv.style.backgroundImage = "url(Images/1_px_bottomline.png)";
    bottomRoundCenterDiv.style.backgroundImage = "url(http://www.ontraz.ie/Images/1_px_bottomline.png)";
    //        bottomRoundCenterDiv.style.backgroundImage = "url(http://www.aurusit.com/testserver/OntrazRev/Images/1_px_bottomline.png)";        
    //topRoundCenterDiv.style.background = "Black";
    bottomRoundCenterDiv.style.backgroundRepeat = "repeat-x";

    var bottomRoundRightDiv = document.createElement('div');
    bottomRoundRightDiv.setAttribute('id', 'LightBoxBottomRoundRightDiv');
    bottomRoundRightDiv.style.height = '20px';
    bottomRoundRightDiv.style.width = 20 + 'px';
    bottomRoundRightDiv.style.position = 'relative';
    bottomRoundRightDiv.style.left = parseInt(width) - 10 + 'px';
    bottomRoundRightDiv.style.top = -40 + 'px';
    bottomRoundRightDiv.style.border = 'solid 0px black';
    bottomRoundRightDiv.style.zIndex = 1501;
    //    bottomRoundRightDiv.style.backgroundImage = "url(Images/roundcorner_bottomright.png)";
    bottomRoundRightDiv.style.backgroundImage = "url(http://www.ontraz.ie/Images/roundcorner_bottomright.png)";
    //        bottomRoundRightDiv.style.backgroundImage = "url(http://www.aurusit.com/testserver/OntrazRev/Images/roundcorner_bottomright.png)";


    bottomRoundedDiv.appendChild(bottomRoundLeftDiv);
    bottomRoundedDiv.appendChild(bottomRoundCenterDiv);
    bottomRoundedDiv.appendChild(bottomRoundRightDiv);


    //Dirty ie6 fix for div space usage therefore disconnecting topRoundedDiv and centerContendDiv
    if (isIE6) {
        bottomRoundedDiv.style.position = 'relative';
        bottomRoundedDiv.style.top = '-60px';
    }

    centerDiv.appendChild(bottomRoundedDiv);


    document.body.appendChild(centerDiv);





}

function HidePopup() {

    if (document.getElementById("LightBoxCenterDiv") != null) {
        document.getElementById("LightBoxCenterDiv").style.display = 'none';
        document.body.removeChild(document.getElementById("LightBoxCenterDiv"));
    }

    if (document.getElementById("LightPopupBGDiv") != null) {
        document.getElementById("LightPopupBGDiv").style.display = 'none';
        document.body.removeChild(document.getElementById("LightPopupBGDiv"));
    }

    //Code to redirect the parent once the light box is closed
    if (recRedirectUrl == " ") {

    }
    else
        if (recRedirectUrl == "self") {
        window.parent.location.href = window.parent.location;
    }
    else {
        window.parent.location.href = recRedirectUrl;
    }


}



/* Supporting functions */

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

function getScreenCenterY() {
    var y = 0;

    y = getScrollOffset() + (getInnerHeight() / 2);

    return (y);
}

function getScreenCenterX() {
    return (document.body.clientWidth / 2);
}

function getInnerHeight() {
    var y;
    if (self.innerHeight) // all except Explorer
    {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
    {
        y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        y = document.body.clientHeight;
    }
    return (y);
}

function getScrollOffset() {
    var y;
    if (self.pageYOffset) // all except Explorer
    {
        y = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    // Explorer 6 Strict
    {
        y = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        y = document.body.scrollTop;
    }
    return (y);
}

