// JavaScript Document

// borrowed from http://www.geekdaily.net/2007/07/04/javascript-cross-browser-window-size-and-centering/
/*
function getSize()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}
*/

/*
function showPopup(sURL, sTitle, nW, nH) {
	//alert(typeof nW);
	var nWidth = nW + 40;
	var nHeight = nH + 40;
	var sParams = 'width=' + nWidth + ",height=" + nHeight;
	sParams += ',menubar=0,status=0,location=0,toolbar=0,resizeable=1,scrollbars=0';
	popWin = window.open(sURL, sTitle, sParams);
	popWin.resizeDocumentTo = function(nWidth, nHeight) {
		alert('resizeDocumentTo. this:' + typof this);
		//this.resizeTo(nWidth*2-((typeof this.innerWidth ==	'undefined')?document.body.clientWidth:this.innerWidth),nHeight*2-((typeof this.innerHeight =='undefined')?document.body.clientHeight:this.innerHeight));
	}
	popWin.resizeDocumentTo(nW, nH);

popWin.focus();
}
*/

function showPopup(sURL, sTitle, nW, nH) {
	
	//alert("showPopup called.");
	
	customArgs = {};
	customArgs.width = nW + 40;
	customArgs.height = nH + 40;
	
	customArgs.winWidth = customArgs.width;
	customArgs.winHeight = customArgs.height;
	
	customArgs.title = sTitle;
	customArgs.blockWholeScreen = false;

	if(typeof screen != "undefined" && customArgs.width!= '100%') {
		if(screen.availHeight < (customArgs.height+10) || screen.availWidth < (customArgs.width+10)) {
			customArgs.width = '100%';
			customArgs.height = '100%';
		}
	}
	
	var agt=navigator.userAgent.toLowerCase();
	var is_opera = (agt.indexOf("opera") != -1);
	var appVer   = navigator.appVersion.toLowerCase();
	var is_ie    = ((appVer.indexOf('msie')!=-1) && (!is_opera));
	var is_mac   = (agt.indexOf("mac")!=-1);
	
	var is_gecko = (agt.indexOf('gecko')!=-1);
	function openAppWindow(url) {
		/*
		if(url.indexOf("?") != -1) {
			url = url + "&launched=true";
		}
		else {
			url = url + "?launched=true";
		}
		*/
		var features = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,left=0,top=0';
		if (is_ie) {
			var width = (customArgs.blockWholeScreen || customArgs.width=="100%") ? (screen.availWidth-14) : customArgs.winWidth;
			var height = (customArgs.blockWholeScreen || customArgs.height=="100%") ? (screen.availHeight-38) : customArgs.winHeight;
			features += ',resizable=yes,width='+width+',height='+height;
		}
		else if(!(is_gecko || is_opera)) {
			// do not allow resizing on netscape < 5 b/c resizing causes the page to reload (including the flash movie)
			var swidth = (customArgs.blockWholeScreen || customArgs.width=="100%") ? ('outerWidth='+screen.availWidth) : ('width='+customArgs.winWidth);
			var sheight = (customArgs.blockWholeScreen || customArgs.height=="100%") ? ('outerHeight='+screen.availHeight) : ('height='+customArgs.winHeight);
			features += ',resizable=no,'+swidth+','+sheight;
		}
		else {
			var swidth = (customArgs.blockWholeScreen || customArgs.width=="100%") ? ('outerWidth='+(is_mac ? (screen.availWidth-30) : screen.availWidth)) : ('width='+customArgs.winWidth);
			var sheight = (customArgs.blockWholeScreen || customArgs.height=="100%") ? ('outerHeight='+(is_mac ? (screen.availHeight-6) : screen.availHeight)) : ('height='+customArgs.winHeight);
			features += ',resizable=yes,'+swidth+','+sheight;
		}
		var w = window.open(url, "popWin", features);
	}
	
	openAppWindow(sURL);
}
