//////////////////////////////////////////////////////////////////////////////
//
// Common.js
//
// Copyright (c) 2003 by iManage, Inc.  All Rights Reserved
//
//////////////////////////////////////////////////////////////////////////////
//
// DESCRIPTION:
// 	Various client-side utility functions
//

var IMAN_DATA_DELIMITOR = "{}";
var IMAN_DATA_TERMINATOR = "[]";
var k2K = 2000

var kDescLookupLength = 15;

var DefaultNamespace = "x-schema:../includes/iwpl.xml";

function iManageEnums() {
	// Access rights
	this.nrRightNone = 0
	this.nrRightRead = 1
	this.nrRightReadWrite = 2
	this.nrRightAll = 3

	// Page Access rights	
	this.nrNoAccess = this.nrRightNone
	this.nrReviewerAccess = this.nrRightRead
	this.nrContributorAccess = this.nrRightReadWrite
	this.nrEditorAccess = this.nrRightAll
	
	// Default Security
	this.nrPrivate = 88
	this.nrPublic = 80
	this.nrView = 86
	this.nrInherit = 73
}

var iEnums = new iManageEnums()

function BrowseTreeNodeEnums() {
	var obj = new Object()
	
	obj.None			= 0x00000000
	obj.Explorer		= 0x00000001
	obj.Worklist		= 0x00000002
	obj.CheckedOut		= 0x00000004
	obj.Database		= 0x00000008
	obj.VF_Pages		= 0x00000010
	obj.VF_Folders		= 0x00000020
	obj.Subscription	= 0x00000040
	obj.Workspace		= 0x00000080
	obj.Folder			= 0x00000100
	obj.Search			= 0x00000200
	obj.Calendar		= 0x00000400
	obj.Discussion		= 0x00000800
	obj.Tasks			= 0x00001000
	obj.Document		= 0x00002000
	//			= 0x00004000
	//			= 0x00008000
	//			= 0x00010000
	obj.Tab				= 0x00020000
	obj.Item			= 0x00040000
	obj.Favorites		= 0x00080000
	obj.RecentWorkspaces = 0x00100000
	obj.PageSearch		= 0x00200000 
	obj.WorkArea		= 0x00400000
	obj.Shortcut		= 0x00800000

	obj.All				= 0x7FFFFFFF

	obj.WorkspaceContents	= obj.Workspace | obj.Tab | obj.Item | obj.Folder | obj.Document | 
								obj.Calendar | obj.Discussion | obj.Tasks | 
								obj.Shortcut | obj.Favorites | obj.Worklist | obj.CheckedOut | 
								obj.Search | obj.PageSearch | obj.Subscription

	obj.WorkspaceParents	= obj.WorkArea | obj.Explorer | obj.Database | obj.VF_Pages| obj.Workspace | 
								obj.RecentWorkspaces | obj.Folder | obj.Shortcut | obj.Subscription | obj.Favorites
								
	obj.FolderParents		= obj.WorkspaceParents | obj.Workspace | obj.Tab | obj.Folder | obj.Search | obj.VF_Folders
	
	obj.DocumentParents		= obj.FolderParents | obj.Worklist | obj.CheckedOut | obj.Search

	obj.FolderLink			= obj.WorkArea | obj.Worklist | obj.CheckedOut | obj.Database | 
								obj.VF_Pages | obj.VF_Folders | obj.Folder | obj.Search | obj.Shortcut
								
	obj.FolderLinkParents	= obj.FolderLink | obj.FolderParents
								 
	
	return obj
}

function ruleEngineEnums () {
	var obj = new Object()
	obj.keyOwner = "%owner%"
	
	obj.formatText = 0
	obj.formatHtml = 1
	
	obj.eventAdd = 15
	obj.eventRemove = 16
	obj.eventVersion = 11
	
	return obj
}

var reEnums = ruleEngineEnums()

function ConnectorFeatures() {
	var obj = new Object()
	
	obj.InstanceOptions = 1
	obj.UserOptions = 2
	obj.GlobalOptions = 4
	obj.Processable = 8
	obj.AllOptions = obj.InstanceOptions | obj.UserOptions | obj.GlobalOptions
	
	return obj
}

//Replace the delimitor for multiple look up result.
function ReplaceDelimitor(val) {	
	return val.replace(new RegExp(IMAN_DATA_DELIMITOR,"ig"), ",");
}

function DocumentTarget() {
	var obj = new Object()
	
	obj.SameWindow = 0
	obj.Frame = 1
	obj.NewWindow = 2
	
	return obj
}

// Suite options
var kSuiteDocFolder = 1
var kSuiteConnector = 2
var kSuiteColaboration = 4
var kSuiteEWork = 8 
var kSuiteAutonomy = 16

// Page types
var kTempPageType = "temp"
var kAdminPageType = "admin"
var kStartPageType = "start"
var kNavigationPageType = "navigation"
var kWorkPageType = "work"
var kPrefsPageType = "preferences"
var kTemplatePageType = "template"
var kConnectorPageType = "connector"
var kBrowsePageType = "browse"
var ResourcesAlias = "_resource"

var kMultiOpSeparator = "^"

var kBrowseWndHt = 400
var kBrowseWndWd = 440

function openTag(tag, content) { return '<' + tag + ' ' + content + ' >' }
function closeTag(tag) { return '</' + tag + '>' }

window.disposeAdvise = window_disposeAdvise

function window_disposeAdvise(funcObj) {
	if ( window.disposeListeners ) {
		window.disposeListeners[window.disposeListeners.length] = funcObj
	} else {
		window.disposeListeners = new Array(funcObj)
	}
}

window.onunload = window_onunload

function window_onunload() {
	if ( window.disposeListeners ) {
		for(var i = 0; i < 	window.disposeListeners.length; ++i ) {
			var listener = window.disposeListeners[i]
			if ( typeof(listener) == "function" ) {
				listener()
			} else if ( typeof(listener) == "string" ) {
				eval(listener)
			}
		}
	}
}

window.onloadAdvise = window_onloadAdvise
function window_onloadAdvise(funcObj) {
	if ( window.onloadListeners ) {
		window.onloadListeners[window.onloadListeners.length] = funcObj
	} else {
		window.onloadListeners = new Array(funcObj)
	}
}

window.onload = window_onload
function window_onload() {
	if ( window.onloadListeners ) {
		for(var i = 0; i < 	window.onloadListeners.length; ++i ) {
			var listener = window.onloadListeners[i]
			if ( typeof(listener) == "function" ) {
				listener()
			} else if ( typeof(listener) == "string" ) {
				eval(listener)
			}
		}
	}
}

document.onkeydown = document_onkeydown
function document_onkeydown()
{
	if ( event.keyCode == 116 )
	{
		setCookie("keyCode", event.keyCode, 1)
	}
	else
	{
		setCookie("keyCode", '', -1)
	}
}

function skipToContent() {
	window.location.replace("#content-area")
}

if ( getCookie("debug", "profile") ) {
	var startTime = new Date()
	window.onloadAdvise("alert(new Date() - startTime)")
}


function jumpToExpandedItem() {
	var item = getCookie("expandedItem","item")
	if(item != "" ) {
		window.location.replace("#"+item+"_anchor")
	}
	setCookie("expandedItem","item=")
}

window.onloadAdvise(jumpToExpandedItem)

function _versionControlObj(ServerSetting, ClientSetting, IsLatest, CanCheckout, CanCheckin, CanLock, CanUnlock,CanReplace, CanNewVersion,CanNewDoc, CurrentUser,IsCheckedOut)
{
	this.ServerSetting = ServerSetting
	this.ClientSetting = ClientSetting
	this.IsLatest = IsLatest
	this.CanCheckout = CanCheckout
	this.CanCheckin = CanCheckin
	this.CanLock = CanLock
	this.CanUnlock = CanUnlock
	this.CanReplace = CanReplace
	this.CanNewVersion = CanNewVersion
	this.CanNewDocument = CanNewDoc
	this.CurrentUser = CurrentUser
	this.IsCheckedOut = IsCheckedOut ;
}

function _document(nrtid, database, number, version, defaultName, extension, path, isCompound, vcObj,editDate)
{
	this.nrtid = nrtid
	this.database = database
	this.number = number
	this.version = version
	this.defaultName = defaultName
	this.extension = extension
	this.path = path
	this.IsCompound = isCompound
	this.VCObject = vcObj
	this.editDate = editDate
}

