//
// IASP 5.0 Base Javascript
//
// Copyright (C) IASP 2007.
// Unauthorised reproduction or use
// on external websites will 
// be subject to rigorous prosecution
//
// Create namespace root
function CMS() { }
CMS.appRoot = '/';
CMS.resUrl = 'http://resource.iasp.com.au/v5/';

// Create dollar sign alias
function $(strId) { return document.getElementById(strId); }

// Implement Array.indexOf
[].indexOf || (Array.prototype.indexOf = function(v,n) {
	n = (n==null)?0:n; var m = this.length;
	for(var i = n; i < m; i++)
		if(this[i] == v)
		return i;
	return -1;
});

String.prototype.trim = function() {
	// Strip leading and trailing white-space
	return this.replace(/^\s*|\s*$/g, "");
}

//
// IASP Browser Detection
// 11/10/06 KM
//
IASP_DetectBrowser.agt = navigator.userAgent.toLowerCase();
IASP_DetectBrowser.is_ie = ((IASP_DetectBrowser.agt.indexOf("msie") != -1) && (IASP_DetectBrowser.agt.indexOf("opera") == -1));

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function IASP_DetectBrowser(redir_url) {
	var browsercap = getCookie('browserCaps');
	if (browsercap == null) browsercap = '';
	//alert(browsercap);
	//if (IASP_DetectBrowser.is_ie) {
	//	if (browsercap != null) return;
	//} else {
	//	if (browsercap == null) return;
	//}
	
	//
	// Mark browser-level-processing done, and Javascript capable.
	//
	browsercap += 'JB';

	//
	// Detect DOM
	//
	if (document.getElementById) {
		browsercap += 'D';
	}

	//
	// Detect XMLHTTP (AJAX)
	//
	if (GetXMLHTTP()) {
		//obj.innerHTML += 'Yes.';
		browsercap += 'X';
	} else {
		//obj.innerHTML += 'No.';
		browsercap += 'x';
	}

	//
	// Detect ContentEditable (WYSIWYG Editor)
	//
	if (document.designMode)
		browsercap += 'C';
	else
		browsercap += 'c';

	//
	// Detect flash
	//
	if (navigator.mimeTypes && navigator.mimeTypes.length) {
		var x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin) {
			browsercap += 'F';
		} else {
			browsercap += 'f';
		}
	} else {
		// try ActiveX detection in IE
		if (IASP_DetectBrowser.is_ie) {
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				if (axo != null) {
					browsercap += 'F';
				} else {
					browsercap += 'f';
				}
			}
			catch (e) {
				browsercap += 'f';
			}
		}
	}

	//window.alert('BrowserCap: ' + browsercap);
		
	document.cookie = 'browserCaps=' + browsercap;
	
	if (redir_url != null) {
		redir_url = unescape(redir_url);
		//window.alert('Redirecting to: ' + redir_url);
		window.location.href = redir_url;
	}
}

// XMLHTTP object loader. Required for Browser Detection
function GetXMLHTTP()
{
    var xh;
    
    // Gecko/KHTML/DOM
    if(typeof XMLHttpRequest != "undefined")
    {
        xh = new XMLHttpRequest();
    }
    
    // IE
    if (!xh) {
	    try { xh = new ActiveXObject("Msxml2.XMLHTTP"); }
	    catch(e)
	    {
		try
		{
		    xh = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
		    xh = null;
		}
	    }
    }
    
    return xh;
}
CMS.GetXMLHTTP = GetXMLHTTP;

//
// popDown function for expandable boxes in Site Builder
//
function popDown(strId) {
	if (document.getElementById('pdI_' + strId).style.display != 'block') {
		document.getElementById('pdI_' + strId).style.display = 'block';
		document.getElementById('pdP_' + strId).style.width = 'none';
		document.getElementById('pdT_' + strId).src = 'images/box_uplt.gif';
	} else {
		document.getElementById('pdI_' + strId).style.display = 'none';
		document.getElementById('pdP_' + strId).style.width = '400px';
		document.getElementById('pdT_' + strId).src = 'images/box_dnrt.gif';
	}
}

