﻿     
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

     
     function doALoginCheck()
    {
        
        xmlhttpLogin=null;

        if (window.XMLHttpRequest)
          {// code for all new browsers
          xmlhttpLogin=new XMLHttpRequest();
          }
        else if (window.ActiveXObject)
          {// code for IE5 and IE6
          xmlhttpLogin=new ActiveXObject("Microsoft.XMLHTTP");
          }
              if (xmlhttpLogin!=null)
              {

                xmlhttpLogin.onreadystatechange=state_Change_xmlhttpLogin;
                                
                var params = "request=";
                
                xmlhttpLogin.open("POST", "/LogInMonitor.axd", true); 
                //Send the proper header information along with the request
                xmlhttpLogin.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlhttpLogin.setRequestHeader("Content-length", params.length);
                xmlhttpLogin.setRequestHeader("Connection", "close");
                
                xmlhttpLogin.send(params);
                
              }
              else
              {
            
              }
     
    }
    
   function state_Change_xmlhttpLogin()
    {
    if (xmlhttpLogin.readyState==4)
      {// 4 = "loaded"
      if (xmlhttpLogin.status==200)
        {
            //Data retrieved - use.
            if(xmlhttpLogin.responseText != '*****OK*****')
            {
                document.location.href = xmlhttpLogin.responseText;
            }
        }
      else
        {
            
        }
      }
      
    }

     
     
        function showPopUp(el, coverDiv) {
            
            doALoginCheck();
            
            
            
            
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_endRequest(OnEndRequest);
                                            
            function OnEndRequest(sender,args)
            {                            
                if ( typeof( dlg ) != "undefined" ) {
                    doResize();  
                    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(OnEndRequest)  
                }
            }




            
            
            var cvr = document.getElementById(coverDiv)
            dlg = document.getElementById(el)
            window.onresize = doResize;

            cvr.style.display = "block"
            
            dlg.style.display = "block"
            setOpacity(cvr, dlg, 1)
            
            dlg.style.top = Math.round((document.documentElement.clientHeight/2)-(dlg.clientHeight/2)) + "px";
            dlg.style.left = Math.round((document.documentElement.clientWidth/2)-(dlg.clientWidth/2)) + "px";
            
            if (document.body.style.overflow = "hidden") 
            {
                cvr.style.width = "100%"
                cvr.style.height = (getPageSizeWithScroll()[1] < document.documentElement.clientHeight ? document.documentElement.clientHeight : getPageSizeWithScroll()[1])  + "px";
            }
            
            document.onkeydown = function (evt) {
                var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
                var eventTarget = evt ? evt.target : event.srcElement;
                if (keyCode == 27) {
                    closePopUp(coverDiv, el);
                }
            }
           }
        
        function setOpacity(cvr , obj, value)
        {

	        obj.style.opacity = value/10;
	        obj.style.opacity = (obj.style.opacity > 1 ? 1 : obj.style.opacity)
	        obj.style.filter = 'alpha(opacity=' + (value > 10 ? 100 : value*10) + ')';
	        
	        cvr.style.top = "0px";
	        obj.style.top = (Math.round((document.documentElement.clientHeight/2)-(obj.clientHeight/2))) + "px";
	        cvr.style.height = (getPageSizeWithScroll()[1] < document.documentElement.clientHeight ? document.documentElement.clientHeight : getPageSizeWithScroll()[1]) + "px";
	        if(value < 10) setTimeout("setOpacity(document.getElementById('"+cvr.id+"'), document.getElementById('"+obj.id+"'), + " + (value + 2) + ")", 10)
        }

        function doResize()
        {
        
            if(dlg.style.display == "block"){
                dlg.style.top = (Math.round((document.documentElement.clientHeight/2)-(dlg.clientHeight/2))) + "px";
                dlg.style.left = Math.round((document.documentElement.clientWidth/2)-(dlg.clientWidth/2)) + "px";    
            }
        }
        
        function closePopUp(el, coverDiv) 
        {
            var cvr = document.getElementById(coverDiv);
            var dlg = document.getElementById(el);
            cvr.style.display = "none";
            dlg.style.display = "none";
            if(document.body.style.overflow == "hidden") document.body.style.overflow = "auto";
        }
        
       

