﻿function LayerLoader()
{
	LayerLoader.ID = "_BarTab_LayerWindow";

    // Flag for WidgetManager.Browser.Opera web browser
	LayerLoader.Browser = new Object();
	LayerLoader.Browser.IE = navigator.userAgent.toLowerCase().indexOf('msie') >= 0 ? true : false;
	LayerLoader.Browser.Opera = navigator.userAgent.toLowerCase().indexOf('opera') >= 0 ? true : false;		
	LayerLoader.Browser.Mozilla = navigator.userAgent.toLowerCase().indexOf('firefox') >= 0 ? true : false;
	LayerLoader.Browser.Netscape = navigator.userAgent.toLowerCase().indexOf('netscape') >= 0 ? true : false;
	
	// Value for Model Window's height and width
	LayerLoader.Height = 200;
	LayerLoader.Width = 200;	
	
	// Value for scroll height & width of the page
	LayerLoader.ScrollWidth = document.body.scrollWidth;
	LayerLoader.ScrollHeight = document.body.scrollHeight;
			
	LayerLoader.ScrollLeft = typeof( window.pageXOffset ) == "number"? window.pageXOffset : (document.body.scrollLeft? document.body.scrollLeft : document.documentElement.scrollLeft);	
	LayerLoader.ScrollTop = typeof( window.pageYOffset ) == "number"? window.pageYOffset : (document.body.scrollTop? document.body.scrollTop : document.documentElement.scrollTop);
				
	// Value for browser height & width of the page	
	LayerLoader.ClientWidth = self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);			
	if(LayerLoader.Browser.Mozilla)
	{
	  LayerLoader.ClientWidth -= 17;
	}
	LayerLoader.ClientHeight = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
					
	// Model window layer
	LayerLoader.WindowLayer = null;	
		
	// IFrame window container
	LayerLoader.LoadingContainer = null;
	
	// Model window call back function
	LayerLoader.CallBackFunction = null;	
	
	// Set controls visibility
	LayerLoader.SetControlsVisibility = function(isVisible)
	{
		//Hide all drop down tags
		var dropDownCtrl = document.getElementsByTagName("SELECT");
		var nLength = dropDownCtrl.length;
		for(var nCnt=0; nCnt<nLength; nCnt++)
		{
			dropDownCtrl[nCnt].style.visibility = isVisible == false? "hidden" : "visible";
		}
		dropDownCtrl = null;
		
		//Hide all embed tags
		var embedCtrl = document.getElementsByTagName("EMBED");
		nLength = embedCtrl.length;
		for(var nCnt=0; nCnt<nLength; nCnt++)
		{
			embedCtrl[nCnt].style.visibility = isVisible == false? "hidden" : "visible";
		}
		embedCtrl = null;
		
		//Hide all drop down tags
		var objectCtrl = document.getElementsByTagName("OBJECT");
		nLength = objectCtrl.length;
		for(var nCnt=0; nCnt<nLength; nCnt++)
		{
			objectCtrl[nCnt].style.visibility = isVisible == false? "hidden" : "visible";
		}
		objectCtrl = null;
	};
			
	// Scroll class
	LayerLoader.Scroller = function()
	{	
		// Initalise scroll class
		LayerLoader.Scroller.Init = function()
		{
			if(document.layers)								   
				{LayerLoader.LoadingContainer.style = LayerLoader.LoadingContainer;}				
						
			LayerLoader.LoadingContainer.X = LayerLoader.StartX;			
			LayerLoader.LoadingContainer.Y = LayerLoader.StartY;			
			LayerLoader.Scroller.PersistPosition();
			
			new LayerLoader.Scroller.Layer();	
			LayerLoader.Scroller.Layer.Refresh();
		};
		
		// Validation IE compact window validation
		LayerLoader.Scroller.IECompact = function()
		{
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		};		
		
		// Set position of IFrame container window
		LayerLoader.Scroller.SetPosition = function(x, y)
		{				
			LayerLoader.LoadingContainer.style.top = y + "px";			
			LayerLoader.LoadingContainer.style.left = x + "px";			
		};	
			
		// Persist position of IFrame container window
		LayerLoader.Scroller.PersistPosition = function()
		{		
			if(LayerLoader.Browser.IE)
			{
				if(LayerLoader.LoadingContainer)
					{LayerLoader.LoadingContainer.Y += (LayerLoader.Scroller.IECompact().scrollTop + LayerLoader.StartY - LayerLoader.LoadingContainer.Y)/8;}
			}
			else
			{
				if(LayerLoader.LoadingContainer)
					{LayerLoader.LoadingContainer.Y += (LayerLoader.Scroller.IECompact().scrollTop + LayerLoader.StartY - LayerLoader.LoadingContainer.Y)/8;}
			}
				
			if(LayerLoader.LoadingContainer)
			{
				LayerLoader.Scroller.SetPosition(LayerLoader.LoadingContainer.X, LayerLoader.LoadingContainer.Y);
				setTimeout("LayerLoader.Scroller.PersistPosition();", 3);				
			}
		};
		
		// Refresh height of opaque layer
		LayerLoader.Scroller.Layer = function()
		{
			LayerLoader.Scroller.Layer.Refresh = function()
			{	
				//Get updated client height & width
				BarTab.Browser.Client();
				
				// Value for browser height & width of the page
				LayerLoader.ClientWidth = (document.documentElement.clientWidth || document.body.clientWidth);
				if(LayerLoader.Browser.Mozilla)
	            {
	              LayerLoader.ClientWidth -= 17;
	            }
				LayerLoader.ClientHeight = document.body.scrollHeight;
										
				LayerLoader.ScrollLeft = typeof( window.pageXOffset ) == "number"? window.pageXOffset : (document.body? (document.body.scrollLeft? document.body.scrollLeft : document.documentElement.scrollLeft): 0);	
				LayerLoader.ScrollTop = typeof( window.pageYOffset ) == "number"? window.pageYOffset : (document.body? (document.body.scrollTop? document.body.scrollTop : document.documentElement.scrollTop): 0);
				
				if(LayerLoader.ScrollHeight < LayerLoader.ClientHeight)
				{
					if(LayerLoader.Browser.IE || LayerLoader.Browser.Mozilla || LayerLoader.Browser.Netscape)
					{
						if(LayerLoader.WindowLayer)
							{LayerLoader.WindowLayer.style.height = LayerLoader.ClientHeight + 30 + "px";}
					}
					else
					{
						if(LayerLoader.WindowLayer)
							{LayerLoader.WindowLayer.style.height = LayerLoader.ClientHeight + 30 + "px";}
					}
				}
				else
				{
					if(LayerLoader.WindowLayer)
						{LayerLoader.WindowLayer.style.height = LayerLoader.ClientHeight + 100 + "px";}	
				}
					
				setTimeout("if(LayerLoader.Scroller.Layer){LayerLoader.Scroller.Layer.Refresh();}", 3);
			};
		};		
	};
	
	// Render Model window
	LayerLoader.Render = function()
	{	
		try
		{
			// Hide all drop down tags
			LayerLoader.SetControlsVisibility(false);
			
			// Value for layer window's start X and Y position			
			LayerLoader.StartX = (LayerLoader.ClientWidth - LayerLoader.Width)/2 - 20;
			LayerLoader.StartY = (LayerLoader.ClientHeight - LayerLoader.Height)/2 - 20;
						
			// Create opaque layer
			LayerLoader.WindowLayer = document.createElement("DIV");			
			LayerLoader.WindowLayer.style.cssText = "position:absolute; background:#333333; opacity:0.3; filter:alpha(opacity=30); width:" + LayerLoader.ClientWidth + "px; left:0px; top:0px";
			LayerLoader.WindowLayer.style.zIndex = 100001;
			if(LayerLoader.ScrollHeight < LayerLoader.ClientHeight)
			{
				if(LayerLoader.Browser.IE || LayerLoader.Browser.Mozilla || LayerLoader.Browser.Netscape)
					{LayerLoader.WindowLayer.style.height = LayerLoader.ClientHeight + 30 + "px";}
				else
					{LayerLoader.WindowLayer.style.height = LayerLoader.ScrollHeight + 30 + "px";}
			}
			else
				{LayerLoader.WindowLayer.style.height = LayerLoader.ScrollHeight + 100 + "px";}
					
			document.body.appendChild(LayerLoader.WindowLayer);
					
			// Create object of google map loader
            LayerLoader.LoadingContainer = document.createElement("DIV");
			LayerLoader.LoadingContainer.className = "DvLoader";
			LayerLoader.LoadingContainer.style.zIndex = 100002;			
			LayerLoader.LoadingContainer.style.position = "absolute";			
			LayerLoader.LoadingContainer.innerHTML = "<div class=\"DvLoaderMain\"><img src=\"../../App_Themes/NewUserTheme/Img/Logo_BarTab.gif\" alt=\"TabTabLogo\" /><p>Please wait while loading</p><div class=\"padt16 padb16\"><img src=\"../../App_Themes/NewUserTheme/Img/loading.gif\" alt=\"Loading\" /></div><p><span>Depending upon the net connection page might take longer time to load than usual.</span></p></div>";				
			document.body.appendChild(LayerLoader.LoadingContainer);				
						
			// Initialise scroller class
			new LayerLoader.Scroller();
			LayerLoader.Scroller.Init();
		}
		catch(e)
		{}
		finally
		{
			dvPopHeader = null;
			dvLft1401 = null;
			dvLogo2 = null;
			dvRht1401 = null;
			dvCloseBtn = null;
			lnkCloseBtn = null;
			newLine = null;
			grayLineTop3 = null;
			dvPopMiddle = null;
		}		
	};
	
	// Show model window
	LayerLoader.Show = function()
	{
        LayerLoader.WindowLayer.style.display = ""; 
    };

	// Hide model window
	LayerLoader.Hide = function()
	{
		LayerLoader.WindowLayer.style.display = "none"; 
	};
	
	// Close model window
	LayerLoader.Close = function()
	{
	    // Show all drop down tags
		LayerLoader.SetControlsVisibility(true);
	    
		// Destroy model window
		LayerLoader.Destroy();	       
		
		if(LayerLoader.CallBackFunction)
			{LayerLoader.CallBackFunction();}
		
	    LayerLoader.CallBackFunction = null;	
	};
	
	// Destroy model window
	LayerLoader.Destroy = function()
	{	   
		// Remove all objects		
		document.body.removeChild(LayerLoader.LoadingContainer);		
		document.body.removeChild(LayerLoader.WindowLayer);
						
		// Nullify all variables
		LayerLoader.ID = null;		
		LayerLoader.StartX = null;
		LayerLoader.StartY = null;
		LayerLoader.Height = null;
		LayerLoader.Width = null;
		LayerLoader.ScrollHeight = null;
		LayerLoader.ScrollWidth = null;
		LayerLoader.ClientHeight = null;
		LayerLoader.ClientWidth = null;
		LayerLoader.WindowLayer = null;
		LayerLoader.LoadingContainer = null;
	};
}