// constants
DIALOG_LAYOUT_HTML = '\
<table class="InlinePopup">\
		<tr>\
			<td class="InlinePopup_Top">\
				<table class="Maxed">\
					<tr>\
						<td class="InlinePopup_Top_First">&nbsp;</td>\
						<td class="InlinePopup_Top_Center" id="InlinePopup_Title">\
							Popup Title\
						</td>\
						<td class="InlinePopup_Top_Last">\
							<div>\
								<a href="javascript:document.ZL_inlinePopup.close()">\
									close\
								</a>\
							</div>\
						</td>\
					</tr>\
				</table>\
			</td>\
		</tr>\
		<tr>\
			<td class="InlinePopup_Body">\
				<table class="Maxed">\
					<tr>\
						<td class="InlinePopup_Body_First">&nbsp;</td>\
						<td class="InlinePopup_Body_Center" id="InlinePopup_Body">\
							&nbsp;\
						</td>\
						<td class="InlinePopup_Body_Last">&nbsp;</td>\
					</tr>\
				</table>\
			</td>\
		</tr>\
		<tr class="InlinePopup_Bottom">\
			<td>\
				<table class="Maxed">\
					<tr>\
						<td class="InlinePopup_Bottom_First">&nbsp;</td>\
						<td class="InlinePopup_Bottom_Center">&nbsp;</td>\
						<td class="InlinePopup_Bottom_Last">&nbsp;</td>\
					</tr>\
				</table>\
			</td>\
		</tr>\
	</table>\
	';

ARGUMENTS = 
{
	"type" 		: "html", // "iframe"
	"url"		: "strUrl",
	"innerhtml"	: "strHTML",
	"title"		: "strTitle"
};

function inlinePopup()
{
	// Defaut Values
	this.type = "iframe";
	this.url = "about:blank";
	this.innerhtml = "";
	this.title = "Popup";
	this.callback = function(){
		void(0);
	}
	this.popupWrapper= document.createElement("DIV");
	this.popupWrapper.className = "PopupWrapper";
	this.dialogTransparency = document.createElement("DIV");
	this.dialogTransparency.className = "PopupTransparency";
	this.dialogTransparency.style.height = document.body.scrollHeight+"px";
	this.dialogTransparency.style.width = document.body.scrollWidth+"px";
	this.popupWrapper.appendChild(this.dialogTransparency);
	document.body.appendChild(this.popupWrapper);
	this.popupBackground = document.createElement("TABLE");
	//this.popupBackground.border = "1";
	this.popupWrapper.appendChild(this.popupBackground);
	this.popupBackground.className = "PopupBackground";
	this.popupBackground.insertRow(0);
	this.popupBox = this.popupBackground.rows[0].insertCell(0);
	this.close = function()
	{
		if(document.ZL_inlinePopup!=null)
		{
			if(document.ZL_inlinePopup.callback != null)
			{
				try{
					document.ZL_inlinePopup.callback(document.ZL_inlinePopup.dialog.returnValue);
				}catch(e){
					
				}
			}
			window.onresize = null;
			window.onscroll = null;
			document.ZL_inlinePopup.popupWrapper.parentNode.removeChild(document.ZL_inlinePopup.popupWrapper);
			document.ZL_inlinePopup = null;
		}
	};
	if(document.ZL_inlinePopup!=null)
	{
		document.ZL_inlinePopup.close();
	}
	for(param in arguments[0])
	{
		this[param] = arguments[0][param];
	}
	document.ZL_inlinePopup = this;
	window.onresize = function()
	{
		document.ZL_inlinePopup.dialogTransparency.style.height = document.body.scrollHeight+"px";
		document.ZL_inlinePopup.dialogTransparency.style.width = document.body.scrollWidth+"px";
		document.ZL_inlinePopup.positionIt();
	};
	window.onscroll = function()
	{
		try {
			document.ZL_inlinePopup.positionIt();
		}catch(e) {};
	};
	this.positionIt = function()
	{
		oDialog = document.ZL_inlinePopup;
		switch(oDialog.type)
		{
			case "iframe":
				oDialog.dialogWidth = oDialog.dialogDocument.body.scrollWidth;
				oDialog.dialogHeight = oDialog.dialogDocument.body.scrollHeight;
			break;
			case "html":
				oDialog.dialogWidth = oDialog.dialogDocument.offsetWidth;
				oDialog.dialogHeight = oDialog.dialogDocument.offsetHeight;
			break;
		}
		oDialog.dialogLeft = document.body.clientWidth/2 - oDialog.dialogWidth/2;
		oDialog.dialogTop = document.body.clientHeight/2 + document.body.scrollTop - oDialog.dialogHeight/2;
		/**/
		oDialog.dialog.style.position = "absolute";
		/*oDialog.dialog.style.top = "10px";
		oDialog.dialog.style.left = "10px";*/
		/**/
		oDialog.dialog.style.height = oDialog.dialogHeight;
		oDialog.dialog.style.width = oDialog.dialogWidth;
		oDialog.dialog.style.top = oDialog.dialogTop + "px";
		oDialog.dialog.style.left = oDialog.dialogLeft + "px";
		oDialog.dialog.style.zIndex = "500";
		oDialog.dialog.style.visibility = "visible";
	};
	switch(this.type)
	{
		case "html":
			this.dialog = document.createElement("DIV");
			this.dialog.className = "inlinePopup_Wrapper";
			this.dialog.innerHTML = DIALOG_LAYOUT_HTML;
			this.dialogDocument = this.dialog.firstChild;
			this.popupBox.appendChild(this.dialog);
			this.dialogTitle = document.getElementById("InlinePopup_Title");
			this.dialogBody = document.getElementById("InlinePopup_Body");
			this.dialogTitle.innerHTML = this.strTitle;
			this.dialogBody.innerHTML = this.innerhtml;
			this.positionIt();
		break;
		case "iframe":
			this.dialog = document.createElement("IFRAME");
			this.dialog.wrapper = this;
			this.dialog.className = "inlinePopup_Wrapper";
			this.dialog.scrolling = "no";
			this.dialog.allowTransparency = "true";
			this.dialog.src = this.url;
			this.popupBox.appendChild(this.dialog);
			this.loadFunction = function()
				{
					oDialog = document.ZL_inlinePopup;
					oDialog.dialogDocument = oDialog.dialog.contentWindow.document;
					if(oDialog.dialogDocument.body) {
						oDialog.dialogDocument.body.className = "Popup";
						//CloseButtonBox = oDialog.dialogDocument.getElementById("Container_Header_Last");
						//ContainerBody = oDialog.dialogDocument.getElementById("Container_Body_Inner");
						//if(ContainerBody.currentStyle)
						//{
						//	ContainerBody.style.display = "block";
						//}
						//CloseButtonBox.innerHTML = "<div><a href='javascript:window.parent.document.ZL_inlinePopup.close()'>close</a></div>";
						oDialog.positionIt();
					}
				};
			this.dialog.onload = this.loadFunction;
			if(this.dialog.readyState != null)
			{
				this.dialog.onreadystatechange = function()
				{
					if(this.readyState == "complete" && this.currentStyle.visibility != "hidden")
					{
						this.wrapper.loadFunction();
					}
				}
			}
		break;
	};
	this.dialog.id = "ZL_inlinePopup";
	//this.dialog.style.visibility = "hidden";
}