function insertTemplateField(mergeField, textBox)
{
   //Update the message display by adding the merge tag
   //IE support
   if (document.selection) {
	textBox.focus();
	sel = document.selection.createRange();
	sel.text = mergeField;
   }
   //MOZILLA/NETSCAPE support
   else if (textBox.selectionStart || textBox.selectionStart == '0') {
	var startPos = textBox.selectionStart;
	var endPos = textBox.selectionEnd;
	textBox.value = textBox.value.substring(0, startPos)
	+ mergeField
	+ textBox.value.substring(endPos, textBox.value.length);
   } else {
	textBox.value += mergeField;
   }

   //Set the focus to the messageBox so the user can enter more characters
   textBox.focus();
}

//
// derived from nodeengine 0.7.0-b3 : /ui/dropdown.js
//

function dm_cvx(strId) {
	document.getElementById(strId).dmEnable = 0;
	setTimeout('cvis(\''+strId+'\',document.getElementById(\''+strId+'\').dmEnable)',100);
}

function cvis(strId, dmx) {
	if (dmx != 1) { document.getElementById(strId).style.display='none'; }
}

function r_dm_ovx(strIdn) {
	strId = 'dm_'+strIdn;
	strTopId = 'ml_'+strIdn;
	return r_dm_ovx_i(strId,strTopId);
}

function a_fm_ovx(strIdn) {
	strId = 'dm_'+strIdn;
	strTopId = 'ml_'+strIdn;
	
	$(strId).fmEnable = 1;
	$(strId).style.top=findPosY($(strTopId)) + "px";
	$(strId).style.left=(findPosX($(strTopId)) + $(strTopId).offsetWidth + 1) + "px";
	$(strId).style.display='block';
}

// make a dropdown menu or IFRAME appear to the top right of another object
function r_dm_ovx_i(strId, strTopId) {
	var otop = findPosY(document.getElementById(strTopId));

	document.getElementById(strId).dmEnable = 1;
	document.getElementById(strId).style.top= otop + "px";
	document.getElementById(strId).style.left=(findPosX(document.getElementById(strTopId)) + document.getElementById(strTopId).offsetWidth) + "px";
	document.getElementById(strId).style.display='block';

	/*
	var bheight = document.getElementById(strId).offsetHeight;
	
	var th = 0;
	
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		th = document.body.offsetHeight - 20;
	} else {
		th = window.innerHeight - 16;
	}
	if (otop + bheight > th) {
		var n_otop = otop - bheight + document.getElementById(strTopId).offsetHeight;
		if (n_otop > 0) document.getElementById(strId).style.top= n_otop + "px";
	}
	*/
}

// make a dropdown menu or IFRAME appear over the top (same top/left position) of another object.
function o_dm_ovx_i(strId, strTopId) {
	var dest_obj = document.getElementById(strId);
	
	// catch wrapping shadow div if available
	var pos_obj = document.getElementById('sw_' + strId);
	if (pos_obj == null) pos_obj = dest_obj;
	
	var ref_obj = document.getElementById(strTopId);
	
	dest_obj.dmEnable = 1;
	pos_obj.style.top= findPosY(ref_obj) + "px";
	pos_obj.style.left=findPosX(ref_obj) + "px";
	dest_obj.style.height = ref_obj.offsetHeight + "px";
	dest_obj.style.width = ref_obj.offsetWidth + "px";
	pos_obj.style.display='block';
}

function b_dm_ovx(strIdn) {
	strId = 'dm_'+strIdn;
	strTopId = 'ml_'+strIdn;
	return b_dm_ovx_i(strId,strTopId);
}

function b_dm_ovx_i(strId, strTopId) {
	document.getElementById(strId).dmEnable = 1;
	document.getElementById(strId).style.top=(findPosY(document.getElementById(strTopId)) + document.getElementById(strTopId).offsetHeight) + "px";
	document.getElementById(strId).style.left=findPosX(document.getElementById(strTopId)) + "px";
	document.getElementById(strId).style.display='block';
}

