
function getObjectById(id) {
    return document.all ? document.all[id] : document.getElementById(id);
}

function hide(id) {
  
    var x = getObjectById(id);
    if (x)  {
        x.style.display = 'none';
        x.style.visibility = 'hidden';
    }
}

function show(id) {
    var x = getObjectById(id);
    if (x)  {
        x.style.display = '';
        x.style.visibility = 'visible';
    }
}

function putDivContent(content, divid) {
    var old_content = getObjectById(divid).innerHTML;
    if (old_content != content) {
        getObjectById(divid).innerHTML = content;
    }
}


function imageOver(active)    {
    if (nav_state != active)    {
        getObjectById(active).src = getObjectById(active).src.replace(/passiv/, 'aktiv');
    }
}

function imageOut(active)    {
    if (nav_state != active)    {
        getObjectById(active).src = getObjectById(active).src.replace(/aktiv/, 'passiv');
    }
}


function sub_menu(active)  {
    var tabs = new Array('tab1','tab2','tab3','tab4','tab5','tab6','tab7','tab8');

    for (var key in tabs)
    {
        var tab = tabs[key];
        if (getObjectById(tab)) {
            if (tab==active)    {
                getObjectById(tab).style.backgroundImage = getObjectById(tab).style.backgroundImage.replace(/passiv/, 'aktiv');
                show(tab+'cont');
                if (getObjectById('ActiveTab')) {
                    getObjectById('ActiveTab').value = tab;
                }
            }
            else    {
                getObjectById(tab).style.backgroundImage = getObjectById(tab).style.backgroundImage.replace(/aktiv/, 'passiv');
                hide(tab+'cont');
            }
        }
        
        
    }
  

}

function loadImages()
{
    document.preloadImages = new Array();

    for (var key in headlines)   {

        document.preloadImages[key] = new Image();
        document.preloadImages[key].src = 'gfx/'+key+'_aktiv_neu.gif';
    }
}

function getElementAbsPos(element) {
    var left = 0;
    var top  = 0;
    var reference = element;
    while(reference){
        top  += reference.offsetTop;
        left += reference.offsetLeft;
        reference = reference.offsetParent;
    }
    return [left, top];
}

// true wenn needle in haystack enthalten ist, sonst false
function inArray(needle, haystack) {
    for (var i=0; i<haystack.length; i++) {
        if (needle == haystack[i]) {
            return true;
        }
    }
    return false;
}


// XMLHttpRequest
function XMLHttpRequestClient(serverScript) {

    var xmlreq = false;
    var method = 'GET';
    var serverUrl = null;
    var response  = null;
    var jsCallback = null;
    var jsCallbackParameters = null;
    var debug = false;

    serverUrl = _serverUrl(serverScript);

    this.Request = doRequest;

    if (typeof XMLHttpRequest == "undefined") {
        function XMLHttpRequest() {
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                    xmlhttp = false;
                }
            }
            return xmlhttp;
        }
    }
    else {
        xmlreq = new XMLHttpRequest();
    }
    return;

    function doRequest(handler, handler_parameters, callback, callback_parameters) {

        jsCallback = callback;
        jsCallbackParameters = callback_parameters;

        var sep = serverUrl.search(/\?/) == -1 ? '?' : '&';
        xmlreq.onreadystatechange = ProcessReqChange;
        xmlreq.open(method, serverUrl + sep + 'f=' + handler + _getUrlParameters(handler_parameters), true);
        xmlreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
        xmlreq.send(null);
    }

    function ProcessReqChange() {

        if (xmlreq.readyState == 4) {
            if (jsCallback != null) {
                response = unescape(xmlreq.responseText);

                eval(jsCallback + "(response" + _getParametersList(jsCallbackParameters) + ")");
            }
        }
    }

    function _getUrlParameters(parameters) {
        var str = '';
        for (var i=0; i<parameters.length; i++) {
            str = str + "&p" + i + "=" + encodeURIComponent(parameters[i]);
        }

        return str;
    }

    function _getParametersList(parameters) {

        var str = '';
        for (var i=0; i<parameters.length; i++) {
            str = str + ",'" + parameters[i] + "'";
        }

        return str;
    }


  function _serverUrl(script) {

        try {
            // der ie kann nicht auf window.location zugreifen, wenn die Funktion,
            // die den XMLHttpRequestClient erzeugt, ueber parent.functionname() aufgerufen wird
            var url = window.location['protocol'] +  '//' + window.location['host'] + getGlobalVariable('web_path') + script;
        }
        catch (e) {
            // ... aber er begnuegt sich mit dem Scriptnamen als Parameter furr XMLHttpRequest.open()
            var url = getGlobalVariable('web_path') + script;
        }

        return addGetParameter(url, getGlobalVariable('session_name'), getGlobalVariable('session_id'));
    }


}

