var images = new Array();
var hoverimages = new Array();

function addPic(id, hoverimg)
{
	var obj = document.getElementById('img'+id)
	if(obj)
	{
		images[id] = new Image();
		images[id].src = obj.src
		hoverimages[id] = new Image();
		hoverimages[id].src = hoverimg
		obj.onload = ''
	}
	else
	{
		setTimeout('addPic('+id+',"'+hoverimg+'")', 100)
	}
}

function changePic(id, hover)
{
	var obj = document.getElementById('img'+id)

	if(obj)
	{
		if(hover)
		{
			obj.src = hoverimages[id].src
		}
		else
		{
			obj.src = images[id].src
		}
	}
}

//Diverse Elemente bei kleiner Fenstergröße verändern
function check_resolution() {
        ChangeImage();
	//array aus IDs die ausgeblendet werden sollen
	var array = new Array();
	var obj;

	var start_logo = document.getElementById('start_logo')
	var start_nav_line = document.getElementById('start_nav_line')
	var start_nav_background = document.getElementById('start_nav_background')
	var start_nav = document.getElementById('start_nav')
	var start_logo_schrift = document.getElementById('start_logo_schrift')
	var start_logo_schrift = document.getElementById('start_logo_schrift')
	var imagebild = document.getElementById('image_background')

	if(start_logo && start_logo_schrift && start_nav_line && start_nav_background && start_nav)
	{
		var topDistance = Math.floor(((document.body.offsetHeight*document.body.offsetWidth) / (640*480))*40);
		start_logo.style.top = 71+topDistance+'px'
		start_logo_schrift.style.top = 151+topDistance+'px'
		start_nav_background.style.top = 188+topDistance+'px'
		start_nav_line.style.top = 187+topDistance+'px'
		start_nav.style.top = 5+topDistance+'px'
		start_nav.style.display='block';
	}

	if (document.body.offsetWidth < 995) {
		for(i = 0; i < array.length; i++) {
			obj = document.getElementById(array[i])
			if(obj)
				obj.style.display = 'none'
		}
	} else {
		for(i = 0; i < array.length; i++) {
			obj = document.getElementById(array[i])
			if(obj)
				obj.style.display = ''
		}
	}

	if(imagebild) {
		if (document.body.offsetHeight < 600) {
			imagebild.style.bottom = '-55px';
		} else {
			imagebild.style.bottom = '0px';
		}
	}
}
window.onresize = window.onload = check_resolution;

function ChangeImage() {
	obj = document.getElementById("start_background");
	if (!obj)
		return;
	var jetzt = new Date();
	var Tag = jetzt.getDate();
	var Monat = jetzt.getMonth()+1;

	/* if((Monat >11 && Tag >20) || (Monat <4 && Tag <1)){ */

	if(Monat > 11 || Monat < 4) {
		obj.innerHTML = '<img src="' + urlCommon + 'images/startpage/background_winter.jpg" alt="" />';
	} else {
		obj.innerHTML = '<img src="' + urlCommon + 'images/startpage/background_sommer.jpg" alt="" />';
	}
}

// flash detect
var benoetigteVersion = 6;
var flash2Installiert = false;
var flash3Installiert = false;
var flash4Installiert = false;
var flash5Installiert = false;
var flash6Installiert = false;
var flash7Installiert = false;
var hoechsteVersion = 7;
var aktuelleVersion = 0;
var richtigeVersion = false;
var browserAol = (navigator.appVersion.indexOf("AOL") != -1) ? true : false;
var browserInternetExplorer  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var betriebssystemWindows = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

if(browserInternetExplorer && betriebssystemWindows && !browserAol) {
	document.write('<scr' + 'ipt language=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installiert = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installiert = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('flash4Installiert = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installiert = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
	document.write('flash6Installiert = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
	document.write('flash7Installiert = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	document.write('<\/scr' + 'ipt\> \n');
}

function detectFlash() {
	if (navigator.plugins) {
		if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var istVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashInfo = navigator.plugins["Shockwave Flash" + istVersion2].description;
			var flashVersion = parseInt(flashInfo.substring(16));
			flash2Installiert = flashVersion == 2;
			flash3Installiert = flashVersion == 3;
			flash4Installiert = flashVersion == 4;
			flash5Installiert = flashVersion == 5;
			flash6Installiert = flashVersion == 6;
			flash7Installiert = flashVersion == 7;
		}
	}

	for(var i = 2; i <= hoechsteVersion; i++)
		if (eval("flash" + i + "Installiert") == true)
			aktuelleVersion = i;

	if(navigator.userAgent.indexOf("WebTV") != -1) aktuelleVersion = 4;

	if(aktuelleVersion >= benoetigteVersion)
		richtigeVersion = true;
}
detectFlash();
// end flash detect

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

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

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 ShowCoworker(id) {
	for(i=0;i<Coworkers.length;i++)
	{
		document.getElementById('ma_'+Coworkers[i]).style.display='none'
	}

	document.getElementById('ma_'+Coworkers[id]).style.display='block'
}

function ShowOrdipic(id)
{
	for(i=0;i<Ordipics.length;i++)
	{
		document.getElementById('ma_'+Ordipics[i]).style.display='none'
	}

	document.getElementById('ma_'+Ordipics[id]).style.display='block'
}











// 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;
		}
	}
}

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) == '*'){
				// 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.substring(0, label.length -1) + ' 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.substring(0, label.length -1) + 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);
}
