function checkEvent(ev)
{
    var e=new Array();
    if (ev==null)
    {
        e.altKey=false;
        e.ctrlKey=false;
        e.shiftKey=false;
        e.clientX=0;
        e.clientY=0;
        e.srcElement=document.body;
        e.button=0;
        e.keycode=0;
        e.screenX=0;
        e.screenY=0;
        e.type="unknown";
    }
    else if (ev.modifiers != null)
    {
        e.altKey=(ev.modifiers & Event.ALT_MASK) != 0;
        e.ctrlKey=(ev.modifiers & Event.CONTROL_MASK) != 0;
        e.shiftKey=(ev.modifiers & Event.SHIFT_MASK) != 0;
        e.clientX=ev.pageX;
        e.clientY=ev.pageY;
        e.srcElement=ev.target;
        e.button=ev.which-1;
        e.keyCode=ev.which;
    }
     else
        e=window.event;
    return e;
}

function searchObject(id,doc)
{
    if (doc == null || doc.layers == null) return null;
    if (doc[id] != null) return doc[id];
    var l=null;
    for (var i=0;
            i<doc.layers.length
                && (l=searchObject(id,doc.layers[i].document))==null;
            i++)
        ;
    return l;
}

function getObject(id,w)
{
    if (w == null) w=window;
    if (w.document.all != null)
        return w.document.all[id];
    else
        return searchObject(id,w.document);
}

function getStyle(id,w)
{
    var obj=getObject(id,w);
    if (obj != null && obj.style != null)
        return obj.style;
    else
        return obj;
}

function getObjectStyle(obj)
{
    if (obj != null && obj.style != null)
        return obj.style;
    else
        return obj;
}

function showObject(ob)
{
    if (ob != null)
    {
        if(ob.style != null)
            ob.style.visibility="show";
        else
            ob.visibility="visible";
    }
}

function hideObject(ob)
{
    if (ob != null)
        if(ob.style != null)
            ob.style.visibility="hidden";
        else
            ob.visibility="hide";
}

function setHTML(ob,text)
{
    if (ob != null)
    {
        if(ob.innerHTML != null)
            ob.innerHTML=text;
        else if(ob.document != null)
        {
            with(ob.document)
            {
                open();
                write(text);
                close();
            }
        }
    }
}

function positionObject(ob,left,top)
{
    if (ob != null)
    {
        var stl = (ob.style != null) ? ob.style : ob;
        stl.left=left;
        stl.top=top;
    }
}

function moveObject(ob,left,top)
{
    if (ob != null)
    {
        var stl = (ob.style != null) ? ob.style : ob;
        stl.left=parseInt(stl.left)+left;
        stl.top=parseInt(stl.top)+top;
    }
}

function checkDimensions()
{
    if(document.body)
    {
        window.innerWidth=document.body.clientWidth;
        window.innerHeight=document.body.clientHeight;
    }
}

function layertree(l,n)
{
    if(!document.layers) return "Layers are not supported in this browser!";
    if(!n) n=1;
    var str="";
    for(var i=1; i<n; i++)
        str+="  ";
    str+=l.name+"\n";
    for(var i=0; i<l.document.layers.length; i++)
        str+=layertree(l.document.layers[i],n+1);
    return str;
}

function setHTML(ob, text)
{
    if(ob)
    {
        if(ob.innerHTML)
            ob.innerHTML = text;
        else if(ob.document)
        {
            ob.document.open();
            ob.document.write(text);
            ob.document.close();
        }
    }
}

function displayWindow(url, width, height) 
{
	var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=1,location=1,status=1');
}

//Layertest
function Layertest()
{
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
/* Functions that swaps down images. */
function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function show(o)
{
	var obj;
	obj=document.getElementById(o);
	if(obj!=null)
	{
		hideAll();
		checkDimensions();
		//obj.style.left=event.clientX - obj.style.posWidth;
		obj.style.left=window.innerWidth - obj.style.posWidth;
		//obj.style.top=event.clientY;
		obj.className='show';
	}
}

function showAbsolute(o)
{
	var obj;
	obj=document.getElementById(o);
	if(obj!=null)
	{
		hideAll();
		obj.className='show';
	}
}

function showLeft(o)
{
	var obj;
	obj=document.getElementById(o);
	if(obj!=null)
	{
		hideAll();
		obj.style.left=event.clientX;
		obj.style.top=event.clientY;
		obj.className='show';
	}
}

function hide(o)
{
	var obj;
	obj=document.getElementById(o);
	if(obj!=null)
	{
		obj.className='hide';
	}
}

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function getCookie()
{
    var co, cv, csplit;
    Cookie=new Array();
    co=document.cookie;
    if(co != null)
    if(co != "")
    {
        csplit=co.split("; ");
        for (var i=0; i<csplit.length; i++)
        {
            cv=csplit[i].split("=");
            Cookie[unescape(cv[0])]=unescape(cv[1]);
        }
    }
    return Cookie;
}

function setCookie(name,wert,tage,verz,domain)
{
    var exp="";
    var dir="";
    var dom="";
    if (tage != null)
    {
        var heute=(new Date()).getTime();
        exp="; expires="
            +(new Date(heute+tage*24*3600000)).toGMTString();
    }
    if (verz != null)
    {
        dir="; path=" + dir;
    }
    if (domain != null)
    {
        dom="; domain=" + domain;
    }
    document.cookie=escape(name) + "=" + escape(wert)
        + exp + dir + dom;
    return getCookie();
}

