﻿//<!--******************************************************************************************-->
//
//  警告: 本電腦程式著作受著作權法及國際公約之保護。
//  未經授權擅自複製或散佈本電腦程式著作之全部或部分
//  ，將導致嚴厲的民事或刑事處份，且將被依法提起最大
//  範圍的追訴。
//
//  CopyRight (C) Galaxy Software Service
//  Version: 2.0.500.3
//<!--******************************************************************************************-->
var __NBase_SubmitValue;    //when blokcing. Save the submit value;
var __NBase_OnkeypressValue;    //for keeping leypress event content
var __NBase_PageBlockerTempValue;
var __NBase_EnablePageBlock=true;
var __Heart_EnablePageBlock=true;
var __NBase_PageBlockCount=0;

function __NBase_PausePageBlocker(vintPeriod)
{
    __NBase_EnablePageBlock=false;
    setTimeout("__NBase_EnablePageBlock=true;",vintPeriod)
}
function __NBase_IsOnbeforeunloadBugVersion()
{
    var info = window.navigator.userAgent;
    var ver = info.substr(info.indexOf('Windows NT')+11,3);
    var sp = window.navigator.appMinorVersion;
    var btnReturn=false;

    switch (ver)
    {
        case "5.2":
            //Windows 2003
            if (sp != ";SP1;") 
                //alert('Please upgrade to Windows 2003 SP1');
            btnReturn=true;
            break;
         case "5.1": 
            //Windows XP
            if (sp != ";SP2;") 
                //alert('Please upgrade to Windows XP SP2');
            btnReturn=true;         
            break;
         case "5.0":
            //Windows 2000
            //Add your code here
            btnReturn=true;
            break;
    }    
    return btnReturn;
}
//function for registering Blocker Count
function __NBase_DisablePageBlockerCount(vintCount, vblnAutoAdd)
{
    if (vblnAutoAdd == null) vblnAutoAdd=false;
    if (vintCount > 0) 
    {
        if (vblnAutoAdd==true && __NBase_IsOnbeforeunloadBugVersion()) {vintCount++;}
        __NBase_PageBlockCount=vintCount;
    }
}
//function for registering window.onblur event
function __NBase_DisablePageBlockerByOnblur()
{
    window.onblur=__NBase_DisablePageBlocker;
}

