function show(id) {
  if (document.getElementById && document.getElementById(id)) {
    var mydiv = document.getElementById(id);
    mydiv.style.display = 'block';
  }
}
function hide(id) {
  if (document.getElementById && document.getElementById(id)) {
    var mydiv = document.getElementById(id);
    mydiv.style.display = 'none';
  }
}
function toggledisplay (id)
{
  if (document.getElementById && document.getElementById(id)) {
    var mydiv = document.getElementById(id);
    mydiv.style.display = (mydiv.style.display=='block'?'none':'block');
  }
}
function show_row (id) {
  if (document.getElementById && document.getElementById(id)) {
    var myrow = document.getElementById(id);
    myrow.style.display = 'table-row';
  }
}
function window_size() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth,myHeight);
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];

	}
}	
function setCookie(c_name,value,expiredays,path)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +
		( ( path ) ? ";path=" + path : "" );
}
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
	 	}
	}
	return "";
}
function deleteCookie(name)
{
    if(getCookie(name)) setCookie(name, '', -30);
} 
function fetchPage(url, doFunc, id) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
        }
    } 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) {
        return false;
    }
    http_request.onreadystatechange = function() { 
        if (http_request.readyState==4)
            if (http_request.status==200)
                doFunc(http_request, id);
    }
    http_request.open('GET', url, true);
    http_request.send(null);
}
function writeHTML(req, id) {
    document.getElementById(id).innerHTML = req.responseText;
}
function doNothing(req, id)
{
	// do nothing
}
function alertResponse(req, id)
{
	alert(req.responseText);
}
function fetchPagePost(url, parameters, doFunc, id) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
        }
    } 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) {
        return false;
    }
    http_request.onreadystatechange = function() { 
        if (http_request.readyState==4)
            if (http_request.status==200)
                doFunc(http_request, id);
    }
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}
function set_val(req, element)
{
	if ( element.type == 'select-one' )
	{
		setDDselectedVal(element,req.responseText);
	} else {
		if ( element.value == '' )
		{
			element.value = req.responseText;
		}
	}
}
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function toggleKat(clName)
{
	var el = getElementsByClassName(document,"*",clName);
	var sl;
	for(var i=0;i<el.length;i++)
	{
		if ( el[i].style.display != 'none' ) {
			el[i].style.display = 'none';
		}
		else {
			el[i].style.display = '';
		}
	}
}
function toggleKat2(kat)
{
	var el = getElementsByClassName(document,"*",'kat_' + kat);
	var sl;
	var img = document.getElementById('plmi_' + kat);
	if ( img.src.search(/plus/) != -1 )
	{
		img.src = img.src.replace(/plus/,'minus');
	} else {
		img.src = img.src.replace(/minus/,'plus');
	}
	for(var i=0;i<el.length;i++)
	{
		if ( el[i].style.display != 'none' ) {
			el[i].style.display = 'none';
		} else {
			el[i].style.display = '';
		}
	}
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
function setDDselectedVal(dd,newValue) {
for (var i = 0; i < dd.length; ++i)
  if (dd[i].value == newValue)
    dd.selectedIndex = i;
}

function setDDselected(dd,newValue) {
for (var i = 0; i < dd.length; ++i)
  if (dd[i].text == newValue)
    dd.selectedIndex = i;
}
function getDDselectedVal_id(dd_id) {
	return document.getElementById(dd_id).options[document.getElementById(dd_id).selectedIndex].value;
}
function getDDVal(dropdown) {
	var myindex  = dropdown.selectedIndex;
	return dropdown.options[myindex].value;
}
function set_bis()
{
	var von = document.getElementById('datum_von');
	var bis = document.getElementById('datum_bis');
	if ( bis.selectedIndex < von.selectedIndex && von.selectedIndex < (von.options.length-1) )
	{
		bis.selectedIndex = von.selectedIndex + 1;
	} else if ( bis.selectedIndex < von.selectedIndex && von.selectedIndex == (von.options.length-1) ) {
		bis.selectedIndex = 0;
	}
}
function set_ab()
{
	var von = document.getElementById('datum_von');
	var bis = document.getElementById('datum_bis');
	if ( bis.selectedIndex < von.selectedIndex && bis.selectedIndex > 0 ) von.selectedIndex = bis.selectedIndex;
}