function dominoEncodeURIComponent(instr) {
  var str = instr.toString();
  var resultStr = "";
  var asciiUnEnc = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
  var i;
  var codePointSave;
  var surrogate = false;
  var vals = new Array(0,0,0,0);
  for (i = 0; i < str.length; i++) {
    var codePoint = str.charCodeAt(i);
    var nVals = 0;
    if (codePoint >= 0xDC00 && codePoint <= 0xDFFF) {
      if (surrogate) {
        vals[0] = ((((codePointSave & 0x03C0) >> 6) + 1) >> 2 ) | 0xF0;
        vals[1] = (((((codePointSave & 0x03C0) >> 6) + 1) & 0x03) << 4) | ((codePointSave & 0x003C) >> 2) | 0x80;
        vals[2] = ((codePointSave & 0x0003) << 4) | ((codePoint & 0x03C0) >> 6) | 0x80;
        vals[3] = (codePoint & 0x003F) | 0x80;
        nVals = 4;
        surrogate = false;
      } else {
        continue;
      }
    } else if (codePoint >= 0xD800 && codePoint <= 0xDBFF) {
      surrogate = true;
      codePointSave = codePoint;
      continue;
    } else {
      surrogate = false;
      if (codePoint > 0x07FF) {
        vals[0] = ((codePoint & 0xF000) >> 12) | 0xE0;
        vals[1] = (codePoint & 0xFC0) >> 6 | 0x80;
        vals[2] = (codePoint & 0x3F) | 0x80;
        nVals = 3;
      } else if (codePoint > 0x007F) {
        vals[0] = ((codePoint & 0x7C0) >> 6) | 0xC0;
        vals[1] = (codePoint & 0x3F) | 0x80;
        nVals = 2;
      } else if (asciiUnEnc.indexOf(str.charAt(i)) < 0) {
        vals[0] = codePoint;
        nVals = 1;
      }
    }
    if (nVals > 0) {
      var j;
      for (j = 0; j < nVals; j++) {
        var hexStr = vals[j].toString(16).toUpperCase();
        if (hexStr.length == 1) {
          hexStr = "0" + hexStr;
        }
        resultStr += "%" + hexStr;
      }
    } else {
      resultStr += str.charAt(i);
    }
  }
  return resultStr;
}
function captureQueryString (val) {
  var strarray= new Array();
//   var index=document.forms[0].refine_search.selectedIndex;
   var index=document.forms[0].refine_search.value;
  strarray= document.forms[0].squery.value.split(" ");
  var result="";
  if (index==0) {
    for (var i=0; i<strarray.length; i++) {
      if (strarray.length==1) {
        result = document.forms[0].squery.value;
      } else if (i==strarray.length-1) {
        result = result+strarray[i];
      } else {
        result = result+strarray[i]+' ';
      }
    }
    result='"'+result+'"';
  }
  if (index==1) { 
    for (var i=0; i<strarray.length; i++) {
      if (i==strarray.length-1) {
        result = result+strarray[i]
      } else if (result != "") {
        result = result + strarray[i]+' AND ';
      } else {
        result = strarray[i]+' AND ';
      }
    }
  }
  if (index==2) {
    for (var i=0; i<strarray.length; i++) {
      if (i==strarray.length-1) {
        result = result+strarray[i]
      } else if (result != "") {
        result = result + strarray[i]+' OR ';
      } else {
        result = strarray[i]+' OR ';
      }
    }
  }
  return result;
}
function captureEnterIE() {
  if(window.event.keyCode == 13) {
    dosearch(captureQueryString(document.forms[0].squery.value));
  }
}
function handleEnterNS(e) {
  var navname = navigator.appName;
  if (navname != "Microsoft Internet Explorer") {
    var keyUsed = e.which;
    if (keyUsed == '13') {
      dosearch(captureQueryString(document.forms[0].squery.value));
    }
  }
}
if (navigator.appName != "Microsoft Internet Explorer") {
  document.captureEvents(Event.KEYPRESS);
}
document.onkeypress = handleEnterNS;
// ############ ENTER abfangen - allgemein ####################
    function submitenter(myfield,e){
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;
        if (keycode == 13){
        // Ereignis, welches abgefangen werden soll
        dosearch(captureQueryString(document.forms[0].squery.value));
        return false;
        }
        else 
       return true;
    }
// ############ ENTER abfangen - ENDE #########################
// ############ HIGHLIGHTING ####################
// init <body onload="highlightWordsInDocument()"
// Aufruf GET &highlight=0,lorem,ipsum,facer
// Definitopn des Hintergrundes und Textfarbe in einer
// geeigneten CSS z.B.: content.css
// div#content .searchhighlight { padding: 2px; color: blue; bachground-color: yellow; }
/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<span class='searchhighlight'>";
    highlightEndTag = "</span>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}
/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}
function highlightSearch(){
    var wURL = window.location.href;
    var patternToMatch = new RegExp();
    if(wURL.indexOf('&') != -1){
        var urlArgs = wURL.substring(wURL.indexOf('&'),wURL.length);
        if(urlArgs.indexOf(',') != -1){
            var wordsToHighLight = urlArgs.substring(urlArgs.indexOf(',') + 1,urlArgs.length).split(',');
			wordsToHighLight = wordsToHighLight.join(" ");
            for(var k=0; k < wordsToHighLight.length; k++){
				highlightSearchTerms(wordsToHighLight);
				// alert(wordsToHighLight);
   } // for
  } // if
 } // if
} // function

