    function searchdate_keypressed(field,code){
        var t=0,m=0,j=0,d;
        var at=0,am=0,aj=0,ad;
        d=new Date();
        ad=searchdate_input2date(field);
        if (ad!=null){at=ad.getDate(); am=ad.getMonth();aj=ad.getFullYear();}
        t=d.getDate(); m=d.getMonth();j=d.getFullYear();h=d.getHours();n=d.getMinutes();
        if (code >= 48  && code <= 57){return true; } // 0123456789
        if (code >= 37  && code <= 40){return true; } // ArrowKeys
        if (code >= 96  && code <= 105){return true; } // 0123456789 Numpad
        if (code == 0 || code==36 || code==35 || code == 190 || code == 8 || code == 13  || code == 46 || code == 9){return true; }
        if (code == 27){document.searchform.elements[field].value=""; return true; }
        if (code==72 || code==104 || code==84 || code==116){searchdate_insert(field, j,m,t,h,n); return false;}
        if (code==187 || code==43 || code==107) {if (ad!=null) searchdate_insert(field, aj,am,at+1,0,0); return false;}
        if (code==189 || code==45 || code==109) {if (ad!=null) searchdate_insert(field, aj,am,at-1,0,0); return false;}
        return false;
    }
    function searchdate_insert(formfield,j,m,t){
        if (h + ""=="")h=0;
        if (n + ""=="")n=0;
        var d=new Date(j,m,t,h,n,0);
        t="" + d.getDate(); m="" + (d.getMonth()+1);j="" + d.getFullYear();
        if (t.length==1) t="0" + t; if (m.length==1) m="0" + m;
        h="" + d.getHours();
        n="" + d.getMinutes();
        if (h.length==1) h="0" + h; if (n.length==1) n="0" + n;
        document.searchform.elements[formfield].value=t + "." + m + "." + j; document.searchform.elements[formfield].focus; document.searchform.elements[formfield].select;
        if (document.searchform.elements[formfield + "_time"]){
            //if (h+n !=0 ) document.searchform.elements[formfield + "_time"].value=""+ h + ":" + n;
            if (h+n !=0 ) document.searchform.elements[formfield + "_time"].value="0:00";
        }

    }
    function searchdate_input2date(formfield){
        var t=document.searchform.elements[formfield].value; var d;
        if (t=="") {return null;}
        var tmp=t.split("."); if (tmp.length!=3) {return null;}
        var t=0,m=0,j=0;
        t=parseInt(tmp[0],10); m=parseInt(tmp[1],10); j=parseInt(tmp[2],10);
        if (isNaN(t) || isNaN(m) || isNaN(j)) {return null;}
        if (t<1 || t>31)     {return null;}
        if (m<1 || m>12)     {return null;}
        if (j<70 && j>=0)    {j=j+2000;}
        if (j>=70 && j<100)  {j=j+1900;}
        if (j<1900 || j>2100){return null;}
        d=new Date(j,m-1,t);
        return d;
    }


    function searchmarker_event(feld){
        if (document.searchform.elements[feld].selectedIndex>=0){
            var n=0;
            var sel = document.searchform.elements[feld].selectedIndex;
            var temp=document.searchform.elements[feld].options[document.searchform.elements[feld].selectedIndex];
            if (temp.text.substring(0,3)=="[x]"){
                temp.text ="[ ] " + temp.text.substring(4,1000);
            } else {
                temp.text = "[x] " + temp.text.substring(4,1000);
            }
            document.searchform.elements[feld].options[document.searchform.elements[feld].selectedIndex].text=temp.text;

            searchmarker_setid(feld);
            if (temp.text.substring(4,6)!="- "){
                // Rekursiv
                for (n=sel+1;n<document.searchform.elements[feld].options.length;n++){
                    if (document.searchform.elements[feld].options[n].text.substring(4,6)=="- "){
                        document.searchform.elements[feld].selectedIndex=n;
                        marker_event(feld);
                    } else {
                        break;
                    }
                }
            }
            document.searchform.elements[feld].selectedIndex = sel;
        }
    }

    function searchmarker_setid(feld){
        var n,s="";
        for (n=0;n<document.searchform.elements[feld].options.length;n++){
            if (document.searchform.elements[feld].options[n].text.substring(0,3)=="[x]"){
                s=s + "" + document.searchform.elements[feld].options[n].value + ",";
            }
        }
        document.searchform.elements[feld + "_hidden"].value = s;
    }











    function date_keypressed(field,code){
        var t=0,m=0,j=0,d;
        var at=0,am=0,aj=0,ad;
        d=new Date();
        ad=date_input2date(field);
        if (ad!=null){at=ad.getDate(); am=ad.getMonth();aj=ad.getFullYear();}
        t=d.getDate(); m=d.getMonth();j=d.getFullYear();h=d.getHours();n=d.getMinutes();
        if (code >= 48  && code <= 57){return true; } // 0123456789
        if (code >= 96  && code <= 105){return true; } // 0123456789 Numpad
        if (code >= 37  && code <= 40){return true; } // ArrowKeys
        if (code == 0 || code==36 || code==35 || code == 190 || code == 8 || code == 13  || code == 46 || code == 9){return true; }
        if (code == 27){document.f.elements[field].value=""; return true; }
        if (code==72 || code==104 || code==84 || code==116){date_insert(field, j,m,t,h,n); return false;}
        if (code==187 || code==43 || code==107) {if (ad!=null) date_insert(field, aj,am,at+1,0,0); return false;}
        if (code==189 || code==45 || code==109) {if (ad!=null) date_insert(field, aj,am,at-1,0,0); return false;}
        return false;
    }
    function date_insert(formfield,j,m,t,h,n){
        if (h + ""=="")h=0;
        if (n + ""=="")n=0;
        var d=new Date(j,m,t,h,n,0);
        t="" + d.getDate(); m="" + (d.getMonth()+1);j="" + d.getFullYear();
        if (t.length==1) t="0" + t; if (m.length==1) m="0" + m;
        h="" + d.getHours();
        n="" + d.getMinutes();
        if (h.length==1) h="0" + h; if (n.length==1) n="0" + n;
        document.f.elements[formfield].value=t + "." + m + "." + j; document.f.elements[formfield].focus; document.f.elements[formfield].select;
        if (document.f.elements[formfield + "_time"]){
            //if (h+n !=0 ) document.f.elements[formfield + "_time"].value=""+ h + ":" + n;
            if (h+n !=0 ) document.f.elements[formfield + "_time"].value="0:00";
        }

    }
    function date_input2date(formfield){
        var t=document.f.elements[formfield].value; var d;
        if (t=="") {return null;}
        var tmp=t.split("."); if (tmp.length!=3) {return null;}
        var t=0,m=0,j=0;
        t=parseInt(tmp[0],10); m=parseInt(tmp[1],10); j=parseInt(tmp[2],10);
        if (isNaN(t) || isNaN(m) || isNaN(j)) {return null;}
        if (t<1 || t>31)     {return null;}
        if (m<1 || m>12)     {return null;}
        if (j<70 && j>=0)    {j=j+2000;}
        if (j>=70 && j<100)  {j=j+1900;}
        if (j<1900 || j>2100){return null;}
        d=new Date(j,m-1,t);
        return d;
    }
    function marker_event(feld){
        if (document.f.elements[feld].selectedIndex>=0){
            var n=0;
            var sel = document.f.elements[feld].selectedIndex;
            var temp=document.f.elements[feld].options[document.f.elements[feld].selectedIndex];
            if (temp.text.substring(0,3)=="[x]"){
                temp.text ="[ ] " + temp.text.substring(4,1000);
            } else {
                temp.text = "[x] " + temp.text.substring(4,1000);
            }
            document.f.elements[feld].options[document.f.elements[feld].selectedIndex].text=temp.text;

            marker_setid(feld);
            if (temp.text.substring(4,6)!="- "){
                // Rekursiv
                for (n=sel+1;n<document.f.elements[feld].options.length;n++){
                    if (document.f.elements[feld].options[n].text.substring(4,6)=="- "){
                        document.f.elements[feld].selectedIndex=n;
                        marker_event(feld);
                    } else {
                        break;
                    }
                }
            }
            document.f.elements[feld].selectedIndex = sel;
        }
    }

    function marker_setid(feld){
        var n,s="";
        for (n=0;n<document.f.elements[feld].options.length;n++){
            if (document.f.elements[feld].options[n].text.substring(0,3)=="[x]"){
                s=s + "" + document.f.elements[feld].options[n].value + ",";
            }
        }
        document.f.elements[feld + "_hidden"].value = s;
    }

    
   
    
    
    function open_info(root){
        window.open (root + "credits/index.php","Info","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=400,height=350,resizable=no");
    }
    function open_help(root,k){
        window.open (root + "lib/help.php?k=" + k + "","Help","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,width=530,height=500,resizable=yes");
    }

    function open_notiz(root,param,edit){
        window.open (root + "notiz/notiz.php?" + param + "","Notiz","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,width=500,height=600,resizable=no");
    }

    function open_email(root,id_email){
        window.open (root + "emailclient/maske_email.php?id=" + id_email + "","Email","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,width=600,height=650,resizable=yes");
    }

    function open_newemail(root,id_kundenakt,emailto,id_file){
        window.open (root + "emailclient/maske_email.php?id=0&id_kundenakt="+id_kundenakt+"&emailto="+emailto+"&attach_id_file="+id_file,"Email","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,width=600,height=650,resizable=yes");
    }

    function open_emailadresssuche(root,modul,id_email){
        if (modul!='') var f = window.open (root + "emailclient/suche_adressen.php?id_email="+id_email+"&modul="+modul,"suche_adresse","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,width=600,height=405,resizable=yes");
    }

    function open_adressbuch(root){
        var f = window.open (root + "emailclient/suche_adressbuch.php","suche_adressbuch","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,width=450,height=405,resizable=yes");
    }

    function open_adressbuchpers(root,id_email){
        var f = window.open (root + "emailclient/suche_adressbuchpers.php?id_email="+id_email,"suche_adressbuchpers","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,width=450,height=405,resizable=yes");
    }

    function open_dokumente(root,id_email){
        var f = window.open (root + "emailclient/suche_dokumente.php?id_email="+id_email,"suche_dokumente","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,width=450,height=405,resizable=yes");
    }

    function SendEmailTo(email){
        alert("Email senden an: " + email + ". Muss noch in javascript.js definiert werden.");
    }

    function replace(text,f,rep){
      var npos=0,nfindlen=0;nreplen=0,t="",l=0;
      t=text;
      l=text.length;
      nfindlen=f.length;
      nreplen=rep.length;
      if (find=!"" && f!=rep){
          npos=t.indexOf(f);
          while (npos>=0){
              t=t.substr(0,npos) + rep + t.substr(npos+nreplen,10000);
              npos=t.substr(npos+nreplen,l).indexOf(find);
          }
      }
      return t;
  }


  function FormatKomma(wert,komma){
      var pos,n,vor="",nach="",erg="";

      wert=wert * Math.pow(10,komma);
      wert=Math.round(wert);
      wert=wert / Math.pow(10,komma);
      cont = "" + wert;
      content="";
      content=cont.replace(/\./,",");
      pos=content.indexOf(",");
      if (pos<0) pos=content.length
      vor=content.substr(0,pos);
      nach=content.substr(pos+1,100);
      if (nach.length<komma)nach=nach+"0";
      if (nach.length<komma)nach=nach+"0";
      for (n=vor.length;n>=0;n--){
          erg=String(vor.charAt(n)) + String(erg);
          //if ((vor.length-n)%3==0 && n>0 && vor.length-n>0 && vor.charAt(n-1)!="-") erg="." + String(erg);
      }
      return String(erg) + "." + String(nach);
  }

  function preview(feld,root,msg){
        // Größe:
        if (document.f.elements[feld].value==""){
            alert(msg);
            return;
        }
        var w=0;
        var h=0;
        if (document.f.elements[feld + "_size"]){
            if (document.f.elements[feld + "_size"].options){
                var s=document.f.elements[feld + "_size"].options[document.f.elements[feld + "_size"].selectedIndex].value;
            } else{
                var s=document.f.elements[feld + "_size"].value;
            }
            var sa=s.split(",");
            w=parseInt(sa[0],10) + 20;
            h=parseInt(sa[1],10) + 20;
        }
        if (w==20)w=400;
        if (h==20)h=300;
        //if (window.preview_win) if (window.preview_win.closed==false) preview_win.close();

        preview_win=window.open ("about:blank","PREVIEW","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,width=" + w + ",height=" + h + ",resizable=yes");
        var oldtarget=document.f.target;
        var oldaction=document.f.action;
        document.f.target="PREVIEW";
        document.f.action=root + "lib/image_preview.php?field=" + feld;
        document.f.submit();
        document.f.target=oldtarget;
        document.f.action=oldaction;
  }



    function httpRequest(url,callbackfunction) {
        http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request) {
            alert('ERROR: AJAX NOT AVAILABLE');
            return false;
        }
        if ('function'==typeof callbackfunction) http_request.onreadystatechange =  function(){
            if(http_request.readyState == 4){callbackfunction(http_request.responseText);}
        }
        try {
            if ('function'==typeof callbackfunction) {
                http_request.open('GET', url, true);
                http_request.send(null);
            } else {
                http_request.open('GET', url, false);
                http_request.send(null);
                return http_request.responseText;
            }
        } catch (e) {return e;}
        if ('function'!=typeof callbackfunction) return "";
    }










