﻿/**************************************************/
/* Modal Dialog Effect                            */
/* Date Created       : January 17, 2009          */
/* Date Last Modified : January 19, 2009          */
/* Company            : SoftShore Global Solotion */
/* Authored By        : Michael John C. Veloso    */
/**************************************************/

window.onresize = function () { reloadLightWindow(); };
/*window.onscroll = function() { startScrollingDetector(); };*/

/*Check javascript*/
function jsCheck() {
    document.getElementById("loginDiv").style.display = 'block';
    document.getElementById("nojsDiv").style.display = 'none';
}

/* Global Variable Declartion */
var lightwindowWidth = 0;
var lightwindowHeight = 0;
var documentWidth = 0;
var objlightwindow = null;
var objligthwindowoverlay = null;
var windowScrollingTopPosition = 0;
var windowScrollingLeftPosition = 0;
var div_ifrsrc = null;
var div_ifrW = null;
var div_ifrH = null;

/* Detect user scrolling event and get the Page Offset X and Y */
function startScrollingDetector() {
    //setInterval("scrollingDetector()", 500);
    scrollingDetector()
}

function scrollingDetector() {
    if (typeof (window.pageYOffset) == 'number') {
        // Netscape
        windowScrollingLeftPosition = window.pageXOffset;
        windowScrollingTopPosition = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        // DOM
        windowScrollingLeftPosition = document.body.scrollLeft;
        windowScrollingTopPosition = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        // IE6 standards compliant mode        
        windowScrollingLeftPosition = document.documentElement.scrollLeft;
        windowScrollingTopPosition = document.documentElement.scrollTop;
    }

    checkLightWindow();
}

/* Check if LightWindow Box is Instanciated */
function checkLightWindow() {
    if (objlightwindow != null) {
        if (lightwindowTopPosition() < 0) {
            objlightwindow.style.top = "0px";
        }
        else {
            objlightwindow.style.top = lightwindowTopPosition() + "px";
        }

        if (lightwindowLeftPosition() < 0) {
            objlightwindow.style.left = "0px";
        }
        else {
            var currentLeftPosition = lightwindowLeftPosition() + lightwindowWidth;

            if (currentLeftPosition < lightwindowLeftPosition()) {
                objlightwindow.style.left = lightwindowLeftPosition() + "px";
            }
        }

        if (document.body.clientWidth < 1024) {
            documentWidth = 1184;
            objligthwindowoverlay.style.width = 1024 + "px";
        }
        else {
            documentWidth = document.body.clientWidth;
            objligthwindowoverlay.style.width = document.body.clientWidth + "px";
        }
    }
}

function getScrollingTopPosition() {
    var scrollingTopPosition = 0;
    if (typeof (window.pageYOffset) == 'number') {
        // Netscape
        scrollingTopPosition = window.pageYOffset;
    } else if (document.body && document.body.scrollTop) {
        // DOM
        scrollingTopPosition = document.body.scrollTop;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        // IE6 standards compliant mode
        scrollingTopPosition = document.documentElement.scrollTop;
    }

    return scrollingTopPosition;
}

/* Get the Current Top Position of the Light Window and Apply Page Offset X if necessary */
function lightwindowTopPosition() {
    var TopPosition = (getWindowHeight() * .5) - (lightwindowHeigth * .5);

    //	if(navigator.appName == "Microsoft Internet Explorer")
    //	{
    //	    TopPosition = (getWindowHeight() * .5) - (lightwindowHeigth * .2);
    //	}

    var scrollingTopPosition = getScrollingTopPosition();

    //    if (windowScrollingTopPosition >= 0) {
    //        TopPosition += windowScrollingTopPosition;
    //    }

    if (scrollingTopPosition >= 0) {
        TopPosition += scrollingTopPosition;
    }

    return TopPosition;
}

/* Get the Current Left Position of the Light Window and Apply Page Offset Y if necessary */
function lightwindowLeftPosition() {
    var LeftPosition = (getWindowWidth() * .5) - (lightwindowWidth * .5);

    if (windowScrollingLeftPosition >= 0) {
        LeftPosition += windowScrollingLeftPosition;
    }

    return LeftPosition;
}

/* Get the Current Document/Page width */
function getWindowWidth() {
    var windowWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        windowWidth = window.innerWidth;
    }
    else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        }
        else {
            if (document.body && document.body.clientWidth) {
                windowWidth = document.body.clientWidth;
            }
        }
    }

    return windowWidth;
}

/* Get the Current Document/Page height */
function getWindowHeight() {
    var windowHeight = 0;

    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }

    return windowHeight;
}

