/* ***************************************************************** */
/*                                                                   */
/* IBM Confidential                                                  */
/*                                                                   */
/* OCO Source Materials                                              */
/*                                                                   */
/* Copyright IBM Corp. 2007, 2008                                    */
/*                                                                   */
/* 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",
	
	loadLocale: function() {
	
	
		if ( QuickrCookieUtil.hasCookie(this._STRINGLOCALECOOKIE) ) {
			this._stringLocale = QuickrCookieUtil.getCookie(this._STRINGLOCALECOOKIE).split(",");
		} else {
			this.loadLocaleForTarget("/qphtml/skins/common", "QuickrCommonStrings.js", this._stringLocale, this._STRINGLOCALECOOKIE);
		}
		
		if ( QuickrCookieUtil.hasCookie(this._STYLELOCALECOOKIE) ) {
			this._styleLocale = QuickrCookieUtil.getCookie(this._STYLELOCALECOOKIE).split(",");
		} else {
			this.loadLocaleForTarget("/qphtml/skins/common/themes", "core.css", this._styleLocale, this._STYLELOCALECOOKIE);
		}
	
	},
	
	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 testurl = rootUrl + sbase + "/nls/" + curLanguages[i] + "/" + 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.shift();
		djConfig.extraLocale = langs;
		
		dojo.locale = djConfig.locale;
		dojo.extraLocale = langs;
		
		
		
		
		//to be used for localization	
		dojo.require("dojo.i18n.common");
		
		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;
		
	},
	
	loadCssFiles: function (sThemePath, sThemeCss) {
		
		
		//remove any legacy CSS files.  We're starting new!!!
		var linktags = document.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") {
					cssRemove[cssRemove.length] = linktag;
				}
			}
		}
		
		
		//load the css files
		var useLang = ( QuickrLocaleUtil.getStyleLocaleList() )[0];
		
		var defLang = "en";
		
		var CSSCOMMON_BASE_DEF = "/qphtml/skins/common/themes/nls/" + defLang + "/";
		var CSSCOMMON_BASE = "/qphtml/skins/common/themes/nls/" + useLang + "/";
		
		
		var cssList = new Array();

		cssList[cssList.length] = CSSCOMMON_BASE + "core.css";
		cssList[cssList.length] = CSSCOMMON_BASE + "defaultTheme.css";
		if ( h_ClientBrowser && h_ClientBrowser.isIE() ) {
			cssList[cssList.length] = CSSCOMMON_BASE + "iehacks.css";
		}

		
		if (typeof(sThemeCss) != "undefined" && sThemeCss != null) {
			cssList[cssList.length] = sThemePath + "/nls/" + useLang + "/" + sThemeCss;
		}
		
		var head = document.getElementsByTagName("head");
		
		if (head && head[0]) {
			for (var i = 0; i < cssList.length; i++) {
				if (i < cssRemove.length) {
					cssRemove[i].href = (cssList[i]);

				} else {
					var skinCss = document.createElement("link");
					skinCss.rel = ("stylesheet");
					skinCss.type = ("text/css");
					skinCss.href = (cssList[i]);
					head[0].appendChild(skinCss);
				}

			
			}

		}
	
	},
	
	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();		
	},	
	
	
	
	
	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.io.bind({
					url: urlCgiScript,
					method: "get",
					mimetype: "text/plain",
					load: function(type, data, evt){
						document.getElementById(idx).src = urlCgiScript;
					},
					error: function(type, error){
					},
					sync: true,
					transport: "XMLHTTPTransport"
				});

			}
			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 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;
	
	}	


}



var QuickrGeneralUtil = {

	_defaultServletRoot: "/servlet",
	
	getServletRoot: function() {
		return QuickrGeneralUtil._defaultServletRoot;
	},
	
	
	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 ALL_CHARS = "0123456789.";
		var ret = "";
		
		val += "..";
		
		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 == ".") {
					ALL_CHARS = "0123456789";
				}
			}
			
		}
		
		var num = ret;
		num++;
		num--;
		return num;
	},
	
	formatBytes: function (val) {
		var BYTE_TO_KB = 1024;
		var BYTE_TO_MB = 1048576;
		var suffix = " B";
		
		
		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;
		
		
		return ret + suffix;
	
	},
	
	isBlank: function (val) {
		return (typeof(val) == "undefined" || val == "" || val == null);
	
	}
	
	
	

}

var QuickrDateUtil = {

	getDateTimeString: function ( date, dateSelector, dateLength ) {
		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";
		}		
		
		dojo.require("dojo.date.format");
		dojo.requireLocalization("qdojo.i18n.calendar", "gregorian");
		dojo.date.addCustomFormats("qdojo.i18n.calendar","gregorian");

		
	
		return dojo.date.format(date, {selector:dateSelector, formatLength:dateLength, locale:QuickrLocaleUtil.getStringLocaleList()[0]});
	
	},
	
	getDateString: function  (date, dateLength) {
		return this.getDateTimeString(date, "dateOnly");
	},

	getTimeString: function (date, dateLength) {
		return this.getDateTimeString(date, "timeOnly");
	},
	
	convertStringToDate: function (xmlDateTime) {
	
		if (xmlDateTime.indexOf('T') == -1) {
			var d;
			var sep = "";
			
			var dt = xmlDateTime.split(' ');
			var dp = dt[0];
			var tp = dt[1];
			
			var ampm = "AM";
			if (dt.length > 2) ampm = dt[2];
			
			
			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) {
						while(hm[0].substring(0,1) == "0") {
							hm[0] = hm[0].substring(1);
						}
						hm[0] = parseInt(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])) {
						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];
		var iYear = xDate.substring(0,4)-0;
		var iMonth = xDate.substring(4,6)-1;
		var iDay = xDate.substring(6,8)-0;

		var xTime = xmlDateTime.split('T')[1].split(',')[0];
		var iHours = xTime.substring(0,2)-0;
		var iMins = xTime.substring(2,4)-0;
		var iSecs = xTime.substring(4,6)-0;
		
		return new Date(iYear, iMonth, iDay, iHours, iMins, iSecs);	
	},


	returnDateTimeString: function (xmlDateTime) {
		
		
		var dDate = this.convertStringToDate(xmlDateTime);
		
		
		if (typeof dDate != 'string')
			return this.getDateString(dDate) + ' ' + this.getTimeString(dDate);
		else
			return dDate;
	}
}

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) {
		document.cookie = name + "=" + escape(value) + "; 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;;
		
		try {
			dojo.io.bind({
				url: url,
				method: "get",
				
				load: function(type, data, evt) {
					if (typeof(responseFunc) == "string") {
						responseFunc = eval(responseFunc);
					}
					if (typeof(responseFunc) == "function") {
						responseFunc (data, this.url);
					}					
				},
				
				error: function(type, error) {
					if (typeof(errorFunc) == "string") {
						errorFunc = eval(errorFunc);
					}
					if (typeof(errorFunc) == "function") {
						errorFunc (type, error);
					}
				},
				
				timeoutSeconds: timeoutSecs,
				
				timeout: function(type, data, evt) {
					if (typeof(timeoutFunc) == "string") {
						timeoutFunc = eval(timeoutFunc);
					}
					if (typeof(timeoutFunc) == "function") {
						timeoutFunc (type, data, evt);
					}
				},
				
				sync: doSync,
				
				mimetype: "text/plain",
				transport: "XMLHTTPTransport"
			});
		}
		catch(e) {

		}
		
	}
	
	
}


var QuickrSetupUtil = {

	strings: {
		ERRORS: {
			PLACE_NOT_FOUND: 		"Impossible de trouver les fichiers partagés pour \"{0}\""
		},
		
		ENTRYWINDOWTITLE: 				"Rechercher les fichiers partagés - IBM Lotus Quickr"
	},

	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 = QuickrSetupUtil.strings.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 );
				
			} 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 = "/" + 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 );
			
			return false;
					
		
	},
	
	_ERRORSHOWN: false,
	processFilesPlace: function ( xmlstring ) {
		eval(xmlstring);
		
		if (QuickrEntryPlaceInfo.exists) {
			window.location.href = QuickrEntryPlaceInfo.placeLocation;
		} else {
			if (!QuickrSetupUtil._ERRORSHOWN) {
				var err = QuickrSetupUtil.strings.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();
			}
			
		}
		
		
		
	},
	
	getTextWidth: function( text ) {
		var elSpan = document.createElement("span");
		elSpan.className = "lotusText";
		elSpan.innerHTML = text;
		document.body.appendChild(elSpan);
		var spanWidth = elSpan.offsetWidth;
		elSpan.parentNode.removeChild(elSpan);
		return spanWidth;		
	},
	
	adjustPrefilledTextBox: function( id, extraPX ) {
		var elSearch = dojo.byId(id);
		if (elSearch) {
			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 = {

	strings: {
		CHOICES: {
			BANNER:		"** NOMBRE de résultats disponibles. Affichage des 15 premiers uniquement",
			
					/* {0} is the common name, {1} is the email address */
			FORMAT:		"{0} ({1})"
		},
		
		ERRORS: {
			GENERAL:	"Erreur lors de la recherche de &quot;{0}&quot;"
		}
		
	},
	
	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;
	},

	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.io.bind({
				url: svcUrl,
				method: "get",
				mimetype: "text/plain",	// PNOT79UP7H
				load: function(type, data, evt){
					var xmlData=MemberLookupUtil.getXMLDocFromString(data);	// PNOT79UP7H
					MemberLookupUtil.showNames(xmlData,val);
				},
				error: function(type, error){MemberLookupUtil.error(error,val);},
				transport: "XMLHTTPTransport"
			});

			var html='<ul'
				 + '<li class="selected">'
				 + '<img src="/qphtml/html/common/ajax_loader.gif"/>'
				 + '&nbsp;<em>Recherche</em>&hellip;'
				 + '</li></ul>';

			var el = dojo.byId("m_autocomplete"+MemberLookupUtil.curRole+"_choices");
			
			el.innerHTML=html;
			el.style.display="block";
		}
		catch(e) {
		}
	},

	error: function(err,sLookup) {

		var html='<ul'
		+ '<li tabindex="0" class="selected">'
		+ 'Erreur lors de la recherche de "'+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 == "") {
			alert("Erreur : le nom sélectionné n'a pas d'adresse e-mail.");
		
		} 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 = MemberLookupUtil.strings.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) {
			html += '<a class="selected">Aucun nom disponible.</a>';
		}
		else {
			if (nEntries > this.maxNames) {
				html += '<a><em>** '+nEntries+' noms disponibles. Affichage des '+this.maxNames+' premiers noms uniquement.</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;
		
	}	


}

