//
// Various Javascript Functions
//

var pathRoot = '/NewSite';

function doPopup(URL, width, height) {
	if (typeof URL != "undefined" && URL != null && URL.length > 0) {
	        var w = (width ? width : 800);
	        var h = (height ? height : 500);
	        var wleft = (screen.width - w) / 2;
	        var wtop = (screen.height - h) / 2;
		var oWin = window.open(URL, '_blank', 'directories=0,location=0,resizable=1,scrollbars=1,' +
			'width=' + w + ',height=' + h + ',left=' + wleft + ',top=' + wtop);
	}
}


function go(pageName, width, showRightImages) {
	// width in pixels
	var URL;
	var openInNewWindow = false;
	if (showRightImages == null) showRightImages = false;

	var cf = top.document.getElementById('ContentFrame');
	if (!cf) return;
	var cfc = top.document.getElementById('ContentFrameCell');
	if (!cfc) return;

	var hasGA = (cfc.getAttribute);
	var cf_defWidth = parseInt((hasGA ? cfc.getAttribute('defaultWidth') : cfc.defaultWidth));
	var cf_imgWidth = parseInt((hasGA ? cfc.getAttribute('imgWidth') : cfc.imgWidth));

	if (isNaN(cf_defWidth)) cf_defWidth = '100%'; else cf_defWidth = cf_defWidth + 'px';
	if (isNaN(cf_imgWidth)) { cf_imgWidth = cf_defWidth; showRightImages = false; } else cf_imgWidth = cf_imgWidth + 'px';

	var ri = top.document.getElementById('RightImages');

	if (pageName.substr(pageName.length-4).toLowerCase() == '.pdf')
		openInNewWindow = true;
	
	if (width < 0) {
		openInNewWindow = true;
	} else {
		if (!width || width < 100) width = cf_defWidth;
	}
	
	if (pageName.substr(0, 4).toLowerCase() == 'http' || pageName.substr(0,1) == '/')
		URL = pageName
	else {
		URL = pathRoot + '/ContentPages/' + pageName;
		//URL = location.pathname + '/../' + pageName;
        }

	if (openInNewWindow) {
		window.open(pathRoot + '/Loading.asp?url=' + escape(URL), "StMContent");
	} else {
		if (ri != null && showRightImages) {
			ri.style.display = 'inline'
			//cfc.style.pixelWidth = cf_imgWidth;
			cfc.style.width = cf_imgWidth;
		} else {
			if (ri != null) ri.style.display = 'none';
			//cfc.style.pixelWidth = width;
			cfc.style.width = width;
		}			
		cf.src = pathRoot + '/Loading.asp?url=' + escape(URL);
	}
}

function openInNewPage(URL) {
	if (!URL) {
		var cf = top.document.getElementById('ContentFrame');
		if (!cf) return;
		URL = cf.src;
	}

	if (!URL || URL.length < 1) return;
	window.open(pathRoot + '/Loading.asp?url=' + escape(URL), "StMContent");
}