/* Instantiate/Activate/Open Light Window Popup window */
function activateLightWindow(ifrsrc, ifrW, ifrH) {
    var selects = document.getElementsByTagName('select');
    for (i = 0; i < selects.length; i++) {
        selects[i].style.display = 'none';
    }

    div_ifrsrc = ifrsrc;
    div_ifrW = ifrW;
    div_ifrH = ifrH;


    lightwindowWidth = ifrW;
    lightwindowHeigth = ifrH;

    var docHeight;
    var docWidth;

    docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
    docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;

    if (docWidth < 1184) {
        documentWidth = 1184;
    }
    if (docHeight < document.documentElement.clientHeight) {
        docHeight = document.documentElement.clientHeight;
    }

    var lightwindowDiv = document.createElement('div');

    LeftPosition = lightwindowLeftPosition();
    TopPosition = lightwindowTopPosition();

    objligthwindowoverlay = lightwindowDiv;

    lightwindowDiv.setAttribute("id", "lightwindow");
    lightwindowDiv.setAttribute("scrolling", "no");
//    lightwindowDiv.setAttribute("onclick", "deactivateLightWindow();");
    lightwindowDiv.style.width = docWidth + "px";
    lightwindowDiv.style.height = docHeight + "px";
    lightwindowDiv.className = "PopupWindowModalBackground";

    var lightwindowDiv1 = document.createElement('div');

    lightwindowDiv1.setAttribute("id", "lightwindowContent");
    lightwindowDiv1.style.width = ifrW + "px";
    lightwindowDiv1.style.height = ifrH + "px";
    //    alert(ifrW + '---' + ifrH);
    if (navigator.appName == "Microsoft Internet Explorer") {
        //lightwindowDiv1.style.Display = "table";
    }
    else {
        //lightwindowDiv1.style.Display = "inline";
    }
    lightwindowDiv1.style.position = "absolute";
    lightwindowDiv1.style.top = TopPosition + "px";
    lightwindowDiv1.style.left = LeftPosition + "px";
    //    alert(TopPosition + '---' + LeftPosition);
    lightwindowDiv1.className = "PopupWindowLightwindowcontainer";

    var lightwindowframe = document.createElement("iframe");

    objlightwindow = lightwindowDiv1;

    lightwindowframe.setAttribute("id", "ifrwindow");
    lightwindowframe.setAttribute("src", ifrsrc);
    
    //Added by Shekhar for correct dispay in IE. 
    lightwindowframe.setAttribute("scrolling", "no");
    //Change complete. 

    
    //    lightwindowframe.setAttribute("frameborder", "0");
    lightwindowframe.setAttribute('frameborder', '0', 0);
    lightwindowframe.setAttribute("allowtransparency", "true");

    lightwindowframe.style.width = ifrW + "px";
    lightwindowframe.style.height = ifrH + "px";
    lightwindowframe.style.position = "absolute";

    if (lightwindowframe.attachEvent) {
        lightwindowframe.attachEvent("onload", function () {
            changeBackGroundColor(lightwindowframe);
        });
    } else {
        lightwindowframe.onload = function () {
            changeBackGroundColor(lightwindowframe);
        };
    }



    lightwindowDiv1.appendChild(lightwindowframe);
    //    lightwindowDiv.appendChild(lightwindowDiv1);

    var _backgroundElement = document.createElement('div');
    _backgroundElement.setAttribute("id", "_backgroundElement"); ;
    _backgroundElement.style.display = 'none';
    // position:fixed; does not work in IE in quirks mode, so need to set to absolute
    //    if (Sys.Browser.agent == Sys.Browser.InternetExplorer && document.compatMode != "CSS1Compat")
    _backgroundElement.style.position = 'absolute';
    //    else
    //        this._backgroundElement.style.position = 'fixed';
    _backgroundElement.style.left = '0px';
    _backgroundElement.style.top = '0px';
    // Want zIndex to big enough that the background sits above everything else
    // CSS 2.1 defines no bounds for the <integer> type, so pick arbitrarilymodalBackground
    _backgroundElement.style.zIndex = 10000;

    _backgroundElement.className = "PopupWindowModalBackground";
    _backgroundElement.style.width = docWidth + "px";
    _backgroundElement.style.height = docHeight + "px";

    document.body.appendChild(lightwindowDiv);
    document.body.appendChild(lightwindowDiv1);



}
function changeBackGroundColor(objFrame) {
    objFrame.setAttribute("allowtransparency", "allowtransparency");
    objFrame.allowTransparency = true; /* IE only */
    objFrame.style.backgroundColor = 'transparent';
}

/* Deactivate/Close Light Window Popup window */
function deactivateLightWindow() {
    var lightwindowDiv = document.getElementById('lightwindow');
    var lightwindowDiv1 = document.getElementById('lightwindowContent');

    lightwindowDiv.style.Display = "none";
    lightwindowDiv1.style.Display = "none";
    document.body.removeChild(lightwindowDiv);
    document.body.removeChild(lightwindowDiv1);
    objlightwindow = null;

    var selects = document.getElementsByTagName('select');
    for (i = 0; i < selects.length; i++) {
        selects[i].style.display = 'inline';
    }
}

function reloadLightWindow() {
    var lightwindowDiv = document.getElementById('lightwindow');
    if (lightwindowDiv != 'undefined' && lightwindowDiv != null && lightwindowDiv.style.Display != "none") {
        checkLightWindow();
        resizeLightWindow(div_ifrW, div_ifrH);
    }
}


function resizeLightWindow(ifrW, ifrH) {
    lightwindowWidth = ifrW;
    lightwindowHeigth = ifrH;

    div_ifrW = ifrW;
    div_ifrH = ifrH;

    var docHeight;
    var docWidth;

    docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
    docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;

    if (docWidth < 1184) {
        documentWidth = 1184;
    }
    if (docHeight < document.documentElement.clientHeight) {
        docHeight = document.documentElement.clientHeight;
    }

    var lightwindowDiv = document.getElementById('lightwindow');

    LeftPosition = lightwindowLeftPosition();
    TopPosition = lightwindowTopPosition();

    var lightwindowDiv1 = document.getElementById('lightwindowContent');

    lightwindowDiv1.style.width = ifrW + "px";
    lightwindowDiv1.style.height = ifrH + "px";
    lightwindowDiv1.style.top = TopPosition + "px";
    lightwindowDiv1.style.left = LeftPosition + "px";

    var lightwindowframe = document.getElementById("ifrwindow");

    lightwindowframe.style.width = ifrW + "px";
    lightwindowframe.style.height = ifrH + "px";
}

