function randOrd(){
    return (Math.round(Math.random())-0.5); 
} 

function swapImage(element, newimage) {
	/*show normal image for the active category when user hovers over another category*/
	var nav = document.getElementById('nav');
	var lis = nav.getElementsByTagName('LI');

	for(var i = 0; i < lis.length; i++)
	{
		var as = lis[i].getElementsByTagName('a')
		for(var a = 0; a < as.length; a++)
		{
			if(as[a].innerHTML.indexOf(activeMenu) > -1)
			{
				imgs = as[a].getElementsByTagName('img')
				if(imgs[0].src.indexOf('_hover') > -1)
				{
					imgs[0].src = imgs[0].src.split('_hover').join('')
				}
				else
				{
					imgs[0].src = imgs[0].src.split('.png').join('_hover.png')
				}
				
			}
		}
	}

	var oldsrc = element.src
	element.src = newimage
	if (!element.onmouseout)
		element.onmouseout = function (event) { swapImage(this, oldsrc); };
}

// Array für zusätzliche Funktionen die in der js_onload ausgeführt werden sollen
col_onload_functions = new Array();

// Cookie objekte
var cookie_pairs = new Object();
var cookie_expiration = new Date(2099,1,1,1,1,1,1);

// Objekt für die Default Schriftgrössen
fontsizes_default = new Object();

// Allgemeine Variablen
window_loaded = false;
nav_hover_img = null;
nav_hover_img_event = null;
nav_hover_img_new = null;

// Ausführung von JS Code bevor die Seite geladen ist
js_init();

window.onload = js_onload;

// Initialisierung bevor Seite geladen ist
function js_init () {

	// die Schriftgrössen werden initialisier
	
	if (js_browser_accepts_cookies()) {
		js_cookie_init();
		
		// Schriftgrössenänderung
		if (cookie_pairs.fontsizefactor!=0){
			js_fontsize_change(cookie_pairs.fontsizefactor);
		}
	}
	
}

function js_browser_accepts_cookies () {
	return navigator.cookieEnabled;
}

// Cookie initialisieren
// sollten die Cookiewerte falsch sein, werden die js_variablen mit standardwerten befüllt
// am ende wird das cookie mit den js_variablen befüllt
function js_cookie_init () {
	// Wenn kein Cookie gesetzt ist, wird es mit Standardwerten befüllt.
	if (!document.cookie){
		document.cookie = "fontsizefactor=0; path=/; expires=" + cookie_expiration.toGMTString();
	}
	
	// die Cookiewerte werden in js_variablen umgesetzt
	cookie_vals = document.cookie.split(";")[0];
	cookie_pairs_arr = cookie_vals.split(",");
	cookie_pairs_arr.each(function(pair, i) {
		pair_arr = pair.split("=");
		cookie_pairs[pair_arr[0]] = pair_arr[1];
	});
	
	// die werte werden überprüft und gegebenfalls neu gesetzt
	if (cookie_pairs.fontsizefactor){
		parseInt(cookie_pairs.fontsizefactor);
		if (isNaN(cookie_pairs.fontsizefactor)){
			cookie_pairs.fontsizefactor = 0;
		}
	}
	else {
		cookie_pairs.fontsizefactor = 0;
	}
	
	// das cookie wird mit den js_variablen neu gespeichert (hat den sinn, falls die werte falsch waren, dass sie jetzt richtig gespeichert werden)
	document.cookie = "fontsizefactor=" + cookie_pairs.fontsizefactor + "; path=/; expires=" + cookie_expiration.toGMTString();
}

/* Ändert die font-size des body Tags. D.h. alle Angaben die skaliert werden sollen müssen relativ (in %) angegeben werden */
var busywaiter = window.setInterval(function() {
	if (document.body) {
		window.clearInterval(busywaiter);
		var nameEQ = "fontsize=";
		var ca = document.cookie.split(';');
		for(var i=0; i < ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0) return document.body.style.fontSize = c.substring(nameEQ.length, c.length);
		}
	}
}, 10);

