/*			UNIVERSAL JAVASCRIPT CODEContains many different functions that can be used in various applications.frm = window.document.forms[0];servername = location.host;protocol = 'http://';formAction = false;*/var protocol;var servername;var doc;var frm;var formAction;function logout() {	window.open("\signin.nsf?logout", "_top" );};//START COOKIE MANAGER ************************************************************function getCookieVal(offset){//Get specified cookie's value	var endstr=doc.cookie.indexOf(";", offset);	if(endstr==-1) endstr=doc.cookie.length;	return unescape(doc.cookie.substring(offset, endstr));}function getCookie(name) {	var arg=name+"=";	var alen=arg.length;	var clen=doc.cookie.length;	var i=0;	while (i < clen) {		var j=i+alen;		if (doc.cookie.substring(i, j)==arg) return getCookieVal(j);		i=doc.cookie.indexOf(" ", i)+1;		if (i==0) break	};	return null;}function setCookie(cookieName, cookieValue) {//Set specified cookies value	doc.cookie = cookieName + "=" + cookieValue + "; path=/";	return true;}function checkCookies() {	//var x = getCookie('retPath');	//alert ('Current return path: ' + x) // + ' -  document: ' + 	//	document.cookie + '  -  doc: ' + doc.cookie);	var nval = Math.floor(Math.random() * 1000000).toString();	setCookie('checkCookie', nval);	var x = getCookie('checkCookie');	if (x == nval) {		alert('Cookies are working. Return val: ' + x);	} else {		alert('Cookies don\'t seem to be enabled. Return val: ' + x);	}}//END COOKIE MANAGER ************************************************************//not sure what this is, but it is NOT universal! Not sure where it's used. 2009-02-26function changeView (form) {	var sel = form.fldSelectView.options[form.fldSelectView.selectedIndex].value;	if (sel != '' && sel.charAt(0) != "-") {		nURL = protocol + servername + '/' + form.fldDbName.value + '/' + sel + '?OpenView';		window.location = nURL;	}};//Used to refresh a form on the web using JavaScript in place of ViewRefreshFieldsfunction refresh(frm) {   var objCurrentFrame = frm;   objCurrentFrame.__Click.value = '$Refresh';   objCurrentFrame.submit();}function searchText (sScope, sString) {//"/" + fldScope + "/?S;//sScope = name of view to search	var tmpScope;	if (sScope == null) {		tmpScope = '';	} else {		tmpScope = '/' + sScope;	}			if (sString =='') {		alert('No search text entered...\nPlease enter search text in the QuickSearch box and try again.');	} else {		nURL = protocol + servername + '/' + frm.fldDbName.value + tmpScope + '?SearchView&Query=' + sString;		window.location = nURL;	}}function getRadioItem(item) {/*This function will get any radio field value and return the value of the option*///t	if(isNaN(item.length))  {//t		s=item.value+'!'//t	}else{		for (var i = 0; i < item.length; i++) {			if (item[i].checked) {break;}		}//t	}	return item[i].value;}function getCheckboxItem(item) {/*This function will get values of all checked boxes for any checkbox field andreturn a string separated by semicolons*/	var s='';	if(isNaN(item.length))  {		//check if NaN first to see if there are one or more elements for this field.		//if isNaN, then only zero or one items in list		s=item.value+'!'	}else{		for (var i = 0; i < item.length; i++) {			if (item[i].checked) {s=s+item[i].value+'!';}		}	}	s = sLeft(s, s.length-1); //removes last separator mark	return s;}function replaceString(oldStr,newStr,fullStr) {/*This function replaces oldS with newS in the string fullS, similar to @ReplacesSubstring in Formula language- oldS is the string you want replaced- newS is the string to replace it with- fullS is the variable being are manipulating*/	parmArray=fullStr.split(oldStr);	var qstring = parmArray.join(newStr);	return qstring;}function replaceSubstring(inputString, fromString, toString) {// Goes through the inputString and replaces every occurrence of fromString with toString	var temp = inputString;	if (fromString == "") {		return inputString;	}	if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)		while (temp.indexOf(fromString) != -1) {			var toTheLeft = temp.substring(0, temp.indexOf(fromString));			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);			temp = toTheLeft + toString + toTheRight;		}	} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop		var midStrings = new Array("~", "`", "_", "^", "#");		var midStringLen = 1;		var midString = "";		// Find a string that doesn't exist in the inputString to be used		// as an "inbetween" string		while (midString == "") {			for (var i=0; i < midStrings.length; i++) {				var tempMidString = "";				for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }				if (fromString.indexOf(tempMidString) == -1) {					midString = tempMidString;					i = midStrings.length + 1;				}			}		} // Keep on going until we build an "inbetween" string that doesn't exist		// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string		while (temp.indexOf(fromString) != -1) {			var toTheLeft = temp.substring(0, temp.indexOf(fromString));			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);			temp = toTheLeft + midString + toTheRight;		}		// Next, replace the "inbetween" string with the "toString"		while (temp.indexOf(midString) != -1) {			var toTheLeft = temp.substring(0, temp.indexOf(midString));			var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);			temp = toTheLeft + toString + toTheRight;		}	} // Ends the check to see if the string being replaced is part of the replacement string or not	return temp; // Send the updated string back to the user} // Ends the "replaceSubstring" functionfunction sLeft(str, n){		 if (n <= 0)		     return "";		 else if (n > String(str).length)		     return str;		 else		     return String(str).substring(0,n);}function sRight(str, n){    if (n <= 0)       return "";    else if (n > String(str).length)        return str;    else {       var iLen = String(str).length;       return String(str).substring(n+1, iLen);//was: return String(str).substring(iLen, iLen - n);    }}String.prototype.Trim = function() {	//Use as: string.Trim()	//trim blank spaces from either side of the string	return this.replace(/(^\s*)|(\s*$)/g, '');}  String.prototype.LTrim = function() {	//Use as: string.LTrim()	// trim blank space at the beginning	return this.replace(/(^\s*)/g, '');}  String.prototype.RTrim = function() {	//Use as: string.RTrim()	// trim blank space at the end	return this.replace(/(\s*$)/g, '');}function searchString (frm) {/*This function creates the search string for the advanced search page. @URLOpen would notwork on the page, so needed to write in JS instead.*/	var dspCountNdx = frm.fldDisplay.selectedIndex;	//d alert(dspCountNdx);		var dspCount = frm.fldDisplay.options[ dspCountNdx ].text;	var connector;	var searchStr = frm.fldWords.value;	var maxResultsNdx = frm.fldMaxResults.selectedIndex;	var maxResults = frm.fldMaxResults.options[ maxResultsNdx ].text;	var radioItem = getRadioItem(frm.fldWType);		if(radioItem == '1') {		connector = ' AND ';	} else if(radioItem == '2') {		connector = ' OR ';	} else {		connector = ' ';	}	//Replace the blank characters in searchStr with the connector	searchForStr = replaceString(" ", connector, searchStr);	var fuzzy = (frm.fldFuzzy.checked) ? 'TRUE' : 'FALSE';	var sort = getRadioItem(frm.fldRelevance);	var wv = (frm.fldVariants.checked) ? 'TRUE' : 'FALSE';	var nurl = './DefaultView/?SearchView&Query=' + searchForStr + '&Count=' + dspCount + 		'&SearchFuzzy=' + fuzzy + '&SearchOrder=' + sort + '&SearchMax=' + maxResults + 		'&SearchWV=' + wv;	//alert(url1);	window.location.href = nurl;}