/**
 * P.I.C.S. JS Framework 5.0.0 - window extension
 * Copyright(c) 2009 P.I.C.S. EDV GmbH
 * http://www.pics.co.at
 * 
 * @author Ing. Christian Grösswang
 * 
 * 20100413,gc - v5.00.00		initial defintion based on pics.windows v1.03
 * 20100730,gc - v5.00.01		added params for pics.Windows.load
 */

/**
 * @class pics.Tabs
 * function for tab-management
 * @singleton
 */
pics.Windows = {
    		version 		: 	'5.0.0'			//* @type {String}	version of the framework
			,list			:	new Array()		//* @type {Array}	list of managed windows
			,active			:	''				//* @type {String}	name of the active window
			,dragElement	:	null			//* @type {Object}	element for drag&drop
			,maxLevel		:	100				//* @type {Int}		level of the top-element
		};	// pics.Windows
			


	/**
	 * pics.Windows.closeWindow
	 *		close a window by the given ID 
	 *		@param 	{String}	pWindowName 		name of the window
	 *		@param	{Int}		pID 				window-ID in the list
	 */
	pics.Windows.closeWindow = function(pWindowName, pID)
	{
		if (pics.isUndefined(pWindowName)) 		pWindowName='';
		if (pWindowName == '') 					pWindowName=pics.Windows.list[pID];
		
		// hide the window
		pics.Windows.list[pWindowName].hide();
		// if destroy is set, remove window
		if (pics.Windows.list[pWindowName].destroyOnClose) 
		{
			pics.Windows.list[pWindowName].destroy();
			delete(pics.Windows.list[pWindowName]);
		} // if
	}; // pics.Windows.close


	/**
	 * pics.Windows.addWindow
	 *		add a new window in the list
	 *		@param 	{String}	pWindowName 		name of the window
 	 *		@return	{Object}	the new created window
	 */
	pics.Windows.addWindow = function(pWindowName)
	{
		// if no name is given, create one out of the timestamp
		if (pics.isUndefined(pWindowName))
		{
			var lNow=new Date();
			pWindowName='win_'+lNow.getTime();
		}
	
		// create window and add to list
		var oWin=new pics.Windows.Window(pWindowName);
		pics.Windows.list[pWindowName]	=oWin;
		pics.Windows.list[oWin.id]		=pWindowName;
		return oWin;
	}; // pics.Windows.addWindow

	/**
	 * pics.Windows.getWindow
	 * 		return the window according to the name
	 *		@param 	{String}	pWindowName 		name of the window
 	 *		@return	{Object}	the window-object or null if not exists
	 */
	pics.Windows.getWindow = function(pWindowName)
	{
		if (!pics.Windows.list[pWindowName]) return null;
		return pics.Windows.list[pWindowName];
	}; // pics.Windows.getWindow

	/**
	 * pics.Windows.hideWindow
	 *		hide the window
	 *		@param 	{String}	pWindowName 		name of the window
	 *		@param	{Int}		pID 				window-ID in the list
	 */
	pics.Windows.hideWindow = function(pWindowName, pID)
	{
		if (pics.isUndefined(pWindowName)) 		pWindowName='';
		if (pWindowName == '') 					pWindowName=pics.Windows.list[pID];
		pics.Windows.list[pWindowName].hide();
	}; //pics.Windows.hideWindow

	/**
	 * pics.Windows.showWindow
	 *		show a window
	 *		@param 	{String}	pWindowName 		name of the window
	 *		@param	{Int}		pID 				window-ID in the list
	 */
	pics.Windows.showWindow = function(pWindowName, pID)
	{
		if (pics.isUndefined(pWindowName)) 		pWindowName='';
		if (pWindowName == '') 					pWindowName=pics.Windows.list[pID];
		pics.Windows.list[pWindowName].show();
	}; // pics.Windows.showWindow

	/**
	 * pics.Windows.isActive
	 *		check if this is the active window
	 *		@param 	{String}	pWindowName 		name of the window
	 *		@return	{Bool}		
	 */
	pics.Windows.isActive = function(pWindowName)
	{
		if (pics.Windows.active==pWindowName) return true;
		return false;
	}; // pics.Windows.isActive


	/**
	 * pics.Windows.activate
	 *		activate a window, if necessary deactivate the lase
	 *		@param 	{String}	pWindowName 		name of the window
	 */
	pics.Windows.activate = function(pWindowName)
	{
		// do we have an old window
		if (pics.Windows.active!='') 	pics.Windows.hideWindow(pics.Windows.active);
		pics.Windows.active	=	pWindowName;
		pics.Windows.showWindow(pWindowName);
		return false;
	}; // pics.Windows.activate

	/**
	 * pics.Windows.load
	 *		load the content of the given panel/window
	 *		@param 	{Mixed}		pElement 		Element/ID of the panel/window
	 *		@param 	{String}	pParams 		optional parameters for load
	 */
	pics.Windows.load = function(pElement, pParams)
	{
		if (pics.isUndefined(pParams)) 		pParams='';

		// get the reference to the panel/window
		var oWin			=	pics.obj(pElement);
		
		// get the params for url and refresh if they exists
		if (!oWin.attributes['url']) return false;
		var lUrl=oWin.getAttribute('url')+pParams;
		var lRefresh=0;
		if (oWin.attributes['refresh']) lRefresh=oWin.getAttribute('refresh');
		
		// find the content-container
		var oContent=pics.findByName(oWin, 'panel_content', true);
		if (!oContent) return false;
		
		// show loading animation
		pics.setHTML(oContent,'<div class="p-wins-loading32">loading ...</div>');
		
		// load the content
		pics.Ajax.request(lUrl, '*PJR:EXTRA', "GET", '', oContent);

		// if we need a refresh, add a time
		if (lRefresh>0) var lTimer=window.setTimeout("pics.Windows.load('"+pElement+"')", lRefresh);
		return true;		
	}; // pics.Windows.load