function changeFontSize(factor) {
	if (document.getElementById('content').currentStyle) {
		var fontsize = document.getElementById('content').currentStyle['fontSize'];
		var lineheight = document.getElementById('content').currentStyle['lineHeight'];
    }
	else if (window.getComputedStyle) {
		var fontsize = document.defaultView.getComputedStyle(document.getElementById('content'), null).getPropertyValue('font-size');
		var lineheight = document.defaultView.getComputedStyle(document.getElementById('content'), null).getPropertyValue('line-height');
    }

	fontsize = /(\d+)(.+)/.exec(fontsize);
	lineheight = /(\d+)(.+)/.exec(lineheight);

    document.getElementById('content').style.fontSize = (parseInt(fontsize[1]) + factor) + fontsize[2];
    document.getElementById('content').style.lineHeight = (parseInt(lineheight[1]) + factor) + lineheight[2];

	document.cookie = "fontsize=" + document.getElementById('content').style.fontSize + "; path=/";
	document.cookie = "lineheight=" + document.getElementById('content').style.lineHeight + "; path=/";
}

function resetFontSize() {
	document.getElementById('content').style.fontSize = '';
	document.getElementById('content').style.lineHeight = '';
	document.cookie = "fontsize=;path=/";
	document.cookie = "lineheight=;path=/";
}

function js_onload() {
	window_loaded = true;
	
	for (i=0;i<col_onload_functions.length;i++){
		eval(col_onload_functions[i]);
	}
	
	// Resizefunktion aufrufen
	window.onresize = js_resize;
	js_resize();
}

var headerBGx = 0;
/*
function numberScroll()
{
	var toScroll = new Array('start_vertical_numbers', 'vertical_numbers', 'vertical_numbers_light');

	for(i=0;i<toScroll.length;i++)
	{
		headerBGx+=1;

		obj = document.getElementById(toScroll[i]);
		
		if(obj)
		{
			img1 = obj.childNodes[0];
			img2 = obj.childNodes[1];

			if(img1 && img2)
			{
				if(headerBGx >= img1.offsetHeight)
					headerBGx = 0

				img2.style.marginTop=(headerBGx - img1.offsetHeight) + 'px'
				img1.style.marginTop=headerBGx + 'px'
			}
		}
	}

	setTimeout('numberScroll()',50);
}

numberScroll();
*/

function js_resize(){
	if (window_loaded){
		var steuerberatung = document.getElementById('steuerberatung');
		if(steuerberatung)
		{
			if(steuerberatung.offsetHeight >= 487)
			{
				steuerberatung.style.backgroundPosition='bottom left';
			}
			else
			{
				steuerberatung.style.backgroundPosition='0px 0px';
			}
		}
	}
}

function GetDate() {
	obj = document.getElementById("date");
	if (!obj)
		return;
	var jetzt = new Date();
	var Tag = jetzt.getDate();
	if (Tag < 10)
		Tag = "0" + String(Tag);
	var months = new Array("Jänner", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	var Wochentag = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
	var Jahr = jetzt.getYear();
	if (Jahr < 999)
		Jahr += 1900;
	obj.innerHTML = Wochentag[jetzt.getDay()] + ", <span>" + Tag + ". " + months[jetzt.getMonth()] + " " + Jahr + "</span>";
}


function getAdr(prefix, postfix, text) {
        document.write('<a href="mailto:' + prefix + '@' + postfix + '">' + (text ? text : prefix + '@' + postfix) + '</a>');
}

/*printjob*/
function printjob() {
	if (document.all && (navigator.appVersion.indexOf("Mac") != -1)) {
		self.focus();
		alert("Drucken-Funktion unter Macintosh nicht moeglich! \nBitte verwenden Sie Datei/Drucken");
	} else {
		if (document.all && navigator.appVersion.substring(22,23)==4) {
			self.focus();
			var OLECMDID_PRINT = 6;
			var OLECMDEXECOPT_DONTPROMPTUSER = 2;
			var OLECMDEXECOPT_PROMPTUSER = 1;
			var WebBrowser = '<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
			document.body.insertAdjacentHTML('beforeEnd',WebBrowser);
			WebBrowser1.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER);
			WebBrowser1.outerHTML = '';
		} else{
			self.focus();
			window.print();
		}
	}
}


function js_search_submit() {
	search_ok = false;
	obj = document.getElementById('form_search_words');
	obj.value = 'nicht aktiv'
	return false;
	if (obj){
		if (js_trim(obj.value).length>0) {
			search_ok = true;
		}
	}
	if (search_ok){
		return true;
	}
	else {
		obj.focus();
		return false;
	}
}

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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popup(url,typ,para1,width,height)
{
	attrib = "";
	Y = (screen.height - width) / 2;
	X = (screen.width - height) / 2;
	X = Math.round(X);
	Y = Math.round(Y);
	if (para1 == 'CENTER') {attrib += 'height=' + height + ',width=' + width + ',top=' + Y + ',left=' + X;}
	if (typ == 'TYP1') {attrib += ",scrollbars=no";}
	if (typ == 'TYP2') {attrib += ",scrollbars=yes";}
	if (typ == 'TYP3') {attrib += ",scrollbars=yes,menubar=yes";}
	x = Math.random();
	fenster = window.open(url, 'win', attrib);
	return false;
}

