// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
function checkWindowName( windowName )
{
	var newWindowName;

	if (window.name == windowName) {
		newWindowName = windowName+'2';
	}
	else {
		newWindowName = windowName;
	}

	return newWindowName;
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
function metPopSmall( fileName )
{
	var newWinName = checkWindowName('metSmall');
	
	openPop = this.open(fileName,newWinName,'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=800,height=1,left=100,top=5,screenX=100,screenY=5');

	openPop.focus();

	// close the old pop if metResized pop was blocked
	if ((window.name != newWinName) && ((window.name == 'metSmall') || (window.name == 'metSmall2'))) {
		window.close();
	}
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
function metPopSplash( fileName )
{
	openPop = this.open(fileName,'metSplash','toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=600,height=321,left=100,top=5,screenX=100,screenY=5');
	openPop.focus();
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
function metPopTall( fileName )
{
	var newWinName = checkWindowName('metTall');

	if (screen.height > 600) {
		openPop = this.open(fileName,newWinName,'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=618,height=550,left=100,top=5,screenX=100,screenY=5');
	}
	else {
		openPop = this.open(fileName,newWinName,'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=618,height=515,left=100,top=5,screenX=100,screenY=5');
	}
	openPop.focus();
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
function metPopWide( fileName )
{
	var newWinName = checkWindowName('metWide');

	if (screen.height > 600) {
		openPop = this.open(fileName,newWinName,'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=750,height=550,left=16,top=5,screenX=16,screenY=5');
	}
	else {
		openPop = this.open(fileName,newWinName,'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=750,height=515,left=16,top=5,screenX=16,screenY=5');
	}
	openPop.focus();
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
function openAndClose(loadPage,pageType) {
	if ( pageType == "wide" ) {
		newPop = metPopWide(loadPage);
	}
	else {
		if ( pageType == "tall" ) {
			newPop = metPopTall(loadPage);
		}
		else {
			newPop = metPopSmall(loadPage);
		}
	}
	window.close()
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
function resizeMe( pageName, winWidth )
{
	var newWinName = checkWindowName('metResized');

	var agt = navigator.userAgent.toLowerCase();
	var is_mac = (agt.indexOf("mac")!=-1);

	var winX, winY;
	if (winWidth > 600) {
		winX = 16;
	}
	else {
		winX = 100;
	}
	winY = 5;
	
//	var winWidth = window.outerWidth ? outerWidth : document.body && document.body.clientWidth ? document.body.clientWidth : null;
//	var winWidth = document.width ? document.width : document.body && document.body.scrollWidth ? document.body.scrollWidth : null;
	var docHeight = document.height ? document.height : is_mac && document.body && document.body.scrollHeight ? document.documentElement.offsetHeight : document.body && document.body.scrollHeight ? document.body.scrollHeight: null;

	var winHeight;
	var vertScroll;
	var forceResize;
	if ((screen.height - 85) < docHeight) {
		newWinName = checkWindowName('metTest');
		winHeight = screen.height - 100;
		vertScroll = "yes";

		if ((window.name != 'metTest') || ((document.referrer != '') && (document.referrer.indexOf(pageName) == -1))) {
			winWidth += 18;
			newPopResized = window.open(pageName,newWinName,'toolbar=no,menubar=no,location=no,scrollbars='+vertScroll+',resizable=no,width='+winWidth+',height='+winHeight+',left='+winX+',top='+winY+',screenX='+winX+',screenY='+winY);
				if (((window.name == 'metSmall') || (window.name == 'metSmall2')) && (!newPopResized)) {
					winWidth += 30;
					winHeight += 30;
					window.resizeTo(winWidth,winHeight);
					window.moveTo(winX,winY);
				}
			newPopResized.focus();
			window.close();
		}

		forceResize = true;
	}
	else {
		winHeight = docHeight;
		vertScroll = "no";
		forceResize = false;
	}

	if (winWidth && docHeight) {
		if ((((docHeight) == (window.innerHeight ? window.innerHeight : document.body && document.body.scrollHeight ? document.body.clientHeight : null))) || (forceResize)) {
			void(0);
		}
		else {
			newPopResized = window.open(pageName,newWinName,'toolbar=no,menubar=no,location=no,scrollbars='+vertScroll+',resizable=no,width='+winWidth+',height='+winHeight+',left='+winX+',top='+winY+',screenX='+winX+',screenY='+winY);

			// if newPop fails, resize and move old pop
			if (((window.name == 'metSmall') || (window.name == 'metSmall2')) && (!newPopResized)) {
				winWidth += 30;
				winHeight += 30;
				window.resizeTo(winWidth,winHeight);
				window.moveTo(winX,winY);
			}
		newPopResized.focus();
		window.close();
		}
	}
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
