function DialogBox()
{
	this.topWindow = window;
	
	while (this.topWindow.parent && this.topWindow.parent != this.topWindow) {
		try
		{
			if (this.topWindow.parent.document.domain != document.domain) break;
			if (this.topWindow.parent.document.getElementsByTagName('frameset').length > 0) break;
		}
		catch ( e )
		{
			break ;
		}
		this.topWindow = this.topWindow.parent;
	}

	this.topDocument = this.topWindow.document;
	
	this.createLayerOverlay();
}

DialogBox.prototype = {
	topWindow: null,
	topDocument: null,
	
	layer_overlay: null,
	overlay_opacity: 50,
	
	layer_box: null,
	box_left: 0,
	box_top: 0,
	box_width: 0,
	box_height: 0,
	box_title: '',
	box_url: '',
	box_content: '',
	box_btn_ok: '',
	box_btn_ok2: '',
	box_btn_cancel: '',
	box_event_ok: null,
	box_event_ok2: null,
	box_refresh_content: null,
	box_close_dialog: null,
	box_styles: [],
	
	show : function(title, width, height) {
		this.box_title = title;
		this.box_width = width;
		this.box_height = height;
		
		if (this.box_width > this.GetViewportWidth()) this.box_width = this.GetViewportWidth();
		if (this.box_height > this.GetViewportHeight()) this.box_height = this.GetViewportHeight();
		
		this.layer_overlay.style.display = "block";
		
		this.createLayerBox();
		
		dim = this.GetBoxCenter(this.box_width, this.box_height);
		this.box_left = dim.left;
		this.box_top = dim.top;
		
		this.layer_box.style.left = ""+dim.left+"px";
		this.layer_box.style.top = ""+dim.top+"px";
		this.layer_box.style.width = ""+this.box_width+"px";
		this.layer_box.style.height = ""+this.box_height+"px";
	},
	
	hide : function() {
		this.layer_box.parentNode.removeChild(this.layer_box);
		this.layer_overlay.style.display = "none";
	},
	
	createLayerBox : function() {
		var d = this.topDocument.getElementById("DialogBoxLayerBox20081218181503");
		if (d) d.parentNode.removeChild(d);
		
		this.layer_box = this.topDocument.createElement('IFRAME');
		this.layer_box.id = "DialogBoxLayerBox20081218181503";
		this.layer_box.style.margin = "0";
		this.layer_box.style.padding = "0";
		this.layer_box.style.border = "0";
		this.layer_box.style.backgroundColor = "transparent";
		this.layer_box.style.backgroundImage = "none";
		this.layer_box._DialogBox = this;
		this.layer_box.src = PATH_ABSOLUTE + 'include/dialog/basedialog.html';
		this.layer_box.frameBorder = 0;
		this.layer_box.allowTransparency = true;
		this.layer_box.style.position = "absolute";
		this.layer_box.style.zIndex = "20000";
		
		this.topDocument.body.appendChild(this.layer_box);
	},
	
	createLayerOverlay : function() {
		d = this.topDocument.getElementById("DialogBoxLayerOverLay20081218181503");
		if (d) {
			this.layer_overlay = d;
			return;
		}
		
		dim = this.GetPageSize();
		
		this.layer_overlay = this.topDocument.createElement('DIV');
		this.layer_overlay.id = "DialogBoxLayerOverLay20081218181503";
		this.layer_overlay.style.position = "absolute";
		this.layer_overlay.style.left = "0";
		this.layer_overlay.style.top = "0";
		this.layer_overlay.style.width = ""+dim.width+"px";
		this.layer_overlay.style.height = ""+dim.height+"px";
		this.layer_overlay.style.zIndex = "19000";
		this.layer_overlay.style.backgroundColor = "#fff";
		this.layer_overlay.style.opacity = ""+(this.overlay_opacity/100);
		this.layer_overlay.style.filter = "alpha(opacity="+this.overlay_opacity+")";
		this.layer_overlay.style.display = "none";
		
		this.topDocument.body.appendChild(this.layer_overlay);
	},
	
	GetPageSize : function() {
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			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;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth) windowWidth = document.documentElement.clientWidth; 
			else 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;
		}	
		
		// 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 = xScroll;
		else pageWidth = windowWidth;
		
		return {width: pageWidth, height: pageHeight};
	},
	
	GetViewportWidth : function()
	{
		return (webkit && !document.evaluate) ? 
				self['innerWidth'] :
				((opera || ie) && !ie7) ? 
					document.body['clientWidth'] : 
					document.documentElement['clientWidth'];
	},
	GetViewportHeight : function()
	{
		return (webkit && !document.evaluate) ? 
				self['innerHeight'] :
				((opera || ie) && !ie7) ? 
					document.body['clientHeight'] : 
					document.documentElement['clientHeight'];
	},
	GetScrollOffsetsTop : function()
	{
		return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
	},
	GetScrollOffsetsLeft : function()
	{
		return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
	},
	GetBoxCenter : function(width, height)
	{
		return {
			left: this.GetScrollOffsetsLeft() + (this.GetViewportWidth()-width)/2, 
			top: this.GetScrollOffsetsTop() + (this.GetViewportHeight()-height)/2
		};
	}
};
