﻿var fInitState=false;
var overlayID="mPopupOverlayX";
function getOverlayWindowSize() {
    var myWidth=0,myHeight=0;
    if(typeof(window.innerWidth)=='number') {
        myWidth=window.innerWidth;
        myHeight=window.innerHeight;
    } else 
    if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){
        myWidth=document.documentElement.clientWidth;
        myHeight=document.documentElement.clientHeight;
    } else 
    if(document.body&&(document.body.clientWidth||document.body.clientHeight)) {
        myWidth=document.body.clientWidth;myHeight=document.body.clientHeight;
    }
    return{width:myWidth,height:myHeight}
}

function getOverlayScrollXY() {
    var scrOfX=0,scrOfY=0;
    if(typeof(window.pageYOffset)=='number') {
        scrOfY=window.pageYOffset;
        scrOfX=window.pageXOffset;
    } else 
    if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){
        scrOfY=document.body.scrollTop;
        scrOfX=document.body.scrollLeft;
    } else 
    if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){
        scrOfY=document.documentElement.scrollTop;
        scrOfX=document.documentElement.scrollLeft;
    }
    return{x:scrOfX,y:scrOfY};
}

function getOverlayIEVersion() {
    if(navigator.appVersion.indexOf("MSIE")==-1) return false;
    var p1=navigator.appVersion.indexOf("MSIE");
    var p2=navigator.appVersion.indexOf(";",p1);
    return navigator.appVersion.substr(p1+5,p2-(p1+5));
}

function addOverlayEventTo(obj,event,handler) {
    var altEN='on'+event;
    if(obj.attachEvent)
        obj.attachEvent(altEN,handler);
    else if(obj.addEventListener)
        obj.addEventListener(event,handler,false);
    else
        alert("You browser doesn't support "+altEN+" event.");
}

function InitializeOverlay() {
    var div=document.createElement("div");
    div.id=overlayID;
    div.style.display="none";
    div.style.backgroundColor="#000000";
    div.style.width="100%";
    div.style.left="0px";
    div.style.top="0px";
    div.style.position=(navigator.appName=="Microsoft Internet Explorer"&&getOverlayIEVersion()=="6.0")?"absolute":"fixed";
    div.style.filter="Alpha(Opacity=10)";
    div.style.MozOpacity=0.1;
    div.style.opacity=0.1;
    document.body.appendChild(div);
    if(navigator.appName=="Microsoft Internet Explorer"&&getOverlayIEVersion()=="6.0") 
        addOverlayEventTo(window,"scroll",CorrectPosition);
    addOverlayEventTo(window,"resize",function(){ShowOverlay();}); 
    addOverlayEventTo(div,"click",function(){
        HideOverlayPopup();
        document.getElementById("lang-panel").style.display = "none";
    });
}

function ShowOverlay() {
    if(!fInitState)
        InitializeOverlay();
    var mOverlay=document.getElementById(overlayID);

    mOverlay.style.display="block";
    mOverlay.style.zIndex=999;
    mOverlay.style.height=getOverlayWindowSize().height+"px";
    if(navigator.appName=="Microsoft Internet Explorer"&&getOverlayIEVersion()=="6.0") {
        mOverlay.style.top=getOverlayScrollXY().y+"px";
    } else {
        mOverlay.style.top="0px";
    }
}

function CorrectPosition() {
    document.getElementById(overlayID).style.top=getOverlayScrollXY().y+"px";
}
function HideOverlayPopup(){
    if (document.getElementById(overlayID) != null) {
        document.getElementById(overlayID).style.display = "none";
    }
}