/* 
 * ==================================================================================================================
 * 		default event handler
 * ==================================================================================================================
 */

	/**
	 * pics.Windows.closeButton
	 *		close the window according to the close-button 
	 *		@param 	{Object}	pButton 		this-reference of the button
	 */
	pics.Windows.closeButton = function(pButton)
	{
		if (pics.isUndefined(pButton)) 		return;
		
		// find the parent window-object and get the name
		var oWin=pics.findParent(pButton,"TABLE");
		var lName=pics.Windows.list[oWin.getAttribute('name')];
		// hide the window
		pics.Windows.list[lName].hide();
		// if destroy is set, remove window
		if (pics.Windows.list[lName].destroyOnClose) 
		{
			pics.Windows.list[lName].destroy();
			delete(pics.Windows.list[lName]);
		} // if
	}; // pics.Windows.closeButton
	


/* 
 * ==================================================================================================================
 * 		drag & drop helper-functions
 * ==================================================================================================================
 */

	/**
	 * pics.Windows.dragStart
	 *		start drag
	 *		@param	{Event}	pEvent	Event-Object
	 *		@return	{Bool}	
	 */
	pics.Windows.dragStart = function(pEvent)
	{
		// check if drag & drop is enabled
		if (!this.parentObject.dragEnable) return false;
	
		// get current positions
   		var lMouseX = (pEvent) ? pEvent.pageX : event.clientX + document.body.scrollLeft;
		var lMouseY = (pEvent) ? pEvent.pageY : event.clientY + document.body.scrollTop;
		
		var lWinX = this.parentObject.window.offsetLeft;
		var lWinY = this.parentObject.window.offsetTop;
		
		// remember current position
		this.parentObject.dragX=lMouseX - lWinX;
		this.parentObject.dragY=lMouseY - lWinY;

		pics.Windows.dragElement = this.parentObject;

		// now put element on the top
		if (this.parentObject.window.style.zIndex!=pics.Windows.maxLevel)
		{
			pics.Windows.maxLevel++;
			this.parentObject.window.style.zIndex=pics.Windows.maxLevel;
		} // if
		
		// set the eventhandlers for move / drop
		document.onmousemove 	= pics.Windows.dragMove;
		document.onmouseup 		= pics.Windows.dragStop;
	}; // pics.Windows.dragStart
	
	/**
	 * pics.Windows.dragMove
	 *		move the window according to the mouse while dragging
	 *		@param	{Event}	pEvent	Event-Object
	 */
	pics.Windows.dragMove = function(pEvent)
	{
   		var lMouseX = (pEvent) ? pEvent.pageX : event.clientX + document.body.scrollLeft;
		var lMouseY = (pEvent) ? pEvent.pageY : event.clientY + document.body.scrollTop;
		if(pics.Windows.dragElement!=null) 
		{
			pics.Windows.dragElement.window.style.left 	= (lMouseX - pics.Windows.dragElement.dragX) + "px";
			pics.Windows.dragElement.window.style.top 	= (lMouseY - pics.Windows.dragElement.dragY) + "px";
		}
	}; // pics.Windows.dragMove

	/**
	 * pics.Windows.dragStop
	 *		stop the drag & drop
	 *		@param	{Event}	pEvent	Event-Object
	 */
	pics.Windows.dragStop = function(pEvent)
	{
		pics.Windows.dragElement = null;
	};	// pics.Windows.dragStop
		