function br_dm_ovx_i(strId, strTopId, noSwap) {
	var s_width = parseInt(parent.document.documentElement.clientWidth);
	if (s_width == 0) s_width = parseInt(parent.document.body.clientWidth);
	var idO = document.getElementById(strId);
	if (noSwap == null && idO.className == 'iasp_tooltip_Right') {
		brr_dm_ovx_i(strId,strTopId,1);
	} else {
		idO.dmEnable = 1;
		idO.style.top=(findPosY(document.getElementById(strTopId)) + document.getElementById(strTopId).offsetHeight) + "px";
		idO.style.left = '12px';
		var lVal = (findPosX(document.getElementById(strTopId)) + document.getElementById(strTopId).offsetWidth);
		idO.style.display='block';
		idO.style.left=lVal + "px";
		if (idO.className == 'iasp_tooltip_Left' && noSwap != 1) {
			if (lVal + idO.offsetWidth > s_width || lVal + 200 > s_width) {
				idO.className = 'iasp_tooltip_Right';
				brr_dm_ovx_i(strId,strTopId);
			}
		} else if (idO.className == 'iasp_tooltip_Right') idO.className = 'iasp_tooltip_Left';
	}
}

function brr_dm_ovx_i(strId, strTopId) {
	var idO = document.getElementById(strId);
	idO.dmEnable = 1;
	idO.style.top=(findPosY(document.getElementById(strTopId)) + document.getElementById(strTopId).offsetHeight) + "px";
	//idO.style.left=findPosX(document.getElementById(strTopId)) + "px";
	idO.style.left = '12px';
	idO.style.display='block';
	var lVal = (findPosX(document.getElementById(strTopId)) - idO.offsetWidth);
	
	if (idO.className == 'iasp_tooltip_Left') idO.className = 'iasp_tooltip_Right';
	
	if (idO.className == 'iasp_tooltip_Right' && lVal < 0)
	{
		idO.className = 'iasp_tooltip_Left';
		br_dm_ovx_i(strId,strTopId,1);
	}
	else
	{
		idO.style.left=lVal + 'px';
	}
}

function dm_svx(strId,strParent) {
	if (document.getElementById(strId).forcehide != 1) {
		document.getElementById(strId).dmEnable = 1;
		if (strParent != null)
			document.getElementById('dm_' + strParent).dmEnable = 1;
	}
}

//
// Automatic dropdown code
//
function a_dm_cvx(strIdn) {
	strId = 'dm_' + strIdn;
	document.getElementById(strId).dmEnable = 0;
	setTimeout('cvis(\'dm_'+strIdn+'\',document.getElementById(\''+strId+'\').dmEnable)',100);
}

function cvis(strId, dmx) {
	if (dmx != 1) { document.getElementById(strId).style.display='none'; }
}

function a_dm_ovx(strIdn) {
	strId = 'dm_'+strIdn;
	strTopId = 'ml_'+strIdn;
	document.getElementById(strId).dmEnable = 1;
	document.getElementById(strId).style.top=(findPosY(document.getElementById(strTopId)) + document.getElementById(strTopId).offsetHeight + 1) + "px";
	document.getElementById(strId).style.left=findPosX(document.getElementById(strTopId)) + "px";
	document.getElementById(strId).style.display='block';
}

function a_dm_svx(strIdn) {
	strId = 'dm_'+strIdn;
	document.getElementById(strId).dmEnable = 1;
}

//
// Basic general-purpose functions
//

//
// Find Position
// from quirksmode.org
// with improvements to catch absolute/relative positioned parents
//
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if (document.defaultView && document.defaultView.getComputedStyle) { // is Gecko / W3C DOM
				var cs = document.defaultView.getComputedStyle(obj,'');
				if ((cs.getPropertyValue('position') == 'absolute' && cs.getPropertyValue('left') != null) || cs.getPropertyValue('position') == 'relative') {
					break;
				}
			} else if (obj.currentStyle) { // is IE
				if ((obj.currentStyle.position == 'absolute' && obj.currentStyle.left != null) || obj.currentStyle.position == 'relative') {
					break;
				}
			} 
			
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
CMS.findPosX = findPosX;

