/*
 *	$Id: lib.CMS.js,v 1.1 2003/09/10 16:39:35 jgauld Exp $
 *	$Name:  $
 *
 *	JavaScript used by the CMS system itself.
 *	Include this in your base templates using:
 *		<script language="JavaScript" src="{$CMS.URL.root}/cms/templates/base/lib.CMS.js"></script>
 */

//-------------------------------
// Global vars
//-------------------------------
//var undefined;

//-------------------------------
// CMS_browser()
// Static Class to help in determining which browser the user has running
//-------------------------------
CMS_browser = function() {
}

CMS_browser.isIE = function(ver) {

	// Vars
	if(ver==undefined) ver = 0;
	var isIE = (navigator.userAgent.indexOf('MSIE')>-1) ? true : false;
	var version = (isIE) ? parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf('MSIE')+4)) : parseInt(navigator.appVersion);

	// Results
	return (isIE && version>=ver);
}

//-------------------------------
// CMS_popup()
// Create a new popup window
//-------------------------------
function CMS_popup(target, width, height, scroll, resize) {

	// Vars
	resize = (resize==null || resize<1) ? '' : ',resizable';
	scroll = (scroll==null || scroll<1) ? '' : ',scrollbars';

	// Generate coords to place window in centre of screen
	var x = (screen.availWidth - width)/2;
	var y = (screen.availHeight - height)/2;
	var winPos = CMS_browser.isIE() ? 'left='+x+',top='+y : 'screenX='+x+',screenY='+y;

	// Open window
	var w = window.open(target, null, winPos+scroll+resize+',width='+width+',height='+height);
	w.focus();
}

//-------------------------------
// STRING CMS_genHREF( archiveID, contentID, menuID, branchID )
//--
// STRING archiveID	= Archive ID
// STRING contentID	= content ID
// STRING menuID	= menu ID
// STRING branchID	= branch ID
//--
// Generates a URL in line with the setting of 'URLFriendly'
//-------------------------------
function CMS_genHREF(archiveID, contentID, menuID, branchID) {

	// Vars
	var href = '';

	// Generate href
	if(CMS_CONFIG['URLFriendly']=='1') {
		href = '/exec/' + archiveID + '/' + contentID + '/' + menuID + '/' + branchID;
	}
	else {
		href = '/?archiveID=' + archiveID + '&contentID=' + contentID + '&menuID=' + menuID + '&branchID=' + branchID;
	}

	// Result
	return href;
}