

///////////////////
function ExitPopInit()
{
	var i = window.screenTop; 
	if ( i > 9000 ) // Close is always a big number.
	{
		if (typeof(OnClosePopunder) != "undefined")
			PopInit(OnClosePopunder);

		if (typeof(OnClosePopup) != "undefined")
			PopInit(OnClosePopup);
	}
}

///////////////////
function PopInit(PopArray)
{
	if (typeof(PopArray) != "undefined")
	{
		if (PopArray.length == 6)
		{
			LaunchWindow(PopArray[0], PopArray[1], PopArray[2], PopArray[3], PopArray[4], PopArray[5]);
		}
	}
}

///////////////////
function LaunchWindow(IsPopup, strURL, strName, intWidth, intHeight, strProperties) 
{
	CreateWindow(IsPopup, strURL, strName, intWidth, intHeight, strProperties);
	return false;
}

///////////////////
function CreateWindow(IsPopup, strURL, strName, intWidth, intHeight, strProperties)
{
	var mywin;
	var intVersion;
	var dummyDate = new Date(); 

	intVersion = navigator.appVersion.substring(0,1);
	if (strURL != "") // cachebusting
	{
		if (strURL.indexOf("?") != -1) 
		{ 
			strURL = strURL + "&rnd="
		} 
		else 
		{
			strURL = strURL + "?rnd="
		}
		strURL = strURL + dummyDate.getTime();	
		strURL = strURL.replace("@","%40");
	}
	
	LeftPosition = (screen.width) ? (screen.width-intWidth)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-intHeight)/2 : 0;
		
	if ( (typeof(strProperties) == "undefined") || (strProperties == "")) 
	{
		strProperties = "status=no,scrollbars=yes,resizable=yes,menubar=no,location=no,directories=no,toolbar=no";
	}	
	strProperties = 'top=' + TopPosition + ',left=' + LeftPosition + ',height=' + intHeight + ',width=' + intWidth + ',' + strProperties;

	// replace all non-alphacharacters with X
	if(strName.replace)
		strName = strName.replace(/\W/g,"X");
	
	// lower case the string
	strName = strName.toLowerCase();
	
	mywin = window.open(strURL, strName, strProperties);
	// check for NULL in case we are in a popup blocker
	if (mywin) 
	{
		mywin.name = strName
		if (mywin.opener == null) 
		{
			mywin.opener = self;
		}
		else 
		{
			if (IsPopup)
			{
				mywin.focus();
			}
			else
			{
				mywin.blur();
				mywin.opener.focus();
			}
		}
	} 
	else 
	{
		//window.document.location = strURL;
	}
	
	return mywin;
}