function findPosY(obj)
{
	var curtop = 0;
	//alert(obj.tagName + '---' + obj.id);
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if (document.defaultView && document.defaultView.getComputedStyle) { // is Gecko / W3C DOM
				var cs = document.defaultView.getComputedStyle(obj,'');
				if ((cs.getPropertyValue('position') == 'absolute' && cs.getPropertyValue('top') != null) || cs.getPropertyValue('position') == 'relative') {
					break;
				}
			} else if (obj.currentStyle) { // is IE
				if ((obj.currentStyle.position == 'absolute' && obj.currentStyle.top != null) || obj.currentStyle.position == 'relative') {
					break;
				}
			} 

			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
CMS.findPosY = findPosY;

function findAbsPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
CMS.findAbsPosX = findAbsPosX;


function findAbsPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
CMS.findAbsPosY = findAbsPosY;

function parentFindPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if (parent.document.defaultView && parent.document.defaultView.getComputedStyle) { // is Gecko / W3C DOM
				var cs = parent.document.defaultView.getComputedStyle(obj,'');
				if ((cs.getPropertyValue('position') == 'absolute' && cs.getPropertyValue('left') != null) || cs.getPropertyValue('position') == 'relative') {
					break;
				}
			} else if (obj.currentStyle) { // is IE
				if ((obj.currentStyle.position == 'absolute' && obj.currentStyle.left != null) || obj.currentStyle.position == 'relative') {
					break;
				}
			} 
			
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function parentFindPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if (parent.document.defaultView && parent.document.defaultView.getComputedStyle) { // is Gecko / W3C DOM
				var cs = parent.document.defaultView.getComputedStyle(obj,'');
				if ((cs.getPropertyValue('position') == 'absolute' && cs.getPropertyValue('top') != null) || cs.getPropertyValue('position') == 'relative') {
					break;
				}
			} else if (obj.currentStyle) { // is IE
				if ((obj.currentStyle.position == 'absolute' && obj.currentStyle.top != null) || obj.currentStyle.position == 'relative') {
					break;
				}
			} 

			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//
// DEPRECATED Auto-resizing Image Popup
//
PositionX = 100;
PositionY = 100;
defaultWidth  = 500;
defaultHeight = 500;
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4) {
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}

var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

function i_popImage(imageURL,imageTitle){
	if (imageTitle = null) imageTitle = 'View Image';
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
		writeln('window.innerWidth=document.images["nePPimg"].width;');writeln('window.innerHeight=document.images["nePPimg"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		if (!AutoClose)
			writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else
			writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="nePPimg" src='+imageURL+' style="display:block"></body></html>');
		close();
	}
	return false;
}

function setimage(id,image)
{
	document.getElementById(id).src = image;
}

