function popupDiv(w,h,sb){
	this.w = w?w:1;
	this.h = h?h:1;
	this.ob = null;
	this.withSandBox = sb;
}

popupDiv.prototype = {
	
	show: function(cnt){	
		
		if(document.getElementById("popupDiv"))
			this.hide();
		
		this.ob = document.createElement("div");
		this.ob.innerHTML = cnt;
		this.ob.setAttribute("id","popupDiv");	
		
		var cs = this.getContentSize();
		this.w = cs[0];
		this.h = cs[1];		
		
		var coords = this.getCenterCoords();
		
		this.ob.className = "popup_div";
		this.ob.style.width = this.w;
		this.ob.style.height = this.h;
		this.ob.style.left = coords[0] + "px";
		this.ob.style.top = coords[1] + "px";
		
		/* sand background */
		if(this.withSandBox){
			var sb = document.createElement("div");
			sb.className = "sand_bg";
			sb.style.width = winsize_o.getFullWidth();
			sb.style.height = winsize_o.getFullHeight();
			sb.setAttribute("id","sandBg");
			document.body.appendChild(sb);
		}
		
		//document.body.style.overflow = 'hidden';				
		document.body.appendChild(this.ob);
		
	},
	
	hide: function(){
		if(this.ob)
			document.body.removeChild(this.ob);
		var sb = document.getElementById("sandBg");
		if(sb)
			document.body.removeChild(sb);		
		//document.body.style.overflow = 'auto';
	},
	
	resize: function(nw,nh){	
		
		var sz = this.getContentSize();		
		if(sz[0] && sz[1]){
			this.w = sz[0];
			this.h = sz[1];
			var nc = this.getCenterCoords();
			this.ob.style.width = this.w;
			this.ob.style.height = this.h;
			this.ob.style.left = nc[0];
			this.ob.style.top = nc[1];		
		}
		
	},
	
	getCenterCoords: function(){
		var l = winsize_o.leftOffset() + (winsize_o.getWidth() - this.w)/2;
		var t = winsize_o.topOffset() + (winsize_o.getHeight() - this.h)/2;
		return new Array(l,t);
	},
	
	getContentSize: function(){
		
		var sz = new Array(0,0);
		
		if(this.ob){
			var tt = this.ob.getElementsByTagName("table");
			for(i=0; i<tt.length; i++){
				if(tt[i].getAttribute("id") == "popup_content"){
					sz[0] = parseInt(tt[i].style.width);
					sz[1] = parseInt(tt[i].style.height);
					break;
				}
			}
		}
		
		return sz;
		
	}
	
}

var popupdiv_o = new popupDiv(1,1,true);