function js_popup_image(image, image_width, image_height) {
	window_width = image_width + 'px';
	window_height = image_height + 'px';
	window.open(image,'_blank','location=no,menubar=no,resizable=no,status=no,toolbar=no,dependent=yes,scrollbars=yes,width=' + window_width + ',height=' + window_height);
}

// deletes leading and trailing spaces in a string - adds the function directly to the String Object, so that all strings inherit this method
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, '');
}

function checkEmail(val) {
	if (val) {
		var usr = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
		var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
		var regex = "^"+usr+"\@"+domain+"$";
		var myrxp = new RegExp(regex);
		var check = (myrxp.test(val));
		if (check!=true) {
			return false;
		}
		else {
			return true;
		}
	}
}

/*
validates formfields if they have a value or not
to check for other options do the following
specialfields = new Object();
specialfields.fieldname = new Object();
specialfields.fieldname.check1 = 'function_to_call,error_message';
specialfields.fieldname.check2 = 'second_function_to_call,second_error_message';
specialfields.another_fieldname = new Object();
specialfields.another_fieldname.check1 = 'function_to_call,error_message';
*/
function validateForm(form,specialfields) {
	var errors = new Array();
	var fields = form.getElementsByTagName('label');
	for (i = 0; i < fields.length; i++) {
		var span = fields[i].getElementsByTagName('span')[0];
		if (span) {
			var label = span.firstChild.data;
			label = label.trim();
			// if there is a '*' in the label - this indicates the inputfield has to be filled
			if (label.charAt(label.length - 1) == '*'){
                                label = label.substring(0, label.length - 1).trim();
				// get the inputfield
				var obj_input = fields[i].getElementsByTagName('input');
				if (!obj_input[0])
					obj_input = fields[i].getElementsByTagName('select');
				if (!obj_input[0])
					obj_input = fields[i].getElementsByTagName('textarea');

				// if there is an inputfield
				if (obj_input && obj_input[0]) {
					input = obj_input[0];
					error = false;
					
					// check if the inputfield has a value
					if (!input.value || input.value.trim().length==0) {
						error = true;
						errors.push(label + ' nicht eingegeben');
					}
					
					// check the inputfield for special things (email, ...)
					if (!error && specialfields[input.name]){
						specialfield = specialfields[input.name];
						for (check in specialfield){
							check_function = specialfield[check].split(',')[0];
							check_message = specialfield[check].split(',')[1];
							if (!eval(check_function)(input.value)){
								error = true;
								errors.push(label + ' ' + check_message);
							}
						}
					}
		            
					// on error give the label the className 'error' otherwise delete the className 'error' (if exists)
					if (error){
						className = fields[i].className;
						if (className.length>0){
							className = className + ' ';
						}
						fields[i].className = className + 'error';
					} else {
		            	className = fields[i].className;
		                if (className.indexOf('error')>-1){
							className = className.replace(' error', '');
							className = className.replace('error', '');
							fields[i].className = className;
						}
		            }
				}
			}
		}
	}
    return errors;
}

function showFormErrors (errors) {
	error_message = '';
	for (i=0;i<errors.length;i++){
		error_message += errors[i] + '\n';
	}
	alert(error_message);
}

/***** Mootools Popup *****/

