﻿var __AT_SubmitValue;	//when blokcing. Save the submit value;
var __AT_OnkeypressValue;
var __AT_PageBlockerTempValue;
var __AT_EnablePageBlock=true;
var __AT_PageBlockCount=0;



function __AT_PausePageBlocker(vintPeriod)
{
		__AT_EnablePageBlock=false;
		setTimeout("__AT_EnablePageBlock=true;",vintPeriod) 
}


function __AT_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 __AT_DisablePageBlockerCount(vintCount, vblnAutoAdd)
{
		if (vblnAutoAdd == null) vblnAutoAdd=false;
	
	
		if (vintCount > 0) 
		{
				if (vblnAutoAdd==true && __AT_IsOnbeforeunloadBugVersion()) {vintCount++;}
				__AT_PageBlockCount=vintCount;
		}
		
		
}


//function for registering window.onblur event
function __AT_DisablePageBlockerByOnblur()
{
		window.onblur=__AT_DisablePageBlocker;
}

//function for Disable PageBlocker
function __AT_DisablePageBlocker() 
{
		__AT_PageBlocking(false);
}


//function for fail event
function __AT_FalseFunction()
{
	return false;
}


//function for onbeforeunload
function __AT_PageBlocker() 
{
		setTimeout("__AT_PageBlocking(true)",__AT_PageBlockerIdleTime);
}

//function for setting PageBlockerPeriod
function __AT_SetPageBlockerPeriod(vintPeriod)
{
	if (vintPeriod == null)
	{
			if (__AT_PageBlockerPeriod > 0)
			{
				setTimeout("__AT_PageBlocking(false)",(__AT_PageBlockerPeriod)) 
			}
	}
	else
	{
				alert(vintPeriod+ __AT_PageBlockerIdleTime);
			setTimeout("__AT_PageBlocking(false)",(vintPeriod+ __AT_PageBlockerIdleTime)) 
	}
} 


//main function for blocking 
function __AT_PageBlocking(vblnDoing) 
{
	
	
		if (__AT_PageBlockCount > 0)
		{
			//alert(__AT_PageBlockCount);
			__AT_PageBlockCount=__AT_PageBlockCount-1;
			return;
		}
	 

	
		if(!__AT_EnablePageBlock) 
		{
		//	__AT_EnablePageBlock=true;
			return;
		}
	
		try
		{if (Page_BlockSubmit) return;}
		catch(e)
		{}

	
		if (vblnDoing!=false) {vblnDoing=true;}
 
		if (vblnDoing==true) 
		{
			
			
			document.body.style.height="100%";
			document.body.style.padding="0";
			//document.body.style.margin="0";
			document.body.style.border="none";
			
			if (document.all.__PageBlocker.style.display == 'block') return;
			if (document.body.clientHeight > document.body.scrollHeight)
			{
				document.all.__PageBlocker.style.height=document.body.clientHeight;
			}
			else
			{
				document.all.__PageBlocker.style.height=document.body.scrollHeight;
			}
			
				document.all.__PageBlocker.style.display = 'block';
			
			if(__AT_PageBlockNoteControl != null)
			{
				__AT_PageBlockNoteControl.style.display="";
			}
			
			
				__AT_OnkeypressValue=document.onkeypress;
				__AT_SubmitValue=document.forms[0].onsubmit;				
				document.onkeypress=__AT_FalseFunction;
				document.forms[0].onsubmit=__AT_FalseFunction;
			  
				for (i=0;i<document.all.tags("SELECT").length;i++)
				{
						tempSelect = document.all.tags("SELECT")[i];
						if (tempSelect.disabled==true) 
						{
								tempSelect.setAttribute("PreDisabled","true");  
						} 
						else 
						{
								tempSelect.setAttribute("PreDisabled","false");
						}
						tempSelect.disabled = true;
							//tempSelect.style.background = '#CCCCCC';
				}
		
		
		
				__AT_SetPageBlockerPeriod()
		} 
		else 
		{
			
			  if (document.all.__PageBlocker.style.display == 'none') return;
			 	document.all.__PageBlocker.style.display = 'none';		
			 	document.onkeypress=__AT_OnkeypressValue;
				document.forms[0].onsubmit=__AT_SubmitValue;
				
				if(__AT_PageBlockNoteControl != null)
				{
					__AT_PageBlockNoteControl.style.display="none";
				}
				
			  for (i=0;i<document.all.tags("SELECT").length;i++)
  			{
				 	  tempSelect = document.all.tags("SELECT")[i];
				  	if (tempSelect.getAttribute("PreDisabled")=="false") 
				  	{
				    		tempSelect.disabled = false;
				    	//	tempSelect.style.background = '#FFFFFF';
				   	} 
				   	else 
				   	{
				    		tempSelect.disabled = true;
				    //tempSelect.style.background = '#CCCCCC';
				   }
  			}
	  }
}
