/*
	File:			NexusJs
	Version:		0003
	Version Date:		
	Purpose:		To provide all Nexus Javascript while making it easier to
					keep track of what changes are present in this file and
					how recent it is.
	
	Use:			When you are creating a change to this file you should 
					create a copy of the existing file with the next version number,
					and change the include file (nexusjs.html) to reference your 
					new file.
	
	Changelog:

	20080827 RTC: Created version 1 from nxadmin.js	
	20080908 RTC: Changed to version 2 to contain widespread removal of esdiAPI use FS#1787 changes
	20081014 RTC: Added contents of nxlistpopup
	20081210 RTC: Created nexusjs0003 to contain jQuery .draggable conversion
*/

//alias jQuery to shorthand jQ, because $ may have problems with some CCSIDs
var jQ = jQuery.noConflict();

//disable caching on all jQuery AJAX requests
jQuery.ajax({ cache: false });

//create a custom jQuery function to replace a classname
jQuery.fn.replaceClass = function(newclass) 
{ 
	return this.each(function() 
	{ 
		this.className = newclass;
	});
};

//custom jQuery function to change the display of an element to indicate
//that it is disabled and disable all contained input elements
jQuery.fn.disable = function()
{
	return this.each(function()
	{
		jQ(this).addClass('disabled');
		jQ(this).find('input').attr('disabled',true);
	});
};
//custom jQuery function to change the display of an element to indicate
//it is regularly accessible and enable all contained input elements
jQuery.fn.enable = function()
{
	return this.each(function()
	{
		jQ(this).removeClass('disabled');
		jQ(this).find('input').attr('disabled',false);
	});
};


//create a custom jQuery function to handle right mouse clicks which dont work in IE
var onRightRelease = function(handler,e)
{
	//if this is an event on the right mouse button, call the passed function
	if(e.which == 3)
	{
		//dont affect future mouseup events
		jQ(this).unbind('mouseup',onRightRelease);
		handler(e);
		
		//prevent default action, such as following links
		e.preventDefault();
		return false;
	}
};

jQuery.fn.rightClick = function(handler) 
{
	jQ(this).each( function() 
	{
		jQ(this).mousedown( function(e) 
		{
			//check that this is a mousedown event on the right button
			if(e.which == 3)
			{
				//on the next mouseup event, call the release handler
				jQ(this).mouseup( onRightRelease(handler, e) );
				return false;
			}
		});
		
		//prevent contextmenu (IE)
		jQ(this)[0].oncontextmenu = function() 
		{
			return false;
		};
		
	});
};

//RTC 20081211: globals for use as constants (not defined because not needed for non-edit mode)
var dragOptions, dropOptions;

// Fix for IE background image flickering
try
{
  document.execCommand('BackgroundImageCache', false, true);
}
catch(e) {}

var iframearray = [];
var iframectr = 0;
var ViewTreeLoaded = false;
var ViewTreeLoaded2 = false;
var popupWin;
var randnum = Math.random();

var ECMNavigators = [];
var ECMNavigatorctr = 0;
var keywindow = null;
var key2window = null;
var keyloaded = false;
var key2loaded = false;
var settype = 'Y';
var dragObj = {};
dragObj.zIndex = 0;
var currentPortlet = '';
var ReloadPath = '';
var clonedPortlet = '';
var placeHereObj = '';
var currentObjHeight = '';
var currentPortletObj = '';
var trackdown = -1;
var selectedObj;
var saveselect;

var authrrn = 0;

/* Poller functions */ 
function PadDigits(n, totalDigits) 
{ 
	n = n.toString(); 
	var pd = ''; 
	if (totalDigits > n.length) 
	{ 
		for (i=0; i < (totalDigits-n.length); i++) 
		{ 
			pd += '0'; 
		} 
	} 
	return pd + n.toString(); 
} 


function altrows()
{
	for(i = 0; i < rows.length; i++)
	{           
		if(i % 2 == 0)
		{ 
			rows[i].className = "even"; 
		}
		else
		{ 
			rows[i].className = "odd"; 
		}       
	} 
}

function hilite(myrow)
{ 
	if (prevrow && (prevrow.className != "hideme") )
	{
		prevrow.className = prevclass;
	}
	
	actrow = myrow; 
	prevrow = myrow;

	prevclass = jQ('#'+myrow).className;
	jQ('#'+myrow).replaceClass('hilite');
	
	mydiv ="dv" + (myrow.rowIndex -1); 
	jQ('#currem').html( jQ('#'+mydiv).html() );
}


function hiderow(action) 
{ 
	var hdone = false;
	var rrn = 0; 
	for (i = 1; i < rows.length; i++) 
	{
		if (rows[i].className == "hilite")  
		{ 	 				  
			for (x= i-1; x > 0; x--) 
			{ 
				if (rows[x].className != "hideme")
				{ 
					hilite(rows[x]);
					rrn = rows[i].rrn; 
					hdone = true;
					break;
				}
			}
			
			if (hdone == false) 
			{ 
				for (x =i+1; x < rows.length; x++)
				{ 
					if (rows[x].className != "hideme")
					{ 
						hilite(rows[x]);
						hdone = true;
						break;
					}
				}
			}
			
			rrn = rows[i].rrn; 
			
			if (action == 'S') 
			{ 
				var myurl ="nxupoll.pgm?task=snooze&rrn=" + rrn; 
				myurl += "&snoozeval="+document.snoozeform.timeval.value; 
				myurl += "&snoozeunit="+document.snoozeform.timeunit.value; 
				
				jQ.get(myurl);
			} 
			else if (action == 'D')
			{
				var myurl ="nxupoll.pgm?task=dismiss&rrn=" + rrn; 			
				jQ.get(myurl);
				
			} 	
			rows[i].className="hideme"; 
			break; 
		}
	}
	if (hdone == false)
	{
		self.close();
	}
}
//dismiss a reminder
function dismiss(rrn)
{
	var myurl ="nxupoll.pgm?task=dismiss&rrn=" + rrn; 			
	jQ.get(myurl);
	
	jQ('#tr'+rrn).remove();
}

function dismissall() 
{ 
	jQ.get('nxupoll.pgm?task=dismissall');
	
	self.close();  
}

function ShutdwnReminder() 
{ 
	jQ.get('nxupoll.pgm?task=snoozeall');
}

function SetupReminder() 
{
	//bind highlight on mouseup to all rows
	jQ('#remindtable tbody tr').bind('mouseup', function()
	{ 
		hilite(this);
	});
	
	//highlight the last row
	jQ('#remindtable tbody tr:last').hilite(this);
	
}


/* Group Functions */
function GroupDetVal(mvgrpfail, namefail, addnamefail)
{
	if (mvgrpfail == 'Y')
	{
		jQ('#prntgrp').replaceClass('error');
		
		//check if group and destination are the same
		if( jQ('#group').val() == jQ('#movetogroup').val() )
		{
			alert('You cannot move a group into itself');
		}
		else
		{
			alert('Error: You cannot move a group into one of its child groups');
		}
	}
	
	if (addnamefail == 'Y')
	{
		jQ('#crtgroup').replaceClass('error');
		alert('Error: You cannot have duplicate subgroup names.');
	}
	else if (namefail == 'Y')
	{
		jQ('#crtgroup').replaceClass('error');
		alert('Error: You cannot have duplicate subgroup names.');
	}
	
}


function moveGroup()
{
	jQ('#applybtn').val('Apply and Move');
}

function chgManager(rrn, manger)
{
	if (manger == false)
	{
		manger = "N";
	}
	else
	{
		manger = "Y";
	}
	
	// TODO: put an id on the group element rather than this lengthy DOM retrieval method
	var url = "nxgrpmng.pgm?task=chgmanager&manager=" + manger + "&group=" + document.inpform.group.value + "&rrn=" + rrn;
	//xl_AjaxUpdate(url, mydiv);
	jQ.get(url);
}

function clearGroupform()
{
	jQ('#formfilt').children('input').val('');
	document.formfilt.submit();
}


function grouppage(page)
{	
	jQ('#pagedsp1').hide();
	jQ('#pagedsp2').hide();
	jQ('#pagedsp3').hide();
	
	jQ('#pg1').replaceClass('tab');
	jQ('#pg2').replaceClass('tab');
	jQ('#pg3').replaceClass('tab');
	
	if (page == 1)
	{
		jQ('#pagedsp1').show();
		var grpifr = jQ(parent.document).find('#groupifr')[0];
		
		if (document.body.scrollHeight > 500)
		{
			grpifr.height = document.body.scrollHeight + 20;
		}
		
		parent.PageNumber = 1;
		jQ('#pg1').addClass('tabsel');
	}	
	else if (page == 2)
	{
		jQ('#dyniframe1')[0].src = 'nxgrpmng.pgm?task=memberlist&group=' + document.inpform.group.value;
		parent.PageNumber = 2;
		jQ('#pg2').addClass('tabsel');
	}	
	else if (page == 3)
	{
		jQ('#pagedsp3').show();
		parent.PageNumber = 3;
		jQ('#pg3').addClass('tabsel');
	}
}

function SizePage(page)
{
	var ifr = jQ('#page')[0];
	if(ifr == undefined)
	{
		return;
	}
	var grpifr = jQ(parent.document).find('#groupifr')[0];
		
	var contentHeight = ifr.contentWindow.document.body.scrollHeight;
	if (contentHeight > 500)
	{
		ifr.height(contentHeight);
	}
}


function grouplist(task, userno, group) 
{ 
	if(jQ('#content')[0])
	{
		if ((group == '') || (group == 0))
		{
			jQ('#content').html("Use the tree on the left to maintain your Groups...");
			return;
		}
		else
		{
			jQ('#content').html("");
		}
	}
	
	if (task == 'gotogroup')
	{
		var url = 'nxgrpmng.pgm?group=' + group + '&rnd='+Math.random();
		top.location.href = url;
	}
	else if (task == 'delgroup')
	{
		
		if (group == 1)
		{
			alert('The Everyone Group can not be deleted.');
		}
		else
		{
			if (document.inpform.dltflg.value != 'Y')
			{
				alert('This Group has dependent groups. Delete the dependent groups first, then delete this group.');
			}
			else
			{
				var return_value = confirm('You are about to permanently delete this group and all users owned by this group. Do you wish to continue?');
			}
			
			if ( return_value == true )
			{
				var url = 'nxgrpmng.pgm?task=dltgroup&group=' + group + "&rnd=" +  Math.random();
				top.location.href = url;
			}
		}
		
	}
	else if (task == 'addgroup')
	{
		var errorflg = val_InpChar('groupname', 'Group Name', 'crtgroup');
		var errorflg2 = val_InpChar('groupdet', 'Group Description', 'crtgroup1');
		if ((errorflg != 'Y') && (errorflg2 != 'Y'))
		{
			var url = 'nxgrpmng.pgm?task=addgroup&groupname=' + jQ('#groupname').val()
			+ '&group=' + jQ('#group').val() + '&groupdet=' + jQ('#groupdet').val();
			location = url;
		}
		
	}
	else if (task == 'chggroup')
	{
		
		
		var errorflg = val_InpChar('GMGRPD', 'Group Name', 'grpname');
		var errorflg2 = val_InpChar('GMDET', 'Group Description', 'grpdet');
		if((errorflg != 'Y') 
		&& (errorflg2 != 'Y'))
		{
			// RTC 20090923 replace with jQuery selectors
			/*
			// TODO: This looks suspect, probably a better way to do whatever this is...
			if (document.inpform.GMCEIL.checked == true)
			{
				document.inpform.GMCEIL.value = "Y";
			}
			if (document.inpform.GMCRTUSR.checked == true)
			{
				document.inpform.GMCRTUSR.value = "Y";
			}
			if (document.inpform.GMCRTGRP.checked == true)
			{
				document.inpform.GMCRTGRP.value = "Y";
			}
			if (document.inpform.GMVISBLE.checked == true)
			{
				document.inpform.GMVISBLE.value = "Y";
			}
			else
			{
				document.inpform.GMVISBLE.value = "";
			}
			
			// TODO: make sure there is an id on these inputs and get the values directly
			var url = 'nxgrpmng.pgm?task=chggroup&group=' + document.inpform.group.value + 
			"&GMGRPD=" + document.inpform.GMGRPD.value + "&GMDET=" + document.inpform.GMDET.value 
			+ "&GMCEIL=" + document.inpform.GMCEIL.value + "&GMCRTGRP=" + 
			document.inpform.GMCRTGRP.value + "&GMCRTUSR=" + document.inpform.GMCRTUSR.value 
			+ "&GMVISBLE=" + document.inpform.GMVISBLE.value + 
			"&movetogroup=" + document.inpform.movetogroup.options[document.inpform.movetogroup.selectedIndex].value;
			
			location.href = url;

			// end RTC 20090220
			
			*/
			var url = 'nxgrpmng.pgm?task=chggroup&group=' + jQ('#group').val()
			+ '&GMGRPD=' + jQ('#GMGRPD').val()
			+ '&GMDET=' + jQ('#GMDET').val()
			+ '&GMCEIL=' + jQ('#GMCEIL:checked').val()
			+ '&GMCRTGRP=' + jQ('#GMCRTGRP:checked').val()
			+ '&GMCRTUSR=' + jQ('#GMCRTUSR:checked').val()
			+ '&GMVISBLE=' + jQ('#GMVISBLE:checked').val()
			+ '&movetogroup=' + jQ('#movetogroup').val();
			
			location.href = url;
			// end RTC 20090923
			
		}
		
	}
	else if (task == 'upduser')
	{
		var url = 'nxusrmnt.pgm?task=upd&group='+ document.inpform.group.value + '&USUNBR=' + userno + '&rnd=' + Math.random();
		jQ('#dyniframe1',parent.document).attr('src', url);
		parent.PageNumber = 2;
		jQ('#pg2').replaceClass('tab tabsel');
	}
	else if (task == 'rmvgroup')
	{
		var url = 'nxgrpmng.pgm?task=removegroup&group='+ document.inpform.group.value + '&rmvgroup=' + userno + "&rnd=" +  randnum;
		location.href = url;
	}
	else if (task == 'dltuser')
	{
		var return_value = confirm('You are about to permanently delete this user. Do you wish to continue?');
		
		if ( return_value == true )
		{
			var url = 'nxgrpmng.pgm?task=dltuser&group='+ jQ('#group').val() + '&USUNBR=' + userno + "&rnd=" +  randnum;
			location.href = url;
		}
	}
	else
	{
		var url = 'nxgrpmng.pgm?task=' + task + '&group=' + group + '&usernbr=' + userno + "&rnd=" +  randnum;
		
		jQ('a').removeClass();

		jQ('#grp'+group).replaceClass('selected');
		jQ('#groupifr').attr('src',url);
	}
}

function postovalue (value) 
{
	var url = 'nxgrpmng.pgm?task=details&group='+ document.inpform.group.value + "&rnd=" +  Math.random();
	
	jQ('#groupifr')[0].src = url;
	parent.inpform.group.options[value].selected = true;
	
}

/* Start Login Functions */

// innovaedit initialization for todo
function setup_todo()
{
	
	oEdit1.btnSpellCheck=true;
	oEdit1.width="100%";
	oEdit1.height="200px";
	oEdit1.btnStyles=true;
	oEdit1.REPLACE("taskdesc2");
}

function pwdhelp()
{
	if ( hinttype == "H") 
	{
		jQ('#nx_hinter').show();
		if (g_user == '') 
		{
			jQ('#nx_hint').html('Enter a User ID');
		}

	}

	if (hinttype == "Q")
	{ 
		if (secretquest == '')
		{
			jQ('#nx_hint').html('No secret question defined for this User');
			jQ('#nx_hinter').show();
		}
		else
		{
			jQ('#forgot').val('Y');
			jQ('#task').val('reqpwd');
			jQ('#loginfm')[0].submit();
		}		
	} 
	
	return true; 
}

function newaccount()
{ 
	document.newaccfm.submit();
} 	

function trylogin()
{	
	jQ('#forgot').val('N');
	jQ('#task').val('extlogin');
	jQ('#loginfm')[0].submit(); 
}

function entsub(e) 
{
	if (e.which == 13)
	{
		trylogin();
	}
	else
	{
		return true;
	}
}

// TODO: review this function and the login page
function loadformvars() 
{
	var hdr = jQ('#nx_header')[0];
	
	if ((hdr.src == "" ) || (hdr.src.match("/nexuspublic/nothing.htm") != null))
	{
		hdr.src = iframetgt;  
	}
	if (hdr.height =="")
	{
		hdr.height = iframehght; 
	}
	
	jQ(document).bind('keypress',entsub);
	jQ('#nx_crtacct').bind('mousedown', newaccount);
	jQ('#nx_login').bind('mousedown', trylogin);
	
	if((g_forgotpwd == 'N') 
	|| (g_message == '') 
	|| ((hinttype == "Q") && (secretquest == '')) 
	|| ((hinttype == "H") && (g_hint == '')))
	{
		jQ('#forgotpwd').hide();
	}
	else
	{
		jQ('#nx_pwdhelp').bind('click', pwdhelp);
	}
	
	lgform = jQ('#loginfm')[0];
	lgform.action = lgaction; 
	lgform.method = "post"; 
	lgform.siteno.value = g_sitenbr;
	lgform.task.value = "extlogin"; 
	lgform.user.value = g_user;
	lgform.user.focus();
	
	if (showremind  == "Y")
	{
		jQ('#nx_remind').show();
	}
	else
	{
		jQ('#nx_remind').hide();
	}
	
	if (allownewaccs == "Y")
	{ 
		jQ('#nx_newaccts').show();
		jQ('#nx_newaccts2').show();
	}
	else 
	{
		jQ('#nx_newaccts').hide();
		jQ('#nx_newaccts2').hide();
	}
	
	if(errclass != "")
	{
		jQ('#nx_errmsg').replaceClass(errclass);
	}
	
	jQ('#nx_errmsg').html(g_message);
	jQ('#nx_hint').html(g_hint);
	jQ('#nx_sitename').html(g_sitename);	
}
/*** End Login Functions **/


function submitmnu() 
{
	var errorflg = val_InpChar('MFPGNAME', 'Menu Name', 'menuname','N');
	if (errorflg != 'Y')
	{
	
		document.inpform.submit();
	}
}

function submitcstmnu() 
{
	var errorflg = val_InpChar('MIITEM', 'Item Name', 'menuname','N');
	if (errorflg != 'Y')
	{
		document.inpform.submit();
	}
}

/**Group User Links Functions **/

function fnFrameLoadHandler() 
{ 
	try 
	{ 
		var the_height = parent.document.getElementById('dyniframe').contentWindow.document.body.scrollHeight; 
		this.parent.document.getElementById('dyniframe').style.height=the_height; 
	} 
	catch(err) 
	{
		this.parent.document.getElementById('dyniframe').style.height=global_height; 
	}  
} 


function ChgStatusBar(e)
{
	//RTC 20080908: event.target is W3C standard, normalized by jQuery
	//var MyEventObj = xl_GetEventTarg(e);
	var MyEventObj = e.target;
	var EventObj = MyEventObj; 
	
	if (EventObj.nodeName == "LI") 
	{ 
		var children = EventObj.childNodes; 
		
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].nodeName == "A") 
			{
				MyEventObj.title = children[i].title; 
				EventObj = children[i];
				break; 
			}
		}
	}
	
	if (EventObj.href) 
	{
		window.status = jQ(EventObj).attr('href') + ' ('+ jQ(EventObj).text + ')';
		return true; 
	}
} 

function ClrStatusBar()
{ 
	window.status= ""; 
	return true;
}

// when a user clicks on a link in the ECM right click menus
// TODO: test out this code, it looks a little suspect with frame changes
function rungulink(link_obj) 
{ 
	var link_url = link_obj.href; 
	var link_target = link_obj.target; 
	
	if ( link_url != "") 
	{	
		if (link_target  == "")
		{ 
			if (parent.frames.insidepageurl) 
			{ 
				jQ(parent.document).find('#xx').html( link_obj.title );
				parent.frames.insidepageurl(link_url); 
				
				var url = link_url.substring(0, 3);
				if (url != "htt")
				{		
					oIframe = jQ(this.parent).find('#dyniframe');
					jQ(oIframe).bind('onload', fnFrameLoadHandler);
				}
				else 
				{
					jQ(this.parent).find('#dyniframe').css('height', linkHeight);
				}
				
			}
		}
		
		if (link_target == "_blank")
		{
			newWindow = window.open(link_url, "_blank"); 
		}
		
		if (link_target == "_top")
		{	
			newWindow = window.open(link_url, "_top"); 
		}
	}				
}

function guClickHandler(e) 
{
	// RTC 20080908: jQuery normalizes use of W3C standard event.target
	//var EventObj = xl_GetEventTarg(e);
	var EventObj = e.target;
	var ajaxurl;
	
	if (EventObj.tagName == "LI")
	{ 
		var children = EventObj.childNodes; 
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].nodeName == "A") 
			{
				EventObj = children[i];
				break; 
			}
		}
	}
		
	if (EventObj.tagName == "A")
	{
		if (EventObj.parentNode.className == "nxmnuFldrClosed" || EventObj.parentNode.className=="nxmnuFldr") 
		{
			EventObj.parentNode.className = (EventObj.parentNode.className=='nxmnuFldr') ? "nxmnuFldrClosed" : "nxmnuFldr";
			
			if (EventObj.parentNode.className == "nxmnuFldrClosed")
			{
				
				children = EventObj.parentNode.childNodes; 
				for (var i = 0; i < children.length; i++) 
				{
					if (children[i].nodeName == "UL") 
					{
						var myid = children[i].id;
						break;
					}
				}	
				
				ajaxurl = "NXLNKSTREE.pgm?task=EXPAND&ALPHNODE=" + myid + "&mnumopt=" + mnumopt + "&instance=" + instance; 		
				jQ.get(ajaxurl, function(resp)
				{
					jQ('#'+myid).html(resp);
						
					adjustParent();
				});
			}
			else
			{	   	 
				adjustParent();
			} 
		}
		else 
		{
			if (savSelObj)
			{
				savSelObj.className = savSelObj.className.substring(0,2) + savSelObj.className.substring(4);
				
				children = savSelObj.childNodes; 
				for (var i = 0; i < children.length; i++) 
				{
					if (children[i].nodeName == "A") 
					{
						children[i].className = '';
						break;
					}
				}	
			}
			
			savSelObj = EventObj.parentNode;
			EventObj.className = 'selected';
			EventObj.parentNode.className = EventObj.parentNode.className.substring(0,2) + 'Op' + EventObj.parentNode.className.substring(2);
			
			rungulink(EventObj); 
		} 
	}
	
	if (window.event)
	{
		return false;
	}
	else
	{
		e.preventDefault();
	}
}	

function initlinks()
{ 	
	jQ(document).bind("mouseover", ChgStatusBar);
	jQ(document).bind("mouseout", ClrStatusBar);
	jQ(document).bind("click", guClickHandler);
	
	adjustParent(25);
} 


/*** Start Calendar Functions **/

function cal_restore() 
{
	jQ('#activedlt').checked = "checked";
	jQ('#activermd').checked = "checked";
}

function calshoworhide(imgname) 
{ 
	var instance = jQ('#instance').val();
	var ifr = jQ('#writestateframe')[0];
	
	
	if (flipper == 'O') 
	{
		jQ('#navbar2').hide();
		flipper = 'C'; 
		
		
		document.images[imgname].src = '/nexuspublic/images/closebar.gif'; 
		document.images[imgname].alt = "Hide Left Column"; 
		
		var url = 'nxmcal.pgm?task=updatestate&state=C&instance=' + instance + "&rnd=" + Math.random();
		ifr.src = url;
		
		jQ('#navbar2').width = '';
		loadcalendars('C');
		
	}
	else 
	{
		jQ('#navbar2').show();
		flipper = 'O'; 
		
		document.images[imgname].src = '/nexuspublic/images/openbar.gif'; 
		document.images[imgname].alt = "Show Left Column"; 
		
		var url = 'nxmcal.pgm?task=updatestate&state=O&instance=' + instance + "&rnd=" + Math.random();
		ifr.src = url;
		
		jQ('#navbar2').width = '165px';
		loadcalendars('O');
		
	} 
}


function calreverseflipperimg() 
{ 
	if (flipper == 'O') 
	{
		jQ('#colhider')[0].src = '/nexuspublic/images/closebarreverse.gif'; 
	}
	else 
	{ 
		jQ('#colhider')[0].src = '/nexuspublic/images/openbarreverse.gif'; 
	} 
}

function calflipperimg() 
{ 
	if (flipper == 'O') 
	{
		jQ('#colhider')[0].src = '/nexuspublic/images/closebar.gif'; 
	}
	else 
	{ 
		jQ('#colhider')[0].src = '/nexuspublic/images/openbar.gif'; 
	} 
}

function closedaywin()
{
	jQ(parent.document).find('#daypopup').hide();
}

function calpagefunc2()
{
	jQ('#pagedsp1').hide();
	jQ('#pagedsp2').show();
	jQ('#pg1').replaceClass('tab');
	jQ('#pg2').replaceClass('tab tabsel');
	
}

function chgPrivate()
{
	if (!document.all.TDSHRU.value != 'P')
	{
		jQ('#sharedevent').html("This Event is being shared. Click on the following link to make this a private event: <a onclick='private();'>Private</a>");
		calpagefunc2();
	}
	else
	{
		jQ('sharedevent').html("This Event is Private");
	}
}

function setprivate()
{
	var authFound = 'N';
	var authdoc = jQ(jQ('#authframe')[0].contentWindow.document);
	
	var children = jQ('#addedauths > div', authdoc); 
	children.each(function()
	{
		if( jQ(this).css('display') != 'none')
		{
			authFound = 'Y';
		}
	});
	
	if (authFound != 'Y')
	{
		var children = jQ('#selauth > div',authdoc);
		children.each(function()
		{
			if((jQ(this).css('display') != 'none')
			&& (jQ(this).attr('id') != 'norecords'))
			{
				authFound = 'Y';
			}
		});
	}
	
	if (authFound == 'Y')
	{
		jQ('#sharedevent').html("<span class=\"nolink\">This Event is being shared.</span> <a href='#' onclick='dltallauth();'>Set as Private</a>"); 
		jQ('#norecords', authdoc).hide();
		
		document.inpform.TDSHRU.value = '';
	}
	else
	{
		jQ('#sharedevent').html("<span class=\"nolink\">This Event is Private.</span>");
		jQ('#norecords', authdoc).show();
		document.inpform.TDSHRU.value = 'P';	
	}
}

function calpagefunc1()
{
	jQ('#pagedsp1').show();
	jQ('#pagedsp2').hide();
	jQ('#pg1').addClass('tabsel');
	jQ('#pg2').replaceClass('tab');
	
	setprivate();
	
	document.inpform.TDDETE.focus();
	
}


function gotodate()
{
	var month = jQ('#MONTH').val();
	var year = jQ('#YEAR').val();
	
	var instance = jQ('#instance').val();
	var viewby = jQ('#viewby').val();
	var viewtype = jQ('#viewtype').val();
	
	pagetoload = 'NXMCAL.pgm?task=default&instance='+ instance + '&MONTH=' + month + '&YEAR=' + year + '&DAY=1&viewby=' + viewby + '&viewtype=' + viewtype + '&rnd=' + Math.random();
	document.location.href= pagetoload;
}

function usroptions(ev) 
{ 
	var ifr = jQ('#usroptframe');
	var instance = jQ('#instance').val();

	ifr.css('left', (ev.clientX - 300) + 'px');
	ifr.css('top', (ev.clientY + 15) + 'px');
	
	var url = 'nxclusr.pgm?task=default&instance=' + instance + "&rnd=" + Math.random();
	ifr.attr('src',url);
	ifr.attr('zIndex',50);
	
	jQ('#usropt').show();
}

function closeusroptions()
{
	jQ(parent.document).find('#usropt').hide();
}


function loadbar(openclose, imgname) 
{
	if (openclose == "O") 
	{ 
		flipper = 'O'; 
		
		document.images[imgname].src = '/nexuspublic/images/closebar.gif'; 
		document.images[imgname].alt = "Hide Left Column"; 
		
		jQ('#navbar2').attr('width','165px');
		
	}
	else 
	{
		flipper = 'C'; 
		
		document.images[imgname].src = '/nexuspublic/images/openbar.gif'; 
		document.images[imgname].alt = "Show Left Column"; 
		
		jQ('#navbar2').attr('width','');
	} 
	
	loadcalendars(openclose);
}

//refresh the calendar portlet
function cal_redisplay(framename, instance)
{
	jQ('#auxframe', top.document).hide();
	
	calframe = jQ('#'+framename, top.document);
	
	//prevent issues when the calendar frame cant be found
	if(calframe.length == 0) return;
	
	var calwdw = jQ(calframe[0].contentWindow.document);

	var thismon = calwdw.find('#thismon').val();
	var thisyear = calwdw.find('#thisyear').val();
	var instance = calwdw.find('#instance').val();
	var viewby =  calwdw.find('#viewby').val();
	var viewtype = calwdw.find('#viewtype').val();
	var selectedday = calwdw.find('#selectedday').val();

	pagetoload = 'NXMCAL.pgm?task=default&instance=' + instance + '&MONTH=' + thismon + '&YEAR=' + thisyear + '&DAY=' + selectedday + '&viewby=' + viewby + '&viewtype=' + viewtype + "&rnd=" + Math.random();	
	calframe.attr('src',pagetoload);
}

//RTC 20090123: refactor to use jQuery event binding
//function changeappt(apptnbr, e)
function changeappt(ev)
{
	//substring the apptnumber out of the id (in the form chgappt####)
	var apptnbr = ev.target.id.substring(7); 
	
	var framename = window.name;

	var parentflg = 'N';
	jQ('#auxinfo',parent.document).css('visibility','');
	var ifr = jQ('#auxframe', parent.document);
	if (ifr[0] == null)
	{
		ifr = jQ('#apptframe', parent.document);
		parentflg = 'Y';
	}
	
	var instance = jQ('#instance').val();
	var curtime = jQ('#currenttime').val();
	
	var popupSize = 600;
	
	ifr.css('height',popupSize + 'px');
	ifr.css('width',popupSize + 'px');
	
	
	var frameobj = jQ('#'+this.name, parent.document);

	var y = ev.pageY;
	var x = ev.pageX;
	
	if ((600 + x) > parent.document.body.scrollWidth)	
	{
		x = (parent.document.body.scrollWidth - 600) - 10;
	}
	
	// RTC 20080908: frames were removed
	//y = top.frames['block_page'].document.body.scrollTop + 5;
	y = parent.document.body.scrollTop + 5;
	
	ifr.css('left',x+'px');
	ifr.css('top',y+'px');
	
	var url = 'nxwappts.pgm?TASK=BEGINCHG&TDSENU=' + apptnbr + '&instance=' + instance + '&TIMBIT=' + curtime + "&framename=" + framename + "&rnd=" + Math.random();
	ifr.attr('src',url);
	ifr.show();
}

function rmvprivate()
{
	//document.all.TDSHRU.checked = "";
}

/* RTC 20081217 refactoring
function addpopup(day,time, e) 
{ 
	var ifr = jQ(parent.document).find('#auxframe')[0];
	var instance = jQ('#instance').val();
	
	
	var framename = jQ(parent.document).find('#'+this.name)[0];
	var event = e;
	
	var popupSize = 600;
	
	jQ(ifr).css('height',popupSize + 'px');
	jQ(ifr).css('width', popupSize + 'px');
	
	//var y = xl_FindPosY(framename) + event.y + 10;
	//var x = xl_FindPosX(framename) + event.x;
	var y = e.pageY;
	var x = e.pageX;
	
	if ((600 + x) > parent.document.body.scrollWidth)	
	{
		x = (parent.document.body.scrollWidth - 600) - 10;
	}
	
	// RTC 20080908: removed frames, so this is no longer valid
	//y = top.frames['block_page'].document.body.scrollTop + 5;
	y = parent.document.body.scrollTop + 5;
	
	jQ(ifr).css('left',x + 'px');
	jQ(ifr).css('top',y + 'px');
	
	if (time == null)
	{
		time = '';
	}
	
	var url = 'nxwappts.pgm?newdate=' + day + '&instance=' + instance + '&newtime=' + time + "&framename=" + this.name + "&rnd=" + Math.random();
	
	jQ(ifr)[0].src = url;
	jQ(ifr).css('zIndex',50);
}
*/
function addpopup(ev) 
{ 
	var day = ev.target.id.substring(3);
	var framename = window.name;
	
	var ifr = jQ(parent.document).find('#auxframe');
	var instance = jQ('#instance').val();
	
	var popupSize = 600;
	
	ifr.css('height',popupSize + 'px');
	ifr.css('width', popupSize + 'px');
	
	var x = ev.pageX;
	if ((popupSize + x) > parent.document.body.scrollWidth)	
	{
		x = (parent.document.body.scrollWidth - popupSize) - 10;
	}
	
	// TEH 20090921 - Position relative to cursor now
	//var y = parent.document.body.scrollTop + 5;
	var y = ev.pageY + 5;
	
	ifr.css('left',x + 'px');
	ifr.css('top',y + 'px');
	
	if (typeof(time) === undefined)
	{
		var time = '';
	}
	
	var url = 'nxwappts.pgm?newdate=' + day + '&instance=' + instance + '&newtime=' + time + "&framename=" + framename + "&rnd=" + Math.random();
	
	ifr.attr('src',url);
	ifr.css('zIndex',50);
	ifr.css('visibility', 'visible');
	ifr.show();
}
// end RTC 20081217

function addpopup2(day,time) 
{ 
	var ifr = jQ(top.document).find('#auxframe');
	var instance = jQ('#instance').val();
	
	ifr.css('height',600);
	ifr.css('width', 600);
	ifr.css('left', 15 + 'px');
	ifr.css('top', 15 + 'px');
	
	if (time == null)
	{
		time = '';
	}
	
	var url = 'nxwappts.pgm?newdate=' + day + '&instance=' + instance + '&newtime=' + time + "&rnd=" + Math.random();
	
	ifr.attr('src', url);
	ifr.css('zIndex',50);
	ifr.css('visibility', 'visible');
	ifr.show();
}

function daypopup(day) 
{ 
	var thismon = jQ('#thismon').val();
	var thisyear = jQ('#thisyear').val();
	var instance = jQ('#instance').val();
	var viewby = jQ('#viewby').val();
	var viewtype = jQ('#viewtype').val();
	
	var ifr = jQ('#dayframe');
	var instance = jQ('#instance').val();
	
	// ifr.height = 317
	jQ(ifr).css('height','317px');
	jQ(ifr).css('left','15px');
	jQ(ifr).css('top','15px');
	
	var url = 'NXMCAL.pgm?task=daymode&singleday=Y&instance='+ instance + '&MONTH=' + thismon + '&YEAR=' + thisyear + '&DAY=' + day + '&viewby=' + viewby + '&viewtype=D' + "&rnd=" + Math.random();

	jQ(ifr)[0].src = url;
	jQ(ifr).css('zIndex',50);
	
	jQ('#daypopup').show();
	
	adjustParent();
}


function displayDate(day, month, year, rtnform, rtnbox, datfmt, e) 
{
	var instance = jQ('#instance').val();
	var url =  "nxclsl.pgm?TASK=PREDRAW&DAY=" + day + "&MONTH=" + month + "&YEAR=" + year +"&RTNFORM=" + rtnform + "&RTNTEXTBX=" +rtnbox + "&RTNDATFMT=" + datfmt + "&instance=" + instance + "&rnd=" + Math.random();
	
	//var event = xl_event();
	var event = e;
	
	var ifr = jQ('#usrgrpframe');
	jQ(ifr).css('height', '185px');
	jQ(ifr).css('width', '185px');
	
	jQ(ifr).css('left', event.x + 'px');
	jQ(ifr).css('top', (event.y + 15) + 'px');
	
	jQ(ifr)[0].src = url;
	jQ(ifr).css('zIndex',50);
	
	//usrgrppopup.style.display = "";
	jQ('#usrgrpopup').show();
}

function dltdisplay(dltallowed) 
{
	if (dltallowed == "Y") 
	{
		jQ('#display2').show();
	} 
	else 
	{
		jQ('#display2').hide();
	}
}

function SelectDate(day, month, year, rtnform, rtnbox, datfmt) 
{
	var instance = document.inpform.instance.value;
	var url =  "nxclsl.pgm?TASK=PREDRAW&DAY=" + day + "&MONTH=" + month + "&YEAR=" + year +"&RTNFORM=" + rtnform + "&RTNTEXTBX=" +rtnbox + "&RTNDATFMT=" + datfmt  + "&instance=" + instance + "&rnd=" + Math.random();
		
	var ifr = jQ('#usrgrpframe');
	jQ(ifr).css('left',  jQ('#seldate').css('left') );
	jQ(ifr).css('top', jQ('#seldate').css('top') );
	
	jQ(ifr).css('height', '185px');
	jQ(ifr).css('width', '185px');
	
	jQ(ifr).attr('src',url);
	jQ(ifr).css('zIndex',50);
	
	jQ('#usrgrppopup').show();
}

function ResetRBs(chkbox) 
{ 
	if (chkbox.value == "P") 
	{ 
		if(document.inpform) 
		{ 
			for (var i=0; i < length; i++) 
			{ 
				var element = elements[i]; 
				if (element.type == 'radio') 
				{ 
					if (element.value == "N") 
					{
						element.checked  = true; 
					} 
					else 
					{ 
						element.checked = false; 
					}	
				}
			}
		}
	}
}

function setPrivorPub() 
{
	if(document.inpform) 
	{ 
		TDSHRU.value="P"; 
		for (var i=0; i < length; i++) 
		{ 
			var element = elements[i]; 
			if (element.type == 'radio' && element.value != "N") 
			{ 
				TDSHRU.checked = false; 
				break;
			}
		}
	}
}

/**************************************** End Calendar Functions *********************************************/

function navigator_KeyDown(e)
{

	if(e.keyCode == 27)	
	{
		closeMenu();
		
		if (listType != 'V')
		{

			jQ(window).hide();
			
			return false;
		}
		
		return false;
	}
	else
	{
		return true;
	}
}

function menu_KeyDown(e)
{
	if(e.keyCode == 13)
	{
		searchdoc();
		return false;
	}
	
	if (e.keyCode == 27)
	{
		// RTC 20080908: removed frames so this wont work
		//top.frames['block_page'].closeWindows();
		parent.closeWindows();
		return false;	
	}
	
	return true;
}

function mpage2_KeyDown(event)
{
	if(event.keyCode == 27)
	{	
		parent.closeWindows();
		return false;	
	}
	
	return true;
}

function popup_KeyDown(e) 
{
	if(e.keyCode == 27)
	{		
		jQ(window).hide();
		return false;
		
	}
	return true;
}

function mpage_KeyDown(e) 
{
	if(e.keyCode == 27)
	{
		closeWindows();	
		return false;
	}
	else
	{
		return true;
	}
}

// closes all popup windows on the nxmenu top level page
function closeWindows()
{
	//RTC 20080912: only change visibility so that dimensions of content is retrievable
	jQ('#favoritesdiv').css('visibility','hidden');
	jQ('#helpdiv').css('visibility','hidden');
	jQ('#searchwow').css('visibility','hidden');
	jQ('#menudisplay').css('visibility','hidden');
	jQ('#submenudisplay').css('visibility','hidden');
	jQ('#auxinfo').css('visibility','hidden');
	jQ('#quickadd2').css('visibility','hidden');
	jQ('#quickadd').css('visibility','hidden');
}


function sbmpage(ordbyval)
{
	var frm = document.headfrm;
	frm.ordby.value=ordbyval;
	frm.submit();
}				 

function loadmnuauth(rrn, e)
{
	var url = 'NXMNUMNT.pgm?task=mnuauth&mnurrn=' + rrn + '&rnd=' + Math.random();
	popup('auxframe',url,450,600,'float', e,-35,'auxinfo');
	
}

function loadmnuitauth(rrn, e)
{
	var url = 'NXMNUMNT.pgm?task=mnuitauth&mnurrn=' + rrn + '&rnd=' + Math.random();
	popup('auxframe',url,450,600,'float',e,-35,'auxinfo');
}	



/**************************************** Start Admin functions *****************************************/
function sendEmail()
{
	// RTC 20080908: jQuery replacement of xl_ functions
	//var myurl = 'nxchgpg.pgm?task=sendemail&docnum=' + parent.xl_GetObj('lnknum').value + "&email=" + document.inpform.email.value + "&emaildesc=" + document.inpform.emaildesc.value + "&emailsub=" + document.inpform.emailsub.value + "&emailcc=" + document.inpform.emailcc.value + "&rndnum=" + randnum;
	//xl_AjaxUpdate(myurl, mydiv);	
	
	nx_closepopup();
	
	var url = 'nxchgpg.pgm?task=sendemail&docnum=' + jQ('#lnknum').val() + "&email=" + document.inpform.email.value + "&emaildesc=" + document.inpform.emaildesc.value + "&emailsub=" + document.inpform.emailsub.value + "&emailcc=" + document.inpform.emailcc.value;
	
	jQ.get(url);

}

function emailECM(ev)
{			
	//RTC 20080821: moving non-page construction functionality from nxmpage to nxchgpg
	//var url = 'nxmpage.pgm?task=email&docnum=' + ecmnode + "&rndnum=" + randnum;
	nx_closepopup();

	var url = 'nxchgpg.pgm?task=email&docnum=' + jQ('#lnknum').val() + "&rnd=" + Math.random();
	
	popup('auxframe' ,url,225,600,'float',ev,20,'auxinfo');
}

function printECM()
{
	var docwdw = jQ('#ifrmviewdoc')[0].contentWindow;
	if (docwdw && docwdw.auxprint)
	{
		docwdw.auxprint();
	}
	else
	{
		frames["ifrmviewdoc"].focus();
		frames["ifrmviewdoc"].print();
	}
}

// TODO: This could probably be done much more elegantly by filtering by a class instead of id substring
//RTC 20081210: refactor edit mode
function editmode(editflag)
{
	if (editflag == 'Y')
	{
		dragOptions = {
			cursorAt: {top: 10, left: 20},
			ghosting: true,
			opacity: 0.5,
			fx: 300,
			helper: 'clone',
			//handle: '.draghandle',
			handle: '.topborder',
			start: collapsePortlets,
			stop: expandPortlets
		};
		dropOptions = {
			accept: '.portletBlock',
			hoverClass: 'movespot_hover',
			drop: dropHandler,
			tolerance: 'pointer'
		};
		
		jQ('.portletBlock').draggable(dragOptions);
		jQ('.movespot').droppable(dropOptions);
		jQ('.topborder').addClass('draghandle');
	}
}

//RTC 20081211: handle when a portlet has been dragged to a new location
//note: 'this' refers to the drop target, ui.draggable.element refers to the dragged element
function dropHandler(ev, ui)
{
	//determine column and sequence of destination
	var placeHere = jQ(this); //destination placement element
	var movePort = jQ(ui.draggable); //source portlet for move
	
	var colObj = placeHere.parent();
	var column = colObj.attr('id').substring(3);
	var sequence = placeHere.attr('id').substring(9);

	//alert('dragged '+ movePort.attr('id') +' onto '+ placeHere.attr('id') + '(col: '+column+', seq: '+sequence+').');
				
	//Update the server with the new positions
	var url = 'nxchgpg.pgm?task=moveinst&plytrrn='+ movePort.attr('id') + '&column=' + column + '&sequence=' + sequence; 
	jQ.get(url);

	//Update the current page layout & ids to match new sequence
	var portCopy = movePort.clone(true);
		
	//insert the clone before the target location
	portCopy.insertBefore(placeHere);
	
	//bind the new clone as draggable
	portCopy.draggable(dragOptions);
	
	//remove the source portlet
	jQ(movePort).remove();
	
	//resequence the moveHere element's id
	var incby = parseInt( placeHere.attr('id').substring(12)) + 1;
	if (!incby)
	{
		incby = 1;
	}
	placeHere.attr('id', placeHere.attr('id').substring(0,12) + incby );

	
}

function collapsePortlets(ev, ui)
{
	jQ('.portletBlock>.border').hide();
	jQ('.movespot').addClass('movespot_active');
	jQ(ui.helper).find('.options').hide();
}
function expandPortlets(ev, ui)
{
	jQ('.portletBlock>.border').show();
	jQ('.movespot').removeClass('movespot_active');
	jQ(ui.helper).find('.options').show();
}


function disabletext(e)
{
	return false
}

function reEnable()
{
	return true
}

//RTC 20081202: refactor loaddetails to accept a single parm which is a complex object
//function loaddetails(instrrn, plytrrn, pgrrn, docnum, skinspath, fromPgm, e)
function loaddetails(e)
{
	var parms = e.data;

	/* RTC 20081202: construct the url using the parms array
	// RTC 20080821: moved this functionality to nxconfig
	//var url = 'nxmpage.pgm?task=loaddet&pgrrn=' + pgrrn + '&plytrrn=' + plytrrn + '&instrrn=' + instrrn + '&docnum=' + docnum + '&skinspath=' + skinspath + '&fromPgm=' + fromPgm + "&rand=" + randnum;
	var url = 'nxconfig.pgm?task=loaddet&pgrrn=' + pgrrn + '&plytrrn=' + plytrrn + '&instrrn=' + instrrn + '&docnum=' + docnum + '&skinspath=' + skinspath + '&fromPgm=' + fromPgm;
	
	if (fromPgm == 'NXINSTMNG')
	*/
	var url = 'nxconfig.pgm?task=loaddet&pgrrn='+ parms.pg + '&plytrrn=' + parms.plyt + '&instrrn=' + parms.inst + '&docnum=' + parms.doc + '&skinspath=' + parms.pth + '&fromPgm=' + parms.frm;
	
	if(parms.frm == 'NXINSTMNG')
	// end RTC 20081202
	{	
		parent.popup('auxframe', url,0,600,'float',e,35,'auxinfo');
	}
	else
	{
		popup('auxframe', url,0,600,'float', e,15,'auxinfo');
	}
}

// RTC 20090122: wrap loaddetails for simplified use from work with portlets page
function loaddetails2(ev)
{
	var portletrrn = ev.target.id.substr(5); //remove the rrn from ids in the format 'lddet000'
	var data = {'inst': portletrrn, 'frm': 'NXINSTMNG'};

	ev.data = data;
	
	loaddetails(ev);
}

function addpage(e)
{
	nx_closepopup(); 
	
	//RTC 20080911: moved add page to nxchgpg program
	//var url = 'nxmpage.pgm?task=newpage&pgrrn=' + pgrrn + '&pagetype=' + document.docform.pagetype.value + '&grpusrnbr=' + document.docform.grpusrnbr.value;
	var url = 'nxchgpg.pgm?task=newpage&pgrrn=&pagetype=' + jQ('#pagetype').val() + '&grpusrnbr=' + jQ('#grpusrnbr').val();
	popup('auxframe',url,200,450,'right',e,15,'auxinfo');		
}

//TODO: was removed from nxpages, check to see if this is used elsewhere and remove if possible
function addpage2(e)
{
	nx_closepopup();
	
	//RTC 20080821: moving non-page construction functionality from nxmpage to nxchgpg
	//var url = 'nxmpage.pgm?task=newpage&pgrrn=' + pgrrn + '&pagetype=' + parent.document.docform.pagetype.value + '&grpusrnbr=' + parent.document.docform.grpusrnbr.value + "&rand=" + randnum
	var url = 'nxchgpg.pgm?task=newpage&pgrrn=&pagetype=' + jQ('#pagetype').val() + '&grpusrnbr=' + jQ('#grpusrnbr').val();
	
	parent.popup('auxframe',url,200,450,'left',e,35,'auxinfo');	
}

// used by nxpages, this function will load the selected page 
function loadpage(ev)
{
	var pgrrn = ev.target.id.substr(8);
	top.location.href = 'nxmenu.pgm?pgrrn=' + pgrrn;	
}

/* RTC 20080108: rewrote loadauthorities to require fewer parameters
   and work with jQuery event binding.
function loadauthorities(instrrn, fromPgm, e)
{
	nx_closepopup(); 
	
	var url = 'nxinstmng.pgm?task=loadauth&instrrn=' + instrrn;
	
	if (fromPgm == 'NXINSTMNG')
	{
		parent.popup('auxframe',url,450,600,'float',e,35,'auxinfo');
	}
	else	
	{
		popup('auxframe' ,url,450,600,'float',e,10,'auxinfo');
	}
}
*/

//RTC 20090108: replace loadauthorities function used by the edit page layout portlet banner icons
function loadauthorities(ev)
{
	nx_closepopup();
	
	//get target portlet rrn from the clicked div id
	var portletrrn = ev.target.id.substring(6);

	var url = 'nxinstmng.pgm?task=loadauth&instrrn=' + portletrrn;
	popup('auxframe' ,url,450,600,'float',ev,10,'auxinfo');
}


/*RTC 20081209: change function so that the values are retrieved off the page
function addportlet(plytrrn, pgrrn, docnum, skinspath, e)
{
	//RTC 20080821: moving non-page construction tasks to nxchgpg
	var url = 'nxchgpg.pgm?task=newportlet&pgrrn=' + pgrrn + '&plytrrn=' + plytrrn + '&docnum=' + docnum + '&skinspath=' + skinspath;
	
*/
function addportlet(e)
{
	//RTC 20080821: moving non-page construction tasks to nxchgpg
	var url = 'nxchgpg.pgm?task=newportlet&pgrrn='+ jQ('#pgrrn').val() 
	        + '&plytrrn='+ jQ('#plytrrn').val() + '&docnum=' + jQ('#lnknum').val()
	        + '&skinspath=' + jQ('#skinspath').val();
// end RTC 20081209

	nx_closepopup();
	
	popup('auxframe',url,150,400,'float',e,15,'auxinfo');
}

//RTC 20090205: change function to retrieve data from the link element the event was fired from
//function pageproperties2(pgrrn, e)
function pageproperties2(ev)
{
	nx_closepopup();

	var pgrrn = ev.target.id.substring(5); //element ids are in the form chgpg#####
	
	
	//RTC 20080821: moving non-page construction functionality from nxmpage to nxchgpg
	//var url = 'nxmpage.pgm?task=pageprop&wrkpages=Y&pgrrn=' + pgrrn + "&rand=" + randnum;
	var url = 'nxchgpg.pgm?task=pageprop&wrkpages=Y&pgrrn=' + pgrrn;
	
	parent.popup('auxframe',url,200,300,'float',ev,35,'auxinfo');
}


/*RTC 20081209: changing the function to get the values from the page
function pageproperties(pgrrn, docnum, skinspath,e)
{
	// RTC 20080821: Removing non-page construction functionality to nxchgpg
	var url = 'nxchgpg.pgm?task=pageprop&pgrrn=' + pgrrn + '&docnum=' + docnum + '&skinspath=' + skinspath;
*/
function pageproperties(e)
{
	// RTC 20080821: Removing non-page construction functionality to nxchgpg
	var url = 'nxchgpg.pgm?task=pageprop&pgrrn='+ jQ('#pgrrn').val() + '&docnum='
			+ jQ('#lnknum').val() + '&skinspath=' + jQ('#skinspath').val();
// end RTC 20081209
	
	nx_closepopup(); 
		
	popup('auxframe',url,200,300,'right',e,15,'auxinfo');
}

//RTC 20081202: refactored the function to use event and jQuery normalization
//RTC 20081208: add zIdx parm to allow specification of popup zIndex parameter
function popup(frameid,url,height,width,position,event,topoffset,divname,zIdx)
{
	var ifr = jQ(nx_gettopframe(frameid));
	
	var xpos = event.pageX;
	var ypos = event.pageY;
	
	if(zIdx == undefined)
	{
		var zIdx = 102;
	}
	ifr.css('zIndex', zIdx);
	
	// RTC 20080821: fixing offset which changed when removing frames
	//ifr.style.top =  (y + topoffset) + 'px';
	if ( jQ('#nexusmain').offset())
	{
		topoffset -= jQ('#nexusmain').offset().top;
	}
	ifr.css('top', (ypos + topoffset) + 'px');
	

	
	//RTC 20080821: use jQuery for cross browser support
	ifr.load( function()
	{
		setsize(frameid,height,width,position,xpos,ypos,divname);
	});
	
	ifr.attr('src', url);
}

function hideframe(frameid) 
{
	var ifr = jQ('#' + frameid);
	ifr.css('height', '0px');
	ifr.css('visibility','hidden');
}

function closeframe(frameid)
{
	var ifr = jQ('#' + frameid);
	ifr.hide();
}

function setsize(frameid, height, width, position, thiseventleft,topoffset, divid)
{		
	var ifr = nx_gettopframe(frameid);
	jQ(ifr).css('height', height + 'px');
	jQ(ifr).css('width', width + 'px');
	
	if (divid != '')
	{
		try
		{
			var optifr = jQ(ifr.document).find('#optframe')[0];
			
			var height = 0;
			var width = 0;
		
			if (optifr && optifr.contentWindow)
			{
				var ifrwdw = ifr.contentWindow;
			
				jQ(ifrwdw).find('#pagedsp1').hide();
				jQ(ifrwdw).find('#pagedsp2').show();
				
				height = ifrwdw.document.body.scrollHeight + 20;
				width  = ifrwdw.document.body.scrollWidth;
				
				jQ(ifrwdw).find('#pagedsp1').show();
				jQ(ifrwdw).find('#pagedsp2').hide();	
			}
			
			// set height to the largest value we could find
			if (ifr.contentWindow.document.body.scrollHeight > jQ(ifr).height() )
			{
				ifr.style.height = ifr.contentWindow.document.body.scrollHeight + 5 + 'px';
			}
			else
			{
				ifr.style.height = (ifr.style.height + 30) + 'px';
			}
		
			//set width to the largest value we could find
			if (ifr.contentWindow.document.body.scrollWidth > jQ(ifr).width() )
			{
				ifr.style.width = ifr.contentWindow.document.body.scrollWidth + 'px';
			}
			else
			{
				ifr.style.width = (ifr.style.width + 30) + 'px';
			}
			
		}
		catch(err)
		{
			ifr.style.height = ifr.contentWindow.document.body.scrollHeight + 'px';
			ifr.style.width = ifr.contentWindow.document.body.scrollWidth + 20 + 'px';
		}
	}
	
	
	if (position == 'left')
	{
		ifr.style.left = 25 + 'px';
	}
	else if (position == 'right')
	{
		ifr.style.left = (document.body.offsetWidth - parseInt(ifr.style.width)) - 25 + 'px';	
	}
	else if (position == 'float')
	{
		var x = thiseventleft + document.documentElement.scrollLeft + document.body.scrollLeft;
		if ((parseInt(ifr.style.width) + x) > document.body.offsetWidth)
		{
			ifr.style.left = (x - parseInt(ifr.style.width)) + 'px';
		}
		else
		{
			ifr.style.left = x + 'px';
		}
	}
	
	jQ(ifr).show();
	jQ(ifr.parentNode).css('visibility','visible');
} 


function portletDetails(e)
{
	jQ('#pg1').addClass('tabsel');
	jQ('#pg2').replaceClass('tab');
	
	jQ('#pagedsp1').show();
	jQ('#pagedsp2').hide();
	
	adjustoptions();
	
	//RTC 20081202: prevent repositioning within page
	return false;
}

function portletOptions(e)
{	
	jQ('#pg1').replaceClass('tab');
	jQ('#pg2').addClass('tabsel');
	
	jQ('#pagedsp1').hide();
	jQ('#pagedsp2').show();
	
	adjustoptions();
	
	//RTC 20081202: prevent repositioning within page
	return false;
}

function adjustoptions()
{	
	var ifr = jQ(parent.document).find('#auxframe')[0];
	var optifr = jQ('#optframe')[0];
	
	try 
	{
		if(ifr)
		{
			jQ(optifr).height( optifr.contentWindow.document.body.scrollHeight );
			if (optifr.style.height > ifr.style.height)
			{
				ifr.style.height = parseInt(optifr.style.height) + 20 + 'px';
			}


			optifr.style.width = optifr.contentWindow.document.body.scrollwidth + 'px';
			if (parseInt(optifr.style.width) > parseInt(ifr.style.width))
			{
				ifr.style.width = parseInt(optifr.style.width) + 20 + 'px';
			}
		}
		
		if(parent.adjustIFrame)
		{
			parent.adjustIFrame(optifr);
		}
		
	}
	catch(err)
	{
		try
		{
			if (parent.adjustIFrame) parent.adjustIFrame(window);
			if (parent.parent.adjustIFrame) parent.parent.adjustIFrame(parent.window);
		}
		catch(err)
		{ }
	}
}


function groupselect()
{
	
	try 
	{
		jQ('#copypage').show();
	}
	catch(err)
	{
	}
	
	var returnValue = '';
	if (document.inpform.task.value == 'endaddpage')
	{
		returnValue = getSelectedRadioValue(document.forms[0].pagetype);
	}
	else
	{
		returnValue = document.inpform.pagetype.value;
	}
	
	if (returnValue == 'G')
	{
		jQ('#selGroup').show();
		
		if (document.inpform.task.value == 'endaddpage')
		{			
			jQ('#pagetype').show();
			jQ('#pageorder').show();
		}
	}	
	else if (returnValue == 'U')
	{
		jQ('#selGroup').hide();
		
		if (document.inpform.task.value == 'endaddpage')
		{			
			jQ('#pagetype').show();
			jQ('#pageorder').show();
		}
	}
	else if (returnValue == 'T')
	{	
		jQ('#selGroup').hide();
		jQ('#ECM').hide();
		
		if (document.inpform.task.value == 'endaddpage')
		{
			document.inpform.addpagetype.selectedIndex = 0;		
			document.inpform.wnode.value = 0;
						
			jQ('#pagetype').hide();
			jQ('#pageorder').hide();
		}
	}
}

function end_add(pgrrn, node)
{
	if (node == 0)
		top.location.href = 'nxmenu.pgm?pgrrn=' + pgrrn;
	else
		top.location.href = 'nxmenu.pgm?docnum=' + node;
}

function endPageAdd()
{
	var errorflg = val_InpChar('addname', 'Name', 'check_name','N');
	
	if (errorflg != 'Y')
	{
		document.inpform.submit();
	}
}

function updinst(fromPgm)
{
	var errorflg = val_InpChar('WIWANA', 'Name', 'check_name','N');
	var errorflg2 = val_InpChar('WIWADE', 'Description', 'check_description','N');
	
	if ((errorflg != 'Y') && (errorflg2 != 'Y'))
	{
		// RTC 20080912: only change visibility, because changing display affects dimensions
		//jQ(parent.document).find('#auxinfo').hide();
		jQ(parent.document).find('#auxinfo').css('visibility','hidden');
	
		
		document.inpform.submit();
		
		if (fromPgm == 'NXINSTMNG')
		{
			var ifr = jQ(parent.document).find('#instframe')[0];
			ifr.src = 'nxinstmng.pgm';
		}
		else
		{
			if ( jQ('#docnum').val() == 0)
			{
				top.location.href = 'nxmenu.pgm?pgrrn=' + jQ('#pgrrn').val();
			}
			else
			{
				top.location.href = 'nxmenu.pgm?docnum=' + jQ('#docnum').val();
			}
		}
	}
}

function updprop(wrkpages)
{
	var errorflg = val_InpChar('PMPANA', 'Page Name', 'check_name','N');
	
	if( ( parseInt(jQ('#PMCOWI').val())
		 +parseInt(jQ('#PMCOW1').val())
	 	 +parseInt(jQ('#PMCOW2').val())
	  	 +parseInt(jQ('#PMCOW3').val())
	  	) > 100)
	{
		
		jQ('.colwidthrow').addClass('error');
		
		alert('Column width\'s exceeds 100%. Enter column width\'s that in total do not exceed 100%.');
		errorflg = 'Y';
	}
	
	
	if (errorflg != 'Y')
	{
		//RTC 20080912: only change visibility so dimensions are intact
		//parent.auxinfo.style.display = "none";
		jQ(parent.document).find('#auxinfo').css('visibility','hidden');
		
		jQ('#inpform')[0].submit();
		
		if (wrkpages == 'Y')
		{
			// TODO: get doc rrn by element id
			jQ(parent.document).find('#instframe2')[0].src = 'NXPAGES.pgm?pgrrn=' + parent.document.docform.pgrrn.value;
		}
		else
		{
			if ( jQ('#docnum').val() == 0)
			{
				top.location.href = 'nxmenu.pgm?pgrrn=' + jQ('#pgrrn').val();
			}
			else
			{
				top.location.href = 'nxmenu.pgm?docnum=' + jQ('#docnum').val();
			}
		}
	}
}

function crtportlet()
{
	
	if (document.inpform.instnbr.options[document.inpform.instnbr.selectedIndex].value == 0)
	{	
		var errorflg = val_InpChar('newname', 'Name', 'check_name','N');
		var errorflg2 = val_InpChar('newdesc', 'Description', 'check_description','N');	
	
	}
	
	if ((errorflg != 'Y') && (errorflg2 != 'Y'))
	{
		// RTC 20080912: only change visibility so dimensions are left intact
		//jQ(parent.document).find('#auxinfo').hide();
		jQ(parent.document).find('#auxinfo').css('visibility','hidden');
		
		document.inpform.submit();
		
		if (document.inpform.docnum.value == 0)
		{
			top.location.href = 'nxmenu.pgm?pgrrn=' + jQ('#pgrrn').val();
		}
		else
		{
			top.location.href = 'nxmenu.pgm?docnum=' + jQ('#docnum').val();
		}
	}
}



function showdet(portlet)
{
	jQ('#'+portlet).toggle();
}

// TODO: replace this with css 
function reverseflipperimg() 
{ 
	if (flipper == '')
	{
		jQ('#colhider')[0].src = '/nexuspublic/images/closebarreverse.gif';
	}
	else
	{
		jQ('#colhider')[0].src = '/nexuspublic/images/openbarreverse.gif';
	}
}

function flipperimg() 
{ 
	if (flipper == '')
	{
		jQ('#colhider')[0].src = '/nexuspublic/images/closebar.gif';
	}
	else
	{
		jQ('#colhider')[0].src = '/nexuspublic/images/openbar.gif';
	}
}


function insidepageurl(newurl) 
{	
	jQ('#insert').show();
	jQ('#dyniframe')[0].src = newurl;
}

function fnBuildMsg(iMsg, iBtns)
{
	var msgText = "<span class='alert'><center><br>" + iMsg + "<br><br>";
	
	x = iBtns.search("~!");
	while (x != -1)
	{
		iBtns = iBtns.substr(x+2);
		y = iBtns.search("~!");
		if (y != -1)
		{
			btnName = iBtns.substr(0, y);
			iBtns = iBtns.substr(y);
			x = iBtns.search("~!");
			
			iBtns = iBtns.substr(x+2);
			y = iBtns.search("~!");
			btnAction = iBtns.substr(0, y);
			iBtns = iBtns.substr(y);
			
			msgText = msgText + '<input class=\'msgBtn\' type=\'button\' value=\''+ btnName +'\' onclick="'+ btnAction+'; window.close();"> ';		
		}
		x = iBtns.search("~!");
	}
	return msgText;
}

function removep(instnum, plytrrn, pgrrn, fromPgm, usage, authflg)
{	
	//RTC 20080821: moving non-page construction functionality from nxmpage to nxchgpg
	//var url = 'nxmpage.pgm?task=rmvportlet&pgrrn='+ pgrrn + '&plytrrn='+ plytrrn + '&rand=' + random_num; 
	var url = 'nxchgpg.pgm?task=rmvportlet&pgrrn='+ pgrrn + '&plytrrn='+ plytrrn; 
	
	if (fromPgm == 'NXINSTMNG')
	{		
		jQ.get(url);
		jQ(parent.document).find('#instframe').attr('src','nxinstmng.pgm');
	}
	else
	{
		jQ.get(url);
		jQ('#wc'+instnum).hide();
	}
}

// RTC 20090107: remove useless parms
//function deletep(instrrn, pgrrn, usage, fromPgm, plytrrn, instnum)
function deletep(instrrn, pgrrn, fromPgm)
{
	// RTC 20080821: moved delete portlet handling to nxconfig
	//var url = 'nxmpage.pgm?task=delportlet&pgrrn=' + pgrrn + '&instrrn=' + instrrn + '&rand=' + random_num;
	var url = 'nxconfig.pgm?task=delportlet&pgrrn=' + pgrrn + '&instrrn=' + instrrn;
	
	var mydiv = '';
	
	jQ.get(url, function()
	{ 
		delChild(mydiv);
	});
	
	if (fromPgm == 'NXINSTMNG')
	{
		jQ(top.document).find('#instframe').attr('src','nxinstmng.pgm');
	}
	else
	{
		top.location.reload(true);
	}
}

function removecnf(instnum, plytrrn, pgrrn, fromPgm, usage, authflg, instrrn)
{
	return_val = confirm('Are you sure you would like to remove this portlet from the current page?');
	if(!return_val)
	{
		return;
	}
	
	/* TEH 20091001 - Users found the instance removal much too confusing so we are now just removing the portlet from the page
	//if we arent authorized to delete the portlet instance, just remove the portlet
	if(authflg != 'Y')
	{
		removep(instnum,plytrrn,pgrrn,fromPgm,usage,authflg);
	}
	else //otherwise, check if we should delete the portlet instance as well
	{		
		//only used on this one page, so prompt the user if they want to delete the instance
		if((usage == 1) 
		&& (fromPgm == ''))
		{
			return_val = confirm('This Portlet is currently only used on this page. Do you want to delete this Portlet? (There is no recovery from this operation)');
		}
		else //used on multiple pages, check if it should be removed from all of them
		{
			return_val = confirm('This Portlet is currently used on ' + usage + ' pages. Are you SURE you want to delete this Portlet? (You cannot recover deleted Portlet instances)'); 
		}

		//if user answered yes, delete the portlet (and remove all places it is used)
		if (return_val)
		{
			// RTC 20090107: remove unused parms
			//deletep(instrrn,pgrrn,usage,fromPgm,'',instnum);
			deletep(instrrn, pgrrn, fromPgm)
		}
		else //otherwise, just remove it from the current page
		{
			removep(instnum,plytrrn,pgrrn,fromPgm,usage,authflg);
		}
	}
	*/
	// remove the portlet from the current page
	removep(instnum,plytrrn,pgrrn,fromPgm,usage,authflg);
	// ... end TEH 20091001
}

//RTC 20090107: changed deleteportlet to better suit its purpose as the deleteportlet handler
// for the 'Work with Portlets' screen. When using this screen we are not removing the portlets
// from a page, so the messages can be clearer. Also, the user will now be notified when they
// attempt to remove a single instance portlet class, which is not allowed from that screen.
function deleteportlet(instrrn, pgrrn, usage, fromPgm)
{
	//check if the portlet can be removed
	// TEH 20091001 - Had parameter name wrong
	//jQ.get('nxconfig.pgm?task=chkremove&instnum='+instrrn, function(resp)
	jQ.get('nxconfig.pgm?task=chkremove&instrrn='+instrrn, function(resp)
	{	
		if(resp == "NOTMULTIINSTANCE")
		{
			alert("This portlet class contains only a single instance, and cannot be removed using this interface. If you are sure you would like to remove the portlet instance anyway, you can do so through the admin pages 'manage portlet classes' interface.");
			return;
		}
		
		return_val = confirm('This Portlet is currently used on ' + usage + ' pages. Are you SURE you want to delete this Portlet? (There is no recovery from this operation)'); 
		if (return_val)
		{
			//RTC 20090107: removed unused parms
			//deletep(instrrn,pgrrn,usage,fromPgm,'',instrrn);
			deletep(instrrn,pgrrn,fromPgm);
		}	
	});
}

function delChild(mydiv, url)
{
	// RTC 20080821: Handle single instance wadgets by not removing
	if(url == "NOTMULTIINSTANCE")
	{
		return;
	}

	jQ.get(url);
	
	// TODO: find out why this is referring to ifr at all, it would only be defined as a global because this is a callback function
	var ifr = ifr; // RTC 20081006 prevent undefined errors
	if (ifr)	
	{
		jQ('#instframe').attr('src','nxinstmng.pgm');
	}
}


function hidecolsel()
{
	if (document.inpform.cpypage.options[document.inpform.cpypage.selectedIndex].value == 0)
	{
		jQ('#addpgcolumn').show();
	}
	else
	{
		jQ('#addpgcolumn').hide();
	}
}

function vldcolno(btnval) 
{
	
	if (document.inpform.PMPACO.value < hicol)
	{ 
		var userinput = confirm('Portlets exist on columns beyond the number of columns for this page. Click OK to adjust the columns automatically, Cancel to cancel.'); 
		if (userinput == true) 
		{ 
			document.inpform.nxtorfin.value= btnval; 
			document.inpform.submit();
		}
		else 
		{ 
			return false; 
		} 
	} 	
	else	
	{
		document.inpform.nxtorfin.value= btnval; 
		document.inpform.submit();
	}
	
}

//change displayed options for add page interface depending on the selected page type
function selectpgtype()
{
	if ( jQ('#addpagetype').val() == 'ECM Document') 
	{
		jQ('#ECM').show();
		jQ('#copypage').hide();
		jQ('#addpgcolumn').hide();
	}
	else
	{		
		jQ('#ECM').hide();
		jQ('#copypage').show();
		jQ('#addpgcolumn').show();
	}
}

//confirm the deletion of a specified page and page type
function confirmPageDelete(pgrrn, pgtype)
{
	//check for an ECM Template page
	var return_val;
	if( pgtype == 'T')
	{
		return_val = confirm('You are about to permanently delete this ECM Template. If you continue all ECM content that references this Template will be effected. Do you wish to continue?');
	}
	else
	{
		return_val = confirm('You are about to permanently delete this Page. Do you wish to continue?');
	}
	
	if(return_val)
	{
		//RTC 20080821: moving non-page construction functionality from nxmpage to nxchgpg
		//var url = 'nxmpage.pgm?task=delpage&pgrrn=' + pgrrn + "&rand=" + randnum;
		var url = 'nxchgpg.pgm?task=delpage&pgrrn=' + pgrrn;

		// if we are on the work with pages screen 
		if ( jQ(parent.document).find('#pagedsp1').css('display') == 'none' )
		{
			jQ.get(url, parent.loadpages);
		}
		else
		{	
			jQ.get(url);
			top.location.href = 'NXMENU.pgm';
		}
	}
}

//RTC 20090107: confirm the user wants to delete the current page
function confirmPageDeleteCurrent()
{
	var pgtype = jQ('#pagetype').val();
	var pgrrn = jQ('#pgrrn').val();
	
	confirmPageDelete(pgrrn,pgtype);
}

function loadpages(response)
{
	if ( jQ('#pgrrn').val() == response)
	{
		top.location.href = 'NXMENU.pgm';
	}
	else
	{	
		jQ('#instframe2').attr('src','NXPAGES.pgm');
	}
}

function loadinst()
{
	jQ('#newoptions').show();
	
	//RTC 20080821: moving non-page construction functionality from nxmpage to nxchgpg
	//var url = 'nxmpage.pgm?task=selinst&classnbr=' + document.inpform.classnbr.options[document.inpform.classnbr.selectedIndex].value + '&rand=' + random_num;
	var url = 'nxchgpg.pgm?task=selinst&classnbr=' + document.inpform.classnbr.options[document.inpform.classnbr.selectedIndex].value;
	
	if (document.inpform.classnbr.options[document.inpform.classnbr.selectedIndex].innerHTML == 'ECM Navigator')
	{
		document.inpform.newwconu.selectedIndex = 1;
	}
	
	//xl_AjaxUpdate(myurl, mydiv, Receive_inst_Response); 
	jQ.get(url, Receive_inst_Response); 
}

function Receive_inst_Response(response)
{
	jQ('#instance').html(response);
	
	// TODO: add an id to instnbr and reference directly
	if (document.inpform.instnbr.options[document.inpform.instnbr.selectedIndex].value == 0)
	{
		jQ('#newoptions').show();
	}
	else
	{
		jQ('#newoptions').hide();
	}
	
	adjustoptions();
}



function instoptions()
{
	// TODO: add an id to instnbr and reference directly
	if ((document.inpform.instnbr.options[document.inpform.instnbr.selectedIndex].value == 0) && (document.inpform.instnbr.options[document.inpform.instnbr.selectedIndex].innerHTML == '*New Portlet'))
	{
		jQ('#newoptions').show();
	}
	else
	{
		jQ('#newoptions').hide();
	}
	
	setseq();
}

function closeauthwin()
{
	// RTC 20080912: only change visibility so that dimensions are intact
	//jQ('#auxinfo').hide();
	jQ('#auxinfo').css('visibility','hidden');
}

function setserver(optkey, optvalue) 
{ 
	var url = 'nxblkset.pgm?optkey='+ optkey + '&optvalue='+ optvalue; 
	// RTC 20080820: trying to resolve firefox exceptions 
	//xl_AjaxUpdate(url);
	
	jQ.get(url)
}  

function setseq() 
{
	// TODO: change newwconu, neworder to have an id and reference directly
	var column = document.inpform.newwconu.options[document.inpform.newwconu.selectedIndex].value;
	
	if (column == 5)
	{
		document.inpform.neworder.value = document.inpform.colhdr.value;
	}
	else if (column == 1)
	{
		document.inpform.neworder.value = document.inpform.colseq1.value;
	}
	else if (column == 2)
	{
		document.inpform.neworder.value = document.inpform.colseq2.value;
	}
	else if (column == 3)
	{
		document.inpform.neworder.value = document.inpform.colseq3.value;
	}
	else if (column == 6)
	{
		document.inpform.neworder.value = document.inpform.colseq4.value;
	}
	else if (column == 4)
	{
		document.inpform.neworder.value = document.inpform.colfoot.value;
	}
	
}

//page properties uses column to control visibility of relevant attributes and
// set default widths when switching the number of columns
function column() 
{
	//if page already exists
	if( jQ('#wnode').val() != 0)
	{		
		jQ('#pgcolumn').hide();
		jQ('#ECM').show();
	}
	else //otherwise creating a page, set default values
	{
		
		columndisplay();
				
		//create an array of column widths based on the number of columns
		var colwidths = new Array(4);
		switch( jQ('#PMPACO').val() )
		{
			case "1":	
					colwidths = [100,0,0,0]; 
					break; 
			case "2": 
					colwidths = [25,75,0,0]; 
					break; 
			case "3": 
					colwidths = [25,50,25,0]; 
					break; 
			default: 
					colwidths = [25,25,25,25];
					break;
		}
		
		//assign the widths to their form elements
		jQ('#PMCOWI').val( colwidths[0]);
		jQ('#PMCOW1').val( colwidths[1]);
		jQ('#PMCOW2').val( colwidths[2]);
		jQ('#PMCOW3').val( colwidths[3]);
		
		
	}
}

//page properties uses column display to control visible column width inputs
function columndisplay() 
{
	//hide all columns
	jQ('.colwidthrow').hide();
	
	
	//use fallthrough property of switch to incrementally display all the necessary columns
	switch( jQ('#PMPACO').val() )
	{
		case "4": jQ('#column4').show();
		case "3": jQ('#column3').show();
		case "2": jQ('#column2').show();
		default:  jQ('#column1').show();
	}
}

function edtpage()
{
	jQ('#pg1').addClass('tabsel');
	jQ('#pg2').replaceClass('tab');
	jQ('#pg3').replaceClass('tab');
	
	jQ('#pagedsp1').show();
	jQ('#pagedsp2').hide();
	jQ('#pagedsp3').hide();
}

function wrkportlets()
{
	jQ('#pg1').replaceClass('tab');
	jQ('#pg2').addClass('tabsel');
	jQ('#pg3').replaceClass('tab');
	
	jQ('#pagedsp1').hide();
	jQ('#pagedsp2').show();
	jQ('#pagedsp3').hide();
}

function wrkpages()
{	
	jQ('#pg1').replaceClass('tab');
	jQ('#pg2').replaceClass('tab');
	jQ('#pg3').addClass('tabsel');
	
	jQ('#pagedsp1').hide();
	jQ('#pagedsp2').hide();
	jQ('#pagedsp3').show();
}

/**************************************** End Admin Functions *****************************************/

/*
function xl_event() 
{ 
	if (window.event) return window.event; 
	else return ff_event;
}	 
*/

/**************************************** Start authority functions *****************************************/


//RTC 20090618: jquerify
function clearform()
{
	jQ('#filter1').val('');
	
	if( jQ('#mrulist').val() == 'Y')
	{
		jQ('#mrulist').val('');
	}
	else
	{
		jQ('#mrulist').val('Y');
	}

	jQ('#formfilt').submit();
}


function handleKeyUp(e, divname) 
{
	//e = (!e) ? window.event : e;
	//target = (!e.target) ? e.srcElement : e.target;
	
	target = e.target;
	
	if (e.type == "keyup") 
	{
		if (e.keyCode == 16 || e.keyCode == 17 || e.keyCode == 18) 
		{
			
		}
		else if (((e.keyCode == 40) || (e.keyCode == 38)) && ( jQ('#result_div').style.display != 'none'))
		{
			var children = jQ('#result_div').children();
			
			if (e.keyCode == 38)
			{
				if (trackdown > children.length)
				{
					trackdown = children.length - 1;
				}
				else
				{
					trackdown--;
				}
				
				if (trackdown < 0)
				{
					
					children[0].className = '';
					trackdown = -1;
					
					jQ('#filter1').val(saveselect);
					return;
				}
			}
			else
			{
				if (trackdown == -1)
				{
					saveselect = jQ('#filter1').val();
				}
									
				trackdown++;
			}
			
			
			if (trackdown >= children.length)
			{
				trackdown--;
			}
			
			for (var i = 0; i < children.length; i++) 
			{
				children[i].className = '';
				if((children[i].nodeName == "DIV") 
				&& (trackdown == i))
				{
					selectedObj = children[i];
				}
			}
			
			selectedObj.className = 'sellink';
			var objtext = selectedObj.id + 'name';
			
			jQ('#filter1').val( jQ('#'+objtext).html() );
		}
		else if ((e.keyCode == 13) && ( jQ('#result_div').css('display') != 'none'))
		{
			var addtype = selectedObj.id.substring(0,1);
			var grpusrnbr = selectedObj.id.substring(1,8);
			var authtype = selectedObj.id.substring(8,18);
			addauth(grpusrnbr, authtype, addtype);
						
			jQ('#result_div').hide();
			jQ('#filter1').val('');
			
			return false;
		}
		else 
		{
			trackdown = -1;
			if (target.value) 
			{
				Send_AJAX_Request(target);
			} 
			else 
			{
			
				jQ('#'+divname).html('').hide(); 
			}
		}
	}
}

function clearDiv(divname)
{
	jQ('#'+divname).html('').hide(); 
}

function Send_AJAX_Request(target) 
{ 
	var url = "NXAUTHPOP.pgm?task=ajaxresp&filter1=" + encodeURIComponent(target.value) + "&authtype=" + document.inpform.authtype.value; 	
	jQ.get(url, authselect_Response); 
} 	

function authselect_Response(response)
{

	var inpbox = jQ('#filter');
	if (response != '')
	{
		jQ('#result_div').html(response); 
		jQ('#result_div').show();
				
		jQ('#result_div').css('left', xl_FindPosX(inpbox) + "px");
		jQ('#result_div').css('top', (xl_FindPosY(inpbox) + 21) + "px");
	}
	else
		jQ('#result_div').hide();
}


function addauth(grpusrnbr, authtype, addtype, type)
{
	var mydiv
	var url;
		
	if (type == undefined)
	{
		type = '*READ';
	}
	
	
	// TODO: clean up this mess- surely these urls could be constructed in a better way
	if (authtype == "ECM")
	{
		url = "nxauthpop.pgm?task=addauth&addtype=" + addtype + "&grpusrnbr=" + grpusrnbr + "&authlvl=" + type + "&authtype=" + authtype + "&docnum=" + parent.document.inpform.docnum.value;
	}
	else if (authtype == "PROCDIR")
	{
		url = "nxauthpop.pgm?task=addauth&addtype=" + addtype + "&grpusrnbr=" + grpusrnbr + "&authtype=" + authtype  + "&prtnbr=" + parent.document.inpform.prtnbr.value;
	}
	else if (authtype == "RULE")
	{
		url = "nxauthpop.pgm?task=addauth&addtype=" + addtype + "&grpusrnbr=" + grpusrnbr + "&authtype=" + authtype  + "&rulenum=" + parent.document.inpform.rulenum.value + "&authlvl=" + type;
	}
	else if (authtype == "PORTLET")
	{
		url = "nxauthpop.pgm?task=addauth&addtype=" + addtype + "&grpusrnbr=" + grpusrnbr + "&authtype=" + authtype  + "&instnbr=" + parent.document.inpform.instnbr.value + "&authlvl=" + type;
	}
	else if (authtype == "CAL")
	{
		url = "nxauthpop.pgm?task=addauth&addtype=" + addtype + "&grpusrnbr=" + grpusrnbr + "&authtype=" + authtype  + "&instnbr=" + parent.document.inpform.instnbr.value + "&authlvl=" + type + "&TDSENU=" + parent.document.inpform.TDSENU.value + "&smurf=" + parent.document.inpform.smurf.value;
		jQ.get(url, Rcv_AJAX_addCalauth);
		return;
	}
	else if ((authtype == "MENU") || (authtype == "MENUITEM"))
	{
		url = "nxauthpop.pgm?task=addauth&addtype=" + addtype + "&grpusrnbr=" + grpusrnbr + "&authtype=" + authtype  + "&mnurrn=" + parent.document.inpform.mnurrn.value + "&authlvl=*READ";
	}
	else
	{
		url = "nxauthpop.pgm?task=addauth&addtype=" + addtype + "&grpusrnbr=" + grpusrnbr + "&authlvl=" + type + "&authtype=" + authtype ;
	}
	
	
	if (authtype == "PROCDIR")
	{
		jQ.get(url, Rcv_AJAX_addprdauth);
	}
	else
	{
		jQ.get(url, Rcv_AJAX_addauthority);
	}
}

function Rcv_AJAX_addCalauth(response)
{
	if (response == "")
	{
		alert("You are not authorized to this group or user");
	}
	else
	{
		jQ(parent.document).find('#addedauths').append(response);
		parent.parent.setprivate();
	}
}

function Rcv_AJAX_addprdauth(response)
{
	if (response == "")
	{
		alert("You are not authorized to this group or user");
	}
	else
	{
		jQ(parent.document).find('#addedauths').append(response);
	}
}

function Rcv_AJAX_addauthority(response)
{
	if (response == "")
	{
		alert("You are not authorized to this group or user");
	}
	else
	{
		jQ(parent.document).find('#addedauths').append(response);
	}
	
	parent.adjustParent();
}


function delauth(authtype, rrn, docnum)
{
	if (authtype == "ECM")
	{
		var url = "nxauthpop.pgm?task=delauth&rrn=" + rrn + "&authtype=" + authtype  + "&docnum=" + docnum;
	}
	else if (authtype == "RULE")
	{
		var url = "nxauthpop.pgm?task=delauth&authtype=" + authtype  + "&rrn=" + rrn;
	}
	else if (authtype == "CAL")
	{
		var url = "nxauthpop.pgm?task=delauth&rownbr=" + rrn +"&authtype=" + authtype  + "&smurf=" + parent.document.inpform.smurf.value;
		
		jQ.get(url, function(resp)
		{ 
			Rcv_AJAX_DltCalAuth(rrn, resp); 
		});
		
		return;
	}
	else
	{
		var url = "nxauthpop.pgm?task=delauth&rrn=" + rrn + "&authtype=" + authtype;
	}
	
	jQ.get(url, function(resp)
	{
		Rcv_AJAX_DltAuth('authdet'+rrn, resp);
	});
}

function dltallauth()
{
	var url = "nxauthpop.pgm?task=delauth&authtype=ALLCAL&smurf=" + document.inpform.smurf.value;
	jQ.get(url, Rcv_AJAX_DltAllAuth);
}

// if the delete all request succeeds, remove all attached authority elements on the page
// and indicate that the event is now private.
function Rcv_AJAX_DltAllAuth(response)
{	
	if(response == "Deleted")
	{
		var children = jQ( jQ('#authframe')[0].contentWindow.document ).find('#addedauths > div').remove();
		var children = jQ( jQ('#authframe')[0].contentWindow.document ).find('#selauth > div').not('#norecords').remove();
	
		setprivate();
	}
}

//present options to  change authority level of a user or group to an ECM object
function chgauth(authtype, rrn, docnum)
{
	var chgid = "chg" + rrn;
	var sltid = "slt" + rrn;
	
	// RTC 20090223: this shouldnt be needed
	/*
	authrrn = rrn;
	if (authrrn != 0)
	{
		setAuthLvl();
	}
	*/
	
	if(authtype == 'CAL')
	{
		setprivate();
	}
	
	var chgid = "chg" + rrn;
	var sltid = "slt" + rrn;
	
	authrrn = rrn;
	
	
	var authtype = '*' + jQ('#'+chgid).html().toUpperCase();
	jQ('#'+chgid).html('');
	jQ('#'+sltid).html( jQ('#chgauthlvl').html() );
	//check the matching input as the current value
	jQ('#'+sltid+' input[value="'+authtype+'"]')[0].checked = true;
	
	//bind function to handle change events
	jQ('#'+sltid+' input').bind('change', updauth);
	
}

//updates a user or group's authority to an object to the selected level
function updecmauth(rrn, docnum)
{
	var newauth = jQ('#chg'+rrn).val();
	var url = "nxauthpop.pgm?task=chgauth&rrn=" + rrn + "&authlvl=" + newauth + "&authtype=ECM" + "&docnum=" + docnum;
	
	jQ.get(url);
}

//updates a user or group's authority to a portlet object
function updportauth(rrn, instance)
{
	var newauth = jQ('#chg'+rrn).val();
	var url = "nxauthpop.pgm?task=chgauth&rrn=" + rrn + "&authlvl=" + newauth + "&authtype=PORTLET&instnbr=" + instance;
	
	jQ.get(url);
}


//updates a user or group's authority to a distribution rule entry
function updruleauth(rrn, rulenum)
{
	var newauth = jQ('#chg'+rrn).val();
	var url = "nxauthpop.pgm?task=chgauth&rrn=" + rrn + "&authlvl=" + newauth + "&authtype=RULE&rulenum=" + rulenum;
	
	jQ.get(url);
}

//updates a user or group's authority to a calendar event
function updcalevtauth(rrn, instnum)
{
	var newauth = jQ('#chg'+rrn).val();
	var url = "nxauthpop.pgm?task=chgauth&rownbr=" + rrn + "&authlvl=" + newauth + "&authtype=CAL&instnbr="+instnum+ "&smurf=" + parent.document.inpform.smurf.value;

	jQ.get(url);
}

/* RTC 20090622: replaced by upd***auth functions
function updauth()
{
	var sltid = "slt" + authrrn;
	var chgid = "chg" + authrrn;
	
	var type = jQ('#'+sltid+' input:checked').val();
	if (type != "undefined")
	{
		if (document.inpform.authpgm.value == "RULE")
		{
			var url = "nxauthpop.pgm?task=chgauth&rrn=" + authrrn + "&authlvl=" + type + "&authtype=" + document.inpform.authpgm.value + "&rulenum=" + document.inpform.rulenum.value;
		}
		else if (document.inpform.authpgm.value == "ECM")
		{
			var url = "nxauthpop.pgm?task=chgauth&rrn=" + authrrn + "&authlvl=" + type + "&authtype=" + document.inpform.authpgm.value + "&docnum=" + document.inpform.docnum.value;
		}
		else if (document.inpform.authpgm.value == "PORTLET")
		{
			var url = "nxauthpop.pgm?task=chgauth&rrn=" + authrrn + "&authlvl=" + type + "&authtype=" + document.inpform.authpgm.value + "&instnbr=" + document.inpform.instnbr.value;
		}
		else if (document.inpform.authpgm.value == "CAL")
		{
			var url = "nxauthpop.pgm?task=chgauth&rownbr=" + authrrn + "&authlvl=" + type + "&authtype=" + document.inpform.authpgm.value + "&instnbr=" + document.inpform.instnbr.value + "&smurf=" + parent.document.inpform.smurf.value;
		}
		
		//var mydiv;
		//xl_AjaxUpdate(url, mydiv, Rcv_AJAX_chgAuth);
		jQ(url, Rcv_AJAX_chgAuth);
	}
	else
		authrrn = 0;
}
*/

function chgauthexclude(authtype, rrn, exclude)
{	
	var url = "nxauthpop.pgm?task=chgauth&rrn=" + rrn + "&authtype=" + authtype  + "&exclude=" + exclude;
	
	//var mydiv = rrn;
	//var mydiv;
	//xl_AjaxUpdate(url, mydiv);
	jQ.get(url);
}

function chgauthemail(authtype, rrn, email)
{
	var url = "nxauthpop.pgm?task=chgauth&rrn=" + rrn + "&authtype=" + authtype  + "&email=" + email;
	//var mydiv;
	//var mydiv = rrn;
	//xl_AjaxUpdate(url, mydiv);
	jQ.get(url);
}


function Rcv_AJAX_chgAuth(mydiv, response)
{
	if (response = "Changed")
	{
		setAuthLvl();
	}
}

function setAuthLvl()
{
	var sltid = "slt" + authrrn;
	var chgid = "chg" + authrrn;
	
	/*
	var authlvl = document.inpform;
	j= authlvl.chglevel.length;
	
	for (i=0; i<j; i++)
	{
		if(authlvl.chglevel[i].checked) var type = authlvl.chglevel[i].value;
	}
	*/
	var type = jQ('#chgauthlvl input:checked').val();
	
	if (type == "*READ")
	{
		type = "Read";
	}
	else if (type == "*WRITE")
	{
		type = "Write";
	}
	else if (type == "*ADMIN")
	{
		type = "Admin";
	}
	
	jQ('#'+sltid).html('');
	jQ('#'+chgid).html(type);
	
	authrrn = 0;
}


function Rcv_AJAX_DltAuth(mydiv, response)
{
	if (response == "Deleted")
	{
		jQ('#'+mydiv).remove();
	}
	
	if( jQ('#authpgm').val() != 'PROCDIR')
	{
		adjustParent();
	}
}

function Rcv_AJAX_DltCalAuth(mydiv, response)
{
	if (response == "Deleted")
	{
		jQ('#authdet'+mydiv).remove();
		parent.setprivate();
	}
	
	if( jQ('#authpgm').val() != 'PROCDIR')
	{
		adjustParent();
	}
}

function loadControl()
{
	setuptabs();
	loadportlets();
	curformdspmode();
}

function chgblkstate(blocknbr, myurl, ajax, optkey) 
{ 
	var wcdiv = 'wcdiv'+blocknbr; 
	var ifrmid = 'ifrm'+blocknbr; 
	
	var wcdivobj = jQ('#wcdiv'+blocknbr)[0];
	var borderobj = jQ('#bdr'+blocknbr)[0];
	
	var icondiv;
	var newstate =''; 
	
	if ( jQ(wcdivobj).css('display') != 'none' )
	{
		jQ(wcdivobj).hide();
		
		icondiv = jQ(borderobj).find('.navcollapse')[0];
		icondiv.className = "navexpand";
		icondiv.title = "Expand"; 
		newstate='C';
	} 
	else 
	{
		if (myurl.search('nourl') == -1)
		{ 
			if (ajax == 'Y')
			{
				jQ.get(myurl, function(resp) {
					loadinclude(wcdivobj, resp);
				});
			}
			else
			{
				wcdivobj.innerHTML = '<iframe name="'+ ifrmid +'" id="'+ ifrmid +'" src="' + myurl+ '" scrolling=auto height="500" width=100% frameborder=0 style="">No IFRAME support</iframe>';
			}
		}
		else
		{
			// RTC 20080820: Removed to implement simpler resize handling
			// loaddocchk();	
		}
		
		jQ(wcdivobj).show();
		
		icondiv = jQ(borderobj).find('.navexpand')[0];
		icondiv.className = "navcollapse";
		icondiv.title = "Collapse";
		newstate=''; 
	}
	
	setserver(optkey,newstate);	
} 

function chglnkstate(blocknbr) 
{ 
	var toggleObj = jQ('#wcimg'+blocknbr); 
	if (jQ('#link').css('display') != "none") 
	{ 
		jQ('#link').hide();
		toggleObj.replaceClass('navexpand');
		toggleObj.attr('title', 'expand');
	} 
	else 
	{
		jQ('#link').show();
		toggleObj.replaceClass('navcollapse');
		toggleObj.attr('title', 'collapse');
	}
} 

function insidepageurl(newurl) {
	jQ('#insert').show();	
	jQ('#insert2').show();
	jQ('#dyniframe')[0].src = newurl;
}

function loadwcdiv(blocknbr , loadstate, myurl, height, width, autoscroll, wdw, icons, ajax) 
{ 
	var wcdiv = 'wcdiv'+blocknbr; 
	var ifrmid = 'ifrm'+blocknbr; 
	var wcdivobj = jQ('#'+wcdiv)[0];
	
	if ((wdw != '1') && (wdw != '2'))
	{		
		if (loadstate != 'C') 
		{ 
			if (ajax == 'Y')
			{
				jQ.get(myurl, function(resp) {
					loadinclude(wcdivobj, resp);
				});
			}
			else
			{
				wcdivobj.innerHTML = '<iframe name="'+ ifrmid +'" id="'+ ifrmid +'" src="' + myurl + '" scrolling="' + autoscroll + '" height="' + height + '" width="100%" frameborder=0 style="" marginwidth="0" marginheight="0">No IFRAME support</iframe>';
			}
		} 
	}
	else
	{	
		if (wdw == '1')
		{
			var position = 'scrollbars=1,resizable=1,height=' + height + ',width=' + width +',left=015,top=045';
			window.open(myurl, 'open_window', position);
		}
	}
} 

function loadinclude(mydiv, response)
{
	jQ(mydiv).html(response);
}

/*
function loaddocchk()
{
	var ifr = xl_GetObj('ifrmviewdoc');
	
	// RTC 20080811: This interferes with minimizing and expanding the viewer
	//xl_GetObj('ifrmviewdoc').style.height = '0px';

	// RTC 20080717: trying to categorize the page DOM type this way is not going to work, removing for now
	// The document types which would be used as a top level frame and do not provide DOM height information 
	// will be handled as exceptions. The default behavior is to attempt to use size using the HTML
	//if ((ifr.src.search(/.htm/i) == -1) && (ifr.src.search(/.pgm/i) == -1) && (ifr.src.search(/.gif/i) == -1) && (ifr.src.search(/.jpg/i) == -1) && (ifr.src.search(/.txt/i) == -1))
	//{
	//	setTimeout('setiframesize()', 300);
	//}
	//else

	// pdf and doc files don't have onload events
	if ( (ifr.src.search(/.pdf/i) > -1) 
	  || ( ifr.src.search(/.doc/i) > -1))
		setTimeout('setiframesize()', 300);
	else
	{
		xl_AttachEvent(ifr, "load", setiframesize);
	}
}

function setiframesize()
{
	xl_GetObj('loading').style.display = "none";
	
	try 
	{ 
		//var the_height = xl_GetObj('ifrmviewdoc').contentWindow.document.body.scrollHeight + 40; 
		var the_height = document.getElementById('ifrmviewdoc').contentWindow.document.body.scrollHeight + 40; 

		if (the_height == 40)
			xl_GetObj('ifrmviewdoc').style.height = dociframeHeight + 'px'; 
		else
			xl_GetObj('ifrmviewdoc').style.height = the_height + 'px';
	} 
	catch(err) 
	{
		xl_GetObj('ifrmviewdoc').style.height = dociframeHeight + 'px'; 
	}  
	
	xl_DetachEvent(xl_GetObj('ifrmviewdoc'), "load", setiframesize);
}
*/

// RTC 20080820: attempt to improve viewer automatic sizing
function autoSizeViewer()
{
		var viewerFrame = jQ('#ifrmviewdoc')[0];
		
		// document has been retrieved, remove 'loading document' text
		jQ('#loading').hide();
		
		//attempt to retrieve the height of the document from the DOM. 
		// *NOTE* This is not possible when the frame document is coming 
		// from a different domain, in FireFox at least.
		try
		{
			var viewerDoc;
			if(viewerFrame)
			{
				viewerDoc = viewerFrame.contentDocument;
			}
			
			if(viewerDoc) 
			{			
				//use offset height in firefox because scrollHeight doesnt autoshrink
				if(viewerDoc.body)
				{
					var newViewerHeight;
					
					//RTC 20091021 if viewer portlet is closed we need to toggle it visible briefly to get the height
					var viewerParentDiv = jQ(viewerFrame).parent();
					if( viewerParentDiv.css('display') == 'none')
					{
						viewerParentDiv.show();
						
						newViewerHeight = viewerDoc.body.offsetHeight + 32;
						
						viewerParentDiv.hide();
					}
					else // viewer content is visible
					{
						newViewerHeight = viewerDoc.body.offsetHeight + 32;
					}	
				}
				else
				{
					var newViewerHeight = 600;
				}
					
			}
			else
			{
				if(viewerFrame && viewerFrame.contentWindow)
				{
					viewerDoc = viewerFrame.contentWindow.document;
				}
				
				if(viewerDoc && viewerDoc.body)
				{
					var newViewerHeight = viewerDoc.body.scrollHeight + 40;
				}
				else
				{
					var newViewerHeight = 600;
				}
					
			}
			
		}
		catch (error)
		{
			var newViewerHeight = 600;
		}
		
		jQ('#ifrmviewdoc').css('height', newViewerHeight +'px');
}


// this function toggles the show or hide first column open and closed
function showorhide(imgname,optkey,optvalue) 
{ 	
	var col1cell = jQ('#tdsbmform');
	var col2cell = jQ('#tdsbmform2');
	
	if (flipper == '') 
	{
		
		Column2Width = col2cell.width();
		col2cell.width( parseInt(jQ('#column2').html()) + parseInt(jQ('#column1').html()) + '%' );
		col1cell.hide();
		
		optvalue = 'C'; 
		flipper = 'C';
		
		jQ('#colhider').replaceClass('colhiderright');
		jQ('#colhider').attr('title','Show Left Column'); 
	}
	else 
	{
		col2cell.width( parseInt(jQ('#column2').html()) + '%' );
		col1cell.show();
		
		optvalue = '';  
		flipper = '';
		
		
		jQ('#colhider').replaceClass('colhiderleft');
		jQ('#colhider').attr('title','Hide Left Column');  

		Reload_Navigators();
	} 
	
	setserver(optkey, optvalue); 
}

function curformdspmode() 
{ 		
	var col1cell = jQ('#tdsbmform');
	var col2cell = jQ('#tdsbmform2');
	
	displayCorners();
	
	try 
	{
		if ( jQ('#nbrColumn1').val() > 1)
		{  
			if (flipper == 'C') 
			{ 
				col1cell.hide();
				Column2Width = col2cell.width();
				col2cell.width(parseInt(jQ('#column2').html()) + parseInt(jQ('#column1').html()) + '%');
				jQ('#colhider')[0].src = '/nexuspublic/images/openbar.gif';
			}
			else 
			{
				col1cell.show();
				col2cell.width( parseInt(jQ('#column2').html()) + '%');
				
				jQ('#colhider')[0].src = '/nexuspublic/images/closebar.gif';
			}
		}
		else	
		{		
			
			col1cell.width( parseInt(jQ('#column1').html()) + '%' );
		}
		
	}
	catch(err) 
	{
	}
	
	//RTC 20081203: simplifying if condition
	//if( document.docform && (document.docform.lnknum.value != '0000000') && jQ('#ifrmviewdoc')[0] )
	if( (jQ('#lnknum').val() != '0000000')
	&& (jQ('#ifrmviewdoc')[0] ) )
	{
		//RTC 20081203: simplifying if condition
		//if (document.docform.docnum.value != '000000000')
		if( jQ('#docnum').val() != '0000000' )
		{
			if (reSize == 'Y')
			{
				var activewidth = jQ('#ifrmviewdoc')[0].contentWindow.document.body.scrollWidth - 10;
				jQ('#ifrmviewdoc')[0].contentWindow.document.body.innnerHTML = "<image src=\"" + ECMDocument + "\" style=\"width:" + activewidth  + "px\">";
			}
			else
			{
				ECMDocument = decode_html(ECMDocument);
				jQ('#ifrmviewdoc').attr('src',ECMDocument);
			}
			
			//RTC 20080811: adjust to get corresponding height without frames
			//dociframeHeight = document.body.clientHeight;
			dociframeHeight = jQ('#nexusmain').height();
			// ... end RTC 20080811: 
			
			//RTC 20081119: initial size for PDF docs and external content
			jQ('#ifrmviewdoc').height( jQ('#nexusmain').height() - 180);
			
			
			// RTC 20080820 replaced resizing method
			//xl_GetObj('ifrmviewdoc').style.height = dociframeHeight + 'px';
		}
		else
		{
			jQ('#ifrmviewdoc')[0].src = 'NXMNGDOC.pgm?task=nodoc';
			
			// RTC 20080820 replaced resizing method
			//xl_GetObj('ifrmviewdoc').style.height = dociframeHeight + 'px';
		}

		// RTC 20080820: automatic resizing attempt
		//loaddocchk();
	}
	else
	{
		loadsearch();
	}	
	
	setTimeout('scroll(0,0);', 200);
	
}

function loadsearch()
{
	if (searchURL != "")
	{ 	
		searchdoc(searchURL);
	} 
}

//used by the nxpages program, this function will load up the selected page
function loaddocs(ev)
{
	var docnum = ev.target.id.substr(7);
	top.location.href = 'nxmenu.pgm?docnum=' + docnum;	
}

function SetNavOptions()
{
	if (document.inpform.fixedsize.checked == true)
	{
		document.inpform.navheight.disabled = false;
	}
	else
	{
		document.inpform.navheight.disabled = true;
	}
	
	if (document.inpform.navheight.value == '')
	{
		document.inpform.navheight.value = 500;
	}
	
	jQ('#aSelectDefaultLoc').bind('click',opendoctree4);
}

/**************************************** End authority functions *****************************************/



/****************************************Start ECM Functions *********************************************/

function ecm_restore() 
{	
	// TODO: streamline this process by resetting all inputs for the parent form, then changing ones with default values
	jQ('#listsize').val("   20");
	jQ('#ORDBYKEY').val("DMRLNM");
	jQ('#maintrcd').checked = "checked";
	jQ('#advview').checked = "checked";
	jQ('#usersearch').checked = "";
	jQ('#instancesrch').checked = "";
	jQ('#aplyauth').checked = "";
	jQ('#quickadd').val('');
	jQ('#allowsrch').checked = "checked";
	jQ('#advsearch').checked = "";
	jQ('#useand').val("");
	jQ('#rstrctkey').val("");
	jQ('#allowkv').checked = "checked";
	jQ('#addkv').val("");
	jQ('#rstrcttoinst').val("");
	jQ('#optkv').checked = "";
	jQ('#searchstr2').val("");
	jQ('#addsearch').checked = "checked";
	jQ('#optaddsrch').checked = "checked";
	jQ('#appsrchstr').val("");
	jQ('#addappend').checked = "checked";
	jQ('#optaddapnd').checked = "checked";
	
}

function addQuickItem(e)
{
	if( jQ('#create_in')[0] && ( jQ('#nodename2').val() == "") )
	{
		alert('The Create after location can not be blank. Please use the icon on the right to select a Folder.');
		popup.find('#create_in').replaceClass('error');
		return;
	}
	
	if( jQ('#titletext').val() == '')
	{
		var z = 0;
		var endpos = 256;
		
		for (var x = 256; x >= 0; x--) 
		{ 
			z = z + 1;
			var y = jQ('#url').val().substring(x,x - 1);
			
			if (((y == '.') || (y == '/')) && (endpos != 256))
			{
				break;
			}
			
			if (y == '.') 
			{
				endpos = x - 1;       	
			}
		}
		
		if(x > 0)
		{
			jQ('#title').val( jQ('#url').val().substring(x,endpos) );
		}
		
	}
	
	// if we have a link, check for a .pgm extension and set those URLs as PGMs
	if( jQ('#ECMType').val() != "Folder")
	{
		var exttype = getExtension( jQ('#url').val() );
		
		if (exttype == "PGM")
		{
			jQ('#ECMType').val(exttype);
		}
	}
	
	var errorflg = val_InpChar('titletext', 'Name', 'doc_name', 'N');
	if(errorflg != 'Y')
	{
		var url = "NXADDECM.pgm?task=addECMcnt&inFolder=" + jQ('#infolder').val() + "&type=" 
				+ jQ('#ECMType').val() + "&ECMtype=" + jQ('#ECMType').val() + "&title=" 
				+ jQ('#titletext').val() + "&wnode2=" + jQ('#wnode2').val() + "&instance=" 
				+ jQ('#instance').val() + "&targetmtch=" + jQ('[name=targetmtch]').val() 
				+ "&url=" + encodeURIComponent( jQ('#url').val() ) + "&favorites=" 
				+ jQ('#favorites').val() + "&framename=" + jQ('#framename').val();
		
		var optvalue = jQ('[name=targetmtch]').val();
		if(optvalue != undefined)
		{
			setserver("FAVORITESTARGET", optvalue);
		}
		
		//add the document with ajax and refresh the appropriate part of the page
		if( jQ('#framename').val() == 'favframe')
		{
			jQ.get(url, function()
			{
				//reload the favorites frame
				var ifrm = jQ(top.document).find('#favframe')[0];
				ifrm.src = ifrm.src;
			});
		}
		else
		{
			jQ.get(url, function()
			{
				//reload all the navigator portlets on the main page
				top.Reload_Navigators();
			});
		}
		
		//hide the quickadd popup
		jQ('#quickadd').hide();
		
		// ... end RTC 20081009
	}
} 


function getExtension(url, exttype)
{
	var z = 0;
	var endpos;
	
	z = 0;
	for (var x = 255; x >= 0; x--) 
	{ 
		z = z + 1;
		var y = url.substring(x,x - 1);
		
		if (y == ".") 
		{ 
			break;
		} 
	}
	
	exttype = url.substring(x,z).toUpperCase();
	
	return exttype;
}

function createECMcnt()
{
	if( jQ('#create_in')[0] && ( jQ('#nodename2').val() == '') )
	{
		alert('The create after location can not be blank. Please use the icon on the right to select a Folder.');
		jQ('#create_in').replaceClass('error');
		return;
	}
	
	var errorflg = val_InpChar('titletext', 'Name', 'doc_name','N');
	if (errorflg != 'Y')
	{
		var optvalue = jQ('[name=targetmtch]').val();
		if(optvalue != undefined)
		{
			setserver("FAVORITESTARGET", optvalue);
		}
		
		if( jQ('#ECMType').val() == 'HTML' )
		{
			jQ('#loadingfile').show();
			jQ('#taskdesc2').val( oEdit1.getHTMLBody() );
			jQ('#ECMType').val('HTML');
			
			document.inpform.type.value = "html";
			
			//check that document isnt too long to be added
			if (document.forms.inpform.taskdesc2.value.length <= 50000)
			{
				document.forms.inpform.submit();
			}
			else
			{
				alert('Error: The documented you attempted to add is ' + document.forms.inpform.taskdesc2.value.length + ' characters. The maximum size for documents created in the Nexus ECM is 50,000 characters.');
			}
		}
		else if( jQ('#ECMType').val() == 'document' )
		{
			if ( jQ('#updfile').val() == '')
			{
				alert('You must enter a vaild path. Use the Browse button to enter a path.');
				jQ('#pcfile').replaceClass('error');
				return;
			}
				
			jQ('#loadingfile').show();
			jQ('#ECMType').val('document');
			//RTC 20091014 use the file extension instead (set in stripfilename)
			//document.inpform.type.value = "document";
			
			document.forms.inpform.submit();
		}
	}
} 

function EndQuickAdd(frameid)
{
	jQ(parent.document).find('#quickadd2').hide();
	jQ(parent.document).find('#quickadd').hide();
	
	if (frameid == 'favframe')
	{
		var url = "NXMNGDOC.PGM?task=viewfavorites&type=V&favorites=Y&rnd=" + Math.random();
		jQ(parent.document).find('#'+frameid).attr('src', url);
	}	
	else
	{
		//RTC 20081009: reload the parent (navigator) frame
		window.parent.document.location= window.parent.document.location;
	}
}


function Reload_Navigators()
{
	var t;
	for (t = 0; t < ECMNavigatorctr; t++)
	{	
		var ifr = jQ('#'+ECMNavigators[t])[0];
		if(ifr) 
		{
			ifr.src = ifr.src + '&rnd=' + Math.random();
		}
	}
	
	// RTC 20080722: If there is an ECM viewer, we need to recalculate its height with the
	// new, smaller width. This only affects firefox.
	var viewer = document.getElementById('ifrmviewdoc');
	if(viewer)
	{
		if(viewer.contentWindow)
		{
			adjustIFrameSize(viewer.contentWindow);
		}			
	}
	// ... end RTC 20080722
	
	// RTC 20100113 MedAxiom portlet reloads
	/*for(iframe in iframeArray)
	{
		if(iframe.src.search('MNDOCDET2.pgm' != -1)
		{
			ifr.src = ifr.src.substring(0, ifr.src.search('&rnd='))+'&rnd='+ math.Random();
		}
       if(ifr.src.search('mddocrat.pgm') != -1) 
       {
            ifr.src =  '/cgi/mddocrat.pgm?TASK=RATEIT&log=Y&wnode=' + docnum  + '&rnd='+ math.Random();
       }
	}*/
}


function openTree3()
{
	if( openIndex >= 0 )
	{
		var myid = openArray[openIndex];
		var myobj = jQ('#mi' + myid)[0];
		
		if ( myobj && ( myobj.innerHTML || myobj.innerHTML == '' ) )
		{
			var url = "NXMNGDOC.pgm" + "?task=EXPAND&ALPHNODE="+ openArray[openIndex] + "&wnode=" + currentNode + "&type="+ listType + "&instance=" + instance; 
			jQ.get(url, function(resp) {
				openTree2(myid,resp);
			});
		}
		else
		{
			openIndex = openIndex - 1;
			openTree3();
		}
	}
}

function init()
{ 	
	jQ(document).bind('click', ClickHandler);
	jQ(document).bind('mouseover', ChgStatusBar);
	jQ(document).bind('mouseout', ClrStatusBar);
	
	//RTC 20091221: clear when leaving the window or over the maint header
	// jQ('#content').bind('mouseleave', closeClickMenu);
	jQ('#content').parent().bind('mouseleave', closeClickMenu);
	jQ('#topbanner').bind('mouseenter', closeClickMenu);
	
	openTree();
	
	
	if (listType != 'M')
	{	
		if ((fixedsize == 'Y') || (listType != 'V'))
		{
			var iframeElement = nx_gettopframe(window.name);
			
			// RTC 20081022: This line shouldnt be necessary, navigator content divs can be autosized
			//jQ('#content').css('height', navheight + 'px');
			
			//RTC 20081202: this line wasnt properly parsing navheight as an int so the add was incorrect 
			//jQ(iframeElement).css('height', ( navheight + jQ('#topbanner')[0].offsetHeight) + 'px'); 
			jQ(iframeElement).css('height', navheight + 'px'); 
		}
		else if (listType == 'V')
		{
			adjustSize = true;
		}
		
		if (listType == 'V')
		{
			jQ(document).rightClick(RightClickHandler);
		}
	}
	
	if (adjustSize)
	{	
		sizeNavigator();
	}
	
} 

function UpdNavConfig()
{
	
	// TODO: replace this with non xl_ code
	var url = xl_BuildURLWithFormElements('inpform', 'NXMNGDOC.pgm');
	jQ.get(url, Rcv_AJAX_NavUpd);
} 

function Rcv_AJAX_NavUpd(response)
{
	top.location.reload();
}

function expandFolder(EventObj)
{
	var children = EventObj.childNodes;	
	for (var i = 0; i < children.length; i++) 
	{
		if (children[i].nodeName == "A") 
		{
			EventObj = children[i];
			break; 
		}
	}

	var parNode  = EventObj.parentNode;
	var parClass = EventObj.parentNode.className;	
	if (EventObj.tagName == "A")
	{
		if((parClass == "nxFolder") 
		|| (parClass == "nxOpFolder") 
		|| (parClass == "nxFavFolder")
		|| (parClass == "nxOpFavFolder")) 
		{
			if((parClass == "nxFolder") 
			|| (parClass == "nxFavFolder"))
			{
				children = parNode.childNodes; 
				for (var i = 0; i < children.length; i++) 
				{
					if (children[i].nodeName == "UL") 
					{
						var myid = children[i].id;
						break;
					}
				}	
				
				if (!myid)
				{
					return false;
				}
				
				if( jQ('#'+myid).html().length <= 1)
				{	
					var url = "NXMNGDOC.pgm?task=EXPAND&ALPHNODE="+ myid + "&wnode=" + currentNode + "&urltype=" + urltype + "&favorites=" + favorites + "&type=" + listType + "&instance=" + instance; 	
					 
					jQ.get(url, function(resp)
					{
						expandtree(myid, resp);
					});
				}
			}
			else
			{	   	
				if (adjustSize)
				{	 
					sizeNavigator();
				}
			}
			
			switch(parClass)
			{
				case 'nxOpFolder':
					parClass = 'nxFolder';
					break;
				case 'nxFolder':
					parClass = 'nxOpFolder';
					break;
				case 'nxOpFavFolder':
					parClass = 'nxFavFolder';
					break;
				case 'nxFavFolder':
					parClass = 'nxOpFavFolder';
					break;
			}
			
			//change the DOM element
			EventObj.parentNode.className = parClass;
		}		
	}
}

function expandtree(myid, response)
{  
	jQ('#' + myid).html(response);
	
	sizeNavigator();
}  

function loadDocument(EventObj)
{
	if (EventObj.tagName == 'LI')
	{
		EventObj = jQ(EventObj).find('a:first')[0];
		/* RTC 20090108: rewrote with above line
		children = EventObj.childNodes; 
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].nodeName == "A") 
			{
				EventObj = children[i];
				break;
			}
		}
		*/
	}
	
	if (listType == "M")
	{
		if (savSelObj)
		{
			if((savSelObj.className.substring(2,4) == 'Op') 
			&& (savSelObj.className != 'nxOpFolder') 
			&& (savSelObj.className != 'nxFolder') 
			&& (savSelObj.className != 'nxOpFavFolder') 
			&& (savSelObj.className != 'nxFavFolder'))
			{
				savSelObj.className = savSelObj.className.substring(0,2) + savSelObj.className.substring(4);
			}
			
			children = savSelObj.childNodes; 
			for (var i = 0; i < children.length; i++) 
			{
				if (children[i].nodeName == "A") 
				{
					children[i].className = '';
					break;
				}
			}	
		}
		
		savSelObj = EventObj.parentNode;
		
		
		if((EventObj.parentNode.className.substring(2,4) != 'Op') 
		&& (EventObj.parentNode.className != 'nxOpFolder') 
		&& (EventObj.parentNode.className != 'nxFolder') 
		&& (EventObj.parentNode.className != 'nxOpFavFolder') 
		&& (EventObj.parentNode.className != 'nxFavFolder'))
		{
			EventObj.parentNode.className = EventObj.parentNode.className.substring(0,2) + 'Op' + EventObj.parentNode.className.substring(2);
		}
	}
	
	if(EventObj.href != undefined)
	{
		// remove the selected class from all the link elements
		jQ('A').removeClass();
		
		//load the chosen link into the viewer
		runlink(EventObj);
	
		jQ(EventObj).addClass('selected');
	}
}

function closeClickMenu()
{
	jQ('#clickmenu').hide();
	
	if((jQ(parent.document).find('#quickadd2').css('display') == 'none') 
	&& (jQ(parent.document).find('#quickadd').css('display') == 'none'))
	{
		clearActive();
	}
}


function clearActive()
{
	jQ('#adduploads').attr('src', "/nexuspublic/images/adddocument.gif");
	jQ('#addhtmls').attr('src',"/nexuspublic/images/addhtml.gif");
	jQ('#addfavs').attr('src', "/nexuspublic/images/addlink.gif");
	jQ('#addfolders').attr('src', "/nexuspublic/images/addfolder.gif");
	
	// TODO: change these to use classes rather than substringing the current document type
	if (activelink.substring(8,9) == 'F')
	{		
		jQ('#'+activelink).children('DIV:first').replaceClass('nolink');
	}
	else
	{	
		if (activelink != '')
		{			
			jQ('#'+activelink).children('A:first').removeClass();
		}
	}
}


function RightClickHandler(e) 
{
	//determine if this was a right click click event
	if (e.which)
	{
		var rightclick = (e.which == 3);
	}
	else
	{
		var rightclick = (e.button == 2);
	}

	//RTC 20081008: change flow to be more clear. non-rightclick events return immediately
	if((!rightclick)
	|| (quickadds != 'Y'))
	{
		return;
	}

	
	inFolder = '';
	clearActive();

	var EventObj = e.target;
	var viewOnly;
	var MyEvent = e; 		

	jQ(parent.document).find('#quickadd').hide();
	jQ(parent.document).find('#quickadd2').hide();


	var folder = "N";
	var windowPos;

	//RTC 20080917: dont handle this event if it is on the topBanner element
	if((EventObj.id == 'topbanner')
	|| (EventObj.parentNode.id == 'topbanner'))
	{
		jQ('#clickmenu').hide();
		return false;
	}

	//RTC 20090302: only pop up the menu on some types of elements, inside the 'innerclick' container
	if(((EventObj.tagName != 'LI') 
	 && (EventObj.tagName != 'A') 
	 && (EventObj.tagName != 'DIV')) 
	|| (EventObj.parentNode.id == 'innerclick'))
	{
		jQ('#clickmenu').hide();
		clearActive();
		return false;
	}

	// RTC 20090302: If the element isnt a list item, it will be a direct child. 
	// get the ECM node information from the list item element.
	if (EventObj.tagName != 'LI')
	{
		//RTC 20081008: added 'tn' prefix to tree node ids so they will be valid, correcting the substring
		//node = EventObj.parentNode.id.substring(0,7);
		node = EventObj.parentNode.id.substring(2,9);

		activelink = EventObj.parentNode.id;
		//viewOnly = EventObj.parentNode.id.substring(7,8);
		//inFolder = EventObj.parentNode.id.substring(8,9);
		viewOnly = EventObj.parentNode.id.substring(9,10);
		inFolder = EventObj.parentNode.id.substring(10,11);
		//.. end RTC 20081008 

		if (inFolder == 'F')
		{
			EventObj.className = 'nolinkactive';
		}
		else
		{
			EventObj.className = 'active';
		}
	}
	else 
	{
		//RTC 20081008: correcting substring now that there is a new prefix
		//node = EventObj.id.substring(0,7);
		//viewOnly = EventObj.id.substring(7,8);
		node = EventObj.id.substring(2,9);
		viewOnly = EventObj.id.substring(9,10);
		// ... end RTC 20081008
		activelink = EventObj.id;

		/*var children = EventObj.childNodes; 
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].nodeName == "A") 
			{
				children[i].className = 'active';
				break;
			}
		}
		*/
		jQ(EventObj).children('A:first').replaceClass('active');
	}

	if (node != '')
	{
		var innerclick = jQ('#innerclick');
		var rclickopts = "";

		/*RTC 20081209: refactor this to use divs instead for better sizing and display
		// Favorites folder is specially handled, doesn't allow uploads, editing or deletes
		if ((EventObj.parentNode.className == 'nxFavFolder') 
		|| (EventObj.parentNode.className == 'nxOpFavFolder'))
		{
			innerclick.innerHTML = "<span class=\"disabledselection\">Upload File</span><br><span class=\"disabledselection\">Create Document</span><br><span class=\"disabledselection\">Add Link</span><br><span class=\"disabledselection\">Add Folder</span><br><hr><span class=\"disabledselection\">Delete</span><br><span class=\"disabledselection\">Edit</span>";
		}

		// *ADMIN access inside a folder
		else if ((viewOnly == 'A') && (inFolder == 'F'))
		{
			// TODO: figure out why these all have javascript hrefs with no code
			innerclick.innerHTML = "<a class=\"menuselection\" id=\"uploadECM\" href=\"javascript:\">Upload File</a><br><a class=\"menuselection\" id=\"createECM\" href=\"javascript:\">Create Document</a><br><a class=\"menuselection\" id=\"AddLinkECM\" href=\"javascript:\">Add Link</a><br><a class=\"menuselection\" id=\"addFolderECM\" href=\"javascript:\">Add Folder</a><br><hr><span class=\"disabledselection\" id=\"deleteECM\">Delete</span><br><span class=\"disabledselection\" id=\"editECM\">Edit</span>";			
		}

		// *ADMIN access outside a folder
		else if (viewOnly == 'A')
		{
			innerclick.innerHTML = "<a class=\"menuselection\" id=\"uploadECM\" href=\"javascript:\">Upload File</a><br><a class=\"menuselection\" id=\"createECM\" href=\"javascript:\">Create Document</a><br><a class=\"menuselection\" id=\"AddLinkECM\" href=\"javascript:\">Add Link</a><br><a class=\"menuselection\" id=\"addFolderECM\" href=\"javascript:\">Add Folder</a><br><hr><a class=\"menuselection\" id=\"deleteECM\" href=\"javascript:\">Delete</a><br><a class=\"menuselection\" id=\"editECM\" href=\"javascript:\">Edit</a>";			
		}

		// *WRITE access, don't allow delete option
		else if (viewOnly == 'P')
		{
			//TEH 20080715: *WRITE authority option DELETE should be disabled
			//innerclick.innerHTML = "<span class=\"disabledselection\">Upload File</span><br><span class=\"disabledselection\">Create Document</span><br><span class=\"disabledselection\">Add Link</span><br><span class=\"disabledselection\">Add Folder</span><br><hr><a class=\"menuselection\" id=\"deleteECM\" href=\"javascript:\">Delete</a><br><a class=\"menuselection\" id=\"editECM\" href=\"javascript:\">Edit</a>";	
		
			innerclick.innerHTML = "<span class=\"disabledselection\">Upload File</span><br><span class=\"disabledselection\">Create Document</span><br><span class=\"disabledselection\">Add Link</span><br><span class=\"disabledselection\">Add Folder</span><br><hr><span class=\"disabledselection\">Delete</span><br><a class=\"menuselection\" id=\"editECM\" href=\"javascript:\">Edit</a>";			
		}

		// *READ access, don't allow any options
		else if (viewOnly == 'V')
		{
			innerclick.innerHTML = "<span class=\"disabledselection\">Upload File</span><br><span class=\"disabledselection\">Create Document</span><br><span class=\"disabledselection\">Add Link</span><br><span class=\"disabledselection\">Add Folder</span><br><hr><span class=\"disabledselection\">Delete</span><br><span class=\"disabledselection\">Edit</span>";
		}
		*/
		
		// Construct the options popup HTML
		
		//RTC 20090925: check for favorites on the window body instead
		if( jQ('#favorites',EventObj.parentDocument).val() == 'Y' )
		//if ((EventObj.parentNode.className == 'nxFavFolder')  //handling favorites, no uploads edits delete
		//|| (EventObj.parentNode.className == 'nxOpFavFolder'))
		{
			/* TEH 20090928 - Disable upload/create if user can't add documents to the ECM */
			if(jQ('#uo_favupload').val() == "Y")
			{
				rclickopts = "<div class=\"menuselection\" id=\"uploadECM\">Upload File</div>"
						 +"<div class=\"menuselection\" id=\"createECM\">Create Document</div>";
			}
			else
			{
				rclickopts = "<div class=\"disabledselection\">Upload File</div>"
						 +"<div class=\"disabledselection\">Create Document</div>";
			}

			rclickopts += "<div class=\"menuselection\" id=\"AddLinkECM\">Add Link</div>"
						+"<div class=\"menuselection\" id=\"addFolderECM\">Add Folder</div>"
						+"<hr>"
						+"<div class=\"menuselection\" id=\"deleteECM\">Delete</div>"
						+"<div class=\"menuselection\" id=\"editECM\">Edit</div>";
		}
		else
		{
			switch(viewOnly)
			{
				case 'A': //admin access to this document or folder
				{
					rclickopts = "<div class=\"menuselection\" id=\"uploadECM\">Upload File</div>"
						 		 +"<div class=\"menuselection\" id=\"createECM\">Create Document</div>"
								 +"<div class=\"menuselection\" id=\"AddLinkECM\">Add Link</div>"
								 +"<div class=\"menuselection\" id=\"addFolderECM\">Add Folder</div>"
								 +"<hr>"
								 +"<div class=\"menuselection\" id=\"deleteECM\">Delete</div>"
								 +"<div class=\"menuselection\" id=\"editECM\">Edit</div>";
					break;
				}

				case 'P': //write access, no delete
				{
					//RTC 20090302: changed write access to allow document creation
					rclickopts = "<div class=\"menuselection\" id=\"uploadECM\">Upload File</div>"
						 		 +"<div class=\"menuselection\" id=\"createECM\">Create Document</div>"
								 +"<div class=\"menuselection\" id=\"AddLinkECM\">Add Link</div>"
								 +"<div class=\"menuselection\" id=\"addFolderECM\">Add Folder</div>"
								 +"<hr>"
								 +"<div class=\"disabledselection\">Delete</div>"
								 +"<div class=\"menuselection\" id=\"editECM\">Edit</div>";
					break;
				}

				case 'V': //read only
				{
					rclickopts = "<div class=\"disabledselection\">Upload File</div>"
								+"<div class=\"disabledselection\">Create Document</div>"
								+"<div class=\"disabledselection\">Add Link</div>"
								+"<div class=\"disabledselection\">Add Folder</div>"
								+"<hr>"
								+"<div class=\"disabledselection\">Delete</div>"
								+"<div class=\"disabledselection\">Edit</div>";
					break;
				}
			}
		}
		
		innerclick.html(rclickopts);
		//RTC 20081212: prevent doubled event handler
		//jQ('#clickmenu .menuselection').bind('click',ClickHandler);
		// end RTC 20081209
		

		var clickmenu = jQ('#clickmenu')[0];
		jQ(clickmenu).show();

		var iframeElement = parent.window;
		var menuWidth = jQ('#clickmenu').attr('scrollWidth');
		var windowWidth = jQ('#content').attr('offsetWidth');

		var posx = 0;
		var posy = 0;
		var contentWindow = jQ('#content')[0];

		posx = e.pageX;
		posy = e.pageY;

		if ((posx + menuWidth) > (windowWidth))
		{
			x = posx - menuWidth;			
		}
		else
		{
			x = posx;
		}

		if (x < 0)
		{
			clickmenu.style.left = 5 + 'px';
		}
		else
		{
			clickmenu.style.left = x + 'px';
		}

		var menuHeight = jQ('#clickmenu').attr('offsetHeight');
		var windowHeight = jQ('#content').attr('offsetHeight');
		var headerHeight = jQ('#topbanner').attr('offsetHeight');

		//if the right click menu would be placed off the screen, grow it upwards from the bottom instead
		if(posy + menuHeight > windowHeight)
		{
			posy -= (posy + menuHeight) - windowHeight;
		}
		
		//RTC 20091221 simplified placement due to changed html element location
		jQ('#clickmenu').css('top', posy + 'px');

		var parentNode = EventObj.parentNode;
		if((parentNode.className == "nxFolder")
		|| (parentNode.className =="nxOpFolder")
		|| (parentNode.className == "nxFavFolder")
		|| (parentNode.className=="nxOpFavFolder"))
		{
			FolderFlag = "Y";
		}
		else
		{
			FolderFlag = "N";
		}
		
	}
	else
	{
		jQ('#clickmenu').hide();
	}	
}

function sizeNavigator()
{
	var iframeElement = jQ(parent.document).find('#'+ window.name)[0];
	
	if (iframeElement != null)
	{
		if ( jQ('#content')[0].scrollWidth > iframeElement.scrollWidth)
		{
			
			jQ('#content').height( jQ('#content')[0].scrollHeight + 18 );
			//jQ(iframeElement).height(600);
			jQ(iframeElement).height(document.body.scrollHeight);
		}
		else 
		{
			iframeElement.style.height = document.body.scrollHeight + 'px';
		}
	}
	return false;
}

function quickmenu2(addtype,selnode)
{
	jQ('#clickmenu').hide();
	
	qadd = jQ(parent.document).find('#quickadd');
	quickadd2 = jQ(parent.document).find('#quickadd2');
	
	var displayFlag = 'N';
	var displayAddFlag = 'N';
	var url;
	
	var frameobj = jQ(parent.document).find('#'+this.name)[0];
	
	var clkmnu = jQ('#clickmenu')[0];	
	var y = xl_FindPosY(frameobj) + xl_FindPosY(clkmnu) + 10;
	var x = xl_FindPosX(frameobj) + xl_FindPosX(clkmnu);

	var widthLoc = 600;
	var heightLoc = 300;

	if((addtype == 'addhtml')
	|| (addtype == 'editECM'))
	{
		widthLoc = 825;
		heightLoc = 600;
	}


	if ((widthLoc + x) > parent.document.body.scrollWidth)	
	{
		x = (parent.document.body.scrollWidth - widthLoc) - 10;
	}

	/* RTC 20090102: this calculation will cause more harm than good, since we
	   may have scrolled the page
	if ((heightLoc + y) > parent.document.body.scrollHeight)
	{
		y = (parent.document.body.scrollHeight - heightLoc);
		if (y < 5)
		{
			y = 5;
		}
	}
	*/

	switch(addtype)
	{
		case 'Folder':
		case 'Symbolic':
		{
			//if we already have that add popup open, hide it
			if((qadd.css('display') == '') 
			&& (jQ(parent.document).find('#ECMType').val() == addtype))
			{
				qadd.hide();
				return;
			}
			
			var url ="NXMNGDOC.pgm?task=quickadd2&instance=" + jQ('#instance').val() 
			+ "&ECMType=" + addtype + "&wnode2=" + selnode 
			+ "&framename=" + this.name + "&infolder=" + jQ('#inFolder').val() + "&favorites=" +jQ('#favorites').val(); 
			break;
		}
					
		case 'document':
		case 'addhtml': 
		{
			var ifr = jQ(parent.document).find('#quickframe')[0];
		
			//if we already have that iframe open, hide it
			if((quickadd2.css('display') == '') 
			&& ( jQ(ifr.contentWindow).find('#ECMType').val() == addtype))
			{
				quickadd2.hide();
				return;
			}
			
			var url = "nxmngdoc.pgm?task=quickECMAdd2&ECMType=" + addtype
			+ "&framename=" + this.name + "&instance=" + jQ('#instance').val() 
			+ "&wnode2="+ selnode + "&infolder=" + jQ('#inFolder').val() +"&favorites=" +jQ('#favorites').val();
			//TODO RTC 20081212: change nxmngdoc to use the ECMTYPE 'addhtml' so we dont need this special case 
			if(addtype == 'addhtml')
			{
				url = "nxmngdoc.pgm?task=quickECMAdd2&ECMType=HTML&framename=" + this.name 
				+ "&instance=" + jQ('#instance').val() + "&wnode2=" + selnode 
				+ "&infolder=" + jQ('#inFolder').val() + "&favorites=" +jQ('#favorites').val();
			}			
			break;
		}
		case 'editECM':
		{
			url = "NXDOCSRCH2.pgm?task=edit&wnode=" + selnode + "&instance=" 
			+ jQ('#instance').val() + "&framename=" + this.name + "&favorites=" +jQ('#favorites').val();
			break;
		}
	}

	jQ(quickadd2).hide();

	if((addtype == "Folder") 
	|| (addtype == "Symbolic"))
	{
		qadd.css('left', x + 'px');
		qadd.css('top',  y + 'px');

		jQ.get(url, function(resp)
		{ 
			Rcv_AJAX_quickadd(qadd, resp);
		});
	}
	
	if((addtype == "document") 
	|| (addtype == "addhtml") 
	|| (addtype == "editECM"))
	{
		var ifr = jQ(parent.document).find('#quickframe');
		ifr.attr('src', url + "&rnd=" + Math.random() );

		ifr.css('left', x + 'px');
		ifr.css('top',  y + 'px');

		ifr.css('height',heightLoc);
		ifr.css('width',widthLoc);

		quickadd2.css('zIndex',105);

		qadd.hide();
	}
	// end RTC 20081212	
}


function ClickHandler(e)
{
	var EventObj = e.target;
	var url;
		
	//RTC 20081209: changed elements to Divs
	//only process events on list items and links
	//if ((EventObj.tagName != 'LI') && (EventObj.tagName != 'A'))
	if((EventObj.tagName != 'DIV')
	&& (EventObj.tagName != 'LI') 
	&& (EventObj.tagName != 'A'))
	{
		return false;
	}
	
	//RTC 20090302: prevent actions on right click
	if((e.which == 3) 
	|| (e.button == 2))
	{
		return false;
	}
	
	switch(EventObj.id)
	{
		case 'editECM':
			quickmenu2('editECM', node);
			return;
			break;
			
		case 'uploadECM':
			quickmenu2('document', node);
			return;
			break;
		
		case 'createECM':
			quickmenu2('addhtml', node);
			return;
			break;
		
		case 'addFolderECM':
			quickmenu2('Folder', node);
			return;
			break;
		
		case 'AddLinkECM':
			quickmenu2('Symbolic', node);
			return;
			break;
		
		case 'deleteECM':
			var linkname;
			
			linkname = jQ('#'+activelink).children('A:first').html();
			
			var delflag;
			if (FolderFlag == 'Y')
			{
				var return_value = confirm('You are about to permanently delete folder ' + linkname.toUpperCase() + ' and all of its subfolders. Do you wish to continue?');
				
				if ( return_value == true )
				{
					delflag = 'Y';
				}
			}
			else
			{
				var return_value = confirm('You are about to permanently delete ' + linkname.toUpperCase() + '. Do you wish to continue?');
				
				if ( return_value == true )
				{
					delflag = 'Y';
				}
			}
			
			if (delflag == 'Y')
			{
				var editsrc = "NXADDECM.PGM?task=delnode&instance=" + instance + "&wnode2=" + node;
				jQ.get(editsrc, Rcv_AJAX_return);
				return;
			}
			else
			{
				clearActive();
				return;
			}
			break;
		
		default:
			//closeClickMenu();
	}	
	
	if((listType == "M") 
	|| (listType == "V"))
	{
		if((EventObj.tagName == "LI")
		&& ((EventObj.className == "nxFolder") 
		 || (EventObj.className=="nxOpFolder") 
		 || (EventObj.className == "nxFavFolder") 
		 || (EventObj.className=="nxOpFavFolder"))) 
		{
			expandFolder(EventObj);
		}
		else if (EventObj.parentNode.tagName == "LI")
		{
			loadDocument(EventObj);
			
			if((EventObj.parentNode.className == "nxFolder")
			|| (EventObj.parentNode.className == "nxFavFolder"))
			{
				expandFolder(EventObj);
			}
		}
		
	}
	else // folder select or place after mode (or ?)
	{	
		if((EventObj.tagName == "LI")
		&& ((EventObj.className == "nxFolder")
		 || (EventObj.className == "nxOpFolder") 
		 || (EventObj.className == "nxFavFolder") 
		 || (EventObj.className == "nxOpFavFolder")))
		{	
			expandFolder(EventObj);
		}
		else
		{	
			if(listType == 'Z' && EventObj.className == 'nolink')
			{
				
				return false;
			}
			
			loadDocument(EventObj);
		}
	}
	
	e.preventDefault();
}	

function Rcv_AJAX_return(response)
{
	if (favorites == 'Y')
	{
		var url = "NXMNGDOC.PGM?task=viewfavorites&type=V&favorites=Y&rnd=" + Math.random();
		
		jQ(parent.document).find('#favframe')[0].src = url;
	}
	else
		parent.Reload_Navigators();
}

function expandtree(myid, response)
{ 
 
	jQ('#'+myid).html(response);
	
	if (adjustSize) 	 
		sizeNavigator();
}  

function Ldplaceafter(myid, response)
{ 
	//RTC 20081124: previous code would not be looking in the right container for the placeafter element
	//jQ(parent.parent).find('#placeafter').html(response);
	jQ(parent.parent.document).find('#placeafter').html(response);
}

//decides how a link an ECM document tree should be handled when clicked
function runlink(link_obj) 
{
	var link_url = link_obj.href; 
	var link_target = link_obj.target;
	
	//RTC 20090108: get the name of the current frame
	var framename = jQ('#framename').html();
	var listType = jQ('#listType').html();
	
	if (link_url == "") 
	{	
			if (listType == 'S')
			{
				if (framename == '')
				{
					parent.parent.setPlaceIn(link_obj.innerHTML, currentNode);
								
					var ajaxurl = "NXDOCSRCH2.pgm?task=fldrlist&instance=" + instance + "&fromnode=" + currentNode; 
					jQ.get(ajaxurl, function(resp)
					{
						Ldplaceafter('placeafter', resp);
					});
					
					jQ(parent.parent.document).find('#doctree').hide();
				}
		}
		return;
	}
	
	
	var strpos = link_url.search('docnum=');
	if (strpos != -1)
	{
		docnum = link_url.substring((strpos + 7)); 
		strpos = docnum.search('&');

		if (strpos != -1)
		{
			docnum = docnum.substring(0, strpos); 
		}
	}
	else
	{
		docnum = 0;
	}

	var strpos = link_url.search('wnode=');
	if (strpos > 0)
	{
		currentNode = link_url.substring((strpos + 6));
		strpos = currentNode.search('&');
		currentNode = currentNode.substring(0, strpos); 
	}

	if (listType == 'S')
	{
		if (framename == 'ECMQuickAdd')
		{				
			jQ('#nodename2',parent.parent.document).val(link_obj.innerHTML);
			jQ('#wnode2', parent.parent.document).val(currentNode);

			// RTC 20080908: no longer using frames, this code wouldnt work
			//top.frames['block_page'].xl_GetObj('auxframe').style.display='none';
			//top.frames['block_page'].document.headfrm.auxframe').style.display='none';
			jQ('#auxframe').hide();

			return;

		}
		else if (framename == '')
		{
			parent.parent.setPlaceIn(link_obj.innerHTML, currentNode);

			var ajaxurl = "NXDOCSRCH2.pgm?task=fldrlist&instance=" + instance + "&fromnode=" + currentNode; 
			jQ.get(ajaxurl, function(resp)
			{
				Ldplaceafter('placeafter', resp);
			});

			jQ(parent.parent.document).find('#doctree').hide();
		}
	}
	else if (listType == 'M')
	{
		parent.frames["text"].location = link_url;

	}
	else if (listType == 'U')
	{
		if (urltype == "I")
		{
			var strpos = link_url.search(sitepath);
			link_url = link_url.substring(strpos);
			parent.parent.inpImgURL.value = link_url;

		}
		else if (urltype == "H")
		{
			var strpos = link_url.search('&docnum=');

			var strpos2 = link_url.search('http:');
			if (strpos2 < 0)
			{
				strpos2 = 0;
			}
			else
			{
				strpos2 = strpos2 + 7;
			}

			parent.parent.inpURL.value = link_url.substring(strpos2,strpos);
			parent.parent.javaURL.value = 'if (parent.oUtil == undefined){this.href = \'' + sitepath + 'nxmenu.pgm?docnum=' + docnum + '\';}';
			parent.parent.inpTarget.options[0].selected = true;
			parent.parent.inpTargetCustom.value = '_top';
			parent.parent.inpType.options[1].selected = true;
		}
		else if (urltype == "U")
		{
			var strpos2 = link_url.search(sitepath2);
			if (strpos2 < 0)
			{
				strpos2 = 0;
			}
			else
			{
				strpos2 = strpos2;
			}

			jQ(parent.parent.document).find('#inpURL').val( link_url.substring(strpos2) );
		}

		jQ(parent.parent.document).find('#doctree').hide();
	}
	else if((listType == "A") 
		 || (listType == "F") 
		 || (listType == "C") 
		 || (listType == 'Z'))
	{	
		if (link_url)
		{
			if (framename == 'ECMQuickLoc')
			{
				jQ('#nodename2', parent.parent.document).val( link_obj.innerHTML );
				jQ('#wnode2',parent.parent.document).val( docnum );	

				// RTC 20080909: removed frames, this wont work 
				//top.frames['block_page'].xl_GetObj('auxframe').style.display='none';
				jQ('#auxframe', top.document).hide();
				return;	
			}
			else if (framename == 'ECMQuickLoc2')
			{
				// RTC 20080909: removed frames, this wont work 
				//var ifr = top.frames['block_page'].xl_GetObj('quickframe');
				var ifr = jQ('#quickframe',top.document)[0];
				jQ(ifr.contentWindow.document).find('#nodename2').val( link_obj.innerHTML );
				jQ(ifr.contentWindow.document).find('#wnode2').val( docnum );	

				// RTC 20080909: removed frames, this wont work 
				//top.frames['block_page'].xl_GetObj('auxframe').style.display='none';
				jQ('#auxframe', top.document).hide();

				return;	
			}
			else if (framename == 'ECMQuickAdd')
			{
				if (listType == "A")
				{
					jQ(parent.parent.document).find('#url').val(link_url);
				}
				else
				{						
					jQ('#nodename2', parent.parent.document).val( link_obj.innerHTML );
					jQ('#wnode2', parent.parent.document).val( docnum );
				}

				// RTC 20080909: removed frames, this wont work 
				//top.frames['block_page'].xl_GetObj('auxframe').style.display='none';
				jQ('#auxframe', top.document).hide();

				return;

			}
			else if (framename != '')
			{
				// RTC 20080909: removed frames, this wont work 
				//var ifr = top.frames['block_page'].xl_GetObj(framename);
				var ifr = jQ('#'+framename)[0];

				if (listType == "A")
				{
					jQ(ifr.contentWindow.document).find('#url').val(link_url);
				}
				else
				{						
					jQ(ifr.contentWindow.document).find('#nodename2').val( link_obj.innerHTML );
					jQ(ifr.contentWindow.document).find('#wnode2').val( docnum );
				}

				// RTC 20080909: removed frames, this wont work 
				//top.frames['block_page'].xl_GetObj('auxframe').style.display='none';
				jQ(top.document).find('#auxframe').hide();
				return;
			}
			else
			{
				//RTC 20090507: properly handle the link node add link lookup
				if(listType == 'A')
				{
					jQ('#wnode2',parent.parent.document).val(docnum);
					jQ('#nodename2',parent.parent.document).val(link_obj.innerHTML);
				}
				else
				{
				// end RTC 20090507
				
					jQ(parent.parent.document).find('#wnode').val(docnum);
					jQ(parent.parent.document).find('#nodename').val(link_obj.innerHTML);
					if( jQ(parent.parent.document).find('#lnsdsc').size > 0)
					{
						//default short description
						if ( jQ(parent.parent.document).find('#lnsdsc').val() == '')
						{
							jQ(parent.parent.document).find('#lnsdsc').val( link_obj.innerHTML );
						}

						//default long description
						if ( jQ(parent.parent.document).find('#lnldsc') == '')
						{
							jQ(parent.parent.document).find('#lnldsc').val( link_obj.innerHTML );
						}
					}
				}
			}
		}
		else
		{
			jQ(parent.parent.document).find('#wnode2').val(0);
			jQ(parent.parent.document).find('#nodename2').val('Top of Tree');
		}

		jQ(parent.parent.document).find('#doctree').hide();
	}
	else
	{	
		if (link_target == "_blank")
		{
			window.open(link_url, '_blank');
		}
		else
		{
			var strpos = link_url.search('tmpnbr=');
			var template = link_url.substring((strpos + 7)); 
			strpos = template.search('&');

			if (strpos != -1)
			{
				template = template.substring(0, strpos); 
			}

			// reuse the current template if the template is the same and the reuse templates option is on 
			if((template == jQ(parent.document).find('#template').val()) 
			&& (jQ(parent.document).find('#lnknum').val() != docnum)
			&& (ReuseTemplate == 'Y'))
			{
				jQ(parent.document).find('#lnknum').val(docnum);

				if( jQ(parent.document).find('#edtwindow')[0] )
				{
					if((link_obj.parentNode.id.substring(7,8) == 'A') 
					|| (link_obj.parentNode.id.substring(7,8) == 'P') )
					{
						jQ(parent.document).find('#edtwindow').show();
					}
					else
					{
						jQ(parent.document).find('#edtwindow').hide();
					}
				}

				// RTC 20080811: removing frames
				//top.frames['title'].document.headfrm.docnum.value = docnum;
				//top.frames['title'].loadBreadCrumbs();	
				jQ(top.document).find('#docnum').val(docnum);
				top.loadBreadCrumbs();

				var t;
				for (t = 0; t < parent.ECMNavigatorctr; t++)
				{

					var ifr = jQ(parent.document).find('#' + parent.ECMNavigators[t])[0];
					if(ifr)
					{
						ifr.contentWindow.RemovedSelected();
						ifr.contentWindow.selectNode(docnum);
					}

				}



				var myurl = "NXMNGDOC.PGM?task=loaddoc&wnode=" + docnum;
				if (favorites == "Y")
				{
					jQ.get(myurl, parent.Rcv_AJAX_LoadDoc);
					jQ('#favoritesdiv',parent.document).hide();
				}
				else
				{		
					jQ.get(myurl, Rcv_AJAX_LoadDoc);
				}


			}
			else
			{
				if( (link_url.search('&') > 0) 
				&& (link_url.search('\\?') > 0) )
				{
					top.location.href = link_url + "&rnd=" + Math.random();
				}
				else
				{
					top.location.href = link_url;
				}
			}
		}
	}
}

function dymloadurl(url)
{
	var strpos = url.search('tmpnbr=');
	var template = url.substring((strpos + 7)); 
	strpos = template.search('&');
	
	if (strpos != -1)
	{
		template = template.substring(0, strpos); 
	}
	
	strpos = url.search('docnum=');
	var docnum = url.substring((strpos + 7)); 
	strpos = docnum.search('&');
	
	if (strpos != -1)
	{
		docnum = docnum.substring(0, strpos);
	}
	
	strpos = url.search('lnknum=');
	var lnknum = url.substring((strpos + 7)); 
	strpos = lnknum.search('&');
	
	if (strpos != -1)
	{
		lnknum = lnknum.substring(0, strpos);
	}
	
	if( (jQ('#template')[0])
	&& (jQ('#template')[0].value == template) )
	{
		document.docform.lnknum.value = docnum;
		
		//RTC 20080820: fix to work without frames
		//top.frames['title'].xl_GetObj('docnum').value = docnum;
		//top.frames['title'].loadBreadCrumbs();	
		
		jQ('#docnum').val(docnum);
		loadBreadCrumbs();
		// ... end RTC 20080820
		
		var t;
		for (t = 0; t < ECMNavigatorctr; t++)
		{
			
			var ifr = jQ('#' + ECMNavigators[t])[0];
			if(ifr)
			{		
				ifr.contentWindow.RemovedSelected();
				ifr.contentWindow.selectNode(lnknum);
			}
		}
		
		var myurl = "NXMNGDOC.PGM?task=loaddoc&wnode="+ docnum;		
		//var mydiv;
		//xl_AjaxUpdate(myurl, mydiv, Rcv_AJAX_LoadViewDoc);
		
		jQ.get(myurl, Rcv_AJAX_LoadViewDoc);
		
	}
	else
	{
		top.location.href = url + "&rnd=" + Math.random();
	}
}

function selectNode(lnknum)
{
	var currentSelect;
	
	/* 200806?? jquery conversion
	if (xl_GetObj(lnknum + 'V'))
		currentSelect = xl_GetObj(lnknum + 'V');	
	else if (xl_GetObj(lnknum + 'A'))
		currentSelect = xl_GetObj(lnknum + 'A');

	if (currentSelect)
	{
		
		var children = currentSelect.childNodes; 
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].nodeName == "A") 
			{
				children[i].className = 'Selected';
				break;
			}
		}
		
		currentNode = lnknum;
	}
	*/
	
	currentSelect = jQ('#' +lnknum + 'V').children('A:first').replaceClass('Selected');
	if(!currentSelect)
	{
		currentSelect = jQ('#' +lnknum + 'A').children('A:first').replaceClass('Selected');
	}
	
	if(currentSelect)
	{
		currentNode = lnknum;
	}
}

function RemovedSelected()
{	
	/* 200806?? jquery conversion
	var currentSelected = xl_GetObj(currentNode + 'V');
	if (currentSelected == null)
		currentSelected = xl_GetObj(currentNode + 'A');
	
	if ((currentSelected) && (currentSelected.tagName == 'LI'))
	{
		children = currentSelected.childNodes; 
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].nodeName == "A") 
			{
				EventObj = children[i];
				break;
			}
		}
		EventObj.className = "";	
	}
	*/
	
	var currentSelected = jQ('#'+currentNode + 'V').is('LI');
	if(currentSelected)
	{
		EventObj = jQ(currentSelected).children('A:first');
		EventObj.removeClass();
	}
	

}

function Rcv_AJAX_LoadViewDoc(response)
{
	jQ('#docname').html('');
	
	var docnbr = response.substring(0, 9);
	var title = response.substring(9, 100);
	var doctype = response.substring(109, 125);
	var resize = response.substring(125, 126);
	var docpath = response.substring(126, 1000);
	var url = response.substring(1126, 5000);
	
	var checkurl = url.toUpperCase();	
	var reload = checkurl.search('NXMENU.PGM');
	if( reload != -1 )
	{
		top.location.href = url;
		return; 
	}
	
	jQ('#docnum').val(docnbr);
	jQ('#docpath').val(docpath);
	jQ('#docname').html(title);
	jQ('#loading').show();

	if( jQ('#ECMemail') )
	{
		if((doctype == "Folder          ") 
		|| (doctype == "Symbolic        ") )
		{
			jQ('#ECMemail').hide();
		}
		else
		{
			jQ('#ECMemail').show();
		}
	}

	if( jQ('#ECMprint') ) 
	{
		if( (doctype == "PDF             ") || (doctype == "pdf             ") )
		{
			jQ('#ECMprint').hide();
			
			//RTC 20081119: PDFs wont autosize, so lets set the viewer to a large, standard size
			jQ(parent.document).find('#ifrmviewdoc').height(600);
			resize = 'N';
			
		}
		else
		{
			jQ('#ECMprint').show();
		}
	}
	
	if( resize == 'Y' )	
	{	
		//RTC 2008117: access might be denied to child frame document, so use try/catch
		try
		{
			var viewerbody = jQ('#ifrmviewdoc')[0].contentWindow.document.body;
			var activewidth = viewerbody.scrollWidth - 10;
			jQ(viewerbody).html("<image src=\"" + url + "\" style=\"width:" + activewidth  + "px\">");
			
			//success, return since we're done
			return;
		}
		catch(error)
		{}
	}

	if (url.search('&') > 0)
	{
		jQ('#ifrmviewdoc')[0].src = url + "&rnd=" + Math.random();
	}
	else
	{
		jQ('#ifrmviewdoc')[0].src = url + "?rnd=" + Math.random();
	}
	
	// RTC 20080820: simplified viewer resizing
	//loaddocchk();
}

function Rcv_AJAX_LoadDoc(response)
{
	jQ(parent.document).find('#docname').html('');
	
	var docnbr = response.substring(0, 9);
	var title = response.substring(9, 100);
	var doctype = response.substring(109, 125);
	var resize = response.substring(125, 126);
	var docpath = response.substring(126, 1000);
	var url = response.substring(1126, 5000);
	
	var checkurl = url.toUpperCase();	
	var reload = checkurl.search('NXMENU.PGM');
	if (reload != -1)
	{
		top.location.href = url;
		return; 
	}
	
	parent.document.docform.docnum.value = docnbr;
	parent.document.docform.docpath.value = docpath;

	jQ(parent.document).find('#docname').html(title);
	jQ(parent.document).find('#loading').show();
	
	if( jQ(parent.document).find('#ECMemail') ) 
	{
		if((doctype == "Folder          ") 
		|| (doctype == "Symbolic        "))
		{
			jQ(parent.document).find('#ECMemail').hide();
		}
		else
		{
			jQ(parent.document).find('#ECMemail').show();
		}
	}
	if( jQ(parent.document).find('#ECMprint') )
	{	
		if((doctype == "PDF             ") 
		|| (doctype == "pdf             "))
		{
			jQ(parent.document).find('#ECMprint').hide();
			
			//RTC 20081119: PDFs wont autosize, so lets set the viewer to a large, standard size
			jQ(parent.document).find('#ifrmviewdoc').height(600);
			resize = 'N';
		}
		else
		{
			jQ(parent.document).find('#ECMprint').show();
		}
	}

	if (resize == 'Y')	
	{
		try
		{
			var viewerbody = jQ(parent.document).find('#ifrmviewdoc')[0].contentWindow.document.body;
			var activewidth = viewerbody.scrollWidth - 10;
		
			jQ(viewerbody).html("<image src=\"" + url + "\" style=\"width:" + activewidth  + "px\">");
			
			return;
		}
		catch(error)
		{}
		
	}

	//RTC 20081117: this is the default loading handler, use this if we fail to autosize an image (above block)
	if (url.search('\\?') > 0)
	{
		jQ(parent.document).find('#ifrmviewdoc')[0].src = url + "&rnd=" + Math.random();
	}
	else
	{
		jQ(parent.document).find('#ifrmviewdoc')[0].src = url + "?rnd=" + Math.random();
	}
		
	// RTC 20080820: replaced resizing method
	// parent.loaddocchk();
}


function ChgStatusBar(e)
{
	var MyEventObj = e.target;
	var EventObj = MyEventObj; 
	
	if((EventObj)
	&& (EventObj.nodeName == "LI"))
	{ 
		var children = EventObj.childNodes; 
		
		for (var i = 0; i < children.length; i++) 
		{
			if (children[i].nodeName == "A") 
			{
				MyEventObj.title = children[i].title; 
				EventObj = children[i];
				break; 
			}
		}
	}
	
	if((EventObj) 
	&& (EventObj.href)) 
	{
		if(document.all)
		{
			window.status = EventObj.href + ' (' + EventObj.innerText+ ')';
		}
		else
		{
			window.status = EventObj.href + ' (' + EventObj.textContent + ')'; 
		}
		
		return true; 
	}
} 

function ClrStatusBar()
{ 
	window.status= ""; 
	return true;
}

//highlights the selected ECM document and expands it if it is a folder
function openTree2(myid, response)
{ 	
	try 
	{ 
		var objpar = jQ('#mi'+myid)[0].parentNode;
		if( objpar.className != '')
		{			
			jQ("#mi"+myid).html(response);
		
			if (objpar.className == "nxFavFolder")
			{
				objpar.className = "nxOpFavFolder";
			}
			else
			{
				objpar.className = "nxOpFolder";
			}
		}
		
		if((openIndex == 0) 
		&& (subfolder == 'Y'))
		{			
			EventObj = jQ(objpar).children('A:first');
			EventObj.replaceClass("selected");
		}
		
		// TODO: make sure this is correct
		if(scrollto)
		{
			jQ(window.document).scroll(scrollto);
		}
	}
	catch(err) {}
	
	openIndex = openIndex - 1;
	openTree3();
	
	if (adjustSize)
	{	 
		sizeNavigator();
	}
}  

function addentry(url)
{
	parent.frames["text"].location = url;
	Show_New_Window = false; 
}


function displayDocuments()
{
	var optvalue = "";
	var optkey = "DISPLAYDOCUMENTS" + instance;
	var contentdisp = jQ('#content').css('display');
	
	if ( contentdisp == '' || contentdisp == 'block')
	{
		jQ('#viewdocs').replaceClass('ecmexpand');
		jQ('#content').hide();
		
		optvalue = "N";
		var iframeElement = jQ(parent.document).find('#'+window.name);
		iframeElement.height( jQ('#topbanner').height() );
	}
	else
	{		
		jQ('#viewdocs').replaceClass('ecmcollapse');
		jQ('#content').show();
		
		optvalue = "Y";
		sizeNavigator();
	}
	
	setserver(optkey, optvalue);
}

function quickaddmenu(framename)
{	
	jQ('#'+framename).val(framename);
	
	/* 200806?? jquery conversion
	if (xl_GetObj('ECMType').value == "Symbolic")
	{
		xl_GetObj('addname').innerHTML = "Name";
		xl_GetObj('path').style.display = '';
		xl_GetObj('openin').style.display = '';
		
		if (framename == 'favframe')
		{
			if (document.docform.lnknum.value != '0000000')
				xl_GetObj('url').value = 'nxmenu.pgm?docnum=' + document.docform.lnknum.value;
			else 
				xl_GetObj('url').value = 'nxmenu.pgm?pgrrn=' + document.docform.pgrrn.value;
		}
	}
	else if (xl_GetObj('ECMType').value == "Folder")
	{
		xl_GetObj('addname').innerHTML = "Folder Name:";
		xl_GetObj('path').style.display = 'none';
		xl_GetObj('openin').style.display = 'none';
	}
	
	xl_GetObj('quickadd').style.zIndex = 55;
	xl_GetObj('quickadd').style.display = "";
	*/
	
	if ( jQ('#ECMType').val() == "Symbolic" )
	{
		jQ('#addname').html("Name");
		jQ('#path').show();
		jQ('#openin').show();

		if (framename == 'favframe')
		{
			if ( jQ('#lnknum').val() != '0000000')
			{
				jQ('#url').val('nxmenu.pgm?docnum=' + jQ('#lnknum').val() );
			}
			else
			{
				jQ('#url').val('nxmenu.pgm?pgrrn=' + jQ('#pgrrn').val() );
			}
		}
	}
	else if ( jQ('#ECMType').val() == "Folder")
	{
		jQ('#addname').html("Folder Name:");
		jQ('#path').hide();
		jQ('#openin').hide();
	}

	jQ('#quickadd').css('zIndex',105);
	jQ('#quickadd').show();
	
	setTimeout('jQ(\'#title\').focus();', 10);
}

function quickmenu(addtype, e)
{
	var qadd = jQ(parent.document).find('#quickadd');
	var displayAddFlag = 'N';
	var url;
	
	
	/*RTC 20081212: refactor & simplify
	jQ('#adduploads').attr('src',"/nexuspublic/images/adddocument.gif");
	jQ('#addhtmls').attr('src', "/nexuspublic/images/addhtml.gif");
	
	jQ('#addfavs').attr('src', "/nexuspublic/images/addlink.gif");
	jQ('#addfolders').attr('src', "/nexuspublic/images/addfolder.gif");
	
	
	if (addtype == "Symbolic")
	{
		if((qadd.css('display') == '') 
		&& ( jQ(parent.document).find('#ECMType').val() == "Symbolic"))
		{
			qadd.hide();
		}
		else
		{
			jQ('#addfavs').attr('src', "/nexuspublic/images/addlinksel.gif");
			url ="NXMNGDOC.pgm?task=quickadd&instance=" + instance + "&ECMType=" + addtype + "&wnode=" + currentNode + "&framename=" + this.name + "&favorites=" + favorites; 
			displayFlag = 'Y';
		}
	}
	else if (addtype == "Folder")
	{
		if((qadd.css('display') == '') 
		&& ( jQ(parent.document).find('#ECMType').val() == "Folder"))
		{
			jQ(qadd).hide();
		}
		else
		{
			jQ('#addfolders').attr('src',"/nexuspublic/images/addfoldersel.gif");
			url ="NXMNGDOC.pgm?task=quickadd&instance=" + instance + "&ECMType=" + addtype + "&wnode=" + currentNode + "&framename=" + this.name + "&favorites=" + favorites;
			displayFlag = 'Y';
		}
		
	}
	else if (addtype == "document")
	{
		var ifr = jQ(parent.document).find('#quickframe')[0];
		if(( jQ(parent.document).find('#quickadd2').css('display') == '') 
		&& ( jQ(ifr.contentWindow.document).find('#ECMType').val() == "document"))
		{
			jQ(parent.document).find('#quickadd2').hide();
		}
		else
		{
			jQ('#adduploads').attr('src', "/nexuspublic/images/adddocumentsel.gif");
			url = "nxmngdoc.pgm?task=quickECMAdd&ECMType=document&framename=" + this.name + "&instance=" + instance + "&wnode="+ currentNode + "&framename=" + this.name + "&favorites=" + favorites;
			displayFlag = 'Y';
		}
	}
	else if (addtype == "addhtml")
	{
		var ifr = jQ(parent.document).find('#quickframe')[0];
		if((jQ(parent.document).find('#quickadd2').css('display') == '') 
		&& ( jQ(ifr.contentWindow.document).find('#ECMType').val() == "HTML"))
		{
			jQ(parent.document).find('#quickadd2').hide();
		}
		else
		{
			jQ('#addhtmls').attr('src', "/nexuspublic/images/addhtmlsel.gif");
			url = "nxmngdoc.pgm?task=quickECMAdd&ECMType=HTML&framename=" + this.name + "&instance=" + instance + "&wnode=" + currentNode + "&framename=" + this.name + "&favorites=" + favorites;
			displayFlag = 'Y';
		}
	}
		
	jQ(parent.document).find('#quickadd2').hide();

	var framename = jQ(parent.document).find('#'+this.name)[0];

	var widthLoc;

	if((addtype == "Folder") 
	|| (addtype == "Symbolic"))
	{
		widthLoc = 600;
	}
	else if (addtype == "document")
	{
		widthLoc = 600;
	}
	else if (addtype == "addhtml")
	{
		widthLoc = 900;
	}

	if (!e)
	{
		e = window.event;
	}

	x = xl_FindPosX(framename) + e.x;
	y = xl_FindPosY(framename) + jQ('#topbanner')[0].scrollHeight;

	if ((widthLoc + x) > parent.document.body.scrollWidth)	
	{
		x = (x - widthLoc);
		if (x < 0)
		{
			x = 10;
		}
	}
	else
	{
		// TODO: huh?
		if((x > 1) 
		&& (x < 45))
		{
			x = 18;	
		}
		else if((x > 45) 
		&& (x < 75))
		{
			x = 45;	
		}
		else if((x > 75) 
		&& (x < 105))
		{
			x = 75;
		}
		else if((x > 105) 
		&& (x < 125))
		{
			x = 105;
		}
	}
	
	/ * RTC 20081208: refactoring logic blocks to simplify
		if ((displayFlag == 'Y') && ((addtype == "Symbolic") || (addtype == "Folder")))
		{
			qadd.style.left = x + 'px';
			qadd.style.top =  y + 'px';
	
			jQ(parent.document).find('#quickadd2').hide();
			jQ.get(url, function(resp)
			{
				Rcv_AJAX_quickadd(qadd,resp);
			});
		}
		else if((displayFlag == 'Y') 
		&& ((addtype == "document") || (addtype == "addhtml")))
		{
			var framename = 'quickframe';	
			var ifr = jQ(parent.document).find('#'+framename)[0];
	
			ifr.src = url;
			ifr.style.left = x + 'px';
			ifr.style.top =  y + 'px';
	
			jQ(parent.document).find('#quickadd2').css('zIndex',105);
			jQ(qadd).hide();
		}
	* /
	
	if(displayFlag == 'Y')
	{
			if((addtype == "Symbolic") 
			|| (addtype == "Folder"))
			{
				qadd.css('left', x + 'px');
				qadd.css('top',  y + 'px');
		
				jQ(parent.document).find('#quickadd2').hide();
				jQ.get(url, function(resp)
				{
					Rcv_AJAX_quickadd(qadd,resp);
				});
			}
			
			if((addtype == "document") 
			|| (addtype == "addhtml"))
			{
				var framename = 'quickframe';	
				var ifr = jQ(parent.document).find('#'+framename);
		
				ifr.attr('src', url);
				ifr.css('left', x + 'px');
				ifr.css('top', y + 'px');
		
				jQ(parent.document).find('#quickadd2').css('zIndex',105);
				qadd.hide();
			}
		}
	// end RTC 20081208
	*/
	
	switch(addtype)
	{
		//note: links and folders use a popup div, uploading and adding html uses an iframe
		case "Symbolic": 
		case "Folder":
		{
			//toggle the frame closed if the current selection is already open
			if((qadd.css('display') == '')
			&& (jQ(parent.document).find('#ECMType').val() == addtype))
			{
				qadd.hide();
				return;
			}
			
			//otherwise build the URL to load into the div
			url ="NXMNGDOC.pgm?task=quickadd&instance=" + instance + "&ECMType=" + addtype + "&wnode=" + currentNode + "&framename=" + this.name + "&favorites=" + favorites;
			break;
		}
		case "document":
		case "addhtml":
		{
			var ifr = jQ(parent.document).find('#quickframe');
			
			//if the iframe is already open for the current selection, toggle it closed
			if((jQ(parent.document).find('#quickadd2').css('display') == '') 
			&& (jQ(ifr.contentWindow.document).find('#ECMType').val() == addtype))
			{
				jQ(parent.document).find('#quickadd2').hide();
				return;
			}
			
			//otherwise construct the URL to load in the iframe
			url = "nxmngdoc.pgm?task=quickECMAdd&ECMType="+addtype+"&framename=" + this.name + "&instance=" + instance + "&wnode="+ currentNode + "&framename=" + this.name + "&favorites=" + favorites;
			
			//TODO RTC 20081212: change nxmngdoc so it accepts addhtml so this code can be removed
			if(addtype == 'addhtml')
			{
				url = "nxmngdoc.pgm?task=quickECMAdd&ECMType=HTML&framename=" + this.name + "&instance=" + instance + "&wnode="+ currentNode + "&framename=" + this.name + "&favorites=" + favorites;
			}
			break;
		}
	}
	
	jQ(parent.document).find('#quickadd2').hide();
	
	var frameobj = jQ(top.document).find('#'+this.name)[0];
	
	//set the size of the destination iframe or div
	var widthLoc = 600;
	if(addtype == "addhtml")
	{
		widthLoc = 900;
	}
	
	//placement coordinates for the popup
	var x = xl_FindPosX(frameobj) + e.pageX;
	var y = xl_FindPosY(frameobj);
	
	//if the current location would place the popup off the edge of the screen, move it left
	if ((widthLoc + x) > parent.document.body.scrollWidth)	
	{
		x = parent.document.body.scrollWidth - widthLoc - 5;
	}

	if((addtype == "Symbolic") 
	|| (addtype == "Folder"))
	{
		qadd.css('left', x + 'px');
		qadd.css('top',  y + 'px');

		jQ(parent.document).find('#quickadd2').hide();
		jQ.get(url, function(resp)
		{
			Rcv_AJAX_quickadd(qadd,resp);
		});
	}

	if((addtype == "document") 
	|| (addtype == "addhtml"))
	{
		var framename = 'quickframe';	
		var ifr = jQ(parent.document).find('#'+framename);

		ifr.attr('src', url);
		ifr.css('left', x + 'px');
		ifr.css('top', y + 'px');

		jQ(parent.document).find('#quickadd2').css('zIndex',105);
		qadd.hide();
	}
	// end RTC20081212

}

function Rcv_AJAX_quickadd(qadd, response)
{
	qadd.html(response);
	qadd.show();
	parent.quickaddmenu(this.name);
	
	//RTC 20081208: bind lookup events
	jQ(qadd).find('#seldoc').bind('click', opendoctree10);
	jQ(qadd).find('#selfolder').bind('click', opendoctree9);
	jQ(qadd).find('#addfavbtn').bind('click', top.addQuickItem);
}

function favoritesSetup(dspfav)
{
	if (dspfav == 'Y')
	{
		jQ('#content').show();
	}
	else
	{
		jQ('#content').hide();
	}
}

// function called when creating an HTML document or uploading a document
function quickfunc(addtype)
{
	//find the iframe containing the current document
	var ifr = jQ(parent.document).find('#'+ window.name);
	
	setTimeout('document.inpform.title.focus();', 10);
	
	jQ(parent.document).find('#quickadd2').show();
	
	if (addtype == "HTML")
	{
		jQ('#pcfile').hide();
		ifr.css('width', '900px');
	}
	else if (addtype == "document")
	{
		jQ('#pcfile').show();
		ifr.css('width', '600px');
	}
	
	//resize the containing iframe
	ifr.height(document.body.scrollHeight + 5);
}

function addfile_setup(optaddsrch, optaddapnd)
{
	if (optaddsrch == "Y")
	{	
		jQ('#optbox4').show();
	}
	
	if (optaddapnd == "Y")
	{	
		jQ('#optbox5').show();
	}
	
	document.forms[0].srchkeys.enabled="true";
	document.forms[0].addsearch.disabled="true";
	document.forms[0].addappend.disabled="true";
	
	if (document.forms[0].addtype.value == "Folder")
	{		
		jQ('#pcfile').hide();
		jQ('#Symbolic').hide();
		jQ('#prcdir').hide();
		jQ('#symlnk').hide();
		
		if (document.inpform.task.value != 'endadd')
		{
			jQ('#downloadbtn').hide();
		}
	}
	else if (document.forms[0].addtype.value == "Symbolic")
	{
		jQ('#Symbolic').show();
		jQ('#pcfile').hide();
		
		if (document.inpform.task.value != 'endadd')
		{			
			jQ('#urlview').show();
			jQ('#downloadbtn').hide();
			jQ('#urlview2').hide();
		}
	}
	else
	{
		jQ('#pcfile').show();
		jQ('#Symbolic').hide();
		jQ('#prcdir').hide();
		jQ('#symlnk').hide();
	}
	
}

function edit_setup(allowkv, framename)
{
	if((document.inpform.auxicons.value == "Y") 
	&& (document.inpform.objauth.value == "Y")  
	&& (document.forms[0].addtype.value != "Header") 
	&& (document.forms[0].addtype.value != "Symbolic"))
	{
		if((document.inpform.addtype.value != "Folder") 
		&& (document.inpform.addtype.value != "Header"))
		{
			jQ('#auxregister').show();
		}
	
		jQ('#auxselect').show();
		
		if((document.inpform.auxsmurf.value != "") 
		|| (document.inpform.srchkeys.value.search('ListObjects') != -1))
		{
			document.inpform.srchkeys.disabled = true;
		}
	}
	
	if((document.forms[0].addtype.value == "Folder") 
	|| (document.forms[0].addtype.value == "Header"))
	{		
		jQ('#filetype').hide();
		jQ('#pcfile').hide();
		jQ('#Symbolic').hide();
		jQ('#prcdir').hide();
		jQ('#symlnk').hide();
		
		if (document.forms[0].addtype.value == "Folder")
		{
			jQ('#downloadbtn').hide();
			jQ('#fdermode').show();
		}
		else
		{	
			jQ('#htmledit').show();
			jQ('#htmldftcnt').show();	
		}
		
	}
	else if (document.forms[0].addtype.value == "Symbolic")
	{
		jQ('#filetype').show();
		jQ('#Symbolic').show();
		jQ('#fdermode').hide();
		jQ('#pcfile').hide();
		
		if (document.inpform.task.value  != 'endadd')
		{	
			jQ('#urlview').show();
			jQ('#downloadbtn').hide();
			jQ('#urlview2').hide();
		}

		sellink();
	}
	else
	{			
		jQ('#filetype').show();
		jQ('#fdermode').hide();
		if (document.inpform.htmlflag.value == 'HTML')
		{
			jQ('#pcfile').hide();
			jQ('#template').show();
			jQ('#htmledit').show();
			jQ('#htmldftcnt').show();
		}
		else
			jQ('#pcfile').show();

		jQ('#Symbolic').hide();
		jQ('#prcdir').hide();
		jQ('#symlnk').hide();
	}
	
	if((document.forms[0].addtype.value == "Header") 
	|| ((document.forms[0].addtype.value == "Symbolic") 
	&&  (document.inpform.lnktype.selectedIndex == 0) ))
	{
		jQ('#template').hide();
	}
	else
	{
		jQ('#template').show();
	}	
	
	if((document.forms[0].addtype.value == "Header") 
	|| (document.forms[0].addtype.value == "Symbolic") 
	|| ((document.inpform.htmlflag.value != 'HTML') 
	&&  (document.forms[0].addtype.value != "Folder")) )
	{
		jQ('#skins').hide();
	}
	else
	{
		jQ('#skins').show();
	}	
	
	if (document.inpform.objauth.value == "Y")
	{	
		jQ('#move0').show();
		jQ('#deletercd').show();
		jQ('#deletercd2').show();
		jQ('#hidden2').show();
	}
	
	if (allowkv == "Y")
	{
		jQ('#allowkv1').show();
	} 
	else 
	{
		jQ('#allowkv1').hide();
	}
	
	if (window.name == "quickframe")
	{
		jQ('#closebutton').show();
		
		//var ifr = parent.xl_GetObj(window.name);
		var ifr = parent.window;
	
		jQ(parent.document).find('#quickadd2').show();
		
		jQ(ifr).css('width', '825px');
		jQ(ifr).css('height', (document.body.scrollHeight + 5) + 'px');
	}
	
	check_type();
}

//RTC 20100113: auxreg function used by Medaxiom
function auxreg()
{
	if((document.inpform.auxicons.value == "Y")
	&& (document.inpform.objauth.value == "Y"))
	{
		var ifr = jQ('#keyframe')[0];
		
		ifr.style.left = '30px';
		ifr.style.top =  '30px';
		ifr.style.height = 420 + 'px';
		ifr.style.width = 400 + 'px';
		ifr.style.zIndex=50;
		
		var url = 'MEREGAPP.pgm?docnum=' + document.inpform.DMDCNB.value + '&auxsmurf=' +document.inpform.auxsmurf.value;
		ifr.src = url;
	
		jQ('#keypair').show();
	}
}

//RTC 20100113: add auxsel function used by Medaxiom
function auxsel()
{
	// Allow for special auxicons flag
	if ((document.inpform.auxicons.value == "Y") && (document.inpform.objauth.value == "Y"))
	{
		var ifr = jQ('#key2frame')[0];

		ifr.style.left = '30px';
		ifr.style.top =  '30px';
		ifr.style.height = 625 +'px';
		ifr.style.width = 655 +'px';
		ifr.style.zIndex=50;

		var url = 'MESELLST.pgm?docnum=' + document.inpform.DMDCNB.value + '&auxsmurf='  +document.inpform.auxsmurf.value;
		ifr.src = url;

		jQ('#key2pair').show();
	}
}

//RTC 20090114: get instance value directly from the page
function openkey(ev) 
{ 
	var ifr = jQ('#keyframe');
	
	ifr.css('left',(ev.pageX - 200) + 'px');
	ifr.css('top', (ev.pageY + 15) + 'px');
	ifr.css('zIndex',50);
	ifr.height(210);
	
	//TODO: remove use of this global
	if (keyloaded == false)
	{
		var url = 'NXSRCHKEY.pgm?instance=' + jQ('#instance').val() + "&rnd=" + Math.random();
		ifr.attr('src',url);
		keyloaded = true;
	}
	
	jQ('#keypair').show();
	jQ('#key2pair').hide();
	
	adjustParent();
}

function openkey2(ev) 
{ 
	
	var ifr = jQ('#key2frame');

	// TEH 20091006 - Only used in ECM Search portlet options so I'm customizing to look nice there
	//ifr.css('left', (ev.pageX - 175) + 'px');
	//ifr.css('top',  (ev.pageY + 15) + 'px');
	ifr.css('left', (ev.pageX - 375) + 'px');
	ifr.css('top',  (ev.pageY - 115) + 'px');
	ifr.css('zIndex',50);
	ifr.height(210);
	
	//TODO: remove use of this global
	if (key2loaded == false)
	{
		var url = 'NXSRCHKEY2.pgm?instance=' + jQ('#instance').val() + "&rnd=" +  Math.random();
		ifr.attr('src',url);
		key2loaded = true;
	}
	
	jQ('#key2pair').show();
	jQ('#keypair').hide();

	adjustParent();
}

function openkey3(instance, ev) 
{ 
	var ifr = jQ('#keyframe');

	ifr.css('left', ev.pageX + 'px');
	ifr.css('top',  ev.pageY + 'px');
	ifr.css('zIndex', 50);
	ifr.height(210);
	
	//TODO: remove use of this global
	if (key2loaded == false)
	{
		var url = 'NXSRCHKEY.pgm?instance=' + jQ('#instance').val() + "&equal=N" + "&rnd=" + Math.random();
		ifr.attr('src',url);
		keyloaded = true;
	}
	
	jQ('#keypair').show();
	
	adjustParent();
}


function postoend() 
{ 
	document.inpform.srchkeys.value = document.inpform.srchkeys.value + "";
}


function postoend2() 
{ 
	document.inpform.srchkeys2.value = document.inpform.srchkeys2.value + "";
}


function massdelete()
{
	
	if((document.inpform.srchkeys.value != '') 
	|| (document.inpform.srchkeys2.value != ''))
	{	
		var return_value = confirm('You are about to permanently delete all the ECM entries that match the defined search criteria. Do you wish to continue?');
		
		if ( return_value == true )
		{
			inpform.massdltflg.value='Y';
			inpform.submit();
		}
	}
	else
	{
		alert('You must enter a Search Criteria for the Delete');
	}
}


function optdispdocument(optaddsrch, optaddapnd) 
{ 
	if (optaddsrch == "Y")
	{	
		optbox4.style.display = "";
	}
	
	if (optaddapnd == "Y")
	{	
		optbox5.style.display = "";
	}
}

//RTC 20080903: Seperate upload file into filename and extension, and auto populate
// the name input box
function stripfilename()
{
	//find the last '.' character and strip off the extension
	var fullpath = jQ('#upfile').val();
	var x2 = fullpath.lastIndexOf('.');
	
	//determine where to start the substring (the end of the last folder)
	var x1 = fullpath.lastIndexOf('\\') + 1;
	
	//TEH 20091005 - The ID being changed is 'titletext'
	//if(x2 > 0 && jQ('#title').val() == '')
	//{
	//	jQ('#title').val( fullpath.substring(x1,x2) );
	//}
	if(x2 > 0 && jQ('#titletext').val() == '')
	{
		jQ('#titletext').val( fullpath.substring(x1,x2) );
	}

	if(x2 > 0 && jQ('#DMSDSC').val() == '')
	{
		jQ('#DMSDSC').val( fullpath.substring(x1,x2) );
		jQ('#srchkeys').val( fullpath.substring(x1,x2) );
	}
	

	//get the extension value
	//RTC 20091013 changed exttype to lowercase, set the type for the document master to this value, changed the image determination to use lowercase extensions
	var exttype = fullpath.substring(x2+1,fullpath.length).toLowerCase();
	jQ('#type').val(exttype);
	
	if((exttype == "jpg") 
	|| (exttype == "jpeg") 
	|| (exttype == "gif") 
	|| (exttype == "bmp") 
	|| (exttype == "tiff") 
	|| (exttype == "png"))
	{
		jQ('#imgsize').checked = true;
		jQ('#imgsize').show();
	}
	else
	{
		jQ('#imgsize').checked = false;
		jQ('#imgsize').hide();
	}
}

function check_type()
{
	if( jQ('#resize_img') )
	{
		var exttype = document.inpform.wltype.options[document.inpform.wltype.selectedIndex].value.toUpperCase();

		//var exttype = xl_GetObj('wltype').options[xl_GetObj('wltype').selectedIndex].value.toUpperCase();
		if((exttype == "JPG") 
		|| (exttype == "JPEG") 
		|| (exttype == "GIF") 
		|| (exttype == "BMP") 
		|| (exttype == "TIFF") 
		|| (exttype == "PNG"))
		{
			jQ('#resize_img').show();
		}
		else
		{
			jQ('#resize_img').hide();
			jQ('#resize_img').checked = false;
		}
	}
}

function addoptdisp() 
{ 	
	document.forms[0].srchkeys.disabled=false;
	document.forms[0].addsearch.disabled=false;
	document.forms[0].addappend.disabled=false;
	
	var z = 0;
	var endpos;
	var textval = '' + jQ('#upfile').val();
	
	for (var x = 1000; x >= 0; x--) 
	{ 
		z = z + 1;
		var y = textval.substring(x,x - 1);
		
		if (y == '.')
		{
			endpos = x - 1;       	
		}
		
		if (y == "\\") 
		{
			break;
		}
	}
	if((jQ('#DMSDSC').value == "") 
	&& (x > 0))
	{
		jQ('#DMSDSC').val( textval.substring(x,endpos) );
	}
	
	if((jQ('#srchkeys').value == "") 
	&& (x > 0))
	{
		jQ('#srchkeys').val( textval.substring(x,endpos) );
	}
	
	
	if(settype == 'Y')		
	{
		z = 0;
		for (var x = 255; x >= 0; x--) 
		{ 
			z = z + 1;
			var y = document.inpform.upfile.value.substring(x,x - 1);
			
			if (y == ".") 
			{ 
				break;
			} 
		}
		
		var exttype = document.inpform.upfile.value.substring(x,z);
		
		var selectedindex = 0;
		for (var counter=0; counter < document.inpform.wltype.length; counter++) 
		{
			if (document.inpform.wltype.options[counter].value.toUpperCase() == exttype.toUpperCase())
			{
				selectedindex = counter;
			}
		}
		
		if (selectedindex != '')
		{
			document.inpform.wltype.options[selectedindex].selected = true;
		}
		else
		{
			document.inpform.wltype.options[0].selected = true;
		}
		
		check_type();
	}
}

function addvalue() 
{
	document.inpform.srchkeys.value = document.inpform.srchkeys.value + " " + document.inpform.kvpairs.value+"=";
}

function addhtml_setup(allowkv)
{
	if (allowkv == "Y")
	{
		jQ('#allowkv1').show(); 
	}
	else
	{
		jQ('#allowkv1').hide();
	}
}

function setstart()
{
	var current_node = "";
	var parent_node = "";
	
	if((document.inpform.auxicons.value == "Y") 
	&& (document.inpform.objauth.value == "Y") 
	&& (document.forms[0].addtype.value != "Header") 
	&& (document.forms[0].addtype.value != "Symbolic"))
	{
		if((document.inpform.addtype.value != "Folder") 
		&& (document.inpform.addtype.value != "Header"))
		{
			jQ('#auxregister').show();
		}

		jQ('#auxselect').show();
		
		
		if((document.inpform.auxsmurf.value != "") 
		|| (document.inpform.srchkeys.value.search('ListObjects') != -1))
		{
			document.inpform.srchkeys.disabled = true;
		}
	}
}

function statusMsg()
{
	if (document.inpform.statusmsg.value != '') 
	{
		document.write(document.inpform.statusmsg.value);
		var url = 'NXMNGDOC.pgm?task=menuframe&instance=' + document.inpform.instance.value + '&wnode=' + document.inpform.fromnode.value + '&scrollto=' + jQ(parent.document).find('#tree_frame').scrollTop() + "&rnd=" + Math.random();
		parent.frames["tree_frame"].location.href = url;
	}
}

function Reload_MaintTree(node)
{
	var url = 'NXMNGDOC.pgm?task=menuframe&wnode=' + node + '&scrollto=' + jQ(parent.document).find("#tree_frame").scrollTop() + "&rnd=" +  Math.random();
	parent.frames["tree_frame"].location.href = url;
}

function sellink()
{
	
	var linktype = jQ('#lnktype').val();
	if(linktype == "E") //ECM Document
	{
		jQ('#ecmdoc').show();
		jQ('#url').hide();
		jQ('#urldoc').val("");
		jQ('#template').hide();
		jQ('#prcdir').hide();
		
		if ( jQ('#task').val()  != 'endadd')
		{
			jQ('#urlview').hide();
			jQ('#downloadbtn').hide();
			jQ('#urlview2').hide();
		}
	}
	else // URL 
	{
		jQ('#ecmdoc').hide();
		jQ('#url').show();
		if ( jQ('#urldoc').val() == "")
		{
			jQ('#urldoc').val("http://");
		}
		jQ('#wnode2').val(0);
		jQ('#nodename2').val("");
		jQ('#template').show();
	}	
	
}


function changecss()
{
	if (document.inpform.htmlflag.value == 'HTML')
	{
		var cssname;
		var sitepath = document.inpform.sitepath.value;
		
		if (document.inpform.WLSKIN.options[document.inpform.WLSKIN.selectedIndex].value == 0)
		{
			cssname = sitepath + 'ECM/DocSkins/ECMDocSkin' + document.inpform.parentskin.value + '.css';
		}
		else
		{
			cssname = sitepath + 'ECM/DocSkins/ECMDocSkin' + document.inpform.WLSKIN.options[document.inpform.WLSKIN.selectedIndex].value + '.css';
		}
		
		oEdit1.isCssLoaded=false;
		oEdit1.css = cssname;
		oEdit1.arrStyle=[];
		var idStyles=document.getElementById("idStyles"+oEdit1.oName);
		idStyles.innerHTML = '';
		
		document.forms.inpform.taskdesc2.value = oEdit1.getHTMLBody();
		oEdit1.loadHTML(document.forms.inpform.taskdesc2.value);
	}
}

//RTC 20081205: set the parent skin as the default for new quick add HTML documents
function setcss()
{	
	oEdit1.isCssLoaded = false;
	if( jQ('#parentskin').val() > '')
	{
		oEdit1.css = jQ('#sitepath').val() + 'ECM/DocSkins/ECMDocSkin' + jQ('#parentskin').val() + '.css';
	}
	else
	{
		oEdit1.css = jQ('#sitepath').val() + 'ECM/DocSkins/ECMDocSkin1.css';
	}
	
	oEdit1.arrStyle = [];
	var idStyles = jQ('#idStyles' + oEdit1.oName);
	idStyles.html('');

	jQ('#taskdesc2').val( oEdit1.getHTMLBody() );
	oEdit1.loadHTML( jQ('#taskdesc2').val() );
}

//used by create ecm document interface, this will prompt the user to replace
// their current html content with a content template
function changedftcnt()
{
	if ( jQ('#ecmdftcnt').val() != 0)
	{
		var return_value = true;
		if (oEdit1.getHTMLBody() != "")
		{
			return_value = confirm('If you select a new default you will replace the current HTML content. Do you wish to continue?');
		}
		
		if ( return_value )
		{
			var myurl = "NXDOCSRCH2.pgm?task=getdftcnt&dftcntnbr=" + jQ('#ecmdftcnt').val() + '&instance=' + jQ('#instance').val(); 
			
			jQ.get(myurl, function(resp)
			{
				oEdit1.loadHTML(resp);
				changecss();
			});
		}
	}
}

function submitAddForm() 
{
	
	var errorflg = validate();
	if (errorflg != 'Y')
	{
		jQ('#srchkeys').attr('disabled',false);
		jQ('#nodename2').attr('disabled',false);
		
		jQ('#loadingfile').show();
		document.forms.inpform.submit();
	}
}


function submitForm() 
{
	var errorflg = validate();
	if (errorflg != 'Y')
	{
		jQ('#srchkeys').attr('disabled',false);
		jQ('#nodename2').attr('disabled',false);
		
		if ( jQ('#htmlflag').val() == 'HTML')
		{
			
			if ( jQ('#DMTYPE').val() == 'Header')
			{
				jQ('#taskdesc2').val( oEdit1.getHTMLBody() );
			}
			else
			{
				jQ('#taskdesc2').val( oEdit1.getHTML() );
			}
			
			if ( jQ('#taskdesc2').val().length <= 50000)
			{
				document.forms.inpform.submit();
			}
			else
			{
				alert('Error: The documented you attempted to add is ' + jQ('#taskdesc2').val().length + ' characters. The maximum size for documents created in the Nexus ECM is 50,000 characters.');
			}
			
		}
		else
		{
			jQ('#loadingfile').show();
			jQ('#statusmsg').hide();
			
			document.forms.inpform.submit();
		}
		
		if ( jQ('#framename').val() != "")
		{
			jQ(parent.document).find('#quickadd2').hide();
		}
	}
}

function submitFormDocument() 
{
	var errorflg = validate();
	if (errorflg != 'Y')
	{
		
		// Auxinput
		document.inpform.srchkeys.disabled = false;	
		
		if ( jQ('#addtype').val() == "Header")
		{
			jQ('#taskdesc2').val( oEdit1.getHTMLBody() );
		}
		else
		{
			jQ('#taskdesc2').val( oEdit1.getHTML() );
		}
		
		document.forms.inpform.submit();
	}
}

function confirm_delete()
{
	var url = 'NXDOCSRCH2.pgm?task=del&instance=' + jQ('#instance').val() + '&rrn=' + jQ('#rrn').val() + '&wnode=' + jQ('#fromnode').val() + '&framename=' + jQ('#framename').val() + "&rnd=" + Math.random();
	
	if ( jQ('#DMTYPE').val() == 'Folder')
	{
		var return_value = confirm('You are about to permanently delete this folder and all of its subfolders. Do you wish to continue?');
		
		if ( return_value == true )
		{
			document.location = url;
		}
	}
	else
	{
		var return_value = confirm('You are about to permanently delete this object. Do you wish to continue?');
		
		if ( return_value == true )
		{
			document.location = url;
		}
	}
}

//RTC 20081205: moved next to setupEditor for easier comparison
function setupQuickEditor()
{	
	oEdit1.mode="HTMLBody";
	oEdit1.btnSpellCheck=true;
	//RTC 20090220: Update for InnovaEdit 3.5
	oEdit1.useTab=false;
	oEdit1.height="305";
	oEdit1.width="100%";
	
	oEdit1.features=["FullScreen","Preview","Print","Search","Cut","Copy","Paste","PasteWord","PasteText","|","Undo","Redo","|","ForeColor","BackColor","|","Bookmark","Hyperlink","XHTMLSource","|","Numbering","Bullets","|","Indent","Outdent","BRK","Paragraph","FontName","FontSize","|","LTR","RTL","|","Table","Guidelines","Absolute","|","Characters","Line","Form","RemoveFormat","ClearAll","BRK","Image","Flash","Media","|","StyleAndFormatting","TextFormatting","ListFormatting","BoxFormatting","ParagraphFormatting","CssText","Styles","|","Bold","Italic","Underline","Strikethrough","|","JustifyLeft","JustifyCenter","JustifyRight","JustifyFull", "|", "CustomTag", "|", "SpellCheck"];	
	
	var header = '<div class="welcome">Welcome Text...<div class="welcome_Description">Welcome description...</div><br></div>';
	
	var columnheadingfloat = '<div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column 1 text...</div></div>';
	var columnheading = '<div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column 1 text...</div>';
	var bullet = '<li><span class="bullet">Bullet text...</span></li>';
	var TextFrame = '<div align="center"><div class="TextFrame"><span class="innerTextFrame">Test text...</span></div></div>';
	var CenteredImage =  '<div class="image" align="center"><img height="100" width="100" align="middle" border="0"></div>';
	var imageundertext = '<div class="image" align="left">Test text...<br><div align="center"><br><img height="100" width="100" align="middle" border="0"></div></div>';
	var imageabovetext = '<div class="image" align="left"><div align="center"><br><img height="100" width="100" align="middle" border="0"></div><br>Test text...</div>';
	var floatimageleft = '<img class="floatleft" height="100" width="100" align="middle" border="0">';
	var floatimageright = '<img class="floatright" height="100" width="100" align="middle" border="0">';
	var Listitems = '<div class="listitems"><span class="banner">List Heading...</span><ul><li>Item 1</li><li>Item 2</li></ul></div>';
	var quotebox = '<div align="center"><div class="quote" align="center">"Quote..."</div></div>';
	var singlecolumn = '<table class="column_table"><tr><td class="column_Single"><div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column text...</div><br><span class="Guide_Text"> More Column Headings...</span></div></td></tr></table>';
	var twocolumn = '<table class="column_table"><tr><td class="column1"><div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div> <div class="Column_Text">Column text...</div><br><span class="Guide_Text"> More Column Headings...</span></div></td><td class="column_space"></td><td class="column2"><div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column text...</div><br><span class="Guide_Text"> More Column Headings... </span></div></td></tr></table>';
	
	oEdit1.arrCustomTag=[["Single Column",singlecolumn],["Two Column",twocolumn],["Header",header],["column Header",columnheading],["Floating column Header",columnheadingfloat],["bullet",bullet],["List Items",Listitems],["Quote",quotebox],["Text Frame",TextFrame],["Image Under Text",imageundertext],["Image Above Text",imageabovetext],["Centered Image",CenteredImage],["Float Image Left",floatimageleft],["Float Image Right",floatimageright]];
	oEdit1.btnStyles=true;
	oEdit1.initialRefresh=true;
	
	oEdit1.REPLACE("taskdesc2");
	
}

function setupEditor()
{
	
	oEdit1.mode="HTMLBody";
	oEdit1.btnSpellCheck=true;
	//RTC 20090220: Update for InnovaEdit 3.5
	oEdit1.useTab=false;
	oEdit1.height="250";
	oEdit1.width="100%";
	
	oEdit1.features=["FullScreen","Preview","Print","Search","Cut","Copy","Paste","PasteWord","PasteText","|","Undo","Redo","|","ForeColor","BackColor","|","Bookmark","Hyperlink","XHTMLSource","|","Numbering","Bullets","|","Indent","Outdent","BRK","Paragraph","FontName","FontSize","|","LTR","RTL","|","Table","Guidelines","Absolute","|","Characters","Line","Form","RemoveFormat","ClearAll","BRK","Image","Flash","Media","|","StyleAndFormatting","TextFormatting","ListFormatting","BoxFormatting","ParagraphFormatting","CssText","Styles","|","Bold","Italic","Underline","Strikethrough","|","JustifyLeft","JustifyCenter","JustifyRight","JustifyFull", "|", "CustomTag", "|", "SpellCheck"];
	
	var header = '<div class="welcome">Welcome Text...<div class="welcome_Description">Welcome description...</div><br></div>';
	var columnheadingfloat = '<div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column 1 text...</div></div>';
	var columnheading = '<div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column 1 text...</div>';
	var bullet = '<li><span class="bullet">Bullet text...</span></li>';
	var TextFrame = '<div align="center"><div class="TextFrame"><span class="innerTextFrame">Test text...</span></div></div>';
	var CenteredImage =  '<div class="image" align="center"><img height="100" width="100" align="middle" border="0"></div>';
	var imageundertext = '<div class="image" align="left">Test text...<br><div align="center"><br><img height="100" width="100" align="middle" border="0"></div></div>';	
	var imageabovetext = '<div class="image" align="left"><div align="center"><br><img height="100" width="100" align="middle" border="0"></div><br>Test text...</div>';
	var floatimageleft = '<img class="floatleft" height="100" width="100" align="middle" border="0">';
	var floatimageright = '<img class="floatright" height="100" width="100" align="middle" border="0">';
	var Listitems = '<div class="listitems"><span class="banner">List Heading...</span><ul><li>Item 1</li><li>Item 2</li></ul></div>';
	var quotebox = '<div align="center"><div class="quote" align="center">"Quote..."</div></div>';
	var singlecolumn = '<table class="column_table"><tr><td class="column_Single"><div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column text...</div><br><span class="Guide_Text"> More Column Headings...</span></div></td></tr></table>';
	var twocolumn = '<table class="column_table"><tr><td class="column1"><div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div> <div class="Column_Text">Column text...</div><br><span class="Guide_Text"> More Column Headings...</span></div></td><td class="column_space"></td><td class="column2"><div class="column"><div class="Banner"><span class="banner_highlight"></span><span class="banner_space"></span>Column Heading</div><div class="Column_Text">Column text...</div><br><span class="Guide_Text"> More Column Headings... </span></div></td></tr></table>';
	
	oEdit1.arrCustomTag=[["Single Column",singlecolumn],["Two Column",twocolumn],["Header",header],["column Header",columnheading],["Floating column Header",columnheadingfloat],["bullet",bullet],["List Items",Listitems],["Quote",quotebox],["Text Frame",TextFrame],["Image Under Text",imageundertext],["Image Above Text",imageabovetext],["Centered Image",CenteredImage],["Float Image Left",floatimageleft],["Float Image Right",floatimageright]];
	oEdit1.btnStyles=true;
	oEdit1.initialRefresh=true;
	
	oEdit1.REPLACE("taskdesc2");
}

function validate()
{
	var errorflg = val_InpChar('DMSDSC', 'Name', 'doc_name','N');
	var errorflg2 = val_InpChar('dddesc', 'Description', 'doc_description','Y');
	if (errorflg2 == 'Y')
	{
		
		errorflg = 'Y';
	}
	
	// RTC 20080909: simplified
	//if ( jQ('#purgedate')[0] && (( jQ('#purgedate').value != "*NEVER") && (isDate( jQ('#purgedate').value) == false)))
	
	var dateval = jQ('#purgedate').val();
	if((dateval)
	&& (dateval != '*NEVER')
	&& (isDate(dateval) == false ))
	{
		alert('The Purge Date entered is invalid. Make sure it is in yyyy-mm-dd format (Eg: 2001-12-25) or *NEVER.');
		doc_purgedate.className = 'error';
		errorflg = 'Y';
	}
	
	
	if (document.inpform.htmlflag.value != 'HTML')
	{
		if((document.inpform.upfile.value == '') 
		&& (document.inpform.addtype.value != 'Symbolic') 
		&& (document.inpform.addtype.value != 'Folder') 
		&& (document.inpform.DMPCPA.value == ''))
		{
			alert('You must enter a vaild path. Use the Browse button to enter a path.');
			pcfile.className = 'error';
			errorflg = 'Y';
		}
	}
	
	if((document.inpform.addtype.value == 'Symbolic') 
	&& (document.inpform.wnode2.value == 0) 
	&& (document.inpform.lnktype.selectedIndex == 0))
	{
		alert('You must select an ECM location for the link.');
		Symbolic.className = 'error';
		errorflg = 'Y';
	}
	
	if((document.inpform.addtype.value == 'Symbolic') 
	&& (document.inpform.lnktype.selectedIndex == 1) 
	&& (jQ('#urldoc').value == ''))
	{
		alert('You must enter a URL for the link.');
		Symbolic.className = 'error';
		errorflg = 'Y';
	}
	
	return 	errorflg;
}



/*********** Date validation *************/

var dtCh= "-";
var minYear=0001;
var maxYear=2100;

function isInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		if((c < "0") 
		|| (c > "9"))
		{
			return false;
		}
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";

	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1)
		{
			returnString += c;
		}
	}
	return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31;
		if((i==4) 
		|| (i==6) 
		|| (i==9) 
		|| (i==11))
		{
			this[i] = 30;
		}
		if (i==2)
		{
			this[i] = 29;
		}
	} 
	return this;
}


function isDate(dtStr)
{
	//RTC 20081020: check for non-string args (these cannot be dates!)
	if(typeof(dtStr) != 'string')
	{
		return false;
	}
	
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	
	var strYear=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strDay=dtStr.substring(pos2+1);
	
	strYr=strYear;
	
	if((strDay.charAt(0) == "0")
	&& (strDay.length > 1));
	{
		strDay=strDay.substring(1);
	}
		
	if((strMonth.charAt(0) == "0")
	&& (strMonth.length > 1))
	{
		strMonth=strMonth.substring(1);
	}

	for (var i = 1; i <= 3; i++)
	{
		if((strYr.charAt(0) == "0")
		&& (strYr.length > 1))
		{
			strYr=strYr.substring(1);
		}
	}
	
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if((pos1 == -1) 
	|| (pos2 == -1))
	{
		return false;
	}
	
	if((strMonth.length < 1)
	|| (month < 1)
	|| (month > 12))
	{
		return false;
	}
	
	if((strDay.length < 1)
	|| (day < 1)
	|| (day > 31)
	|| ( (month == 2) && (day > daysInFebruary(year)) ) 
	|| (day > daysInMonth[month]))
	{
		return false;
	}
	
	if((strYear.length != 4)
	|| (year == 0) 
	|| (year < minYear)
	|| (year>maxYear))
	{
		return false;
	}
	
	return true;
}

/*********** Date validation *************/


/****************************************End ECM Functions *********************************************/



/****************************************Start Distribution Functions *********************************************/

function distdelconfirm()
{
	var url = 'NXDCRULE.pgm?task=del&instance=' + jQ('#instance').val() + '&currrn=' + jQ('#currrn').val() + "&rnd=" + Math.random();
	
	
	var return_value = confirm('You are about to permanently delete this rule. Do you wish to continue?');
	
	if (return_value)
	{
		document.location = url;
	}
}


function distauthaccumflg()
{
	if ( jQ('#authaccum').attr('checked') == true)
	{
		
		jQ('#folder1').hide();
		jQ('#folder3').hide();
		jQ('#purge').hide();
		jQ('#wnode2').val('0');
		
	}
	else
	{
		jQ('#folder1').show();
		jQ('#folder3').show();
		jQ('#purge').show();
	
		adjustParent();
	}
}


function distpagefunc1()
{
	pageval = "1";
	distoptdisp();

	jQ('#pg1').addClass('tabsel');
	jQ('#pg2').replaceClass('tab');
	
	document.inpform.srchkeys.focus();
	
	adjustParent();
}

function distpagefunc2()
{
	pageval = "2";
	distoptdisp();

	jQ('#pg1').replaceClass('tab');
	jQ('#pg2').addClass('tabsel');
	
	adjustParent();
}


function distoptdisp() 
{ 
	jQ('#pagedsp1').hide();
	jQ('#pagedsp2').hide();
	
	if (pageval == "1") 
	{	
		jQ('#pagedsp1').show();
	} 
	
	if (pageval == "2") 
	{
		jQ('#pagedsp2').show();
		jQ('#keypair').hide();
		jQ('#key2pair').hide();
	}
	
	distauthaccumflg();	
}



function submitDistForm()
{
	//if((xl_GetObj('purgedate').value != "*NEVER") && (isDate(xl_GetObj('purgedate').value) == false) && (IsNumeric(xl_GetObj('purgedate').value) == false))
	
	var dateval = jQ('#purgedate').val();
	if(( isDate(dateval) == false ) 
	&& ( dateval != '*NEVER' ) 
	&& ( isNumeric(dateval) == false ))
	{
		alert('The Purge Date entered is invalid. Make sure it is in yyyy-mm-dd format (Eg: 2001-12-25), number of days (Eg: 30) or *NEVER.');
		jQ('#purge').replaceClass('error');
		errorflg = 'Y';
	}
	else
	{
		document.forms.inpform.submit();
	}
}

function IsNumeric(sValue)
{

	if(sValue == null) 
	{
		return false;
	}

	var ValidChars = '0123456789';
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sValue.length && IsNumber == true; i++) 
	{ 
		Char = sValue.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	
	return IsNumber;
	
}


/****************************************End Distribution Functions *********************************************/

function include() 
{
	if (document.forms[0].incltype.checked) 
	{
	
		document.forms[0].type.value = "U";

		jQ('#url').show();
		jQ('#ajax').show();
		jQ('#html').hide();
		jQ('#width').show();
		jQ('#height').show();
		
	} 
	else 
	{
		document.forms[0].type.value = "";

		jQ('#html').show();
		jQ('#url').hide();
		jQ('#ajax').hide();
		jQ('#width').hide();
		jQ('#height').hide();
	}
	
	jQ('#selinc').bind('click',opendoctree8);
	
	adjustoptions();
}


function loadBreadCrumbs()
{
	
	var myurl = "nxmenu.pgm?task=breadcrmbs&docnum=" + jQ('#lnknum').val();	
	jQ.get(myurl, function(resp)
	{
		jQ('#breadCrumbs').html(resp);
	});
}

function textonly(string)
{
	if(string == undefined)
	{
		return "undefined";
	}

	var rtnerrors = '';
	var string = string.toUpperCase();
	
	for (i=0; i < string.length; i++)
	{
		var chkvalue = string.substring(i,i + 1);
		if (checkCharacters(chkvalue) == 'N')
		{
			rtnerrors = rtnerrors + ' ' + chkvalue;
		}
	}
	
	return rtnerrors;
}

function checkCharacters(chkvalue)
{
	
	var validCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!-,@*$+_?.:() ";
	
	/* RTC 20080909: rewrote to be faster and simpler
	var found = 'N';
	for (y=0; y < validCharacters.length; y++)
	{
		if (chkvalue == validCharacters.substring(y,y + 1))
		{
			found = 'Y';
			return found;
		}
	}
	*/
	
	if( validCharacters.indexOf(chkvalue) >= 0)	
	{
		return 'Y';
	}
	else
	{
		return 'N';
	}
}

function val_InpChar(chkobj, fieldtitle, errorid, allowblnk)
{
	var errorflg = 'N';
	var errortext = '';
	var errorobj = jQ('#'+errorid)[0];
	
	var chkobjval = jQ('#'+chkobj).val();
	
	if(( chkobjval == '') 
	&& (allowblnk != 'Y'))
	{
		errorobj.className = 'error';
		errortext = 'The ' + fieldtitle + ' cannot be blank. Please enter a valid ' + fieldtitle + '.\r\n';	
	}
	
	var errors = textonly(chkobjval);
	if (errors != '')
	{
		errorobj.className = 'error';
		errortext = 'Error: The ' + fieldtitle + ' contains invalid characters (' + errors + ').';
	}
	
	
	if (errortext != '')
	{
		alert(errortext);
		errorflg = 'Y';
	}
	
	return errorflg;
}

function nxheader(hdrtitle, firstname, lastname, userno) 
{	
	var addmin = "";	
	if (userno == '0000001') 
	{ 
		addmin = "<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = '/nexusadmin/nexadm.pgm?task=default';\" src=\"/nexuspublic/images/admin.gif\" align=\"middle\" alt=\"My Pages\" border=\"0\" height=\"13\" width=\"14\"><a href='/nexusadmin/nexadm.pgm?task=default' target='_top'>Admin Pages</a>";
	}
	
	if (userno == '0') 
	{ 
		rtnhtml ="<div id=\"header\"><div class=\"sign\"></div><div class=\"imgholder\"><div id=\"nx80\"></div><div id=\"nx81\"></div><div id=\"nx83\"></div></div><div class=\"mytitle\">" + hdrtitle + "</div></div>";	
	}
	else
	{	
		rtnhtml = "<div id=\"header\"><div class=\"imgholder\"><div id=\"nx80\"></div><div id=\"nx81\"></div><div id=\"nx83\"></div></div><div class=\"mytitle\">" + hdrtitle +"</div><div class=\"sign\"><div class=\"left\">Welcome "+firstname+" "+lastname+"</div><div class=\"right\">" + addmin + "&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'NXMENU.pgm?task=admmnt';\" src=\"/nexuspublic/images/manage.gif\" align=\"middle\" alt=\"Manage Site\" border=\"0\" height=\"13\" width=\"14\"><a href='NXMENU.pgm?task=admmnt' target='_top'>Manage Site</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'NXMENU.pgm?task=usrmnt';\" src=\"/nexuspublic/images/settings.gif\" align=\"middle\" alt=\"User Settings\" border=\"0\" height=\"13\" width=\"14\"><a href='NXMENU.pgm?task=usrmnt' target='_top'>Settings</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'nxmenu.pgm?adminpage=Y';\" src=\"/nexuspublic/images/mypages.gif\" align=\"middle\" alt=\"My Pages\" border=\"0\" height=\"13\" width=\"14\"><a href='nxmenu.pgm?adminpage=Y' target='_top'>My Pages</a>&nbsp;<a href='http://www.excelsystems.com/nexususerguide.htm' target='_blank'><img align=\"middle\" class=\"cursorhand\" src=\"/nexuspublic/images/questionMark.gif\" align=\"middle\" alt=\"Help\" border=\"0\" height=\"13\" width=\"14\"></a><a href='http://www.excelsystems.com/nexususerguide.htm' target='_blank'>Help</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'nxlogin.pgm?task=out';\" src=\"/nexuspublic/images/log-out.gif\" align=\"middle\" alt=\"Log out\" border=\"0\" height=\"13\" width=\"14\"><a href='nxlogin.pgm?task=out' target='_top'>Log out</a></div></div></div>"; 
	}
	
	rtnhtml = rtnhtml + "<\/script><script>AJAX_Poller(\"30000\")</script><br><br>"; 	
	document.writeln(rtnhtml);
}


function nxheader2(hdrtitle, firstname, lastname, userno, manage) 
{	
	var addmin = "";
	if (userno == '0000001') 
	{ 
		addmin = "<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = '/nexusadmin/nexadm.pgm?task=default';\" src=\"/nexuspublic/images/admin.gif\" align=\"middle\" alt=\"My Pages\" border=\"0\" height=\"13\" width=\"14\"><a href='/nexusadmin/nexadm.pgm?task=default' target='_top'>Admin Pages</a>";
	}
	
	if (userno == '0') 
	{ 
		rtnhtml="<div id=\"header\"><div class=\"sign\"></div><div class=\"imgholder\"><div id=\"nx80\"></div><div id=\"nx81\"></div><div id=\"nx83\"></div></div><div class=\"mytitle\">" + hdrtitle + "</div></div>";	
	}
	else if ((manage == null) || (manage != 'Y'))
	{	
		rtnhtml = "<div id=\"header\"><div class=\"imgholder\"><div id=\"nx80\"></div><div id=\"nx81\"></div><div id=\"nx83\"></div></div><div class=\"mytitle\">" + hdrtitle +"</div><div class=\"sign\"><div class=\"left\">Welcome "+firstname+" "+lastname+"</div><div class=\"right\">&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'NXMENU.pgm?task=usrmnt';\" src=\"/nexuspublic/images/settings.gif\" align=\"middle\" alt=\"User Settings\" border=\"0\" height=\"13\" width=\"14\"><a href='NXMENU.pgm?task=usrmnt' target='_top'>Settings</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'nxmenu.pgm?adminpage=Y';\" src=\"/nexuspublic/images/mypages.gif\" align=\"middle\" alt=\"My Pages\" border=\"0\" height=\"13\" width=\"14\"> <a href='nxmenu.pgm?adminpage=Y' target='_top'>My Pages</a>&nbsp;<a href='http://www.excelsystems.com/nexususerguide.htm' target='_blank'><img align=\"middle\" class=\"cursorhand\" src=\"/nexuspublic/images/questionMark.gif\" align=\"middle\" alt=\"Help\" border=\"0\" height=\"13\" width=\"14\"></a><a href='/nexuspublic/manual/nexus2guidepdf.pdf' target='_blank'>Help</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'nxlogin.pgm?task=out';\" src=\"/nexuspublic/images/log-out.gif\" align=\"middle\" alt=\"Log out\" border=\"0\" height=\"13\" width=\"14\"><a href='nxlogin.pgm?task=out' target='_top'>Log out</a></div></div></div>"; 
	}
	else if ((manage != null) && (manage == 'Y'))
	{	
		rtnhtml = "<div id=\"header\"><div class=\"imgholder\"><div id=\"nx80\"></div><div id=\"nx81\"></div><div id=\"nx83\"></div>	</div>	<div class=\"mytitle\">" + hdrtitle +"</div><div class=\"sign\"><div class=\"left\">Welcome "+firstname+" "+lastname+"</div><div class=\"right\">" + addmin + "&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'NXMENU.pgm?task=admmnt';\" src=\"/nexuspublic/images/manage.gif\" align=\"middle\" alt=\"Manage Site\" border=\"0\" height=\"13\" width=\"14\"><a href='NXMENU.pgm?task=admmnt' target='_top'>Manage Site</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'NXMENU.pgm?task=usrmnt';\" src=\"/nexuspublic/images/settings.gif\" align=\"middle\" alt=\"User Settings\" border=\"0\" height=\"13\" width=\"14\"><a href='NXMENU.pgm?task=usrmnt' target='_top'>Settings</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'nxmenu.pgm?adminpage=Y';\" src=\"/nexuspublic/images/mypages.gif\" align=\"middle\" alt=\"My Pages\" border=\"0\" height=\"13\" width=\"14\"> <a href='nxmenu.pgm?adminpage=Y' target='_top'>My Pages</a>&nbsp;<a href='http://www.excelsystems.com/nexususerguide.htm' target='_blank'><img align=\"middle\" class=\"cursorhand\" src=\"/nexuspublic/images/questionMark.gif\" align=\"middle\" alt=\"Help\" border=\"0\" height=\"13\" width=\"14\"></a>&nbsp;<a href='http://www.excelsystems.com/nexususerguide.htm' target='_blank'>Help</a>&nbsp;<img align=\"middle\" class=\"cursorhand\" onclick=\"top.location.href = 'nxlogin.pgm?task=out';\" src=\"/nexuspublic/images/log-out.gif\" align=\"middle\" alt=\"Log out\" border=\"0\" height=\"13\" width=\"14\"><a href='nxlogin.pgm?task=out' target='_top'>Log out</a></div></div></div>"; 
	}
	
	rtnhtml = rtnhtml + "<\/script><script>AJAX_Poller(\"30000\")</script><br>"; 
	
	document.writeln(rtnhtml);
}

// Open user or group popup window
function openusrgrppopup(type,group,single, e) 
{ 
	var ifr = jQ('#usrgrpframe')[0];
	
	jQ(ifr).css('height', '100px');
	
	// use correct event model
	if (!e.y)
	{
		e = window.event;  // IE Event Model
	}
	var y = e.y;
	var x = e.x;
	
	if( (450 + x) > document.body.scrollWidth )	
	{
		x = (document.body.scrollWidth - 450) - 10;
	}
	
	if( (300 + y) > document.body.scrollHeight )	
	{
		y = (document.body.scrollHeight - 300) - 10;
		
		if (y < 0)
		{
			y = 5;
		}
	}
	
	ifr.style.left = x + 'px';
	ifr.style.top = y + 'px';
	
	var url = 'NXPOPUPS.pgm?type=' + type + "&group=" + group + "&single=" + single + "&rnd=" + Math.random();
	ifr.src = url;
	ifr.style.zIndex=50;
	
	jQ('#usrgrppopup').show();
}

function checkparentpos(ifr)
{
	try 
	{
		bodyWidth = parent.document.body.offsetWidth;
		bodyHeight = parent.document.body.offsetHeight;
		
		parifr = jQ(parent.document).find('#auxframe')[0];
		
		var x = parseInt(parifr.style.left) + parseInt(ifr.style.width);
		
		if (x > bodyWidth)
		{
			parifr.style.left = parseInt(parifr.style.left) - (x-bodyWidth) - 50 + 'px';
		}
		
		var y = parseInt(parifr.style.top) + parseInt(ifr.style.height);
		
		if (y > bodyHeight)
		{
			parifr.style.top = parseInt(parifr.style.top) - (y-bodyHeight) - 120 + 'px';
		}
		
		if (parseInt(parifr.style.height) < (parseInt(ifr.style.top) + parseInt(ifr.height) + 30))
		{
			parifr.style.height = (parseInt(ifr.style.top) + parseInt(ifr.height)) + 30 + 'px';
		}
		
		if (parseInt(parifr.style.width) < (parseInt(ifr.style.left) + parseInt(ifr.width) + 20))
		{
			parifr.style.width = (parseInt(ifr.style.left) + parseInt(ifr.width)) + 20 + 'px';
		}
	} 
	catch(err) {}
}


// Group mng return selected user from window
function returnuser(user,single,usrnbr,parentrqst)
{
	// Update the last used file 
	var url = 'nxpopups.pgm?task=addlast&usernbr=' + usrnbr + '&group=0' + "&rnd=" + Math.random();
	
	jQ('#lastframe')[0].src = url;
	
	if (parent.document.inpform.nxUserName)
	{
		if (single == "N")
		{
			var len = parent.document.inpform.nxUserName.length;
			var returnvalue = parent.document.inpform.nxUserName.value.substring(len, len - 1);
			if ((returnvalue == ';') || (len == 0) || (len == null))
			{
				parent.document.inpform.nxUserName.value = parent.document.inpform.nxUserName.value + user + ';';
			}
			else
			{
				parent.document.inpform.nxUserName.value = parent.document.inpform.nxUserName.value + ';' + user + ';';
			}
		}
		else
		{
			parent.document.inpform.nxUserName.value = user;
			jQ(parent.usrgrppopup).hide();
		}
		
		
		if (parentrqst == "")
		{
			parent.document.inpform.nxUserName.focus();
			parent.document.inpform.nxUserName.value = parent.document.inpform.nxUserName.value + "";
		}
		
		
	}
	
	if (parent.document.inpform.srchkeys)
	{
		if (single == "N")
		{
			var len = parent.document.inpform.srchkeys.length;
			var returnvalue = parent.document.inpform.srchkeys.value.substring(len, len - 1);
			if((returnvalue == ';') 
			|| (len == 0) 
			|| (len == null))
			{
				parent.document.inpform.srchkeys.value = parent.document.inpform.srchkeys.value + user + ';';
			}
			else
			{
				parent.document.inpform.srchkeys.value = parent.document.inpform.srchkeys.value + ';' + user + ';';
			}			
		}
		else
		{
			
			parent.document.inpform.srchkeys.value = user;
			jQ(parent.usrgrppopup).hide();
		}
		
		parent.document.inpform.srchkeys.focus();
		parent.document.inpform.srchkeys.value = parent.document.inpform.srchkeys.value + "";
	}
	
	if (parentrqst != "")
	{
		parent.authframe.document.inpform.nxUserName.value = user;
		jQ(parent.usrgrppopup).hide();
		
	}
}

// Group mng return selected group from window
function returngroup(group,groupnbr,type,single,parentrqst)
{
	// Update the last used file 
	var url = 'nxpopups.pgm?task=addlast&group=' + groupnbr + '&usernbr=0' + "&rnd=" +  Math.random();
	
	jQ('#lastframe').attr('src', url);
	
	if (single == "N")
	{
		var len = parent.document.inpform.nxGroupName.length;
		var returnvalue = parent.document.inpform.nxGroupName.value.substring(len, len - 1);
		if ((returnvalue == ';') || (len == 0) || (len == null))
		{
			parent.document.inpform.nxGroupName.value = parent.document.inpform.nxGroupName.value + group + ';';
			parent.document.inpform.nxGroupNbr.value = parent.document.inpform.nxGroupNbr.value + groupnbr + ';';
		}
		else
		{
			parent.document.inpform.nxGroupName.value = parent.document.inpform.nxGroupName.value + ';' + group + ';';
			parent.document.inpform.nxGroupNbr.value = parent.document.inpform.nxGroupNbr.value + ';' + groupnbr + ';';
		}				
	}
	else
	{
		if (parentrqst != "")
		{
			parent.authframe.document.inpform.nxGroupName.value = group;
			parent.authframe.document.inpform.nxGroupNbr.value = groupnbr;
		}
		else
		{
			parent.document.inpform.nxGroupName.value = group;
			parent.document.inpform.nxGroupNbr.value = groupnbr;
		}	
		
		jQ('#usrgrppopup',parent.document).hide();
	}
}

// Close the user and group popup window
function closewin()
{
	jQ('#usrgrppopup',parent.document).hide();
}

// Close the document selection popup
function closetreewin(type, framename)
{
	if (framename != '')
	{
		// RTC 20080909: removed frames so this wont work
		//top.frames['block_page'].xl_GetObj('auxframe').style.display='none';
		jQ('#auxframe').hide();
		
		jQ(parent.document).find('#doctree').hide();
		
	}
	else
	{
		
		jQ(parent.document).find('#doctree').hide();
		jQ(parent.document).find('#doctree')[0].src = '';
		
		if (type != 'S')
		{
			parent.adjustoptions();
		}
	}
}



function returnto(task, group)
{
	if( jQ('#group').value != "0000000" )
	{
		document.location = document.inpform.rdr.value + '?task=' + task + '&group=' + group;
	}
	else
	{
		document.location = document.inpform.rdr.value;
	}
}

function smisrldisplay(smisrl) 
{
	/* RTC 20090629: PML controls the presence of these fields now
	if (smisrl == "Y")
	{
		jQ('#display1').show();
	}
	else
	{
		jQ('#display1').hide();
	}
	*/
	
	if (document.inpform.group.value == "0000000")
	{	
		jQ('#admheader').show();
		jQ('#admtable').replaceClass('adminPageBorder');
	}
	else
	{
		jQ('#pagebody').replaceClass('nomarg');
		jQ('#buttons').replaceClass('form');
	}	
	
	/* RTC 20090629: PML controls presence of this field now
	if (document.inpform.siteadmin.value == "Y")
	{
		jQ('#sitemng').show();
	}
	*/
}

//control disabled/enabled inputs for the nxusrmnt program based on user type
function usisrldisplay() 
{

	//disable all conditionally displayed fields
	jQ('.condfld').disable();
	
	var usertype = jQ('#usisrl').val();
	if(jQ('#usisrl').attr('checked') == false)
	{
		usertype = '';
	}

	//enable only the input elements required by the current user type
	switch( usertype )
	{			
		case 'Y': //iSeries
		{
			jQ('.iseriesfld').enable();
			break;
		}
		case 'L': //LDAP
		{
			jQ('.ldapfld').enable();
			break;
		}
		case '': //Nexus
		{
			jQ('.nexusfld').enable();
			break;
		}
	}

	// Set focus to the user id
	if ( jQ('#group').val() == 0)
	{
		jQ('#ususer').focus();
	}
	else
	{
		jQ('#cancelbtn').hide();
	}
}


// This function check for creation authority for user and group
function chkoptauth(user, group, ceiling, useradd, groupadd, sitemng)
{
	if((document.inpform.group.value == '0000001') 
	|| (document.inpform.group.value == 1))
	{
		jQ('#prntgrp').hide();
	}
	else
	{
		jQ('#prntgrp').show();
	}
	
	if((sitemng != 'Y') 
	|| ((document.inpform.group.value == '0000001') 
	 || (document.inpform.group.value == 1)))
	{
		
		if((useradd != 'Y') 
		|| ((document.inpform.group.value == '0000001') 
		 || (document.inpform.group.value == 1)))
		{
			if((sitemng != 'Y')
			&& (useradd != 'Y'))
			{
				jQ('#pg3').hide();
			}
		}
			
	}
	
	if((document.inpform.group.value == '0000001') 
	|| (document.inpform.group.value == 1))
	{
		jQ('#prntgrp').hide();
	}
	
	if (user == 'Y')
	{
		document.inpform.GMCRTUSR.checked = "checked";
	}

	
	if((group == 'Y') 
	|| (sitemng == 'Y'))
	{
		jQ('#crtgroup').show();
		jQ('#crtgroup1').show();
		if (group == 'Y') 
		{
			document.inpform.GMCRTGRP.checked = "checked";
		}
	}
	else
	{
		jQ('#crtgroup').hide();
		jQ('#crtgroup1').hide();
	}
	
	if (ceiling == 'Y')
	{
		document.inpform.GMCEIL.checked = "checked";
	}
}

function adjustIFrameSize (iframeWindow, HeightAdj) 
{	
	if (!HeightAdj)
	{
		HeightAdj = 5;
	}
		
	var iframeElement;
	try
	{
		iframeElement = jQ('#' + iframeWindow.name)[0];
	}
	catch(err) {}

	if (iframeElement)
	{
		if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') 
		{
			iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + HeightAdj + 'px';
		}
		else 
		{
			if(iframeWindow.document.body.scrollHeight == 0)
			{
				iframearray[iframectr] = iframeWindow;		
				iframectr = iframectr + 1;
			}
			else
			{
				jQ(iframeElement).css('height', (iframeWindow.document.body.scrollHeight + HeightAdj) + 'px');
			}
		}
	}
}

function adjustIFrame(iframeWindow) 
{	
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
	var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers
	var FFextraHeight=parseFloat(getFFVersion)<=3? 0 : FFextraHeight; //FF3 doesnt appear to need the height adjust
	
	if (iframeWindow.document.height) 
	{
		iframeElement = jQ('#'+iframeWindow.name)[0];
		var newheight = iframeWindow.document.height + FFextraHeight;
		iframeElement.style.height = newheight + 'px';
		iframeElement.style.width = iframeWindow.document.width + 'px';
	}
	else
	{
		if (document.all) 
	  	{
			var iframeElement = document.all[iframeWindow.name];
		}
		
		
		if (iframeElement)
		{
			if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') 
			{
				iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 'px';
				iframeWindow.document.documentElement.scrollWidth + 'px';
			}
			else 
			{
				if(iframeWindow.document.body.scrollHeight == 0)
				{
					iframearray[iframectr] = iframeWindow;		
					//setTimeout('resizeiframe();', 200);
					iframectr = iframectr + 1;
				}
				else
				{
					iframeElement.style.height = iframeWindow.document.body.scrollHeight + 'px';
					iframeElement.style.width = iframeWindow.document.body.scrollWidth + 'px';
				}
			}
		}
	}
}



//resize the iframes that have a 0 scroll height.
function resizeif()
{
	var t;
	for (t = 0; t < iframectr; t++)
	{
		document.all[iframearray[t].name].style.height = iframearray[t].document.body.scrollHeight + 5 + 'px';
	}
}


// Check for header display 
function checkhdr(usertype)
{
	if((usertype == "U") 
	|| (usertype == "T"))
	{
		admheader.style.display = "";
	}
}

function closeECMEdit()
{
	if (document.inpform.framename.value == '')
	{
		var instance = document.inpform.instance.value;	
		document.location='NXMNGDOC.pgm?task=startpage&instance=' + instance + '&wnode=0';
	}
	else
	{
		var frame = document.inpform.framename.value;

		nx_gettopframe(frame).contentWindow.clearActive();
		nx_gettopframe('quickadd2').style.display = 'none';
	}
}

// Request the document search window
function searchdoc()
{
	// RTC 20080820: removing frames
	//var ifr = document.all ? top.frames['block_page'].document.all['ifrsearch'] : top.frames['block_page'].document.getElementById('ifrsearch');
	//top.frames['block_page'].xl_GetObj('searchwow').style.display = "";
	var ifr = jQ('#ifrsearch');

	//check that the iframe was actually found
	if( jQ(ifr).length < 1 )
	{
		return;
	}
		
	jQ('#searchwow').show();
	// ... end RTC 20080820
	
	var url = encodeURIComponent(document.searchform.SearchECM.value);
	url = "NXDOCSRCH3.pgm?search=" + url + "&rand=" +  randnum;
	ifr.attr('src',url);
	/* RTC 20100113 MedAxiom code to show results in iframe viewer
	url = "MADOCSRCH.pgm?search=" + url + "&rand=" +  randnum;
	jQ('#ifrmviewdoc').attr(‘src’, url); 
	*/
	
	ifr.css('zIndex',50);
	ifr.css('left',100);
	ifr.css('top',50);
}


function show_Favorites(e)
{
	var favdiv = jQ('#favoritesdiv');
	var ifr = jQ('#favframe');
	
	//if favorites is visible, hide it
	if( jQ(favdiv).css('display') != 'none')
	{
		jQ(favdiv).hide();
		return;
	}
	
	//otherwise, construct the favorites window
	favdiv.show();
	
	ifr.css('height',400);
	ifr.css('width',300);
	ifr.css('zIndex',101);
	ifr.css('top', e.pageY + 10 + 'px');
	ifr.css('left', e.pageX + 'px');
	
	ifr.attr('src',"NXMNGDOC.PGM?task=viewfavorites&type=V&favorites=Y&rand=" +  Math.random() );
}


function showhelp(helpfile)
{ 
	myfile=  "/nexuspublic/help/" + helpfile; 
	window.open (myfile,"NexusHelp","dependent,scrollbars=1,resizable=1,width=650,height=500,top=0,left=0")	
} 

function showhelp2(helpfile)
{ 
	window.open (helpfile,"NexusHelp","dependent,scrollbars=1,resizable=1,width=650,height=500,top=0,left=0")	
} 


// TODO: combine all these opendoctree calls since they share the majority of their code, pass a parm to branch if needed
function opendoctree(e) 
{ 
	var ifr = jQ('#treeframe');
	
	ifr.css('left', (e.pageX - 300) + 'px');
	ifr.css('top',  (e.pageY + 10) + 'px');
	ifr.css('zIndex',50);
	ifr.height(300);
	
	var url = 'nxpostree.pgm?type=S&wnode=' + jQ('#fromnode').val() + "&instance=" + jQ('#instance').val() + '&rnd=' + Math.random();
	ifr.attr('src',url);

	jQ('#doctree').show();
	ifr.show();
	
	adjustParent();
}

function opendoctree2(e) 
{ 
	var ifr = jQ('#treeframe');
	
	ifr.css('left', (e.pageX - 300) + 'px');
	ifr.css('top',  (e.pageY + 10) + 'px');
	ifr.css('zIndex',50);
	ifr.height(300);
	
	var url = 'nxpostree.pgm?type=A&wnode=' + jQ('#wnode2').val() + "&rnd=" + Math.random();	
	ifr.attr('src', url);
	
	jQ('#doctree').show();
	ifr.show();
	
	adjustParent();
}

//RTC 20081204: refactored to use jQuery
function opendoctree3(e) 
{ 	
	var ifr = jQ('#treeframe');

	ifr.css('left', (e.pageX - 300) + 'px');
	ifr.css('top', (e.pageY + 10) + 'px');
	ifr.css('zIndex',50);
	ifr.height(300);
	
	//load doc tree lookup url
	var url = 'nxpostree.pgm?type=A&wnode=' + jQ('#wnode2').val() + "&rnd=" + Math.random();
	ifr.attr('src',url);
	
	//display the results
	jQ('#doctree').show();
	//RTC 20081204: make sure the iframe is visible as well
	ifr.show();
}

function opendoctree4(e) 
{ 
	var ifr = jQ('#treeframe');
	var optifr = jQ(parent.document).find('#optframe')[0];
	var auxifr = nx_gettopframe('auxframe');
	
	ifr.css('left', e.pageX - 300);
	ifr.css('top', e.pageY + 10);
	ifr.css('zIndex',50);
	ifr.height(600);
	
	ifr[0].src = 'nxpostree.pgm?type=F&wnode=' + jQ('#wnode2').val() + '&rnd=' + Math.random();	
	
	jQ('#treeframe').show();
	jQ('#doctree').show();

	adjustParent();
	parent.adjustParent();
}

function opendoctree5(e) 
{ 
	var ifr = jQ('#treeframe');

	ifr.css('left', e.pageX - 300);
	ifr.css('top', e.pageY + 10);
	ifr.css('zIndex',50);
	ifr.height(300);
	
	var url = 'nxpostree.pgm?type=A&wnode=' + jQ('#wnode2').val() + "&rnd=" + Math.random();
	ifr.attr('src',url); 
	
	//show tree invisibly
	jQ('#doctree').css('visibility','hidden');
	jQ('#doctree').show();
	jQ('#doctree').css('visibility', 'visible');
	ifr.show();
	
	
	adjustoptions();
}

/* RTC 20081121: commenting these out as they appear unused
function opendoctree6(e) 
{ 
	var ifr = jQ('#treeframe');
	
	ifr.css('left', e.pageX - 300);
	ifr.css('top', e.pageY + 10);
	ifr.css('zIndex',50);
	ifr.height(300);
	
	var callerWindowObj = dialogArguments;
	var url = callerWindowObj.document.inpform.sitepath.value + 'nxpostree.pgm?type=U&urltype=I';	
	
	ifr[0].src = url + '&rnd=' + Math.random();
	
	jQ('#doctree').show();
}
*/
function opendoctree7(e) 
{ 
	var ifr = jQ('#treeframe');
	
	ifr.css('left', e.pageX - 300);
	ifr.css('top', e.pageY + 10);
	ifr.css('zIndex',50);
	ifr.height(300);
	
	var callerWindowObj = dialogArguments;
	var url = callerWindowObj.document.inpform.sitepath.value + 'nxpostree.pgm?type=U&urltype=H';	
	ifr[0].src = url + "&rnd=" +  Math.random();
	
	jQ('#doctree').show();
}

// used by include portlets to select include url from ECM docs
function opendoctree8(e) 
{ 
	var ifr = jQ('#treeframe');
	
	ifr.css('left', e.pageX - 300);
	ifr.css('top', e.pageY + 10);
	ifr.css('zIndex',99);
	ifr.height(300);
	
	var url = 'nxpostree.pgm?type=U&urltype=U' + "&rnd=" + Math.random();	
	ifr.attr('src', url);

	ifr.show();
	jQ('#doctree').show();
	
	jQ('#optframe',parent.document).height(500);
	jQ('#auxframe',parent.parent.document).height(500);
}

//TODO: combine opendoctree9 - 11
function opendoctree9(e) 
{ 
	var ifr = jQ('#auxframe');
	ifr.show();
	
	var url = "nxpostree.pgm?type=Z&framename=ECMQuickLoc&favorites=" + jQ('#favorites').val();
	
	//RTC 20081208: pass zIndex parameter to popup and increase value
	//popup('auxframe',url,300,300,'float', e,10,'auxinfo');
	// ifr.css('zIndex',99);
	popup('auxframe',url,300,300,'float', e,10,'auxinfo',115);
}


function opendoctree10(e) 
{ 
	var ifr = jQ('#auxframe');
	ifr.show();
	
	var url = 'nxpostree.pgm?type=A&framename=ECMQuickAdd&wnode=' + jQ('#wnode2').val();

	//RTC 20081208: pass zIndex parameter to popup and increase value
	//popup('auxframe',url,300,300,'float', e,10,'auxinfo');
	// ifr.css('zIndex',99);
	popup('auxframe',url,300,300,'float', e,10,'auxinfo',115);
	
}

function opendoctree11(e) 
{ 
	var ifr = jQ('#auxframe');
	
	var url = "nxpostree.pgm?type=Z&framename=ECMQuickLoc2&favorites=" + jQ('#favorites').val();
	// RTC 20081208: use new zIndex parameter to make sure the popup is above the upload file dialog
	//parent.popup('auxframe' ,url,300,300,'float', e,10,'auxinfo');
	popup('auxframe' ,url,300,300,'float', e,10,'auxinfo',110);
	
	ifr.show();
}

function getSelectedRadioValue(buttonGroup) 
{
	// returns the value of the selected radio button or "" if no button is selected
	var i = getSelectedRadio(buttonGroup);
	if (i == -1) 
	{
		return "";
	} 
	else 
	{
		if (buttonGroup[i]) 
		{ 
			// Make sure the button group is an array (not just one button)
			return buttonGroup[i].value;
			
		} 
		else 
		{ 
			// The button group is just the one button, and it is checked
			return buttonGroup.value;
		}
	}
	
} // Ends the "getSelectedRadioValue" function

function getSelectedRadio(buttonGroup) 
{
	// returns the array number of the selected radio button or -1 if no button is selected
	if (buttonGroup[0]) 
	{ 
		// if the button group is an array (one button is not an array)
		for (var i=0; i<buttonGroup.length; i++) 
		{
			if (buttonGroup[i].checked) 
			{
				return i;
			}
		}
	} 
	else 
	{
		// if the one button is checked, return zero
		if (buttonGroup.checked)
		{ 
			return 0; 
		} 
	}
	
	// if we get to this point, no radio button is selected
	return -1;
} // Ends the "getSelectedRadio" function

//clear page properties column widths
function clearcol() 
{
	jQ('#inpform input.colwidth').val(0);
}

function selecttype()
{
	if (inpform.pagetype.selectedIndex == 1) 
	{
		jQ(wow).show();
		
		jQ('#column1').hide();
		jQ('#column2').hide();
		jQ('#column3').hide();
		jQ('#column4').hide();
		jq('#nbrcol').hide();
		
		jQ('#nextbtn').val('Finish');
	}
	else
	{
		jQ('#wow').hide();
		jQ('#nbrcol').show();
		
		jQ('#wnode2').val(0);
		jQ('#nextbtn').val('Next>>');
		column();
	}
}

// Add/Update user options
function uo_options_display(cu_designp, cu_edtact, cu_instance, cu_links, cu_mylinks, cu_mainp, cu_mpage, cu_passwrd, cu_skins, cu_topfrm, siteadmin, cu_procdir, cu_favorites, cu_favupload) 
{
	/* RTC 20081205: refactor to simplify
	if ((cu_designp == 'Y') || (siteadmin == 'Y'))
		jQ('#uodesignp').show();
	
	if ((cu_edtact == 'Y') || (siteadmin == 'Y'))
		jQ('#uoedtact').show();
	
	if ((cu_passwrd == 'Y') || (siteadmin == 'Y'))
		jQ('#uopasswrd').show();
	
	if ((cu_instance == 'Y') || (siteadmin == 'Y'))
		jQ('#uoinstance').show();
	
	if ((cu_favorites == 'Y') || (siteadmin == 'Y'))
		jQ('#uofavorites').show();
	
	if ((cu_favupload == 'Y') || (siteadmin == 'Y'))
		jQ('#uofavupload').show();
		
	if ((cu_links == 'Y') || (siteadmin == 'Y'))
		jQ('#uolinks').show();

	
	if ((cu_mylinks == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#uomylinks').show();
		jQ('#prefmylinks').show();
	}
	if ((cu_mainp == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#uomainp').show();
		jQ('#prefmpagestyle').show();
	}
	*/
	if(siteadmin == 'Y')
	{
		jQ('#uodesignp').show();
		jQ('#uoedtact').show();
		jQ('#uopasswrd').show();
		jQ('#uoinstance').show();
		jQ('#uofavorites').show();
		jQ('#uofavupload').show();
		jQ('#uolinks').show();
		jQ('#uomylinks').show();
		jQ('#prefmylinks').show();
		jQ('#uomainp').show();
		jQ('#prefmpagestyle').show();
	}
	else
	{
		if(cu_designp == 'Y'){  jQ('#uodesignp').show(); }
		if(cu_edtact == 'Y'){   jQ('#uoedtact').show();  }
		if(cu_passwrd == 'Y'){  jQ('#uopasswrd').show(); }
		if(cu_instance == 'Y'){	jQ('#uoinstance').show();}
		if(cu_favorites == 'Y'){jQ('#uofavorites').show();}
		if(cu_favupload == 'Y'){jQ('#uofavupload').show();}
		if(cu_links == 'Y'){	jQ('#uolinks').show();}
		if(cu_mylinks == 'Y')
		{	
			jQ('#uomylinks').show(); 
			jQ('#prefmylinks').show();
		}
		if(cu_mainp == 'Y')
		{
			jQ('#uomainp').show();
			jQ('#prefmpagestyle').show();
		}
	}
	// end RTC 20081205
	
	
	if((cu_mpage == 'Y') 
	|| (siteadmin == 'Y'))
	{
		jQ('#uompage').show();
		jQ('#prefmainpage').show();
		
		// Optional display the main page selection options
		if((jQ('#USOPPA').val() == ' ') 
		|| (jQ('#USOPPA').val() == 'Y'))
		{
			jQ('#prefmainpage2').show();
			jQ('#prefmainpage3').hide();
		}
		else
		{
			jQ('#prefmainpage2').hide();
			jQ('#prefmainpage3').show();
			
			if( jQ('#USMAPA').val() == '*DEFAULT')
			{
				jQ('#USMAPA').attr('disabled',true);
			}
		}
	}
	
	if((cu_skins == 'Y') 
	|| (siteadmin == 'Y'))
	{
		jQ('#uoskins').show();
		jQ('#prefskin').show();
	}
	if((cu_topfrm == 'Y') 
	|| (siteadmin == 'Y'))
	{
		jQ('#prefshowtopframe').show();
	}
}

// Options to hide the user modification form options
function modify_options(ou_designp, ou_edtact, ou_instance, ou_links, ou_mylinks, ou_mainp, ou_mpage, ou_passwrd, ou_skins, ou_topfrm, siteadmin) 
{
	
	if ((ou_links == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#uolinks').show(); 
	}
		
	if ((ou_mylinks == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#uomylinks').show();
	}
	
	if ((ou_mpage == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#uompage').show();
	}
	
	
	if ((ou_skins == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#uoskins').show();
	}
	
	if ((ou_topfrm == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#uotopfrm').show();
	}
	
	if ((ou_mainp == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#prefmainpage').show();
	
		
		// Optional display the main page selection options
		if(( jQ('#USOPPA').val() == ' ') 
		|| ( jQ('#USOPPA').val() == 'Y'))
		{
			jQ('#prefmainpage2').show();
			jQ('#prefmainpage3').hide();
		}
		else
		{
			jQ('#prefmainpage2').hide();
			jQ('#prefmainpage3').show();
			
			if ( jQ('#USMAPA').val() == '*DEFAULT')
			{
				jQ('#USMAPA').attr('disabled',true);
			}
		}
	}
	
}

// Optional display of my Portal Settings menu
function portal_settings(ou_edtact, ou_instance, ou_passwrd, siteadmin, groupmng)
{
	
	if ((ou_edtact == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#edtact').show();
	}
			
	if ((ou_passwrd == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#passwrd').show();
	}
		
	if ((groupmng == 'Y') || (siteadmin == 'Y'))
	{
		jQ('#group').show();
	}
}

// Set the edit options off
function set_editopt()
{

	// TODO: clear these all using jQuery and a common class
	if (!document.inpform.uo_edtact.checked)
	{
		document.inpform.uo_mpage.checked = "";
		document.inpform.uo_skins.checked = "";
		document.inpform.uo_mainp.checked = "";
		document.inpform.uo_topfrm.checked = "";
		document.inpform.uo_links.checked = "";
		document.inpform.uo_mylinks.checked = "";
	}
}


// Allow user to change there settings (NXUSRMNT)
function allow_change()
{

	// TODO: clear these all using jQuery and a common class
	if (!document.inpform.USALSE.checked)
	{
		document.inpform.uo_edtact.checked = "";
		document.inpform.uo_mpage.checked = "";
		document.inpform.uo_skins.checked = "";
		document.inpform.uo_mainp.checked = "";
		document.inpform.uo_topfrm.checked = "";
		document.inpform.uo_links.checked = "";
		document.inpform.uo_mylinks.checked = "";
		document.inpform.uo_passwrd.checked = "";
		document.inpform.uo_designp.checked = "";
		document.inpform.uo_instance.checked = "";
	}
}


function setupskinEditor()
{
	
	oEdit1.mode="HTMLBody";
	oEdit1.btnSpellCheck=true;
	//RTC 20090220: Update for InnovaEdit 3.5
	oEdit1.useTab=false;	
	oEdit1.height="200";
	oEdit1.width="600";
	oEdit1.useTab=false;
	
	// Allow for custom style sheet
	oEdit1.btnStyles=true;
	oEdit1.initialRefresh=true;
	
	oEdit1.REPLACE("title");
}

// TODO: think about removing polling altogether
function AJAX_Poller(polling_interval) 
{

	// Fire request for data and populate div: 
	jQ.get("nxupoll.pgm?task=pollme", Rcv_AJAX_Polling);
	
	var RunScript = 'AJAX_Poller(' + polling_interval + ')';
	window.setTimeout(RunScript, polling_interval)
} 	

// Called from inside the function xl_AjaxUpdate: 
function Rcv_AJAX_Polling(response)
{
	if (response.substring(0, 4) == "CALR") 
	{	
		var myurl ="nxupoll.pgm?task=reminders&rnd="+ Math.random(); 
		popupWin=window.open(myurl,'open_window','dependent, width=700,height=480, left=15, top=45 resizable=1') 
	}
	
	if (response.substring(4) == "MAIL") 
	{	
		var myurl ="nxmsg.pgm?TASK=pollmsg&rnd="+ Math.random(); 
		popupWin=window.open(myurl,'open_window','dependent, width=700,height=480, left=15, top=45 resizable=1') 
		}
	
	if (response.substring(4) == "CHAT") 
	{	
		var myurl ="nxupoll.pgm?task=chat&rnd="+ Math.random(); 
		popupWin=window.open(myurl,'open_window','dependent,width=465,height=268,left=15,top=45') 
	}
}

// RTC 20081203: controlls visibility of main page selection row in nxusrmnt based on
// the selected main page style value.
function dsp_mainpage(display_type)
{
	//RTC 20081203: reference inputs using their ids
	//if (document.inpform.uo_mainp.value == 'Y')
	if( jQ('#uo_mainp').val() == 'Y')
	{
		// Optionally display the main page selection options
		/* RTC 20081203: restructure if condition and logic block ordering
		if ((inpform.USOPPA.options[inpform.USOPPA.selectedIndex].value == ' ') || (inpform.USOPPA.options[inpform.USOPPA.selectedIndex].value == 'Y'))
		{
			jQ('#prefmainpage2').show();
			jQ('#prefmainpage3').hide();
			
			//document.getElementById('mainpage').innerHTML = '<input class=\"field\" type=\"text\" name=\"usmapa\" value=\"\">';
			jQ('#mainpage').html('<input class=\"field\" type=\"text\" name=\"usmapa\" value=\"\">');
			document.inpform.usmapa.disabled = false;
		}
		else
		{
			jQ('#prefmainpage2').hide();
			jQ('#prefmainpage3').show();
		}
		*/
		if( jQ('#USOPPA').val() == 'B' )
		{
			//select the first checkbox (Default)
			jQ('.mpagetypesel:first').attr('checked','checked');
			jQ('#usmapa').val('*DEFAULT');
			jQ('#usmapa').attr('disabled','disabled');
						
			jQ('#prefmainpage').show();
			jQ('#prefmainpage2').show();
			jQ('#prefmainpage3').show();
		}
		else
		{
			jQ('#prefmainpage').hide();
			jQ('#prefmainpage2').show();
			jQ('#prefmainpage3').hide();

			jQ('#mainpage').html('<input class=\"field\" type=\"text\" id=\"usmapa\" name=\"usmapa\" value=\"\">');
			jQ('#usmapa').attr('disabled','');
		}
		// end RTC 20081203
	}
}


// RTC 20081204: refactored using jQuery and a switch statement
function load_mainpage(selECMdoc)
{
	var rtnvalue = jQ('.mpagetypesel:checked').val();
	
	jQ('#selECMdoc').val('');
	
	switch(rtnvalue)
	{
		case 'D':		
			jQ('#mainpage').html('<input class=\"field\" type=\"text\" id=\"usmapa\" name=\"usmapa\" value=\"\">');
			jQ('#usmapa').val( jQ('#mainpagesitedefault').val() );
			jQ('#usmapa').attr('disabled','disabled');
			break;
	
		case 'P':
			var url = 'nxusrmnt.pgm?task=listpage&selpage=' + jQ('#selpage').val() + '&usernbr=' + jQ('#usunbr').val();

			// Fire request for data and populate div: 
			jQ.get(url, function(resp)
			{
				jQ('#mainpage').html(resp);
			});
			break;
			
		case 'E':
			//RTC 20081204: simplify html structure and add id attribute
			//jQ('#mainpage').html('<input size=\"50\" maxlength=\"256\" name=\"nodename2\" disabled type=\"text\" value=\"' + selECMdoc + '\"> <span id=\"seldoc\"><a class=\"cursorhand\" onclick=\"opendoctree3();\"><img src=\"/nexuspublic/images/Searchkey.gif\" alt=\"Select Default Location\" title=\"Select Default Location\"></a></span>');
			jQ('#mainpage').html('<input size=\"50\" maxlength=\"256\" id=\"nodename2\" name=\"nodename2\" disabled type=\"text\" value=\"' + selECMdoc + '\"> <img id=\"seldoc\" class=\"cursorhand\" src=\"/nexuspublic/images/Searchkey.gif\" alt=\"Select Default Location\" title=\"Select Default Location\">');
			jQ('#seldoc').bind('click',opendoctree3);
			break;
	}
	
	if ( jQ('#group').val() != 0 )
	{
		parent.SizePage('dyniframe1');
	}
}

function popupcheck()
{
	
	if (document.headfrm.popup.checked == true)
	{
		jQ('#windowdetails').show();
	}
	else
	{
		jQ('#windowdetails').hide();
	}
}


var allStyleRules;

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type. args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) 
{
	// if we got here it's because we didn't find anything try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) 
	{
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) 
		{
			// grab stylesheet rules
			var rules;
			if (document.styleSheets[x].cssRules)
			{
				rules = document.styleSheets[x].cssRules;
			}
			else if (document.styleSheets[x].rules)
			{
				rules = document.styleSheets[x].rules;
			}
			
			if(rules.length > 0) 
			{
				// check each rule
				for(var y = 0; y < rules.length; y++) 
				{
					var z = rules[y].style;
					
					allStyleRules = rules[y].selectorText.toLowerCase();
					if(allStyleRules) 
					{
						if((allStyleRules == c) 
						|| (allStyleRules == (t + "." + c))) 
						{
							return z[p];
							break;
							
						}   
					} 
					else 
					{
						// use the native selectorText and style stuff
						if(((z[p] != "") 
						 && (z[p] != null)) 
						&& ((rules[y].selectorText == c) 
						 || (rules[y].selectorText == (t + "." + c)))) 
						{
							return z[p];
							break;
						}
					}
				}
			}
		}
	}
	
	return null;
}



function corners()
{		
	var pageColor = getStyleByClass('body', 'body', 'background');
	var border = getStyleByClass('span', 'border', 'color');
	
	var divname = '';
	var list = jQ('#mainpage');
	
	var InstCollection = list.find("DIV");
	for (var i=0; i < InstCollection.length; i++) 
	{
		if ((InstCollection[i].id) && (InstCollection[i].getAttribute("id").substring(0, 2) == "wc") && (InstCollection[i].getAttribute("id").substring(0, 3) != "wcd")) 
		{			
			var bdrdsp = jQ('#bdr' + InstCollection[i].id.substring(2,12));
			
			if( bdrdsp.css('display') != 'none')
			{
				divname = 'div#' + InstCollection[i].id;
				Rounded(divname,"top",pageColor,border,"small");
			}
		} 
	}
}


function NiftyCheck()
{
	if(!document.getElementById || !document.createElement)
	{
		return(false);
	}
	isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
	if(Array.prototype.push==null)
	{
		Array.prototype.push=function()
		{
			this[this.length]=arguments[0]; 
			return(this.length);
		}
	}
	return(true);
}

function Rounded(selector,wich,bk,color,opt)
{
	var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false;
	
	if(color=="transparent")
	{
		cn=cn+"x";
		ecolor=bk;
		bk="transparent";
	}
	else if(opt && opt.indexOf("border")>=0)
	{
		var optar=opt.split(" ");
		for(i=0;i<optar.length;i++)
		{
			if(optar[i].indexOf("#")>=0) 
			{
				ecolor=optar[i];
			}
		}
			
		if(ecolor=="")
		{
			ecolor="#666";
		}
		
		cn+="e";
		edges=true;
	}
	else if(opt && opt.indexOf("smooth")>=0)
	{
		cn+="a";
		ecolor=Mix(bk,color);
	}
	
	
	if(opt && opt.indexOf("small")>=0) 
	{
		cn+="s";
	}
	
	prefixt=cn;
	prefixb=cn;
	
	if(wich.indexOf("all")>=0)
	{
		t=true;b=true
	}
	
	else if(wich.indexOf("top")>=0) 
	{
		t="true";
	}
	
	else if(wich.indexOf("tl")>=0)
	{
		t="true";
		if(wich.indexOf("tr")<0)
		{
			prefixt+="l";
		}
	}
	else if(wich.indexOf("tr")>=0)
	{
		t="true";
		prefixt+="r";
	}
	if(wich.indexOf("bottom")>=0)
	{
		b=true;
	}
	else if(wich.indexOf("bl")>=0)
	{
		b="true";
		if(wich.indexOf("br")<0)
		{
			prefixb+="l";
		}
	}
	else if(wich.indexOf("br")>=0)
	{
		b="true";
		prefixb+="r";
	}
	var v=getElementsBySelector(selector);
	var l=v.length;
	for(i=0;i<l;i++)
	{
		if(edges)
		{
			AddBorder(v[i],ecolor);
		}
		if(t)
		{
			AddTop(v[i],bk,color,ecolor,prefixt);
		}
		if(b)
		{
			AddBottom(v[i],bk,color,ecolor,prefixb);
		}
	}
}

function AddBorder(el,bc)
{
	var i;
	if(!el.passed)
	{
		if(el.childNodes.length==1 && el.childNodes[0].nodeType==3)
		{
			var t=el.firstChild.nodeValue;
			el.removeChild(el.lastChild);
			var d=CreateEl("span");
			d.style.display="block";
			d.appendChild(document.createTextNode(t));
			el.appendChild(d);
		}
		for(i=0;i<el.childNodes.length;i++)
		{
			if(el.childNodes[i].nodeType==1)
			{
				el.childNodes[i].style.borderLeft="1px solid "+bc;
				el.childNodes[i].style.borderRight="1px solid "+bc;
			}
		}
	}
	el.passed=true;
}

function AddTop(el,bk,color,bc,cn)
{
	var i,lim=4,d=CreateEl("b");
	
	if(cn.indexOf("s")>=0)
	{
		lim=2;
	}
	if(bc)
	{
		d.className="artop";
	}
	else d.className="rtop";
	d.style.backgroundColor=bk;
	for(i=1;i<=lim;i++)
	{
		var x=CreateEl("b");
		x.className=cn + i;
		x.style.backgroundColor=color;
		if(bc)
		{
			x.style.borderColor=bc;
		}
		d.appendChild(x);
	}
	el.style.paddingTop=0;
	el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,bc,cn)
{
	var i,lim=4,d=CreateEl("b");
	
	if(cn.indexOf("s")>=0)
	{
		lim=2;
	}
	if(bc)
	{
		d.className="artop";
	}
	else d.className="rtop";
	d.style.backgroundColor=bk;
	for(i=lim;i>0;i--)
	{
		var x=CreateEl("b");
		x.className=cn + i;
		x.style.backgroundColor=color;
		if(bc)
		{
			x.style.borderColor=bc;
		}
		d.appendChild(x);
	}
	el.style.paddingBottom=0;
	el.appendChild(d);
}

function CreateEl(x)
{
	if(isXHTML)
	{
		return(document.createElementNS('http://www.w3.org/1999/xhtml',x));
	}
	else
	{
		return(document.createElement(x));
	}
}

function getElementsBySelector(selector)
{
	var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];
	
	if(selector.indexOf(" ")>0)
	{  
		//descendant selector like "tag#id tag"
		s=selector.split(" ");
		var fs=s[0].split("#");
		if(fs.length==1)
		{
			return(objlist);
		}
		f=document.getElementById(fs[1]);
		if(f)
		{
			return(f.getElementsByTagName(s[1]));
		}
		return(objlist);
	}
	if(selector.indexOf("#")>0)
	{ 
		//id selector like "tag#id"
		s=selector.split("#");
		tag=s[0];
		selid=s[1];
	}
	if(selid!="")
	{
		f=document.getElementById(selid);
		if(f)
		{
			objlist.push(f);
		}
		return(objlist);
	}
	if(selector.indexOf(".")>0)
	{  //class selector like "tag.class"
		s=selector.split(".");
		tag=s[0];
		selclass=s[1];
	}
	var v=document.getElementsByTagName(tag);  // tag selector like "tag"
	
	if(selclass=="")
	{
		return(v);
	}
	
	for(i=0;i<v.length;i++)
	{
		if(v[i].className.indexOf(selclass)>=0)
		{
			objlist.push(v[i]);
		}
	}
	return(objlist);
}

function Mix(c1,c2)
{
	var i,step1,step2,x,y,r=new Array(3);
	
	if(c1.length==4)
	{
		step1=1;
	}
	else
	{
		step1=2;
	}
	
	if(c2.length==4)
	{
		step2=1;
	}
	else
	{
		step2=2;
	}
	
	for(i=0;i<3;i++)
	{
		x=parseInt(c1.substr(1+step1*i,step1),16);
	
		if(step1==1)
		{
			x=16*x+x;
		}
		y=parseInt(c2.substr(1+step2*i,step2),16);
		
		if(step2==1)
		{
			y=16*y+y;
		}
		r[i]=Math.floor((x*50+y*50)/100);
	}
	return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16));
}

function reloadmainpage()
{
	try
	{
		parent.window.opener.top.location.reload(true);
	}
	catch(err)
	{
		
	}
	
	parent.window.close();
	
}


function setupdftcnt()
{
	oEdit1.mode="HTMLBody";
	oEdit1.btnSpellCheck=true;
	//RTC 20090220: Update for InnovaEdit 3.5
	oEdit1.useTab=false;
	
	oEdit1.height = '400';
	oEdit1.width="750";
	
	// Allow for custom style sheet
	oEdit1.btnStyles=true;
	oEdit1.initialRefresh=true;
	
	oEdit1.REPLACE("dftcnt");
}


function dragdiv(elementToDrag, event) 
{
	//elementToDrag.style.cursor = "pointer"; 
	var startX = event.clientX, startY = event.clientY;
	var origX = elementToDrag.offsetLeft, origY = elementToDrag.offsetTop;
	var deltaX = startX - origX, deltaY = startY - origY;
	
	if (document.addEventListener) 
	{ 
		document.addEventListener("mousemove", moveHandler, true);
		document.addEventListener("mouseup", upHandler, true);
	}
	else if (document.attachEvent) 
	{
		elementToDrag.setCapture( );
		elementToDrag.attachEvent("onmousemove", moveHandler);
		elementToDrag.attachEvent("onmouseup", upHandler);
		elementToDrag.attachEvent("onlosecapture", upHandler);
	}
	else 
	{  
		var oldmovehandler = document.onmousemove;
		var olduphandler = document.onmouseup;
		document.onmousemove = moveHandler;
		document.onmouseup = upHandler;
	}
	
	if (event.stopPropagation)
	{
		event.stopPropagation();
	}
	else
	{
		event.cancelBubble = true;
	}
	
	if (event.preventDefault)
	{
		event.preventDefault();
	}
	else
	{
		event.returnValue = false;
	}
	
	function moveHandler(e) 
	{
		//elementToDrag.style.cursor = "move"; 
		if (!e)
		{
			e = window.event;  // IE Event Model
		}
		elementToDrag.style.left = (e.clientX - deltaX) + "px";
		elementToDrag.style.top = (e.clientY - deltaY) + "px";
		
		if (e.stopPropagation)
		{
			e.stopPropagation();
		}
		else
		{
			e.cancelBubble = true;
		}
	}
	
	function upHandler(e) {
		//elementToDrag.style.cursor = "default"; 
		
		if (!e) 
		{
			e = window.event;
		}
		
		if (document.removeEventListener) 
		{
			document.removeEventListener("mouseup", upHandler, true);
			document.removeEventListener("mousemove", moveHandler, true);
		}
		else if (document.detachEvent) 
		{  
			elementToDrag.detachEvent("onlosecapture", upHandler);
			elementToDrag.detachEvent("onmouseup", upHandler);
			elementToDrag.detachEvent("onmousemove", moveHandler);
			elementToDrag.releaseCapture( );
		}
		else 
		{  
			document.onmouseup = olduphandler;
			document.onmousemove = oldmovehandler;
		}
		
		if (e.stopPropagation)
		{
			e.stopPropagation( );
		}
		else
		{
			e.cancelBubble = true;
		}
	}
}
/**************************************** esdi javascript library *********************************************/

/** Function:  	 xl_FindPosX 
 *  Purpose: 		 Find left position (x coordinate) of an object on a page. 
 *  @param			 Object reference (can be got with xl_GetObj) 
/*  @return			 curleft  left position of object
*/  

function xl_FindPosX(obj)
{
	var curleft = 0;
	if (obj && obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
		curleft += obj.offsetLeft;  // added in Version 1.90 - ESDIAPI010.js
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
	
}


/** Function:  	 xl_FindPosY 
 *  Purpose: 		 Find top position (y coordinate) of an object on a page. 
 *  @param			 Object reference (can be got with xl_GetObj) 
/*  @return			 curleft  left position of object
*/  
function xl_FindPosY(obj)
{
	var curtop = 0;
	if (obj && obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
		curtop += obj.offsetTop;  // added in Version 1.90 - ESDIAPI010.js
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

//      - - - - - - - - End of  Bill Dortch code - - - - - - - -      


/** Function:	xl_GetDay
 *  Purpose: 	Get the text for a given day of week index
 */
function xl_GetDay(intDay)
{
	var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
	"Thursday", "Friday", "Saturday");
	return DayArray[intDay];
}

/** Function:	xl_Getmonth
 *  Purpose: 	Get the text for a given month index
 */
function xl_GetMonth(intMonth)
{
	var MonthArray = new Array("January", "February", "March",
	"April", "May", "June",
	"July", "August", "September",
	"October", "November", "December");
	return MonthArray[intMonth];	  	 
}

/** Function:	xl_GetDateStr
 *  Purpose: 	Format and return the current date
 */
// Example: September 21, 2004		
function xl_GetDateStr()
{
	var today = new Date();
	var year = today.getYear();
	if(year<1000)
	{
		year+=1900;
	}
	
	var todayStr = xl_GetMonth(today.getMonth()) + " " + today.getDate();
	todayStr += ", " + year;
	return todayStr;
}

/** Function:	xl_GetDateStr
 *  Purpose: 	Format and return the current date
 */
// Example: Monday September 21, 2004
function xl_GetDateStrWithDOW()
{
	var today = new Date();
	var year = today.getYear();
	if(year<1000)
	{
		year+=1900;
	}
	
	var todayStr = xl_GetDay(today.getDay()) + ", ";
	todayStr += xl_GetMonth(today.getMonth()) + " " + today.getDate();
	todayStr += ", " + year;
	return todayStr;
}

/** Function:	xl_GetShortDate
 *  Purpose: 	Format and return the current date
 */
// Example:  09/21/2004		
function xl_GetShortDate()
{
	var today = new Date();
	var year = today.getYear();
	// 2006-12-20 Tyson Gilberstad - added leading zeros for < 10 case for month & day
	var month = today.getMonth() + 1;
	if (month < 10)
	{
		month = "0" + month;
	}
	var day = today.getDate();
	if (day < 10) 
	{
		day = "0" + day;
	}
	if(year<1000)
	{
		year+=1900;
	}
	var shortdate=    month + "/" +  day + "/" + year;
	return shortdate;
}

/** Function:	  xl_BuildURLWithFormElements
 *  Purpose:   	 Constructs a string that (usually) comprises a URL, to emulate the format provided by a conventional html form submission. It finds every element name and value for a specified form and appends them to the specified string in the format ?name1=value1&name2=value2 or &name1=value1&name2=&value2, depending on whether an initial parm is present.
 *  @param        frmname - Name of form on page containing elements to use 
 *                string - Starting string to contain the URL. 
 * 		            boolean - Flag if disabled elements should be added to string (optional: default true)
 *  @return       string - Resulting constructed string.
 *  Usage notes:  See Wiki 
*/  
function xl_BuildURLWithFormElements(frmname, str, addDisabled)
{
	// Look for '?' in string - if found, the first parm in a url exists- no need to add it. 
	if (str == undefined)
	{
		str = "";
	}
	
	var x=str.indexOf('?');
	var frm = jQ('#'+frmname)[0];
	
	// 2006-12-20 Tyson Gilberstad - check for form name if form not found by id
	if (frm == undefined) 
	{
		frm = document.forms[frmname];
	}
	
	var elem = frm.elements;
	var parmAdded = ( x != -1);
	
	if (addDisabled == undefined)
	{
		addDisabled = true;
	}
	
	for (var i = 0; i < elem.length; i++)
	{
		if (!addDisabled && elem[i].disabled) 
		{
			// do nothing
		}
		
		else if ((elem[i].tagName == 'INPUT') && ((elem[i].type == 'radio') || (elem[i].type == 'checkbox')) && (!elem[i].checked)) 
		{
			// do nothing
		}
		
		else if ((elem[i].tagName == 'SELECT') && (elem[i].multiple))
		{
			// need to iterate through the items in the select and add all that are selected
			
			for (j=0; j< elem[i].options.length; j++)
			{	
				if ( elem[i].options[j].selected == true )
				{
					str = xl_AddParmToURLString(str, elem[i].name, elem[i].options[j].value);
				}
			}
			
		}
		
		else 
		{
			str = xl_AddParmToURLString(str, elem[i].name, elem[i].value);
		}
	} 
	return str;
}

/** Function:   xl_FocusFirstElement
 *  Purpose:    Set the focus to the first valid element we can find (regardless of form)
 * 	Source:		http://www.codeproject.com/jscript/FocusFirstInput.asp
 *  Usage notes:  See Wiki 
*/    
function xl_FocusFirstElement()
{
	var bFound = false;
	
	// for each form
	for (f=0; f < document.forms.length; f++)
	{
		// for each element in each form
		for(i=0; i < document.forms[f].length; i++)
		{
			// if it's not a hidden element
			if (document.forms[f][i].type != "hidden")
			{
				// and it's not disabled
				if (document.forms[f][i].disabled != true)
				{
					// set the focus to it
					document.forms[f][i].focus();
					var bFound = true;
				}
			}
			
			// if found in this element, stop looking
			if (bFound == true)
			{
				break;
			}
		}
		
		// if found in this form, stop looking
		if (bFound == true)
		{
			break;
		}
	}
}


/** Function:	  xl_EnableDrag
 *  Purpose:   	  Enables any element to be draggable, usually DIVs. 
 *  @param        object - Obj -  Handle to Object eg: xl_GetObj(id) using  id attribute value of <div> tag)  
 */  
function xl_EnableDrag(Obj)
{ 
	var ObjCurrStyle; 
	
	// Actually, allow use of id also: 
	if (Obj instanceof Object == false)
	{
		Obj = xl_GetObj(Obj); 
	}
	
	// IE method of getting computed style for this element (combines classes and inline CSS)
	if (Obj.currentStyle) 
	{
		ObjCurrStyle = Obj.currentStyle; 
	}
	else // Mozilla method: 
	{
		ObjCurrStyle  = window.getComputedStyle(Obj, null); 
	}
	
	// Make sure the style sheet setting is position:absolute -required for drag and drop.
	// Use computed style to determine this, but change actual style (computed style is read-only)
	if (ObjCurrStyle.position != "absolute")
	{
		Obj.style.position = "absolute"; 
	}
	
	// If no z-index value, make sure our div sits above rest of page: 
	
	// Check for zIndex being 0 or auto (FireFox) . If so, make it sit above rest of page: 
	if((ObjCurrStyle.zIndex == 0) 
	|| (ObjCurrStyle.zIndex == "auto"))
	{
		Obj.style.zIndex=999;
	}
	
	//xl_AttachEvent(Obj, "mousedown", xl_DragMe); 
	jQ(Obj).bind('mousedown', xl_DragMe);
}   

/** Function:	  xl_DragMe
 *  Purpose:      Implementation for xl_EnableDrag - drag absolutely positioned HTML elements.
 *				  Drags element that is the direct target of the current event object. Uses xl_Drag, which requires the element id in addition to the event object.
 *  @param        event-  the Event object for the mousedown event.
 */
function xl_DragMe(e) 
{
	//var target =xl_GetEventTarg(event); 
	var target = e.target;
	
	xl_Drag(target, e); 
} 	

/** Function:	  xl_Drag

 *  Purpose:      Called from an onmousedown event handler. Subsequent mousemove events will
 *                move the specified element. A mouseup event will terminate the drag.
 *                If the element is dragged off the screen, the window does not scroll.
 *                This implementation works with both the DOM Level 2 event model and the IE event model.
 *
 *  @param 	      me - the element that received the mousedown event or
 *                  some containing element. It must be absolutely positioned. Its
 *                  style.left and style.top values will be changed based on the user's
 *                  drag.
 *                event-  the Event object for the mousedown event.
 */
function xl_Drag(me, e) 
{
	var event = e;
	
	me.style.cursor = "pointer"; 
	// The mouse position (in window coordinates)
	// at which the drag begins
	
	var startX = event.clientX;
	var startY = event.clientY;
	
	// The original position (in document coordinates) of the
	// element that is going to be dragged. Since me is
	// absolutely positioned, we assume that its offsetParent is the
	// document body.
	var origX = me.offsetLeft;
	var origY = me.offsetTop;
	
	// Even though the coordinates are computed in different
	// coordinate systems, we can still compute the difference between them
	// and use it in the moveHandler( ) function. This works because
	// the scrollbar position never changes during the drag.
	var deltaX = startX - origX;
	var deltaY = startY - origY;
	
	
	// Register the event handlers that will respond to the mousemove events
	// and the mouseup event that follow this mousedown event.
	jQ(document).bind('mousemove',moveHandler);
	jQ(document).bind('mouseup', upHandler);
	
	
	// We've handled this event. Don't let anybody else see it.
	e.stopPropagation();
	
	
	// Now prevent any default action.
	e.preventDefault();
	
	/**
	* This is the handler that captures mousemove events when an element
	* is being dragged. It is responsible for moving the element.
	**/
	function moveHandler(e) 
	{
		
		me.style.cursor = "move"; 
		
		// Move the element to the current mouse position, adjusted as
		// necessary by the offset of the initial mouse-click.
		me.style.left = (e.clientX - deltaX) + "px";
		me.style.top = (e.clientY - deltaY) + "px";
		
		e.stopPropagation();
	}
	
	/**
	* This is the handler that captures the final mouseup event that
	* occurs at the end of a drag.
	**/
	function upHandler(e) 
	{
		me.style.cursor = "default"; 
		
		// Unregister the capturing event handlers.
		jQ(document).unbind('mouseup',upHandler);
		jQ(document).unbind('mousemove',moveHandler);
		
		// And don't let the event propagate any further.
		e.stopPropagation();
	}
}

/** Function:	  xl_AddParmToURLString
 *  Purpose:   	  Adds a parameter to a URL string
 *  @param        string - Starting string to contain the URL.  
 *                string - Parameter name
 *                string - Parameter value
 *  @return       string - Resulting constructed string.
*/  
function xl_AddParmToURLString(str, name, value)
{
	if(str.indexOf('?') == -1) 
	{
		str += "?";
	}
	else
	{
		str += "&";
	}
	
	return str + xl_Encode(name) + "=" + xl_Encode(value);
}

/** Function: 	   xl_Encode 
 *  Purpose: 		 	 URL-encode a string to ensure compatibility with all character sets
 *  @param				 uri - raw string
 *  @return 			 uri - encoded string
*/
function xl_Encode( uri )
{
	if (encodeURIComponent)
	{
		return encodeURIComponent(uri);
	}
	
	if (escape)
	{
		return escape(uri);
	}
} 


// pop up nexus help dialog
function nx_showHelp(event)
{
	var toppos = event.screenY + 15;
	var leftpos = event.screenX - 400;
	var position = 'dependent,scrollbars=1,resizable=1,height=400,width=400,left=' + leftpos + ',top=' + toppos;
	window.open('/nexuspublic/help/searchtipshelp.htm','searchtips',position);
}

//attempts to find and retrieve one of the top level iframes, regardless of calling depth or implementation of parent layers
function nx_gettopframe(frameid)
{
	return jQ(window.top.document).find('#'+frameid)[0];
}

// 'closes' a popup by hiding its contents
function nx_closepopup()
{
	jQ(top.document).find('#auxinfo').css('visibility','hidden');
}


/// former contents of nxlistpopup 

function returnvalue(keyvalue, equal)
{
	var gpdoc = jQ(parent.parent.document);
	if (equal == "N")
	{
		gpdoc.find('#srchkeys').val(keyvalue);
	}
	else
	{
		var keyslist = gpdoc.find('#srchkeys').val() + " "+ keyvalue + "=";
		if(keyslist.charAt(0) == " ")
		{
			keyslist = keyslist.substring(1);
		}
		gpdoc.find('#srchkeys').val( keyslist );
	}

	gpdoc.find('#srchkeys').focus();
	gpdoc.find('#keypair').hide();
}

function returnvalue2(keyvalue)
{
	var gpdoc = jQ(parent.parent.document);
	if ( gpdoc.find('#srchkeys2').val() != "")
	{	
		gpdoc.find('#srchkeys2').val( gpdoc.find('#srchkeys2').val() +" "+ keyvalue + "=");
	}
	else
	{
		gpdoc.find('#srchkeys2').val( keyvalue + "=");
	}
	
	gpdoc.find('#srchkeys2').focus();
	gpdoc.find('#key2pair').hide();
}


function searchlist()
{
	var searchval = jQ('#searchvalue').val().toUpperCase();
	
	var listdoc = jQ(jQ('#srchlist')[0].contentWindow.document);
	var searchelem = jQ(listdoc).find('#searchstr');
	searchelem.val( searchelem.val().toUpperCase() );
	
	var TempString = listdoc.find('#searchstr').val();

	var StrPos = listdoc.find('#searchstr').val().search( searchval );
	if (StrPos == -1)
	{
		//find the closest match
		var length = searchval.length;
		while ((StrPos == -1) && ( searchval != ""))
		{
			length = length - 1;
			searchval = searchval.substr(0, length);
			var StrPos = TempString.search(searchval);
		}
	}
	
	//if we found a match
	if (StrPos != -1)
	{
		var TempString = TempString.substr(StrPos);
		TempString = TempString.substr(0, TempString.search(';'));
		var gotohash = '#' + TempString;
		listdoc[0].location.hash = gotohash;
		location.hash = "Top";
	}
	
	jQ('#searchvalue').val('');


}


function closekey()
{
	jQ(parent.document).find('#keypair').hide();
}

function closekey2()
{
	jQ(parent.document).find('#key2pair').hide();
}


function closetype()
{
	jQ(parent.document).find('#doctype').hide();
}

/// end former contents of nxlistpopup

/// former contents of nxchgmsgtabs
var pageval = "";
var userwindow = null;
var groupwindow = null;
var userloaded = false;
var grouploaded = false;

function pagefunc1()
{
	pageval = "1";
	optdisp();

	jQ('#pg1').addClass("tabsel");
	jQ('#pg2').replaceClass("tab");
	jQ('#pg3').replaceClass("tab");
	jQ('#pg4').replaceClass("tab");
	jQ('#pg5').replaceClass("tab");

	adjustParent();
	jQ('#pageval').val(pageval)

	if ( jQ('#allowimsg').val() == "")
	{
		jQ('#imsgtab').hide();
		jQ('#imsg1').hide();
		jQ('#imsg2').hide();
		jQ('#imsg3').hide();
		jQ('#imsg4').hide();
	}
	 
}

function pagefunc2()
{
	pageval = "2";
	optdisp();
	jQ('#pg1').replaceClass("tab");
	jQ('#pg2').addClass("tabsel");
	jQ('#pg3').replaceClass("tab");
	jQ('#pg4').replaceClass("tab");
	jQ('#pg5').replaceClass("tab");

	adjustParent();
	jQ('#pageval').val(pageval);

	var instance = jQ('#instance').val();
	
	var url = 'NXMSG.pgm?task=nexusmsg&instance=' + instance + "&rnd=" + Math.random();
	jQ('#nexusmsgframe')[0].src=url;
}

function pagefunc3()
{
	pageval = "3";
	optdisp();
	jQ('#pg1').replaceClass("tab");
	jQ('#pg2').replaceClass("tab");
	jQ('#pg3').addClass("tabsel");
	jQ('#pg4').replaceClass("tab");
	jQ('#pg5').replaceClass("tab");

	adjustParent();
	jQ('#pageval').val(pageval);

	var instance = jQ('#instance').val();
	var url = 'NXMSG.pgm?task=nexussent&instance=' + instance + "&rnd=" + Math.random();
	
	jQ('#nexussentframe').attr('src',url);
}

function pagefunc4()
{
	pageval = "4";
	optdisp();
	jQ('#pg1').replaceClass("tab");
	jQ('#pg2').replaceClass("tab");
	jQ('#pg3').replaceClass("tab");
	jQ('#pg4').addClass("tabsel");
	jQ('#pg5').replaceClass("tab");

	document.inpform.pageval.value = "4";

	var ifr = jQ('#iseriesframe')[0];

	var instance = jQ('#instance').val();
	if ((ifr.src != '') && (ifr.src.search('/nexuspublic/nothing.htm') == -1))
	{
		var queuename = jQ('#iseriesframe')[0].contentWindow.document.inpform.queuename.value;
		var queuelib = jQ('#iseriesframe')[0].contentWindow.document.inpform.queuelib.value
		var url = 'NXMSG.pgm?task=iseriesmsg&instance=' + instance + '&queuename=' + queuename + '&queuelib=' + queuelib + "&rnd=" + Math.random();
	}
	else
	{
		var url = 'NXMSG.pgm?task=iseriesmsg&instance=' + instance + "&rnd=" + Math.random();
	}

	ifr.src = url;
	adjustParent();
}


function pagefunc5()
{
	pageval = "5";
	optdisp();
	jQ('#pg1').replaceClass("tab");
	jQ('#pg2').replaceClass("tab");
	jQ('#pg3').replaceClass("tab");
	jQ('#pg4').replaceClass("tab");
	jQ('#pg5').addClass("tabsel");
	
	adjustParent();
	jQ('#pageval').val(pageval);
 	
 	reloadcontacts();
}


function optdisp() 
{ 
   	jQ('#pagedsp1').hide();
	jQ('#pagedsp2').hide();
	jQ('#pagedsp3').hide();
	jQ('#pagedsp4').hide();
	jQ('#pagedsp5').hide();

   	switch(pageval)
   	{
   		case '1':
   			jQ('#pagedsp1').show();
   			jQ('#dspbuttons').hide();
   			break;
		case '2':
			jQ('#pagedsp2').show();
			jQ('#dspbuttons').show();
			break;
		case '3':
			jQ('#pagedsp3').show();
			jQ('#dspbuttons').show();	
			break;
		case '4':
			jQ('#pagedsp4').show();
			jQ('#dspbuttons').show();
			break;
	   	case '5':
	   		jQ('#pagedsp5').show();
			jQ('#dspbuttons').hide();	
			break;
   	}
}


function sendmsg()
{

	jQ('#usrgrppopup').hide();
	
	//set the form value to match the current data in the editor element
	jQ('#htmlTBBox').val( oEdit1.getHTMLBody() );

	// PFC 20050520 - 
	var text = jQ('#htmlTBBox').val();
	
	text = text.replace(/\"/g , "&#034;");
	
	// PFC 20050520 - Not the best solution (will come back to this)
	var text = text.replace(/\'/g , " ");

	document.inpform.msgtxt.value = text;

	if (text.length < 30000)
	{
		document.inpform.submit();
	}
	else
	{
		alert('The body content length (' + text.length + ') exceeds the available space of 30000');
	}
}


function clearmsg() 
{ 
	document.inpform.iUserName.value = "";
	document.inpform.msgtype.value = "";
	document.inpform.msgq.value = "";
	document.inpform.msglib.value = "";
	document.inpform.nxUserName.value = "";
	document.inpform.nxGroupName.value = "";
	oEdit1.putHTML("");
}

function reply(msgtype,textid,msgdate,msgtime,touser,fromuser) 
{ 

	var rExp = '/<br>/gi';
	var text = jQ('#'+textid).html();
	
	text = text.replace(rExp, '\r\n');
	var msgtxt = "<br>___________________________________________________________________________________<br><b>From:</b> " + touser + "<br><b>Sent:</b> " + msgdate + "  " + msgtime + "<br><b>To:</b> " + fromuser + "<br>" + text;

	if (msgtype == "Reply")
	{
		parent.document.inpform.nxUserName.value = touser;
	}

	parent.pagefunc1();
	parent.oEdit1.putHTML(msgtxt);
}


function replytogroup(msgtype,textid,msgdate,msgtime,touser,group) 
{ 
	var rExp = '/<br>/gi';
	var text = jQ('#'+textid).html();

	text = text.replace(rExp, '\r\n');
	var msgtxt = "<br>___________________________________________________________________________________<br><b>From:</b> " + touser + "<br><b>Sent:</b> " + msgdate + "  " + msgtime + "<br><b>To Group:</b> " + group + "<br>" + text;

	if (msgtype == "Reply")
	{
		parent.document.inpform.nxGroupName.value = group;
		parent.document.inpform.nxUserName.value = '';
	}

	parent.pagefunc1();
	parent.oEdit1.putHTML(msgtxt);
}

function sendnewmsg(touser)
{
	parent.document.inpform.nxUserName.value = touser;
	parent.pagefunc1();
	parent.oEdit1.putHTML("");
}


function sendchat(fromuser)
{
	if (parent.sendmsgframe.document.inpform.contactname.value != '')
	{	
		var fromusername = parent.sendmsgframe.document.inpform.fromusername.value;
		var date = new Date();
		if (parent.rcvmsgframe.document.inpform.rcvchatmsg.value == '')
		{
			parent.rcvmsgframe.document.inpform.rcvchatmsg.value = parent.rcvmsgframe.document.inpform.rcvchatmsg.value + 'From: ' + fromusername + '   ' + date + '\r\n' + parent.sendmsgframe.document.inpform.chatmsg.value;	
		}
		else
		{
			parent.rcvmsgframe.document.inpform.rcvchatmsg.value = parent.rcvmsgframe.document.inpform.rcvchatmsg.value + '\r\n\r\nFrom: ' + fromusername + '   ' + date +'\r\n' + parent.sendmsgframe.document.inpform.chatmsg.value;	
		
		}

		// Positions to the end of the textarea 
		var range = parent.rcvmsgframe.document.inpform.rcvchatmsg.createTextRange();
		range.collapse(false);
		range.select();

		// Set focus to the send msg area 
		parent.sendmsgframe.document.inpform.chatmsg.focus();

		var tousername = parent.sendmsgframe.document.inpform.contactname.value;
		var chatmsg = parent.sendmsgframe.document.inpform.chatmsg.value;
		parent.sendmsgframe.document.inpform.chatmsg.value = '';
		
		chatmsg = chatmsg.replace(/\"/g , "&#034;");

		// PFC 20050317 - added escape function 
		var url = 'nximsg.pgm?task=sendchat&fromuser=' + fromuser + '&tousername=' + tousername + '&chatmsg=' + escape(chatmsg) + "&rand=" + randnum;
		sendframe.location.href=url;	
	}
	else
	{
		parent.rcvmsgframe.document.inpform.rcvchatmsg.value = parent.rcvmsgframe.document.inpform.rcvchatmsg.value + '\r\nError: Contact Not specified. No Message has been sent.';
	}
}

function writemsg()
{
	onerror=handlerFunction

	var fromform = parent.document.inpform;
	if ((document.inpform.rcvmessage.value != '') 
	 && (fromform.tousername.value == document.inpform.fromusername.value))
	{
		var date = new Date();
		var tomsg = parent.rcvmsgframe.document.inpform.rcvchatmsg.value;
		if (tomsg == '')
		{
			tomsg = tomsg + 'From: ' + document.inpform.fromusername.value + '   ' + date +'\r\n' + document.inpform.rcvmessage.value;
			
		}
		else
		{
			tomsg = tomsg + '\r\n\r\nFrom: ' + document.inpform.fromusername.value + '   ' + date +'\r\n' + document.inpform.rcvmessage.value;
		}

		// If the chat is ended then stop the user from sending more msgs
		var result = tomsg.search('has ended this chat session!')
		if (result != -1)
		{		
			parent.sendmsgframe.document.inpform.chatmsg.disabled = true;	
		}

		var fromuser = document.inpform.fromuser.value;
		var url = 'NXIMSG.pgm?task=deletemsg&fromuser=' + fromuser + "&rnd=" + Math.random();
		parent.deleteframe.location.href=url;

		// Positions to the end of the textarea 
		var range = parent.rcvmsgframe.document.inpform.rcvchatmsg.createTextRange();
		range.collapse(false);
		range.select();
		
		// Retain position in the send msg box
		parent.sendmsgframe.document.inpform.chatmsg.focus();
		parent.sendmsgframe.document.inpform.chatmsg.value = parent.sendmsgframe.document.inpform.chatmsg.value + '';
	}
	reloadgetmsg();
}

function handlerFunction()
{
	return true
}


function loadgetmsg()
{
	var touser = document.inpform.touser.value;
	var url = 'NXIMSG.pgm?task=getmsg&touser=' + touser + "&rand=" + randnum;
	getframe.location.href=url;	
	
	parent.sendmsgframe.document.inpform.chatmsg.focus();
}

function reloadgetmsg()
{
		setTimeout('reloadnow()',5000); 
}

function reloadnow()
{
	var touser = document.inpform.touser.value;
	var url = 'NXIMSG.pgm?task=getmsg&touser=' + touser + "&rnd=" + Math.random();
	parent.getframe.location.href=url
}

// Reload the contacts list every 60 sec
function reloadcontacts()
{
	
	if (document.inpform.pageval.value == '5')
	{
		var instance = document.inpform.instance.value;
		var url = 'NXMSG.pgm?task=friendlist&instance=' + instance + "&rnd=" + Math.random();
		contactframe.location.href=url;
		setTimeout('reloadcontacts()',60000);
	}
}


function closechat()
{
	parent.document.inpform.task.value = 'closechat';
	parent.inpform.submit();
}

// Send close msg to chat window
function closechatwdw(fromusername)
{
	parent.sendmsgframe.document.inpform.endofchat.value = 'Y';
	parent.sendmsgframe.document.inpform.tousername.value = parent.sendmsgframe.document.inpform.contactname.value;
	parent.sendmsgframe.document.inpform.chatmsg.value = fromusername + ' has ended this chat session!';
	parent.sendmsgframe.document.inpform.submit();
	parent.sendmsgframe.document.inpform.chatmsg.value = '';
	
	// Pause to allow prev submit to run...
	wait(2000);
}

/* RTC 20081014: just use wait instead
// Pause the browser
function pausecomp(Amount)
{
	d = new Date() //today's date
	while (1)
	{
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > Amount ) {break;}
	}
}
*/


// Set the show inactive flag
function setstatus()
{
	document.inpform.task.value = 'setstatus';

	if (document.inpform.setinactive.checked)
	{
		document.inpform.status.value = 'I';	
	}
	else
	{
		document.inpform.status.value = '';
	}

	inpform.submit();
}

// Refresh list
function processrefresh()
{
    if (pageval == "2") 
	{
		nexusmsgframe.inpform.task.value = 'nexusmsg';
		nexusmsgframe.inpform.submit();
	}

    if (pageval == "3") 
	{
		nexussentframe.inpform.task.value = 'nexussent';
		nexussentframe.inpform.submit();
	}

    if (pageval == "4") 
	{		
		iseriesframe.inpform.task.value = 'iseriesmsg';
		iseriesframe.inpform.submit();
	}
}

// Delete list 
function processremove()
{
    if (pageval == "2") 
	{
		nexusmsgframe.inpform.task.value = 'clearlist';
		nexusmsgframe.inpform.submit();
	}

    if (pageval == "3") 
	{
		nexussentframe.inpform.task.value = 'clearlist';
		nexussentframe.inpform.submit();
	}

    if (pageval == "4") 
	{
		iseriesframe.inpform.task.value = 'rmvimsg';
		iseriesframe.inpform.submit();
	}
}

function setuptabs()
{
	try 
	{ 
		var background = getStyleByClass('span', 'tab', 'background');

		NiftyCheck();
		
		Rounded('div#nav span','top','transparent',background,'small');
		
		// RTC 20090914: removing unnecessary runtime css change. Changed the programs to be visible initially
		//jQ('#tabbar').css('visibility','visible');
	}
	catch(err) 
	{
		
	}  	
}
	

/// end former contents of nxchgmsgtabs

/// former contents of nxwebmsg
function setcontact(user)
{
	var instance = jQ('#instance').val();
	var url = 'NXIMSG.pgm?task=chatrequest&tousername=' + user + "&rnd=" + Math.random();
	parent.spawnframe.location.href=url;

	url = 'nxmsg.pgm?TASK=chat&instance=' + instance + '&touser=' + user + '&dspwait=Y';
	window.open(url,user,'dependent,width=435,height=268,left=15,top=45');
	
	wait(1000);
	window.location.reload(true);
}
/// end former contents of nxwebmsg

/// start former contents of nxpolltabs
var pageval = "";
var userwindow = null;
var groupwindow = null;
var userloaded = false;
var grouploaded = false;
var iframearray = new Array(100);
var iframectr = 0;

function nxp_pagefunc1()
{
	pageval = "1";
	optdisp();
	jQ('#pg1').addClass("tabsel");
	jQ('#pg2').replaceClass("tab");
}

function nxp_pagefunc2()
{
	pageval = "2";
	optdisp();
	jQ('#pg1').replaceClass("tab");
	jQ('#pg2').addClass("tabsel");
}




function nxp_optdisp() 
{ 
    if (pageval == "1") 
	{	
		jQ('#pagedsp1').show();
		jQ('#pagedsp2').hide();
   	} 
  	if (pageval == "2") 
	{
		jQ('#pagedsp1').hide();
		jQ('#pagedsp2').show();
    }
}


function nxp_sendmsg()
{

	usrgrppopup.style.display = "none";

	document.forms.inpform.elements.msgtxt.value = oEdit1.getHTMLBody();

	// PFC 20050520 - 
	var text = document.inpform.msgtxt.value.replace(/\"/g , "&#034;");
	// PFC 20050520 - Not the best solution (will come back to this)
	var text = document.inpform.msgtxt.value.replace(/\'/g , " ");

	document.inpform.msgtxt.value = text;

	if (document.forms.inpform.msgtxt.value.length < 30000)
	{
		inpform.submit();
	}
	else
	{
		alert('The body content length (' + document.forms.inpform.msgtxt.value.length + ') exceeds the available space of 30000');
	}
}


function nxp_clearmsg() 
{ 
	document.inpform.msgtxt.value = "";
	document.inpform.iUserName.value = "";
	document.inpform.msgtype.value = "";
	document.inpform.msgq.value = "";
	document.inpform.msglib.value = "";
	document.inpform.nxUserName.value = "";
	document.inpform.nxGroupName.value = "";
	oEdit1.putHTML("");
}

function nxp_reply(msgtype,textid,msgdate,msgtime,touser,fromuser) 
{ 
	var rExp = '/<br>/gi';
	var text = jQ('#'+textid).html();

	text = text.replace(rExp, '\r\n');
	var msgtxt = "<br>___________________________________________________________________________________<br>"
	+"<b>From:</b> " + touser + "<br><b>Sent:</b> " + msgdate + "  " + msgtime + "<br><b>To:</b> " + fromuser + "<br>" + text;

	if (msgtype == "Reply")
	{
		parent.sendframe.document.inpform.nxUserName.value = touser;
		parent.sendframe.document.inpform.nxGroupName.value = '';
	}

	parent.pagefunc2();
	parent.sendframe.oEdit1.putHTML(msgtxt);
}


function nxp_replytogroup(msgtype,textid,msgdate,msgtime,touser,group) 
{ 
	var rExp = '/<br>/gi';
	var text = jQ('#'+textid).html();

	text = text.replace(rExp, '\r\n');
	var msgtxt = "<br>___________________________________________________________________________________<br>"
	+"<b>From:</b> " + touser + "<br><b>Sent:</b> " + msgdate + "  " + msgtime + "<br><b>To Group:</b> " + group + "<br>" + text;

	if (msgtype == "Reply")
	{
		parent.sendframe.document.inpform.nxGroupName.value = group;
		parent.sendframe.document.inpform.nxUserName.value = '';
	}

	parent.pagefunc2();
	parent.sendframe.oEdit1.putHTML(msgtxt);
}

/// end former contents of nxpolltabs


//from Telnet_Objects
function loadTelnet(widtha,heighta,licname,lickey,EMHOST,EMPORT,EMKEYS,EMLCLSV,EMSECC,EMSSH,EMNGTDS,EMCLRD,EMCLBG,EMCLCR,EMCLSL,EMFNTWT,EMFNTIT,EMFNTNM,EMPFNTSZ,EMPFNTWT,EMPFNTIT,EMPFNTNM,EMUSECV,EMAUTOC,EMPRHOST,EMPRENAB,EMPRPORT,EMPRSNTX,EMPRSOCK,EMPRRTN,EMBLKCS,EMCSTYP)
{
  jQ('#DivID').html('<object id="MATELNET" classid="CLSID:A5A216EB-4F7C-11D5-8438-0000B456BA3D" codebase="matelnet.cab#version=1,3,0,0" align="center" border="0" width="' + widtha + '" height="' + heighta + '"><param name="licname" value="' + licname + '"><param name="lickey" value="' + lickey + '"><param name="host_name" value="' + EMHOST + '"><param name="port" value="' + EMPORT + '"><param name="termtype" value="VT220"><param name="keys" value="' + EMKEYS + '"><param name="localsave" value="' + EMLCLSV + '"><param name="security_connect" value="' + EMSECC + '"><param name="ssh" value="' + EMSSH + '"><param name="ssh_encryption" value="' + EMNGTDS + '"><param name="color_fg" value="' + EMCLRD + '"><param name="color_bg" value="' + EMCLBG + '"><param name="color_cursor" value="' + EMCLCR + '"><param name="color_bold" value="' + EMCLSL + '"><param name="font_weight" value="' + EMFNTWT + '"><param name="font_italic" value="' + EMFNTIT + '"><param name="term_size" value="132"><param name="font_name" value="' + EMFNTNM + '"><param name="pfontsize" value="' + EMPFNTSZ + '"><param name="pfont_weight" value="' + EMPFNTWT + '"><param name="pfont_italic" value="' + EMPFNTIT + '"><param name="pfont_name" value="' + EMPFNTNM + '"><param name="use_cv" value="' + EMUSECV + '"><param name="ignore_app" value="0"><param name="autoconnect" value="' + EMAUTOC + '"><param name="proxy_host" value="' + EMPRHOST + '"><param name="proxy_enable" value="' + EMPRENAB + '"><param name="proxy_port" value="' + EMPRPORT + '"><param name="proxy_syntax" value="' + EMPRSNTX + '"><param name="auto_search1" value=""><param name="auto_search2" value=""><param name="proxy_socks_enable" value="' + EMPRSOCK + '"><param name="auto_response1" value=""><param name="auto_response2" value=""><param name="myid" value="MOCHA_TELNET"><param name="proxy_return" value="' + EMPRRTN + '"><param name="blink_cursor" value="' + EMBLKCS + '"><param name="cursortype" value="' + EMCSTYP + '"><param name="local_echo" value="0"><param name="host_echo" value="0"><param name="auto_wrap" value="1"><param name="new_line" value="0"><param name="scroll_bar" value="1"></object>');
}
// ... end from Telnet_Objects

// from restore_telnetemulator
function restore(adminsite) 
{ 
	if (adminsite == "Y") 
	{
		document.inpform.licname.value = "";
		document.inpform.lickey.value = "";
		document.inpform.EMPRENAB.value = "";
		document.inpform.EMSECC.value = "";
		document.inpform.EMAUTOL.value = "";
	}

	document.inpform.width.value = "  950"; 
	document.inpform.height.value = "  650";
	document.inpform.EMOPN.value = "0";
	document.inpform.EMHOST.value = "";
	document.inpform.EMAUTOC.value = "";
	document.inpform.EMUSECV.value = "1";
	document.inpform.EMBLKCS.value = "";
	document.inpform.EMCSTYP.value = "0";
	document.inpform.EMNGTDS.value = "1";
	document.inpform.EMCLBG.value = "16776960       ";
	document.inpform.EMCLCR.value = "8421504        ";
	document.inpform.EMCLSL.value = "128            ";
	document.inpform.EMCLRD.value = "0              ";
	document.inpform.EMFNTNM.value = "Courier New              ";
	document.inpform.EMFNTWT.value = "0";
	document.inpform.EMFNTIT.value = "0";
	document.inpform.EMFNTSZ.value = "80";
	document.inpform.EMPFNTNM.value = "Courier New              ";
	document.inpform.EMPFNTWT.value = "0";
	document.inpform.EMPFNTIT.value = "0";
	document.inpform.EMPFNTSZ.value = "80";
	document.inpform.EMPORT.value = "23";
	document.inpform.EMSSH.value = "";
	document.inpform.EMPRHOST.value = "";
	document.inpform.EMPRPORT.value = "1080";
	document.inpform.EMPRSNTX.value = "$1 $2";
	document.inpform.EMPRSOCK.value = "";
	document.inpform.EMPRRTN.value = "\015\012";
	document.inpform.EMLCLSV.value = "";
	document.inpform.EMKEYS.value = "KEYS.TXT";
}
// end from restore_telnetemulator

// from Emulator_Objects
function load5250(WIDTHA,HEIGHTA,EMLCLSV,licname,lickey,EMHOST,EMPORT,EMSSH,EMDEV,EMAUTOC,EMSECC,EMAUTOL,EMTERM,EMKEYS,EMEBCDIC,EMCLBG,EMCLCR,EMCLSL,EMCLRD,EMCLBL,EMCLPK,EMCLGN,EMCLTQ,EMCLYW,EMCLWH,EMFNTWT,EMFNTIT,EMFNTNM,EMPFNTSZ,EMPFNTWT,EMPFNTIT,EMPFNTNM,EMUSECV,EMPRHOST,EMPRENAB,EMPRPORT,EMPRSNTX,EMPRSOCK,EMPRRTN,EMBLKCS,EMCSTYP,EMTYPAH,EMNGTDS,EMTBLPS,EMBELL,EMHOTSPT,EMSWPDEL,EMMSGBEL,EMCHRSET,EMPCHRST)
{
  jQ('#DivID').html('<object id="MATN5250" classid="CLSID:A6A216EB-4F7C-11D5-8438-0000B456BA3D" codebase="mochasoft/matn5250.cab#version=1,7,0,0" align="center" border="0" width="' + WIDTHA+ '" height="' + HEIGHTA+ '"><param name="localsave" value="' + EMLCLSV+ '"><param name="licname" value="' + licname+ '"><param name="lickey" value="' + lickey+ '"><param name="host_name" value="' + EMHOST+ '"><param name="port" value="' + EMPORT+ '"><param name="ssh" value="' + EMSSH+ '"><param name="devicename" value="' + EMDEV+ '"><param name="autoconnect" value="' + EMAUTOC+ '"><param name="security_connect" value="' + EMSECC+ '"><param name="auto_login" value="' + EMAUTOL+ '"><param name="auto_user" value=""><param name="auto_password" value=""><param name="termtype" value="' + EMTERM+ '"><param name="keys" value="' + EMKEYS + '"><param name="ignore_fer" value="1"><param name="ebcdic" value="' + EMEBCDIC + '"><param name="color_bg" value="' + EMCLBG+ '"><param name="color_cursor" value="' + EMCLCR+ '"><param name="color_select" value="' + EMCLSL+ '"><param name="color_red" value="' + EMCLRD+ '"><param name="color_blue" value="' + EMCLBL+ '"><param name="color_pink" value="' + EMCLPK+ '"><param name="color_green" value="' + EMCLGN+ '"><param name="color_turquoise" value="' + EMCLTQ+ '"><param name="color_yellow" value="' + EMCLYW+ '"><param name="color_white" value="' + EMCLWH+ '"><param name="font_weight" value="' + EMFNTWT+ '"><param name="font_italic" value="' + EMFNTIT+ '"><param name="term_size" value="132"><param name="font_name" value="' + EMFNTNM+ '"><param name="pfontsize" value="' + EMPFNTSZ+ '"><param name="pfont_weight" value="' + EMPFNTWT+ '"><param name="pfont_italic" value="' + EMPFNTIT+ '"><param name="pfont_name" value="' + EMPFNTNM+ '"><param name="use_cv" value="' + EMUSECV+ '"><param name="proxy_host" value="' + EMPRHOST+ '"><param name="proxy_enable" value="' + EMPRENAB+ '"><param name="proxy_port" value="' + EMPRPORT+ '"><param name="proxy_syntax" value="' + EMPRSNTX+ '"><param name="proxy_socks_enable" value="' + EMPRSOCK+ '"><param name="proxy_return" value="' + EMPRRTN+ '"><param name="blink_cursor" value="' + EMBLKCS+ '"><param name="cursortype" value="' + EMCSTYP+ '"><param name="typeahead" value="' + EMTYPAH+ '"><param name="negotiate_display" value="' + EMNGTDS+ '"><param name="tablepaste" value="' + EMTBLPS+ '"><param name="bell" value="' + EMBELL+ '"><param name="hotspots" value="' + EMHOTSPT+ '"><param name="swap_del" value="' + EMSWPDEL+ '"><param name="message_bell" value="' + EMMSGBEL+ '"><param name="charset" value="' + EMCHRSET+ '"><param name="pcharset" value="' + EMPCHRST+ '"></object>');
}
// end from Emulator_Objects

//restore_todo

function restore_todo() 
{ 
	document.inpform.listsize.value = "   20";
	document.inpform.truncdesc.checked = "checked";
	document.inpform.dueflag.checked = "checked";
	document.inpform.dsptopmnu.checked = "checked";
	document.inpform.dspborder.checked = "checked";
}

//end restore_todo

//helper function- HTMLDecode
// written 20080410 by RTC
// removes html formatted characters
function decode_html(htmlstr)
{
  var tempbox =document.createElement("textarea");
  tempbox.innerHTML = htmlstr;
  return tempbox.value;
}

// RTC 20090107: created this function as a replacement for commonly duplicated code
function adjustParent(extrawidth)
{
	if (parent.adjustIFrameSize)
	{
		parent.adjustIFrameSize(window,extrawidth);
	}
}

// begin Emulator_Options
function pagefunc(pageval)
{
	//set page display
	jQ('.pagedsp').hide();
	jQ('#pagedsp'+pageval).show();

	
	//set tab appearance
	jQ('.tab').removeClass('tabsel');
	jQ('#pg'+pageval).addClass('tabsel');

	adjustoptions();
}


function eo_admin(adminsite) 
{ 
    if (adminsite == "Y") 
	{	
		jQ('.admopt').show();
   	} 
	else 
	{
		jQ('.admopt').hide();
    }
}

function eo_write(writeauth) 
{ 
    if (writeauth == "Y") 
	{	
		jQ('.wrtopt').show();
   	} 
	else 
	{
		jQ('.wrtopt').hide();
    }
}

function eo_proxy(adminsite) 
{ 
    if ( jQ('#EMPRENAB')[0].checked) 
	{	
		if (adminsite == "Y") 
		{
			jQ('.proxyopt').show();
		}
   	} 
	else 
	{
		jQ('.proxyopt').hide();
    }
    
    adjustParent();
    parent.adjustParent();
}
// end from Emulator_Options

// Spool-Explorer for the Web
function se_pagefunc(pageval)
{
	//set page display
	jQ('.pagedsp').hide();
	jQ('#pagedsp'+pageval).show();

	
	//set tab appearance
	jQ('.tab').removeClass('tabsel');
	jQ('#pg'+pageval).addClass('tabsel');

	adjustParent();
}

function se_printpage()
{
	document.dyniframe.focus();
	window.print();
}

function se_loadpdf(url)
{

	if (url != "")
	{
		window.open(url,'pdf','dependent,width=465,height=268,left=15,top=45');
		
	}
}

// end Spool-Explorer for the Web

function innovaEdit_Hyperlink_init()
{
	jQ('#srchimg').bind('click',opendoctree7);
}

/// /// /// merge in remaining outside JS files

// nxskins_demo_skin creates a popup window which will show a preview of the skin color, 
// font and banner values currently selected in the nxskins program
function nxskins_demo_skin()
{
	jQ('#task').val('demoskin');
	jQ('#title').val( oEdit1.getHTML() );

	//create the url with the form elements, but escape the values so that
	// they will be properly treated as parm values and not part of the url structure 
	var url = 'NXSKINS.pgm?TASK=demoskin'
	+ '&title=' + escape( jQ('#title').val() ) 
	+ '&SCCLR1=' + escape( '#'+ jQ('#color1').val() )
	+ '&SCCLR2=' + escape( '#'+jQ('#color2').val() )
	+ '&SCCLR3=' + escape( '#'+jQ('#color3').val() )
	+ '&SCCLR4=' + escape( '#'+jQ('#color4').val() )
	+ '&SCCLR5=' + escape( '#'+jQ('#color5').val() )
	+ '&SCCLR6=' + escape( '#'+jQ('#color6').val() )
	+ '&SCCLR7=' + escape( '#'+jQ('#color7').val() )
	+ '&SCCLR8=' + escape( '#'+jQ('#color8').val() )
	+ '&SCCLR9=' + escape( '#'+jQ('#color9').val() )
	+ '&SCCLR10=' + escape( '#'+jQ('#color10').val() )
	+ '&SCCLR11=' + escape( '#'+jQ('#color11').val() )
	+ '&SCCLR12=' + escape( '#'+jQ('#color12').val() )
	+ '&SCCLR13=' + escape( '#'+jQ('#color13').val() )
	+ '&SCCLR14=' + escape( '#'+jQ('#color14').val() )
	+ '&SCCLR15=' + escape( '#'+jQ('#color15').val() )
	+ '&SCCLR16=' + escape( '#'+jQ('#color16').val() )
	+ '&SCCLR17=' + escape( '#'+jQ('#color17').val() )
	+ '&SCCLR18=' + escape( '#'+jQ('#color18').val() )
	+ '&SCCLR19=' + escape( '#'+jQ('#color19').val() )
	+ '&SCCLR20=' + escape( '#'+jQ('#color20').val() )
	+ '&SCCLR21=' + escape( '#'+jQ('#color21').val() )
	+ '&SCCLR22=' + escape( '#'+jQ('#color22').val() )
	+ '&SCCLR23=' + escape( '#'+jQ('#color23').val() )
	+ '&SCCLR24=' + escape( '#'+jQ('#color24').val() )
	+ '&SCFNT1=' + escape( jQ('#SCFNT1').val() )
	+ '&SCFNT2=' + escape( jQ('#SCFNT2').val() )
	+ '&SCFNTSZ1=' + escape( jQ('#fontsize1').val() )
	+ '&SCFNTSZ2=' + escape( jQ('#fontsize2').val() )
	+ '&SCTIFR=' + jQ('#SCTIFR').val() + "&rndnum=" + Math.random();

	popupWin = window.open(url ,'demo_window','dependent,scrollbars=1,resizable=1,width=650,height=500,top=45,left=15');
}

//configure the search interface presented by nxdocsrch2
function nxdocsrch2_advsrchdisp() 
{ 
   	jQ('#advsearch').attr('disabled',false);
   	jQ('#allowsrch').attr('disabled',false);
   	jQ('#useand').attr('disabled',false);
   	
   	//if( jQ('#advsearch').val() != "")
	if (document.forms[0].advsearch.checked) 
 	{	
		jQ('#opt20').show();
		jQ('#allowsrch').attr('disabled',true);
   	} 
	else 
	{
		jQ('#opt20').hide();
		jQ('#useand').attr('disabled',true);
   	}

	//if( jQ('#allowsrch').val() != "")
	if (document.forms[0].allowsrch.checked) 
	{	
		jQ('#advsearch').attr('disabled',true);
   	} 

	//if( jQ('#allowsrch').val() != "" && jQ('#advsearch').val() != "")
	if (document.forms[0].allowsrch.checked && document.forms[0].advsearch.checked)
	{
		jQ('#advsearch').attr('disabled', false);
		jQ('#allowsrch').attr('disabled', false);
   	} 

}

// control visibility of the key/pair 
function nxdocsrch2_keypairdisp() 
{ 
	//if ( jQ('#rstrctkey').val() != "")
	if (document.forms[0].rstrctkey.checked) 
	{	
		jQ('#opt21').show();
   	} 
	else 
	{
		jQ('#opt21').hide();
    }
}

function showkvp(allowkv)
{
	if (allowkv == "Y")
	{
		jQ('#allowkv2').show();
	}
	else
	{
		jQ('#allowkv2').hide();
	}
}

//show key value panel
function nxdocsrch2_showkvp(allowkv, optkv)
{
	if (allowkv == "Y")
	{
		allowkv1.style.display = "";
		if (optkv == "Y")
		{
			optkv1.style.display = "";
		} 
		else 
		{
			optkv1.style.display = "none";
		}
	} 
	else 
	{
		allowkv1.style.display = "none";
	}
}

// show key value panel 3
function nxdocsrch2_showkvp3(allowkv)
{
	if (allowkv == "Y")
	{
		jQ('#allowkv1').show();
		jQ('#allowkv2').show();
   	} 
	else 
	{
		jQ('#allowkv1').hide();
		jQ('#allowkv2').hide();
    }
}

//show key value panel 2
function nxdocsrch2_showkvp2()
{
	if (document.forms[0].allowkv.checked)
	{
		jQ('#allowkv1').show();
		jQ('#allowkv2').show();
   	} 
	else 
	{
		jQ('#allowkv1').hide();
		jQ('#allowkv2').hide();
    }
}

/* RTC 20090409: couldnt find any of these used anywhere...
function addvalue() 
{
	document.inpform.srchkeys.value = document.inpform.srchkeys.value + " " + document.inpform.kvpairs.value+"=";
}

function nxdocsrch2_addvalue() 
{
	jQ('#searchstr2').val( jQ('#searchstr2').val() + " " + jQ('#kvpairs').val()+ "=" );
}
	
function nxdocsrch2_addvalue2() 
{
	jQ('#appsrchstr').val( jQ('#appsrchstr').val() + " " + jQ('#kvpairs2').val()+ "=" );
}
*/

//changes form element and display text to reference specified ECM tree node values
// this is typically used by a popup window to return information to the parent program
function setPlaceIn(textdsp, nodenum)
{
	jQ('#nodename').val(textdsp);
	jQ('#wnode').val(nodenum);
}

function colchange()
{
	clearcol();
	column();
	adjustoptions();
}

//control optionally displayed element visibility in nxdocsrch
//TEH 20090911 - Displayed done inline now
/*
function nxdocsrch_optdisp(allowsrch, authflg, advview, allowkv, advsearch) 
{ 
	if (allowsrch == "Y") 
	{
		jQ('#optbox2').show();
		jQ('#allowkv1').show();
	} 

	if (advview == "Y") 
	{
		jQ('#advopt1').show();
		jQ('#advopt2').show();
		jQ('#advopt3').show();
	} 

	if (advsearch == "Y") 
	{
		jQ('#searchdsp').show();
		jQ('#searchdsp2').show();
	}
}
*/

function nxdocsrch_searchtips(ev)
{
	var toppos = ev.screenY + 15;
	var position = 'dependent,scrollbars=1,resizable=1,height=400,width=400,left=' + ev.screenX + ',top=' + toppos;
	window.open('/nexuspublic/help/searchtipshelp.htm','searchtips',position);
}
function nxdocsrch_requestAdd()
{
	var url = jQ('#additem').val();
	window.open(url, 'open_window', 'scrollbars=1,resizable=1,height=750,width=1000,left=50,top=50');
}

function nxwlnks_lnksoptdisplay()
{
	jQ('#url').hide();
	jQ('#wow').hide();
	jQ('#urltext').hide();

	if (document.inpform.lntype.options[document.inpform.lntype.selectedIndex].value == "Folder")
	{
		jQ('#url').hide();
		jQ('#wow').hide();
		jQ('#urltext').hide();
		jQ('target').hide();
	}
	else
	{
		if (document.inpform.lntype.options[document.inpform.lntype.selectedIndex].value == "ECM Document")
		{ 
			jQ('#wow').show();
			document.inpform.LNTRGT.selectedIndex = 2;
		}
		else
		{
			jQ('#url').show();
			jQ('#urltext').show();
		}

		jQ('#target').show();
	}


	if (document.inpform.mopt.value == 2)
	{
		jQ('#group').hide();
	}
	else
	{
		jQ('#group').hide();
	}
}

//enter change program for a clicked menu element (nxmnumnt)
function changeMenu(ev)
{
	//substring the rrn off the id of the event element (in form chglnk####)
	var lnkrrn = ev.target.id.substring(6); 
	location.href = 'nxmnumnt.pgm?task=chg&currrn='+lnkrrn+'&rnd='+Math.random();
}

//edit authorities for a clicked menu element (nxmnumnt)
function editMenuAuths(ev)
{
	//substring the rrn off the id of the event element (in form authlnk####)
	var lnkrrn = ev.target.id.substring(7);
	loadmnuauth(lnkrrn,ev);

}

//request delete of a clicked menu element (nxmnumnt)
function deleteMenu(ev)
{
	//substring the rrn off the id of the event element (in form dellnk####)
	var lnkrrn = ev.target.id.substring(6);
	location.href = 'nxmnumnt.pgm?task=del&currrn='+lnkrrn+'<field name=currrn>&rnd='+Math.random();
}

//edit authorities for a clicked menu item element (nxmnumnt - change menu)
function editItemAuths(ev)
{
	//get the rrn from the id of the clicked element (in format itmauth####)
	var lnkrrn = ev.target.id.substring(7); 
	loadmnuitauth(lnkrrn, ev);
}

// prevents form submission on enter and instead entered data with javascript
function nxmsg_handleEnter(ev)
{
	if(ev.keyCode == 13)
	{
		sendmsg();
		return false;
	}
	return true;
}

function nxpopups_clearform()
{
	document.formfilt.filter1.value = "";
	document.formfilt.filtera.value = "";
	document.formfilt.submit();
}

function nxpopups_clearformG()
{
	document.formfilt.filter5.value = "";
	document.formfilt.submit();
}

function nxtodo_cnfclose(mybox, viewby) 
{
	if (viewby == 'C')
	{
		var userinput = confirm('Click OK to open this task, Cancel to return to list.');
	}
	else
	{
		var userinput = confirm('Click OK to close this task, Cancel to return to list.');
	}

	// Ok - change value of the hidden form element tdcose to value of checkbox
	// and submit the form named closeform.
	if(userinput)
	{ 
		document.closeform.tdcose.value= mybox.value;
		document.closeform.submit(); 
	}
	else // Cancel - uncheck the checked box and return. 
	{
		mybox.checked = false; 
	}
}

function nxtodo_CrtDepWindow(task, instance, tdcose) 
{
	mypage=  'nxtodo.pgm?task=' + task + '&instance=' + instance+ '&tdcose='+ tdcose;

	popupWin = window.open(mypage,   'open_window',
	'dependent,width=650,height=350,left=200,top=45');
}

function nxtodo_redir()
{	
	document.redirform.submit();  
}

function nxtodo_redir2()
{	
	document.reloadlst.submit();  
}

function nxtodo_enterHandler(ev)
{
	if (ev.keyCode == 13)
	{
		//check that the body content isnt too long
		jQ('#taskdesc2').val( oEdit1.getHTMLBody() );		
		if ( jQ('#taskdesc2').val().length > 30000)
		{
			alert('The body content length (' + jQ('#taskdesc2').val().length + ') exceeds the available space of 30000');
			return;
		}

		//submit the form
		document.inpform.submit();	
	
		return false;
	}
}

function nxwrkkey_selected() 
{
	document.inpform.task.value = "updselect";
	document.inpform.submit();
}

function nxwrkkey_restricted() 
{
	document.inpform.task.value = "updrestrict";
	document.inpform.submit();
}

function nxwrkkey_globe() 
{
	document.inpform.task.value = "updglobal";
	document.inpform.submit();
}

function openwindow(url)
{
	window.open(url); 
}


function nxwsite_smgulodisplay()
{
	if (document.forms[0].smgulo.checked)
	{
		jQ('#logindrpbox').show();
	} 
	else {
		jQ('#logindrpbox').hide();
	}
}

function nxwsite_smalmedisplay()
{
	if (document.forms[0].smalme.checked)
	{
		jQ('#pwdhelpoptions').show();
	} 
	else {
		jQ('#pwdhelpoptions').hide();
	}
}

//controls iframe loading and tabbing for the messaging for the web portlet
function mftw_loadtab(tabnumber)
{
	var url,frameid;

	//load or refresh the iframe for the specified tab
	switch(tabnumber)
	{
		case 2 : 	url = 'NXMSG.pgm?task=nexusmsg';
					frameid = '#nexusmsgframe';
					break;
		case 3 :    url = 'NXMSG.pgm?task=nexussent'
					frameid = '#nexussentframe';
					break;
		case 4 : 	url = 'NXMSG.pgm?task=iseriesmsg';
					frameid = '#iseriesframe';
					break;
		case 5 :    url = 'NXMSG.pgm?task=friendlist';
					frameid = '#contactframe';
					break;
		default:
	}	
	
	url += '&instance=' + jQ('#instance').val() + "&rnd=" + Math.random();
	jQ(frameid)[0].src = url;

	//control the tab paging to update which tab is selected and show that tab's contents	
	pagefunc(tabnumber);
}

//nxskins

function nxskins_sizefont()
{
	var font = document.inpform.SCFNT1.options[document.inpform.SCFNT1.selectedIndex].value;
	var fontsize = document.inpform.SCFNTSZ1.value;
	var font2 = document.inpform.SCFNT2.options[document.inpform.SCFNT2.selectedIndex].value;
	var fontsize2 = document.inpform.SCFNTSZ2.value;


	jQ('#clrtable').css('fontFamily', font);
	jQ('#portlet').css('fontFamily', font);
	jQ('#wdw').css('fontFamily', font);
	jQ('#wdwheader').css('fontFamily', font2);
	jQ('#row1').css('fontFamily', font);
	jQ('#row2').css('fontFamily', font);
	jQ('#row3').css('fontFamily', font);
	jQ('#row4').css('fontFamily', font);
	jQ('#portlethdr').css('fontFamily', font2);
	jQ('#links').css('fontFamily', font);
	jQ('#linkhover').css('fontFamily', font);
	jQ('#title').css('fontFamily', font2);
	jQ('#title2').css('fontFamily', font2);
	jQ('#menuheader').css('fontFamily', font2);
	jQ('#menus').css('fontFamily', font);
	jQ('#menuhover').css('fontFamily', font);
	jQ('#banner').css('fontFamily', font2);
	jQ('#').css('fontFamily', font);
	
	jQ('#clrtable').css('fontSize', fontsize);
	jQ('#portlet').css('fontSize', fontsize);
	jQ('#wdw').css('fontSize', fontsize);
	jQ('#row1').css('fontSize', fontsize);
	jQ('#row2').css('fontSize', fontsize);	
	jQ('#row3').css('fontSize', fontsize);
	jQ('#row4').css('fontSize', fontsize);
	jQ('#wdwheader').css('fontSize', fontsize2);
	jQ('#portlethdr').css('fontSize', fontsize2);
	jQ('#links').css('fontSize', fontsize);
	jQ('#linkhover').css('fontSize', fontsize);
	jQ('#title').css('fontSize', fontsize2);
	jQ('#title2').css('fontSize', fontsize2);
	jQ('#menuheader').css('fontSize', fontsize2);
	jQ('#menus').css('fontSize', fontsize);
	jQ('#menuhover').css('fontSize', fontsize);
	jQ('#banner').css('fontSize', fontsize2);
}
function nxskins_setColors() 
{ 
	jQ('#clrtable').css('background', '#' + document.inpform.SCCLR1.value);
	jQ('#portlet').css('background', '#' + document.inpform.SCCLR2.value);
	jQ('#wdw').css('background', '#' + document.inpform.SCCLR3.value);
	jQ('#wdw').css('border', 'thin solid ' + '#' +  document.inpform.SCCLR4.value);
	jQ('#portlet').css('border', 'thin solid ' +  '#' + document.inpform.SCCLR4.value);
	jQ('#portlethdr').css('background', '#' + document.inpform.SCCLR4.value);
	jQ('#links').css('color','#' +  document.inpform.SCCLR5.value);

	jQ('#row1').css('background','#' +  document.inpform.SCCLR6.value);
	jQ('#row3').css('background', '#' + document.inpform.SCCLR6.value);
	jQ('#row2').css('background', '#' + document.inpform.SCCLR7.value);
	jQ('#row4').css('background', '#' + document.inpform.SCCLR7.value);

	jQ('#row1').css('color', '#' + document.inpform.SCCLR16.value);
	jQ('#row2').css('color','#' +  document.inpform.SCCLR16.value);
	jQ('#row3').css('color','#' +  document.inpform.SCCLR16.value);
	jQ('#row4').css('color', '#' + document.inpform.SCCLR16.value);
	jQ('#text1').css('color', '#' + document.inpform.SCCLR16.value);
	jQ('#titletext1').css('color', '#' + document.inpform.SCCLR20.value);
	jQ('#titletext2').css('color','#' +  document.inpform.SCCLR21.value);
	jQ('#control').css('color','#' +  document.inpform.SCCLR19.value);


	jQ('#title').css('background', '#' + document.inpform.SCCLR8.value);
	jQ('#title2').css('background', '#' + document.inpform.SCCLR13.value);
	jQ('#menuheader').css('background', '#' + document.inpform.SCCLR9.value);

	jQ('#menus').css('background', '#' + document.inpform.SCCLR10.value);
	jQ('#menuhover').css('background', '#' + document.inpform.SCCLR11.value);
	jQ('#menus').css('color', '#' + document.inpform.SCCLR18.value);
	jQ('#menuhover').css('color', '#' + document.inpform.SCCLR18.value);


	jQ('#tab').css('background', '#' + document.inpform.SCCLR22.value);
	jQ('#tab').css('color', '#' + document.inpform.SCCLR24.value);
	jQ('#seltab').css('color', '#' + document.inpform.SCCLR23.value);
	jQ('#seltab').css('background','#' +  document.inpform.SCCLR22.value);

	jQ('#menus').css('color', '#' + document.inpform.SCCLR18.value);
	jQ('#menuhover').css('color','#' +  document.inpform.SCCLR18.value);


	jQ('#headertext').css('color', '#' + document.inpform.SCCLR12.value);

	jQ('#linkhover').css('color', '#' + document.inpform.SCCLR5.value);
	jQ('#linkhover').css('background','#' +  document.inpform.SCCLR14.value);

	jQ('#banner').css('background', '#' + document.inpform.SCCLR15.value);
	jQ('#bannertext').css('color', '#' + document.inpform.SCCLR17.value);

	nxskins_sizefont();
}

// attempt to close the preview window when exiting the change skin screen
function nxskins_unloaddemo()
{
	try
	{
		if(popupWin)
		{
			popupWin.close();
		}
	}
	catch(err) {}
}

//attaches jQuery color pickers to elements
function attachColorPickers()
{
	jQ('.colorinput').each( function() 
	{
		var elemid = this.id;
		
		jQ(this).ColorPicker(
		{
			onSubmit: function(hsb, hex, rgb, el)
			{
				jQ(el).val(hex);
				jQ(el).ColorPickerHide();
			},
			onBeforeShow: function ()
			{
				jQ(this).ColorPickerSetColor( jQ(this).val());
			},
			onChange: function(hsb,hex,rgb)
			{ 
				jQ('#'+elemid).val(hex);
				nxskins_setColors();
			}
		});
	});
}