function showHTMLPopup(html) {
	var popupcontainer = $('popupcontainer');
	if(!popupcontainer) {
		popupcontainer = new Element('div').inject(document.body, 'bottom');
		popupcontainer.id = 'popupcontainer';
	}

	popupcontainer.setStyles({
		position: 'fixed',
		top: '0',
		left: '0',
		right: '0',
		bottom: '0',
		background: 'black',
		opacity: '0',
		zIndex: '100000'
	});

	if(navigator.userAgent.indexOf('MSIE 6') > -1) {
		popupcontainer.setStyles({
			position: 'absolute',
			width: document.getWidth(),
			height: document.getHeight(),
			top: $(document.body).getScroll().y
		});
	}

	popupcontainer.html = html;
	popupcontainer.html += '<a class="close" href="javascript:closeHTMLPopup()"><span>X</span></a>';
	popupcontainer.innerHTML = "";
	var fx = new Fx.Morph(popupcontainer, {
		duration: 500,
		wait: false,
		onComplete: function() {
			var popupcontent = $('popupcontent');
			if(!popupcontent) {
				popupcontent = new Element('div').inject(document.body, 'bottom');
				popupcontent.id = 'popupcontent';
			}
			popupcontent.setStyles({
				border: '2px solid gray',
				position: 'fixed',
				top: '50%',
				left: '50%',
				width: 500,
				marginLeft: -250,
				padding: 20,
				zIndex: popupcontainer.getStyle('zIndex')+1,
				opacity: 0,
				visibility: 'hidden'
			});

			popupcontent.innerHTML = popupcontainer.html;
			var close = popupcontent.getElement('.close');
			if(close) {
				close.addEvent('mouseover', function() {
					this.setStyle('opacity', 0.5);
				});
				close.addEvent('mouseout', function() {
					this.setStyle('opacity', 1);
				});
			}
			popupcontent.origHeight = popupcontent.getHeight(); //save for later
			if(popupcontent.getHeight() > document.body.offsetHeight) {
				popupcontent.setStyles({
					overflow: 'hidden',
					height: (document.body.offsetHeight - popupcontent.getStyle('padding').toInt() - 40)
				});
			}
			popupcontent.setStyles({
				marginTop: 0-Math.round(popupcontent.getHeight()/2),
				visibility: 'visible',
				overflow: 'auto'
			});
			var aphex = new Fx.Morph(popupcontent, {
				duration: 500,
				wait: false,
				onComplete: function() {
					popupcontainer.addEvent('click', function() {
						closeHTMLPopup();
					});
				}
			}).start({
				opacity: 1
			});

			if(navigator.userAgent.indexOf('MSIE 6') > -1) {
				popupcontent.setStyles({
					position: 'absolute',
					marginTop: 0,
					top: $(document.body).getScroll().y + (document.body.offsetHeight / 2)  - (popupcontent.getHeight() / 2)
				});
			}
		}
	}).start({
		opacity: '0.4'
	});
}

function closeHTMLPopup() {
	[$('popupcontainer'), $('popupcontent')].each(function(el, i) {
		if(el) {
			el.removeEvents('click');
			var fx = new Fx.Morph(el, {
				duration: 500,
				wait: false,
				onComplete: function() {
					if($('popupcontent'))
						$('popupcontent').destroy();
				}
			}).start({
				opacity: 0
			});
		}
	});
}

function resizeHTMLPopup() {
	var popupcontent = $('popupcontent');
	var popupcontainer = $('popupcontainer');
	if(popupcontent) {
		if(popupcontent.getHeight() > document.body.offsetHeight) {
			popupcontent.setStyles({
				overflow: 'auto',
				height: (document.body.offsetHeight - popupcontent.getStyle('padding').toInt() - 40)
			});
		}
		else {
			popupcontent.setStyles({
				height: popupcontent.origHeight - 40
			});
		}
		popupcontent.setStyles({
			marginTop: 0-Math.round(popupcontent.getHeight()/2)
		});

		if(navigator.userAgent.indexOf('MSIE 6') > -1) {
			popupcontainer.setStyles({
				top: $(document.body).getScroll().y,
				width: document.body.getWidth(),
				height: document.body.getHeight()
			});
			popupcontent.setStyles({
				top: $(document.body).getScroll().y + (document.body.offsetHeight / 2)  - (popupcontent.getHeight() / 2),
				marginTop: 0
			});
		}
	}
}

window.addEvent('resize', function() {
	resizeHTMLPopup();
});
window.addEvent('scroll', function() {
	resizeHTMLPopup();
});

window.addEvent('domready', function() {
	if($('startpage')) {
		//showHTMLPopup($('popuphtml').innerHTML); // INACTIVE BY KSC: GENERATES JS ERROR!
	}
});

/*WEIHNACHTSBANNER*/
window.addEvent('domready', function() {
  var d=new Date();
  var currdate = d.getFullYear() + "" + (d.getMonth()+1) + "" + d.getDate ();
  if(currdate > 20091214 && currdate < 20100105 )
  {
    if (document.getElementById("newsbox") != null)
      document.getElementById("newsbox").style.display = "none";
    if (document.getElementById("christmasbanner") != null)
    document.getElementById("christmasbanner").style.display = "block";
  }
});