<!--
/*
	' /////////////////////////////////////////////////////////////////////////
	' Copyright (c) 1998-2005 Mobigator Technology Group.  ALL RIGHTS RESERVED.
	' 
	' Unauthorized use of any portion of the code below without prior written 
	' authorization of Mobigator Technology Group is straightly prohibited.
	' 
	' For licensing information, please contact info@mobigator.com
	'//////////////////////////////////////////////////////////////////////////
*/
//-->
var closebutton = "/images/close_window.gif";

var objPopup, xtra, ytra;

function setupLayer()
{
	if (event.button != 1)
		return ;

	objPopup = eval("popupLayer");
	temp1 = objPopup.style.posLeft;
	temp2 = objPopup.style.posTop;
	xpos = event.clientX;
	ypos = event.clientY;
	xtra = temp1 - xpos;
	ytra = temp2 - ypos;
	document.onmousemove = moveLayer;
}

function moveLayer()
{
	if (event.button == 1)
	{
		objPopup.style.pixelLeft = event.clientX + xtra;
		objPopup.style.pixelTop = event.clientY + ytra;
		return false;
	}
}

function ShowIWinAtCenter( title, url, width, height )
{
	var x, y
	x= (screen.width)?(screen.width-width)/2:100;
	y =5;
	x = x + document.body.scrollLeft;
	y = y + document.body.scrollTop ;		
	InlineWindowUtils.show( iwin_def, url, title, width, height, x, y );	
}

function showLayer(title, url, html, bgcolor, width, height, background)
{
	showLayerEx(title, url, html, bgcolor, width, height, background, true)
}


function showLayerEx(title, url, html, bgcolor, width, height, background, bShowScrollBar)
{
	titlecolor = "#333366";
	opacitytitle = 100;

	if (!width)
	{
		width = 500;
		height = 325;
	}

	if(url.length >=0) {

		/* Use resizeable inline window */
		if (bShowScrollBar)
			InlineWindowUtils.showAtCenter( iwin_def, url, title, width, height, '');
		else
			InlineWindowUtils.showAtCenterNoScroll( iwin_def, url, title, width, height, '');
		return;
	}
	else {
		inside = html;
	}

	if (!bgcolor) bgcolor = "#ccccff";
	
	popupLayer.style.pixelLeft = document.body.scrollLeft + 50;
	popupLayer.style.pixelTop = document.body.scrollTop + 50;
	popupLayer.style.visibility = "visible";

	var btn = "<td bgcolor='#ccccff' align=center>" + 
				"<input type='image' alt=\"Close\" onclick='closeLayer()' " + 
				" src='" + closebutton + "'></td>"
	
	output = "<table bgcolor=#333366 border=0 cellpadding=0 cellspacing=1 width=" + width + " height=" + height + "><tr>";

	output += btn;
	output +=
	"<td align=center onmousedown='setupLayer()' style='cursor:move' " + 
	" onmouseup='JavaScript:document.onmousemove=\"\" ' bgcolor='" + titlecolor + "' " + 
	" style='z-Index:100; position: relative; filter:alpha(opacity=" + opacitytitle + ");' " + 
	" width =" + width + " height=20>" + 
	"<b><font face='verdana, arial' color=white>" + title + "</font></b></td>";

	output += btn; 
	output += "</tr>";
	output += "<tr><td width=100% colspan=3><table ";

	if (background) {
		output += "style='background-image:url(\" " + background + "\")'";
	}

	output += " width=100% height=100% bgcolor='" + bgcolor +
	"'><tr><td height=100% width=100% >" + inside +
	"</td></tr></table></td></tr></table>";

	// if we are on a frame already, then reuse the frame instead of nesting another one
	if (window.parent.popupFrame) {
		window.parent.popupLayer.innerHTML = output;
		// window.parent.popupFrame.location.reload();
	}
	else {
		popupLayer.innerHTML = output;
		// window.popupFrame.location.reload();
	}
}

function closeLayer()
{
	popupLayer.style.visibility = "hidden";
}

function IsOnPopupLayer()
{
	return (window.name == "popupFrame") ;
}

function IsPopWindow()
{
	return (window.name == "popview");
}

function IsIWinLayer()
{
	return (window.name == "popupFrame_iwin");
}


function IsOnHiddenPopupLayer()
{
	var res = IsOnPopupLayer() && window.parent.popupLayer.style.visibility == "hidden"
	
	return res
}

function CloseMe()
{
	// close ext window if any
	if(parent.CloseExtWin)
	{
		parent.CloseExtWin();
		return true;
	}

	if (IsOnPopupLayer()) {
		// a popup layer
		window.parent.closeLayer();
		return true;
	}
	
	if (IsIWinLayer()){	
		window.parent.HideIWin();
		return true;
	}

	// if the user start the application in a popup window, then 
	// there is a possibility that the window.opener is set
	// checking window.name gives a bit more insurance that we are really on a popup window
	// all popups show start their name with "popup_"
	if (window.name.length > 0 && window.opener) { 
		// a popup browser
		try
		{
			window.opener.focus(); 
			window.close();
			return true;
		}catch (err)
		{
			//alert(err.description);
		}
	}
	return false;
}

function FindOpener()
{
	if (IsOnPopupLayer()) 
	{
		return window.parent;
	}
	
	if (IsIWinLayer())
	{
		return window.parent;
	}
	
	if (window.opener) {
		return window.opener;
	}
	
	if (window.parent) {
		return window.parent;
	}
}

function CloseMeOrGoBack()
{
	if (!CloseMe()) { 
		// if there are hidden frames, remove them, otherwise go(-1) will be executed by the frame
		RemoveAllIFrames();
		window.history.go(-1);
	}
	return true;
}

function IsOnHiddenFrame()
{
	return window.name.match("hidden") || window.name.match("cmd_frame")
}

function RemoveAllIFrames()
{
	var iframes = document.getElementsByTagName('IFRAME');
	while (iframes.length > 0)
	{
		iframes[iframes.length - 1].removeNode(true);
		iframes = document.getElementsByTagName('IFRAME');
	}
}