/* 
 * ==================================================================================================================
 * 		OBJECT : pics.Windows.Window
 * ==================================================================================================================
 */
	
	/**
	 * pics.Windows.Windows
	 *		constructor for a new window-object
	 */
	pics.Windows.Window = function(pWindowName) 
	{
		// create a unique id, we use the time for this
		var lNow=new Date();
		this.id=lNow.getTime();
		this.name=pWindowName;
	
		
		pics.Windows.maxLevel++;
		this.window			=	null;	// reference to the outer div
		this.level			=	pics.Windows.maxLevel;
		this.destroyOnClose	=	true;
		this.windowmodal	=	null;	// reference to the modal layer
		this.referer		=	null;	// element which has created the window
		
		// size of the window
		this.width			=	0;
		this.height			=	0;

		// properties for look & feel - set defaults
		this.showTitleBar		=	true;
		this.showCloseButton	=	true;
		this.classTitleBar		=	'p-win-head';
		this.classWindow		=	'';
		this.classContent		=	'';
		this.classButtons		=	'p-panel-buttons';
		this.classIFrame		=	'p-win-content-iframe';
		this.classModal			=	'p-win-modal';
	
		// properties for drag & drop
		this.dragX				=	0;
		this.dragY				=	0;
		this.dragEnable			=	true;
		
		// create title-bar
		this.titleBar = document.createElement("div");
		this.titleBar.setAttribute("height","100%");
		this.titleBar.setAttribute("width","100%");
			//this.titleBar.setAttribute("class",this.classTitleBar);
			//if (pics.isIE) this.titleBar.className=this.classTitleBar;
		
		// create content-container
		this.content = document.createElement("div");
		this.content.setAttribute("height","100%");
		this.content.setAttribute("width","100%");
			//this.content.setAttribute("class",this.classContent);
			//if (pics.isIE) this.content.className=this.classContent;
	
		// create button-container
		this.buttons = document.createElement("div");
		this.content.setAttribute("width","100%");
			this.buttons.setAttribute("class",this.classButtons);
			if (pics.isIE) this.buttons.className=this.classButtons;
	
		// set references to the objects
		this.titleBar.parentObject=this;
		
		// reset the timer for the window
		this.closeTimer=null;
	
	}; // pics.Windows.Window
	
	/**
	 * pics.Windows.Window.prototype.create
	 *		create the real window
	 *		@param	{Int}		pX			x-position of the window
	 *		@param	{Int}		pY			y-position of the window
	 *		@param	{Int}		pWidth		width
	 *		@param	{Int}		pHeight		height
	 *		@param	{String}	pContent	content
	 *		@param	{String}	pTitle		title
	 *		@param	{Bool}		pModal		show modal?
	 */
	pics.Windows.Window.prototype.create = function(pX, pY, pWidth, pHeight, pContent, pTitle, pModal)
	{
		// undefinierte Parameter vorbelegen
		if (pics.isUndefined(pX))		pX=0;
		if (pics.isUndefined(pY))		pY=0;
		if (pics.isUndefined(pWidth))	pWidth=200;
		if (pics.isUndefined(pHeight))	pHeight=0;
		if (pics.isUndefined(pContent))	pContent='';
		if (pics.isUndefined(pTitle))	pTitle='';
		if (pics.isUndefined(pModal))	pModal=false;
	
		// set dimensions
		this.width=pWidth;
		this.height=pHeight;
		
		// create element in DOM
		var oDiv = document.createElement("div");
	
		// for modal windows we move up 1000 levels
		if (pModal == true) this.level+=1000;
		
		// add scroll-position to window-position
		pX=pX+pics.getPageScrollX();
		pY=pY+pics.getPageScrollY();
		
		// set attributes
		oDiv.setAttribute("id","pics_Window_"+this.id);	
		oDiv.setAttribute("name",this.name);	

		// set style for firefox, see IE-workaround later
	    var lStyle="position: absolute; left: "+pX+"px; top: "+pY+"px; width: "+(pWidth+4)+"px; z-index:"+this.level+";";
		if (pHeight!=0) lStyle+=" height: "+(pHeight+20)+"px;";
		oDiv.setAttribute("style",lStyle);
		oDiv.setAttribute("class",this.classWindow!="" ? this.classWindow : "p-win");



		// workaround for IE - set the style in the DOM
		if (pics.isIE)
		{
			oDiv.style.position="absolute";
			oDiv.style.left=pX;
			oDiv.style.top=pY;
			oDiv.style.width=pWidth;
			if (pHeight!=0) oDiv.style.height=(pHeight+20);
			oDiv.style.zIndex=this.level;
			oDiv.className=this.classWindow;
		}

		// create the base window
		var lHtml='<table class="p-panel-table" width="'+this.width+'" name="'+this.id+'" cellpadding="0" cellspacing="0">\n';
		lHtml+='	<tr>\n';
		lHtml+='		<td class="p-panel-top-left"></td>\n';
		lHtml+='		<td class="p-panel-top-center" name="panel_title"></td>\n';
		lHtml+='		<td class="p-panel-top-right"></td>\n';
		lHtml+='	</tr>\n';
		lHtml+='	<tr>\n';
		lHtml+='		<td class="p-panel-left"></td>\n';
		lHtml+='		<td class="p-panel-center" name="panel_content" style="padding: 0px;"></td>\n';
		lHtml+='		<td class="p-panel-right"></td>\n';
		lHtml+='	</tr>\n';
		lHtml+='	<tr>\n';
		lHtml+='		<td class="p-panel-bottom-left"></td>\n';
		lHtml+='		<td class="p-panel-bottom-center"></td>\n';
		lHtml+='		<td class="p-panel-bottom-right"></td>\n';
		lHtml+='	</tr>\n';
		lHtml+='</table>\n';
		oDiv.innerHTML=lHtml;

		// do we have a title-bar
		if (this.showTitleBar)
		{
			var oTitle=pics.findByName(oDiv, 'panel_title', true);		
			this.titleBar.innerHTML=this.createTitleBar(pTitle);
			oTitle.appendChild(this.titleBar);
		}
		
		// find the content-container inside
		var oContentDiv=pics.findByName(oDiv, 'panel_content', true);		
		this.content.innerHTML=pContent;
		oContentDiv.appendChild(this.content);
		oContentDiv.appendChild(this.buttons);

		// if modal is set, we need a semitransparent background layer
		if (pModal == true)
		{
			var lWidth=Math.max(pics.getDocumentWidth(),pics.getScreenWidth());
			var lHeight=Math.max(pics.getDocumentHeight(),pics.getScreenHeight());

			var oModal = document.createElement("div");
			oModal.setAttribute("class",this.classModal);
		    var lStyle="width: "+lWidth+"px; height: "+lHeight+"px;";
			oModal.setAttribute("style",lStyle);
			if (pics.isIE)
			{
				oModal.className=this.classModal;
				oModal.style.width=lWidth;
				oModal.style.height=lHeight;
			}
			document.body.appendChild(oModal);
			this.windowmodal=oModal;
		} // if modal
		document.body.appendChild(oDiv);
		this.window=oDiv;
		
		// add event-handler for drag & drop ( not for modal windows )
		if (!pModal) this.titleBar.onmousedown = pics.Windows.dragStart;
	}; // pics.Windows.Window.prototype.create
	
	/**
	 * pics.Windows.Window.prototype.destroy
	 *		destroy the window
	 */
	pics.Windows.Window.prototype.destroy = function()
	{
		if (this.window) 		document.body.removeChild(this.window);
		if (this.windowmodal)	document.body.removeChild(this.windowmodal);
	}; // pics.Windows.Window.prototype.destroy
	
	/**
	 * pics.Windows.Window.prototype.setContent
	 *		add content to a window
	 *		@param	{String}	pContent	content
	 */
	pics.Windows.Window.prototype.setContent = function(pContent)
	{
		// set the content style 
		this.content.setAttribute("class",this.classContent);
		if (pics.isIE) this.content.className=this.classContent;
		// add the content
		this.content.innerHTML=pContent;
	}; // pics.Windows.Window.prototype.setContent
	
	/**
	 * pics.Windows.Window.prototype.loadContent
	 *		load content to a window
	 *		@param	{String}	pUrl	url where to load content from
	 */
	pics.Windows.Window.prototype.loadContent = function(pUrl)
	{
		if (pics.isUndefined(pUrl))			return false;

		// set the content style 
		this.content.setAttribute("class",this.classContent);
		if (pics.isIE) this.content.className=this.classContent;

		// show loading animation in the content
		pics.setHTML(this.content,'<div class="p-wins-loading32">loading ...</div>');

		pics.Ajax.request(pUrl, '*HTML:EXTRA', "POST", '', this.content);
		return true;
	}; // pics.Windows.Window.prototype.loadContent

	/**
	 * pics.Windows.Window.prototype.addButton
	 *		add a button to the window
	 *		@param	{String}	pButtonText		text on the button
	 *		@param	{String}	pButtonCode		javascript to execute on click
	 *		@param	{Boolean}	pRightAligned	right-align the button in the bar
	 *		@param	{String}	pButtonID		id of the button
	 */
	pics.Windows.Window.prototype.addButton = function(pButtonText, pButtonCode, pRightAligned, pButtonID)
	{
		if (pics.isUndefined(pButtonText))		pButtonText='OK';
		if (pics.isUndefined(pButtonCode))		pButtonCode="pics.Windows.closeButton(this);";
		if (pics.isUndefined(pRightAligned))	pRightAligned=false;
		if (pics.isUndefined(pButtonID))		pButtonID=false;
		
		var lHtml = '<div class="p-btn24" onclick="'+pButtonCode+'"';
		if (pRightAligned) lHtml += ' style="float:right"';
		if (pButtonID) lHtml += ' id="'+pButtonID+'"';
				lHtml += '>';
				lHtml += '<div class="p-btn-left"></div>';
				lHtml += '<div class="p-btn-center"><div class="p-btn-text">'+pButtonText+'</div></div>';
				lHtml += '<div class="p-btn-right"></div>';
			lHtml += '</div>';
		this.buttons.innerHTML=this.buttons.innerHTML+lHtml;
	}; // pics.Windows.Window.prototype.addButton

	/**
	 * pics.Windows.Window.prototype.setIFrame
	 *		add an iframe to the content
	 *		@param	{String}	pUrl			url to load in the iframe
	 *		@param	{String}	pScrolling		scrolling configuration
	 */
	pics.Windows.Window.prototype.setIFrame = function(pUrl, pScrolling)
	{
		if (pics.isUndefined(pScrolling))		pButtonText='Auto';
	
		// set the content style
		this.content.setAttribute("class",this.classIFrame);
		if (pics.isIE) this.content.className=this.classIFrame;
		// add iframe
		this.content.innerHTML='<iframe src="'+pUrl+'" width="'+this.width+'" height="'+this.height+'" frameborder="0" scrolling="'+pScrolling+'"></iframe>';
	}; // pics.Windows.Window.prototype.setIFrame
	
	/**
	 * pics.Windows.Window.prototype.createTitleBar
	 *		create the content of the titlebar
	 *		@param	{String}	pTitle			title for the window
	 */
	pics.Windows.Window.prototype.createTitleBar = function(pTitle)
	{
		var lHtml="";
		lHtml +='	<div class="p-panel-title" style="float:left">'+pTitle+'</div>';
		lHtml +='	<div class="p-tb p-tb-close" style="float:right" onclick="pics.Windows.closeButton(this)"></div>';
		return lHtml;
	};	// pics.Windows.Window.prototype.createTitleBar
	
	/**
	 * pics.Windows.Window.prototype.hide
	 *		hide the window
	 */
	pics.Windows.Window.prototype.hide = function()
	{
		// reset the timer if exists
		if (this.closeTimer!=null)
		{
			window.clearTimeout(this.closeTimer);
			this.closeTimer=null;
		}
		
		// hide window 
		this.window.style.visibility='hidden';
		if (this.windowmodal) this.windowmodal.style.visibility='hidden';
	};	// pics.Windows.Window.prototype.hide
	
	/**
	 * pics.Windows.Window.prototype.show
	 *		show the window
	 */
	pics.Windows.Window.prototype.show = function()
	{
		// pics.backupScroll();
		this.window.style.visibility='';
		if (this.windowmodal) this.windowmodal.style.visibility='';
		// pics.restoreScroll();
	}; // pics.Windows.Window.prototype.show

	/**
	 * pics.Windows.Window.prototype.move(pX, pY)
	 *		move window to the given position
	 *		@param	{Int}	pX 		X-position
	 *		@param	{Int}	pY 		Y-position
	 */
	pics.Windows.Window.prototype.move = function(pX, pY)
	{
		if (pics.isUndefined(pX))		pX=-9999;
		if (pics.isUndefined(pY))		pY=-9999;

		if (pX>-9999) this.window.style.left	=	pX+'px';
		if (pY>-9999) this.window.style.top		=	pY+'px';

	};	// pics.Windows.Window.prototype.move
	
	