function setFocusOnFirstItem(form) {
	if (!form) return
	var firstObj = null 
	if (form) {
		var elements = form.elements
		for (var i=0; i< elements.length; i++) {
			var item =elements[i]
			var type = item.type
			var isRightType = (type == "text" || type == "textarea" || type=="file" || type=="password")
			var canGetFocus = ( (!g_browser.isNS4) ? (!item.disabled) : true)
			if (type != "hidden" && canGetFocus) {
				if (!firstObj) {
					firstObj = item
				}
			}
			if (isRightType && canGetFocus) {
				item.focus()
				return
			}
		}
		if (firstObj) {
			firstObj.focus()
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////
// standard API for netscape
///////////////////////////////////////////////////////////////////////////////////

// BrowserInfo object
function Browser() {
/*
	Properties:
		isIE:	is Internet Explorer;
		isNS6:	is Netscape 6 and above;
		isNS4:  is Netscape 4.x;
		isNav:	is Netscape browser;
		isMac:	is Macintosh machine;
		isWin:  is Windows machine;
		isIE5:  is Internet Explorer 5.0*;
		isIE55: is Internet Explorer 5.5;
*/	
	 this.isIE	= (document.all)? true : false
	 this.isNS6 = (document.implementation && document.implementation.createDocument) ? true : false
	 this.isNS4 = (navigator.userAgent.toUpperCase().indexOf("MOZILLA/4.79") > -1) || (navigator.userAgent.toUpperCase().indexOf("MOZILLA/4.8") > -1)
	 this.isNav = this.isNS6 || this.isNS4
	 this.isMac = (navigator.userAgent.indexOf("Macintosh") > -1)
	 this.isWin = !this.isMac	 
	 this.isIE5 = (navigator.userAgent.indexOf("MSIE 5.0") > -1)
	 this.isIE55 = (navigator.userAgent.indexOf("MSIE 5.5") > -1)
}

g_browser = new Browser()

var kComplete = 'complete'
var kInComplete = 'incomplete'
var locationHRef = window.location.href

if ( g_browser.isNav ) {
	document.readyState = kInComplete
} 

function attachment(url, title, imgSrc) {
	this.url = url
	this.title = title
	this.imgSrc = imgSrc
	this.AttStr = '|' + this.url + ';' + this.title + ';' + this.imgSrc + '|'
}
				
function getStyleObject(obj){
	var theObj
	if ( typeof obj == "string" ){
		if ( g_browser.isNS4 ) {
			theObj = window.document.ids[obj]
		} else {
			theObj = window.document.getElementById(obj).style
		}
	} else {
		theObj = obj
	}
	return theObj
}

function getAppletById(id) {
	if ( g_browser.isNS4 ) {
		return document.applets[id]
	} else {
		return document.getElementById(id)
	}
}

function addOptionItem(selObj, val, text, select) 
{
	var options = selObj.options
	var valUpper = val.toUpperCase();
	for (var i = 0; i < options.length; i++) 
	{
		if ( options[i].value.toUpperCase() == valUpper) 
		{
			if ( select )
			{
				selObj.selectedIndex = i
			}
			return
		}
	}
	options[options.length] = new Option(text, val)
	if ( select )
	{
		selObj.selectedIndex = options.length - 1
	}
}

function clearSelectObjOpitons (selObj, nth) 
{
	if ( !nth ) 
	{
		nth = 0
	}
	while (selObj.options.length > nth) 
	{
		selObj.options[selObj.options.length -1] = null
	}
}

///////////////////////////////////////////////////////////////////////////////////
// standard API for netscape END
///////////////////////////////////////////////////////////////////////////////////

var undefined = 0

function getCookie(name, item) {
	var arg = name.toUpperCase() + "="
	var alen = arg.length
	var clen = document.cookie.length
	var i = 0
	while (i < clen) {
		var j = i + alen
		if (document.cookie.substring(i, j).toUpperCase() == arg) {
			var cEnd = document.cookie.indexOf(";",j)
			if (cEnd == -1) {
				cEnd = document.cookie.length
			}
			var cookie = unescape(document.cookie.substring(j, cEnd))
			if (item != null) { // Find item
				arg = item.toUpperCase() + "="
				alen = arg.length
				clen = cookie.length
				i = 0
				while (i < clen) {
					j = i + alen
					if (cookie.substring(i, j).toUpperCase() == arg) {
						cEnd = cookie.indexOf("&",j)
						if (cEnd == -1) {
							cEnd = cookie.length
						}
						cookie = cookie.substring(j, cEnd)
						return unescape(cookie)
					} else {
						i = cookie.indexOf("&", i) + 1
						if (i == 0) return ""
					}
				}	
			}
			return unescape(cookie)
		} else {
			i = document.cookie.indexOf(" ", i) + 1
			if (i == 0) break;
		}
	}
	return ""
}

function setCookie(name, value, expireDays,path) {
	var pair = name + "=" + escape(value)
	if (expireDays) {
		var expires = new Date()
		var expTime = expires.getTime() + (expireDays * 86400000)
		expires.setTime(expTime)
		pair += "; expires=" + expires.toGMTString()
	}
	if (path) {
		pair += "; path=" + path
	} else {
		/*
		var docpath= document.location.pathname
		var position = docpath.indexOf("/",1)
		if (position >0) {
			docpath=docpath.substring(0,position)
			pair += "; path=" + docpath
		}
		*/
		pair += "; path=" + "/"
	}
	document.cookie = pair
}
	
function getParam(name) {
	var query = window.location.search
	var arg = name + "="
	var alen = arg.length
	var qlen = query.length
	var i = query.indexOf("?") + 1
	while (i < qlen) {
		var j = i + alen
		if (query.substring(i, j) == arg) {
			var cEnd = query.indexOf("&",j)
			if (cEnd == -1) {
				cEnd = query.length
			}
			return unescape(query.substring(j, cEnd))
		} else {
			i = query.indexOf("&", i) + 1
			if (i == 0) break;
		}
	}
	return ""
}

function javaString(str) {
	// This add's backslashes to any single || double quotes
	if ( str ) {
		str = str.replace(/\s/g, " ")
		str = str.replace(/\\/g, "\\\\")
		str = str.replace(/\'/g, "\\\'")
		str = str.replace(/\"/g, "\\\"")
		return str
	} else {
		return ''
	}
}
		
function htmlString(str) {
	// This HTML escapes the string

	if ( str ) {
		str = str.replace(/&/g, "&amp;")
		str = str.replace(/\'/g, "&#39;")
		str = str.replace(/\"/g, "&quot;")
		str = str.replace(/</g, "&lt;")
		str = str.replace(/>/g, "&gt;")
		return str
	} else {
		return ''
	}
}

function htmlDeString(str) {
	// This HTML unescapes the string

	if ( str ) {
		str = str.replace(/&#39;/gi, "\'")
		str = str.replace(/&quot;/gi, "\"")
		str = str.replace(/&lt;/gi, "<")
		str = str.replace(/&gt;/gi, ">")
		str = str.replace(/&amp;/gi, "&")
		return str
	} else {
		return ''
	}
}

function rTrim(str) 
{ 
	return str.replace(/\s+$/, "")
} 

function lTrim(str) 
{
	return str.replace(/\s*/, "") 
} 

function trim(str) 
{
	return str.replace(/\s*(.*\S)\s*$/, "$1") 
} 

function getURLParam(url, param) {
	// This extracts a named param
	
	var value
	
	var index = url.indexOf(param + "=")
	if (index >= 0) {
		var start
		if (index == 0) {
			start = param.length + 1
		} else {
			var priorChar = url.charAt(index-1)
			if (priorChar == '&' || priorChar == '?') {
				start = index + param.length + 1
			}
		}
		
		if (start) {
			var end = url.indexOf("&", start)
			if (end < 0) {
				end = url.length
			}
			value = url.slice(start, end)
		}
	}
	
	return unescape(value)
}

function setURLParam(url, param, value) {
	// This sets a named param
	
	var index = url.indexOf("?" + param + "=")
	if (index < 0) {
		index = url.indexOf("&" + param + "=")
			}

	if (index > 0) {
		var start = index + 1
			var end = url.indexOf("&", start)
			if (end < 0) {
				end = url.length
			}
			value = url.slice(0, start) + param + "=" + value + url.slice(end)
	} else {
		value = appendURLParam(url, param, value)
	}
	
	return value
}

function clientToAsp(id) {
	id = id ? id : "clientToAspApplet"

	var domObj = document.getElementById(id)
	if ( domObj ) {
		return domObj;
	}
	
	var htmlStr = "<div id='" + id + "'></div>"
	document.writeln(htmlStr)
	
	domObj = document.getElementById(id)
	
	//Note: We had added following variable to make sure every request is unique,because XMLHTTP caches similar requests : SJ
	domObj.globalIndex = (new Date()).valueOf()
	domObj.hasError = false;
	domObj.errorMessage = "";
	
	domObj.getData = clientToAsp_getData
	domObj.clearError = clientToAsp_clearError
	domObj.isAccessGranted = clientToAsp_isAccessGranted
	domObj.putData = clientToAsp_putData 
	domObj.checkResult = clientToAsp_checkResult	
	domObj.getDataByPost = clientToAsp_getDataByPost
	
	return domObj;
}
 function clientToAsp_getData(url) 
 {
 	this.clearError();

	url = setURLParam(url, "xmlFormat", "1")
	url = setURLParam(url, "globleindex", this.globalIndex++)
	var result = ""
	var requestObj = g_browser.isIE ? (new ActiveXObject("Microsoft.XMLHTTP")) : (new XMLHttpRequest())
	//if url is pointing to an xml directly, we may need create an ASP
	//file to handle it.

	if(url.length > k2K) {
		alert(parseAndLocalizeStr("{1155|Please reduce the number of Selected Items}"))
		return
	}
	
	
	requestObj.open("GET",url,false)
	requestObj.send(null);
	var dataNode = requestObj.responseXML && requestObj.responseXML.documentElement ? requestObj.responseXML.documentElement.firstChild : null
	if (dataNode) {
		result = dataNode.nodeValue
		this.checkResult(result);					
	}
	return result;
}

function clientToAsp_clearError() 
{ 
	this.hasError = false; 
	this.errorMessage = "";
}

function clientToAsp_isAccessGranted() 
{ 
	return true;
}
	
function clientToAsp_putData(url) 
{
 	this.clearError();
	url = setURLParam(url, "xmlFormat", "1")
	url = setURLParam(url, "globleindex", this.globalIndex++)
	var requestObj = null
	requestObj = g_browser.isIE ? (new ActiveXObject("Microsoft.XMLHTTP")) : (new XMLHttpRequest())

	if(url.length > k2K) {
		alert(parseAndLocalizeStr("{1155|Please reduce the number of Selected Items}"))
		return
	}

	requestObj.open("GET",url,false)
	requestObj.send(null)
}
	
function clientToAsp_checkResult(result) 
{
	if ( result ){
		var indexError = result.indexOf(IMAN_DATA_DELIMITOR)
		if (indexError > 0) {
			this.hasError = result.substring(0,indexError).toUpperCase() == "ERROR:";
		}
		if (this.hasError) {
			this.errorMessage = result.substring(indexError + IMAN_DATA_DELIMITOR.length);
		}
	}
}
	
function clientToAsp_getDataByPost(url, body) 
{
 	this.clearError();
	body += (body ? "&" : '') + "xmlFormat=1"
	var result = ""
	var requestObj = g_browser.isIE ? (new ActiveXObject("Microsoft.XMLHTTP")) : (new XMLHttpRequest())

	if(url.length > k2K) {
		alert(parseAndLocalizeStr("{1155|Please reduce the number of Selected Items}"))
		return
	}

	requestObj.open("POST", url, false)
	requestObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
	requestObj.send(body)

	var dataNode = requestObj.responseXML && requestObj.responseXML.documentElement ? requestObj.responseXML.documentElement.firstChild : null
	if (dataNode) {
		result = dataNode.nodeValue
		this.checkResult(result);
	}
	return result;
}

function writeClientToAsp(id,locale) {
	var applet = getAppletById("clientToAspApplet")
	if(!applet)
	{	
		id = id ? id : "clientToAspApplet"
		if (g_browser.isNS4) {
			var htmlStr = '<applet archive="iManage.jar" code="gridapplet/clientToAsp.class" width="1" height="1" id="' + id +'" name="' + id +'" codebase="../includes" MAYSCRIPT="true">'
					+'	<param name="cabbase" value="iManage.cab"/>'
			  		+'	<param name="locale" value="' + locale +'"/>'
					+'</applet>'
			document.writeln(htmlStr)
		}else {
			var cl = new clientToAsp(id)
		}
	}
}

function isMonikerEqualIgnoreServerName(id1,id2) {
	return getMonikerInfo(id1,"database") == getMonikerInfo(id2,"database") && getMonikerInfo(id1,"page") == getMonikerInfo(id2,"page")
}

function getMonikerInfo(id,name) {
	//return the moniker part without any session information.
	var result = ""
	if (id)	{
		var oid = id.toUpperCase()
		if (!name) {
			result = id
		}else {
			var oname= name.toUpperCase()
			var posStart = oid.indexOf("!" +oname + ":")
			if (posStart > -1) {
				var nid = oid.substr(posStart + oname.length + 2)
				var posEnd = nid.indexOf(":")
				if (posEnd > 0) {
					result = nid.substring(0,posEnd)
				}
			}			
		}
	}
	return result
}

function appendURLParam(url, param, value) {
	if (url.indexOf("?") < 0) {
		url = url + "?"
		} else {
		url =  url + "&"
	}
	url += param + "=" + value
	
	return url
}

function sortColumn(id, column, element, view, description) {
	/*
		Now that we no longer store cached pages, we must resubmit hidden forms after processing
		the sort.  Therefore, we are using clientToAsp to perform the sort, and then the form
		with hidden variables gets resubmitted so that the sort can re-execute.
	*/	
	if (!description) {
		description = ""
	}
	setCookie(window.name + "Offset", document.body.scrollLeft + "," + document.body.scrollTop, 0)
	var redirect = escape(window.page.getRedirect())

	/*
		var url = "../scripts/Sort.aspx?page=" + page.id + "&id=" + id + "&column=" + column + "&element=" + element + "&view=" + view + "&description=" + description + "&redirect=" + redirect
		window.location = url
	*/
	var pageid = ""
	var applet = getAppletById('clientToAspApplet')
	if (document.forms["fm"])
	{
		var parent = document.forms["fm"].elements["page"]
		if (parent)
		{
			//use the form variable if present
			pageid =  document.forms["fm"].elements["page"].value 
		}
		else
		{
			pageid = ResourcesAlias
		}
	}
	else
	{
		pageid = page.id
	}
	var url = "../scripts/Sort.aspx?page=" + escape(pageid) + "&id=" + escape(id) + "&column=" + escape(column) + "&element=" + escape(element) + "&view=" + escape(view) + "&description=" + escape(description) //+ "&redirect=" + redirect

	var data = applet.getData(url)
	data = data ? String(data) : ""
	
	if (data.length > 0) {
		locAlert(data)
		return
	}
	
	if (document.forms["fm"])
	{
		
		if ( element == "tasks" || element == "events" )
		{
			var cmd = document.getElementById ('command');
			if (cmd != null ) 
			{
				document.fm.command.hidden = false 
				document.fm.command.value = "save"
			
				var  viewElement = document.getElementById ('view')
				if ( viewElement != null )
				{
					if ( element == "tasks")
						viewElement.value = "tasksearch"
					if ( element == "events")
						viewElement.value = "eventsearch"
					
				} 
				
			}
		}
			
		document.forms["fm"].submit()
	}
	else
	{
		window.location = unescape(redirect)
	}
}

function eWorkSort(columnName,order,tabID,itemID,type)
{ 
	var url = "../scripts/Home.aspx?page="+ escape(page.id) +"&columnName="+ escape(columnName) +"&order="+ escape(order);
	if(itemID)
	{
		url = url + "&id="+ escape(itemID) +"&tabid="+ escape(tabID) +"&eworkType="+ escape(type); 
	}
	window.location = url 
}

function browseLookUpCallBack(window, cmd, nrtid, id, title, img, href, context)
{
	var paramArray = context.split(",")
	var formName = paramArray[0]
	var fieldName = paramArray[1]
	var form = document.forms[formName]
	if (form) {
		var controlObj = document.forms[formName].elements["p-" + fieldName]
		if(controlObj) {
			controlObj.value =  nrtid
			controlObj.focus()
		}
	}		
	window.close()
}

function doBrowseDlgLookup(attributeID, parentName, title, formName, fieldName, dependents, isSearch,callBackFn) {
	callBackFn = callBackFn ? callBackFn: "browseLookUpCallBack"
	var btnEnums = BrowseTreeNodeEnums()
	var context = formName + "," + fieldName
	var select = btnEnums.Folder | btnEnums.Workspace | btnEnums.Tab
	var pageId = page.type != "temp" ? page.id : ""
	var url = 'BrowseDlg.aspx?title=' + escape(getLocStrByLID(617, 'Select+Folder')) + '&callback='+callBackFn+'&context=' + context + '&filter=' + btnEnums.FolderParents  + '&select=' + select + "&page=" + pageId
	var height = page.type != "temp" ? kBrowseWndHt+ 50 : kBrowseWndHt  
	var wnd = openWindow(url, 'browseWnd', kBrowseWndWd, height, '')
}


function doLookup(attributeID, parentName, title, formName, fieldName, dependents, isSearch,callBackFn) 
{
	if(fieldName == "search-for") {
		return
	}else if(fieldName == "container-id") {
		doBrowseDlgLookup(attributeID, parentName, title, formName, fieldName, dependents, isSearch,callBackFn)	
		return
	}
		
	var form = document.forms[formName]
	var parentValue = ""
	title = escape(parseAndLocalizeStr(title))
	
	if (form) {		    
		var parentValue = ""
		var parent = document.forms[formName].elements["p-" + parentName]

		//var parent = document.getElementById("p-" + parentName)
		if (parent) 
		{			
			if (parent.type == "select-one") 
			{
				parentValue = parent.options[parent.selectedIndex].value
			} 
			else 
			{
				parentValue = parent.value
			}		
		}
		// Get database name, if any
		var databaseName = ""
		var databaseField = document.forms[formName].elements["p-databases"]			
		if (databaseField)
		{			    
			var selected = ""
			//there is no good way to know if the selection is single or multiple, and hence I need to iterate thru the
			//options collections.
			var bMultiple = false
			for(var j=0; j<databaseField.length ;j++) 
			{
					selected = databaseField.options[j].selected
					if (!bMultiple)
					{
						if (selected)
						{
							bMultiple = true
							databaseName = databaseField.options[j].value
							//alert(databaseName)
						}
					}
					else
					{
						if(selected)
						{
							databaseName = ""
							break;
						}
					}
			}
		}
		else
		{
			databaseName = getDatabaseValueforLookup(formName)
		}
		
		databaseName = databaseName.indexOf(",") >=0 ? "" : databaseName
		var params = formName + "," + fieldName + "," + dependents
		isSearch = isSearch ? isSearch : ""
		callBackFn = callBackFn ? callBackFn: "lookupCallback"
		//var lookupApp = document.getElementById("lookupApplet")
		title = title.replace(/%20/g," ")
		if (g_browser.isNS4) 
		{
			var lookupApp =getAppletById("lookupApplet")		
			lookupApp.setLookupType(attributeID, this,callBackFn , String(parentValue), title, params, databaseName, isSearch)
		}
		else 
		{
			var domObject = document.getElementById("lookupApplet")
			var scriptName = domObject.getAttribute("scriptName");
			var url = virtualPath() + "/scripts/lookupDialog.aspx?"
			var querryString = "id=lookup_" + attributeID +
							"&title=" + escape(title) +
							"&scriptName=" + escape(scriptName) +
							"&type=" + attributeID +
							"&parentString=" + escape(String(parentValue)) +
							"&functionName=" + callBackFn +
							"&textFieldId=" + params +
							"&database=" + databaseName+
							"&isSearch=" + isSearch 
			url +=querryString
			var winObj= openWindow(url,"", 430, 300, "scrollbars=no")
		}
	}
}

function doGroupRoleMgmtLookup(itemId, dbName, lookupType)
{
	title = escape(parseAndLocalizeStr("{511|Add User}"))

	//var callBackFn = callBackFn ? callBackFn: "lookupCallback"
	title = title.replace(/%20/g," ")
	if (g_browser.isNS4) {
		var lookupApp =getAppletById("lookupApplet")		
		lookupApp.setLookupType(attributeID, this,callBackFn , String(parentValue), title, params, databaseName, isSearch)
	}else {
		
		var domObject = document.getElementById("lookupApplet")
		var scriptName = domObject.getAttribute("scriptName");
		var url = virtualPath() + "/scripts/lookupDialog.aspx?"
		var querryString = "id=lookup_group" +
						"&title=" + escape(title) +
						"&scriptName=" + escape(scriptName + "?isGrpRoleMgmt=1") +
						"&type=" + lookupType +
						"&parentString=" +
						"&functionName=grpRoleMgmtCallback" +
						"&textFieldId=" + escape(itemId) + "," + dbName + "," + lookupType +
						"&database=" + dbName +
						"&isSearch=1"
		url +=querryString
		
		var winObj= openWindow(url,"", 430, 300, "scrollbars=no")
	}
}

function grpRoleMgmtCallback(id, name, itemId)
{
	var redirect = escape(page.getRedirect());
	window.location.href = virtualPath() + "/scripts/XManagement.aspx?command=add&userid="+id+"&xid="+itemId.split(",")[0]+"&database=" + itemId.split(",")[1] + "&container=" + itemId.split(",")[2] + "&redirect=" + redirect
}

function removeUserFromGrpRole(id, containerId, database, container, multiselectID)
{
	if (multiselectID)
	{
		id = new NRTItems(multiselectID).getItems()
	}
	var redirect = escape(page.getRedirect());
	window.location.href = virtualPath() + "/scripts/XManagement.aspx?command=remove&userid="+id+"&xid="+containerId+"&database=" + database+"&container="+container+"&redirect="+redirect
}

function writeLookupApplet(id,scriptName,locale) {
	var htmlStr = ""
	if (g_browser.isNS4) {
		htmlStr +='<applet archive="iManage.jar" code="Picker/NRLookUp.class" width="1" height="1" id="' +id +'" name="'+ id + '"  MAYSCRIPT="true"  codebase="../includes" viewastext="1">' 
			  	+ '	<param name="cabbase" value="iManage.cab"/>'
			  	+ '	<param name="scriptName" value="' + scriptName +'"/>'
			  	+ '	<param name="locale" value="' + locale +'"/>'																				
				+ '</applet>'
	}else {
		htmlStr = '<lookupNode id="' + id + '" scriptName="' + scriptName + '"/>'
	}
	document.write(htmlStr);

}
		
function lookupCallback(alias, description, params) {	
	alias = ReplaceDelimitor(alias);
	description = ReplaceDelimitor(description)
	var paramArray = params.split(",")
	var formName = paramArray[0]
	var fieldName = paramArray[1]
	var dependents = paramArray[2]
	var form = document.forms[formName]
	if (form) {
		var controlObj = document.forms[formName].elements["p-" + fieldName]
		var exitingValue = controlObj.value
		//TODO: to allow multiple selection for search, we may want to have a window scoped
		//variable indicate if the lookup is for a search criteria and append the alias to
		//any existing value
		//controlObj.value = (exitingValue ? (exitingValue + "," + alias) : alias)
		controlObj.value = alias
		controlObj.focus()

		//fix for 31376:  display description for all validated custom fields (c1-c12, c29-c30) (NS, 2/9/05)
		var span 
		if (g_browser.isIE) {
			span = document.getElementById("s-" + fieldName)
			if (span) {
				span.innerText = description.length > kDescLookupLength ? description.substring(0, kDescLookupLength) + "..." : description
			}
		}	
		var descField = document.forms[formName].elements[fieldName + "Desc"]
		if (descField) {
			descField.value = description
		}
		
		clearDependents(formName, dependents)
		if ( window.location.href.toLowerCase().indexOf("docprofile.aspx") >= 0 && (fieldName == "class" || fieldName == "subclass")) {
			updateRequiredFields(formName)
		}
	}
}  
 
function copySecLookupCallBack(alias, description, params){
	alias = ReplaceDelimitor(alias);
	description = ReplaceDelimitor(description);
	var paramArray = params.split(",")
	var formName = paramArray[0]
	var fieldName = paramArray[1]
	var dependents = paramArray[2]
	var form = document.forms[formName]
	if (form) {
		var controlObj = document.forms[formName].elements["p-" + fieldName]		
		controlObj.value = alias
		controlObj.focus()
		//document.getElementById("p-" + fieldName).value = alias
		//var span = document.forms[formName].elements["s-" + fieldName]
		var span 
		var descField = document.forms[formName].elements[fieldName + "Desc"]
		if (descField) {
			descField.value = description
		}
		clearDependents(formName, dependents)		
	}
} 
 
function onSelectChange(formName, name, dependents, updateRequired) {
	var form = document.forms[formName]
	if (form) {
		var select = form.elements["p-" + name]
		if (select) {
			var title
			var selectedIndex = select.selectedIndex
			if (selectedIndex >= 0) {
				var option = select.options[selectedIndex]
				var title = option.getAttribute("title")
			}
			if (!title) {
				title = ""
			}
			if ( document.getElementById ) {
				var span = document.getElementById("s-" + name)
				if (span) {
					span.innerText = title
				}
			}
			clearDependents(formName, dependents)
			if (updateRequired && (name == "class" || name == "subclass")) {
				updateRequiredFields(formName)
			}
		}
	}
}

function updateRequiredFields(formName) {
	var form = document.forms[formName]
	if (form) {
		// we dont need to validates fields for folder profileing : SJ
		if(form.isFolderProfile && form.isFolderProfile.value=="1") {
			return
		}
		var className = form.elements["p-class"] ? form.elements["p-class"].value : ""
		var subclassName = form.elements["p-subclass"] ? form.elements["p-subclass"].value : ""
		var databaseName = form.elements["p-database"] ? form.elements["p-database"].value : ""
		var pDatabaseName = form.elements["pdatabase"] ? form.elements["pdatabase"].value : ""
		var url = virtualPath() + "/scripts/GetRequired.aspx?class=" + escape(className) + "&subclass=" + escape(subclassName) + "&database=" + escape(databaseName ? databaseName : pDatabaseName)
		var applet = getAppletById('clientToAspApplet')
		var data = applet.getData(url)
		data = data ? String(data) : ""
		if (data.substring(0, 6) == "Error:") {
			locAlert(data)
			return
		}
		for (ii=0; ii < form.elements.length; ii++) {
			var element = form.elements[ii]
			var name = element.name
			if (name.substring(0, 2) == "p-") {
				name = name.slice(2)
				var img = document.images[name + "-img"]
				var pos = data.search("," + name + ",")
				if (pos >= 0) {
					if (img) {
						img.src = virtualPath() + "/images/RequiredInd.gif"
						img.title = img.alt = getLocStrByLID(81,"Required Field")
					}
					if ( element.setAttribute ) {
						element.setAttribute("required", "1")
					}
				} else {
					if (img) {
						img.src = virtualPath() + "/images/BlankIcon.gif"
						img.title = img.alt = ""
					}
					if ( element.setAttribute ) {
					
						element.setAttribute("required", "0")
					}
				}
			}
		}
	}
}

function validateProfileFields(formName) {
	var valid = true
	var form = document.forms[formName]
	if (form) {
		for (i=0; i < form.elements.length && valid; i++) {
			var element = form.elements[i]			
			if ( element.getAttribute && element.getAttribute("required") == "1" ) {
				var value = getFieldValue(form, element.name)
				if (value.length == 0) {
					locAlert(getLocalizedString("882|Values must be entered for all required profile fields."))
					valid = false
				}
			}
		}
	}
	
	return valid
}

function validateSearchFields(formName) {
	var valid = true
	var form = document.forms[formName]
	if (form) {
		var database = getFieldValue(form,"p-database")
		var commentQuery = getFieldValue(form, "p-comment")
		var fullTextQuery = getFieldValue(form, "p-full-text")
		if (commentQuery.length > 0 && fullTextQuery.length > 0) {
			locAlert(getLocalizedString("883|Searching on both the comments and full text cannot be done simultaneously."))
			valid = false
		}				
		form.redirect.value = page.getRedirect();
	}
	
	return valid
}

function clearSearch(formName) {
	var form = document.forms[formName]
	if (form) {
		for (ii=0; ii < form.elements.length; ii++) {
			var element = form.elements[ii]
			if ((element.name.substring(0,2) == "p-") && !element.readOnly) {
				var fieldName = element.name.substring(2, element.name.length)
				if (element.tagName == "INPUT") {
					if (element.type == "text") {
						element.value = ""
					} else if (element.type == "hidden") {
						var dateSel = form.elements["sel-p-" + fieldName]
						if (dateSel) {
							dateSel.selectedIndex = 0
							dateSel.onchange()
						}
					}
				} else if (element.tagName == "SELECT") {
					element.selectedIndex = -1
				} else if (element.tagName == "TEXTAREA") {
					element.value == ""
				}
				var span = document.getElementById("s-" + fieldName)
				if (span) {
					span.innerText = ""
				}
				var descField = form.elements[fieldName + "Desc"]
				if (descField) {
					descField.value = ""
				}
			}
		}
	}
}

function getFieldValue(form, fieldName) {
	var value = ""
	var field = form.elements[fieldName]
	if (field) {
		if (field.type == "select-one") {
			if (field.selectedIndex >= 0) {
				value = field.options[field.selectedIndex].value
			}
		} else {
			value = field.value
		}
	}
	
	return value
}
			
function writeSelect(formName, name, attributeID, parentName, isSearch, defaultValue) {
	// alert("onSelectFocus(name=" + name + ", attributeID=" + attributeID + ", parent=" + parent + ")")	
	var form = document.forms[formName]
	if (form) {
		var select = form.elements["p-" + name]
		if (select) {
			var populated = select.getAttribute("populated")
			if (!populated || populated == "0") {				
				select.options.length = 0
				// Get options
				var parentValue = ""
				if (parentName) {
					var parent = form.elements["p-" + parentName]
					if (parent) {
						if (parent.type == "select-one") {
							parentValue = parent.options[parent.selectedIndex].value
						} else {
							parentValue = parent.value
						}
					}
				}
				// Get database name, if any
				var databaseName = ""
				var databaseField = form.elements["p-database"]
			    if(!databaseField) {
					databaseField = form.elements["pdatabase"]							    
			    }			
				if (databaseField) {
					databaseName = databaseField.value
				}
				isSearch = isSearch ? isSearch : ""
				var applet = getAppletById("clientToAspApplet")
				var url = virtualPath() + "/scripts/GetLookup.aspx?lookupType=" + attributeID + "&searchString=&parentString=" + parentValue + "&database=" + databaseName + "&isSearch=" + isSearch
				var data = applet.getData(url)				
				populateSelect(select, data, defaultValue)
			}
		}
	}
}
			
function populateSelect(select, data, selectedValue) {
	//alert("populateSelect")
	if (data.substring(0, 6) == "Error:") {
		locAlert(data)
		return
	}
	var dataArray = data.split(IMAN_DATA_TERMINATOR)
	dataArray.sort()
	select.options.length = 0
	var count = 0
	var option = new Option("", "")
	option.setAttribute("title", "")
	select.options[count++] = option
	for (var ii = 0; ii < dataArray.length; ii++) {
		var dataPair = dataArray[ii]
		var end = dataPair.indexOf(IMAN_DATA_DELIMITOR)
		if (end > 0) {
			var alias = dataPair.substring(0, end)
			var description = dataPair.substring(end + 1, dataPair.length)
			// alert("alias = " + alias + ", description = " + description)
			option = new Option(alias, alias)
			option.setAttribute("title", description)
			select.options[count] = option
			if ((selectedValue != null) && (selectedValue == alias)) {
				select.options[count].selected = true
				selectedValue = null
			}
			count++
		}
	}
	select.setAttribute("populated", "1")
}

function onChangeValidated(name) {
	if ( document.getElementById ) {
		var span = document.getElementById("s-" + name)
		if (span) {
			span.innerText = ""
		}
	}
}

function clearDependents(formName, dependents) {
	var form = document.forms[formName]
	if (form && dependents) {
		var dependent = form.elements["p-" + dependents]
		if (dependent) {
			if (dependent.type == "select-one") {
				dependent.options.length = 0
				dependent.setAttribute("populated", "0")
			} else {
				dependent.value = ""
			}
			if ( document.getElementById ) {
				span = document.getElementById("s-" + dependents)
				if (span) {
					span.innerText = ""
				}
			}
		}
	}
}

function centralize(Sr, Pl, Pw, Dw) {
	return Math.max(0, Math.min(Sr - Dw, (Math.max(0, Pl) + Math.min(Sr, Pl + Pw) - Dw) / 2))
}

function openWindow(sURL, sName, nWidth, nHeight, sFeatures) {
// wraps around 'window.open' and centralizes the new window based on its opener window
// usage:  var wnd = openWindow("Page.htm", "page name", 400, 400, "resizable=1")
	if(sURL.length > k2K) {
		alert(parseAndLocalizeStr("{1155|Please reduce the number of Selected Items}"))
		return
	}
	sFeatures = getWindowCenterOptions(nWidth, nHeight)  + (sFeatures ? ("," + sFeatures) : "") 
	if (g_browser.isNS6) {
		sFeatures = "modal" + (sFeatures ? ("," + sFeatures): "") 
	}
	if (g_browser.isIE) {
		return window.open(sURL, sName, sFeatures)
	} else {
		return window.open(sURL, sName, sFeatures)
	}
	
	

}

function getWindowCenterOptions(nWidth, nHeight) {
	var sFeatures
	var nLeft, nTop
	
	if ( g_browser.isNav ) {
		nLeft = centralize(screen.availWidth, window.screenX, window.outerWidth, nWidth  )
		nTop = centralize(screen.availHeight, window.screenY, window.outerHeight, nHeight)
		sFeatures = "screenY=" + nTop + ",screenX=" + nLeft + ",outerWidth=" + nWidth + ",outerHeight=" + nHeight
	} else { 
		nLeft = centralize(screen.availWidth, window.screenLeft, window.document.body.offsetWidth, nWidth + 10) // 10 is a magic number
		nTop = centralize(screen.availHeight, window.screenTop, window.document.body.offsetHeight, nHeight + 29)	// 29 is another magic number
		sFeatures = "top=" + nTop + ",left=" + nLeft + ",width=" + nWidth + ",height=" + nHeight
	}
	
	return sFeatures
}

function download(nrtids) 
{
	var nrtidArr = nrtids.split(kMultiOpSeparator)
	if( g_browser.isIE && document.WebTransferCtrl ){
		for (var i = 0; i < nrtids.length; i++) {
			var nrtid = nrtidArr[i]
			if (!nrtid) continue
			var destURL = document.location.pathname
			var ctrl = document.WebTransferCtrl
			var temp = destURL.slice(0, destURL.lastIndexOf("/"))
			ctrl.DestinationURL = temp.slice(0, temp.lastIndexOf("/")+1) + "scripts/ViewDoc.aspx"
			
			ctrl.SessionID =  document.cookie
			ctrl.NrtID = nrtid
			ctrl.Server = document.location.hostname 
			if (document.location.port) {
				ctrl.Port = parseInt(document.location.port)
			}
			ctrl.Protocol = document.location.protocol
			ctrl.Download() 
		}
	}else {
		clearFileItems("TransferClient")
		for (var i = 0; i < nrtids.length; i++) {
			var nrtid = nrtidArr[i]
			if (!nrtid) continue
			var url = "../scripts/ViewDoc.aspx?nrtid=" + nrtid + "&command=ok"
			// viewFile("TransferClient", "../scripts/ViewDoc.aspx?nrtid=" + nrtid + "&command=ok")
			document.TransferClient.addTransferItem('','',url)
		}
		startView("TransferClient");
	}
}

function downloadEx(nrtid, documentOption, overrideDocumentTarget) 
{
	var clientToAsp = getAppletById("clientToAspApplet");
	if ( clientToAsp ) 
	{
		var data = clientToAsp.getData(virtualPath() + "/scripts/getDocProps.aspx?nrtid=" + escape(nrtid)) + "";
		if ( ! clientToAsp.hasError && data ) 
		{
			eval(data + ";");
			if ( docProps.archived )
			{
				return;
			}
			nrtid = docProps.nrtid; 
			switch ( documentOption ) 
			{
				case "view":
					if ( typeof(overrideDocumentTarget) == 'undefined' )
					{
						overrideDocumentTarget = docProps.documentTarget
					}
					switch ( overrideDocumentTarget )
					{
						case DocumentTarget().Frame:
							if ( docProps.url )
							{
								window.location.href = virtualPath()+ "/scripts/redirector.aspx?url=" + escape(docProps.url);
							}
							else
							{
								window.location.href = virtualPath()+ "/scripts/redirector.aspx?nrtid=" + escape(nrtid);
							}
							break;
							
						case DocumentTarget().NewWindow:
							if ( docProps.url )
							{
								window.open(docProps.url);
							}
							else
							{
								downloadExView(nrtid);
							}
							break;
					}
					break;
					
				case "viewHTML":
					downloadExViewHTML(nrtid);
					break;
				
				case "checkOut":	
					downloadExCheckOut(nrtid);
					break;
					
				case "profile":
					downloadExProfile(nrtid);		
					break;
				
				case "portable":
					downloadExPortable(nrtid);
					break;
			}
		} 
		else 
		{
			locAlert(clientToAsp.errorMessage);
		}
	}
}

function downloadExView(nrtid, script, action, path, open, duedate, comments, portable,editDate) 
{  
	if ( g_browser.isIE && document.WebTransferCtrl )
	{
		script = script ? script : "ViewDoc.aspx"
		action = action ? action : 3
		open = open ? open : 1
		duedate = duedate ? duedate : ""
		comments = comments ? comments : ""
		path = path ? path : ""
		portable = portable ? portable : "0"
		editDate = editDate ? editDate: ""
		url = virtualPath()+ "/scripts/ProgressBar.aspx?nrtid=" + escape(nrtid) + "&script=" + escape(script) + "&action=" + action + "&open=" + open + "&duedate=" + escape(duedate) + "&comments=" + escape(comments) + "&path=" + escape(path) + "&portable=" + portable 
		if ( editDate != "")
			url = url + "&editDate=" + editDate
		var wnd = openWindow(url, "Progressbar", 400, 100, "")	
	} 
	else 
	{
		viewFile("TransferClient", "../scripts/ViewDoc.aspx?nrtid=" + escape(nrtid) + "&command=ok")
	}
}
function downloadExViewHTML(nrtid) 
{  	
	if ( g_browser.isIE && document.WebTransferCtrl )
	{
		openAsHTML(nrtid)				
	} 
	else 
	{					
		viewFile("TransferClient", "../scripts/ViewDoc.aspx?nrtid=" + escape(nrtid) + "&command=ok&isHTML=1")
	}
}
	
function downloadExCheckOut(nrtid) 
{  	
	var clientToAsp = getAppletById("ClientToAspApplet");
	var data = clientToAsp.getData(virtualPath()+ "/scripts/viewDoc.aspx?command=informationonly&nrtid=" + escape(nrtid)) + "";
	var docInfo;
	if ( data.length > 0 ) 
	{
		docInfo = eval(data);
	}
	if ( ! docInfo )
	{
		return;
	}
	if (docInfo.VCObject.IsCheckedOut )
	{
		locAlert(getLocalizedString("1162|The file is already checked out."));
		return ;
	}
	if ( docInfo.VCObject.CanCheckout != 1 ) {
		locAlert(getLocalizedString("1374|Action Checkout cannot be Performed. \nSelect View to open document"));
		return ;
	}
	window.location.href = virtualPath()+ "/scripts/Checkout.aspx?nrtid=" + escape(nrtid) + "&redirect=" + escape(page.getRedirect())
}

function downloadExProfile(nrtid) 
{  	
	window.location.href = virtualPath()+ "/scripts/getDoc.aspx?nrtid=" + escape(nrtid) + "&redirect=" + escape(page.getRedirect())
}

function downloadExPortable(nrtid) 
{  	
	var clientToAsp = getAppletById("ClientToAspApplet");
	var data = clientToAsp.getData(virtualPath()+ "/scripts/viewDoc.aspx?command=informationonly&nrtid=" + escape(nrtid)) + "";
	var docInfo;
	if ( data.length > 0 ) 
	{
		docInfo = eval(data);
	}
	if ( ! docInfo )
	{
		return;
	}
	if (docInfo.VCObject.IsCheckedOut )
	{
		locAlert(getLocalizedString("1162|The file is already checked out."));
		return ;
	}
	if ( docInfo.VCObject.CanCheckout != 1 ) {
		locAlert(getLocalizedString("1374|Action Checkout cannot be Performed. \nSelect View to open document"));
		return ;
	}
	var myPath = document.WebTransferCtrl.GetPortableFilePath(docInfo.database, docInfo.VCObject.CurrentUser, docInfo.number, docInfo.version, docInfo.extension);
	//The original WebTransferCtrl does not provide the about GetPortableFilePath method and it
	//use the following properties to prepare the right paths for both the file itself and the PRF file.
	//Since the PRF file path is still needed, so the following code is required. BX.
	document.WebTransferCtrl.DocNum  = docInfo.number
	document.WebTransferCtrl.Version  = docInfo.version
	document.WebTransferCtrl.Database  = docInfo.database
	document.WebTransferCtrl.UserID  = docInfo.VCObject.CurrentUser
	document.WebTransferCtrl.Extension  = docInfo.extension
	document.WebTransferCtrl.PortableCheckout = true
	if (!document.WebTransferCtrl.OpenByThirdParty(nrtid) ) {
		if (docInfo.IsCompound == "1") {
			url = virtualPath() + "/scripts/Checkout.aspx?nrtid=" + nrtid
			url = setURLParam(url, "redirect", page.getRedirect())					
			url = setURLParam(url, "PortableCheckOut", "on")
			url = setURLParam(url,"open", "1")				
			window.location.href = url
		}else {
			var url = virtualPath() + "/scripts/ProgressBar.aspx?nrtid=" + nrtid + "&script=Checkout.aspx&action=0&open=1&path=" + myPath + "&portable=1&refreshParent=1"
			var wnd = openWindow(url, "Progressbar", 400, 100, "")
		}
	}
}
					
function writeItemHeader(id, title, imgSrc, expand, menu,params, noTitle,adHocSearch) {	
	var expandLink, zoomLink, closeLink, altImgStr;
	var style, btnImg,locString
	var expandId = id.replace(/-/gi, "_")	// NS4 stuff

	imgSrc = imgSrc ? imgSrc : "pixel.gif"
	altImgStr = getAltImgText(imgSrc)
	var themeRoot = getThemeRoot()
	title = checkLength(title, 40)
	
	if ( expand == "0" ) {
		style = (g_browser.isIE ? 'display:none;':'')+'populated:0;originalid:' + id 
		btnImg = 'item-header-collapsed.gif'
		locString = '{668|Expand section:  }'
	} else {
		style = (g_browser.isIE ? 'display:block;':'')+'populated:1;originalid:' + id 
		btnImg = 'item-header-expanded.gif'
		locString = '{540|Collapse section:  }'
	}
			
	if ( page.zoomed == "0") {
		var href = "javascript:toggleExpand(\'" + expandId + "\',\'" + javaString(title) + "\')"
		expandLink = '<a  class="item-header-bar" href="'+ href +'" title="'+parseAndLocalizeStr(locString)+title+'">'
		zoomLink = '<a  class="item-header-bar" href="' + setURLParam(page.getRedirect(), "id", id) + '">'
		closeLink = '</a>'
	} else { 
		expandLink = zoomLink = closeLink = ''
	}
	if (!noTitle) {
		html = '\n' +
				'<a name="'+expandId+'_anchor">' +
				'<table width="100%" border="0" cellspacing="0" cellpadding="0">\n' +
					'<tr> \n' +
					'<td width="1%" nowrap align="left">' +
					'<img src="'+themeRoot+'/images/item-header-left-corner.gif" width="6" height="24" border="0"></td>' +
					'<td width="1%" align="left" valign="top">' +
						'<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr>' +
						'	<td colspan="5" class="item-header-border"><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>' +
						'</tr>' +
						'<tr>'+
						'<td width="1%">'
					if (menu) {
						// to check whether to show menu & expand collapse link ? can we check some other param instead of "menu" ????
						if (page.zoomed == "0") {
							html += expandLink +'<img id="grouping_' +  expandId + '" src="'+themeRoot+'/images/'+btnImg+'" width="16" height="16"  border="0" alt="'+parseAndLocalizeStr(locString)+title+'">' + closeLink 
						}else {
							var expandImg = themeRoot + (getCookie("enable508Menus") == "1" ? '/images/pixel.gif' : '/images/item-header-always-expanded.gif')
							html += expandLink +'<img id="grouping_' +  expandId + '" src="' + expandImg + '" width="16" height="16"  border="0" alt="">' + closeLink 
						}	
					}					
						html+= '</td>\n'
						
						imgSrc = imgSrc.substring(0,1) == "/" ? imgSrc  : "../images/" + imgSrc
						html +=	'<td class="item-header-bar" width="1%"><img src="'+themeRoot+'/images/pixel.gif" width="2" height="22" alt="" border="0"></td>\n' +
						 		'<td class="item-header-bar" width="1%"><img src="' + imgSrc + '" alt="' + altImgStr + '" width="16" height="16" alt="" border="0"></td>\n' +
									'<td class="item-header-bar" width="1%"><img src="'+themeRoot+'/images/pixel.gif" width="2" height="22" alt="" border="0"></td>\n' +
									'<td class="item-header-bar" nowrap>'	 
										+ zoomLink 
											+ title
										+ closeLink + '\n' +
									'</td>\n' +
						'</tr>' +
					'<tr>' +
						'<td colspan="5" class="item-header-border" valign="bottom" ><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>'+
					'</tr>'	+			
					'</table>' +
				'</td>' +
					'<td class="item-header-background" nowrap align="right">\n' +
							'<img src="'+themeRoot+'/images/pixel.gif" width="62" height="24" alt="" border="0">' +
					'</td>\n' +
					'<td  nowrap align="right" width="95%">\n' +
						'<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr>' +
						'	<td colspan="2" class="item-header-border"><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>' +
						'</tr>' +
						'<tr>'+
						'<td class="item-header-menu-bar" width="1%"><img src="'+themeRoot+'/images/pixel.gif" width="1" height="22" alt="" border="0"></td>\n' +
						'<td class="item-header-menu-bar"  width="1%" align="right">' +
							( menu ? writeActionMenus("{523|Action}", "big", menu,true,params,title,imgSrc, noTitle) : "&nbsp;") + '\n' +
						'</td>\n' +
						'</tr>' +
						'<tr>' +
							'<td colspan="2" class="item-header-border" valign="bottom" ><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>'+
						'</tr>'	+			
					'</table>' +
					'</td>' +
					'<td  nowrap align="left"><img src="'+themeRoot+'/images/item-header-right-corner.gif" width="6" height="24" border="0"></td>' +
					'</tr>\n' 					
					if(adHocSearch == true)
					{
						html += '<tr class="container">\n' +
							'<td colspan="5" align="center"><a href = "javascript:toggleExpandAdhocSearch(\'' + expandId + '\',\'' + javaString(title) + '\',this)"	>' + htmlString(parseAndLocalizeStr("{1401|Click here to toggle search parameters screen}")) + '</a>'  + '</td>\n' +							
						'</tr>\n'					
					}
			html += '</table>'
	}else {
		//no header if user is not owner or admin
		html = '\n'
		if(page.access == iEnums.nrEditorAccess) {
			html = 	'<table width="100%" border="0" cellspacing="0" cellpadding="0">\n' +
					'<tr> \n' +
						'<td nowrap align="right">\n' +
						( menu ? writeActionMenus("{523|Action}", "small", menu,false,params,title,imgSrc, noTitle) : "&nbsp;") + '\n' +
						'</td>\n' +
					'</tr>\n' +
			'</table>' 
		}
		
	}
	html += '<div id="' + expandId + '" style="' + style + '">'	
	document.write(html)
}

function writeMultiActionMenus(menu,id,nrtid,hideChkBox) {
	var params
	var menuName = 'menu_' + (window.g_menuid++)
	var hRef=""
	var onClick =  menu ? htmlString('return showMenu(&quot;' + menu +'&quot;,&quot;'+ menuName+'&quot;,&quot;'+ params+'&quot;)') : ""
	var imgURL='<img ' +(g_browser.isIE ? '' :'name="' + menuName + '" ')+' border="0" src="'+virtualPath()+'/images/menuarrow.gif" width="9" height="9" align="absmiddle" />'
	var root = virtualPath()
	var cls =  'action-button-big' 
	var str = '<table class="multi-form-header" cellpadding="1" cellspacing="0" width="100%" border="0" >'
		str+='<tr>'
		str += '<td width="1%" class="item-table-cell">'
		str += writeMultiCheckFormOpen(id,nrtid)
		str += '<table width="100%" border="0" cellpadding="0" cellspacing="0" >'
		str+='<tr >'
	if (!hideChkBox) {
		str += '<td width="1%" id="multiOpChk" class1="table-heading">'+getMultiOpParentChkBox(id)+'</td>'
	}
		str+='<td class1="table-heading"  align="right"> '+ eval(menu)+'</td>'
		str+='</tr></table>'
		str+='</td></tr></table>'
	document.write(str)
}

function getMultiOpParentChkBox(id) {
	var str = ""
	var title = getLocStrByLID(1148, "Select/Unselect All")
	str= '<input type="checkbox" name="group-sel-'+id+'" value="'+id+'" onClick="selectAllItemCheckBox(this)" title="'+title+'">'
	return str
}

function doNothing() {
	//return false
}
function writeMultiCheckFormOpen(id,nrtid) {
	var str =''
	str+='<form name="fm-'+id+'" method="post">'
	str+='<input type="hidden" name="parent-'+id+'" value="'+nrtid+'" />'
	return str 
}

function writeTreeHeader(title, replyLink) {
	title = parseAndLocalizeStr(title)
	title = checkLength(title,40)	
	
	menu = replyLink != "" ? true:false;

	var imgSrc = "pixel.gif"
	imgSrc = imgSrc.substring(0,1) == "/" ? imgSrc  : "../images/" + imgSrc
	
	var themeRoot = getThemeRoot()	
	
	html = '\n' +				
	'<table border="0" cellspacing="0" cellpadding="0">\n'+
		'<tr>\n'+
			'<td width="1%" nowrap align="left">'+
				'<img src="'+themeRoot+'/images/item-header-left-corner.gif" width="6" height="24" border="0">'+
			'</td>'+
			'<td width="1%" align="left" valign="top">'+
				'<table cellspacing="0" cellpadding="0" border="0" width="100%">'+
					'<tr>'+
						'<td colspan="3" class="item-header-border"><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>'+
					'</tr>'+
					'<tr>'+						
						'<td class="item-header-bar" width="1%"><img src="'+themeRoot+'/images/pixel.gif" width="2" height="22" alt="" border="0"></td>\n' +						
						'<td class="item-header-bar" width="1%"><img src="'+themeRoot+'/images/pixel.gif" width="2" height="22" alt="" border="0"></td>\n' +									
						'<td class="item-header-bar" nowrap>'+title+'</td>'+
					'</tr>'+
					'<tr>' +
						'<td colspan="3" class="item-header-border" valign="bottom" ><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>'+
					'</tr>'	+			
				'</table>' +
			'</td>'+
			'<td class="item-header-background" nowrap align="right">\n' +
				'<img src="'+themeRoot+'/images/pixel.gif" width="62" height="24" alt="" border="0">' +
			'</td>' +
			'<td  nowrap align="right" width="95%">\n' +
				'<table cellspacing="0" cellpadding="0" border="0" width="100%">'+
					'<tr>' +
						'<td colspan="2" class="item-header-border"><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>' +
					'</tr>' +
					'<tr>'+
						'<td class="item-header-menu-bar" width="1%"><img src="'+themeRoot+'/images/pixel.gif" width="1" height="22" alt="" border="0"></td>\n' +
						'<td class="item-header-menu-bar"  width="1%" align="right">' +
							( menu ? replyLink : "&nbsp;") + '\n' +
						'</td>\n' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2" class="item-header-border" valign="bottom" ><img src="'+themeRoot+'/images/pixel.gif" width="1" height="1" border="0"></td>'+
					'</tr>'+			
				'</table>' +
			'</td>' +
			'<td  nowrap align="left"><img src="'+themeRoot+'/images/item-header-right-corner.gif" width="6" height="24" border="0"></td>' +
		'</tr>\n' +
	'</table>\n'		
	
	document.write(html)
}

function writeItemFooter() {
	document.write('</div>\n<br>\n')
}

function writeSearchFormFooter() {
	document.write('</div>')
}

function getMenuButton(menuFn,params,title,img, headerID, alignment) {
	/*	Added headerID param on 5/28/02 (NS).  This is required
		for 508 compliance when spitting out data tables.  We
		must associate a headers attribute on each <td> with the
		id of the main <th>.
		
		Added alignment param on 9/5/02 (NS).  This is optional param
		that is needed to determine how to position button.  When the user
		has selected to display the menu button on the left, we should center-align.
		This is handled in iwpl.
	*/
	var html
	
	if (headerID) {
		headerID = "headers=\"" + headerID + "\""
	}
	
	if (!alignment) {
		alignment = "align=\"right\""
	} else {
		alignment = "align=\"" + alignment + "\""
	}
	
	if (headerID) {
		html = '<td class="icon" ' + alignment + ' width="1%" ' + headerID + '>' + writeActionMenus("{523|Action}","small", menuFn,false,params,title,img)  + '</td>'
	} else {
		html = '<td class="icon"' + alignment + ' width="1%">' + writeActionMenus("{523|Action}","small", menuFn,false,params,title,img)  + '</td>'
	}
	
	return html
}

function writeMenuButton(menuFn,params,title,img, headerID, alignment) {
	document.write(getMenuButton(menuFn,params,title,img, headerID, alignment))
}

function toggleExpand(id, title, dontUpdateServer) {
	setCookie("expandedItem","item=")
	var refresh = false
	var divStyle = getStyleObject(id)

	var populated = (divStyle.populated == '1')
	var originalID = divStyle.originalid
	
	var url = virtualPath() + "/scripts/" + "Expand.aspx?page=" + page.id + "&id=" + originalID + "&expand=" + (populated ? "0" : "1")
	var altString = ""	
	if ( g_browser.isNS4 ) {
		refresh = true
	} else {
		var imgSrc 
		if ( populated ) {
			if ( divStyle.display == "none" ) {
				divStyle.display = "block"
				imgSrc = getThemeRoot()+ "/images/item-header-expanded.gif"
				url = setURLParam(url, "expand", "1")
				altString="{540|Collapse section:  }"
			} else {
				divStyle.display = "none"
				imgSrc = getThemeRoot()+ "/images/item-header-collapsed.gif"
				url = setURLParam(url, "expand", "0")
				altString="{668|Expand section:  }"
			}
		} else {
			refresh = true
		}
	}
		
	if ( refresh ) {
		setCookie("expandedItem","item="+id)
		var redirect = page.getRedirect()
		redirect = escape(redirect)
		window.location.href = setURLParam(url, "redirect", redirect)
		
	} else {
		// Notify the server
		var applet = getAppletById('clientToAspApplet')
		applet.putData(url)
				
		// change the image
		var groupingImg = document.images["grouping_" + id ]
		if ( groupingImg ) {
			groupingImg.src =  imgSrc
			groupingImg.alt=parseAndLocalizeStr(altString) + title
		}
	}
}

function toggleExpandAdhocSearch(id,title){
	//var url = virtualPath()	
	var divStyle = getStyleObject(id)
	if ( divStyle.display == "none" ) {
		divStyle.display = "block"
		imgSrc = getThemeRoot()+ "/images/item-header-expanded.gif"
		//url = setURLParam(url, "expand", "1")
		altString="{540|Collapse section:  }"
	} else {
		divStyle.display = "none"
		imgSrc = getThemeRoot()+ "/images/item-header-collapsed.gif"
		//url = setURLParam(url, "expand", "0")
		altString="{668|Expand section:  }"
	}
	var groupingImg = document.images["grouping_" + id ]
	if ( groupingImg ) {
		groupingImg.src =  imgSrc
		groupingImg.alt=parseAndLocalizeStr(altString) + title
	}
}

function doOpen() {
	var options = document.fm.attachments.options
	var index = document.fm.attachments.selectedIndex
	if (index < 0) {
		locAlert(getLocalizedString("786|Please make a selection first"))
		return
	}
	var option = document.fm.attachments.options[index]
	var url
	var ar = option.value.split("|")
	url = ar[0]
	var	j = url.search("GetDoc.aspx")
	if ( j >=0 )
	{
		var nrtid = getURLParam(url, "nrtid")
		downloadExView(nrtid)
	}
	else
	{
		// url = "../scripts/" + url
		//Fix for 9120:  Open attachments in current window, not new window (NS, 1/27/02)
		var url = virtualPath() + "/scripts/" + url
		var nsFeatures = "height=600,width=600"
		var ieFeatures = "dialogHeight:600px; dialogWidth:600px"		
		window.open(url,"", g_browser.isIE? ieFeatures:nsFeatures)	
	}
}

function selectThumbnail(callbackFnName) {
	// callback function must be of the form:
	//		function thumbNailCallback(wnd, cmd, title, nrtid)
	//			cmd		"ok" | "cancel"
	//			title	Image title
	//			nrtid	iManage moniker id for the thumbnail document

	var title = escape(getLocalizedString("1050|Select a workspace icon"))
	var url = "../scripts/PageIconDlg.aspx?title="+title+"&callback=_thumbnailCallback&context=" + callbackFnName
	if (g_browser.isIE) {
	var wnd = openWindow(url, "thumbnailWnd", 500, 460, "")
	} else {
		var wnd = openWindow(url, "thumbnailWnd", 500, 510, "")
	}
}

function _thumbnailCallback(wnd, cmd, nrtid, id, title, imgSrc, url, context) {

	var callbackFn = eval("window." + context)
	if (!callbackFn) {
		locAlert(getLocalizedString("884|Callback function not found!"))
	}
	else {
		callbackFn(wnd, cmd, title, nrtid)
	}
}

function mailtoURL(nrtid, title, script) { 
	/*	NS, 8/6/02:
		This function now supports multiple links sent simultaneously.
		nrtid parameter can contain multiple id's separated by kMultiOpSeparator
		NOTE:  nrtid will come in escaped; must unescape
	*/
	var body = ""
	var subject = ""
	var link = ""
	
	nrtid = unescape(nrtid)
	//Trim off last kMultiOpSeparator so array length represents the actual # of nrtid's passed
	if (nrtid.charAt(nrtid.length-1) == kMultiOpSeparator)
	{
		nrtid = nrtid.slice(0, nrtid.length-1)
	}
	
	var nrtidAry = nrtid.split(kMultiOpSeparator)
	
	if (nrtidAry.length == 1) {
		if (!title) {
			title = getLocStrByLID(1115, "WorkSite Link")
		}
	} else {
		title = getLocStrByLID(1114, "WorkSite Links")
	}

	
	if ( ! g_browser.isIE || ! g_browser.isIE5 ) {
		for (var j = 0; j < nrtidAry.length; j++)
		{
				body += script + escape(nrtidEncode(nrtidAry[j])) + "&ext=1" + "\n"
		}
		subject = title
		link = "mailto:?body=" + escape(body) + "&subject=" + javaString(subject)
	} else {
		for (var j = 0; j < nrtidAry.length; j++) {
				body += mailtoEncode(script) + nrtidEncode(nrtidAry[j]) + "%2526ext=1" + "\n"
		}
		subject = mailtoEncode(title)
		link = "mailto:?body=" + body + "&subject=" + subject
	}
	
	//window.location.replace(link )
	return link
}

function nrtidEncode(nrtid) {
	return nrtid.replace(/\!/g, "$").replace(/\:/g, ";")
}

function mailtoEncode(input) {
	return escape(input).replace(/%/g,  "%25")
}

function toggleGroupExpand(itemID, groupBy, groupName, img, altImgText) {
	// This expand or collapses the specified group.  img should be the expand or collapse image.  id should be the container
	// that needs to have its display style changed.
	
	/*	NS, 6/6/02:  Had to add altImgText param for grouping by date-time.  groupName is formatted
		as YYYY-MM-DD"T"HH:MM.  If I display groupName on toggling, then this is not helpful for
		the user.  Therefore, have to format date in xsl and send to this function as a param.
		
		The alt text is required for 508 compliance.	
	*/
	if (!img) {
		return 
	}
	
	var expand
	
	var elem = document.getElementById(itemID + "-" + groupName)
	if (elem) {
		if (elem.style.display == 'none') {
			img.src = getThemeRoot()+ "/images/group-expand.gif"
			img.alt = parseAndLocalizeStr("{688|Collapse grouping: }") + altImgText
			elem.style.display = "inline"
			expand = "1"
		} else {
			img.src = getThemeRoot()+ "/images/group-collapse.gif"
			img.alt = parseAndLocalizeStr("{693|Expand grouping: }") + altImgText
			elem.style.display = "none"
			expand = "0"
		}

		// DO NOT
		// Notify server
		// var url = virtualPath() + "/scripts/Expand.aspx?page=" + page.id + "&id=" + itemID + "&group=" + escape(groupName) + "&expand=" + expand + "&groupBy=" + groupBy + "&view=" + page.view
		// var applet = getAppletById('clientToAspApplet')
		// if (applet) {
		//	var data = applet.putData(url)
		// }
	}
}

function virtualRoot() {
	if ( ! virtualRootCache ) {
		virtualRootCache = prependIPSURL(getCookie("virtualRoot"))
	}
	return virtualRootCache
}
var virtualRootCache = ""

function virtualPath() {
	if ( ! virtualPathCache ) {
		virtualPathCache = prependIPSURL(getCookie("virtualPath"))
	}
	return virtualPathCache
}
var virtualPathCache = ""

function getThemeRoot()
{

	if ( ! themeRootCache ) {
		themeRootCache = virtualPath() + "/themes/" + getCookie("themeRoot");
	}
	return themeRootCache
}
var themeRootCache = ""

//This function is only useful for iPlanet gateway.
function prependIPSURL(str) {
	var add_ipsURL_to_iman = str;
	return add_ipsURL_to_iman;
}

//Check the length of "str" with "size".If greater, then trim "str" to "size".
function checkLength(str,size)
{
	if(str.length > size)	
		str = str.substring(0,size) + "..."	
	return str
}


function getNrtTypeName(nrtidString) 
{
	var NameDelimitor = '!';
	var ValueDelimitor = ':';
	var resultString = "";

	//Check if the moniker string is null. If not, get the type; if yes, return a empty string.
	if ( nrtidString ) 
	{
		//Find start position of the last name value pair defined by the DMS moniker protocol. 
		var begin = nrtidString.lastIndexOf(NameDelimitor);

		//If there is a pair, get the corresponding value, else return an empty string.
		if (begin > -1) 
		{
			//Advance to the right of the name delimitor to exclude the name moniker.
			begin += 1;

			//Find the end position of the value delimited by the value delimitor.
			var end = nrtidString.indexOf(ValueDelimitor, begin);

			//Get the right value if it exists.
			if (begin < end) 
			{
				resultString = nrtidString.substring(begin, end).toLowerCase();
			}
		}
	}
	return resultString;
}

function Page() {
	// this default values should be aprropriate for all temporary pages
	
	this.id			= 'temp-page'
	this.access		= iEnums.nrReviewerAccess
	this._redirect	= virtualPath() + '/scripts/home.aspx'
	this.image		= virtualPath() + '/images/ipage.gif'
	this.type		= kTempPageType
	this.view		= ''
	this.debug		= ''
	this.zoomed		= '0'
	this.required	= '0'
	this.rights		= '0'
	this.title		= ''
	this.description = ''
	this.owner = ''
	this.database = ''
	this.getRedirect = Page_getRedirect
	this.getTabObj = Page_getTabObj
	this.enable508Menus = '0'
	this.populateAllTabs = '0'
	this.isCurrentTabIsPage = Page_isCurrentTabIsPage
	this.AdhocSearch = '' // quick-search / search
	
}
function Page_getRedirect() 
{ 
	return setURLParam(this._redirect, 'tabid', this.getTabObj().getSelection()) 
}
function Page_getTabObj() 
{ 
	return window.innerTabsObj 
}
function Page_isCurrentTabIsPage()
{ 
	return this.getTabObj().getSelection() == this.id && this.id != ''; 
}

page = new Page()

window.g_menuid = 0

function showMenu(menu,menuName,params) {
	window.menuServerParams=htmlDeString(params)
	window.fw_menu = eval(menu)
	if (!window.fw_menu) return 
	window.fw_menu.writeMenus() 
	FW_showMenu(window.fw_menu, -50, 15, null,  menuName)
	return false
}

function redirectTo508Menu(url) {
	url = setURLParam(url,"tabid", page.getTabObj().getSelection())
	url = setURLParam(url,"redirect", escape(page.getRedirect()))
	window.location.href=(url)
	
}

function writeActionMenus(buttonTxt, size, menu,isItemHeader,params,title,img, noSectionTitle) {
	var menuName = 'menu_' + (window.g_menuid++)
	var hRef
	var onClick = ''
	
	title = title ? title : page.title
	var imgURL =''
	var actionTitle = ''
	
	title = parseAndLocalizeStr(title)

	switch(parseAndLocalizeStr(buttonTxt).toLowerCase()) {
		case 'action':
			actionTitle = getLocalizedMessage(710, title) //Action menu for %1
			break;
		case 'add':
			actionTitle = getLocalizedMessage(711, title) //Add menu for %1
			break;
	}
	
	if (page.enable508Menus=='1') {
		onClick = 'redirectTo508Menu(\'../scripts/show508menu.aspx?menu='+htmlString(escape(menu))+'&page='+page.id+'&title='+escape(title)+'&img='+img+'&access='+page.access+'&view='+page.view+'&required='+page.required+'&pageType='+page.type+'&params='+escape(params ?params:"")+'\');return false'
		//We do not want to show the drop-down arrow next to the Action text for 508 menus.  However, we still need the
		//Action arrow button for content items. (NS, 9/11/02)
		if(size == 'small') {
			imgURL='<img alt="' + htmlString(actionTitle) + '" '+ (g_browser.isIE ? '' :'name="' + menuName + '" ')+' border="0" src="'+getThemeRoot()+'/images/item-menu-button.gif" width="11" height="12" align="absmiddle" />'
		}
	} else {
		onClick= menu ? 'showMenu("' + javaString(menu) + '", "' + menuName + '", "' + javaString(params) + '"); return false' : ""
		if ( size == 'big' ) {
			imgURL = '<img alt="' + htmlString(actionTitle) + '" ' +(g_browser.isIE ? '' :'name="' + menuName + '" ')+'border="0" src="'+getThemeRoot()+'/images/item-header-menu-arrow.gif" width="9" height="5" align="absmiddle" />'
		} else if ( size == 'bigger' ) {
			imgURL = '<img alt="'+ htmlString(actionTitle) + '" ' + (g_browser.isIE ? '' :'name="' + menuName + '" ')+' border="0" src="'+getThemeRoot()+'/images/page-header-menu-arrow.gif" width="11" height="6" align="bottom" />'
		}else {
			imgURL = '<img alt="' + htmlString(actionTitle) + '" ' + (g_browser.isIE ? '' :'name="' + menuName + '" ')+' border="0" src="'+getThemeRoot()+'/images/item-menu-button.gif" width="11" height="12" align="absmiddle" />'
	 	 }	
	}	
	var root = virtualPath()
	var cls = (size=='big' ? 'action-button-big' : size == 'bigger' ? 'action-button-bigger': 'action-button-small')
	var anchorText = ""
	if ( size == 'big' || size == 'bigger' ) {
		anchorText = parseAndLocalizeStr(buttonTxt)
	} else {
		anchorText = '' 
	}
	var str = '\n' +
			'<table border="0" cellspacing="2" cellpadding="0" width="1"><tr>'
		 if (isItemHeader) {
			if (noSectionTitle) {
		  		 str+='<td nowrap align="right"><a class="'+cls+'" href="javascript:doNothing()" onclick="' + htmlString(onClick) + '" title="'+htmlString(actionTitle)+'">' + parseAndLocalizeStr(buttonTxt) +
				 '<img alt="' + htmlString(actionTitle) + '" src="'+ getThemeRoot()+ '/images/pixel.gif" width="2" height="1">' + imgURL+  '</a></td>'			
			}else {
		  		 str+='<td  nowrap align="right" valign="middle"><a class="item-header-menu-bar" href="javascript:doNothing()" onclick="' + htmlString(onClick) + '" title="'+htmlString(actionTitle)+'">' + parseAndLocalizeStr(buttonTxt) +
				 '<img alt="' + htmlString(actionTitle) + '" src="'+ getThemeRoot()+ '/images/pixel.gif" width="2" height="1">' + imgURL+  '</a></td>'
				 
				 				 
			}
		 } else {	
				str+='<td class="' + cls + '" nowrap align="right"><a class="'+cls+'" href="javascript:doNothing()" onclick="' + htmlString(onClick) + '" title="' + htmlString(actionTitle) + '">' + anchorText +
				'<img alt="' + htmlString(actionTitle) + '" src="'+ getThemeRoot()+ '/images/pixel.gif" width="2" height="1">' + imgURL +'</a></td>'
		 }	
		str += '</tr></table>'
	return str		
}

function innerTabsAction(id) {

	innerTabsObj.setSelection(id)

	if ( page.zoomed == '1' 
		|| g_browser.isNS4 
		|| page.populateAllTabs != '1'
		) {
	
		// clear zoomed mode and refresh
		window.location.replace(setURLParam(page.getRedirect(), "id", ""))
	
	} else if ( page.zoomed == '0' && ! g_browser.isNS4 ) {
	
		var tabStyle
		var prevId = innerTabsObj.getPrevSelection()
		if ( prevId ) {
			tabStyle = getStyleObject(prevId)
			if ( tabStyle ) {
				tabStyle.display = "none"
			}
		}
		tabStyle = getStyleObject(innerTabsObj.getSelection())
		if ( tabStyle ) {
			tabStyle.display = "block"
		}
		var innerTabsDiv = window.document.getElementById("innerTabsDiv")
		if ( innerTabsDiv ) {
			innerTabsDiv.innerHTML = innerTabsObj.render()
		}
			
	}
}
	
function showAbout() {
	if (g_browser.isNS4) {
		openWindow(virtualPath() + "/scripts/About.aspx", "aboutWnd", 435, 300, "")
	}else {
		openWindow(virtualPath() + "/scripts/About.aspx", "aboutWnd", 510, 420, "")
	}	
}

function showHelp(topic,isExpandedURL) {
	//temporary fix for #20174 (no help topics) for beta
	//todo:  post-beta this must be removed (NS, 11/4/03)
	/*var helpURL = virtualPath() + "/NoHelp.htm";
	var helpWnd = window.open(helpURL, "help")
	helpWnd.focus() */
	
	//mainly for connectors
	if(isExpandedURL)
	{
		if(topic.indexOf("http") == -1)
		{
			var helpURL = virtualPath() +  topic
		}
		var helpWnd = window.open(helpURL, "help")
		helpWnd.focus()
		return
	}
	
	var helpForm = document.getElementById ('helpForm');
	var helpURL
	if (topic) {
		if(topic.indexOf("http") == -1){
			helpURL = virtualPath() + "/help/help/" + topic
		}else{
			helpURL = topic
		}
	} else {
		if ( helpForm ) {
			helpURL = helpForm.action
		} else if (dialog__Custom__Help ) {
			return dialog__Custom__Help()
		} else {
			helpURL = virtualPath() + "/help/help/WebHelp.htm"
		}
	}	 

	//Support localized help	
	var langExt = window.lllist.abbreviation
	
	//Slice US / GB ... from the langExt for English help.
		var language = langExt.substr(0,2)
		langExt = (language == "en")?language:langExt
	if ( (getCookie("enable508Menus") == "1") && (language == "en")) {
		langExt = "en508";
	}
	var pos = helpURL.indexOf("help")
	var endPos = pos
	if ( pos > -1) {
		endPos = pos + 5
		helpURL = helpURL.substring(0, endPos) + langExt + "/" + helpURL.substring(endPos, helpURL.length)
	} else {
		if(helpURL.indexOf("http") == -1){
			helpURL = langExt + "/" + helpURL					
		}	
	}	
	var helpWnd = window.open(helpURL, "help")
	helpWnd.focus()
	
}

function getSectionHeader(caption)
{
	var str = '<table width="100%" border="0" cellspacing="3" cellpadding="0" align="center" >'
	if(caption) {
		str += '<tr><td class="section-header">'+parseAndLocalizeStr(caption)+'</td></tr>'
	}
	str += '<tr><td  nowrap class="section-header-border"><img src="../images/pixel.gif" width="1" height="1" alt="" border="0"></td></tr>'
	str += '</table>'
	return str
}

function writeSectionHeader(caption) {
	document.write(getSectionHeader(caption))
}

function appendRedirectToURL(url) {
	//This function will append the redirect from the page object (complete with tabid).
	window.location = virtualPath() + setURLParam(url, "redirect", escape(window.page.getRedirect()))
}

function writeNanoXmlApplet(id,locale) {
	if (g_browser.isNS4) {
		var result = '<applet archive="iManage.jar" codebase="../includes" code="nanoxml.dom.DOMApplet.class"  name="domApplet"  width="5" height="5" id="' + id + '" viewastext="1">'
					+ '	<param name="cabbase" value="iManage.cab"/>\n'
					+ ' <param name="locale" value="'+ locale + '">\n'
					+ '</applet>'
		
		document.write(result)
	}else {
		//may create xml dom for IE and NS6
	}
}

function writeFileXferApplet(useActiveX) {

	var appletInfo
	if (g_browser.isNav) {
		appletInfo =	'<applet name="TransferClient" codebase="../includes" code="com.imanage.workteam.filetransfer.TransferClient.class" height="0" width="1"  mayscript="true" archive="iManage.jar" VIEWASTEXT="1" id="TransferClient">'
		appletInfo +=	'	<param name="cabbase" value="iManage.cab"/>'
		appletInfo +=	'	<param name="Action" value="DownloadSelect"/>'
		appletInfo +=	'	<param name="FormName" value="fm"/>'
		appletInfo +=	'	<param name="FileCtrl" value=""/>'
		appletInfo +=	'	<param name="SendFormData" value="yes"/>'
		appletInfo +=	'</applet>'
	} else {
		if (useActiveX == 'True') {
			appletInfo =	'<object ID="WebTransferCtrl" style="display:none;" width="1" height="1" codebase="../includes/iManFile.cab#version=8,0,2,6" classid="CLSID:53C9A69F-A62B-4a09-9B04-F7395682B3AF"  viewastext="1">'
			appletInfo +=	'	<param name="Action" value="3"/>'
			appletInfo +=	'	<param name="_cx" value="0"/>'
			appletInfo +=	'	<param name="_cy" value="0"/>'
			appletInfo +=	'</object>'
		} else {
			appletInfo =	'<applet name="TransferClient" codebase="../includes" code="com.imanage.workteam.filetransfer.TransferClient.class" height="0" width="1"  mayscript="true" archive="iManage.jar" VIEWASTEXT="1" id="TransferClient">'
			appletInfo +=	'	<param name="cabbase" value="iManage.cab"/>'
			appletInfo +=	'	<param name="Action" value="DownloadSelect"/>'
			appletInfo +=	'	<param name="FormName" value="fm"/>'
			appletInfo +=	'	<param name="FileCtrl" value=""/>'
			appletInfo +=	'	<param name="SendFormData" value="yes"/>'
			appletInfo +=	'</applet>'
		}
	}
		
	document.write(appletInfo)
}

//Trim description of any item to the supplied maximum number of characters.
function checkMaxChars(src, maxChars) {							
	if ( src.value.length >= maxChars ) {
		src.value = src.value.substr(0, maxChars )													
	}									
}

function KeyCodes() {
	/*
		key maps:
		left arrow: 37;
		right arrow: 39;
		up arrow: 38;
		down arrow: 40
		shift key: 16;
		tab key: 9;
		space bar: 32;
		enter: 13;
		minus (dash):  189 --> replaced I since JAWS 5.0 now uses I for IE shortcut
		open bracket:  219 --> replaced J since JAWS 5.0 now uses J for IE shortcut
		close bracket:  221 --> replaced K since JAWS 5.0 now uses K for IE shortcut
		quotes:  222 --> replaced M since JAWS 5.0 now uses M for IE shortcut
		semicolon: 186;
		apostrophe: 222;
	
	*/
	this.is508User = getCookie("enable508Menus") == "1"
	this.ARROW_LEFT = this.is508User ? 219 : 37;
	this.ARROW_UP =this.is508User ? 189 : 38;
	this.ARROW_RIGHT = this.is508User ? 221 : 39;
	this.ARROW_DOWN = this.is508User ? 222 : 40;
	this.SHIFT =16;
	this.TAB = 9;
	this.SPACE = this.is508User ? 186 : 32;
	this.ENTER = this.is508User ? 222 : 13;
}
var keyCodes = new KeyCodes()

function dispatch(id, method, e, param) {
	var obj = document.getElementById(id) 
	if ( obj && obj[method] && typeof(obj[method]) == "function" ) {
		obj[method](e, param)
	}
}

function functionVoid() { }

function parseXml(xml) {
	var doc
	if ( g_browser.isNS6 ) {
		doc = (new DOMParser()).parseFromString(xml, "text/xml")
		doc.documentElement.normalize()
	} else if ( g_browser.isIE ) {
		doc = new ActiveXObject("Microsoft.XMLDOM")
		doc.resolveExternals = false
		doc.validateOnParse = false
		doc.async = false
		var success = doc.loadXML(xml)
		if ( ! success && doc.parseError ) {
			alert(doc.parseError.reason)
			doc = null
		}
	}
	return doc
}

function copyChildNodes(sourceNode, targetNode) {
	var copyFunction = null
	if ( g_browser.isNS6 && sourceNode.ownerDocument !== targetNode.ownerDocument ) {
		copyFunction = copyChildNodes_import
	} else if ( sourceNode !== targetNode ) {
		copyFunction = copyChildNodes_clone
	} 
	
	for( var i = 0; copyFunction && i < sourceNode.childNodes.length; i++ ) {
		targetNode.appendChild(copyFunction(sourceNode.childNodes.item(i), targetNode.ownerDocument))
	}
}

function copyChildNodes_import(node, targetDoc) 
{ 
	return targetDoc.importNode(node, true) 
}
function copyChildNodes_clone(node) 
{ 
	return node.cloneNode(true) 
}

function AlternativeImageText() {	
	
	var obj = new Object()
	obj["globaloptions"] = 614 //"Global Options
	obj.archived = 969 // "Archived
	obj.avi = 648 // "AVI file
	obj.addtab = 788 // "Add Tab
	obj.archived = 969 // "Archived
	obj.autonomy = 795 // "WorkKnowledge Search
	obj.bmp = 590 // "BMP file
	obj.browse = 246 // Browse
	obj.bullet = 541 // "Bullet
	obj.cal = 278 // "Calendar
	obj.caloptions = 348 // "Calendar Options
	obj["category-favorite"] = 139 //Category
	obj["category-matters"] = 139 //Category
	obj.checkedout = 164 // "Checked out
	obj.checkedoutdocs = 164 //Checked out
	obj.connectors = 547 // "Connectors
	obj.connector = 585 // "Connector
	obj["connector-new"] = 606 // "New
	obj.database = 150 // "Database
	obj["default"] = 481 // "Unknown file type
	obj.discussion = 316 // "Discussion
	obj.doc = 582 // "Word document
	obj.doclink = 90
	obj.dochdr = 343 // "Icon
	obj.editprofilebtn = 461 // "Edit Profile
	obj["event"] = 314 // "Event
	obj.eventcategory = 104 // "Event Categories
	obj["event-find"] = 324 // "Event Search
	obj["event-findsaved"] = 324 // "Event Search
	obj["event-folder"] = 278 // "Calendar
	obj.exclaim = 131 // "High
	obj.favorites = 558 // "Favorites
	obj.favoritecategory = 139 // "Category
	obj.fax = 375 // "Fax
	obj.fdf = 496 // "Acrobat file
	obj.folder = 429 // "Folder
	obj.folderlink = 574 // "Folder Link
	obj.gif = 643 // "GIF file
	obj.generalsettings = 287 // "General
	obj.group = 355 // "Group
	obj.homepage = 253 // "Start Page
	obj["homepages"] = 544 //"Start Pages
	obj.htm = 274 // "HTML
	obj.html = 274
	obj.ipage = 279 // "Page
	obj.ipagelink = 279
	obj.ipages = 560 // "Pages
	obj.imanagepowered = 580	// "Goto:http://www.imanage.com"
	obj.importdoc = 366 // "Import Document
	obj.importurl = 367 // "Import URL
	obj.jpg = 638 // "JPEG file
	obj.layout = 519 // "Layout
	obj.lgbullet = 541 // "Bullet
	obj.link = 114 // "Link
	obj["link-list"] = 489 //Link List
	obj.links = 105 // "Links
	obj.locked = 970 // "Locked
	obj.manage = 584
	obj.matter = 1201 // Matter
	obj.matters = 1211 //Matters
	obj.minus = 543 // "Expanded
	obj.mmp = 529 // "Microsoft Project
	obj.mode = 45 // "Mode
	obj.morebtn = 945 // "More
	obj.msg = 323 // "Email message
	obj["navigation-menu"] = 1312 //Navigation menus
	obj.newsubfolderbtn = 368 // "Add subfolder
	obj.note = 581 // "Note
	obj.notification = 216 // "Notification
	obj["options"] = 345 //"User Options
	obj.pageprofile = 490 // "Profile
	obj.pagesearch = 577 // "Page Search
	obj["pagesearchform"] = 578 //"Page Search Form"
	obj["pagesearchprofile"] = 225 //"Page Search Profile"
	obj["pagesearchsaved"] = 577 // "Page Search
	obj.pagesearchopen = 578 // "Page Search Form
	obj.paperclip = 123 // "Attachments
	obj.pdf = 496 // "Acrobat file
	obj.plus = 561 // "Collapsed
	obj.privileges = 357 // "Privileges
	obj.profile = 490 // "Profile
	obj["profiles"] = 549 //"Document Profiles
	obj["properties"] = 115	//Properties
	obj.ppt = 499 // "PowerPoint file
	obj.psd = 532 // "Photoshop file
	obj.qpw = 530 // "QuattroPro file
	obj.recentpages = 1211 //Matters
	obj.related = 488 // "Related Documents
	obj.resources = 362 // "Resources
	obj.role = 364 // "Role
	obj.roles = 364 // "Role
	obj.rolemanagement = 397 // "Role Management
	obj.root = "WorkSite"
	obj.sbtab = 1141 // "Tab
	obj.search = 575 // "Document Search
	obj["searchcontainer"] = 247 //"Search
	obj["searchsaved"] = 575 // "Document Search
	obj.searchopen = 575 // "Document Search
	obj.searchfolder = 962 // "Search Folder
	obj.searchform = 576 // "Document Search Form
	obj.security = 214 // "Security
	obj.session = 528 // "Session
	obj.settings = 217 // "Settings
	obj.statushdr = 229 // "Status
	obj.tab = 1141 // "Tab
	obj.task = 275 // "Task
	obj.tasks = 321 // "Tasks
	obj.tasksearch = 280 // "Task Search
	obj["tasksearchsaved"] = 280 // "Task Search
	obj.tif = 646 // "TIFF image file
	obj.topic = 974 // "Topic
	obj["tree-minus"] = 543 // "Expanded
	obj["tree-minus-down"] = 543 // "Expanded
	obj["tree-minus-up"] = 543 // "Expanded
	obj["tree-minus-up-down"] = 543 // "Expanded
	obj["tree-plus"] = 561 // "Collapsed
	obj["tree-plus-down"] = 561 // "Collapsed
	obj["tree-plus-up"] = 561 // "Collapsed
	obj["tree-plus-up-down"] = 561 // "Collapsed
	obj.txt = 766 // "Plain text
	obj.user = 395 // "User
	obj.useroptions = 345 //User Options
	obj.url = 307 // "URL
	obj.view = 106 // "View
	obj["view-document"] = 550 //Document Views
	obj["view-workspace"] = 1323 //WorkSpace Views
	obj.versions = 487 // "Document Versions
	obj.vsd = 515 // "Visio file
	obj.wpd = 583 // "WordPerfect document
	obj.wri = 667 // "Windows Write document
	obj.wav = 650 // "WAV file
	obj.worklist = 555 //Documents
	obj["workspace-template"] = 196
	obj["workspace-templates"] = 546
	obj.xls = 520 // "Excel file
	obj.xml = 660 // "XML
	obj.zip = 524 // "Compressed file
	
	return obj
}

var alternativeImageText = new AlternativeImageText()

function getAltImgText(imgSrc) {
/*	This function returns text to be used for the alt attribute on an image
	NOTE:  not all images are supported.
*/
	var startPos
	var endPos
	var imgName = ""
	var altText = ""

	if ( ! imgSrc || imgSrc.indexOf("pixel.gif") >=0 ) {
		return imgName
	}
	
	startPos = imgSrc.lastIndexOf("/") + 1
	endPos = imgSrc.lastIndexOf(".")
	
	imgName = imgSrc.slice(startPos, endPos).toLowerCase()
	var altText = alternativeImageText[imgName]
	return altText ? getLocStrByLID(altText) : ""
}

function subscribeMatter(){
	var url = virtualPath() + "/scripts/MatterDialog.aspx?id=&functionName=matterSubscriptionCallback"
	var winObj= openWindow(url,"", 420 , 490, "scrollbars=no")
}

//id is not used here
function matterSubscriptionCallback(id, values)
{
	if (values) {
		var url = virtualPath() + "/scripts/MatterSubscribe.aspx?users=" + escape(values);
		var applet = getAppletById("clientToAspApplet");
		if (applet) {
			var result = applet.getData(url);
			if (applet.hasError) 
			{
				locAlert(applet.errorMessage)
			}
			else 
			{
				var href;
				if (getCookie("enable508Menus") == "1")
				{
					//need to redirect for 508 users back to original page
					href = window.location.href.toLowerCase().indexOf("/show508menu") > 0 ?
						page.getRedirect() : window.location.href;
				}
				else
				{
					href = window.location.href;
				}
				
				window.location.href = href;
			}
		}	
			
	}
}

function publishDoc(params,publish) {
	var applet = getAppletById("clientToAspApplet")
		var url = virtualPath() + "/scripts/MiscDocumentOps.aspx?op="+(publish ? "publish" : "unpublish")+ "&"+ params
		if (applet) {
			var val =applet.getData(url)
			var msg
			if(publish) 
			{
				msg = parseAndLocalizeStr("{1080|Document Published Successfully}")
			}
			else
			{
				msg = parseAndLocalizeStr("{1081|Document Unpublished Successfully}")
			}	
			alert(msg)
		}
	}
	
function formatTimeSpan(seconds) {
	var hours = Math.floor(seconds / 3600)
	hours = hours < 10 ? "0" + hours .toString() : hours.toString()
	var minutes = Math.floor((seconds - hours * 3600) / 60)
	minutes = minutes < 10 ? "0" + minutes : minutes.toString() 
	seconds = seconds - hours * 3600 - minutes * 60
	seconds = seconds < 10 ? "0" + seconds.toString() : seconds.toString()
	document.write(hours + ":" + minutes + ":" + seconds)
}
	
function selectCheckBoxRow(obj) {
	var trObj
	checkParentCheckBoxStatus(obj)
	if(g_browser.isNS4) return
	if(g_browser.isIE) {
		trObj = obj.parentElement.parentElement
	}else {
		trObj = obj.parentNode.parentNode
	}
	if(trObj) {
		if(obj.checked) {
			//trObj.className = "checkbox-selected-row"
			trObj.setAttribute("old_color",trObj.style.backgroundColor) 
			var selectedColor = getCookie("multiop","selectedcolor")
			if(!selectedColor) {
				selectedColor="#eef0fb"
			}
			
			trObj.style.backgroundColor=selectedColor
		}else {
			var bgColor =trObj.getAttribute("old_color")
			bgColor = bgColor ? bgColor : "#ffffff"
			trObj.style.backgroundColor=bgColor 
		}	
	}
}	

function checkParentCheckBoxStatus(obj) {
	if (obj.checked)return
	var id = obj.name.replace("nrt-chk-", "")
	var form = obj.form 
	var parentObj = form.elements["group-sel-"+id]
	if(parentObj){
		if(parentObj.checked) {
			parentObj.checked=false
		}
	}
}

function selectAllItemCheckBox(obj,value) {
	var id
	if((typeof obj) == "string") {
		id = obj
	}else {
		id = obj.value
		value = obj.checked		
	}
	var nrtItemsObj = new NRTItems(id)	//obj.value contain the ID
	if(nrtItemsObj) {
		var success =nrtItemsObj.checkAll(value) // to check/uncheck all the checkboxes below this item:SJ
		if(!success) {
			obj.checked=!value
		}		
	}
}

function writeMultiCheckFormClose() {
	document.write('</form>\n')
}
		
function isAbsoluteUrl(url) {
	url = String(url)
	return url.match(/^[A-Za-z]+\:/) || url.match(/^[\/\\]/)
}

function restoreOffset() {
	var name = window.name + "Offset"
	var offset = getCookie(name)
	if ( offset && window.scrollTo ) {
		var offsets = offset.split(",")
		window.scrollTo(offsets[0], offsets[1])
		setCookie(name, "", 0)
	}
}

function beginGroup(id, groupBy, name, expand) {
	var title = name != "!" ? name : getLocStrByLID(1133, "No Category")
	var str = ""
	if (!g_browser.isNS4) {
	str+=	'<tr>' +
			'<td width="1%">' +
				'<a href="#" onclick="javascript:toggleGroupExpand(\'' + id + '\', \'' + htmlString(groupBy) + '\',\'' + htmlString(name) + '\', this.firstChild, \'' + htmlString(title) + '\');return false">' +
					( expand == '1'
						? '<img border="0" width="16" height="16" src="'+getThemeRoot()+'/images/group-expand.gif" alt="' + htmlString(parseAndLocalizeStr("{688|Collapse grouping: }") + title) + '"/>'
						: '<img border="0" width="16" height="16" src="'+getThemeRoot()+'/images/group-collapse.gif" alt="' + htmlString(parseAndLocalizeStr("{693|Expand grouping: }") + title) + '"/>'
					) +
				'</a>' +
			'</td>'
	} else {
	//Fix for 13554:  Do not give hyperlink on expanded image since we always have items expanded for NS4.x (NS, 10/8/02)
	str+=	'<tr>' +
			'<td width="1%">' +
				'<img border="0" width="16" height="16" src="'+getThemeRoot()+'/images/group-expand.gif" />' +
			'</td>'
	}
	str+='<td class="group-heading" colspan="5" width="99%">' +
				title +
			'</td>' +
		'</tr>' +
		'<tbody id="' + id + "-" + name + '" ' + ( expand != "1" && !g_browser.isNS4 ? 'style="display:none"' : '') + ' >'
	document.write(str)
}

function endGroup(msg, colspan) {
	document.write(
			'<tr>' +
				'<td></td>' +
				'<td><img src="../images/blankIcon.gif"/></td>' +
				'<td class="message" colspan="' + (colspan ? colspan : 3) + '" align="center">' +
					'<em>' + (msg ? eval(msg) : '') + '</em>' +
				'</td>' +
			'</tr>' +
		'</tbody>'
		)
}


function openAsHTML(nrtid) {
	//We now support multiple docs being viewed as HTML; therefore, must open a separate window for each document
			
	if (nrtid.charAt(nrtid.length-1) == kMultiOpSeparator)
	{
		nrtid = nrtid.slice(0, nrtid.length-1)
	}
	var nrtAry = nrtid.split(kMultiOpSeparator)
	for (var j = 0; j<nrtAry.length; j++) {
		var url="../scripts/viewDoc.aspx?nrtid=" + nrtAry[j] + "&ishtml=1&command=ok"
		var wnd=window.open(url, "viewDoc_" + j, "scrollbars=yes, resizable=yes, toolbar=yes, location=yes, menubar=yes")
	}

}

function getAccessEnum(access){
	switch(access){
		case "nrRightAll":
		case "3":
			return iEnums.nrRightAll;
		case "nrRightReadWrite":
		case "2":
			return iEnums.nrRightReadWrite;	
		case "nrRightRead":
		case "1":
			return iEnums.nrRightRead;
		case "nrRightNone":
		case "0":
			return iEnums.nrRightNone;
		
	}
}

function getDocumentOptionMessage(documentOption) {
	switch ( documentOption ) {
		case 'view':
			return 951
		case 'viewHTML':
			return 460
		case 'checkOut':
			return 960
		case 'portable':
			return 961
		case 'profile':
			return 964
		default:
			return 0
	}
}

function checkLength(str, size)
{
	if( str.length > size)	
	{
		return str.substring(0, size) + "...";
	}
	return str;
}

function generateFolderEmail(folderID, objectID, folderName, op)
{
	//use clienttoasp to generate email
	//NOTE:  "+" symbol used for url encoding.  Need to replace it with its hex value
	var applet
	var url
	var newEmail = ""
	applet = getAppletById("clientToAspApplet")
	url = virtualPath() + "/scripts/GetFolderEmail.aspx?nrtid=" + folderID + "&folderName=" + folderName.replace("+", "%2b") + "&op=" + op
	if (applet) {
		newEmail = applet.getData(url) + ""
	}
	/*	Fix for 18267:  Netscape - Generate Email Address button function adds (ctrl?) characters 
		to suggested email address which is is interpreted as white space when I try to create folder
		(NS, 7/16/03)
	*/
	if (newEmail)
	{
		newEmail = trim(newEmail)
	}
	//end fix
	
	if (objectID != "")
	{
		document.fm[objectID].value = newEmail
	}
	return
}

function getItemCountMsg(count,overflow, total, singleItemName, multiItemName) {
	document.write(eval(getItemCountMsgEx(count,overflow, total, singleItemName, multiItemName)))
}

function getItemCountMsgEx(count,overflow, total, singleItemName, multiItemName ) {
	if (!singleItemName) {
		singleItemName = "1054|Item"
	}
	
	if (!multiItemName) {
		multiItemName = "1055|Items"
	}
	if (count > 0) {
		if (total && total != "0") {
			return 'getMessage("1051", "' + count + '", "' + total + '", getLocalizedString("' + multiItemName + '"))'
		}

		if (!overflow || overflow == "0") {
			if (count == 1) {
				return '\'1 \' + getString("", "{' + singleItemName + '}", "")'
			} else {
				return '\'' + count + ' \' + getString("", "{' + multiItemName + '}", "")'
			}
		} else {
			overflow = Number(overflow)
			if(!isNaN(overflow))
			{
				if (overflow < 0) {
					return 'getMessage("1051", "' + count + '", "' + count + '", getLocalizedString("' + multiItemName + '"))'		
				} else {
					return 'getMessage("1051", "' + count + '", "' + (count + overflow) + '", getLocalizedString("' + multiItemName + '"))'
				}			
			}
			else
			{
				return 'getMessage("1051", "' + count + '", "' + count + '", getLocalizedString("' + multiItemName + '"))'					
			}
		}
	}
	else
	{	
			return 'parseAndLocalizeStr("{414|There are no items to display.}")'
	}
}

function openSelectedLink(xmlElement) {
	if ( xmlElement ) { 
		openSelectedLinkEx(xmlElement.getAttribute("href"), xmlElement.getAttribute("target"))
	}
}

function openSelectedLinkEx(href, target) {
	if ( href ) {
		if ( target == 'ws_childframe' ) {
			window.open(virtualPath() + "/scripts/redirector.aspx?url=" + escape(href), '_self')
		} else {
			if ( href.indexOf("javascript:") == 0 ) {
				eval(href.substr("javascript:".length))
			} else {
				window.open(href, target)
			}
		}
	}
}

function DocumentsStatus()
{
	this.CheckedOut = 0
	this.Archived = 1
	this.Locked = 2
	this.CheckedIn = 3
}

function getStatusImage(status, compound, altText)
{
	var documentsStatus = new DocumentsStatus();
	var image
	
	switch (status)
	{
		case documentsStatus.CheckedOut:
			image = 'CheckedOut'
			break;
		case documentsStatus.Archived:
			image = 'Archived'
			break;
		case documentsStatus.Locked:
			image = 'Locked'
			break;
		case documentsStatus.CheckedIn:
		default:
			image = 'CheckedIn'
			break;
	}
			
	return '<img border="0" width="16" height="16" src="../images/' + image + (compound ? 'Comp' : '') + '.gif" alt="' + htmlString(altText) + '" >'
}



function prioritySelectHTML(val)
{	
	var priorityTypes = new Array("131","271","128");
	var html ='';																
	html+='<select name="p-priority" id="p-priority" style="width:104">';		
	html+='<option value="-1"/>';															
	html+='<option value="0" '+(val == "0" ? "selected" : "")+'>'+ getLocStrByLID(priorityTypes[0]) +'</option>';
	html+='<option value="1" '+(val == "1" ? "selected" : "")+'>'+ getLocStrByLID(priorityTypes[1]) +'</option>';
	html+='<option value="2" '+(val == "2" ? "selected" : "")+'>'+ getLocStrByLID(priorityTypes[2]) +'</option>';
	html+='</select>';
	return html;
}

function statusSelectHTML(val)
{	
	var statusTypes = new Array(getLocStrByLID(266,"Active"),getLocStrByLID(269,"Completed"),getLocStrByLID(270,"Deferred"));
	var html ='';																
	html+='<select name="p-status" id="p-status" style="width:104">';		
	html+='<option value="-1"/>';															
	html+='<option value="0,1" '+(val == "0,1" ? "selected" : "")+'>'+ statusTypes[0] +'</option>';	
	html+='<option value="2" '+(val == "2" ? "selected" : "")+'>'+ statusTypes[1] +'</option>';
	html+='<option value="3" '+(val == "3" ? "selected" : "")+'>'+ statusTypes[2] +'</option>';
	html+='</select>';
	return html;
}

function categorySelectHTML(val)
{	
	var url = virtualPath() + "/scripts/GetEventCategories.aspx?&category="+val;
	var applet = getAppletById('clientToAspApplet')
	var data = applet.getData(url)	
	document.write(data)	
}	

function dueDateSelectArray()
{
	/*	Removed per Mohit's email on 9/22/03 ; 
		'last week' too confusing w/last 30 days, 
		and last 30 days is more explicit, etc. (NS, 9/23/03) 
	*/
	var dateFilterValues = new Array()
	dateFilterValues[dateFilterValues.length] = ",,0"	
	dateFilterValues[dateFilterValues.length] = "overdue," + getLocalizedString('767|Overdue') + ",0"															
	dateFilterValues[dateFilterValues.length] = "today," + getLocalizedString('173|Today') + ",0"															
	dateFilterValues[dateFilterValues.length] = "tomorrow," + getLocalizedString('753|Tomorrow') + ",0"															
	dateFilterValues[dateFilterValues.length] = "last 7 days," + getLocalizedString('754|Last 7 days') + ",0"															
	dateFilterValues[dateFilterValues.length] = "next 7 days," + getLocalizedString('755|Next 7 days') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "last week," + getLocalizedString('756|Last week') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "this week," + getLocalizedString('757|This week') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "next week," + getLocalizedString('758|Next week') + ",0"															
	dateFilterValues[dateFilterValues.length] = "last 30 days," + getLocalizedString('149|Last 30 days') + ",0"															
	dateFilterValues[dateFilterValues.length] = "next 30 days," + getLocalizedString('112|Next 30 days') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "last month," + getLocalizedString('759|Last month') + ",0"															
	dateFilterValues[dateFilterValues.length] = "this month," + getLocalizedString('760|This month') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "next month," + getLocalizedString('761|Next month') + ",0"															
	dateFilterValues[dateFilterValues.length] = "on or before," + getLocalizedString('762|On or before') + ",1"															
	dateFilterValues[dateFilterValues.length] = "on or after," + getLocalizedString('763|On or after') + ",1"															
	dateFilterValues[dateFilterValues.length] = "on," + getLocalizedString('764|On') + ",1"															
	dateFilterValues[dateFilterValues.length] = "between," + getLocalizedString('765|Between') + ",2"																
	return dateFilterValues														
}

function startDateSelectArray()
{
	/*	Removed per Mohit's email on 9/22/03 ; 
		'last week' too confusing w/last 30 days, 
		and last 30 days is more explicit, etc. (NS, 9/23/03) 
	*/
	var dateFilterValues = new Array()
	dateFilterValues[dateFilterValues.length] = ",,0"	
	dateFilterValues[dateFilterValues.length] = "on or after today," + getLocalizedString('266|Active') + ",0"															
	dateFilterValues[dateFilterValues.length] = "yesterday," + getLocalizedString('752|Yesterday') + ",0"															
	dateFilterValues[dateFilterValues.length] = "today," + getLocalizedString('173|Today') + ",0"															
	dateFilterValues[dateFilterValues.length] = "tomorrow," + getLocalizedString('753|Tomorrow') + ",0"															
	dateFilterValues[dateFilterValues.length] = "last 7 days," + getLocalizedString('754|Last 7 days') + ",0"															
	dateFilterValues[dateFilterValues.length] = "next 7 days," + getLocalizedString('755|Next 7 days') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "last week," + getLocalizedString('756|Last week') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "this week," + getLocalizedString('757|This week') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "next week," + getLocalizedString('758|Next week') + ",0"															
	dateFilterValues[dateFilterValues.length] = "last 30 days," + getLocalizedString('149|Last 30 days') + ",0"															
	dateFilterValues[dateFilterValues.length] = "next 30 days," + getLocalizedString('112|Next 30 days') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "last month," + getLocalizedString('759|Last month') + ",0"															
	dateFilterValues[dateFilterValues.length] = "this month," + getLocalizedString('760|This month') + ",0"															
	//dateFilterValues[dateFilterValues.length] = "next month," + getLocalizedString('761|Next month') + ",0"															
	dateFilterValues[dateFilterValues.length] = "on or before," + getLocalizedString('762|On or before') + ",1"															
	dateFilterValues[dateFilterValues.length] = "on or after," + getLocalizedString('763|On or after') + ",1"															
	dateFilterValues[dateFilterValues.length] = "on," + getLocalizedString('764|On') + ",1"															
	dateFilterValues[dateFilterValues.length] = "between," + getLocalizedString('765|Between') + ",2"																
	return dateFilterValues														
}

function doShowPressed(tableObj){
	if (tableObj != null)
	{
		var imagesCol = tableObj.getElementsByTagName("img")
		if (imagesCol != null && imagesCol.length > 0)
		{
			imagesCol[0].src = virtualPath() + "/images/button-Press-left.gif"
			imagesCol[1].src = virtualPath() + "/images/button-Press-right.gif"
		}
		var tdCol =  tableObj.getElementsByTagName("td")
		if (tdCol != null && tdCol.length > 0)
		{
			for (var nIndex = 0; nIndex < tdCol.length ; nIndex ++)
			{
				if (tdCol[nIndex].className == 'button-text-background')
					tdCol[nIndex].style.backgroundImage="url(" + virtualPath() + "/images/button-Press-repeater.gif)"
			}
		}
	}
			
}
function doShowNormal(tableObj){
	if (tableObj != null)
	{
		var imagesCol = tableObj.getElementsByTagName("img")
		if (imagesCol != null && imagesCol.length > 0)
		{
			imagesCol[0].src = virtualPath() + "/images/button-Reg-left.gif"
			imagesCol[1].src = virtualPath() + "/images/button-Reg-right.gif"
		}
		var tdCol =  tableObj.getElementsByTagName("td")
		if (tdCol != null && tdCol.length > 0)
		{
			for (var nIndex = 0; nIndex < tdCol.length ; nIndex ++)
			{
				if (tdCol[nIndex].className == 'button-text-background')
					tdCol[nIndex].style.backgroundImage="url(" + virtualPath() + "/images/button-reg-repeater.gif)"
			}
		}
	}
}
function replaceDoubleQuoutesToSingle (val)
{
	return val.replace(new RegExp("\"","ig"), "'");
}
function writeButtonHTML (caption,cmdHandler,title,className,accessKey,id,enable){
	
	document.write(getButtonHTML(caption,cmdHandler,title,className,accessKey,id,enable))
}
function getButtonHTML (caption,cmdHandler,title,className,accessKey,id,enable)
{
	var strTitle ;
	var straccessKey ;
	var strId ;
	var strCmd ;
	var strStyle ;
	var strTextId ;
	var enable508 = getCookie("enable508Menus")
	
	cmdHandler = replaceDoubleQuoutesToSingle (cmdHandler) ;
	if ( typeof(title) == "undefined" || title == null) 
		strTitle = '' ;
	else
		strTitle = 'title="' + title +'"'  ;
	
	if ( typeof(accessKey) == "undefined" || accessKey == null) 
		straccessKey =''
	else 
		straccessKey='accesskey="' + accessKey +'"' ;
		
	if ( typeof(id) == "undefined" || id == null) 
	{
		strId =""
	}
	else 
	{
		strId=' id="' + id +'"' ;
		strTextId = ' id="' + id +'_text"' ;
	}

	if ( typeof(enable) != "undefined" &&  enable != null && !enable) 
	{
		strCmd = ' onclick=\"' +cmdHandler+'\"; onmousedown="doNothing();" onmouseup="doNothing();" onmouseout="doNothing();"'
		strStyle = 'style="cursor:text" disabled '
	}
	else
	{
		strCmd = ' onclick=\"' +cmdHandler+'\"; onmousedown="doShowPressed(this)" onmouseup="doShowNormal(this)" onmouseout="doShowNormal(this)"'
		strStyle = 'style="cursor:hand" '
	}		
	if(enable508 == '1')
	{		
		return ("<input  class='dialog-button' type='button' value= '" + caption + "' " + strCmd + straccessKey + strTitle + strId +"/>")
	}
	else
	{
		return ("<table  "+ strTitle + strId +" cellpadding='0' cellspacing='0' border='0' " + strStyle + strCmd +">" 
				   +"<tr><td><img src='" + virtualPath() + "/images/button-reg-left.gif' width='6' height='18'></td >"
				   +"<td nowrap height='18' class='button-text-background' align=absmiddle><a" + strTextId + straccessKey + " class='button-text' href='#'>"+caption+"</a></td>"
				   +"<td ><img src='" + virtualPath() + "/images/button-reg-right.gif' width='6' height='18'>"
				   +"</td></tr></table>")
	}
}


function writeFullTextZone(selected){
	document.write('<span id=\'div-p-full-text-zone\' align=\'left\'>' +	
	'<select name=\'p-full-text-zone\'>' +
	'<option value="0" '+ (selected ==0 ? "selected" : "") + '>' + parseAndLocalizeStr('{1349|Anywhere}')+ '</option>'  +
	'<option value="1" '+ (selected ==1 ? "selected" : "")  + '>' + parseAndLocalizeStr('{478|Comments}')+ '</option>' +
	'<option value="2" '+ (selected ==2 ? "selected" : "") +'>' + parseAndLocalizeStr('{111|Description}')+ '</option>' +
	'<option value="3" '+ (selected ==3 ? "selected" : "") + '>' + parseAndLocalizeStr('{1348|Body}')+ '</option>' +
	'<option value="4" '+ (selected ==4 ? "selected" : "")  + '>' + parseAndLocalizeStr('{1347|Description/Comments}')+ '</option>' +
	'</select>' +
	'</span>')
	
}
function removeFullTextZone()
{
	//hide the full-text zone, as this is not supported for task/event searches
	var search = document.getElementById('div-p-full-text-zone');
	if (search)
	{
		search.style.display = 'none';
	}
}
function getSearchFor(id, defaultVal, style, readOnly)
{
	return "<select id='" + id + "' name='" + id + "'" + (style ? " style='" + style + "'"  : "") + (readOnly ? " disabled" : "") + ">" +
			"<option value='imSearchEmailOrDocuments' " + (! defaultVal || defaultVal == "imSearchEmailOrDocuments" ? "selected='selected'" : "") + ">" + getLocStrByLID(625, "Documents/Emails") + "</option>" +
			"<option value='imSearchEmailOnly' " + (defaultVal == "imSearchEmailOnly" ? "selected='selected'" : "") + ">" + getLocStrByLID(626, "Emails") + "</option>" +
			"<option value='imSearchDocumentsOnly' " + (defaultVal == "imSearchDocumentsOnly" ? "selected='selected'" : "") + ">" + getLocStrByLID(555, "Documents") + "</option>" +
		"</select>";
}

function removeRelation(parentId, childIds)
{
	var url = virtualPath() + "/scripts/DocRemoveRelation.aspx?"
	url = setURLParam(url, "parent", escape(parentId));
	url = setURLParam(url, "children", escape(childIds));
	url = setURLParam(url, "redirect", escape(page.getRedirect()));
	
	window.location.href = url;
}

function Validator(str)
{
	this.data = str
	this.List = new Array();
	this.List[this.List.length] = "abstract"
	this.List[this.List.length] = "event"
	this.List[this.List.length] = "new"
	this.List[this.List.length] = "as"
	this.List[this.List.length] = "null"
	this.List[this.List.length] = "switch"
	this.List[this.List.length] = "base"
	this.List[this.List.length] = "object"
	this.List[this.List.length] = "this"
	this.List[this.List.length] = "bool"
	this.List[this.List.length] = "false"
	this.List[this.List.length] = "operator"
	this.List[this.List.length] = "throw"
	this.List[this.List.length] = "break"
	this.List[this.List.length] = "finally"
	this.List[this.List.length] = "out"
	this.List[this.List.length] = "true"
	this.List[this.List.length] = "byte"
	this.List[this.List.length] = "fixed"
	this.List[this.List.length] = "try"
	this.List[this.List.length] = "case"
	this.List[this.List.length] = "float"
	this.List[this.List.length] = "params"
	this.List[this.List.length] = "typeof"
	this.List[this.List.length] = "catch"
	this.List[this.List.length] = "for"
	this.List[this.List.length] = "private"
	this.List[this.List.length] = "uint"
	this.List[this.List.length] = "char"
	this.List[this.List.length] = "foreach"
	this.List[this.List.length] = "protected"
	this.List[this.List.length] = "ulong"
	this.List[this.List.length] = "unchecked"
	this.List[this.List.length] = "checked"
	this.List[this.List.length] = "goto"
	this.List[this.List.length] = "public"
	this.List[this.List.length] = "class"
	this.List[this.List.length] = "if"
	this.List[this.List.length] = "readonly"
	this.List[this.List.length] = "unsafe"
	this.List[this.List.length] = "const"
	this.List[this.List.length] = "implicit"
	this.List[this.List.length] = "ref"
	this.List[this.List.length] = "continue"
	this.List[this.List.length] = "in"
	this.List[this.List.length] = "return"
	this.List[this.List.length] = "using"
	this.List[this.List.length] = "decimal"
	this.List[this.List.length] = "int"
	this.List[this.List.length] = "sbyte"
	this.List[this.List.length] = "virtual"
	this.List[this.List.length] = "default"
	this.List[this.List.length] = "interface"
	this.List[this.List.length] = "sealed"
	this.List[this.List.length] = "volatile"
	this.List[this.List.length] = "delegate"
	this.List[this.List.length] = "internal"
	this.List[this.List.length] = "short"
	this.List[this.List.length] = "void"
	this.List[this.List.length] = "do"
	this.List[this.List.length] = "is"
	this.List[this.List.length] = "sizeof"
	this.List[this.List.length] = "while"
	this.List[this.List.length] = "double"
	this.List[this.List.length] = "lock"
	this.List[this.List.length] = "stackalloc"
	this.List[this.List.length] = "else"
	this.List[this.List.length] = "long"
	this.List[this.List.length] = "static"
	this.List[this.List.length] = "datetime"
	this.List[this.List.length] = "enum"
	this.List[this.List.length] = "namespace"
	this.List[this.List.length] = "string"
	this.List[this.List.length] = "ioptions"
	this.List[this.List.length] = "options"
	this.List[this.List.length] = "globaloptions"
	this.List[this.List.length] = "useroptions"
	this.List[this.List.length] = "instanceoptions"
	this.List[this.List.length] = "defaultproperties"
	this.IsKeyword = Validator_IsKeyword
	this.HasSpecialCharacters= Validator_HasSpecialCharacters
	this.IsEmpty= Validator_IsEmpty
	
}

function Validator_IsEmpty()
{
	if(!this.data || this.data == "")
	{
		return true;
	}
	
	return false;
}
function Validator_IsKeyword()
{	
	if(!this.data) return false;
	var str = this.data.toLowerCase();
	for(var i=0; i < this.List.length; i++)
	{	 
		if(str == this.List[i])
		{
			return true;
		}	
	}
	return false;
}
 
 
 function Validator_HasSpecialCharacters()
 {
	var regExp = /^[a-z__][a-z_0-9]*/i
	if (this.data.search(regExp) ==-1) 
	{
		return true;
	}
				
	regExp = /[\`\~\!\@\#\$\%\^\&\*\(\)\+\'\"\:\;\?\,\<\>]+/
	
	if (this.data.search(regExp)!=-1) 
	{
		return true;
	}	
			
	if (this.data.match(" ")) {
		return true;
	}				
	return false;
 }
 
 
 function writeSearchButton(formName, buttonOnBottom)
 {
		document.write("<table  width='100%' align='right' border='0' cellpadding='0' cellspacing='2'>")
		if(!buttonOnBottom) {
			document.write('<tr><td  colspan="3" nowrap class="section-header-border"><img src="../images/pixel.gif" width="1" height="1" alt="" border="0"></td></tr>')
			document.write('<tr><td  colspan="3" nowrap><img src="../images/pixel.gif" width="1" height="1" alt="" border="0"></td></tr>')
		}
		document.write('<tr><td></td><td width="1%">')
		document.write(getButtonHTML(parseAndLocalizeStr("{247|Search}") ,"javascript:validateAdvancedSearch('" +formName + "')",parseAndLocalizeStr("{1327|Begin search}")))
		//document.write('</td><td width="1%">')
		//document.write(getButtonHTML(parseAndLocalizeStr("{211|Cancel}") ,"javascript:doAdvancedSearchCancel()",parseAndLocalizeStr("{1327|Begin search}")))		
		document.write("</td></tr>")

		if(buttonOnBottom) {
			document.write('<tr><td  colspan="3" nowrap><img src="../images/pixel.gif" width="1" height="1" alt="" border="0"></td></tr>')
			document.write('<tr><td  colspan="3" nowrap class="section-header-border"><img src="../images/pixel.gif" width="1" height="1" alt="" border="0"></td></tr>')
		}
		document.write("</table>")
		
 }
 
 function doAdvancedSearchCancel()
 {
	var url
	if(document.fm){
		if(document.fm.redirect) {
			url  = unescape(document.fm.redirect.value)
		}	
	}
	if(!url || url == "") {
		url = virtualPath() + "/scripts/home.aspx"
	 }
	window.location.href = url
 }
 
 function doMoreSearch(formName) {
	formName = formName ? formName : "fm"
	var fm = document.forms(formName);
	if(fm.tabid) {
		fm.tabid.value = page.getTabObj().getSelection() 
	}
	var  queryString = constructAdvancedSearyQuery(formName)
	//fix for 22084:  More button does not work on adhoc searches (NS, 3/15/04)
	queryString = setURLParam(queryString, 'more', '1')
	window.location.href = queryString
 }
 
 function constructAdvancedSearyQuery(formName) {
	formName = formName ? formName : "fm"
 	var fm = document.forms(formName)
 	if(fm.redirect)
 	{
		fm.redirect.value = escape(fm.redirect.value)
	}
	var queryString = virtualPath() + "/scripts/" + fm.action  + (fm.action.indexOf("?") !=-1 ? "" : "?")
	
	for(var i=0; i < fm.elements.length; i++){
		var element = fm.elements[i]
			if(element.value !='') {
				queryString +="&" + element.name + "=" + element.value
			}				
	}
	return queryString
 }

 function validateAdvancedSearch(formName) {
	formName = formName ? formName : "fm"
  	var fm = document.forms(formName);
  	var opNum = Number(fm.op.value) 
	fm.op.value = (opNum == searchesEnums.AdvancedSearch)  ?  searchesEnums.AdvancedSearchResult : ( (opNum == searchesEnums.SavedForm) ? searchesEnums.SavedFormResult : fm.op.value);
	fm.tabid.value = page.getTabObj().getSelection() 
	window.location.href = constructAdvancedSearyQuery(formName)
 }
 
 
 function SearchesEnums()
 {
 	var obj = new Object()
 	obj.None					= 0x00000000
 	obj.QuickSearch				= 0x00000001
	obj.AdvancedSearch			= 0x00000002
	obj.AdvancedSearchResult	= 0x00000004
	obj.QuickSearchResult		= 0x00000008
	obj.SavedForm				= 0x00000010
	obj.SavedFormResult			= 0x00000020
	obj.All						= 0x7FFFFFFF
	return obj
 }

 var searchesEnums = SearchesEnums()
 
 function RedirectToRefile()
 {
	if ( document.fm.refileYes.checked )
	{
		window.location.href =  "RefileEdit.aspx?nrtid=" +  document.fm.nrtid.value + "&parent=" + document.fm.parent.value  + "&redirect=" + document.fm.redirect.value;
	}
	else
	{
		dialog.doCancel();
	}
 }
 
 

function getDatabaseValueforLookup(formName)
{
	var databaseName = ""
	databaseField = document.forms[formName].elements["p-database"]					
	if(!databaseField) 
	{
		databaseField = document.forms[formName].elements["pdatabase"]							    
	}			

	if (databaseField) 
	{
		var objType = databaseField.type
		if (objType == "select-one" || objType == "select-multiple" ) 
		{
			var selectedIndex = databaseField.selectedIndex
			if (selectedIndex > -1) 
			{
				databaseName = databaseField.options[selectedIndex].value
			}
		}
		else 
		{
			databaseName = databaseField.value
		}
	}	

	return databaseName
} 

function specialGroupPicker(formName, fieldID){	
	var domObject = document.getElementById("lookupApplet")
	var scriptName = domObject.getAttribute("scriptName");
	var title = getLocalizedString('208|New Group')
	var aclType = 'G'
	var database = getDatabaseValueforLookup(formName)
	window.specialPickerFormName = formName
	var url = 'singlePickerDialog.aspx?title=' + title + '&aclType='+ aclType +'&scriptName='+ escape(scriptName) +'&database='+ database +'&minSecurityLevel=1&maxSecurityLevel=3&roleInfo=&showAccessInfo=&lookupCallback=getDataCallback&copySecurityCallback=iman_picker_copySecResCallBack&context=accessList&fieldID='+fieldID		
	var wnd = openWindow(url,'',400,300);
}

function doThemePreview()
{
	//this function assumes default form name to be fm
	var themeName = document.fm.theme.options[document.fm.theme.selectedIndex].value
	var url = '../scripts/showTheme.aspx?name=' + themeName
	var ieFeatures = 'dialogHeight:600px; dialogWidth:785px'
	
	self.showModalDialog(url,'',ieFeatures)
	//self.openWindow(url, '', '')
}					

function TrustedLoginStates()
{
	var obj = new Object();

	obj.None = 0;
	obj.Login = 1;
	obj.Auto = 2;
	obj.Logout = 4;

	return obj;
}

function TrustedLoginCookie()
{
	var obj = new Object();
	
	obj.cookieName = "trustedLogin";
	obj.getState = TrustedLoginCookie_getState;
	obj.setState = TrustedLoginCookie_setState;
	
	return obj;
}

function TrustedLoginCookie_getState()
{
	var state = Number(getCookie(this.cookieName));
	return state == Number.NaN ? 0 : state;
}

function TrustedLoginCookie_setState(newState)
{
	setCookie("trustedlogin", "", -1);
	setCookie(this.cookieName, newState, 30);
}




