//
//requires: Aspacts.Script.Utils.Core.js
//

addNamespace("Aspacts.Script.Utils.InlineWin")


/*************************************************************

	Name: Aspacts.Script.Utils.InlineWin.System_class
	Description: Main system class for inline window system.
		The system supports modal windows inline with the page.
		Users can set header values, and create buttons in the 
		footer.           
	Public methods:
		- OpenWindow
		- FindWindow
	Author: Coen Hoogstede
	Date: 28-September-2006

**************************************************************/                                                   

	//constructor                                                   
	Aspacts.Script.Utils.InlineWin.System_class = function() 
	{ 	       
		
	};                                                                                                   


	//prototype      
	Aspacts.Script.Utils.InlineWin.System_class.prototype = {
		
		
		// base attributes
		windowItems: new Array(),
	  boolInitialized: false,     
	  refBlockLayerElement: null,
	  intZIndex: 1001,
	  pageOffsetX: 0,
	  pageOffsetY: 0,
	     
 
		/**
		*	Name: Initialize
		* Description:  Prepares document for inline window system
		* Parameters: (none)
		**/	                    
		Initialize: function()
		{  
			if (!this.boolInitialized)
			{         
			 
				if (MS.Browser.isIE)
				{ Aspacts.Script.Utils.Core.ImplementEvent(document.body)
					document.body.addEventListener('resize', function(){Aspacts.Script.Utils.InlineWin.System.HandleResize()}, true)           
				}
				else
				{
				 	Aspacts.Script.Utils.Core.ImplementEvent(window)
			   	window.addEventListener('resize', function(){Aspacts.Script.Utils.InlineWin.System.HandleResize()}, true)           
			  
			  }
			  //create modal blocking layer element
				this.refBlockLayerElement = document.createElement("div")
				document.body.insertBefore(this.refBlockLayerElement, document.body.firstChild)
				this.refBlockLayerElement.className = "InlineWin_ModalBlock"  			
			
		   	this.boolInitialized = true
		  }
		},
		 
		/**
		*	Name: OpenWindow
		* Description:  Opens a new inline window and returns a reference to the new window
		* Parameters: 
		* 	- strUrl: The url to open in the window frame
		*		- strName: A reference name for the window (optional)
		*		- intWidth: Width of the window (optional, default: 800)
		*		- intHeight: Height of the window (optional, default: 600)
		*	Returns: instance of type Aspacts.Script.Utils.InlineWin.WindowItem_class
		**/	  
		OpenWindow:  function(strUrl, strName, intWidth, intHeight)
		{     
			if (!document.body)
			{
				alert('Document.Body not yet initialized. Cannot open window.')
				return
			}
			this.Initialize()
		
			//create new windowitem		 
			this.intZIndex++
			this.intZIndex++//make sure there is at least one open Z-index between layers for the blocking layer
			
			if (this.windowItems.length == 0)
			{
				if (window.pageXOffset)
				{
					this.pageOffsetX = window.pageXOffset
	      			this.pageOffsetY = window.pageYOffset
				} 
				else
				{
					this.pageOffsetX = document.documentElement.scrollLeft
	      			this.pageOffsetY = document.documentElement.scrollTop	
	      			
				}
			}
			
			var newWindowItem = new Aspacts.Script.Utils.InlineWin.WindowItem_class(this, this.intZIndex, strUrl, strName, intWidth, intHeight)
			this.windowItems.push(newWindowItem)
			
			
			
			this.HandleResize()
			this.UpdateBlockLayer()
			return newWindowItem
			
		} ,
		
		OpenLoadingWindow:  function(windowNodes, strName, intWidth, intHeight)
		{     
			if (!document.body)
			{
				alert('Document.Body not yet initialized. Cannot open window.')
				return
			}
			this.Initialize()
		
			//create new windowitem		 
			this.intZIndex++
			this.intZIndex++//make sure there is at least one open Z-index between layers for the blocking layer
			if (this.windowItems.length == 0)
			{
				if (window.pageXOffset)
				{
					this.pageOffsetX = window.pageXOffset
	      			this.pageOffsetY = window.pageYOffset
				} 
				else
				{
					this.pageOffsetX = document.documentElement.scrollLeft
	      			this.pageOffsetY = document.documentElement.scrollTop	
	      			
				}
			}
			var newWindowItem = new Aspacts.Script.Utils.InlineWin.WindowLoading_class(this, this.intZIndex, strName, intWidth, intHeight, windowNodes)
			this.windowItems.push(newWindowItem)
			
			
			
			this.HandleResize()
			this.UpdateBlockLayer()
			return newWindowItem
			
		} ,
		
		/**
		*	Name: OpenWindow
		* Description:  Opens a new inline window and returns a reference to the new window
		* Parameters: 
		*		- strName: A reference name for the window (optional)
		*		- strTitle: The title for the window
		*		- strMessage: The message displayed in the window
		*		- intWidth: Width of the window (optional, default: 800)
		*		- intHeight: Height of the window (optional, default: 600)
		*	Returns: instance of type Aspacts.Script.Utils.InlineWin.WindowItem_class
		**/	  
		OpenMessageWindow:  function(strName, strTitle, strMessage, intWidth, intHeight)
		{    
			if (!document.body)
			{
				alert('Document.Body not yet initialized. Cannot open window.')
				return
			}
			this.Initialize()
		
			//create new windowitem		 
			this.intZIndex++
			this.intZIndex++//make sure there is at least one open Z-index between layers for the blocking layer
				
			if (this.windowItems.length == 1)
			{
				if (window.pageXOffset)
				{
					this.pageOffsetX = window.pageXOffset
	      			this.pageOffsetY = window.pageYOffset
	      			
				} 
				else
				{
					this.pageOffsetX = document.documentElement.scrollLeft
	      			this.pageOffsetY = document.documentElement.scrollTop	
	      			
				}
				
			}
			var newWindowItem = new Aspacts.Script.Utils.InlineWin.WindowItem_class(this, this.intZIndex, '', strName, intWidth, intHeight)
			this.windowItems.push(newWindowItem)
		
			
			this.HandleResize()
			this.UpdateBlockLayer()
			
			newWindowItem.SetTitle(strTitle)
			newWindowItem.RenderMessage(strMessage)
			return newWindowItem	
		},
		
		/**
		*	Name: CloseWindow
		* Description: Handles closing of a window when window.Close() is called
		* Remarks: Internal method, not to be called directly
		* Parameters: 
		* 	- intId: The id of the window being closes
		**/
		CloseWindow:  function(intId)
		{    
			var closedWindows = new Array                  
			for(var i = 0; i<this.windowItems.length; i++)
			{
				if (this.windowItems[i].intId == intId)
				{
					closedWindows.push(this.windowItems[i])
				}
			}	
			for(var i = 0; i<closedWindows.length; i++)
			{
				//closedWindows[i].Close()
				this.windowItems.deleteNode(closedWindows[i])
			}		     
			this.UpdateBlockLayer()
			if(this.windowItems.length == 0)
			{
				
				document.body.blur();
				document.body.focus();
				
				var refItems = document.getElementsByTagName("input")
				for(var i = 0; i<refItems.length; i++)
				{
					try
					{
						if(refItems[i].type == "text")
						{
							//refItems[i].focus()
							refItems[i].select()
							refItems[i].blur()
							break
						}
						//refItems[i].blur()
						
					}
					catch(err)
					{
					 //do nothing
					}
					
				}
				
			}                 
			else
			{
				if (this.windowItems[this.windowItems.length-1].refContentFrame)
					this.windowItems[this.windowItems.length-1].refContentFrame.contentWindow.focus()
			}                 
			
		},
	
		/**
		*	Name: FindWindow
		* Description: Returns a reference to an opened window
		* Parameters: 
		* 	- strName: Name of the window
		*	Returns: instance of type Aspacts.Script.Utils.InlineWin.WindowItem_class
		**/
		FindWindow:  function(strName)
		{ 
			for(var i = 0; i<this.windowItems.length; i++)
			{
				if (this.windowItems[i].strName == strName)
				{
					return this.windowItems[i]
				}
			}	 
			return null                        
		},
	
		/**
		*	Name: UpdateBlockLayer
		* Description: Updates the state of the blocking-layer which blocks 
		* 	user-access to html-elements behind the current window
		* Remarks: Internal method, not to be called directly
		* Parameters: (none)		
		**/
		UpdateBlockLayer: function()
		{     
			var intLayerZIndex = 0
			for(var i = 0; i<this.windowItems.length; i++)
			{
				intLayerZIndex = Math.max(intLayerZIndex,this.windowItems[i].intZIndex) 
			}	              
			                                                      
			intLayerZIndex--           
			if (intLayerZIndex > 0)
			{
				if (MS.Browser.isIE && this.refBlockLayerElement.style.display!="block"	)
				{
					var lstDropdownLists = document.getElementsByTagName("select")
					for (var i=0; i< lstDropdownLists.length; i++)
					{
						lstDropdownLists[i].setAttribute("inlineWin_originalVisibility", lstDropdownLists[i].style.visibility)
						lstDropdownLists[i].style.visibility = "hidden"
					}
				}
				
				var lstObjects = document.getElementsByTagName("object")
				for (var i=0; i< lstObjects.length; i++)
				{
					lstObjects[i].setAttribute("inlineWin_originalVisibility", lstObjects[i].style.visibility)
					lstObjects[i].style.visibility = "hidden"
				}
				
				this.refBlockLayerElement.style.display="block"	
				this.refBlockLayerElement.style.zIndex= intLayerZIndex
       			document.documentElement.style.overflow = "hidden"
				document.documentElement.style.marginTop = 0-this.pageOffsetY + "px"
				document.documentElement.style.marginLeft = 0-this.pageOffsetX + "px"
				document.documentElement.style.paddingRight = "17px";
				this.HandleResize()
			
			}
			else
			{
				if (MS.Browser.isIE)
				{
	      			var lstDropdownLists = document.getElementsByTagName("select")
							for (var i=0; i< lstDropdownLists.length; i++)
							{
								lstDropdownLists[i].style.visibility = lstDropdownLists[i].getAttribute("inlineWin_originalVisibility")	
								lstDropdownLists[i].setAttribute("inlineWin_originalVisibility", null)
							}
				}
				var lstObjects = document.getElementsByTagName("object")
				for (var i=0; i< lstObjects.length; i++)
				{
					lstObjects[i].style.visibility = lstObjects[i].getAttribute("inlineWin_originalVisibility")	
					lstObjects[i].setAttribute("inlineWin_originalVisibility", null)
				}
		               
				this.refBlockLayerElement.style.display="none"
				document.documentElement.style.overflow = ""
				document.documentElement.style.marginTop = ""
				document.documentElement.style.marginLeft = ""
				document.documentElement.style.paddingRight = "";
				window.scrollTo(this.pageOffsetX,this.pageOffsetY)            
				
			}
			
		},
			
		/**
		*	Name: HandleResize
		* Description: Handles resizing of the browser-window. Updates the size 
		* 	of the blockinglayer and also calls ResetPosition of all windows to 
		* 	center windows in the window.
		* Remarks: Internal method, not to be called directly. Linked to window.onresize
		* Parameters: (none)		
		**/
		HandleResize: function()
		{  
			var intBrowserWidth, intBrowserHeight;
	
	
	
			if(typeof( window.innerWidth ) == 'number' )
			{ 
			   intBrowserWidth=window.innerWidth;
			   intBrowserHeight=window.innerHeight;
			}
			else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
			{     
			   intBrowserWidth=document.documentElement.clientWidth;
			   intBrowserHeight=document.documentElement.clientHeight;
			} 
			else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
			{     
			   intBrowserWidth=document.body.clientWidth;
			   intBrowserHeight=document.body.clientHeight;
			} 
			
			
			//this.pageOffsetY = 0
			//this.pageOffsetX = 0
			//alert('top: ' + this.pageOffsetY + ' left: ' + this.pageOffsetX + ' h: ' + intBrowserHeight + ' w: ' + intBrowserWidth)
			this.refBlockLayerElement.style.top = this.pageOffsetY + "px"
			this.refBlockLayerElement.style.left = this.pageOffsetX + "px"
			this.refBlockLayerElement.style.width = intBrowserWidth + "px"
			this.refBlockLayerElement.style.height = intBrowserHeight + "px"
				
			for(var i = 0; i<this.windowItems.length; i++)
			{
					this.windowItems[i].ResetPosition(intBrowserWidth,intBrowserHeight, this.pageOffsetX,  this.pageOffsetY)	
			}
		} ,
		
		ShowToolTip: function(evt, tooltipId, parentId, posX, posY)
		{
			
			it = document.getElementById(tooltipId);
		    
		  	//if ((it.style.top == '' || it.style.top == "0px") 
			//	&& (it.style.left == '' || it.style.left == 0))
			{
				// need to fixate default size (MSIE problem)
				//it.style.width = it.offsetWidth + 'px';
				//it.style.height = it.offsetHeight + 'px';
		        
				img = document.getElementById(parentId); 
				
				if (it.originalParent == null)
					it.originalParent = it.parentNode
				
				// if tooltip is too wide, shift left to be within parent 
				if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
				//if (posX < 0 ) posX = 0; 
		        
				x = this.FindElementPosX(img) + posX;
				y = this.FindElementPosY(img) + posY;
			    
				//it.style.top = y + 'px';
				//it.style.left = x + 'px';
				
				if (evt)
				
				{
					if (window.pageXOffset)
					{
						this.pageOffsetX = window.pageXOffset
	      				this.pageOffsetY = window.pageYOffset
	      			
					} 
					else
					{
						this.pageOffsetX = document.documentElement.scrollLeft
	      				this.pageOffsetY = document.documentElement.scrollTop	
	      				
					}
					
					it.style.top = "0px"
					it.style.left = "0px"
					
					var intTop = (evt.clientY - this.FindElementPosY(it) + posY + this.pageOffsetY)
					var intLeft = (evt.clientX - this.FindElementPosX(it) + posX + this.pageOffsetX)
					
					intTop = Math.max(intTop,0)
					intLeft = Math.max(intLeft,0)
					it.style.top = intTop + "px"//(evt.clientY+posX) + 'px';
					it.style.left =intLeft + "px" // (evt.clientX+posY) + 'px';
				}
				
			}
		    
		   
			it.style.visibility = 'visible'; 
		},
		
		HideToolTip: function(id)
		{
			it = document.getElementById(id); 
			it.style.visibility = 'hidden'; 
			
		},

		FindElementPosY: function(obj) 
		{
			var curtop = 0;
			if (obj.offsetParent) 
			{
				while (obj.offsetParent) 
				{
					curtop += obj.offsetTop
					obj = obj.offsetParent;
				}
			}
			else if (obj.y)
				curtop += obj.y;
			return curtop;
		},
		
		FindElementPosX: function(obj) 
		{
			var curleft = 0;
			if (obj.offsetParent) 
			{
				while (obj.offsetParent) 
					{
						curleft += obj.offsetLeft
						obj = obj.offsetParent;
					}
				}
				else if (obj.x)
					curleft += obj.x;
				return curleft;
		}


	}

	//initialize main Object             
	Aspacts.Script.Utils.InlineWin.System = new Aspacts.Script.Utils.InlineWin.System_class()

