/**
 * @version			1.0.5 - 10 juli 2008
 * 
 * @copyright		1.0.5, 10 juli 2008,	Jan Niemantsverdriet,	Er kan nu ook worden aangegeven of de balk in de top getoond moet worden
 * @copyright		1.0.4, 8 juli 2008,		Jan Niemantsverdriet,	Minimale hoogte voor de popup is nu ook instelbaar
 * @copyright		1.0.3, 7 juli 2008,		Jan Niemantsverdriet,	Kleine visuele verbeteringen
 * @copyright		1.0.2, 4 juli 2008,		Jan Niemantsverdriet,	Popups werken in FF, IE7 en IE6
 * @copyright		1.0.1, 2 juli 2008,		Jan Niemantsverdriet,	Positie in pixels wordt nu afgerond
 * @copyright		1.0.0, 1 juli 2008,		Jan Niemantsverdriet,	Gemaakt
 * 
 * @copyright	afhankelijkheid:	BB/JSDivers/check.js
 * @copyright	afhankelijkheid:	BB/JSDivers/DOM.js
 * @copyright	afhankelijkheid:	BB/JSDivers/layers.js
 * @copyright	afhankelijkheid:	BB/JSDivers/screen.js
 * @copyright	afhankelijkheid:	BB/JSDivers/popup.css
 * @copyright	afhankelijkheid:	BB/JSDivers/layer.css
 */

/** 
 * construtor
 * 
 * @param string a_sInnerHTML			de html in de popup
 * @param string a_sId					de id voor de popup			
 */
function cPopup(a_sInnerHTML, a_sId) {
	if (!bIsDefined(a_sId)) a_sId = "screen" + iScreenCounter;
	this._sInnerHTML = a_sInnerHTML;
	this._sClassName = "CpPopup";
	this._sId = a_sId;
	this._bClose = true;
	this._bCloseOnClick = false;
	iScreenCounter++;
	this.iMinWidth = 200;
	this.iMinHeight = 0;
	this.bShowBar = true;
}

cPopup.prototype = new cScreen();

cPopup.prototype.vToScreen = function() {
	if (!this.bIsOnScreen()) {
		oLayer = oAddLayer(this._sId + "_layer", this._bCloseOnClick);
		oScreen = document.createElement('div');
		oScreen.className = this._sClassName;
		oScreen.id = this._sId;
		if (this.bShowBar) {
			oBar = document.createElement('div');
			oBar.className = 'screenTopBar';
			oBar.innerHTML = 	'<a href="javascript:bRemoveLayer(\'' + oLayer.id + '\')" alt="Sluit dit venster">' +
								'<img src="/cms/beheer/images/popupbarclose.gif" alt="Sluit dit venster" />' +
								'</a>';
			oScreen.appendChild(oBar);
		}
		oInner = document.createElement('div');
		oInner.className = 'popupInnerDiv';
		oInner.id = this._sId + "_inner";
		oInner.innerHTML = this._sInnerHTML;
		oInner.id = this._sId + '_inner';
		oScreen.style.left = (screen.width + 10) + "px";
		oScreen.style.top = "0px";
		oScreen.appendChild(oInner);
		oLayer.appendChild(oScreen);
		aViewPort = aGetViewPortDimensions();
		iScreenWidth = aViewPort[0];
		iScreenHeight = aViewPort[1];
		if (oInner.offsetHeight < this.iMinHeight) oInner.style.height = this.iMinHeight + "px";
		var iHorMargin = (this.bShowBar ? 50 : 20); 
		if (oInner.offsetHeight > (iScreenHeight - iHorMargin)) oInner.style.height = (iScreenHeight - iHorMargin) + "px";
		if (oInner.offsetWidth < this.iMinWidth) oInner.style.width = this.iMinWidth + "px";
		if (oInner.offsetWidth > (iScreenWidth - 30)) oInner.style.width = (iScreenWidth - 30) + "px";
		oScreen.style.width = (oInner.offsetWidth + 5) + "px";
		oScreen.style.left = Math.round((iScreenWidth / 2) - (oScreen.offsetWidth / 2)) + "px";
		oScreen.style.top = Math.round((iScreenHeight / 2) - (oScreen.offsetHeight / 2) + iGetBodyScrollPosition()) + "px";
		if (this.bShowBar) {
			var iCorrection = ((bCheckBrowser("Microsoft Internet Explorer", "5.5", "6.9")) ? 0 : -2);
			oBar.style.width = (oScreen.offsetWidth + iCorrection) + "px";
		}
	}
}

/**
 * Stelt de minimale breedte in van het binnen div waar de daadwerkelijk html in komt
 * 
 * @param integer a_iMinWidth		de minimale breedte in pixels
 */
cPopup.prototype.vSetMinWidth = function(a_iMinWidth) {
	this.iMinWidth = a_iMinWidth;
}

/**
 * Stelt de minimale hoogte in van het binnen div waar de daadwerkelijke html in komt
 * 
 * @param integer a_iMinHeight		de minimale hoogte in pixels
 * @since 1.0.4 - 8 juli 2008
 */
cPopup.prototype.vSetMinHeight = function(a_iMinHeight) {
	this.iMinHeight = a_iMinHeight;
}

/**
 * Geeft aan of de balk bovenaan de popup getoond moet worden
 * 
 * @param boolean a_bShow			true = balk tonen, false = balk niet tonen
 * @since 1.0.5 - 10 juli 2008
 */
cPopup.prototype.vSetShowBar = function(a_bShow) {
	this.bShowBar = a_bShow;
}