var parserPek = 0; var parserStr = 0; function parserInit(str) { parserPek = 0; parserStr = str; } function parserGetOperator() { var operator = "" var opChars = " +-" if (parserPek >= parserStr.length) { return "EOT" } var tkn = parserStr.charAt(parserPek) while (parserPek < parserStr.length && opChars.indexOf(tkn) >= 0) { if (tkn == "+" || tkn == "-") operator = tkn if (++parserPek < parserStr.length) tkn = parserStr.charAt(parserPek) else operator = "EOT" } return operator } function parserGetString() { var string = "" var hotChars = " +-\"" // Skip spaces while (parserPek < parserStr.length && parserStr.charAt(parserPek) == " ") parserPek++ // Check end-of-text if (parserPek >= parserStr.length) { return "EOT" } var tkn = parserStr.charAt(parserPek) if (tkn == "\"") { // Handle quoted string tkn = parserStr.charAt(++parserPek) while (parserPek < parserStr.length && tkn != "\"") { string += tkn if (++parserPek < parserStr.length) tkn = parserStr.charAt(parserPek) } if (parserStr.charAt(parserPek) == "\"") parserPek++ } else { // Handle single word while (parserPek < parserStr.length && hotChars.indexOf(tkn) < 0) { string += tkn if (++parserPek < parserStr.length) tkn = parserStr.charAt(parserPek) } } return string } function translateDebateString(string) { var partAnd = "", glueAnd = "" var partOr = "", glueOr = "" var partNot = "", glueNot = "" var query = ""; glue = "" parserInit(string) do { op = parserGetOperator() str = parserGetString() if (str.indexOf("\"") < 0) str = "\"" + str + "\""; if (op != "EOT" && str != "EOT" && str != "") { if (op == "+") { partAnd += glueAnd + str glueAnd = " and " } else if (op == "-") { partNot += glueNot + "not " + str glueNot = " and " } else { partOr += glueOr + str glueOr = " or " } } } while (op != "EOT") if (partOr) { query += glue + "( " + partOr + " )" glue = " and " } if (partAnd) { query += glue + partAnd glue = " and " } if (partNot) { query += glue + partNot glue = " and " } return query } function translateString(string) { var partAnd = "", glueAnd = "" var partOr = "", glueOr = "" var partNot = "", glueNot = "" var query = ""; glue = "" parserInit(string) do { op = parserGetOperator() str = parserGetString() if (op != "EOT" && str != "EOT" && str != "") { if (op == "+") { //partAnd += glueAnd + "\"" + str + "\"" partAnd += glueAnd + str glueAnd = " and " } else if (op == "-") { //partNot += glueNot + "not \"" + str + "\"" partNot += glueNot + "not " + str glueNot = " and " } else { //partOr += glueOr + "\"" + str + "\"" partOr += glueOr + str glueOr = " or " } } } while (op != "EOT") if (partOr) { query += glue + "( " + partOr + " )" glue = " and " } if (partAnd) { query += glue + partAnd glue = " and " } if (partNot) { query += glue + partNot glue = " and " } return query } function translateStringToSQL(string) { var partAnd = "", glueAnd = "" var partOr = "", glueOr = "" var partNot = "", glueNot = "" var query = ""; glue = "" parserInit(string) do { op = parserGetOperator() str = parserGetString() str = "XXXXX like _1_" + str + "_2_" if (op != "EOT" && str != "EOT" && str != "") { if (op == "+") { partAnd += glueAnd + str glueAnd = " and " } else if (op == "-") { partNot += glueNot + "not " + str glueNot = " and " } else { partOr += glueOr + str glueOr = " or " } } } while (op != "EOT") if (partOr) { query += glue + "( " + partOr + " )" glue = " and " } if (partAnd) { query += glue + partAnd glue = " and " } if (partNot) { query += glue + partNot glue = " and " } return query } function translateStringforASP(string) { //Translate string for MS Indexing Service var partAnd = "", glueAnd = "" var partOr = "", glueOr = "" var partNot = "", glueNot = "" var query = ""; glue = "" parserInit(string) do { op = parserGetOperator() str = parserGetString() if (op != "EOT" && str != "EOT" && str != "") { if (str.indexOf("\"") < 0) str = "\"" + str + "\""; if (op == "+") { partAnd += glueAnd + str glueAnd = " and " } else if (op == "-") { partNot += glueNot + "not " + str glueNot = " and " } else { partOr += glueOr + str glueOr = " or " } } } while (op != "EOT") if (partOr) { query += glue + " " + partOr + " " glue = " and " } if (partAnd) { query += glue + partAnd glue = " and " } if (partNot) { query += glue + partNot glue = " and " } return query } function isDateYYYY_MM_DD(s) { if (s.length != 10) return false if (s.indexOf("-") != 4 || s.indexOf("-", 5) != 7) return false var yy = s.substring(0, 4) - 0 var mm = s.substring(5, 7) - 0 var dd = s.substring(8, 10) - 0 if (yy >= 1900 && yy <= 2200 && mm >= 1 && mm <= 12 && dd >= 1 && ( ((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && dd <= 31) || ((mm == 2) && dd <= (yy % 4 == 0 ? 29 : 28)) || ((mm == 4 || mm == 6 || mm == 9 || mm == 11 ) && dd <= 30) ) ) { return true } return false } function isDateYYYYMMDD(s) { if (s.length != 8) return false var yy = s.substring(0, 4) - 0 var mm = s.substring(4, 6) - 0 var dd = s.substring(6, 8) - 0 if (yy >= 1900 && yy <= 2200 && mm >= 1 && mm <= 12 && dd >= 1 && ( ((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && dd <= 31) || ((mm == 2) && dd <= (yy % 4 == 0 ? 29 : 28)) || ((mm == 4 || mm == 6 || mm == 9 || mm == 11 ) && dd <= 30) ) ) { return true } return false } function chkDateInterval(from, to) { if (from > to) return false; return true; } function chkSimple(theForm) { if (isEmpty(theForm.searchString.value)) { alert("Du måste ange ett sökord!"); return false; } return true; } function chkAdvanced(theForm) { if (isEmpty(theForm.searchString.value) && isEmpty(theForm.validFrom.value) && isEmpty(theForm.validTo.value) && isSelected(theForm.levelOneId) < 0 && isSelected(theForm.orgLevelOneId) < 0) { alert("Du måste ange något av följande sökvillkor! Sökord, datum"); setObjectMarked(theForm.searchString); return false; } if (!isEmpty(theForm.validFrom.value)) { if (!isDateYYYYMMDD(theForm.validFrom.value)) { alert("Ange datum i formatet ÅÅÅÅMMDD!"); theForm.validFrom.focus(); theForm.validFrom.select(); return false; } } if (!isEmpty(theForm.validTo.value)) { if (!isDateYYYYMMDD(theForm.validTo.value)) { alert("Ange datum i formatet ÅÅÅÅMMDD!"); theForm.validTo.focus(); theForm.validTo.select(); return false; } } if (!isEmpty(theForm.validFrom.value) && !isEmpty(theForm.validTo.value)) { if (!chkDateInterval(theForm.validFrom.value,theForm.validTo.value)) { alert("Ogiltigt datum intervall!"); theForm.validTo.focus(); theForm.validTo.select(); return false; } } return true; } function doAdvancedSearch(theForm) { if (theForm.noCheck.value == 1) return true; if (chkSimple(theForm)) { setSearchExpression(theForm); theForm.simpleSearch.value="true"; return true; } return false; } function doAdvancedSearch_cat(theForm) { if (theForm.SearchStarted.value != "true") { if (theForm.noCheck.value == 1) return true; if (chkAdvanced(theForm)) { if (isEmpty(theForm.searchString.value)) { theForm.sortorder.value=2; theForm.sortorder[1].checked="true"; theForm.sortRelevans.value=""; theForm.sortDate.value="checked"; } window.document.simplesearchform.SearchStarted.value = "true"; theForm.SearchStarted.value = "true"; theForm.imgSearching.style.display="block"; setSearchExpression(theForm); setMetaExpressions(theForm); return true; } } return false; } function doSimpleSearch(theForm) { if (theForm.SearchStarted.value != "true") { theForm.searchString.value = theForm.searchStringSimple.value; if (chkSimple(theForm)) { // Because form.object.x dosn't work theForm.SearchStarted.value = "true"; theForm.simpleSearch.value = "true"; setSearchExpression(theForm); return true; } } return false; } function doSimpleSearchPrj(theForm) { theForm.searchString.value = theForm.searchStringSimple.value; if (chkSimple(theForm)) { // Because form.object.x dosn't work theForm.SearchStarted.value = "true"; theForm.simpleSearch.value = "true"; setSearchExpressionPrj(theForm); return true; } return false; } function doSimpleSearch2(theForm) { if (theForm.SearchStarted.value != "true") { if (theForm.noCheck.value == 1) return true; if (chkSimple(theForm)) { if (isEmpty(theForm.searchString.value)) { theForm.sortorder.value=2; theForm.sortorder[1].checked="true"; theForm.sortRelevans.value=""; theForm.sortDate.value="checked"; } window.document.simplesearchform.SearchStarted.value = "true"; theForm.simpleSearch.value = "true"; theForm.SearchStarted.value = "true"; theForm.imgSearching.style.display="block"; setSearchExpression(theForm); return true; } } return false; } function AdvancedSearchFormReset(theForm) { if (theForm.SearchStarted.value != "true") { theForm.sortorder.value=1; theForm.sortorder[0].checked="true"; theForm.sortRelevans.value="checked"; theForm.sortDate.value=""; theForm.searchString.value=""; theForm.validFrom.value=""; theForm.validTo.value=""; //theForm.orgLevelOneId.selectedIndex=0; if (theForm.levelOneId.selectedIndex != 0) { theForm.levelOneId.selectedIndex=0; theForm.submit(); } } } function getLevelOneExpression(theForm) { var levelOneId = isSelected(theForm.levelOneId); if (levelOneId != "-1") return "hgfLevelOneId,=," + levelOneId; return ""; } function getLevelTwoExpression(theForm) { var levelTwoId = isSelected(theForm.levelTwoId); if (levelTwoId != "-1") return "hgfLevelTwoId,=," + levelTwoId; return ""; } function getLevelThreeExpression(theForm) { var levelThreeId = isSelected(theForm.levelThreeId); if (levelThreeId != "-1") return "hgfLevelThreeId,=," + levelThreeId; return ""; } function getLevelFourExpression(theForm) { var levelFourId = isSelected(theForm.levelFourId); if (levelFourId != "-1") return "hgfLevelFourId,=," + levelFourId; return ""; } function getOrgLevelOneExpression(theForm) { var orgLevelOneId = isSelected(theForm.orgLevelOneId); if ( orgLevelOneId > 0) return "hgfOrgLevelOneId,=," + orgLevelOneId; return ""; } function getDateFromExpression(theForm) { var validFrom = theForm.validFrom.value; if (!isEmpty(validFrom)) return "_idxValidFrom,>=," + validFrom; return ""; } function getDateToExpression(theForm) { var validTo = theForm.validTo.value; if (!isEmpty(validTo)) return "_idxValidFrom,<=," + validTo; return ""; } function setMetaExpressions(theForm) { var metaNo = 1 + 0; //test1 var defaultMeta = "hgfLinkText,<>,"; var levelOneMeta = getLevelOneExpression(theForm); var levelTwoMeta = getLevelTwoExpression(theForm); var levelThreeMeta = getLevelThreeExpression(theForm); var levelFourMeta = getLevelFourExpression(theForm); var orgLevelOneMeta = getOrgLevelOneExpression(theForm); var dateFromMeta = getDateFromExpression(theForm); var dateToMeta = getDateToExpression(theForm); // User defined meta expressions if (!isEmpty(levelFourMeta)) theForm["metaExpression" + metaNo++].value = levelFourMeta; else if (!isEmpty(levelThreeMeta)) theForm["metaExpression" + metaNo++].value = levelThreeMeta; else if (!isEmpty(levelTwoMeta)) theForm["metaExpression" + metaNo++].value = levelTwoMeta; else if (!isEmpty(levelOneMeta)) theForm["metaExpression" + metaNo++].value = levelOneMeta; //if (!isEmpty(orgLevelOneMeta)) // theForm["metaExpression" + metaNo++].value = orgLevelOneMeta; if (!isEmpty(dateFromMeta)) theForm["metaExpression" + metaNo++].value = dateFromMeta; if (!isEmpty(dateToMeta)) theForm["metaExpression" + metaNo++].value = dateToMeta; } function setSearchExpression(theForm) { var sTranslateString; theForm.searchString.value = fixSingleQuot(theForm.searchString.value); theForm.searchExpression.value = translateStringforASP(theForm.searchString.value); //Convert search string for projektplatsen (sql search) sTranslateString = theForm.searchString.value; sTranslateString = sTranslateString.replace(/\*/gi,""); sTranslateString = translateStringToSQL(sTranslateString ); sTranslateString = sTranslateString.replace(/"/gi,""); } function setSearchExpressionPrj(theForm) { var sTranslateString; theForm.searchString.value = fixSingleQuot(theForm.searchString.value); theForm.searchExpression.value = translateStringforASP(theForm.searchString.value); //Convert search string for projektplatsen (sql search) sTranslateString = theForm.searchString.value; sTranslateString = sTranslateString.replace(/\*/gi,""); sTranslateString = translateStringToSQL(sTranslateString ); sTranslateString = sTranslateString.replace(/"/gi,""); theForm.PrjSearchExpressionSQL.value = escape(escape(sTranslateString)); theForm.PrjSearchString.value = escape(escape(theForm.searchString.value)); theForm.PrjSearchExpression.value = escape(escape(theForm.searchExpression.value)); }