var __zIndex = 100;

var Div = {
	showPopup: function(name, title, action, dimension){
		this.close('popup_'+name);
		var div = document.createElement('DIV');

		div.id				= 'popup_'+name;
		div.className 		= 'popupWindow';
		div.style.left 		= (f_clientWidth()-dimension.width)+'px';
		div.style.top		= '75px';

		div.style.width		= dimension.width;
		div.style.height	= dimension.height;
		div.style.zIndex	= __zIndex;

		var HTML  = '<table style="width: '+dimension.width+'px;border-collapse: collapse;"><tr style="height: 25px;background-color: blue;">';
		HTML	 += '<td style="text-align: left;color: white;font-weight: bold;">'+title+'</td>';
		HTML     += '<td style="text-align: right;padding-right: 5px;"><img style="cursor: hand;" src="<?php echo Config::ROOT.Config::IMG_CLOSE;?>" id="close" onClick="Div.close(\''+div.id+'\');" /></td>';
		HTML 	 += '</tr></table>';
		HTML     += '<div class="popupDiv" style="width: '+dimension.width+'px; height: '+dimension.height+'px;overflow: auto;" id="'+name+'" ></div>';

		div.innerHTML = HTML;

		this.createHiddenIFrame(div);
		document.body.appendChild(div);
		__zIndex ++;
		loadDivURL(name, action+'&currentDiv='+name);
	},

	createHiddenIFrame: function(div){
		var iframe = document.createElement('IFRAME');

		iframe.id = 'iframe_'+div.id;
		iframe.style.position = 'absolute';
		iframe.style.filter	= 'Alpha(Opacity: 0%);';
		iframe.style.left 	= div.style.left;
		iframe.style.top 	= div.style.top;
		iframe.style.width 	= div.style.width;
		iframe.style.height = div.style.height;
		iframe.style.zIndex = __zIndex-1;

		document.body.appendChild(iframe);
	},

	close: function(divName){
		if(div = $(divName)){
			Element.remove(div);
			if(iframe = $('iframe_'+div.id)){
				Element.remove(iframe);
			}
			if(div = $('popup_'+divName)){
				Element.remove(div);
				if(iframe = $('iframe_'+div.id)){
					Element.remove(iframe);
				}
			}
		}
	}
}
