/* ***************************************************************** */
/*                                                                   */
/* IBM Confidential                                                  */
/*                                                                   */
/* OCO Source Materials                                              */
/*                                                                   */
/* Copyright IBM Corp. 2007, 2010                                    */
/*                                                                   */
/* The source code for this program is not published or otherwise    */
/* divested of its trade secrets, irrespective of what has been      */
/* deposited with the U.S. Copyright Office.                         */
/*                                                                   */
/* ***************************************************************** */


/* 5724-S31                                                          */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */
/*                                                                   */
/*********************************************************************/




var QuickrLocaleUtil = {
	resource: null,
	aResourceIndex: new Array(),
	aResourceById: new Array(),
	
	
	_stringLocale: new Array(),
	_styleLocale: new Array(),
		
	_STRINGLOCALECOOKIE: "QuickrStringLocale",
	_STYLELOCALECOOKIE: "QuickrStyleLocale",
	_ACCEPTLANGCOOKIE: "QuickrAcceptLanguages",
	
	loadLocale: function() {

		var acceptLangs = (navigator.language ? navigator.language : navigator.userLanguage);
		var bReload = false;

		if (typeof(QuickrCGIVariables)!="undefined" && (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE)) {
			acceptLangs = (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE);
		}

		if ( QuickrCookieUtil.hasCookie(this._ACCEPTLANGCOOKIE) ) {
			if (acceptLangs != QuickrCookieUtil.getCookie(this._ACCEPTLANGCOOKIE)) {
				bReload=true;
				QuickrCookieUtil.setCookie(this._ACCEPTLANGCOOKIE, acceptLangs);
			}
        }
        else {
			QuickrCookieUtil.setCookie(this._ACCEPTLANGCOOKIE, acceptLangs);
		}

		if (!bReload && QuickrCookieUtil.hasCookie(this._STRINGLOCALECOOKIE) ) {
			this._stringLocale = QuickrCookieUtil.getCookie(this._STRINGLOCALECOOKIE).split(",");
        }
        else {
			this.loadLocaleForTarget("/qphtml/skins/common", "QuickrCommonStrings.js", this._stringLocale, this._STRINGLOCALECOOKIE);
		}
		
		if (!bReload &&  QuickrCookieUtil.hasCookie(this._STYLELOCALECOOKIE) ) {
			this._styleLocale = QuickrCookieUtil.getCookie(this._STYLELOCALECOOKIE).split(",");
        }
        else {
			this.loadLocaleForTarget("/qphtml/skins/common/themes", "core.css", this._styleLocale, this._STYLELOCALECOOKIE);
		}
	
	},
	
    getSupportLocale: function(sSupportLocale, sDefaultLocale) {

        var supportLocaleList = sSupportLocale.toLowerCase().split(",");
        var supportLocaleMap = new Object();
        for (var i = 0; i < supportLocaleList.length; i++) {
            supportLocaleMap[supportLocaleList[i]] = supportLocaleList[i];
        }
        var acceptLangs = "";
        if (typeof (QuickrCGIVariables) != "undefined" && (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE)) {
            acceptLangs = (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE);
        }
        var langsSection = acceptLangs.toLowerCase().split(",");
        if (typeof (langsSection) != "undefined" && langsSection.length > 0) {
            for (var i = 0; i < langsSection.length; i++) {
                var temp = langsSection[i].split(";");
                var locale = temp[0].replace("_", "-");
                if (typeof (supportLocaleMap[locale]) != "undefined")
                    return locale;
                var lang = locale.split("-");
                if (typeof (supportLocaleMap[lang[0]]) != "undefined") {
                    return lang[0];
                }
            }
        }
        return sDefaultLocale;

    },

	loadLocaleForTarget: function(sbase, sname, atarget, scookie) {

        if (typeof(sbase) == "undefined") 
            sbase = "/qphtml/skins/common/themes";
        if (typeof(sname) == "undefined") 
            sname = "core.css";
        if (typeof(atarget) == "undefined") 
            atarget = this._styleLocale;
        if (typeof(scookie) == "undefined") 
            scookie = this._STYLELOCALECOOKIE;
		
		
		var curLanguages = QuickrLocaleUtil.buildLanguageList();
		
		var rootUrl = QuickrGeneralUtil.getRootUrl();
		

		for (var i = 0; i < curLanguages.length; i++) {
			var locale = curLanguages[i].toLowerCase();
			
			// special case for Bokmaal & Nynorsk
            if (locale == "nb-no" || locale == "nn-no") 
                locale = "no";
			
			var testurl = rootUrl + sbase + "/nls/" + locale + "/" + sname;

            QuickrXMLUtil.fireAjaxRequest(testurl, function(data, url){ //load
					var lang = url.substring(0,url.lastIndexOf("/"))
					lang = lang.substring(lang.lastIndexOf("/")+1);
					
					atarget.push(lang.toLowerCase());
					
					
            }, 5, null, null, true)
		
		}
		
		QuickrCookieUtil.setCookie(scookie, atarget.join(","));
	
	},
	
	
	

	
	loadStringFiles: function( sid, sbase, sname ) {
		var langs = this.getStringLocaleList();
		
		
		//set the languages we found
		djConfig.locale = langs[0]; //this.getSupportLocale("en,ar,da,de,el,es,fi,fr,it,iw,ja,ko,nl,no,pt,pt-br,sv,tr,zh,zh-tw", "en");
		djConfig.extraLocale = langs;
		
		dojo.locale = djConfig.locale;
		dojo.extraLocale = langs;
		
		
		
		
		//to be used for localization	
		dojo.require("dojo.i18n");
		
		dojo.registerModulePath(sid, sbase);
		
		dojo.requireLocalization(sid, sname);
		
		
		//first, let's set the current resource file
		this.resource = dojo.i18n.getLocalization(sid, sname);
		
		/*********************************
		* load any string objects into an array so we can
		* handle multiple ones on the same page.
		* 
		* We maintain two arrays:
		* 1 - so that we can loop thru all of them
		* 2 - so the client can specify the id of the string object
		*********************************/
		this.aResourceIndex[this.aResourceIndex.length] = this.resource;
		this.aResourceById[sid] = this.resource;
		
	},
	
	useOneUIV2: function() {
		//TODO - use the field flag instead of looking at the name...
		return (typeof theme_name != "undefined" && (theme_name=="quickr85" || theme_name=="quickr"));
	},
	
	useBidi: function() {
		var useLang = ( QuickrLocaleUtil.getStyleLocaleList() )[0];
		return ( useLang == "he" || useLang == "ar" );
	},
	
	loadCssFiles: function (sThemePath, sThemeCss) {
		
		var head = document.getElementsByTagName("head");
		if (head && head[0]) {
		
			//remove any legacy CSS files.  We're starting new!!!
			var linktags = head[0].getElementsByTagName("link");
			var cssRemove = new Array();
			if (linktags) {
				for (var i = 0; i < linktags.length; i++) {
					var linktag = linktags[i];
					if (linktag.type == "text/css" && linktag.href.indexOf("&Form=h_StyleSheet")> -1) {
						cssRemove[cssRemove.length] = linktag;
					}
				}
			}
			
			
			//load the css file names into this list
			var cssList = new Array();
			
			if ( QuickrLocaleUtil.useOneUIV2() ) {
			
				//code to correct IE6 not rendering styles when we dyanmically reassign stylesheets
				if (h_ClientBrowser.isIE6() && typeof(sThemeCss) != "undefined" && sThemeCss != null) {
					cssList.push( sThemePath + "/themes/" + sThemeCss );
				}				
				
				//load oneui theme css
				var CSSCOMMON_BASE = "/qphtml/skins/common/themes/oneuiv2/";
				
				var sSuffix = ( QuickrLocaleUtil.useBidi() ) ? "RTL" : "";
				
				cssList.push( CSSCOMMON_BASE + "base/core" + sSuffix + ".css" );
				cssList.push( CSSCOMMON_BASE + "base/dojo" + sSuffix + ".css" );
				
				//How does RTL effect these three css files?
				cssList.push( "/domjs/dojo-1.3.2/dijit/themes/dijit.css" );
				if (QuickrLocaleUtil.useBidi()) {
					cssList.push( "/domjs/dojo-1.3.2/dijit/themes/dijit_rtl.css" );
				}
                cssList.push("/qphtml/ecmintg/css/picker.css");
				
				cssList.push( CSSCOMMON_BASE + "defaultTheme/defaultTheme" + sSuffix + ".css" );
				cssList.push( CSSCOMMON_BASE + "defaultTheme/dojoTheme" + sSuffix + ".css" );
				
				//loading theme css file
				if (typeof(sThemeCss) != "undefined" && sThemeCss != null) {
					cssList.push( sThemePath + "/themes/" + sThemeCss );
				}
				
					
            }
            else {
				var useLang = ( QuickrLocaleUtil.getStyleLocaleList() )[0];
				
				//code to correct IE6 not rendering styles when we dyanmically reassign stylesheets
				if (h_ClientBrowser.isIE6() && typeof(sThemeCss) != "undefined" && sThemeCss != null) {
					cssList.push( sThemePath + "/nls/" + useLang + "/" + sThemeCss );
				}				
				
				//load oneui theme css
				var CSSCOMMON_BASE = "/qphtml/skins/common/themes/nls/" + useLang + "/";			

				cssList.push( CSSCOMMON_BASE + "core.css" );
				cssList.push( CSSCOMMON_BASE + "defaultTheme.css" );
				if ( h_ClientBrowser && h_ClientBrowser.isIE() ) {
					cssList.push( CSSCOMMON_BASE + "iehacks.css" );
				}
				//Adding person card css
				//load oneui theme css
				var CSSCOMMON_BASE_ONEUI = "/qphtml/skins/common/themes/oneuiv2/";
				var sSuffix = ( QuickrLocaleUtil.useBidi() ) ? "RTL" : "";
				cssList.push( CSSCOMMON_BASE_ONEUI + "base/standaloneVcard" + sSuffix + ".css" );
				
				//loading theme css file
				if (typeof(sThemeCss) != "undefined" && sThemeCss != null) {
					cssList.push( sThemePath + "/nls/" + useLang + "/" + sThemeCss );
				}

			}
			

			
			
			if (G_UseServletForPerformance) {
				var tmpList = cssList.join(";");
				cssList.length = 1;
				cssList[0] = QuickrGeneralUtil.getServletRoot() + "/QuickrSupportUtil?type=combinestyles&key=" + tmpList;
			}

			for (var ii = 0; ii < cssList.length; ii++) {
				var skinCss = document.createElement("link");
				skinCss.rel = ("stylesheet");
				skinCss.type = ("text/css");
				skinCss.href = (cssList[ii]);
				head[0].appendChild(skinCss);
			}
		
			for (var ii = 0; ii < cssRemove.length; ii++) {
				cssRemove[ii].parentNode.removeChild(cssRemove[ii]);
			}
			
			
		}
	
        // Load IE style tweaks if running in IE
        if (h_ClientBrowser.isIE()) {
            if (h_ClientBrowser.isIE6()) {
                document.getElementsByTagName("html")[0].className += " lotusui_ie lotusui_ie6";
            }
            else 
                if (h_ClientBrowser.isIE7()) {
                    document.getElementsByTagName("html")[0].className += " lotusui_ie lotusui_ie7";
                }               
        }
	},
	
	getStringLocaleList: function() {
		if (this._stringLocale.length == 0) {
			this.loadLocale();
		}
		return this._stringLocale.concat();		
	},
	
	getStyleLocaleList: function() {
		if (this._styleLocale.length == 0) {
			this.loadLocale();
		}
		return this._styleLocale.concat();		
	},	
	
	getAcceptLangList: function() {
		var acceptLangs = (navigator.language ? navigator.language : navigator.userLanguage);
		var bReload = false;

		if (typeof(QuickrCGIVariables)!="undefined" && (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE)) {
			acceptLangs = (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE);
		}

		if ( QuickrCookieUtil.hasCookie(this._ACCEPTLANGCOOKIE) ) {
			if (acceptLangs != QuickrCookieUtil.getCookie(this._ACCEPTLANGCOOKIE)) {
				bReload=true;
				QuickrCookieUtil.setCookie(this._ACCEPTLANGCOOKIE, acceptLangs);
			}
        }
        else {
			QuickrCookieUtil.setCookie(this._ACCEPTLANGCOOKIE, acceptLangs);
		}
		var langsSection = acceptLangs.split(";");
		if (typeof(langsSection) != "undefined" && langsSection.length > 0) {
			var lang = langsSection[0];
			return lang.split(",");
		}
		var defaultLangs = ["en"];
		return defaultLangs;
	},
	
	buildLanguageList: function() {
	
		var curLanguages = new Array();
		
		var sAllList = ";";
		
		var sDefault = "en";
		

		if (typeof(QuickrCGIVariables)!="undefined" && (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE)) {

			var tempLanguages = (QuickrCGIVariables.HTTP_Accept_language || QuickrCGIVariables.HTTP_ACCEPT_LANGUAGE).split(",");
			for (var i = 0; i < tempLanguages.length; i++) {
				if (tempLanguages[i].indexOf(";") > -1) {
					tempLanguages[i] = tempLanguages[i].split(";")[0];
				}
				
				if (sAllList.indexOf(";" + tempLanguages[i] + ";") == -1) {
					curLanguages.push(tempLanguages[i]);
					sAllList += tempLanguages[i] + ";";
				}

				if (tempLanguages[i].indexOf("-") > -1) {
					var subLang = tempLanguages[i].split("-")[0];
					if (sAllList.indexOf(";" + subLang + ";") == -1) {
						curLanguages.push(subLang);
						sAllList += subLang + ";";
					}
				}
				
								

			}
			
			if (sAllList.indexOf(";" + sDefault + ";") == -1) {
				curLanguages.push(sDefault);
				sAllList += sDefault + ";";
			}

        }
        else {
			curLanguages.push(sDefault);
		}
		
		
		return curLanguages;

	},
	
	loadScriptObject: function(idx) {

		var urlCgiScript = QuickrGeneralUtil.getServletRoot() + "/QuickrSupportUtil?type=quickrvariables";
		
		if ( navigator.userAgent.indexOf("Safari") > -1 ) {  //if it's safari, make sure the servlet is loaded on the server
			try {
			
			dojo.xhrGet({
				url: urlCgiScript,
				sync: true,
				handleAs: "text",
				load: function(response, ioArgs) {
					document.getElementById(idx).src = urlCgiScript;
				},
				error: function(response, ioArgs ) {
				}			

			});
			
			}
			catch(e) {
			}
        }
        else {
			document.getElementById(idx).src = urlCgiScript;
		}
	
	},
	
	getStringResource: function(sResName, sResGroupId) {
		var ret = null;
		
		//if someone passed in the id of the string object, try to use it.
		if ( !QuickrGeneralUtil.isBlank(sResGroupId) ) {
			try {
				ret = eval("QuickrLocaleUtil.aResourceById[\"" + sResGroupId + "\"]." + sResName);
            } 
            catch (exResource) {
            }
		}
		
		if (this.aResourceIndex.length <= 0) {
			QuickrLocaleUtil.loadStringFiles("common", "/qphtml/skins/common", "QuickrCommonStrings");
		}
		
		//if not found already, loop through all the string objects to find them...
		if ( this.aResourceIndex.length > 0 && (QuickrGeneralUtil.isBlank(ret)) ) {
			for (var i = this.aResourceIndex.length - 1; i >= 0 ; i--) {
				try {
					ret = eval("QuickrLocaleUtil.aResourceIndex[" + i + "]." + sResName);
                } 
                catch (exResource) {
                }
				
				if ( !QuickrGeneralUtil.isBlank(ret) ) {
					break;				
				}
			}
		}
		
		//not found at all, return the key with some asterisks to flag it for fixing...
		if ( QuickrGeneralUtil.isBlank(ret) ) {
			ret = "** " + sResName + " **";
		}
		return ret;
	
	},
	
	processLocalizedStringsInStr: function(str) {
		QuickrLocaleUtil.loadStringFiles("common", "/qphtml/skins/common", "QuickrCommonStrings");
		var STRING_START = "@@[";
		var STRING_END = "]@@";
		
		var proc = str;
		var ret = "";
		var arr = proc.split(STRING_START);

		for (var i = 0; i < arr.length; i++) {
			if (arr[i].indexOf(STRING_END) > -1) {
				var arr2 = arr[i].split(STRING_END);

				if (arr2[0].indexOf("QuickrLocaleUtil.resource.") != 0) {
					arr2[0] = "QuickrLocaleUtil.resource." + arr2[0];
				}

				var tmpEval = null;
				try {
					tmpEval = eval(arr2[0]);
                } 
                catch (e1) {
                }

				if (typeof(tmpEval) == "undefined" || tmpEval == null) {
					tmpEval = "**" + arr2[0] + "**";
				}

				ret += tmpEval + arr2[1];																		
			} 
            else {
				ret += arr[i];
			}
		}
		return ret;
	},
	
	processLocalizedStringsOnPage: function() {

		/*********************************************
		* This function goes through the innerHTML of
		* the body to replace the string references
		* to the localized strings.
		* String format in htm file:
		* @@[QuickrEntryStrings.StringName]@@
		*********************************************/
		var STRING_START = "@@[";
		var STRING_END = "]@@";

		//SPR#TORI79ENTF
		var elements = document.body.getElementsByTagName("*");
		var length = elements.length;
		var current;
        for (var j = 0; j < length; j++) {
			current = elements[j];

            if (current.innerHTML.indexOf(STRING_END) > -1) {

				var proc = current.innerHTML;
				var ret = "";
				var arr = proc.split(STRING_START);

				for (var i = 0; i < arr.length; i++) {
					if (arr[i].indexOf(STRING_END) > -1) {
						var arr2 = arr[i].split(STRING_END);

						if (arr2[0].indexOf("QuickrLocaleUtil.resource.") != 0) {
							arr2[0] = "QuickrLocaleUtil.resource." + arr2[0];
						}

						var tmpEval = null;

						try {
							if (arr[i-1].substring(arr[i-1].length-1) == "\"" && arr2[1].substring(0,1) == "\"") {
								tmpEval = eval(arr2[0]);
                            }
                            else {
								tmpEval = "\"" + eval(arr2[0]) + "\"";
							}
                        } 
                        catch (e1) {
                        }

						if (typeof(tmpEval) == "undefined" || tmpEval == null) {
							tmpEval = "**" + arr2[0] + "**";
						}

						ret += tmpEval + arr2[1];																		
					} 
                    else {
						ret += arr[i];
					}
				}
				current.innerHTML = ret;
			}
		}


		//any font tag with the class of "locallizedtext" needs to be pulled and the strings need to be replaced.
		var loc = QuickrGeneralUtil.getElementsByClassName("localizedtext","font");

		if (loc) {
			for (var i = loc.length - 1; i >=0; i--) {
				var att  = loc[i].getAttribute("key");

				if (att) {
                }
                else {
					att = loc[i].innerHTML;
				}

				if (att && att.length > 0) {
					if (att.indexOf("QuickrLocaleUtil.resource.") != 0) {
						att = "QuickrLocaleUtil.resource." + att;
					}

					var newstring = null;

					try {
						newstring = eval(att);
                    } 
                    catch (e2) {
                    }

					if (typeof(newstring) == "undefined" || newstring == null) {
						newstring = "**" + att + "**";
					}

					var el = null;

					//if the string contains tags, we need to set the innerhtml so the browser knows it's not just text
					if (newstring.indexOf("<") > -1 && newstring.indexOf(">") > -1) {
						var el = document.createElement("span");
						el.innerHTML = newstring;
                    }
                    else {
						var el = document.createTextNode(newstring);
					}

					loc[i].parentNode.insertBefore(el, loc[i]);
					loc[i].parentNode.removeChild(loc[i]);					
				}
			}

		}

	}
	
	

}