//** END Aspacts.Script.Utils.InlineWin.System_class *********//      


/*************************************************************

	Name: Aspacts.Script.Utils.InlineWin.WindowItem_class
	Description: Class representing window objects. When opening 
		a new window, an instance of this class is created and acts 
		as a reference for furhter window manipulation 
	Public functions: 
		- Close
		- SetTitle
		- AddButton
		- GetButton
	Author: Coen Hoogstede
	Date: 28-September-2006

**************************************************************/
	
	/**
	*	Name: WindowItem_class (Constructor)
	* Description: Creates a new window-instance
	* Remarks: Internal method, not to be called directly. Called by System_class in OpenWindow
	* Parameters: 
	* 	- windowSystem: reference to calling System_class
	*		- intZIndex: depth of window in document, also used to set id of window
	*		- strUrl: the url to be opened in the window
	*		- strName: name for the window-item (optional)
	*		- intWidth: width in pixels for the window, including header and footer (optional, default: 800)
	*		- intHeight: height in pixels for the window, including header and footer (optional, default: 600)
	**/
	Aspacts.Script.Utils.InlineWin.WindowItem_class = function(windowSystem, intZIndex, strUrl, strName, intWidth, intHeight)
	{            
			this.windowSystem = windowSystem 
			this.intId = intZIndex
			this.intZIndex = intZIndex  
			this.strUrl = strUrl
			if (this.strName != null)        
				this.strName = strName
			if (intWidth != null)
				this.intWidth = intWidth
			if (intHeight != null)
			  this.intHeight = intHeight
			this.Initialize()
	}                                                                                 
	    
	// prototype
	Aspacts.Script.Utils.InlineWin.WindowItem_class.prototype = {
	    
	    //attributes                                                      
			strName: '',
			strUrl: '', 
			intId: 0,    
			windowSystem: null,
			intWidth: 800,
			intHeight: 600,
			strTitle: '',
			refElement: null,
			refTitleElement: null,   
			intZIndex:0,  
			buttonCollection: new Array(),
			OnClose: null,
	    
	    /**
			*	Name: Initialize
			* Description: Initializes a newly created window
			* Remarks: Internal method, not to be called directly. 
			* Parameters: (none)
			**/
			Initialize: function()
	    {                   
	    	//create DOM-elements
	    	this.InitializeElement()
	    	
	    	//set basic style elements for layer
	    	this.refElement.style.position = "absolute"
	    	this.refElement.style.zIndex= this.intZIndex
	    	this.refElement.style.width = this.intWidth+1 + "px"
	    	this.refElement.style.height = this.intHeight+1 + "px"
	    	this.refElement.style.top = "0px"
	    	this.refElement.style.left = "0px"  
	    	
	    	this.refBackgroundFrame.style.position="absolute" 
			//this.refBackgroundFrame.style.width=this.intWidth + "px"
			//this.refBackgroundFrame.style.height=this.intHeight + "px"
			
			
			this.refBackgroundFrame.style.zIndex="10000"
			this.refBackgroundFrame.style.margin="0" 
			this.refBackgroundFrame.style.padding="0" 
			
			this.refElement2.style.position = "absolute"
	    	
	    	this.refElement2.style.width = this.intWidth-2 + "px"
	    	this.refElement2.style.height = this.intHeight-2 + "px"
	    	
	    	//trigger size-adjustment  	
	    	this.ResetSize()
	    },
			                           
			/**
			*	Name: InitializeElement
			* Description: Initializes the DOM-structure for the new window
			* Remarks: Internal method, not to be called directly. 
			* Parameters: (none)
			**/
			InitializeElement: function()
			{
					//create base element
					this.refElement = document.createElement("div")
					this.refElement.className = "container"
					
					this.refBackgroundFrame = document.createElement("iframe")
					this.refBackgroundFrame.frameBorder="0"
					this.refElement.appendChild(this.refBackgroundFrame)
					this.refElement.style.border="solid 0px black"
					
					
					this.refBackgroundFrame.style.position="absolute" 
					this.refBackgroundFrame.style.width="100%" 
					this.refBackgroundFrame.style.height="100%" 
					this.refBackgroundFrame.style.zIndex="10000"
					this.refBackgroundFrame.style.margin="0" 
					this.refBackgroundFrame.style.padding="0" 
					
					this.refBackgroundFrame.style.display = "block";
    				//this.refBackgroundFrame.style.backgroundColor = "black";

					
					this.refElement2 = document.createElement("div")
					this.refElement.appendChild(this.refElement2)
					
				//this.refElement2.className = "container"
					this.refElement2.style.position="absolute" 
					this.refElement2.style.width="100%" 
					this.refElement2.style.height="100%" 
					this.refElement2.style.margin="0" 
					this.refElement2.style.padding="0" 
					this.refElement2.style.zIndex="10001"
						this.refElement2.style.border="solid 0px black"
					
					
						
					
					//create header
					/*<div class="container">
						<div class="header"><span class="title alignLeft"><h3>Locatie toevoegen</h3></span>
							<span class="closeButton alignRight"><button name="" class="btnDefault close" 
									title="Venster sluiten"><span>Venster sluiten</span></button></span>
						</div>
					*/                                
					
					this.refHeader = document.createElement("div")
					this.refElement2.appendChild(this.refHeader)
					this.refHeader.className = "subHeader"    
					this.refHeader.style.zIndex = "12000"    
					this.refHeader.style.backgroundColor = "#d8d8d8"    
					
					refTitleContainer = document.createElement("span")
					this.refHeader.appendChild(refTitleContainer)
					refTitleContainer.className = "title alignLeft"
					
					this.refTitleElement = document.createElement("h3")
					refTitleContainer.appendChild(this.refTitleElement) 
					
					headerButtonContainer = document.createElement("span")
					this.refHeader.appendChild(headerButtonContainer)
					headerButtonContainer.className = "closeButton alignRight"
					
					buttonClose = document.createElement("button")
					buttonClose.refWindow = this
					headerButtonContainer.appendChild(buttonClose)
					
					buttonClose.className="btnDefault close"
					buttonClose.title = "Venster sluiten"				
					Aspacts.Script.Utils.Core.ImplementEvent(buttonClose)
					buttonClose.addEventListener('click', function(){this.refWindow.ButtonClose()}, true);
					
					buttonLabel = document.createElement("span")
					buttonClose.appendChild(buttonLabel)
					buttonLabel.appendChild(document.createTextNode("Venster sluiten"))
					
					
	
					//create main formelement
					/*
					<div class="formTable">
						<iframe width="100%" border="0" src="http://www.nu.nl" />
					</div>
					*/   
					
						this.refContent = document.createElement("div")
						this.refElement2.appendChild(this.refContent)
						this.refContent.className="formContent"
						this.refContent.style.zIndex = "12000"    
					
						
					if (this.strUrl != "")
					{
						this.refContentFrame = document.createElement("iframe")
						this.refContentFrame.frameBorder="0" //frameBorder MUST be set prior to adding item to DOM
						
						this.refContent.appendChild(this.refContentFrame)  
						
						
						this.refContentFrame.width="100%"
						this.refContentFrame.height="100%"
						this.refContentFrame.style.width="100%"
						this.refContentFrame.style.height="100%"
						this.refContentFrame.style.borderWidth="0px"
						
						this.refContentFrame.src=this.strUrl 
						this.refContentFrame.refWindow = this
					}
					else
					{
						this.refContentFrame = document.createElement("div")
						this.refContent.appendChild(this.refContentFrame)  
						this.refContentFrame.width="100%"
						this.refContentFrame.height="100%"
						this.refContentFrame.style.width="100%"
						this.refContentFrame.style.height="100%"
						this.refContentFrame.style.borderWidth="0px"
						
						this.refContentFrame.refWindow = this
					}
					this.refContentFrame.focus()
					//from underlying page use window.frameElement.refWindow to address this class					
					
					//create footer
					/*
						<div class="formFooter">
							<!--<div class="contSelitems"></div>-->
							<div class="contPageIndex">
								<button name="" class="search" title="contactpersoon toevoegen">
								<span>Opslaan</span></button>
								<button name="" class="search" title="contactpersoon toevoegen"><span>Annuleren</span></button>
							</div>
						</div>	
					*/	 
					this.refFooter = document.createElement("div")
					this.refElement2.appendChild(this.refFooter)
					this.refFooter.className="formFooter"
					
					this.refFooterText = document.createElement("span")
					this.refFooter.appendChild(this.refFooterText)
					this.refFooterText.className="formFooterText"
					
					
					this.refFooterContent = document.createElement("div")
					this.refFooter.appendChild(this.refFooterContent)
					this.refFooterContent.className="contPageIndex"
					document.body.insertBefore(this.refElement, document.body.firstChild)
					
			},
			
			/**
			*	Name: ResetSize
			* Description: Sets the size for the iframe-element within the window
			* Remarks: Internal method, not to be called directly. 
			* Parameters: (none)
			**/
			ResetSize: function()
			{
				var intFrameSpace = 0
				intFrameSpace += this.refFooter.offsetHeight
				intFrameSpace += this.refHeader.offsetHeight 
				
				this.refContentFrame.style.width = "10px"
				this.refContentFrame.style.height = "10px"
				this.refContent.style.width = this.intWidth;
				this.refFooter.style.width = this.intWidth-10;
				this.refHeader.style.width = this.intWidth;
				this.refContent.style.height =Math.max( ((this.intHeight - intFrameSpace)-4), 0) + "px"
				
				
				this.refElement.style.width = this.intWidth+1 + "px"
	    		this.refElement.style.height = this.intHeight+1 + "px"
	    		this.refElement2.style.width = this.intWidth-2 + "px"
	    		this.refElement2.style.height = this.intHeight-2 + "px"
			
				this.refContentFrame.style.width = "100%"
				this.refContentFrame.style.height = "100%"
				
			},
			
			/**
			*	Name: ResetPosition
			* Description: Sets the position of the window according to the browser's size and 
			*		scroll values
			* Remarks: Internal method, not to be called directly. 
			* Parameters: 
			*		- intBrowserWidth: width of the browserwindow
			*		- intBrowserHeight: height of the browserwindow
			*		- intOffsetLeft: horizontal offset, influenced by scrolling the main page
			*		- intOffsetTop: vertical offset, influenced by scrolling the main page
			**/
			ResetPosition: function(intBrowserWidth, intBrowserHeight, intOffsetLeft, intOffsetTop)
			{
				var intOldWidth = this.intWidth
				var intOldHeight = this.intHeight
				if (!this.altWidth)
				{
					this.altWidth = this.intWidth
				}
				if (!this.altHeight)
				{
					this.altHeight = this.intHeight
				}
				
				this.intWidth = this.altWidth
				this.intHeight = this.altHeight
				
				intBrowserHeight = intBrowserHeight-40
				if (this.intWidth > (intBrowserWidth-20))
				{
					//this.intWidth = Math.max(intBrowserWidth-20, 0)
				}
				if (this.intHeight > intBrowserHeight)
				{
					this.intHeight = Math.max(intBrowserHeight, 0)
				}
			
				var intPosLeft = Math.max((intBrowserWidth - this.intWidth) / 2, 0) + intOffsetLeft
				var intPosTop = Math.max((intBrowserHeight - this.intHeight) / 2, 0) + intOffsetTop
				
				this.refElement.style.left = intPosLeft + "px"
				this.refElement.style.top = intPosTop + "px"
				this.refElement.style.width = this.intWidth + "px"
	    		this.refElement.style.height = this.intHeight + "px"
	    		
	    		if (intOldWidth != this.intWidth || intOldHeight != this.intHeight)
	    			  this.ResetSize()
	    	
			},  
			
			ButtonClose: function(strReturnValue)
			{
				this.Close(strReturnValue)
			},
			
			/**
			*	Name: Close
			* Description: Closes the window
			* Parameters: (none)
			**/
			Close: function(strReturnValue)
			{
				this.refElement.parentNode.removeChild(this.refElement);			
				this.windowSystem.CloseWindow(this.intId);
				
				if (this.OnClose != null)
				{
					this.OnClose(strReturnValue)
				}
			},
					
			/**
			*	Name: SetTitle
			* Description: Sets the title in the header of the window
			* Parameters: 
			*		- strTitle: The title to be set in the window
			**/
			SetTitle: function(strTitle)
			{
				 this.strTitle = strTitle 
				 
				 while (this.refTitleElement.childNodes[0]) {
				    this.refTitleElement.removeChild(this.refTitleElement.childNodes[0]);
					}
	 
				 this.refTitleElement.appendChild(document.createTextNode(this.strTitle))
			}, 
			
			/**
			*	Name: SetTitleNodes
			* Description: Sets the title in the header of the window
			* Parameters: 
			*		- strTitle: The title to be set in the window
			**/
			SetTitleNodes: function(TitleNodes)
			{
				 
				 while (this.refTitleElement.childNodes[0]) {
				    this.refTitleElement.removeChild(this.refTitleElement.childNodes[0]);
					}
				  
				 for(var i = 0; i< TitleNodes.length;i++)
				 {
					this.refTitleElement.appendChild(TitleNodes[i])
				 } 
				 
			}, 
			
			ClearFooterText: function(strMessage)
			{
				while(this.refFooterText.childNodes.length > 0)
				{
					this.refFooterText.removeChild(this.refFooterText.childNodes[0])
				}
				this.refFooterText.style.display = "none"
			},
			
			SetFooterText: function(strMessage)
			{
				this.ClearFooterText()
				this.refFooterText.style.display = ""
				this.refFooterText.appendChild(document.createTextNode(strMessage))
					
					
			},
			
			/**
			*	Name: AddButton
			* Description: Adds a new button to the footer of the window
			* Parameters: 
			*		- strReference: a reference name for the button
			*		- strLabel: the label for the button
			*		- strTitle: title-tag for the button
			*		- refActionFunction: reference to javascript-method executed on click. 
			*			if the string "CloseWindow" is passed, the button will act as a close-button for the window
			*		- boolEnabled: initiale state of the button
			*	Returns: DOM-element of type button
			**/			                           
			AddButton: function(strReference, strLabel, strTitle, refActionFunction, boolEnabled, strClassName)
			{
				/*	<button name="" class="search" title="contactpersoon toevoegen">
				<span>Opslaan</span></button>*/
				
				var refNewButton = document.createElement("button")	 
				this.refFooterContent.appendChild(refNewButton)
				if (strClassName)
					refNewButton.className = strClassName
				else
					refNewButton.className = "search"	 
				refNewButton.title = strTitle
				refNewButton.id = "winBtn" + this.intId + "_" + strReference
				refNewButton.refWindow = this
				var refLabel = document.createElement("span")
				refNewButton.appendChild(refLabel)
				
				refLabel.appendChild(document.createTextNode(strLabel))

				if (refActionFunction == "CloseWindow")
				{
					Aspacts.Script.Utils.Core.ImplementEvent(refNewButton)
					refNewButton.addEventListener('click', function(){this.refWindow.Close()}, true);			
				}
				else
				{
					refNewButton.onclick = refActionFunction
				}
				
				if (!boolEnabled)
					refNewButton.disabled = true
				
				this.buttonCollection[this.buttonCollection.length] = refNewButton			
				return refNewButton				
				
			},
			
			
			ClearButtons: function()
			{
				for(var i=0; i< this.buttonCollection.length; i++)
				{
					try
					{
					this.buttonCollection[i].parentNode.removeChild(this.buttonCollection[i])
						
					}
					catch(err)
					{
					}
				}
				this.buttonCollection = new Array()
			},
			 
			/**
			*	Name: GetButton
			* Description: Returns a button by searching for it's reference name
			* Parameters: 
			*		- strReference: the reference name for the button to be returned
			*	Returns: DOM-element of type button
			**/		
			GetButton: function(strReference)
			{      
				for(var i=0; i<this.buttonCollection.length; i++)
				{
					if (this.buttonCollection[i].id == "winBtn" + this.intId + "_" + strReference)
					{
						return this.buttonCollection[i]
					}
				}    
				return null
			},
			        
			/**
			*	Name: ResizeTo
			* Description: Sets the size of the window
			* Parameters: 
			*		- intWidth: the new width of the window
			*		- intHeight: the new height
			**/			        
			ResizeTo: function(intWidth, intHeight)
			{
				this.intWidth = intWidth;
				this.intHeight = intHeight;
				this.altWidth = intWidth
				this.altHeight = intHeight
				this.ResetSize()
				this.windowSystem.HandleResize()
				
			},
			
			RenderMessage: function(strMessage)
			{
				this.refContentFrame.appendChild(document.createTextNode(strMessage))
			}
	}

	Aspacts.Script.Utils.InlineWin.WindowLoading_class = function(windowSystem, intZIndex, strName, intWidth, intHeight, windowNodes)
	{            
			this.windowSystem = windowSystem 
			this.intId = intZIndex
			this.intZIndex = intZIndex  
			if (this.strName != null)        
				this.strName = strName
			if (intWidth != null)
				this.intWidth = intWidth
			if (intHeight != null)
			  this.intHeight = intHeight
			this.Initialize(windowNodes)
	}                                                                                 
	
	Aspacts.Script.Utils.InlineWin.WindowLoading_class.prototype = {
	    
	    //attributes                                                      
			strName: '',
			intId: 0,    
			windowSystem: null,
			intWidth: 800,
			intHeight: 600,
			strTitle: '',
			refElement: null,
			refTitleElement: null,   
			intZIndex:0,  
			buttonCollection: new Array(),
			OnClose: null,
			
	    
	    /**
			*	Name: Initialize
			* Description: Initializes a newly created window
			* Remarks: Internal method, not to be called directly. 
			* Parameters: (none)
			**/
			Initialize: function(windowNodes)
	    {                   
	    	//create DOM-elements
	    	this.InitializeElement(windowNodes)
	    	
	    	//set basic style elements for layer
	    	this.refElement.style.position = "absolute"
	    	this.refElement.style.zIndex= this.intZIndex
	    	this.refElement.style.width = this.intWidth+1 + "px"
	    	this.refElement.style.height = this.intHeight+1 + "px"
	    	this.refElement.style.top = "0px"
	    	this.refElement.style.left = "0px"  
	    	
	    	this.refBackgroundFrame.style.position="absolute" 
			//this.refBackgroundFrame.style.width=this.intWidth + "px"
			//this.refBackgroundFrame.style.height=this.intHeight + "px"
			
			
			this.refBackgroundFrame.style.zIndex="10000"
			this.refBackgroundFrame.style.margin="0" 
			this.refBackgroundFrame.style.padding="0" 
		  	
	    	//trigger size-adjustment  	
	    	this.ResetSize()
	    },
			                           
			/**
			*	Name: InitializeElement
			* Description: Initializes the DOM-structure for the new window
			* Remarks: Internal method, not to be called directly. 
			* Parameters: (none)
			**/
			InitializeElement: function(windowNodes)
			{
				//create base element
					this.refElement = document.createElement("div")
					document.body.insertBefore(this.refElement, document.body.firstChild)
					this.refElement.className = "container"
					
					
					this.refBackgroundFrame = document.createElement("iframe")
					this.refBackgroundFrame.frameBorder="0"
					this.refElement.appendChild(this.refBackgroundFrame)
					this.refElement.style.border="solid 0px black"
					
					this.refBackgroundFrame.style.position="absolute" 
					this.refBackgroundFrame.style.width="100%" 
					this.refBackgroundFrame.style.height="100%" 
					this.refBackgroundFrame.style.zIndex="10000"
					this.refBackgroundFrame.style.margin="0" 
					this.refBackgroundFrame.style.padding="0" 
					
					this.refBackgroundFrame.style.display = "block";
    				//this.refBackgroundFrame.style.backgroundColor = "black";


	
					this.refElement2 = document.createElement("div")
					this.refElement.appendChild(this.refElement2)
					
				//this.refElement2.className = "container"
					this.refElement2.style.position="absolute" 
					this.refElement2.style.width="100%" 
					this.refElement2.style.height="100%" 
					this.refElement2.style.margin="0" 
					this.refElement2.style.padding="0" 
					this.refElement2.style.zIndex="10001"
					this.refElement2.style.border="solid 1px black"
					
					
					for (var i = 0; i< windowNodes.length; i++)
					{
						this.refElement2.appendChild(windowNodes[i])
					}
					
			},
			
			ResetSize: function()
			{
				var intFrameSpace = 0
				
				this.refElement.style.width = this.intWidth+1 + "px"
	    		this.refElement.style.height = this.intHeight+1 + "px"
	    
				
				
			},
			
			/**
			*	Name: ResetPosition
			* Description: Sets the position of the window according to the browser's size and 
			*		scroll values
			* Remarks: Internal method, not to be called directly. 
			* Parameters: 
			*		- intBrowserWidth: width of the browserwindow
			*		- intBrowserHeight: height of the browserwindow
			*		- intOffsetLeft: horizontal offset, influenced by scrolling the main page
			*		- intOffsetTop: vertical offset, influenced by scrolling the main page
			**/
			ResetPosition: function(intBrowserWidth, intBrowserHeight, intOffsetLeft, intOffsetTop)
			{
			
				var intPosLeft = Math.max((intBrowserWidth - this.intWidth) / 2, 0) + intOffsetLeft
				var intPosTop = Math.max((intBrowserHeight - this.intHeight) / 2, 0) + intOffsetTop
				
				this.refElement.style.left = (intPosLeft-17) + "px"
				this.refElement.style.top = intPosTop + "px"
				this.refElement.style.width = this.intWidth + "px"
	    		this.refElement.style.height = this.intHeight + "px"
	    	
			},  
			
			
			ButtonClose: function(strReturnValue)
			{
				this.Close(strReturnValue)
			},
			/**
			*	Name: Close
			* Description: Closes the window
			* Parameters: (none)
			**/
			Close: function(strReturnValue)
			{
				this.refElement.parentNode.removeChild(this.refElement);			
				this.windowSystem.CloseWindow(this.intId);
				
				if (this.OnClose != null)
				{
					this.OnClose(strReturnValue)
				}
			},
					
			/**
			*	Name: SetTitle
			* Description: Sets the title in the header of the window
			* Parameters: 
			*		- strTitle: The title to be set in the window
			**/
			SetTitle: function(strTitle)
			{
				
			}, 
			
			/**
			*	Name: SetTitleNodes
			* Description: Sets the title in the header of the window
			* Parameters: 
			*		- strTitle: The title to be set in the window
			**/
			SetTitleNodes: function(TitleNodes)
			{
			
			}, 
			
			/**
			*	Name: AddButton
			* Description: Adds a new button to the footer of the window
			* Parameters: 
			*		- strReference: a reference name for the button
			*		- strLabel: the label for the button
			*		- strTitle: title-tag for the button
			*		- refActionFunction: reference to javascript-method executed on click. 
			*			if the string "CloseWindow" is passed, the button will act as a close-button for the window
			*		- boolEnabled: initiale state of the button
			*	Returns: DOM-element of type button
			**/			                           
			AddButton: function(strReference, strLabel, strTitle, refActionFunction, boolEnabled)
			{
				
			},
			
			
			ClearButtons: function()
			{
				for(var i=0; i< this.buttonCollection.length; i++)
				{
					this.buttonCollection[i].parentNode.removeChild(this.buttonCollection[i])
				}
				this.buttonCollection = new Array()
			},
			 
			/**
			*	Name: GetButton
			* Description: Returns a button by searching for it's reference name
			* Parameters: 
			*		- strReference: the reference name for the button to be returned
			*	Returns: DOM-element of type button
			**/		
			GetButton: function(strReference)
			{      
			
			},
			        
			/**
			*	Name: ResizeTo
			* Description: Sets the size of the window
			* Parameters: 
			*		- intWidth: the new width of the window
			*		- intHeight: the new height
			**/			        
			ResizeTo: function(intWidth, intHeight)
			{
			
				
			},
			
			RenderMessage: function(strMessage)
			{
				
			}
	}
   

//** END Aspacts.Script.Utils.InlineWin.WindowItem_class *********//      
             

