
function isMS()
{
	if(navigator.appName.indexOf("Microsoft")>=0) return true;
	return false;
}
function isNS()
{
	
	if(navigator.appName=="Netscape")
		return true;
	else
		return false;
}
function Obj (objId)
{
	return document.getElementById (objId);	
}
function hideObj (obj)
{
	obj.style.visibility='hidden';
}
function showObj (obj)
{
	obj.style.visibility='visible';
}
function displayObj(obj)
{
	obj.style.display='';
}
function undisplayObj(obj)
{
	obj.style.display='none';
}
function getActualDateString(formatFullDate,showTime)
{
	var d = new Date();
	var t = d.toLocaleTimeString();
	if (formatFullDate)
	{
		if (showTime)
			return d.toLocaleDateString() + ", "+ t;
		else
			return d.toLocaleDateString();
	}
	else
	{
		var ds = (d.getDate()<=9?"0":"") + d.getDate() + "." + 
			(d.getMonth()<=8?"0":"") + (d.getMonth()+1) + "." + d.getFullYear();
		if (showTime)
			ds = ds + ", "+ t;
		return ds;
	}
	
	
}
function LTrim (str)
{
	if (str==null) return "";
	var res="";
	var len = str.length;
	if(len>50) len=50;
	for(var i=0; i<len; i++)
	{
		if(str.substr(i,1)!=" ")
			return str.substr(i); 
	}
	return str;
}

function getWindowWidth () 
{
  if (window.innerWidth) 
  {
    return window.innerWidth;
  } 
  else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else 
  {
    return 0;
  }
}

function getWindowHeight () 
{
  if (window.innerHeight) 
  {
    return window.innerHeight;
  } 
  else if (document.body && document.body.offsetHeight) 
  {
    return document.body.offsetHeight;
  } 
  else 
  {
    return 0;
  }
}

function validateNumber(inp)
{
	if (inp==null) return false;
	if(inp.value==null || inp.value=="") return false;
	var val = inp.value;
	//Replace Comma
	val = val.replace(",",".");
	var t = Number(val);
	if (t>=0)
		return true;	
	else
	{
		alert ("Ihre Eingabe enthält keine gültige Zahl!");
		inp.focus();
		
		
	}
}

function validateDate(inp)
{
	if (inp==null) return false;
	if(inp.value==null || inp.value=="") return false;
	var val = inp.value;
	var res = false;
	var parts = null;
	
	if(val.indexOf(".")>=0) //German format
	{
		parts = val.split(".");
	}
	else if(val.indexOf("-")>=0) //Dutch format
	{
		parts = val.split("-");
	}
	else if(val.indexOf("/")>=0) //English format
	{
		parts = val.split("/");
		if(parts.length>=3)
		{
			var tmp = parts[1];
			parts[1] = parts[0]; //Switch day and month
			parts[0] = tmp;
		}
	}
	if(parts!=null && parts.length>=3)
	{
		var d = parts[0];
		var m = parts[1];
		var y = parts[2];
		
		if(Number(d)>=1 && Number(d)<=31)
			if(Number(m)>=1 && Number(m)<=12)				
				if(Number(y)>=0)
				{		
					if(String(y).length<=2)
					{
						if(Number(y)<=20)	//2000 till 2020
						{
							
							y =2000 + Number(y);
							
						}
						else				//1921 till 1999
							y =1900 + Number(y);
					}
						
					var check = new Date(Number(y),Number(m)-1,Number(d));
					
					var comp = new Date(1,0,1,0,0,0); // 1. Jan 1, 00:00:00
					
					if(check>=comp)
						res = true;
				}
	}
	if (!res)
	{
		alert ("Ihre Eingabe enthält kein gültiges Datum!");
		inp.focus();
	}
}
function setCookie (name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
    	((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function deleteCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			
			setStr = cookie.replace(cookie.substring(offset, end)+";","");
			document.cookie = setStr;
		}
	}
	
}
function getQueryString(name,querystring) {
	if(querystring==null)
		querystring = document.location.search.substr(1);
	var search = "" + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (querystring.length > 0) {
		offset = querystring.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = querystring.indexOf("&", offset)
			if (end == -1) {
				end = querystring.length;
			}
			setStr = unescape(querystring.substring(offset, end));
		}
	}
	return(setStr);
}

function displayPopupAtRelativeLocation (EVENT, popup, objDiv, divWidth, divHeight,offsetLeft, offsetTop, wind, doc)
{
	
	if(wind==null) wind = window;
	if(doc == null) doc  = document;
	var left=100, top=100;
	objDiv.style.display = "";	
	if (isNS())
	{
		left = EVENT.pageX;
		top = EVENT.pageY;	
		
		//Wenn Top > Fensterhöhe
		if ( (top + divHeight) > ( wind.pageYOffset + wind.innerHeight ))
			top = wind.pageYOffset + wind.innerHeight - divHeight;
		//Wenn  Top < 0 
		if (top < wind.pageYOffset)
			top = wind.pageYOffset-10;

		//Wenn Left+Width > Fensterbreite
		if ( (left+divWidth) > ( wind.pageXOffset + wind.innerWidth ) )
			left = wind.pageXOffset + wind.innerWidth - divWidth;
		//Wenn Lef < 0
		if ( left < wind.pageXOffset )
			left = wind.pageXOffset+10;
			
			
			
	}
	else
	{
		left = EVENT.x + doc.body.scrollLeft+ offsetLeft+left;
		top = EVENT.y + doc.body.scrollTop+ offsetTop+top;	
		
		//Debug-Info:
		//window.status= objDiv.currentStyle.height; //top + " - " + document.body.offsetHeight;
		
		
		//Wenn Top > Fensterhöhe
		if ( (top + divHeight) > ( doc.body.offsetHeight + doc.body.scrollTop) )
			top = EVENT.y + doc.body.scrollTop - divHeight;
		//Wenn  Top < 0 
		if (top < doc.body.scrollTop)
			top = EVENT.y + doc.body.scrollTop;
		//Wenn Left+Width > Fensterbreite
		if ( (left+divWidth) > ( doc.body.offsetWidth + doc.body.scrollLeft) )
			left = EVENT.x + doc.body.scrollLeft - divWidth;
		//Wenn Lef < 0
		if ( left < doc.body.scrollLeft )
			left = EVENT.x + doc.body.scrollLeft;
				
	}
	popup.show(left,top,divWidth, divHeight,document.body);
	
}

