var concatAnd = "+AND+"; var concatOr = "+OR+"; function openWin( url ) { window.open(url,'new','statusbar=no,width=500,height=250'); } /** * This method is used to convert a search string to danish characters */ function searchFullText( paramList ) { paramList = replacesubstring( paramList, " & ", " AND " ); paramList = replacesubstring( paramList, "&", "%26" ); var list = ""; var tmpList = paramList; var aringTmp = tmpList; var aring = 229; var Aring = 197; var oslash = 248; var oUmlaud = 246; var OUmlaud = 214; var aUmlaud = 228; var AUmlaud = 196; var aelig = 230; if( ( tmpList.indexOf( "oe" ) != -1 ) || ( tmpList.indexOf( "Oe" ) != -1 ) ) { //replace lowercase while( tmpList.indexOf( "oe" ) != -1 ) tmpList = tmpList.replace( "oe", String.fromCharCode( oslash ) ); //replace uppercase while( tmpList.indexOf( "Oe" ) != -1 ) tmpList = tmpList.replace( "Oe", String.fromCharCode( oslash ) ); } if( ( tmpList.indexOf( "o" ) != -1 ) || ( tmpList.indexOf( "O" ) != -1 ) ) { //replace lowercase while( tmpList.indexOf( "o" ) != -1 ) tmpList = tmpList.replace( "o", String.fromCharCode( oslash ) ); //replace uppercase while( tmpList.indexOf( "O" ) != -1 ) tmpList = tmpList.replace( "O", String.fromCharCode( oslash ) ); if( tmpList.indexOf( " " + String.fromCharCode( oslash ) +"r " ) != -1 ) { var ttt = " " + String.fromCharCode( oslash ) + "r "; tmpList = replacesubstring( tmpList, ttt, " OR " ); } } if( tmpList.indexOf( String.fromCharCode( oUmlaud ) ) != -1 || tmpList.indexOf( String.fromCharCode( OUmlaud ) ) != -1 ) { // Replace lowercase while( tmpList.indexOf( String.fromCharCode( oUmlaud ) ) != -1 ) tmpList = tmpList.replace( String.fromCharCode( oUmlaud ), String.fromCharCode( oslash ) ); // Replace uppercase while( tmpList.indexOf( String.fromCharCode( OUmlaud ) ) != -1 ) tmpList = tmpList.replace( String.fromCharCode( OUmlaud ), String.fromCharCode( oslash ) ); } if( ( tmpList.indexOf( String.fromCharCode( aring ) ) != -1 || (tmpList.indexOf(String.fromCharCode( Aring ) ) != -1 ) && tmpList.indexOf( "aa" == -1) && tmpList.indexOf( "Aa" == -1 ) ) ) { // Replace lowercase while( tmpList.indexOf( String.fromCharCode( aring ) ) != -1 ) tmpList = tmpList.replace( String.fromCharCode( aring ) , "aa"); // Replace uppercase while( tmpList.indexOf( String.fromCharCode( Aring ) ) != -1 ) tmpList = tmpList.replace( String.fromCharCode( Aring ), "aa" ); } if( ( (paramList.indexOf( "aa" ) != -1 ) || ( paramList.indexOf( "Aa" ) != -1 ) ) && ( paramList.indexOf( String.fromCharCode( aring) ) == -1 && paramList.indexOf( String.fromCharCode( Aring) ) == -1 )) { // Replace lowercase while( aringTmp.indexOf( "aa" ) != -1 ) aringTmp = aringTmp.replace( "aa", String.fromCharCode( aring ) ); // Replace uppercase while( aringTmp.indexOf( "Aa" ) != -1 ) aringTmp = aringTmp.replace( "Aa", String.fromCharCode( aring ) ); } if( tmpList.indexOf( String.fromCharCode( aUmlaud ) ) != -1 || tmpList.indexOf( String.fromCharCode( AUmlaud) ) != -1 ) { // Replace lowercase while( tmpList.indexOf( String.fromCharCode( aUmlaud ) ) != -1 ) tmpList = tmpList.replace( String.fromCharCode( aUmlaud ), String.fromCharCode( aelig) ); // Replace uppercase while( tmpList.indexOf( String.fromCharCode( AUmlaud ) ) != -1 ) tmpList = tmpList.replace( String.fromCharCode( AUmlaud ), String.fromCharCode( aelig) ); } if( ( tmpList.indexOf( "ae" ) != -1 ) || ( tmpList.indexOf( "Ae" ) != -1 ) ) { //Replace lowercase while( tmpList.indexOf( "ae" ) != -1 ) tmpList = tmpList.replace( "ae",String.fromCharCode( aelig ) ); //Replace uppercase while( tmpList.indexOf( "Ae" ) != -1 ) tmpList = tmpList.replace( "Ae",String.fromCharCode( aelig ) ); } list = buildSearchString( paramList ); var list1 = buildSearchString( aringTmp ); tmpList = buildSearchString( tmpList ); //alert( "tmpList\n" + tmpList + "\nlist:\n" + list + "\naringTmp:\n" + list1 ); if( tmpList.indexOf( list ) == -1 ) { if( tmpList.indexOf( list1 ) == -1 ) tmpList = "(" + tmpList + ")";// + concatOr + "(" + list1 + ")"; else tmpList = "(" + tmpList + ")"; list = "(" + list + ")" + concatOr + tmpList; }else{ if( tmpList.indexOf( list1 ) == -1 ) { tmpList = "(" + tmpList + ")" + concatOr + "(" + list1 + ")"; } list = "(" + tmpList + ")"; } var tmp = check( list ); list += tmp; //alert( list + tmp ); var url = "/billeder/billeddb.nsf/vSearchView?searchView&Query=" + list; url = replacesubstring( url, "%20", "+" ); url = replacesubstring( url, " ", "+" ); location.href = url + "&start=1&count=10&SearchOrder=4"; } function check( params ) { var list = replacesubstring( params, " and ", " AND " ); var plist = new Array(); var operator = ""; list = replacesubstring( list, " or ", " OR " ); list = replacesubstring( list, "*", "" ); if( list.indexOf( " AND " ) != -1 ) operator = " AND "; else if( list.indexOf( " OR " ) != -1 ) operator = " OR " var years = new Array(); var words = new Array(); var result = ""; years = cfyGetNumbers( list ); words = cfyGetText( list ); if( !years ) return; for( i = 0; i < years.length; i++ ) { for( t = 0; t < words.length; t++ ) { result += concatOr + "(" + words[t] + "*" + operator + "[year]=" + years[i] + ")"; } } return result; } function cfyGetNumbers( params ) { var strlist = replacesubstring( params, " and ", " AND " ); strlist = replacesubstring( strlist, " or ", " OR " ); strlist = replacesubstring( strlist, "*", "" ); strlist = replacesubstring( strlist, "(", "" ); strlist = replacesubstring( strlist, ")", "" ); strlist = replacesubstring( strlist, "+OR+", " OR " ); strlist = replacesubstring( strlist, "+AND+", " AND " ); var list1 = new Array(); var list2 = new Array(); var result = new Array(); var operatorOR = " OR "; var operatorAND = " AND "; var counter = 0; list1 = explode( strlist, operatorOR ); for( i = 0; i < list1.length; i++ ) { var str = list1[i]; list2 = explode( str, operatorAND ); for( t = 0; t < list2.length; t++ ) { var tmps = list2[t]; //Only add strings that are potential numbers. var num = Number( tmps ); if( num ){ //need to check if number is already in array var alreadyUsed = false; for( z = 0; z < result.length; z++ ) { if( result[z] == tmps ) alreadyUsed = true; } if( !alreadyUsed ) result[counter++] = tmps; } } } return result; } function cfyGetText( params ) { var strlist = replacesubstring( params, " and ", " AND " ); strlist = replacesubstring( strlist, " or ", " OR " ); strlist = replacesubstring( strlist, "*", "" ); strlist = replacesubstring( strlist, "(", "" ); strlist = replacesubstring( strlist, ")", "" ); strlist = replacesubstring( strlist, "+OR+", " OR " ); strlist = replacesubstring( strlist, "+AND+", " AND " ); var list1 = new Array(); var list2 = new Array(); var result = new Array(); var operatorOR = " OR "; var operatorAND = " AND "; var counter = 0; list1 = explode( strlist, operatorOR ); for( i = 0; i < list1.length; i++ ) { var str = list1[i]; list2 = explode( str, operatorAND ); for( t = 0; t < list2.length; t++ ) { var tmps = list2[t]; //Only add strings that are not potential numbers. var num = Number( tmps ); if( !num ) result[counter++] = tmps; } } return result; } function checkForYear( params ) { var list = replacesubstring( params, " and ", " AND " ); var plist = new Array(); var operator = ""; list = replacesubstring( list, " or ", " OR " ); list = replacesubstring( list, "*", "" ); if( list.indexOf( " AND " ) != -1 ) operator = " AND "; else if( list.indexOf( " OR " ) != -1 ) operator = " OR " if(operator == "" ) { var nmb; try { var tmp; tmp = replacesubstring(params, "*", "" ); tmp = replacesubstring(params, "(", "" ); tmp = replacesubstring(params, ")", "" ); nmb = Number( tmp); }catch(e){ }finally{ if( nmb ) { result = "[year]=" + nmb; } } if( result == "" ) return; else return result; } plist = explode( list, operator ); var result = ""; var foundNumeric = false; for( i = 0; i < plist.length; i++ ) { var num; try{ var tmp = plist[i]; tmp = replacesubstring(tmp, "*", "" ); tmp = replacesubstring(tmp, "(", "" ); tmp = replacesubstring(tmp, ")", "" ); num = Number( String( tmp ) ); }catch( e ){ //if( e instanceof Error ){ //alert( e.name + ", " + e.message ) //} }finally{ if( num ) { foundNumeric = true; if( i == plist.length-1 ) result += "[year]=" + plist[i]; else result += "[year]=" + plist[i] + operator; }else{ if( i == plist.length-1 ) result += plist[i] + "*"; else result += plist[i] + "*" + operator; } } } //alert( "Result:\n" + result ); if( foundNumeric ) return result; else return; } function buildSearchString( paramList ) { var paramArr = new Array(); var result = new Array(); var newList = ""; var counter = 0; var operator = ""; var list = replacesubstring( paramList, " and ", " AND " ); list = replacesubstring( list, " or ", " OR " ); if( list.indexOf( " AND " ) != -1 ) operator = " AND "; else if( list.indexOf( " OR " ) != -1 ) operator = " OR "; if( operator != "" ) paramArr = explode( list, operator ); else{ return list + "*"; } for( i = 0; i < paramArr.length; i++ ) { if( i == paramArr.length-1 ) newList += paramArr[i] + "*"; else newList += paramArr[i] + "*" + operator; } return newList; } function multiParamSearch() { var form = document.fSearchChoice; var url = "/billeder/billeddb.nsf/vSearchView?searchView" var people = form.people.options[form.people.selectedIndex].text; var locale = form.locale.options[form.locale.selectedIndex].text; var date = form.date.value; var year = form.year.value; var decade = form.decade.options[form.decade.selectedIndex].text; var imageType = form.imageType.options[form.imageType.selectedIndex].text; var fileFormat = form.fileFormat.options[form.fileFormat.selectedIndex].text; var params = ""; var s = ""; if( people != "" ) { if( params != "" ) params += "%20and%20"; if( people.indexOf( "&" ) != -1 ) people = replacesubstring( people, "&", "%26" ); params += "([people]=" + people + ")"; } if( locale != "" ) { if( params != "" ) params += "%20and%20"; if( locale.indexOf( "." ) != -1 ) locale = replacesubstring( locale, ".", "%2E" ); if( locale.indexOf( "&" ) != -1 ) { //alert( "replacing & with %26" ); locale = replacesubstring( locale, "&", "%26" ); } params += "([locale]=" + locale +")"; } if( date != "" ) { if( params != "" ) params += "%20and%20"; params += "(" + searchDate( date ) + ")"; s = "date"; }else{ if( year != "" ) { if( params != "" ) params += concatAnd; params += "(" + searchYear( year ) + ")"; s = "year"; }else{ if( decade != "Alle" ) { if( params != "" ) params += concatAnd; params += "(" + searchDecade( decade ) + ")"; } } } if( imageType != "Alle" && imageType != "" ) { if( params != "" ) params += "%20and%20"; params += "([imageType]=" + imageType +")"; } if( fileFormat != "Alle" && fileFormat != "" ) { if( params != "" ) params += "%20and%20"; params += "([original]=" + fileFormat +")"; } if( params == "" ) return false; params = replacesubstring( params, " ", "+"); params = replacesubstring( params, "%20", "+" ); url += "&Query=" + params + "&start=1&count=10&searchorder=4"; if( s != "" ) url += "&s=" + s; location.href = url; } function searchDate( date ) { var params = ""; params += "[date]=" + date; return params; } function searchYear( year ) { var params = ""; params += "([year]=" + year +")"; params += concatOr + "([date]>=01-01-" + year + concatAnd + "[date]<=31-12-" + year +")"; //params += "&s=year"; return params; } function searchDecade( decade ) { var params = "([decade]=" + decade +")"; var temp = new Array(); temp = explode( decade, ' - ' ); params += concatOr + "([year]>=" + temp[0] + concatAnd + "[year]<=" + temp[1] + ")"; params += concatOr + "([date]>=01-01-" + temp[0] + concatAnd + "[date]<=31-12-" + temp[1] + ")"; return params; } function replacesubstring( source, oldPattern, newPattern ) { var s = source; var DEBUG = false; if( DEBUG ) alert( "source: " + s +"; old: " + oldPattern + ", new: " + newPattern ); while( s.indexOf( oldPattern ) != -1 ) { s = s.replace( oldPattern, newPattern ); } return s; } function explode(inputStr, separatorStr) { var arr = new Array(); var startIndex = 0; var counter = 0; var newIndex = inputStr.indexOf(separatorStr); var lastChar = (inputStr.substr(inputStr.length-1)); if(inputStr.length>1) { while (newIndex != -1) { if(lastChar != "\n") { arr[counter] = inputStr.substring(startIndex, newIndex); counter++; } startIndex = newIndex + separatorStr.length; var newIndex = inputStr.indexOf(separatorStr, startIndex); } if(newIndex == -1) arr[counter] = inputStr.substring(startIndex, inputStr.length); } return arr; }