/* 
 * ==================================================================================================================
 * 		predefined window types
 * ==================================================================================================================
 */	


	/**
	 * pics.Windows.infoBox
	 *		create a new infobox
	 *		@param 	{String}	pWindowName 		name of the window
	 */
	pics.Windows.infoBox = function(pWindowName)
	{
		// if no name is given, create one out of the timestamp
		if (pics.isUndefined(pWindowName))
		{
			var lNow=new Date();
			pWindowName='win_'+lNow.getTime();
		}
	
		// create the window
		var oWin=new pics.Windows.Window();
		// set the infobox-options
		oWin.showTitleBar	=	false;
//		oWin.classWindow	=	'pics_InfoBoxWindow';
//		oWin.classContent	=	'pics_InfoBoxContent';
//		oWin.classButtons	=	'pics_InfoBoxButtonContainer';

		// set the styles for content and buttons
		oWin.content.setAttribute("class",oWin.classContent);
		if (pics.isIE) oWin.content.className=oWin.classContent;
		oWin.buttons.setAttribute("class",oWin.classButtons);
		if (pics.isIE) oWin.buttons.className=oWin.classButtons;
		
		// add to list
		pics.Windows.list[pWindowName]	=	oWin;
		pics.Windows.list[oWin.id]		=	pWindowName;
		return oWin;
	}; // pics.Windows.infoBox
	
	
	/**
	 * pics.Windows.alert
	 *		create a new alert as special type of infobox
	 *		@param 	{String}	pMessage 		content of the window
	 *		@param 	{String}	pTitle 			title of the window
	 */
	pics.Windows.alert = function(pMessage,pTitle) {
		if (pics.isUndefined(pTitle)) pTitle="Hinweis!";
		var oAlert=pics.Windows.infoBox();
		oAlert.showTitleBar=true;
		oAlert.create(400,200,250,0,'loading ...',pTitle,true);
		oAlert.setContent(pMessage);			
		oAlert.addButton("OK");
	};


	/**
	 *	function pics.Windows.lightbox(pUrl, pWidth, pHeight)
	 *		show a remote page as lightbox
	 *		@param 	{String}	pUrl 		url for the content
	 *		@param 	{Int}		pWidth 		width
	 *		@param 	{Int}		pHeight 	height
	 */
	pics.Windows.lightbox = function(pUrl, pWidth, pHeight)
	{
		if (pics.isUndefined(pWidth))	pWidth=500;
		if (pics.isUndefined(pHeight))	pHeight=400;
	
		// definitions
		var lWindowID='picsLightbox';
		var lTotalWidth		=	window.innerWidth 	|| document.body.clientWidth;
		var lTotalHeight	=	window.innerHeight 	|| document.body.clientHeight;
		var lX	=	(lTotalWidth-pWidth)/2;
 		var lY	=	(lTotalHeight-pHeight)/2;
		// check if window already exists
		var oWin=pics.Windows.getWindow(lWindowID);
		if (oWin==null)
		{
			// create new window
			oWin=pics.Windows.addWindow(lWindowID);
			oWin.create(lX, lY, pWidth, pHeight, "", "", true);
		}
		else
		{
//			var oWin=pics.Windows.getWindow(lWindowID);
			oWin.show();
		} // else
		oWin.setIFrame(pUrl);
		pics.Windows.activate(lWindowID);
	}; // pics.lightbox


	/**
	 * pics.Windows.msgBox
	 *	Neue Msgbox erstellen
	 *		@param 	{String}	pText 		text for the messagebox
	 *		@param 	{Bool}		pModal 		show modal
	 *		@param 	{Bool}		pButton 	show the OK-button
	 *		@param 	{Int}		pAutoClose 	close msgbox automatic after x seconds
	 */
	pics.Windows.msgBox = function(pText, pModal, pButton, pAutoClose)
	{
		if (pics.isUndefined(pModal)) 		pModal=true;
		if (pics.isUndefined(pButton)) 		pButton=true;
		if (pics.isUndefined(pAutoClose)) 	pAutoClose=0;

		// basic definition
		var lWidth=400;
		var lHeight=400;
		
//		var lTotalWidth		=	window.innerWidth 	|| document.body.clientWidth;
//		var lTotalHeight	=	window.innerHeight 	|| document.body.clientHeight;
		var lTotalWidth		=	pics.getScreenWidth();
		var lTotalHeight	=	pics.getScreenHeight();
		var lX	=	(lTotalWidth-lWidth)/2;
 		var lY	=	(lTotalHeight-lHeight)/2;

		var oWin=pics.Windows.addWindow();
		// format
		oWin.showTitleBar	=	false;
//		oWin.classWindow	=	'pics_InfoBoxWindow';
//		oWin.classContent	=	'pics_InfoBoxContent';
//		oWin.classButtons	=	'pics_InfoBoxButtonContainer';
		// add content style
		oWin.content.setAttribute("class",oWin.classContent);
		if (pics.isIE) 		oWin.content.className=oWin.classContent;
		
		// add button style
		oWin.buttons.setAttribute("class",oWin.classButtons);
		if (pics.isIE) 		oWin.buttons.className=oWin.classButtons;

		// create window
		oWin.create(lX, lY, lWidth, 0, pText, '', pModal);

		// add button
		if (pButton) 		oWin.addButton("OK");

		// add to list
		var lName='msgbox_'+oWin.id;
		pics.Windows.list[lName]		=	oWin;
		pics.Windows.list[oWin.id]		=	lName;

		// show
		oWin.show();

		// create timer for autoclose
		if (pAutoClose>0) 	oWin.closeTimer=window.setTimeout("pics.Windows.closeWindow('"+lName+"')", pAutoClose*1000);
		
		return oWin;
	};	// pics.Windows.msgBox
		
