function doSearch(tmpSearch,tmpSearch2) { if (tmpSearch=="") { alert('Du måste skriva in något att söka efter') } else { webPath="/web/odes/internet.nsf"; tmpSearch=replaceSubstring(tmpSearch, " and ","* and *"); tmpSearch=replaceSubstring(tmpSearch, " AND ","* AND *"); tmpSearch=replaceSubstring(tmpSearch, " And ","* And *"); tmpSearch=replaceSubstring(tmpSearch, " or ","* or *"); tmpSearch=replaceSubstring(tmpSearch, " OR ","* OR *"); tmpSearch=replaceSubstring(tmpSearch, " Or ","* Or *"); if (tmpSearch2=="SAddr") { this.location.href=webPath +"/Search?SearchView&Query=(*"+tmpSearch+"*)%20and%20Search82kmnsofjspw&SearchOrder=1&SearchWV=TRUE&Start=1&Count=250&SearchMax=250&NavPath=NavStyle1L2~Kontaktaoss"; } else if (tmpSearch2=="SHapp") { this.location.href=webPath +"/Search?SearchView&Query=(*"+tmpSearch+"*)%20and%20Happeninguhwoks7ytr&SearchOrder=1&SearchWV=TRUE&Start=1&Count=250&SearchMax=250&NavPath=NavStyle1L2~Evenemang"; } else if (tmpSearch2=="SAsso") { this.location.href=webPath +"/HTMLDBAsso3?SearchView&Query=(*"+tmpSearch+"*)%20and%20Type3Asso8792923ds&SearchOrder=1&SearchWV=TRUE&Start=1&Count=250&SearchMax=250&NavPath=NavStyle1L3~Kultur/Natur/Fritid;F%C3%B6reningar"; } else if (tmpSearch2=="SComp") { this.location.href=webPath +"/HTMLDBComp3?SearchView&Query=(*"+tmpSearch+"*)%20and%20Type3Comp9753874uh&SearchOrder=1&SearchWV=TRUE&Start=1&Count=250&SearchMax=250&NavPath=NavStyle1L2~N%e4ringsliv"; } else { this.location.href=webPath +"/Search?SearchView&Query=(*"+tmpSearch+"*)&SearchOrder=1&SearchWV=TRUE&Start=1&Count=250&SearchMax=250"; } } } 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 }