function isPopup (sTexts, sPopupID)
{
	this.Background = null;
	this.Popup		= null;
	this.Title		= null;
	this.Content	= null;
	this.Controls	= null;
	this.cbFunction	= null;
	this.cbObject	= null;
	this.cbParams	= null;
	this.sPopupID	= "";
	this.visible	= false;
	this.tabTags	= new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");
	this.tabIndexes	= new Array();
	this.sTextOK	= "";
	this.sTextCancel= "";
	this.sTextClose	= "";

	if(sPopupID != undefined && sPopupID != "") {
		this.sPopupID = sPopupID;
	} else {
		this.sPopupID = "";
	}

	this.Background = document.getElementById("popBackground" + this.sPopupID);
	this.Popup		= document.getElementById("popWindow" + this.sPopupID);
	this.Title		= document.getElementById("m_POPUP" + this.sPopupID + "_head");
	this.Frame		= document.getElementById("modulContent_POPUP" + this.sPopupID);
	this.Content	= document.getElementById("popContent" + this.sPopupID);
	this.Controls	= document.getElementById("popControls" + this.sPopupID);

	this.registerEvent(window, 'resize');
	this.registerEvent(window, 'scroll');

	if (sTexts != "") {
		aTexts = sTexts.split("|");
		if (aTexts.length > 0) {
			this.sTextOK	= aTexts[0];
			this.sTextCancel= aTexts[1];
			this.sTextClose	= aTexts[2];
		}
	}
}