// rebuild an array returned from server as string
// optional delimiter defaults to ~
function jsArrayFromString(s, delim) {
    var d = (delim == null)? '~' : delim;
    return s.split(d);
}

// beliebigen Inhalt in einen Div-Bereich schreiben
// z.B.
// javascript:requestDivContent('employees/xml_http_vacation_requests.php',
//                              'calendar_navigation', 'navigation', new Array('2006-07-01'))
function requestDivContent(serverscript, func, divid, param) {

    var req = new XMLHttpRequestClient(serverscript);
    req.Request(func, param, "putDivContent", new Array(divid));
}

function putDivContent(content, divid) {
    if (getObjectById(divid) && getObjectById(divid).innerHTML != content)  {
        getObjectById(divid).innerHTML = content;
    }
}

function requestParentDivContent(serverscript, func, divid, param) {

    var req = new XMLHttpRequestClient(serverscript);
    req.Request(func, param, "putParentDivContent", new Array(divid));
}

function putParentDivContent(content, divid) {

    if (parent.getObjectById(divid) && parent.getObjectById(divid).innerHTML != content)  {
        parent.getObjectById(divid).innerHTML = content;
    }
}

function addGetParameter(url, pname, pval) {
    var sep = url.indexOf('?') == -1 ? '?' : '&';
    return url + sep + pname + '=' + pval;
}

// globale js-Variable sind im Menu-Frame definiert
function getGlobalVariable(name) {

    if (eval(name)) {
        return eval(name);
    }
    else {
        return null;
    }
}

function fadeIn(objId,opacity) {
    show(objId);
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
            
			setOpacity(obj, opacity);
			opacity += 50;

			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 5);
		}
		else	{
			show(objId+'_close');
		}
	}
	
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
    if (opacity==0) {
        obj.style.zindex = 50;
    }
    else    {
        obj.style.zindex = 200;
    }
    
}

function fadeOut(objId) {
    hide(objId);
	if (document.getElementById) {
		obj = document.getElementById(objId);
		setOpacity(obj, 0);
	}
	hide(objId+'_close');
}


function rollOver(obj, state)	{
	if (state==1)	{
		obj.src = obj.src.replace(/\.lo\./, '.hi.');
		obj.src = obj.src.replace(/\.cl\./, '.hi.');
	}
	if (state==2)	{
		obj.src = obj.src.replace(/\.hi\./, '.lo.');
		obj.src = obj.src.replace(/\.cl\./, '.lo.');
	}
	if (state==3)	{
		obj.src = obj.src.replace(/\.lo\./, '.cl.');
		obj.src = obj.src.replace(/\.hi\./, '.cl.');
	}
}

function rollOver2(obj, state)	{
	if (state==1)	{
		obj.src = obj.src.replace(/\_low\./, '_hi.');
	}
	if (state==2)	{
		obj.src = obj.src.replace(/\_hi\./, '_low.');
	}
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) {
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
		return false
	}
	 if (str.indexOf(at,(lat+1))!=-1) {
		return false
	}
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
		return false
	}
	 if (str.indexOf(dot,(lat+2))==-1) {
		return false
	}
	 if (str.indexOf(" ")!=-1) {
		return false
	}
	return true
}

function IsValidTime(timeStr) {
	if (timeStr=='24:00')	{
		return true;
	}
	// Checks if time is in HH:MM:SS AM/PM format.
	// The seconds and AM/PM are optional.
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (second=="") { second = null; }
	if (ampm=="") { ampm = null }
	if (hour < 0  || hour > 23) {
		return false;
	}
	if (minute < 0 || minute > 59) {
		return false;
	}
	if (second != null && (second < 0 || second > 59)) {
		return false;
	}
	return true;
}

function getWindowWidth() {
	  var myWidth = null, myHeight = null;
	  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 myWidth;
}

function selectCheckboxlist(field, val) {
	
	for (i = 0; i < field.length; i++) {
		if (field[i].value!=val)	{
			field[i].checked = false;
		}
	}
}


