var browser = navigator.userAgent;
var ie      = (document.all);
var opera   = (browser.search(/opera/i)   > 0)? 1 : 0;
var mozilla = (browser.search(/mozilla/i) > 0)? 1 : 0;
var mx, my;
var ok = 0;

var months   = new Array("Jan.", "Feb.", "M&auml;rz", "April", "Mai", "Juni", "Juli", "Aug.", "Sep.", "Okt.", "Nov.", "Dez.");
var weekdays = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
var times_do = 1;
var time;
var htime;
var pre_menu = new Array();


// register event-functions
document.onmousemove = mouseCoords;
window.onerror = errorEvent();

function init()
{
    DisplayTime();
    setInterval("DisplayTime()", 1000);
    LoadImages();
    if (typeof startup == "function") startup();
	ok = 1;
}

function errorEvent()
{
    return true;    
}    

function mouseCoords(e) 
{
    mx = (ie) ? event.clientX + document.body.scrollLeft : e.pageX;
	my = (ie) ? event.clientY + document.body.scrollTop  : e.pageY;       
}    	
	
   
function getObject(id)
{
    if (document.all)
    {
       return(document.all[id]);
    }
    else if (document.getElementById)
    {
       return(document.getElementById(id));
    }	
}

function getNamedObject(name)
{
    return(document.getElementsByName(name)[0]);
}

function getPageCoords (elementId) 
{
	var element = getObject(elementId);

    if (element) 
    {
       var coords = {x: 0, y: 0};
       do 
       {
          coords.x += element.offsetLeft;
          coords.y += element.offsetTop;
          element = element.offsetParent;
       }
       while (element)
       return coords;
   }
   else
   {
        return null;
   }
}

function message(name, state)
{
    o = getObject(name).style;
    o.visibility = (state == 1)? "visible" : "hidden";
    o.top = my - 15;
    o.left = mx - 280;
}

function bubble(state, url, txt)
{
    o = getObject("bubble").style;
    o.visibility = (state == 1)? "visible" : "hidden";
    if (state == 0) return;
    o.top = my;
    o.left = mx - 390;
    getObject("bubble_text").innerHTML = txt;
    getObject("fr_bubble").src=url;
}

function AdjustNumber(len, val)
{
    s = String(val);
    for (i = len - s.length; i; i--) s = "0"+s;
    return(s);
}

function DisplayTime()
{
    systime[0]++;
    if (systime[0] > 59) { systime[0] = 0; systime[1]++; }
    if (systime[1] > 59) { systime[1] = 0; systime[2]++; }
    if (systime[2] > 23) { systime[2] = 0; systime[3]++; }
    
    sec  = ((systime[0] < 10) ? AdjustNumber(2, systime[0]) : String(systime[0]));
    min  = ((systime[1] < 10) ? AdjustNumber(2, systime[1]) : String(systime[1]));
    hour = ((systime[2] < 10) ? AdjustNumber(2, systime[2]) : String(systime[2]));
    time = hour+":"+min+":"+sec;
    getObject("time").innerHTML = time;
    
    display_times();
}

function newImage(arg) 
{
	if (document.images) 
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function chgImage(o,i,s)
{
    if (pre_menu[i*2+s] && ok) o.src=pre_menu[i*2+s].src;
}

function call(link)
{
    location.href=link;
}

function checkcall(text, link)
{
    s = confirm(text);
    if (s==1) location.href=link;
}

function xsubmit(url)
{
    document.postform.action = url; 
    document.postform.submit();
}

function setPost(name, val)
{
    eval("document.postform."+name+".value = val"); 
}

function imail(obj, text)
{
    p = text.split("?");
    e = p[1]+"@"+p[0];
    obj.href = "mailto:"+e;
    obj.innerHTML = e;
}

function expand(button, name, min)
{
    obj = document.getElementsByName(name)[0];
    size = obj.size;
    if (size == min)
    { 
        obj.size = obj.length;
        button.value = "Zuklappen";
    }
    else
    {
        obj.size = min;
        button.value = "Aufklappen";
    }            
}

function openpic(path)
{
    window.open("show.php?file="+path+"&"+Math.random(), "datei", "menubar=no");
}

function display_times()
{
    if (self.times == undefined) return;

    for (var i = 0; i < times.length - 1; i++)
    {
        times[i][0]--;
        
        if (times[i][0] < 0) { times[i][1]--; times[i][0] += 60; }
        if (times[i][1] < 0) { times[i][2]--; times[i][1] += 60; }
        if (times[i][2] < 0) { times[i][3]--; times[i][2] += 24; }
        
        if (times[i][0] % 10 == 0 || times_do == 1)
        {
            if (times[i][3] < 0) 
            {
                s = '<font color="gray">beendet</font>';
            }
            else 
            {
                pre = "";
                end = "</font>";
                
                if (times[i][3] == 0 && times[i][2] == 0 && times[i][1] < 1)
                {
                    pre = '<font color="red">';    
                } 
                else if (times[i][3] == 0 && times[i][2] == 0 && times[i][1] < 10)
                {
                    pre = '<font color="darkred">';
                }
                else
                {
                    end = "";    
                }
                
                s = pre + (times[i][3]? times[i][3] + "T " : "") +
                          ((times[i][2] || times[i][3])? times[i][2] + "Std " : "") +
                          ((times[i][1] || times[i][2] || times[i][3])? times[i][1] + "Min" : "< 1 Min") + end;
            }
            getObject("timeid"+i).innerHTML = s;
        }
    }
    
    times_do = 0;
}


