function hidediv(id) {
//	alert(id);
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function DivKopieren(neuesDiv, altesDiv) {
	if (document.getElementById(neuesDiv) && document.getElementById(altesDiv)) {
		document.getElementById(neuesDiv).innerHTML = document.getElementById(altesDiv).innerHTML;
	} else {
		alert(neuesDiv + " - " + altesDiv);
	}
}



function togglediv(id) {
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}


function htmlentities(str,typ) {
	if(typeof str=="undefined") str="";
	if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	var html=new Array();
	html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
	if(typ==1 || typ==3) html[39]="&#039;";
	if(typ==2 || typ==3) html[34]="&quot;";
	for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
	var entity=new Array(
	  "&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
	  "&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
	  "&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
	  "&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
	  "&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
	  "&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
	  "&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
	  "&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
	  "&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
	  "&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
	  "&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
	  "&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
	  );
	for(var i in entity) eval("str=str.replace(/"+String.fromCharCode(i*1+160)+"/g,\""+entity[i]+"\");");
	return str;
}


function CDownloadUrl(method, url, func, div) {

	var infoDiv = div + 'Info';
	if (document.getElementById(infoDiv)){
		document.getElementById(infoDiv).innerHTML = HTMLWait;
	}

	var httpObj;
	var browser = navigator.appName;
	if(browser.indexOf("Microsoft") > -1)
	   httpObj = new ActiveXObject("Microsoft.XMLHTTP");
	else
	   httpObj = new XMLHttpRequest();
	
	
	
	httpObj.open(method, url, true);
	httpObj.onreadystatechange = function() {
	   if(httpObj.readyState == 4){
	
	      if (httpObj.status == 200) {
	
	         var contenttype = httpObj.getResponseHeader('Content-Type');
	
	         if (contenttype.indexOf('xml')>-1) {
	
	            func(div, httpObj.responseXML);
	
	         } else {
	
	            func(div, httpObj.responseText);
			if (document.getElementById(infoDiv)){
				document.getElementById(infoDiv).innerHTML = HTMLInfo;
			}
	
	         }
	
	      } else {
	
	         func('Error: '+httpObj.status);
	
	      }
	
	   }
	
	};
	
	httpObj.send(null);

	
}

function HTMLinDIV(div, text) {
//	alert(div);
//	alert(text);
	if (document.getElementById(div)) {
		document.getElementById(div).innerHTML = text;
	} else {
		alert(div);
		alert(text);
	}
}

function checkradio(feld){
	for (i=0; i<feld.length; i++){
			if(feld[i].checked == true){
				return feld[i].value;
			}
	}
	return false;
}


function selectAuslesen(sObj) {
	with (sObj) return options[selectedIndex].value;
}
/*
function tooltip(curobj, subobjstr, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		subobj.style.left=xpos+"px"
		subobj.style.top=ypos+"px"
		return false
	}
	else
	return true
}

function tooltipclose(subobj){
	document.getElementById(subobj).style.display="none"
}

function getposOffset(tooltip, offsettype){
	var totaloffset=(offsettype=="left")? tooltip.offsetLeft : tooltip.offsetTop;
	var parentEl=tooltip.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
*/


var prevTooltip;

function getWindowWidth() {
    
    if(window.innerWidth) {
        return window.innerWidth;
    } 
    
    return document.body.clientWidth
}

function mouseX(e) {

    if(e.pageX) {
        return e.pageX;
    }
    
    return e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
}

function mouseY(e) {
   
   if(e.pageY) {
        return e.pageY;
    } 
    
    return e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);    
}

function tooltip(e, o, li) {

	var versatz =  0;
	if (li > 0) {
		versatz = li;
	}
    var windowWidth = getWindowWidth();

    o = document.getElementById(o);
    
    if(prevTooltip && prevTooltip != o) {
        prevTooltip.style.visibility = 'hidden';
    }

    if(o.style.visibility == 'visible') {

        o.style.visibility = 'hidden';
    } else {
    
    		var ew = 1;
        if(o.offsetWidth) {
            ew = o.offsetWidth;
        } else if(o.clip.width) {
            ew = o.clip.width;
        }
    
        var y = mouseY(e) + 16;
        var x = mouseX(e) - (ew / 4) - versatz;
        
        if (x < 2) {
            x = 2;
        } else if(x + ew > windowWidth) {
            x = windowWidth - ew - 4;
        }
        
        o.style.left = x + 'px';
        o.style.top = y + 'px';    
        
        o.style.visibility = 'visible';
        
        prevTooltip = o;
    }
}