var QuickrGeneralUtil = {

	_defaultServletRoot: "/servlet",
	
	getJunctionString: function() {  //used to get the TAM Junction string for mapping...
		var ret = "";
		if (typeof window.G_JunctionLoc == "undefined") {
			var loc = window.location.href;
			if (typeof G_haikuBaseUrl == "string" && loc.indexOf(G_haikuBaseUrl) > -1) {
				loc = loc.substring(loc.indexOf("//") + 2);
				loc = loc.substring(loc.indexOf("/") + 1);		
				loc = loc.substring(0, loc.indexOf(G_haikuBaseUrl) - 1);
                if (loc.length > 0) 
                    ret = "/" + loc;
            }
        }
        else {
			ret = window.G_JunctionLoc;
		}
		return ret;		
	},	
	
	getServletRoot: function() {
		if (typeof window.G_ServletLoc == "undefined") {
			return QuickrGeneralUtil.getJunctionString() + QuickrGeneralUtil._defaultServletRoot;
        }
        else {
			return window.G_ServletLoc;
		}
	},
	
	getDownloadLink: function(docid, fileName, viewName) {
        if (typeof viewName == "undefined" || viewName == null) 
            viewName = "0";
		
		var encFileName = fileName;
		try {
			encFileName = decodeURIComponent(encFileName);
        } 
        catch (e) {
        }

		encFileName = encodeURIComponent(encFileName);
		encFileName = encFileName.replace(new RegExp("\#","g"),"%23");
		encFileName = encFileName.replace(/\%26amp\%3B/gi,"%26");

		var sBase = QuickrGeneralUtil.getBaseUrl();
		sBase = sBase.substring(sBase.indexOf("//")+2);
		sBase = sBase.substring(sBase.indexOf("/"));


		var url = "";
		if ( G_UseServletForDownload && !h_ClientBrowser.isSafari() ) {
			url += QuickrGeneralUtil.getServletRoot() + "/QuickrSupportUtil?type=quickrdownload&key=";
			
			encFileName = encodeURIComponent(encFileName);
			
			//remove the TAM junction because this connection will go directly to the server from the server
			var sJun = QuickrGeneralUtil.getJunctionString();
            if (sJun.length > 0) 
                sBase = sBase.replace(new RegExp(sJun, ""), "");
		}


		url += sBase + "/" + viewName + "/" + docid + "/$file/" + encFileName;


		return url;
	
	},
	
	//Used to tell if it is an office form
	isOfficeOrImportForm: function(sForm) {
		var ret = false;
		if (typeof G_FormIDs != "undefined") {
			ret = (		sForm == G_FormIDs.HTMLPageFormUNID || 
					sForm == G_FormIDs.MultipleImportFormUNID || 
					sForm == G_FormIDs.CreateMSWordFormUNID || 
					sForm == G_FormIDs.CreateMSExcelFormUNID || 
					sForm == G_FormIDs.CreateMSPowerPointFormUNID || 
					sForm == G_FormIDs.CreateOOWriterFormUNID || 
					sForm == G_FormIDs.CreateOOCalcFormUNID || 
            sForm == G_FormIDs.CreateOOImpressFormUNID);
		}

		return ret;
	},
	
	//Is the file name an internally generated one of one attached by the user
	isInternalFileName: function(sName, sForm) {
		if (typeof sForm == "undefined" || sForm == null) {
			if (typeof window.h_Form != "undefined") {
				sForm = window.h_Form;
            }
            else {
				sForm = "";
			}
		}

		var ret = (sName.search(/^TMP[0-9]{2}.*\.[gjch]/i) >= 0);

		// SPR#DAMY83KKLN
		if ( !ret ) { //&& QuickrGeneralUtil.isOfficeOrImportForm(sForm) ) {
			ret = (sName.search(/^image[0-9][0-9][0-9].[gif|jpg|jpeg|bmp|png]/i) >= 0);
		}

		return ret;
	},	
	
	
	loadSupplementalScript: function(sLocation, bCacheCompliant) {
        if (typeof bCacheCompliant == "undefined") 
            bCacheCompliant = false;
	
		if (bCacheCompliant && typeof G_CacheCompliantUrlTemplate != "undefined" && sLocation.indexOf("?") == -1) {
			sLocation = QuickrGeneralUtil.decodeEntities(G_CacheCompliantUrlTemplate).replace("{0}", sLocation);
		}
		
		//load an external js file
		/*
		var oExtObj = document.createElement("script");
		oExtObj.setAttribute("src", sLocation);
		oExtObj.setAttribute("type", "text/javascript");
		var oHeadLoc = document.getElementsByTagName("head")[0];
		if (oHeadLoc) oHeadLoc.appendChild(oExtObj);
		*/
		document.write("<script type=\"text/javascript\" src=\"" + sLocation + "\"><\/script>");
	},	
		
	
	loadCGIVariables: function(sid) {
		var targ = document.getElementById(sid);
		
		if (targ) {
			targ.src = this.getBaseUrl() + "/h_CGIVariables?Open";
		}
	
	},

	getBaseUrl: function () {
		var ret = "";
		
		var loc = window.location.href;
		var loc_l = loc.toLowerCase();
		var idx = loc_l.indexOf(".nsf");
		
		if (idx > -1) {
			ret = loc.substring(0, idx+4);
		}
		
		return ret;
	},
	
	getRootUrl: function() {
		var loc = window.location.href + ":///";
		var p1 = loc.substring(0, loc.indexOf("://") + 3);
		
		loc = loc.substring(loc.indexOf("://") + 3);
		var p2 = loc.substring(0, loc.indexOf("/"));
		
		return p1 + p2;
		
	},
	
	
    getNodeValue: function(node, idx, key){
        if (typeof(idx) == "undefined" || idx == null) 
            idx = 0;
        if (typeof(key) == "undefined" || key == null) 
            key = "text";


		var ret = "";
		var x = node[idx];
		if (x) {
			var y = x.getElementsByTagName(key);
			if (y && y[0] && y[0].firstChild) {
				ret = x.getElementsByTagName(key)[0].firstChild.nodeValue;
			}
		}

		return ret;
	},
	
	hideClassesIfTrue: function (classname, tf, bVisibility) {
		var bVis=(typeof(bVisibility)=="undefined" ? false : bVisibility);
		if ( tf ) {
			var els = QuickrGeneralUtil.getElementsByClassName(classname);
			if (els) {
				for (var i = 0; i < els.length; i++) {
					if (bVis) {
						// just make invisible
						els[i].style.height = "0";
						els[i].style.padding = "0";
						els[i].style.margin = "0";
					}
					else {
						// complete visual removal
						els[i].style.display = "none";
					}
				}
			}
		}	
	},

	showClassesIfTrue: function (classname, tf) {
		if ( tf ) {
			var els = QuickrGeneralUtil.getElementsByClassName(classname);
			if (els) {
				for (var i = 0; i < els.length; i++) {
					els[i].style.display = "block";
				}
			}
		}	
	},


	//supporting functions
    getElementsByClassName: function(className, tag, elm){
		var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var tag = tag || "*";
		var elm = elm || document;
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}
		return returnElements;
	},
	
	replaceQSValue: function (source, name, value) {
		var hasParam = false;
		source = "&" + source;
	
	
		idx = source.indexOf("&" + name + "=");
	
        if (idx > -1) 
            hasParam = true;
	
		if (!hasParam) {
			source += "&" + name + "=" + value;
        }
        else {
			source = source.substring(1);
			var params = source.split("&");
			source = "";
			for (var i = 0; i  < params.length; i++) {
				source += "&";
				if (params[i].indexOf(name + "=") > -1) {
					source += name + "=" + value;
                }
                else {
					source += params[i];
				}
			}
		}
	
		while (source.indexOf("&") == 0) {
			source = source.substring(1);
		}
	
		return source;
	
	},
	
	getQSValue: function (source, sname, sdefault) {
		var ret = sdefault;
		var loc = source + "&=";
	
		var idx = loc.indexOf("&"+sname+"=");
	
		if (idx > -1) {
			var sortx = loc.substring(idx);
			sortx = sortx.substring(sortx.indexOf("=")+1);
			sortx = sortx.substring(0,sortx.indexOf("&"));
	
			ret = sortx;
	
		}
	
		return ret;
	},
	
	convertToNum: function (val) {
		var decSep = haiku.h_Intl_DecimalString;
		
		var ALL_CHARS = "0123456789" + decSep;
		var ret = "";
		
		val += decSep + decSep;
		
		for (var i = 0; i < val.length; i++) {
			var chr = val.substring(i, i + 1);
			if (ALL_CHARS.indexOf(chr) > -1) {
				ret += chr;
				if (chr == decSep) {
					ALL_CHARS = "0123456789";
				}
			}
			
		}
		
		return parseFloat(ret);
	},
	
	formatBytes: function (val) {
		var BYTE_TO_KB = 1024;
		var BYTE_TO_MB = 1048576;
		var suffix = " B";
		
		var decSep = ".";
		
		
		var ret = this.convertToNum(val);
		
		if ( ret > BYTE_TO_MB ) {
			ret = ret / BYTE_TO_MB;
			suffix = " MB";
        }
        else 
		if ( ret > BYTE_TO_KB ) {
			ret = ret / BYTE_TO_KB;
			suffix = " KB";
		}
		

		
		
		ret = Math.round(ret*100)/100;
		
		var returnString = ret + suffix;
		
		if (returnString.indexOf(decSep) > -1 && decSep != haiku.h_Intl_DecimalString) {
			returnString = returnString.replace(".",haiku.h_Intl_DecimalString);
		}
		
		
		return returnString;
	
	},
	
	//if security is enabled, some of the dom preoduced has extra \ chars before quotes.  just remove them
	massageSecurityDomNode: function(node, bForce) {
		if ( typeof node == "object") {
			if (bForce || (typeof G_XSSProtectionEnabled != "undefined" && G_XSSProtectionEnabled == true) ) {
				var c = node.childNodes;
				for (var i = 0; i < c.length; i++) {
					if (c[i].nodeValue != null) {
						c[i].nodeValue = c[i].nodeValue.replace(/\\\"/g,"\"");
					}

					QuickrGeneralUtil.massageSecurityDomNode(c[i], bForce);
				}
				if (typeof c.nodeValue != "undefined") {
					c.nodeValue = c.nodeValue.replace(/\\\"/g,"\"");
				}
			}
		}
	},
	
	isBlank: function (val) {
		return (typeof(val) == "undefined" || val == "" || val == null);
	
	},
	
	c_IESPACER: " &nbsp; ",
	addIESpacingHack: function(src, stype) {  //used only in IE for BiDi LIs
        if (typeof stype == "undefined" || stype == null) 
            stype = "*";
		
		if ( h_ClientBrowser.isIE () && document.body.dir == 'rtl') {
			var aLis=src.getElementsByTagName(stype);
			for (var ii = 0; ii < aLis.length; ii++) {
				aLis[ii].innerHTML = QuickrGeneralUtil.c_IESPACER + aLis[ii].innerHTML + QuickrGeneralUtil.c_IESPACER;
			}
		}
	},
	
	isArray: function (val) {
		return (typeof val == "object" && val.constructor.toString().indexOf("Array") > -1);
	},
	
	isString: function (val) {
		return (typeof val == "string");
	},	
	
	encodeEntities: function (val) {
        if (QuickrGeneralUtil.isArray(val)) {
			for (var ii = 0; ii < val.length; ii++)
				val[ii] = QuickrGeneralUtil.encodeEntities(val[ii]);
        }
        else 
		if (QuickrGeneralUtil.isString(val)) {
			val = QuickrGeneralUtil.decodeEntities(val); //first decode whatever is there so we don't double-encode the strings...
                if ((val.indexOf("<") > -1 || val.indexOf(">") > -1 || val.indexOf("'") > -1 || val.indexOf("\"") > -1)) {
				val = val.replace(new RegExp("\&","g"),"&amp;");
				val = val.replace(new RegExp("\<","g"),"&lt;");
				val = val.replace(new RegExp("\>","g"),"&gt;");
				val = val.replace(new RegExp("\'","g"),"&#39;");
				val = val.replace(new RegExp("\"","g"),"&quot;");
			}
		}
		
		return val;
	},
	decodeEntities: function (val) {
        if (QuickrGeneralUtil.isArray(val)) {
			for (var ii = 0; ii < val.length; ii++)
				val[ii] = QuickrGeneralUtil.decodeEntities(val[ii]);
        }
        else 
            if (QuickrGeneralUtil.isString(val) && val.indexOf("&") > -1) {
			// Just in case someone encoded other than through encodeEntities() (above),
			// unwind multiple encodings of the & character here.
			while (val.indexOf("&amp;") > -1) {
				val = val.replace(new RegExp("\&amp;","g"),"&");
			}
				
			val = val.replace(new RegExp("\&lt;","g"),"<");
			val = val.replace(new RegExp("\&gt;","g"),">");
			val = val.replace(new RegExp("\&apos;","g"),"'");
			val = val.replace(new RegExp("\&\#39;","g"),"'");
			val = val.replace(new RegExp("\&quot;","g"),"\"");

		}
		return val;
	},
	
	decodeApostrophes: function (val, forceBackSlash) {
        if (typeof(forceBackSlash) == "undefined") 
            forceBackSlash = false;
        if (typeof val == "string" && val.indexOf("&") > -1) {
			val = val.replace(new RegExp("\&apos;","g"),"'");
			val = val.replace(new RegExp("\&\#39;","g"),"'");
            if (forceBackSlash) 
                val = val.replace(new RegExp("'", "g"), "\\'");
		}
		return val;
	},	
	
	encodeTag: function (src, val) {
		var ret = src;
		
		ret = ret.replace(new RegExp("  ","gi")," ");
		ret = ret.replace(new RegExp("< ","gi"),"<");
		ret = ret.replace(new RegExp("<<","gi"),"<");
		ret = ret.replace(new RegExp("<" + val,"gi"),"&lt;" + val);
		ret = ret.replace(new RegExp("<\/" + val,"gi"),"&lt;/" + val);
		
		return ret;
	},
	
	encodeAllTags: function (src) {
		var aTags = ["script","object","embed"];
		
		var ret = src;
		for (var ii = 0; ii < aTags.length; ii++) {
			ret = QuickrGeneralUtil.encodeTag(ret, aTags[ii]);
		}
		
		return ret;
	},
	
	decodeCustomFormFields: function ( aDecodeFields ) {
		for (var ii = 0; ii < aDecodeFields.length; ii++) {
			var fName = aDecodeFields[ii];
			if (typeof fieldNames[fName] == "string") {
				fieldNames[fName] = QuickrGeneralUtil.encodeAllTags(QuickrGeneralUtil.decodeEntities(fieldNames[fName]));
				window[fName] = fieldNames[fName];
			}
		}	
	},
	
	processRoomInfo: function (val) {
		
		val = QuickrGeneralUtil.decodeEntities(val);
		val = QuickrGeneralUtil.decodeEntities(val); //called twice for IE...
		val = QuickrGeneralUtil.encodeEntities(val);
		
		val = val.replace(new RegExp("var h_Room","gi"),"window.h_Room");
		
		val = val.replace(new RegExp("new Array[(]\&apos;","gi"),"new Array('");
		val = val.replace(new RegExp("&apos;,&apos;","gi"),"','");
		val = val.replace(new RegExp("&apos;[)];","gi"),"');");
		val = val.replace(new RegExp("new Array[(]\&\#39;","gi"),"new Array('");
		val = val.replace(new RegExp("\&\#39;,\&\#39;","gi"),"','");
		val = val.replace(new RegExp("\&\#39;[)];","gi"),"');");		
		val = val.replace(new RegExp("\n","gi")," ");
		
		eval(val);
	},
	
	getLinkProtocol: function(linkURL) {
		var newlink = linkURL + ":";
		return newlink.substring(0,newlink.indexOf(":"));
	},
	
	isLinkProtocolAllowed: function(linkURL) {
	
		var bOK = true;
		
		if (typeof G_FilterUriEnabled != "undefined" && typeof G_FilterUriAllowed != "undefined" && G_FilterUriEnabled) {
			
			var linkProtocol = QuickrGeneralUtil.getLinkProtocol(linkURL).toLowerCase();
			
			//always allow http and https
			if (linkProtocol != "http" && linkProtocol != "https") {
				bOK = false;
				var aSchemes = G_FilterUriAllowed.split(',');
				for (var ii = 0; ii < aSchemes.length; ii++) {
					if (aSchemes[ii].toLowerCase() == linkProtocol) {
						bOK = true;
						break;
					}
				}
			}	
		}
		
		return bOK;
	}
	
	
	

}

