﻿     
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=";


                var params2 = "&currenturl=" + document.location.href;

                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 + params2.length));
                xmlhttpLogin.setRequestHeader("Connection", "close");

                xmlhttpLogin.send(params + params2);
                
              }
              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
        {
            
        }
      }

  }

      // 3161 - Confirmation box breaks scroll
      // Laurnece Blake
      // 2011-04-01
      // Had to move the javascript functions out of coretools and edit them
      
    
    //These two functions are specifically for the confirmation box.

    function showPopUp(el, coverDiv) {

        showPopUpConf(el, coverDiv, true);
        setTimeout("scroll(0, 0)", 100);
    }

    function showPopUpConf(el, coverDiv, loginCheck) {

        if (loginCheck) {
            doALoginCheck();
        }

        scroll(0, 0);


        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(OnEndRequest);

        function OnEndRequest(sender, args) {
            if (typeof (dlg) != "undefined") {
                doResizeControl();
                Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(OnEndRequest)
            }
        }






        var cvr = document.getElementById(coverDiv)
        dlg = document.getElementById(el)
        window.onresize = doResizeControl;

        cvr.style.display = "block";

        dlg.style.display = "block";

        setOpacityControl(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 (Math.round((document.documentElement.clientHeight / 2) - (dlg.clientHeight / 2)) < 0) {
            dlg.style.top = '30px';
        }

        //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 (EnableCloseButton == undefined || EnableCloseButton == true) {
                if (keyCode == 27) {
                    closePopUp(coverDiv, el);
                    if (window.CoreTools_ConfirmationBox_ServerCall != null) {
                        CoreTools_ConfirmationBox_ServerCall('1');
                    }
                }
            }
        }

    }
    
     //These ones are for the popups.
        function showPopUpControl(el, coverDiv) {
            
            showPopUpControl(el, coverDiv, true);
        }
     
     
        function showPopUpControl(el, coverDiv, loginCheck) {
            
            if(loginCheck)
            {
                doALoginCheck();
            }

            scroll(0, 0);
            
            
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_endRequest(OnEndRequest);
                                            
            function OnEndRequest(sender,args)
            {                            
                if ( typeof( dlg ) != "undefined" ) {
                    doResizeControl();  
                    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(OnEndRequest)  
                }
            }




            
            
            var cvr = document.getElementById(coverDiv)
            dlg = document.getElementById(el)
            window.onresize = doResizeControl;

            cvr.style.display = "block";

            dlg.style.display = "block";

            setOpacityControl(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 (Math.round((document.documentElement.clientHeight / 2) - (dlg.clientHeight / 2)) < 0) {
                dlg.style.top = '30px';
            }
            
            //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 setOpacityControl(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";
            
	        if (Math.round((document.documentElement.clientHeight / 2) - (obj.clientHeight / 2)) < 0) {
	            obj.style.top = '30px';
	        }
	        
	        cvr.style.height = (getPageSizeWithScroll()[1] < document.documentElement.clientHeight ? document.documentElement.clientHeight : getPageSizeWithScroll()[1]) + "px";
	        if (value < 10) setTimeout("setOpacityControl(document.getElementById('" + cvr.id + "'), document.getElementById('" + obj.id + "'), + " + (value + 2) + ")", 10)
        }

        function doResizeControl()
        {
            
            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";

                if (Math.round((document.documentElement.clientHeight / 2) - (dlg.clientHeight / 2)) < 0) {
                    dlg.style.top = '30px';
                }

            }
            
        }
        
        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";
        }



        function set_enabled(id, val) {

            var n = document.getElementById(id);

            if (n != null) {
                n.disabled = val;
            }
        }




        function hideCalendarPopup(sender, args) {

            var c = args.get_keyCode();
            
            if (c == 9) {
                if (sender.get_owner().hidePopup) {
                    sender.get_owner().hidePopup();
                }
                if (sender.get_owner().hideTimePopup) {
                    sender.get_owner().hideTimePopup();
                }
            }
        }

        
