var msgwindow = null;
var simpleOpen_handle = null;
var popupWindowHandles = new Array();

if (window.addEventListener) {
	window.addEventListener("unload", document_onUnload, false);
} else if(window.attachEvent) {
	window.attachEvent("onunload", document_onUnload);
} else {
	window.onunload = document_onUnload;
}

function MsgPopup(strURL, intWidth, intHeight){
	if (msgwindow == null || msgwindow.closed || msgwindow.location != strURL) { 
		msgwindow = window.open(strURL, 'msgopen', 'width=' + intWidth + ',height=' + intHeight + ',screenX=200,screenY=50,left=200,top=50,resizable,location=1');
		if (msgwindow != null) {
			msgwindow.focus();
		if (msgwindow.opener == null)
			msgwindow.opener = self;
		}
	} else {
		msgwindow.focus();
		msgwindow.document.location.reload();
	}
}
function document_onUnload() {
	for (var n = 0; n < popupWindowHandles.length; n++) {
		popupWindowHandles[n].close();
	} 
	if (msgwindow != null)
		msgwindow.close();
}
function newpopup(popupName, href, sID) {
	pepopup = popupName;

	if (pepopup == null || pepopup.closed || pepopup.location != href) {
		pepopup = window.open(href+sID, 'peopen','location=1,toolbar=yes,menubar=yes,scrollbars=yes,width=750,height=500,screenX=50,screenY=50,resizable=yes,status=yes');

		if (pepopup != null) {
			pepopup.focus();
			if (pepopup.opener == null)
				pepopup.opener = self;
			popupWindowHandles[popupWindowHandles.length] = pepopup;
		}
	} else {
		pepopup.focus();
		pepopup.document.location.reload();
	}
}

function namedPopup(sName, iWidth, iHeight, sURL, sID) {
	oWin = window.open(sURL + sID, sName, 'location=1,toolbar=yes,menubar=yes,scrollbars=yes,width=' + iWidth + ',height=' + iHeight + ',screenX=50,screenY=50,top=50,left=50,resizable=yes,status=yes');

	if  ( oWin != null ) {
		if  ( oWin.opener == null )
			oWin.opener = self;
		else
			oWin.focus();
		popupWindowHandles[popupWindowHandles.length] = oWin;
	}
}

function HelpPopUp(url){
	PopupsDoNotClose('http://kb.starcite.com/?cid=7&c=12&cpc=5C434ibhk2IW2NwM2TE01y4x08YN8E2D8kUSU30i6Pqf','win','toolbar=1,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,fullscreen=no,dependent=yes,width=700,height=480');
	self.name = "mainWin";
}

function popUpWindow( strURL )
{
	var xMax = 0;
	var yMax = 0;
	var window_handle = 0;

	if( document.all ) {
        xMax = screen.width;
		yMax = screen.height;
	}
    else{
		if( document.layers ) {
			xMax = window.outerWidth;
			yMax = window.outerHeight;
		}
		else{
			xMax = 760;
			yMax = 420;
		}
	}
	var	xOffset = ( ( xMax - 600 ) / 2 );
	var	yOffset = ( ( yMax - 300 ) / 2 );

	if( window_handle )	window_handle.close();
	window_handle = window.open(strURL,'PopUpWindow','height=300,width=700,screenX='+xOffset+',screenY='+yOffset+',alwaysRaised=yes,status=no,toolbar=no,menubar=no,location=yes,scrollbars=yes,resizable=yes,titlebar=no,top='+yOffset+',left='+xOffset+'');
	popupWindowHandles[popupWindowHandles.length] = window_handle;
	window_handle.focus();
}

	
function MsgPopupWithScroll(strURL, intWidth, intHeight){
	if (msgwindow == null || msgwindow.closed || msgwindow.location != strURL) { 
		msgwindow = window.open(strURL, 'msgopen', 'width=' + intWidth + ',height=' + intHeight + ',screenX=200,screenY=50,left=200,top=50,scrollbars=yes,resizable=yes,location=1');
		if (msgwindow != null) {
			msgwindow.focus();
			if (msgwindow.opener == null)
				msgwindow.opener = self;
			popupWindowHandles[popupWindowHandles.length] = msgwindow;
		}
	} else {
		msgwindow.focus();
		msgwindow.document.location.reload();
	}
}