var QuickrDateUtil = {

	getDateTimeString: function ( date, dateSelector, dateLength, translate ) {
		if( typeof(date) == "string") {
			return date;
		}
		
		if( typeof(date) == "undefined" || date == null ) {
			date = new Date();
		}	
		if ( typeof(dateSelector) == "undefined" || dateSelector == null ) {
			dateSelector = "dateTime";
		}
		if ( typeof(dateLength) == "undefined" || dateLength == null ) {
			dateLength = "short";
		}
		if ( typeof(translate) == "undefined" || translate == null ) {
			translate = true;
		}
		
		
        if (translate) 
            date = QuickrDateUtil.translateDate(date);

		var dateString = QuickrDateUtil.convertDate(date);
		var timeString = QuickrDateUtil.convertTime(date);
		
		if (dateSelector == "dateOnly") {
			return dateString;
        }
        else 
		if (dateSelector == "timeOnly") {
			return timeString;
            }
            else {
			return dateString + " " + timeString;
		}

	},
	
	getDateString: function  (date, dateLength, translate) {
		return this.getDateTimeString(date, "dateOnly", dateLength, translate);
	},

	getTimeString: function (date, dateLength, translate) {
		return this.getDateTimeString(date, "timeOnly", dateLength, translate);
	},
	
	convertDateTo8601String: function(date) {

		return 	date.getUTCFullYear() +
        "-" +
        this.fillingZero(date.getUTCMonth() + 1) +
        "-" +
        this.fillingZero(date.getUTCDate()) +
        "T" +
        this.fillingZero(date.getUTCHours()) +
        ":" +
        this.fillingZero(date.getUTCMinutes()) +
        ":" +
        this.fillingZero(date.getUTCSeconds()) +
			"Z";

	},
		
    fillingZero: function(num){
        return ((num < 10) ? '0' : '') + num;
    },
	
	convertStringToDate: function (xmlDateTime) {
		try {
			if (xmlDateTime.indexOf('T') == -1) {
			
				try {
					// SPR_GHCN7SPB45
					if (haiku.h_Intl_AMString != "" && haiku.h_Intl_PMString != "") {
						//code to make sure there is no extra spaces in the data/time
						var newdate = xmlDateTime;
						
						newdate = newdate.replace(new RegExp(haiku.h_Intl_AMString, "gi"), " " + haiku.h_Intl_AMString + " ");
						newdate = newdate.replace(new RegExp(haiku.h_Intl_PMString, "gi"), " " + haiku.h_Intl_PMString + " ");
						
						xmlDateTime = newdate;
					}
				}
				catch(ee) {
				}
				
				var d;
				var sep = "";

				var dt = new Array();
				var dtTemp = xmlDateTime.split(" ");
				
				for (var ii = 0; ii < dtTemp.length; ii++) {
					if (dojo.string.trim(dtTemp[ii]).length > 0) {
						dt.push(dtTemp[ii]);
					}
				}
				
				var dp = dt[0];
				var tp = dt[1];

				var ampm = haiku.h_Intl_AMString;

				if (dt.length > 2) {
					var dt2 = dt[2];
					if (haiku.h_Intl_AMPMPrefix) {
						if ((typeof(tp)!="undefined") && ((tp == haiku.h_Intl_PMString) || (tp == haiku.h_Intl_AMString))){
							ampm = tp;
							tp = dt2;
						}
                    }
                    else {
						if ((typeof(dt2)!="undefined") && ((dt2 == haiku.h_Intl_PMString) || (dt2 == haiku.h_Intl_AMString))){
							ampm = dt2;
						}
					}
				}

				if (typeof(haiku)!="undefined") {
					try {
						//determine the date from the haiku format
						var ymd = new Array();
						var ymd_s = dp.split(haiku.h_Intl_DateString);
						for (var i = 0; i < haiku.h_Intl_DateFormat.length; i++) {
							var sidx = haiku.h_Intl_DateFormat.substring(i,i+1).toUpperCase();
							ymd[sidx] = ymd_s[i];
						}


						//try and get the time
						if (typeof(tp)=="undefined" || tp.indexOf(haiku.h_Intl_TimeString) == -1) {
							tp = dt[2];
							if (typeof(tp)=="undefined" || tp.indexOf(haiku.h_Intl_TimeString) == -1) {
								tp = "00:00:00";
							}
						}
						var hm = tp.split(haiku.h_Intl_TimeString);
						if (ampm == haiku.h_Intl_PMString && ampm != haiku.h_Intl_AMString) {
							while(hm[0].substring(0,1) == "0") {
								hm[0] = hm[0].substring(1);
							}
							if (QuickrGeneralUtil.convertToNum(hm[0]) < 12) {
								hm[0] = QuickrGeneralUtil.convertToNum(hm[0]) + 12;
							}
						}
                        if (hm.length < 3) 
                            hm[2] = "00";


						//if all is well, build the date object
						if (!isNaN(ymd["Y"]) && !isNaN(ymd["M"]) && !isNaN(ymd["D"]) && !isNaN(hm[0]) && !isNaN(hm[1])) {
							if (QuickrGeneralUtil.convertToNum(ymd["D"]) <= 32 && QuickrGeneralUtil.convertToNum(ymd["M"]) <= 13) {  //if these values are off, then something went wrong with the parsing...
								d = new Date(ymd["Y"], ymd["M"] - 1, ymd["D"], hm[0], hm[1], hm[2]);
							}
						}
                    } 
                    catch (e) {
                    }

				}

				if (typeof(d) == "undefined" || isNaN(d)) {  //we couldn't parse according to haiku, try brute force...
                    if (dp.indexOf("-") > -1) 
                        sep = "-";
                    if (dp.indexOf(".") > -1) 
                        sep = ".";
                    if (dp.indexOf("/") > -1) 
                        sep = "/";

					d = new Date(xmlDateTime);

					if (sep != "/" || isNaN(d.getFullYear())) {
						// this isn't an ISO date format, and it's also not a format JS recognizes. Assume that it's in the form
						// yyyy-MM-dd hh:mm. If we can't parse based on this format, simply return the string as-is.


						if (sep != "/") {
							var ymd = dp.split(sep);

							//if the last element in ymd is longer than the first then the format is actually...
							//dd-MM-yyyy.  SPR #YGUN7C28XK
							if (ymd[2].length > ymd[0].length) {
								var tmpVal = ymd[0];
								ymd[0] = ymd[2];
								ymd[2] = tmpVal;
							}

							if (typeof(tp)=="undefined" || tp.indexOf(":") == -1) {
								tp = dt[2];
								if (typeof(tp)=="undefined" || tp.indexOf(":") == -1) {
									tp = "00:00:00";
								}
							}

							var hm = tp.split(':');
							if (isNaN(ymd[0]) || isNaN(ymd[1]) || isNaN(ymd[2]) || isNaN(hm[0]) || isNaN(hm[1])) {
								return xmlDateTime;
							}

							d = new Date(ymd[0], ymd[1] - 1, ymd[2], hm[0], hm[1]); // month is 0 - 11, hence ymd[1] - 1
                        }
                        else {
							d = xmlDateTime;  // we couldn't parse it...  just return the original string  back
						}
					}
				}

				return d;
			}

			var xDate = xmlDateTime.split('T')[0].replace(/-/g,"");
			var iYear = QuickrGeneralUtil.convertToNum(xDate.substring(0,4));
			var iMonth = QuickrGeneralUtil.convertToNum(xDate.substring(4,6)) - 1;
			var iDay = QuickrGeneralUtil.convertToNum(xDate.substring(6,8));


			var xTime = xmlDateTime.split('T')[1].replace(/:/g,"");
			var iHours = QuickrGeneralUtil.convertToNum(xTime.substring(0,2));
			var iMins = QuickrGeneralUtil.convertToNum(xTime.substring(2,4));
			var iSecs = QuickrGeneralUtil.convertToNum(xTime.substring(4,6));
			
			
			//now we need to get the datetime in GMT...
			var timezoneOffset = 0;
			var iSign = 1;
			
			if (xTime.indexOf("-") > -1) {
				iSign = -1;
				timezoneOffset = QuickrGeneralUtil.convertToNum(xTime.split("-")[1]);
				
            }
            else 
                if (xTime.indexOf("+") > -1) {
				iSign = 1;
				timezoneOffset = QuickrGeneralUtil.convertToNum(xTime.split("+")[1]);
			}

			var utcDate = new Date(iYear, iMonth, iDay, iHours, iMins, iSecs);
			
			if (timezoneOffset != 0) {
				//if we get a number less than 24, then we know that just the hour offset was sent
				if (timezoneOffset < 24) {
					timezoneOffset = timezoneOffset * 100;
				}

				//determine how many hours/mins to offset
				var iMinOffset = timezoneOffset % 100;
				var iHourOffset = (timezoneOffset - iMinOffset) / 100;

				timezoneOffset = (iHourOffset * 3600000) + (iMinOffset * 60000);
				timezoneOffset = -1 * iSign * timezoneOffset;

				utcDate = new Date(utcDate.getTime() + timezoneOffset);
			}

			
			//the time should now be in GMT...  now let's adjust for server's timezone
			var tzone = haiku.ServerTimeZone;
            if (haiku.h_Intl_DaylightSavings) 
                tzone = tzone - 1;
			
			timezoneOffset = tzone * 3600000;

			
			//now create the date object and set it to the server's time.
			return new Date(utcDate.getTime() - timezoneOffset);

		}
		catch(e) {
			return null;
		}
	},



	returnDateTimeString: function (xmlDateTime) {
		
		
		var dDate = this.convertStringToDate(xmlDateTime);
		
		
		if (typeof dDate != 'string')
			return this.getDateString(dDate) + ' ' + this.getTimeString(dDate);
		else
			return dDate;
	},
	
	translateDate: function(dDate, toGregorian) {
        if (typeof(toGregorian) == "undefined") 
            toGregorian = false;

		if ( dDate != null && typeof(dDate) == "object" && !isNaN(dDate.getFullYear()) ) {
			if (toGregorian) {
				if(isHijri||isHebrew) {
					var newDate;
                    if (isHijri) 
                        newDate = new dateHijri();
                    if (isHebrew) 
                        newDate = new dateHebrew();
					
					newDate.setYear(dDate.getFullYear());
					newDate.setMonth(dDate.getMonth());
					newDate.setDate(dDate.getDate());
					newDate.setHours(dDate.getHours());
					newDate.setMinutes(dDate.getMinutes());
					newDate.setSeconds(dDate.getSeconds());
					
					dDate = newDate.toGregorian();
				}
            }
            else {
                if (isHijri) 
                    dDate = new dateHijri().gregorianToHijri(dDate);
                if (isHebrew) 
                    dDate = new dateHebrew().gregorianToHebrew(dDate);
			}		
		}
		
		return dDate;

	},
	
	convertDate: function (date){
		var ret = "";
		var sep;
		var format;
		var date4DigitYear;
        if (haiku.hasRegionalCookie == true) {
			sep = haiku.h_Cookie_DateString;
			format = haiku.h_Cookie_DateFormat;
			date4DigitYear = haiku.h_Cookie_Date4DigitYear;
		}
        else {
			sep = haiku.h_Intl_DateString;
			format = haiku.h_Intl_DateFormat;
			date4DigitYear = haiku.h_Intl_Date4DigitYear;
		}
		
		var year = date.getFullYear();
        if (date4DigitYear == false) {
			year = year.toString().substring(2);
		}
		
		var month =(((date.getMonth()+1) < 10) ? "0" : "") + (date.getMonth()+1);
		var day =((date.getDate() < 10) ? "0" : "") + date.getDate();
		if(format == haiku.kszDMY) {
			ret = day + sep + month + sep + year;
        }
        else 
            if (format == haiku.kszYMD) {
			ret = year + sep + month + sep + day;
            }
            else {
			ret = month + sep + day + sep + year;
		}
		return ret;
	},

	convertTime: function (date){
		var ret = "";
		var am_pm = "";
		var timeString;
		var clock24Hour;
		var amString;
		var pmString;
		var ampmPrefix;
        if (haiku.hasRegionalCookie == true) {
			timeString = haiku.h_Cookie_TimeString;
			clock24Hour = haiku.h_Cookie_Clock24Hour;
			amString = haiku.h_Cookie_AMString;
			pmString = haiku.h_Cookie_PMString;		
			ampmPrefix = haiku.h_Cookie_AMPMPrefix;
		}
        else {
			timeString = haiku.h_Intl_TimeString;
			clock24Hour = haiku.h_Intl_MilitaryTime;
			amString = haiku.h_Intl_AMString;
			pmString = haiku.h_Intl_PMString;	
			ampmPrefix = haiku.h_Intl_AMPMPrefix;	
		}
		
		var hrs = date.getHours();
		var mins = date.getMinutes();
		var mins = ((mins < 10) ? "0" : "") + mins;
		if(!clock24Hour){
			if(ampmPrefix)
				am_pm = ((hrs >= 12) ? pmString + ' ' : amString + ' ');
			else
				am_pm = ((hrs >= 12) ? ' ' + pmString : ' ' + amString);
			hrs  = ((hrs > 12) ? hrs - 12 : hrs);
            if (hrs == 0) 
                hrs = 12;
		}
		if (ampmPrefix) {
			return (am_pm + hrs + timeString + mins);
        }
        else {
			return (hrs + timeString + mins + am_pm);
		}		
	}	
}

