function geid(id) {
    return document.getElementById(id);
}

function hideif(id,cond) {
	var el = geid(id);
	if(el) el.style.display = cond ? 'none' : '';
	return true;
}
function checkif(id,cond) {
	var el = geid(id);
	if(el) el.checked = cond;
	return true;
}

function gen(name) {
	return document.getElementsByName(name)[0];
}

function genv(name) {
	return String(gen(name).value);
}

function zahl(x) {
    x = Number(x);
    if(x==x.toFixed(0)) return x.toFixed(0);
    return String(x.toFixed(2)).replace(/\./,",");
}


function _runOnDomReady() {  // define function: onDomReady()
    if(window.onDomReady) onDomReady();
    foc = geid("focus");
    if(foc) foc.focus();
    init_tablecol();
    // weitere inits here
}
function initOnDomReady(fn) {
    if(document.addEventListener) {
        document.addEventListener("DOMContentLoaded",fn,false);
    } else {
        document.onreadystatechange = function(){readyState(fn);}
    }
    return true;
}
function readyState(func) {
    if(document.readyState == "interactive" || document.readyState == "complete") { func(); }
}
initOnDomReady(_runOnDomReady);

function init_tablecol() {
    var tr_ary = document.getElementsByTagName("tr");
    for(var i=1; i<tr_ary.length; i++) {
        zeile = tr_ary[i];
        var cn = zeile.className;
        if(cn.substr(0,3)=="col") {
            zeile.defclass = cn;
            zeile.onmouseover = function(){setPointer(this,'in');}
            zeile.onmouseout = function(){setPointer(this,'out');}
            zeile.onmousedown = function(){setPointer(this,'klick');}
            if(zeile.id.substr(0,4)=="mark") {setPointer(zeile,'klick');}
        }
    }
    return true;
}

function setPointer(theRow, theAction)
{
    if((theRow.className=="klick") && (theAction!='klick')) {
        return false;
    }
    if(theAction=='in') {
        theRow.className = 'mouse';
    } else {
        if(theAction=='out') {
            theRow.className = theRow.defclass;
        } else { // action = klick
            if(theRow.className=="klick") {
                theRow.className = "mouse";
            } else {
                theRow.className = 'klick';
            }
        }
    }
    return true;
}


function details(ziel) {
	detailwin=window.open(ziel,'detailwin','width=750,height=640,resizable=yes,scrollbars=yes,menubar=yes,location=no,toolbar=no');
	return false;
}

function togglemenu(nr,focusonclick) {
	var row = geid('menu_row_'+nr);
	if(row.style.display=='none') {
		row.style.display='';
		if(getposy(row)>(getvpheight()+getscrolltop())) row.scrollIntoView(false);
		if(focusonclick!='') geid(focusonclick).focus();
	} else {
		row.style.display='none';
	}
}

function getposy(obj) {
	var posy = obj.offsetHeight;
	while(obj.offsetParent) {
		posy += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return posy;
}
function getvpheight() {	
	var vpheight = 0;
	if(document.documentElement && document.documentElement.clientHeight) {
		vpheight = document.documentElement.clientHeight;
	} else if(document.body && document.body.clientHeight) {
		vpheight = document.body.clientHeight;
	} else if(window.innerHeight) {
		vpheight = window.innerHeight-18;
	}
	return vpheight;
}
function getscrolltop() {
	var scrolltop = 0;	
	if(document.documentElement && document.documentElement.scrollTop) {
		scrolltop = document.documentElement.scrollTop;
	} else if(document.body && document.body.scrollTop) {
		scrolltop = document.body.scrollTop;
	} else if(window.pageYOffset) {
		scrolltop = window.pageYOffset;
	} else if(window.scrollY) {
		scrolltop = window.scrollY;
	}
	
	return scrolltop;
}

function menscroll() { // does not work yet
	var men = geid('men');
	var scrolltop = getscrolltop();
	var vpheight = getvpheight();
	var posy = getposy(men);
	var platzoben = men.offsetTop - scrolltop;
	var platzunten = scrolltop+vpheight - posy;
	
	if((platzoben<0) && (platzunten>0)) {
		if((0-platzoben) < platzunten) {
			men.top = scrolltop;
		} else {
			men.top = scrolltop+vpheight-men.offsetHeight;
		}
	} else {
	}
	return true;
}


function selectDate ( form, day, month, year) {
  url = "includes/datesel.inc.php?dsform=" + form + "&day=" + day ;
  current = this.document.forms[form].elements[day].value;
  if (typeof month != "undefined") {
      current += "." + this.document.forms[form].elements[month].value + "." + this.document.forms[form].elements[year].value;
      url += "&month=" + month + "&year=" + year;
  }
  if ((current!="") && (current!="..")) url += '&curdat=' + current;
  window.open( url, "Kalender", "width=300,height=200,resizable=yes,scrollbars=yes,status=no" );
}


function ShowTimeoutWarning ()
{
    window.alert( "Sie haben nun seit 25 Minuten keine Eingabe getätigt.\nAus Sicherheitsgründen werden Sie automatisch abgemeldet, wenn auch in den kommenden 5 Minuten kein neuer Seitenaufruf erfolgt!\nNicht gespeicherte Änderungen auf dieser Seite gehen dabei verloren." );
}