//function for Disable PageBlocker
function __NBase_DisablePageBlocker() 
{
    __NBase_PageBlocking(false)
}
//function for fail event
function __NBase_FalseFunction()
{
    return false;
}
//function for onbeforeunload
function __NBase_PageBlocker(vblnDoing) 
{
    __Heart_EnablePageBlock = true;
    setTimeout("__NBase_PageBlocking(true)",__NBase_PageBlockerIdleTime) ;
}
//function for setting PageBlockerPeriod
function __NBase_SetPageBlockerPeriod(vintPeriod)
{
    if (vintPeriod == null)
    {
        if (__NBase_PageBlockerPeriod > 0)
        {
            setTimeout("__NBase_PageBlocking(false)",(__NBase_PageBlockerPeriod)) 
        }
    }else{
            alert(vintPeriod+ __NBase_PageBlockerIdleTime);
            setTimeout("__NBase_PageBlocking(false)",(vintPeriod+ __NBase_PageBlockerIdleTime));
    }
}
function __GetScrollMaxX()
{
    var xScroll;
    if (window.innerHeight && window.scrollMaxY)
    { 
        xScroll = document.body.scrollWidth;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
    } else {
        xScroll = document.body.offsetWidth;
    }
 
    var windowWidth;
    if (self.innerHeight)
    {
        windowWidth = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
    } 
    
    var pageWidth;
    if(xScroll < windowWidth)
    { 
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    return pageWidth;
}
//main function for blocking 
function __NBase_PageBlocking(vblnDoing) 
{
    if (__NBase_PageBlockCount > 0)
    {
        __NBase_PageBlockCount=__NBase_PageBlockCount-1;
        return;
    }
    if(!__NBase_EnablePageBlock) 
    {
        return;
    }
    if(!__Heart_EnablePageBlock)
    {
        __Heart_EnablePageBlock = true;
        return;
    }
    try
    {
    	if (Page_BlockSubmit) return;}
    catch(E){}
    
    var tempSelect;
    if (vblnDoing!=false) {vblnDoing=true;}
 
    if (vblnDoing==true) 
    {
        document.body.style.height="100%";
        document.body.style.padding="0";
        document.body.style.border="none";
                    
        if (document.getElementById("__NBasePageBlocker").style.display == 'block') return;
        var i = document.body.scrollHeight;
        var intScrollMaxY = (isNaN(window.scrollMaxY) || window.scrollMaxY=="")?0:window.scrollMaxY;
        var intScrollHeight = 0;
        intScrollHeight = parseInt(document.body.scrollHeight) + parseInt(intScrollMaxY);
        if (document.body.clientHeight > intScrollHeight)
        {
            //document.getElementById("__NBasePageBlocker").style.height = document.body.clientHeight;
            $("#__NBasePageBlocker").css("height",document.body.clientHeight);
        }else{
            //document.getElementById("__NBasePageBlocker").style.height = intScrollHeight;
            $("#__NBasePageBlocker").css("height",intScrollHeight);
        }
        var userAgent = navigator.userAgent;
        if(userAgent.indexOf("Firefox") != -1)
        {
            $("#__NBasePageBlocker").css("width",window.innerWidth + window.scrollMaxX - 10);
        }else{
            $("#__NBasePageBlocker").css("width",__GetScrollMaxX());
        }
        document.getElementById("__NBasePageBlocker").style.display = 'block';
            
        if(__NBase_PageBlockNoteControl != null)
        {
            __NBase_PageBlockNoteControl.style.display="";
            //隱藏iframe內的blocker
            try
            {
            var objIFrame = $("iframe");
            for (var i=0; i<objIFrame.length; i++)
            {
                if(objIFrame[i].contentDocument)
                {
                    if(objIFrame[i].contentDocument.getElementById(__NBase_PageBlockNoteControl.id) != null)
                    {
                        objIFrame[i].contentDocument.getElementById(__NBase_PageBlockNoteControl.id).style.display = "none";
                        objIFrame[i].contentDocument.getElementById("__NBasePageBlocker").style.display = "none";
                    }
                }else{
                    if(objIFrame[i].contentWindow.document.getElementById(__NBase_PageBlockNoteControl.id) != null)
                    {
                        objIFrame[i].contentWindow.document.getElementById(__NBase_PageBlockNoteControl.id).style.display = "none";
                        objIFrame[i].contentWindow.document.getElementById("__NBasePageBlocker").style.display = "none";
                    }
                }
            }
            }catch(e){}
            if(this.parent != this)
            {
                if(this.parent.document.getElementById(__NBase_PageBlockNoteControl.id).style.display != "none")
                {
                    __NBase_PageBlockNoteControl.style.display="none";
                    document.getElementById("__NBasePageBlocker").style.display = "none";
                }
            }
        }
        __NBase_OnkeypressValue=document.onkeypress;
        __NBase_SubmitValue=document.forms[0].onsubmit;    
                    
        document.onkeypress=__NBase_FalseFunction;
        document.forms[0].onsubmit=__NBase_FalseFunction;
          
        for (i=0;i<document.getElementsByTagName("SELECT").length;i++)
        {
            tempSelect = document.getElementsByTagName("SELECT")[i];
            if (tempSelect.disabled==true) 
            {
                tempSelect.setAttribute("PreDisabled","true");  
            }else{
                tempSelect.setAttribute("PreDisabled","false");
            }
            tempSelect.disabled = true;
        }

        __NBase_SetPageBlockerPeriod();
    }else{        
        if (document.getElementById("__NBasePageBlocker").style.display == 'none') return;
        document.getElementById("__NBasePageBlocker").style.display = 'none';        
        document.onkeypress=__NBase_OnkeypressValue;
        document.forms[0].onsubmit=__NBase_SubmitValue;
    
        if(__NBase_PageBlockNoteControl != null)
        {
            __NBase_PageBlockNoteControl.style.display="none";
        }
                 
        for (i=0;i<document.getElementsByTagName("SELECT").length;i++)
        {
            tempSelect = document.getElementsByTagName("SELECT")[i];
            if (tempSelect.getAttribute("PreDisabled")=="false") 
            {
                tempSelect.disabled = false;
            }else{
                tempSelect.disabled = true;
            }
        }
    }
}