var QuickrCookieUtil = {

	hasCookie: function (name) {
		var ck = this.getCookie(name);
		return (ck != null && ck != "");
	},

	getCookie: function (name, xdefault) {
        if (typeof(xdefault) == "undefined") 
            xdefault = null
		var cname = name + "=";               
		var dc = document.cookie;             
		if (dc.length > 0) {              
			begin = dc.indexOf(cname);       
			if (begin != -1) {           
				begin += cname.length;       
				end = dc.indexOf(";", begin);
                if (end == -1) 
                    end = dc.length;
				return unescape(dc.substring(begin, end));
			} 
		}
		return xdefault;
	},

	setCookie: function (name, value, expires, path) {
		document.cookie = name + "=" + escape(value) + "; path=" + (typeof(path)=="undefined" ? "/" : path) + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
	},

	delCookie: function (name) {
		document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
	},

	getExpireDate: function (nodays) {
		var UTCstring;
		Today = new Date();
		nomilli=Date.parse(Today);
		Today.setTime(nomilli+nodays*24*60*60*1000);
		UTCstring = Today.toUTCString();
		return UTCstring;
	}
}

var QuickrXMLUtil = {

    getXMLDocFromString: function(stext){
		var doc;
		
		// code for IE
        if (window.ActiveXObject) {
			doc=new ActiveXObject("Microsoft.XMLDOM");
			doc.async="false";
			doc.loadXML(stext);
		}
		// code for Mozilla, Firefox, Opera, etc.
        else {
			var parser=new DOMParser();
			doc=parser.parseFromString(stext,"text/xml");
		}
		
		return doc;
	},
	
    getNodeValuesByTagName: function(xmlDoc, tagname){
		var arr = new Array();
		
		var x = xmlDoc.getElementsByTagName(tagname);
		
		if (x && x.length > 0) {
			for (var i = 0; i < x.length; i++) {
				arr[arr.length] = x[i].childNodes[0].nodeValue;
			}
		}
		
		return arr
	
	
	},
	
	
    fireAjaxRequest: function(url, responseFunc, timeoutSecs, timeoutFunc, errorFunc, doSync){
        if (typeof(timeoutSecs) == "undefined") 
            timeoutSecs = 15;
        if (typeof(doSync) == "undefined") 
            doSync = false;
        ;
		
		var theTimeout = timeoutSecs * 1000;
		var theMethod = "get";
		var theErrFunc = errorFunc || this.Error;
		var theType = "text/plain";
		
		try {
			dojo.xhrGet({
					url: url,
					timeout: theTimeout,
					sync: doSync,
					handleAs: "text",

				load: function(response, ioArgs) { //{type, data, evt) {
					if (typeof(responseFunc) == "string") {
						responseFunc = eval(responseFunc);
					}
		
					if (typeof(responseFunc) == "function") {
						responseFunc (response, this.url);
					} 
				},


				error: function(response, ioArgs) { //function(type, error) {
					if (typeof(errorFunc) == "string") {
						errorFunc = eval(errorFunc);
					}
		
					if (typeof(errorFunc) == "function") {
						errorFunc ("get", response);
					}
				}
			});
	
		}
		catch(e) {
		}	
	},
	
	massageXmlStringForData: function(data) {
		if (typeof data == "string") {
		
			//code will attempt to remove problem characters in the textabstract which IE has a problem with.
			var aSplit = ["<h_TextAbstract><![CDATA[", "]]></h_TextAbstract>"];
			
			var data1 = data.split(aSplit[0]);
			if (data1.length > 1) {
				var data2 = data1[1].split(aSplit[1]);
				
				if (data2.length > 1) {

					data2[0] = encodeURIComponent(data2[0]);
					data2[0] = data2[0].replace(/\%C2\%A0/gi, "%20");
					data2[0] = decodeURIComponent(data2[0]);

					return QuickrXMLUtil.getXMLDocFromString(data1[0] + aSplit[0] + data2[0] + aSplit[1] + data2[1]);
				}
			}

			return QuickrXMLUtil.getXMLDocFromString(data);

        }
        else {
			return data;
		}
	}
}
	

