// Browserweiche
var browser = '';
if (navigator.userAgent.indexOf("MSIE") > 0){
    browser = 'NETSCAPE';
}
if (navigator.userAgent.indexOf("MSIE") > 0 && navigator.userAgent.indexOf("Opera") < 0){
    browser = 'IE';
}
if (navigator.userAgent.indexOf("Opera") > 0){
    browser = 'OPERA';
}

function dbgonoff(){
    if (document.getElementById("debug").style.visibility == "visible") {
        document.getElementById("debug").style.visibility = "hidden";
        document.getElementById("debug").style.display = "none";
    } else {
        document.getElementById("debug").style.visibility = "visible";
        document.getElementById("debug").style.display = "inline";
    }
}
function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
     while (theForm[z].type == 'checkbox') {
         if(theForm[z].name != 'checkall'){
             theForm[z].checked = theElement.checked;
         }
      z++;
 }
}

wmtt = null;

document.onmousemove = updateTooltip;

function updateTooltip(e) {
    x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
    y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
    if (wmtt != null) {
        wmtt.style.left = (x + 20) + "px";
        wmtt.style.top     = (y + 20) + "px";
    }
}

function showTooltip(id) {
    wmtt = document.getElementById(id);
    wmtt.style.display = "block"
}

function hideTooltip() {
    wmtt.style.display = "none";
}

function load(){
     var mybody = document.body;
     var main_table = mybody.getElementsByTagName("TABLE").item(0);

     main_table.style.width = "500px";
 }

function inlineEdit(element, formname){
    element.innerHTML='<input name=\'edit\' type=\'text\' value=\'javascript:this.innerHTML\'>';
    form_element = document.forms[formname];
    form_element.edit.select();
    element.ondblClick='return false';
}

function countLines(strtocount, cols) {
    if(strtocount != undefined){
        var hard_lines = 1;
        var last = 0;
        while ( true ) {
            last = strtocount.indexOf("\n", last+1);
            hard_lines ++;
            if ( last == -1 ) break;
        }
        var soft_lines = Math.round(strtocount.length / (cols-1));
        var hard = eval("hard_lines  " + unescape("%3e") + "soft_lines;");
        if ( hard ) soft_lines = hard_lines;
    }
    return soft_lines;
}

function cleanForm() {
    var the_form = document.forms[0];
    var elems = document.getElementsByTagName('textarea');
    for (var x in elems){
        if(typeof elems[x] != "number"){
            elems[x].rows = countLines(elems[x].value,elems[x].cols) + 1;
        }
    }
}

function popup(url,width,height,name){
    // center on screen
    LeftPosition=(screen.width)?(screen.width-width)/2:100;
    TopPosition=(screen.height)?(screen.height-height)/2:100;

    window.open(url,name,'scrollbars=1,width=' + width + ',height=' + height + ',top='+TopPosition+',left='+LeftPosition);
}

function addListener(element, type, expression, bubbling){
    bubbling = bubbling || false;
    if(window.addEventListener) { // Standard
        element.addEventListener(type, expression, bubbling);
        return true;
    } else if(window.attachEvent) { // IE
        element.attachEvent('on' + type, expression);
        return true;
    } else return false;
}

// useage: addListener(window, 'load', myFunction);

// functions to handle cookies
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

function showhideCheckbox(srcfield,dstfield){

    if(browser == 'IE'){
        if(document.getElementsByName(srcfield)[0].checked){
            document.getElementById(dstfield).style.display='block';
        }else{
            document.getElementById(dstfield).style.display='none';
        }
    }else{
        if(document.getElementsByName(srcfield)[0].checked){
            document.getElementById(dstfield).style.display='table-row';
        }else{
            document.getElementById(dstfield).style.display='none';
        }
    }
}
/*
* <body onLoad="preloadImages('bild1.jpg','bild2.gif');">
*/
if(!document.preload){
    document.preload = new Array();
}
function preloadImages()
{
    if(document.images)
    {
        start = document.preload.length;
        for(var i = start; i < (preloadImages.arguments.length + start); i++)
        {
            document.preload[i] = new Image();
            document.preload[i].src = preloadImages.arguments[i];
           // alert("Load" + preloadImages.arguments[i]);
        }
    }
}

function trim (zeichenkette) {
  // Erst führende, dann Abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}
