var Search = {
  observingId : '',
  defaultMsg  : '',
  lastTimeout : false,
  
  observe : function(id, targetClass) {
    Search.observingId = id;
    
    $(id).observe('keyup', function(elm) {
        if (Search.lastTimeout) {
          clearTimeout(Search.lastTimeout);
        }
        
        Search.lastTimeout = setTimeout("Search.update('" + $(id).value + "', '" + targetClass + "')", 600);
    });
    
    $(id).observe('click', function(evt) {
        if ($(id).value == Search.defaultMsg) {
          $(id).value = '';
        }
    });
  },
  
  setDefault : function(id, value) {
    $(id).value       = value;
    Search.defaultMsg = value;
  },
  
  update : function(value, targetClass) {

      finalValue = '';

      for(i=0; i<value.length; i++) {

          temp = value.charAt(i);

          if(value.charAt(i) == 'Ä'){
              temp = '^^A^^';
          }
          else if(value.charAt(i) == 'Ü'){
              temp = '^^U^^';
          }
          else if(value.charAt(i) == 'Ö'){
              temp = '^^O^^';
          }
          else if(value.charAt(i) == 'ä'){
              temp = '^^a^^';
          }
          else if(value.charAt(i) == 'ü'){
              temp = '^^u^^';
          }
          else if(value.charAt(i) == 'ö'){
              temp = '^^o^^';
          }
          else if(value.charAt(i) == 'ß'){
              temp = '^^B^^';
          }
          else if(value.charAt(i) == 'ø'){
              temp = '^^oo^^';
          }
          else if(value.charAt(i) == 'å'){
              temp = '^^aa^^';
          }
          else if(value.charAt(i) == 'Ø'){
              temp = '^^01^^';
          }
          else if(value.charAt(i) == 'Å'){
              temp = '^^02^^';
          }
          else if(value.charAt(i) == 'æ'){
              temp = '^^03^^';
          }
          else if(value.charAt(i) == 'Æ'){
              temp = '^^04^^';
          }
          
          finalValue = finalValue + temp;
          //alert(value.charAt(i));
      }

    if (value.length > 2) {
      new Ajax.Updater($$('.' + targetClass).first(), '/search.php?s=' + finalValue, {
           asynchronous : true,
           evalScripts  : true,
           onComplete   : function (request) {
           },
           onLoading:function(request) {
             $(Search.observingId).stopObserve();
           },
           method:'post'
      })
    }
  }
  
}


//Search.setDefault("livesearch", "Livesearch");
Search.observe("livesearch", "content_inner");