var QuickrSetupUtil = {

	SHOWTYPE_FILES: 	"1",
	SHOWTYPE_PLACES:	"2",
	SHOWTYPE_PLACESONLY: 	"3",
	
	SHOW_COOKIE_NAME:	"ShowContentUI",
	
	ORIG_HELPPAGE_NAME:	"OrigHelpPageUnid",
	SHOW_MYFILES_NAME:	"ShowMyFiles",
	
	_TITLEHOLDER: 		"",
	_HELPPAGEHOLDER:	"",
	
	findUserName: function () {
		var ret = "";
		
        if (ret == "") 
            ret = this._returnNameIfValid(haiku.userName);
        if (ret == "") 
            ret = this._returnNameIfValid(haiku.AbbrevUserName);
        if (ret == "") 
            ret = this._returnNameIfValid(haiku.loginName);
        if (ret == "") 
            ret = this._returnNameIfValid(haiku.distinguishedName);
		
		
		return ret;
		
	
	},
	
	setEntryWindowTitle: function (yn) {
		return;
		
        if (typeof(yn) == "undefined") 
            yn = true;

		if (yn) {
			QuickrSetupUtil._TITLEHOLDER = document.title;
			document.title = QuickrLocaleUtil.getStringResource("QuickrSetupUtil.ENTRYWINDOWTITLE");
			
        }
        else {
			if (QuickrSetupUtil._TITLEHOLDER != "") {
				document.title = QuickrSetupUtil._TITLEHOLDER;
			}
		}
		
	},
	
	setEntryHelpFile: function (yn) {
		
		if (typeof(G_EntryHelpPageUnid) != "undefined") {
            if (typeof(yn) == "undefined") 
                yn = true;
			
			if (yn) {
				if (helpPageUnid != G_EntryHelpPageUnid) {
					QuickrSetupUtil._HELPPAGEHOLDER = helpPageUnid;
					helpPageUnid = G_EntryHelpPageUnid;

				}
            }
            else {
				if (helpPageUnid == G_EntryHelpPageUnid) {
					var oldunid = QuickrSetupUtil._HELPPAGEHOLDER;
					if (oldunid != "") {
						helpPageUnid = oldunid;
					}
				}
			}
		}
		
	},
	
	_returnNameIfValid: function (val) {
		if (val.indexOf(" ")) {
			return val;
        }
        else {
			return "";
		}
	},
	
	redirectToMyPlace: function(rawdata) {
		var data = null;
		
		if (typeof(rawdata) == "string") {
			data = QuickrXMLUtil.getXMLDocFromString(rawdata);
        }
        else {
			data = rawdata;
		}
		

		if (data != null) {
			var entries = data.getElementsByTagName("viewentry");

			var dn1 = haiku.distinguishedName.toLowerCase();
			var dn2 = "cn=" + dn1;

			for (var i = 0; i < entries.length; i++) {
				var dn=email="";

				cols = entries[i].getElementsByTagName("entrydata");
				for (var j = 0; j < cols.length; j++) {
					colName = cols.item(j).getAttribute("name");
					if (colName == "dn") {
						dn = cols.item(j).firstChild.nodeValue.toLowerCase();
					}
                    else 
                        if (colName == "mail") {
						email = cols.item(j).firstChild.nodeValue;
					}

					if (dn != "" && email != "") {  //we've got everything we need.
						if (dn == dn1 || dn == dn2) {
							haiku.emailAddress = email;
							break;
						}
						
					}

				}
				
				if (haiku.emailAddress != "") {
					break;
				}

			}
			
			if (haiku.emailAddress == "") {
				var dn1 = haiku.userName.toLowerCase();
				
				for (var i = 0; i < entries.length; i++) {
					var dn=email="";

					cols = entries[i].getElementsByTagName("entrydata");
					for (var j = 0; j < cols.length; j++) {
						colName = cols.item(j).getAttribute("name");
						if (colName == "displayname") {
							dn = cols.item(j).firstChild.nodeValue.toLowerCase();
						}
                        else 
                            if (colName == "mail") {
							email = cols.item(j).firstChild.nodeValue;
						}

						if (dn != "" && email != "") {  //we've got everything we need.
							if (dn == dn1) {
								haiku.emailAddress = email;
								break;
							}

						}

					}

					if (haiku.emailAddress != "") {
						break;
					}				
				}
				
			}
			
			
			
		}
		
		QuickrSetupUtil.lookupFilesPlaceFromEmail(haiku.emailAddress);
		
	},
	
	loadMyFiles: function () {
		var showMyFiles = QuickrGeneralUtil.getQSValue(window.location.href, this.SHOW_MYFILES_NAME,"");
		if (showMyFiles == "1") {

			if (haiku.emailAddress == "") {
				//for whatever reason, the email address isn't coming through, let's fall back to pull it through the ldapsearch

				var ldapname = this.findUserName();
				if (ldapname.indexOf(" ") > -1) 
					ldapname = ldapname.substring(ldapname.indexOf(" ")+1);
				if (ldapname.indexOf("=") > -1) 
					ldapname = ldapname.substring(ldapname.indexOf("=")+1);					
				if (ldapname.indexOf("/") > -1) 
					ldapname = ldapname.substring(0,ldapname.indexOf("/"));	
				if (ldapname.indexOf("\\") > -1) 
					ldapname = ldapname.substring(0,ldapname.indexOf("\\"));
				ldapname = haiku.distinguishedName;

				var ldapurl = getAbsoluteServerRootURL(self) + "/dm/atom/action?action=ldapsearch&query=" + encodeURIComponent(ldapname);

				QuickrXMLUtil.fireAjaxRequest( ldapurl, QuickrSetupUtil.redirectToMyPlace, 15, "", QuickrSetupUtil.processFilesPlaceError );
				
            }
            else {
				QuickrSetupUtil.redirectToMyPlace(null);

			}
			return true;
		}

		return false;
	},

	fixPageTitle: function(titleNode, titleKey) {
		if (!titleNode) {
			return;
		}
		
		QuickrLocaleUtil.loadStringFiles("common", "/qphtml/skins/common", "QuickrCommonStrings");
		var titleStr = QuickrLocaleUtil.getStringResource(titleKey);
		titleNode.setAttribute("title", titleStr);
		titleNode.innerHTML = titleStr;
		titleNode.style.overflow = 'hidden';
		titleNode.style.whiteSpace = 'nowrap';
		
	},
	
	showQuickrContent: function(newType, external) {
        if (typeof(external) == "undefined") 
            external = false;
		
		if (QuickrSetupUtil.loadMyFiles()) {
			return;
		}
		
		
		
		

		if ( typeof(newType) != "undefined" && newType != null ) {
			QuickrCookieUtil.setCookie(this.SHOW_COOKIE_NAME, newType);
        }
        else {
			newType = QuickrGeneralUtil.getQSValue(window.location.href, "ShowType","");
			if (newType != "") {
				QuickrCookieUtil.setCookie(this.SHOW_COOKIE_NAME, newType);
			}
		}


        if (typeof(h_InstallType) == "undefined") 
            h_InstallType = this.SHOWTYPE_PLACES;

		if (external) {

			var url = this.getSetupBase() + "&ShowType=" + QuickrCookieUtil.getCookie(this.SHOW_COOKIE_NAME);
			
			window.location.href = url;
			
        }
        else {
		
			/*************************************
			* This array will store the style.display values for the three classes of elements
			*
			* First is the elements for Places-specific content
			* Second is the elements for shared content
			* Third is the elements for File-specific content
			* Forth is a special ID for the "Work with Templates" link.
			* This is the elements for the entry stuff only
			**************************************/
			var arrShow;

			if (h_InstallType == this.SHOWTYPE_FILES) { //THIS IS AN ENTY INSTALL...  SHOW ONLY ENTRY STUFF
				arrShow = new Array("none", "none", "block", "none");
				
				QuickrSetupUtil.setEntryHelpFile(true);
				QuickrSetupUtil.setEntryWindowTitle(true);
				


            }
            else 
                if (h_InstallType == this.SHOWTYPE_PLACES) { //THIS IS AN FULL INSTALL...  SHOW ALL STUFF
				var checkType = h_InstallType;
				if ( QuickrCookieUtil.hasCookie(this.SHOW_COOKIE_NAME) ) {
					checkType = QuickrCookieUtil.getCookie(this.SHOW_COOKIE_NAME);
				}

				var id_p = document.getElementById("typePlaces");
				var id_f = document.getElementById("typeFiles");

				if (checkType == this.SHOWTYPE_FILES) {
					arrShow = new Array("none", "block", "block", "none");

                        if (id_p) 
                            id_p.className = id_p.className.replace("lotusSelected", "");
                        if (id_f) 
                            id_f.className += " lotusSelected";
                        
                        
                    }
                    else 
                        if (checkType == this.SHOWTYPE_PLACES || checkType == this.SHOWTYPE_PLACESONLY) {
					arrShow = new Array("block", "block", "none", "block");

                            if (id_p) 
                                id_p.className += " lotusSelected";
                            if (id_f) 
                                id_f.className = id_f.className.replace("lotusSelected", "");
				}
				
				QuickrSetupUtil.setEntryHelpFile( checkType==this.SHOWTYPE_FILES );
				QuickrSetupUtil.setEntryWindowTitle( checkType==this.SHOWTYPE_FILES );
							

                }
                else 
                    if (h_InstallType == this.SHOWTYPE_PLACESONLY) { //THIS IS A PLACES INSTALL...  SHOW PLACES STUFF
				var checkType = h_InstallType;
				if ( QuickrCookieUtil.hasCookie(this.SHOW_COOKIE_NAME) ) {
					checkType = QuickrCookieUtil.getCookie(this.SHOW_COOKIE_NAME);
				}

				arrShow = new Array("block", "none", "none", "block");
				
				QuickrSetupUtil.setEntryHelpFile( false );
				QuickrSetupUtil.setEntryWindowTitle( false );
							

			} 

			if ( typeof(arrShow) != "undefined" ) {
				var els_p = QuickrGeneralUtil.getElementsByClassName ("QuickrPlacesContent");	//places-specific ui
				var els_s = QuickrGeneralUtil.getElementsByClassName ("QuickrSharedContent");	//shared ui to be displayed on full install
				var els_f = QuickrGeneralUtil.getElementsByClassName ("QuickrFilesContent");	//files-specific ui		
				for (var i = 0; i < els_p.length; i++) {
					els_p[i].style.display = arrShow[0];
				}
				for (var i = 0; i < els_s.length; i++) {
					els_s[i].style.display = arrShow[1];
				}			
				for (var i = 0; i < els_f.length; i++) {
					els_f[i].style.display = arrShow[2];
				}
				
				//massage the templates link...
				var el = document.getElementById("Toc_PlaceTypes");
				if (el) {
					el.parentNode.parentNode.style.display = arrShow[3];
				}				
			}
		}

	},
		
	showMyFiles: function () {

		var url = this.getSetupBase() + "&Login&" + this.SHOW_MYFILES_NAME + "=1";

		window.location.href = url;
	},
	
	getSetupBase: function () {
	
		var xbase = "LotusQuickr";
		if (typeof(getHaikuSubDir) == "function") {
			xbase = getHaikuSubDir();
		}
		var setupHaiku = xbase.toLowerCase();
		var url = QuickrGeneralUtil.getJunctionString() + "/" + xbase + "/" + setupHaiku + "/Main.nsf/h_Toc/22049553d70e00ef85256bb60054a7cb/?OpenDocument";
		
		return url;
	
	},
	
	lookupFilesPlace: function( frm ) {
		return this.lookupFilesPlaceFromEmail(frm.email.value);
			
	},
	
	lookupFilesPlaceFromEmail: function( email ) {
			var url = QuickrGeneralUtil.getServletRoot() + "/QuickrEntry?getEntryPlaceInfo=1&email=" + encodeURIComponent(email);
			
			QuickrXMLUtil.fireAjaxRequest( url, QuickrSetupUtil.processFilesPlace, 15, "", QuickrSetupUtil.processFilesPlaceError );
			
			return false;
					
		
	},
	
	_ERRORSHOWN: false,
	processFilesPlace: function ( xmlstring ) {
		eval(xmlstring);
		
		if (QuickrEntryPlaceInfo.exists) {
			var newloc = QuickrEntryPlaceInfo.placeLocation;
			var sJun = QuickrGeneralUtil.getJunctionString();

			//if we've got a junction string, then we are behind TAM or a similar device.
			//Remove the reference to the server and add the junction string			
			if (newloc.toLowerCase().indexOf("http") == 0) {
				newloc = newloc.substring(newloc.indexOf("//")+2);
				newloc = newloc.substring(newloc.indexOf("/"));
			}
			//SPR #GMU7L5J6M, if the loc started with Junction name, then do not add sJun
			if (sJun != "" && newloc.toLowerCase().indexOf(sJun.toLowerCase()) != 0) {
			    newloc = sJun + newloc;
			}

			window.location.href = newloc;
        }
        else {
			if (!QuickrSetupUtil._ERRORSHOWN) {
				var err = QuickrLocaleUtil.getStringResource("QuickrSetupUtil.ERRORS.PLACE_NOT_FOUND");
				err = err.replace("{0}", QuickrEntryPlaceInfo.email);

				alert(err);

			}
			
			if (window.location.href.indexOf("&" + QuickrSetupUtil.SHOW_MYFILES_NAME + "=1") > -1) {
				QuickrSetupUtil._ERRORSHOWN = true;
				window.location.href = QuickrGeneralUtil.getBaseUrl();
			}
			
		}
		
		
		
	},
	
	processFilesPlaceError: function () {
		alert(QuickrLocaleUtil.getStringResource("QuickrSetupUtil.ERRORS.SERVLET_NOT_CONFIGURED"));
		window.location.href = (window.location.href + "&").split("&")[0];
	},
	
	getTextWidth: function( text ) {
		var elSpan = document.createElement("span");
		elSpan.className = "lotusText";
		elSpan.innerHTML = text.replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
		document.body.appendChild(elSpan);

		// SPR_CWAG7USPWR
		var spanWidth = "";
		if ( elSpan.offsetWidth > 0) {
			spanWidth = elSpan.offsetWidth;
        }
        else {
			spanWidth = 0 - elSpan.offsetWidth;
		}		
		
		elSpan.parentNode.removeChild(elSpan);

		return spanWidth;		
	},
	
	adjustPrefilledTextBox: function( id, extraPX ) {
		var elSearch = dojo.byId(id);
		if (elSearch && elSearch.value.length > 0) {
			var spanWidth = QuickrSetupUtil.getTextWidth(elSearch.value)
			if ( h_ClientBrowser && h_ClientBrowser.isIE() ) {
				spanWidth += 10;
			}
			if (extraPX) {
				spanWidth += extraPX;
			}
			
			elSearch.style.width = spanWidth+"px";			
		}
	}
	
	
	
	
}