isPopup.prototype = {
	registerEvent : function(target,type,args)
	{
		var self = this;

		if (target.addEventListener) target.addEventListener(type,onEvent,true);
		else if (target.attachEvent) target.attachEvent('on'+type,onEvent);

		function onEvent(e)
		{
			e = e||window.event;
			e.element = target;
			return self["on"+type](e, args);
		}
	}
	,
	show : function(sControls, title, width, height, sHTML, cbObject, cbFunction, cbParams)
	{
		this.visible = true;
		this.disableTabs();
		this.hideSelectBoxes();

		/* padding for content */
		var padding = 5;

		/* width for border of the box */
		var BorderWidth = 1;

		var TitleHeight = 33;

		// create callback function
		if(cbObject != "")		this.cbObject	= cbObject;
		if(cbFunction != "")	this.cbFunction	= cbFunction;
		if(cbParams != "")		this.cbParams	= cbParams;

		/* create HTML for controls of the popup*/
		var sHTMLControls = '';
		var sBtnOK		= '<button style="width:50px;" class="FormButton" onclick="document.popup.hide(true);">' + this.sTextOK + '</button>';
		var sBtnCancel	= '<button style="width:90px;" class="FormButton" onclick="document.popup.hide(false);">' + this.sTextCancel + '</button>';
		var sBtnClose	= '<button style="width:90px;" class="FormButton" onclick="document.popup.hide(true);">' + this.sTextClose + '</button>';
		switch (sControls) {
			case ("OK"):
				sHTMLControls = sBtnOK;
				break;
			case ("CANCEL"):
				sHTMLControls = sBtnCancel;
				break;
			case ("OKCANCEL"):
				sHTMLControls = sBtnOK;
				sHTMLControls += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				sHTMLControls += sBtnCancel;
				break;
			case ("CLOSE"):
				sHTMLControls = sBtnClose;
				break;
		}

		aPageSize = this.getPageSize();
		this.Background.style.width		= aPageSize[0] + "px";
		this.Background.style.height	= aPageSize[1] + "px";

		this.Background.style.display	= "block";
		this.Popup.style.display		= "block";
		var ControlsHeight				= parseInt(this.Controls.offsetHeight, 10);
		var calcWidth					= (width - (2*padding) - (2*BorderWidth));
		this.Popup.style.width			= width + "px";
		this.Popup.style.height			= (height + 20) + "px";
		this.Frame.style.width			= calcWidth + "px";
		this.Frame.style.height			= (height - TitleHeight) + "px";
		this.Content.style.width		= calcWidth + "px";
		this.Content.style.height		= (height - ControlsHeight - TitleHeight) + "px";
		this.Controls.style.width		= calcWidth + "px";
		this.Title.innerHTML			= title;
		this.Controls.innerHTML			= sHTMLControls;
		this.Content.innerHTML			= sHTML;
		this.center();
	}
	,
	hide : function(doCallback)
	{
		this.visible = false;
		this.restoreTabs();
		this.showSelectBoxes();

		if (this.Background == null) return;
		this.Background.style.display	= "none";
		this.Popup.style.display		= "none";
//		this.Title.innerHTML			= "";
//		this.Content.innerHTML			= "";

		//callback function
		if (doCallback) {
			if(this.cbObject != null && typeof(this.cbObject.callBackFunction) == "function") {
				this.cbObject.callBackFunction(this.cbParams);
				//parent[this.cbObject][this.cbFunction](this.cbParams);
			}
			else if(this.cbObject == null && this.cbFunction != null) {
				parent[this.cbFunction](this.cbParams);
			}
		}
	}
	,
	hide_ajax : function()
	{
		this.visible = false;
		this.restoreTabs();
		this.showSelectBoxes();

		if (this.Background == null) return;
		this.Background.style.display	= "none";
		this.Popup.style.display		= "none";
	}
	,
	center : function(width, height)
	{
		if (this.visible == true) {
			if (width == null || isNaN(width)) {
				width = this.Popup.offsetWidth;
			}
			if (height == null) {
				height = this.Popup.offsetHeight;
			}

			var fullHeight	= this.getHeight();
			var fullWidth	= this.getWidth();
			var Body		= document.documentElement;
			var TitleHeight	= parseInt(this.Title.offsetHeight, 10);
			var Top			= 0;
			var Left		= 0;
			if(document.all) Top	= parseInt(Body.scrollTop,10);
			if(document.all) Left	= parseInt(Body.scrollLeft,10);

			var iCalcTop = Top + ((fullHeight - (height + TitleHeight)) / 2);
			if (iCalcTop < 0) {
				iCalcTop = 0;
			}

			this.Popup.style.top			= iCalcTop + "px";
			this.Popup.style.left			= Left + ((fullWidth - width) / 2) + "px";
		}
	},

	setBackgroundSize : function()
	{
		aPageSize = this.getPageSize();
		this.Background.style.width		= aPageSize[0] + "px";
		this.Background.style.height	= aPageSize[1] + "px";
	},

	setBackgroundWidth : function()
	{
		aPageSize = this.getPageSize();
		this.Background.style.width		= aPageSize[0] + "px";
	}

	,
	onresize : function(event, args)
	{
		this.center();
		this.setBackgroundSize();
	}
	,

	onscroll : function(event, args)
	{
		this.center();
		this.setBackgroundWidth();
	}
	,
	disableTabs: function()
	{
		if (document.all) {
			var i = 0;
			for (var j = 0; j < this.tabTags.length; j++) {
				var tagElements = document.getElementsByTagName(this.tabTags[j]);
				for (var k = 0 ; k < tagElements.length; k++) {
					this.tabIndexes[i] = tagElements[k].tabIndex;
					tagElements[k].tabIndex="-1";
					i++;
				}
			}
		}
	}
	,
	restoreTabs: function()
	{
		if (document.all) {
			var i = 0;
			for (var j = 0; j < this.tabTags.length; j++) {
				var tagElements = document.getElementsByTagName(this.tabTags[j]);
				for (var k = 0 ; k < tagElements.length; k++) {
					tagElements[k].tabIndex = this.tabIndexes[i];
					tagElements[k].tabEnabled = true;
					i++;
				}
			}
		}
	}
	,
	getHeight:function() {
		if (window.innerHeight!=window.undefined) return window.innerHeight;
		if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
		if (document.body) return document.body.clientHeight;
		return window.undefined;
	}
	,
	getWidth:function() {
		if (window.innerWidth!=window.undefined) return window.innerWidth;
		if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
		if (document.body) return document.body.clientWidth;
		return window.undefined;
	},

	getPageSize : function() {
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		//alert(xScroll + ", " + yScroll);

		var windowWidth, windowHeight;
		if (self.innerHeight) { // all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		//alert(windowWidth + ", " + windowHeight);

		// for small pages with total height less then height of the viewport
		if (yScroll < windowHeight) {
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if (xScroll < windowWidth) {
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}

		aPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
		return aPageSize;
	},

	alertSize : function()
	{
		var myWidth = 0, myHeight = 0;
		if ( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		//alert( 'Width = ' + myWidth + 'Height = ' + myHeight);
	},

	showSelectBoxes : function()
	{
		aSelects = document.getElementsByTagName("select");
		for (i = 0; i != aSelects.length; i++) {
			//Workaround for scw Datetimepicker in AdminProjects
			if (!(aSelects[i].id == "scwMonths" || aSelects[i].id == "scwYears" )) {
				aSelects[i].style.visibility = "visible";
			}
		}
	},

	hideSelectBoxes : function()
	{
		aSelects = document.getElementsByTagName("select");
		for (i = 0; i != aSelects.length; i++) {
			//Workaround for scw Datetimepicker in AdminProjects
			if (!(aSelects[i].id == "scwMonths" || aSelects[i].id == "scwYears" )) {
				aSelects[i].style.visibility = "hidden";
			}
		}
	}
}