function simpleOpen(sOpenUrl, sName, sFeatures, sReplace)
{
	if (sOpenUrl.toLowerCase().indexOf('p_calendar.asp') >= 0) {
		simpleOpen_handle = window.open(sOpenUrl, sName, sFeatures, sReplace);
	} else {
		simpleOpen_handle = window.open(sOpenUrl, sName, PopupsOverrideWindowOptions(sFeatures), sReplace);
	}
	if (simpleOpen_handle != null) {
		if (simpleOpen_handle.opener == null) {
			simpleOpen_handle.opener = self;
		} else {
			simpleOpen_handle.focus();
		}
		popupWindowHandles[popupWindowHandles.length] = simpleOpen_handle;
	}
}

function PopupsOverrideWindowOptions(windowOptions) {
	var ret = windowOptions.toLowerCase();
	
	if (ret.indexOf('location=') > 0) {
		ret = ret.replace('location=0','location=1');
		ret = ret.replace('location=no','location=1');
		ret = ret.replace('location=false','location=1');
	} else {
		ret = ret + ",location=1"
	}
	return ret;
}

function OpenPreviewWindow(strURL) {
	var prvu_popup = null;
	if (prvu_popup == null || prvu_popup.closed) {
		prvu_popup = window.open(strURL, 'usopen2', 'status=no,scrollbars=yes,resizable=yes,width=690,height=540,screenX=50,screenY=25,left=50,top=25');
		if (prvu_popup != null) {
			if (prvu_popup.opener == null)
				prvu_popup.opener = self;
			else // Needed while prvu_popup reinits to null
				prvu_popup.focus();
		}
	} else {
		prvu_popup.focus();
		prvu_popup.document.location.reload();
	}
}

function JSPopupsWindow(href, windowName, windowOptions) {
	PopupsWindowHack2(href, windowName, PopupsOverrideWindowOptions(windowOptions));
	return;
}

function PopupsWindowHack(href, windowName, windowOptions) {
	return PopupsWindowHack2(href, windowName, PopupsOverrideWindowOptions(windowOptions));
}

function PopupsWindowHack2(href, windowName, windowOptions) {
	var popWindow;

	popWindow = window.open(href, windowName, windowOptions);

	if (popWindow != null) {
		if (popWindow.opener == null) {
			popWindow.opener = self;
		}
		popupWindowHandles[popupWindowHandles.length] = popWindow;
		popWindow.focus();
	}
	return popWindow;
}

function OpenWindowCU(href, width, height, windowName, offsetX, offsetY, resizable, scrollbars, menubar, location, toolbar, status)
{
	var popWindow;

	if (windowName == null) windowName = 'usopen';
	if (offsetX == null) offsetX = 50;
	if (offsetY == null) offsetY = 50;
	if (resizable == null) resizable = 1;
	if (scrollbars == null) scrollbars = 1;
	if (menubar == null) menubar = 1;
	if (location == null) location = 1;
	if (toolbar == null) toolbar = 1;
	if (status == null) status = 1;
	
	return PopupsWindowHack(href, windowName, 'width=' + width + ', height=' + height 
		+ ', top=' + offsetY + ', left=' + offsetX + ', resizable=' + resizable 
		+ ', scrollbars=' + scrollbars + ', menubar=' + menubar 
		+ ', location=' + location + ', toolbar=' + toolbar + ', status=' + status);
}

function PopupsDoNotClose(href, windowName, windowOptions) {
	var popWindow;

	popWindow = window.open(href, windowName, windowOptions);

	if (popWindow != null) {
		if (popWindow.opener == null) {
			popWindow.opener = self;
		}		
		popWindow.focus();
	}
	return popWindow;
}