// MEMBER LOOKUP

var MemberLookupUtil = {
	
	origBodyOnClick: null,
	
	currentControl: null,
	
	submitControlForm: false,
	

	
	curRole: "members",

	tmrMS: 300,
	tmout: null,
	iName: "-1",
	maxNames: 15,
	aSelections: new Array(),

	init: function () {
		this.aSelections.length = 0;
		if (G_maxNames != "") {
			this.maxNames=parseInt(G_maxNames);
		}
	},

	onKey: function (val,e) {
		// stop lookup timer
		if (this.tmout != null) {
			clearTimeout(this.tmout);
		}

		var bAbort=false;
		var bDoNothing=false;
		var key;
		if (window.event)			  // IE
			key = e.keyCode;
        else 
            if (e.which) 
			key = e.which;
		var ch=String.fromCharCode(key);

		switch (key) {
		case 13:						  // enter
			//this.chooseName();
			return false;
		/*
		case 38:						  // up arrow
			this.prevName();
			return false;
		case 40:						  // down arrow
			this.nextName();
			return false;
		*/
		case 27:						  // esc
			bAbort=true;
			break;
		case 9:
			bDoNothing=true;
			break;
			
		default:
			break;
		}

		// s <-- string being typed
		var s="";
		var i = val.lastIndexOf("),");
		i = (i<0 ? 0 : i+2);
		if (i<val.length) {
			s=val.substring(i);
		}

		if (bAbort || s.length==0) {
			 this.hideNames();
		}
		else {
			if (!bDoNothing) {
				// set timer to do lookup on the string typed so far
                this.tmout = setTimeout(function(){
                    MemberLookupUtil.doIt(s);
                }, this.tmrMS);
			}
		}
		return false;
	},

	doIt: function(val) {
		// LDAP Search service URL (optional: &flags=g,e)
		var flags="";

		var svcUrl = getAbsoluteServerRootURL(self) + "/dm/atom/action?action=ldapsearch&query=" + encodeURIComponent(val) + flags;

		try {

			dojo.xhrGet({
				url: svcUrl,
				handleAs: "text",
				load: function(response, ioArgs) {
					var xmlData=MemberLookupUtil.getXMLDocFromString(response);	
					MemberLookupUtil.init();
					MemberLookupUtil.showNames(xmlData,val);
				},
				error: function(response, ioArgs ) {
					MemberLookupUtil.error(error,val);					
				}			

			});
			
			var looking_str = QuickrLocaleUtil.getStringResource("QUICKRCOMMON.LOOKING");

            var html = '<ul' +
            '<li class="selected">' +
            '<img src="/qphtml/html/common/ajax_loader.gif"/>' +
            '&nbsp;<em>' +
            looking_str +
            '</em>&hellip;' +
            '</li></ul>';

			var el = dojo.byId("m_autocomplete"+MemberLookupUtil.curRole+"_choices");
			
			if (el) {
				//SPR #QCAO7GVFC5
				if (document.forms["findFilesForm"] && document.forms["findFilesForm"].email && MemberLookupUtil.curRole == "members" && document.body.dir == "rtl") {
					var newLeft = findPos(document.forms["findFilesForm"].email)[0];
					newLeft = newLeft - parseFloat(el.style.minWidth.replace(/px/,""));
					
					el.style.left = newLeft +"px";
				}			
			
				el.innerHTML=html;
				el.style.display="block";
			}
		}
		catch(e) {
		}
	},

	error: function(err,sLookup) {	
		var looking_up_str = QuickrLocaleUtil.getStringResource("QUICKRCOMMON.ERROR_IN_LOOKING_UP");

        var html = '<ul' +
        '<li tabindex="0" class="selected">' +
        looking_up_str +
        ' "' +
        QuickrGeneralUtil.encodeEntities(sLookup) +
        '"' +
        '</li></ul>';

		var el = dojo.byId("m_autocomplete"+MemberLookupUtil.curRole+"_choices");
		el.innerHTML=html;
 		el.style.display="block";
	},

	// Added for PNOT79UP7H - should be common util!
    getXMLDocFromString: function(s){
		var doc;
		
		// code for IE
        if (window.ActiveXObject) {
			doc=new ActiveXObject("Microsoft.XMLDOM");
			doc.async="false";
			doc.loadXML(s);
		}
		// code for Mozilla, Firefox, Opera, etc.
        else {
			var parser=new DOMParser();
			doc=parser.parseFromString(s,"text/xml");
		}
		
		return doc;
	},
	
	showChoices: function (yn, html) {
        if (typeof(yn) == "undefined") 
            yn = true;
		
		var el = dojo.byId("m_autocomplete"+MemberLookupUtil.curRole+"_choices");
		
		if (el) {
			if (yn) {
				if (typeof(html) != "undefined" && html != null) {
					el.innerHTML = html;
				}
				el.style.display = "block";
				
				
				var el2 = dojo.byId(MemberLookupUtil.curRole+"_container");
                if (el2) 
                    el2.focus();

				
				MemberLookupUtil.origBodyOnClick = document.body.onclick;
				document.body.onclick = MemberLookupUtil.onBodyClick;
				
            }
            else {
				el.style.display = "none";
				
				document.body.onclick = MemberLookupUtil.origBodyOnClick;
				MemberLookupUtil.origBodyOnClick = null;
			}
		}
	
	},
	
	selectName: function(newval) {
		if (newval == "") {
			var str = QuickrLocaleUtil.getStringResource("QUICKRCOMMON.ERROR_NO_EMAIL_ADDR");
			alert(str);
		
        }
        else {
			MemberLookupUtil.currentControl.value = newval.replace(/,/g, "/");
			MemberLookupUtil.hideNames();
			MemberLookupUtil.currentControl.focus();		
		}
	},

	showNames: function (root,sLookup) {

		var html = "";
		var nameHtml='';

		var top = root.getElementsByTagName("viewentries");
		var nEntries = top.item(0).getAttribute("toplevelentries");
		var iUsableName = -1;

		if (nEntries > 0) {
			// Found some entries
			var entries = root.getElementsByTagName("viewentry");
			for (var i=0; i<entries.length && i<this.maxNames; i++) {
				// Show up to 15 names
				
				
				var email = "";
				var cn = "";

				cols = entries[i].getElementsByTagName("entrydata");

				for (var j = 0; j < cols.length; j++) {
					colName = cols.item(j).getAttribute("name");
					if (colName == "mail") {
						if (cols.item(j).childNodes.length > 0) {
							email = cols.item(j).firstChild.nodeValue;
						}
					}
                    else 
                        if (colName == "cn") {
						if (cols.item(j).childNodes.length > 0) {
							cn = cols.item(j).firstChild.nodeValue;
						}
					}
                        else 
                            if (email != "" && cn != "") {
						break;
					}
				}

				var temp = QuickrLocaleUtil.getStringResource("MemberLookupUtil.CHOICES.FORMAT");
				temp = temp.replace("{0}", cn);
				temp = temp.replace("{1}", email);

				iUsableName++;

				nameHtml += 	'<a ' +
						'onmouseout="MemberLookupUtil.unhilite(this);" onmouseover="MemberLookupUtil.hilite(this);"' +
						'onblur="MemberLookupUtil.unhilite(this);" onfocus="MemberLookupUtil.hilite(this);"' +
                'href="javascript:void MemberLookupUtil.selectName(&quot;' +
                email +
                '&quot;)">' +
                temp +
                '</a>';
							
			
				
			}
		}

		if (iUsableName < 0) {
		    var str = QuickrLocaleUtil.getStringResource("QUICKRCOMMON.NO_NAMES_AVAILABLE");
			html += '<a class="selected">' +  str + '</a>';
		}
		else {
			if (nEntries > this.maxNames) {
				var str = QuickrLocaleUtil.getStringResource("QUICKRCOMMON.ENTRIES_NAMES_AVAILABLE");
				str = str.replace("{0}", nEntries);
				str = str.replace("{1}", this.maxNames);
				html += '<a><em>** '+ str + '</em></a>';
			}
			html += nameHtml;
		}

		MemberLookupUtil.showChoices(true, html);

	},

	
	hilitedControl: null,
	hilite: function(ctrl) {
		if (ctrl) {
			MemberLookupUtil.unhilite(MemberLookupUtil.hilitedControl);
			
			ctrl.className += " selected";
			MemberLookupUtil.hilitedControl = ctrl;
		}
	},
	unhilite: function(ctrl) {
		if (ctrl) {
			ctrl.className = ctrl.className.replace("selected","");
		}
	},	
	
	

	hiliteName: function(i) {
		var el=dojo.byId(MemberLookupUtil.curRole+"_name_"+this.iName);
		if (el) {
			el.className="";
		}
		el=dojo.byId(MemberLookupUtil.curRole+"_name_"+i);
		if (el) {
			el.className="selected";
			this.iName=i;
		}
	},

	hideNames: function() {
		this.iName=-1;
		dojo.byId("m_autocomplete"+MemberLookupUtil.curRole+"_choices").style.display="none";
	},

	onBodyClick: function(e) {
		dojo.byId("m_autocomplete"+MemberLookupUtil.curRole+"_choices").style.display="none";
	},

 	preventDefaultAction: function (e) {
 		try {
 			e.preventDefault();
        } 
        catch (err1) {
 		}
 	},	
	
	flagCurrentControl: function(ctrl, submitForm) {
		MemberLookupUtil.currentControl = ctrl;
		
		
        if (typeof(submitForm) == "undefined") 
            submitForm = false;
		MemberLookupUtil.submitControlForm = submitForm;
		
	}	


}


