/* functions for Search string prep DVD 11-04-06 CLEANED */ // Moved from SRT function phraseString(str) { //Alert operators and set Advanced option if (str.indexOf("\"") > -1) {alert(quotesMessage); stringType = "advanced"; return str;} //Alert operators str = "\""+str+"\""; return str; //alert(str); } // Moved from SRT function SearchAndReplace(Content, SearchFor, ReplaceWith) {    var tmpContent = Content;    var tmpBefore = new String();    var tmpAfter = new String();    var tmpOutput = new String();    var intBefore = 0;    var intAfter = 0;    if (SearchFor.length == 0)       return;    while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {           // Get all content before the match       intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());       tmpBefore = tmpContent.substring(0, intBefore);       tmpOutput = tmpOutput + tmpBefore;       // Get the string to replace       tmpOutput = tmpOutput + ReplaceWith;       // Get the rest of the content after the match until       // the next match or the end of the content       intAfter = tmpContent.length - SearchFor.length + 1;       tmpContent = tmpContent.substring(intBefore + SearchFor.length);    }    return tmpOutput + tmpContent; } function setOperators (str,myOp) { str = this != window? this : str; var a = myOp; var b = " "; // Operator ck if (a == "AND") { var otherOp = " OR "; } else {var otherOp = " AND ";} if (str.toUpperCase().indexOf(otherOp.toUpperCase()) > -1) { alert(conflictMessage); } //END Operator ck str = SearchAndReplace(str," "+a+" ",b); // temp REPLACE USER TYPED operators with spaces if in quotes // TEST - tried to use replace function instaed of SearchAndReplace - works but str will be uppercase //str = str.toUpperCase().replace(b+a+b,b); //alert('hi '+str); str = str.replace(/^\s+/g, '').replace(/\s+$/g, ''); // DELETE spaces at start and end return str.replace(/\s+/g, ' '+myOp+' '); // REPLACE all spaces with operators } /* functions fix Special words - operators etc DVD 10-04-06 */ function fixSpecial(Content) { if (Content.toUpperCase().indexOf("FIELD") > -1) { //alert(" FIELD "); Content = SearchAndReplace(Content.toUpperCase(),"FIELD","FIELD*"); } if (Content.toUpperCase().indexOf("PARAGRAPH") > -1) { //alert(" PARAGRAPH "); Content = SearchAndReplace(Content.toUpperCase(),"PARAGRAPH","PARAGRAPH*"); } if (Content.toUpperCase().indexOf("SENTENCE") > -1) { //alert(" SENTENCE "); Content = SearchAndReplace(Content.toUpperCase(),"SENTENCE","SENTENCE*"); } return Content } function prepString(str,Op) { var Content = str; var myOp = Op; //SPECIAL WORDS Content = fixSpecial(Content); //COMMAS if (Content.toUpperCase().indexOf(",") > -1) { alert(" COMMA "); Content = SearchAndReplace(Content.toUpperCase(),"\,",""); } if (Content.indexOf("\"") > -1) {  var tmpBefore = Content.substring(0,Content.indexOf("\"")); //alert("1 is \""+tmpBefore+"\""); tempStr = Content.substring(tmpBefore.length+1,Content.length); //alert("TEMP is \""+tempStr+"\""); var tmpBtw = tempStr.substring(0 ,tempStr.indexOf("\"")); //alert("2 is \""+tmpBtw+"\""); //return; var tmpAfter = tempStr.substring(tempStr.indexOf("\"")+1,tempStr.length); //alert("3 is \""+tmpAfter+"\""); //Alert operators and set Advanced option if (tmpAfter.indexOf("\"") > -1) {alert(quotesMessage); stringType = "advanced"; return str;} tmpBefore = setOperators (tmpBefore,myOp); tmpAfter = setOperators (tmpAfter,myOp); if (tmpBtw != "") { if (tmpBefore != "") { tmpBtw = " "+myOp+" \""+tmpBtw; } else { tmpBtw = "\""+tmpBtw; } if (tmpAfter != "") { tmpBtw = tmpBtw+"\" "+myOp+" "; } else { tmpBtw = tmpBtw+"\""; } } newContent = tmpBefore+tmpBtw+tmpAfter; } //IF NO QUOTES else {newContent = setOperators (Content,myOp);} //document.forms[0].left.value = newContent; return newContent; } //END FUNCT prepString /* functions CREATE and READ cookies for forms - from www.irt.org/articles/js025 */ function Get_Cookie(name) { var start = document.cookie.indexOf(name+"="); var len = start+name.length+1; if ((!start) && (name != document.cookie.substring(0,name.length))) return null; if (start == -1) return null; var end = document.cookie.indexOf(";",len); if (end == -1) end = document.cookie.length; cString = unescape(document.cookie.substring(len,end)); getValues(cString) } function getValues(string) { getValue(string,"LocSearchString", document.formloc.LocSearchString, "text"); getValue(string,"Category", document.formloc.Category, "radio"); getValue(string,"Match", document.formloc.Match, "checkbox"); getValue(string,"ViewCk", document.formloc.ViewCk, "checkbox"); getValue(string,"searchBtnDate", document.formloc.searchBtnDate, "button"); getValue(string,"searchBtnRev", document.formloc.searchBtnRev, "button"); getValue(string,"year", document.formloc.year, "select"); } function replace(string,text,by) { // Replaces text with by in string var i = string.indexOf(text); var newstr = ''; if ((!i) || (i == -1)) return string; newstr += string.substring(0,i) + by; if (i+text.length < string.length) newstr += replace(string.substring(i+text.length,string.length),text,by); return newstr; } function onCheck(string) { if (string == "on") return true; return false; } function getValue(string,elementName,object,elementType) { // gets value of elementName from string and populates object of elementType //alert(string); var startPos = string.indexOf(elementName + "=") if (startPos > -1) { startPos = startPos + elementName.length + 1; var endPos = string.indexOf("£",startPos); if (endPos == -1) endPos = string.length; var elementValue = unescape(string.substring(startPos,endPos)); if (elementType == "text") object.value = elementValue; if (elementType == "password") object.value = elementValue; //070606 use value for select - old - if (elementType == "select") object.selectedIndex = elementValue; if (elementType == "select") object.value = elementValue; if (elementType == "checkbox") object.checked = elementValue; if (elementType == "radio") object[elementValue].checked = true; if (elementType == "button") object.style.fontWeight = elementValue; } }