function cacheImages()
{
	var d = document; if (d.images) {
		if (!d.MM_p) d.MM_p = new Array();
		var i,j=d.MM_p.length;
		var a=cacheImages.arguments;

		for (i=0; i < a.length; i++) {
			if (a[i].indexOf("#")!=0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
		}
	}
}

//
// Set 'selected' class of parent table row in innertable
//
function markupParentSelected(obj,value)
{
	var stx = obj.tagName;
	
	var obp = obj.parentNode || obj.parent;
	
	while (obp) {
		if (obp.tagName == 'TR') {
			// found a parent row
			if (value == true) {
				// TODO: Move up in sibling list until we find another selected one?
				obp.className = 'selected';
			} else {
				// TODO: Move down in sibling list until we find another non-selected one?
				obp.className = '';
			}
		}
		obp = obp.parentNode || obp.parent;
	}
}
CMS.markupParentSelected = markupParentSelected;

var _markupCount = 0;
//
// Set 'selected' class of parent table row in innertable with count limiting
//
function markupParentSelectedLimited(obj,value,limit)
{
	if (value == true) {
		if (_markupCount >= limit)
			return false;
		else
			_markupCount++;
	} else {
		_markupCount--;
		if (_markupCount < 0) _markupCount = 0;
	}

	var stx = obj.tagName;
	
	var obp = obj.parentNode || obj.parent;
	
	while (obp) {
		if (obp.tagName == 'TR') {
			// found a parent row
			if (value == true) {
				// TODO: Move up in sibling list until we find another selected one?
				obp.className = 'selected';
			} else {
				// TODO: Move down in sibling list until we find another non-selected one?
				obp.className = '';
			}
		}
		obp = obp.parentNode || obp.parent;
	}
}

function blockEnter(e) {
    e = (e) ? e : event;
    var charCode = (e.charCode) ? e.charCode :
        ((e.which) ? e.which : e.keyCode);
    if (charCode == 13 || charCode == 3) {
        return false;
    } else {
        return true;
    }
}

//
// Image textbox handlers
//
cms_initImageTextbox = CMS.initImageTextbox;

CMS.initImageTextbox = function(box_id, img_url, bg_pos, interval) {
	$(box_id).onfocus = function() { this.isFocused = true; }
	$(box_id).onblur = function() { this.isFocused = false; }
	setTimeout("CMS._handleImageTextbox('" + box_id + "','" + img_url + "','" + bg_pos + "',0," + interval + ")",interval);
}

CMS._handleImageTextbox = function(box_id, img_url, bg_pos, hadImage, interval) {
	var boxobj = document.getElementById(box_id);
	var hasImage = hadImage;
	
	if (boxobj) {
		var hasFocus = false;
		try { hasFocus = boxobj.isFocused; }
		catch(e) { }
		if ((boxobj.value == '' || boxobj.value == null) && hasFocus != true) {
			if (hadImage == 0) {
				boxobj.style.backgroundImage = "url('" + img_url + "')";
				boxobj.style.backgroundPosition = bg_pos;
				boxobj.style.backgroundRepeat = "no-repeat";
				hasImage = 1;
			}
		} else {
			if (hadImage == 1) {
				boxobj.style.backgroundImage = "none";
				hasImage = 0;
			}
		}
	}
	
	setTimeout("CMS._handleImageTextbox('" + box_id + "','" + img_url + "','" + bg_pos + "'," + hasImage + "," + interval + ")",interval);
}

//
// Flash player (de-)activation handling
//
var _activeFlashPlayer = null;

function cms_fpSetPlayerActive(obj) {
	if (_activeFlashPlayer != null) {
		_activeFlashPlayer.SetVariable("externalStop",1);
	}
	_activeFlashPlayer = obj;
}

function cms_fpSetPlayerInactive(obj) {
	if (_activeFlashPlayer == obj) _activeFlashPlayer = null;
}

//
// IE7 Flash Player fix (use non-DOM methods to handle a decidedly non-DOM browser's weird behaviour)
//
function cms_IEfix_overwriteFlashMovie(swfsrc, width, height, id) {
	var parentObject = document.getElementById('swfwrap_' + id);
	
	parentObject.innerHTML = '<object type="application/x-shockwave-flash" id="' + id + '" data="' + swfsrc + '" width="' + width + '" height="' + height + '">'
		+ '<param name="movie" value="' + swfsrc + '" /></object>';
}

//
// Set selected value on a dropdown
//
function cms_selectDropdownValue(selectObj, newValue) {
	if (selectObj) {
		for (var i=0; i < selectObj.options.length; i++) {
			if (selectObj.options[i].value == newValue) selectObj.selectedIndex = i;
		}
	}
}

//
// Cross-browser compatible opacity changer
//
function cms_setOpacity(opacity, id) {
	CMS.setOpacity(opacity,$(id));
}
CMS.setOpacityById = cms_setOpacity;
CMS.setOpacity = function(opacity, obj) {
	var style = obj.style;
	if (IASP_DetectBrowser.is_ie) {
		if (opacity == 100) {
			style.filter = "";
		} else {
			style.filter = "alpha(opacity=" + opacity + ")";	
		}
	} else {
		style.opacity = (opacity / 100);
		style.MozOpacity = (opacity / 100);
		style.KhtmlOpacity = (opacity / 100);
	}
}

// Height changing inline function for transform
function cms_setHeight(height, id) {
	document.getElementById(id).style.height = height + "px";
}
// Width changing inline function for transform
function cms_setWidth(width, id) {
	document.getElementById(id).style.width = width + "px";
}
// X changing inline function for transform
function cms_setLeft(left, id) {
	document.getElementById(id).style.left = left + "px";
}
// Y changing inline function for transform
function cms_setTop(top, id) {
	document.getElementById(id).style.top = top + "px";
}

//
// VV storage
//
CMS.SetVisitVar = function(sKey,sVal) {
	// Get URL
	var url = CMS.appRoot + 'ui.ashx?f=visit_set_var&key=' + encodeURIComponent(sKey) + '&val=' + encodeURIComponent(sVal);
	
	var _xh = GetXMLHTTP();
	if (_xh)
	{
		// Initiate XMLHTTP callback
		_xh.onreadystatechange = function() { };
		_xh.open("GET",url,true);
		_xh.send(null);
	}
}

//
// Off site link confirmation
//
function cms_offsite_linkConfirm() {
	return confirm('This will take you off this site. Please ensure you have saved any changes before continuing.\n\nContinue?');
}

//
// Namespacetree toggle
//
var _cms_nst_MinusHTML = '[-]';
var _cms_nst_PlusHTML = '[+]';

var _cms_nst_haveSetOnUnload = false;
var _cms_nst_treeTable = null;

function cms_nst_toggleNode(linkObj,treeId,nameSpace,alreadyOpen) {
	// Set onunload cookie handler
	if (_cms_nst_haveSetOnUnload == false) {
		window.onunload = cms_nst_onUnload;
		_cms_nst_haveSetOnUnload = true;
	}
	
	// Open dictionary
	if (_cms_nst_treeTable == null) {
		_cms_nst_treeTable = new Object;
		var oldCookie = getCookie('cms_nst_state');
		if (oldCookie != null) {
			var sParts = oldCookie.split(':');
			for (var i=0; i < sParts.length; i++) {
				_cms_nst_treeTable[sParts[i]] = 1;
			}
		}
	}
	
	// Handle already open nodes
	if (alreadyOpen == 1 && linkObj._opened != 1 && linkObj._opened != 0)
		linkObj._opened = 1;
	
	// Toggle node
	if (linkObj._opened != 1) {
		linkObj._opened = 1;
		document.getElementById('nst_ct_' + treeId + '_' + nameSpace).style.display = 'block';
		linkObj.innerHTML = _cms_nst_MinusHTML;
		_cms_nst_treeTable[treeId + '_' + nameSpace] = 1;
	} else {
		linkObj._opened = 0;
		document.getElementById('nst_ct_' + treeId + '_' + nameSpace).style.display = 'none';
		linkObj.innerHTML = _cms_nst_PlusHTML;
		_cms_nst_treeTable[treeId + '_' + nameSpace] = 0;
	}
	return false;
}

function cms_nst_onUnload()
{
	var cookieStr = '';
	for (sNamespaceId in _cms_nst_treeTable) {
		if (_cms_nst_treeTable[sNamespaceId] == 1) {
			if (cookieStr.length > 0) cookieStr += ':';
			cookieStr += sNamespaceId;
		}
	}
	document.cookie = 'cms_nst_state=' + cookieStr;
}

// Find the parent form of an object
function cms_findParentByTag(obj,tagName)
{
	var stx = obj.tagName;	
	var obp = obj.parentNode || obj.parent;
	
	while (obp) {
		if (obp.tagName == tagName) {
			return obp;
		}
		obp = obp.parentNode || obp.parent;
	}
	return null;
}

// Handle image tool flip
CMS.setImageToolPage = function(strImgId, strToolPage)
{
	var pgDetail = $('im_' + strImgId + '_detail');
	if (pgDetail) pgDetail.style.display=(strToolPage=='detail'?'block':'none');
	var tbDetail = $('it_' + strImgId + '_detail');
	if (tbDetail) tbDetail.className=(strToolPage=='detail'?'cms_gtool_stab':'');
	var pgChoose = $('im_' + strImgId + '_choose');
	if (pgChoose) pgChoose.style.display=(strToolPage=='choose'?'block':'none');
	var tbChoose = $('it_' + strImgId + '_choose');
	if (tbChoose) tbChoose.className=(strToolPage=='choose'?'cms_gtool_stab':'');
	var pgUpload = $('im_' + strImgId + '_upload');
	if (pgUpload) pgUpload.style.display=(strToolPage=='upload'?'block':'none');
	var tbUpload = $('it_' + strImgId + '_upload');
	if (tbUpload) tbUpload.className=(strToolPage=='upload'?'cms_gtool_stab':'');
	
	return false;
}