//BBXSS Changes
/*********************************************************************************
*	This object is used in converting the backend data passed 
*	from the server into javascript data used by the UI.  This
*	was necessary for the XSS security work.  First, instantiate
*	the object Then set the rawString value containing the 
*	backend data.  If you want to have a function called with 
*	the data items for each row passed in as parameters, then 
*	set the callbackFunction. If you want a set of arrays to get
*	updated with the appropriate values for each row, set the 
*	targetArrays to the array of arrays.  
*********************************************************************************/
// Constructor.  Pass in row delimiter, column delimiter, and the index of the
// column which is not blank to be added.
// ex: var xssData = new QuickrBackendDataUtil( D_RowDelimiter , D_ColumnDelimiter , 0);
function QuickrBackendDataUtil(sRowDelim, sColumnDelim, iNotBlank) {
	//make sure the parameters passed in have values
    if (typeof(sRowDelim) == "undefined" || sRowDelim == null) 
        sRowDelim = "%~~%";
    if (typeof(sColumnDelim) == "undefined" || sColumnDelim == null) 
        sColumnDelim = "%~%";
    if (typeof(iNotBlank) == "undefined" || iNotBlank == null) 
        iNotBlank = 0;
	
	//define the internal vars
	this._rowDelim = sRowDelim;
	this._columnDelim = sColumnDelim;
	this._notBlank = iNotBlank;
	this._rawArray = new Array();

	//these are set after the object is instantiated.
	this.rawString = "";
	this.targetArrays = new Array();
	this.callbackFunction = null;
	this.dataItem = null;

}

