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);