//Displays an object at a location relative to the cursor
function displayAtRelativeLocation (EVENT, objDiv, divWidth, divHeight,offsetLeft, offsetTop, wind)
{
	if(wind==null) wind = window;
	var doc  = wind.document;
	var left=100, top=100;
	
	if (isNS())
	{
		left = EVENT.pageX;
		top = EVENT.pageY;	
		
		//Wenn Top > Fensterhöhe
		if ( (top + divHeight) > ( wind.pageYOffset + wind.innerHeight ))
			top = wind.pageYOffset + wind.innerHeight - divHeight;
		//Wenn  Top < 0 
		if (top < wind.pageYOffset)
			top = wind.pageYOffset-10;

		//Wenn Left+Width > Fensterbreite
		if ( (left+divWidth) > ( wind.pageXOffset + wind.innerWidth ) )
			left = wind.pageXOffset + wind.innerWidth - divWidth;
		//Wenn Lef < 0
		if ( left < wind.pageXOffset )
			left = wind.pageXOffset+10;
			
			
			
	}
	else
	{
		left = EVENT.x + doc.body.scrollLeft+ offsetLeft;
		top = EVENT.y + doc.body.scrollTop+ offsetTop;	
		
		//Debug-Info:
		//window.status= objDiv.currentStyle.height; //top + " - " + document.body.offsetHeight;
		
		
		//Wenn Top > Fensterhöhe
		if ( (top + divHeight) > ( doc.body.offsetHeight + doc.body.scrollTop) )
			top = EVENT.y + doc.body.scrollTop - divHeight;
		//Wenn  Top < 0 
		if (top < doc.body.scrollTop)
			top = EVENT.y + doc.body.scrollTop;
		//Wenn Left+Width > Fensterbreite
		if ( (left+divWidth) > ( doc.body.offsetWidth + doc.body.scrollLeft) )
			left = EVENT.x + doc.body.scrollLeft - divWidth;
		//Wenn Lef < 0
		if ( left < doc.body.scrollLeft )
			left = EVENT.x + doc.body.scrollLeft;
				
	}
	//objDiv.style.left =left;
	//objDiv.style.top = top ;
	//objDiv.style.display = "";		
	
	
	
	
}

function getAttributes(obj, html,with_functions)
{
	if(with_functions==null) with_functions = false;
	var res = "";
	if(obj==null) return;
	
	for (var a in obj)
	{
		if(!with_functions && String(obj[a]).indexOf("function")>=0) continue;
		res += a + ":\t" + obj[a] + "\t\t";//\r\n";
	}
	if(html!=null || html==true)
	{
		res = res.replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
		res = res.replace("\r\n","<br>");
	}
	return res;	
}

function ObjectParameters (obj)
{
	this.top  =obj.style.top; this.top=(this.top!=null?new Number(this.top.substr(0,this.top.length-2)):null);		
	this.left  =obj.style.left; this.left=(this.left!=null?new Number(this.left.substr(0,this.left.length-2)):null);		
	this.height  =obj.style.height; this.height=(this.height!=null?new Number(this.height.substr(0,this.height.length-2)):null);
	this.width  =obj.style.width; this.width=(this.width!=null?new Number(this.width.substr(0,this.width.length-2)):null);

}

function scrollListBox (lb_id,step)
{
	
	var lb = Obj(lb_id);
	if(lb==null) return;
	var index = lb.selectedIndex;
	index += step;
	if(index<0) index=0;
	if(index>(lb.options.length-1)) index = lb.options.length-1;
	lb.selectedIndex = index;	
	if(window.cancelOverwriting!=null)
		window.cancelOverwriting(null);
}

function scrollerDown (scroller)
{
	if (scroller==null) return;
	scroller.style.borderTop = "1px solid black";
	scroller.style.borderLeft = "1px solid black";
	scroller.style.borderRight = "1px solid white";
	scroller.style.borderBottom = "1px solid white";
	

}
function scrollerUp (scroller)
{
	if (scroller==null) return;
	scroller.style.borderTop = "1px solid white";
	scroller.style.borderLeft = "1px solid white";
	scroller.style.borderRight = "1px solid black";
	scroller.style.borderBottom = "1px solid black";	
}
var childrenCollectionResult = null;
function getChildObject(obj,tagname, id)
{
    if(obj==null || tagname==null) return null;
    if(obj.childNodes==null) return null;
    var children = obj.childNodes;
    
    for(var i=0; i<children.length; i++)
    {
        if(children[i]!=null && children[i].tagName!=null)
            if(children[i].tagName.toLowerCase() == tagname.toLowerCase())
            return children[i];
    }
    return null;
}	
function formatFileSize (file_size)
{
	if(file_size<=1024)
		return file_size + " bytes";
	if(file_size<=1024*1024)
		return Math.round(file_size/1024*10)/10 + " KB";
	if(file_size<=1024*1024*1024)
		return Math.round(file_size/(1024*1024)*10)/10 + " MB";
	else
		return Math.round(file_size/(1024*1024*1024)*10)/10 + " GB";
	return file_size;
}