// Takes the raw string and performs the necessary actions on it
// if the callbackFunction was defined, then it will be called
// for every "row" of data.  If the targetArrays is defined, 
// then just put the column values in the appropriate targets
QuickrBackendDataUtil.prototype.processRawData = function() {
	this._populateRawArray();
	
	var aRaw = this._rawArray;
	var aTarget = this.targetArrays;
	
	if (typeof this.callbackFunction == "function") {  //the callback function was defined, call it for every row
		for (var ii = 0; ii < aRaw.length; ii++) {
			if (aRaw[ii].length > 0) {
				var tmpSplit = aRaw[ii].split( this._columnDelim ); //split the row according to the column delimiter
				tmpSplit[tmpSplit.length] = this.dataItem;  //always pass the dataItem as the final real parameter just in case the callback function needs it
				if (this._notBlank < 0 || (tmpSplit[this._notBlank] && tmpSplit[this._notBlank] != '')) {
					this.callbackFunction( tmpSplit );  //callback the specified function passing in the column values as paramters
				}

			}
		}
		
    }
    else 
	if (aTarget.length > 0) { //the targetArrays was defined, populate it instead.
		for (var ii = 0; ii < aRaw.length; ii++) {
			if (aRaw[ii].length > 0) {
				var tmpSplit = aRaw[ii].split( this._columnDelim ); //split the row according to the column delimiter
				if (this._notBlank < 0 || (tmpSplit[this._notBlank] && tmpSplit[this._notBlank] != '')) {
					for (var jj = 0; jj < tmpSplit.length; jj++) {
						if (jj < aTarget.length ) {
							if (typeof aTarget[jj] == "object") {
								aTarget[jj].push(tmpSplit[jj]);
                                }
                                else {
								aTarget[jj] = tmpSplit[jj];
							}
						}
					}
				}
			}
		}
		
	}
	
	this._resetData();  //reset whatever we don't need anymore...
}
//resets the data for this instantiation of the object
QuickrBackendDataUtil.prototype._resetData = function() {
	this.rawString = "";
	this._rawArray = new Array();
	this.targetArrays = new Array();
	this.callbackFunction = null;
	this.dataItem = null;
}
//takes the raw string passed from the backend and puts each row into
//a separate entry in the rawArray according to the row delimiter.
QuickrBackendDataUtil.prototype._populateRawArray = function() {

	var sRaw = this.rawString;	
	var aTarget = this._rawArray;

	var tmp = new Array();
	if (sRaw.indexOf(this._rowDelim) > -1) {
		tmp = sRaw.split(this._rowDelim);
		for (var ii = 0; ii < tmp.length; ii++) {
			if (tmp[ii] != "") {
				aTarget.push( tmp[ii] );
			}
		}
    }
    else {
		aTarget.push( sRaw );
	}
}

