function popups_class() {
		this.childWindows=new Array();
		this.childWindowNdx=0;

		this.open=function (url, name, width, height, left, top, features) {
			width=width || 300;
			height=height || 350;
			var pos=this.getPosition(width, height);
			left=left || pos.left;
			top=top || pos.top;
			features= features==null ? "menubar=no,location=no," : 
								features=="" ? features : features+",";
			var w=window.open(url, name || "_blank", features+"width="+width+",height="+height+",top="+top+",left="+left);
			this.childWindows[name || this.childWindowNdx++]=w;
			w.focus();
			return w;
		}
		
		this.closeAll=function () {
			if (this.childWindows.length>1)
			{
				for (var i=0,len=this.childWindows.length;i<len;i++) if (this.childWindows[i] && !this.childWindows[i].closed) this.childWindows[i].close();
			}
		}
		
		this.theModalWindow=null;
		
		this.openModal=function (url, callback, name, width, height, left, top, features) {
			if (this.theModalWindow && !this.theModalWindow.closed) return false;
			this.opening=true;
			this.theModalWindow=this.open(url, name, width, height, left, top, features);

			if (window.event) {
				cancelBubble(window.event);
				cancelEvent(window.event);
			}
			
			var me=this;
			var func=function (event) {me.modalCheck(event)};
			this.modalCallback=callback;
			
			this.doc_onclick=window.document.onclick;
			if (window.event)	window.document.onclick=func;
			this.win_onclick=window.onclick;
			if (window.event)	window.onclick=func;

			this.win_onfocus=window.onfocus;
			window.onfocus=func;
			if (typeof(Event)!='undefined' && window.captureEvents) window.captureEvents(Event.FOCUS);
			
			return this.theModalWindow;
		}
		
		this.modalCheck=function (event) {
			if (!event) event=window.event;
			if (this.theModalWindow && !this.theModalWindow.closed) {
				window.document.onclick=this.doc_onclick;
				window.onclick=this.win_onclick;
				if (typeof(Event)!='undefined' && window.releaseEvents) window.releaseEvents(Event.FOCUS);
				window.onfocus=this.win_onfocus;
				this.theModalWindow.close();
			}
		}

						
		this.getPosition=function (width,height) {
			var ret=new Object();
			ret.left=((getInnerWidth() - width)>>1);
			ret.top=((getInnerHeight() - height)>>1);
			return ret;
		}
		
		this.closeModal=function (ret) {
			this.theModalWindow.close();
			window.focus();
			if (this.modalCallback)	this.modalCallback(ret);
		}		
}

var popups=new popups_class();
function closeModal(ret) {
	popups.closeModal(ret);
}

myAttachEvent(window, "unload",	function () {popups.closeAll()});
