// Array für zusätzliche Funktionen die in der js_onload ausgeführt werden sollen
// Allgemeine Variablen
window_loaded = false;
window.onload = js_onload;
window.onresize = js_resize;

function js_onload(){
	window_loaded = true;
	js_resize();
}

//Seite aufgrund der Auflösung anpassen
function js_resize() {
	if (window_loaded){
		obj_rahmen = document.getElementById('rahmen');
	}

	body_width = document.body.offsetWidth;
			
	obj_rahmen.style.width = '';
	if (body_width<1040){	
		obj_rahmen.style.width = '100px';
	}
		
	if (body_width<850){	
		obj_rahmen.style.width = '0';
	}
	else
	{
		obj_rahmen.style.width = '';
	}
}


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 getAdr(prefix, postfix, text) {
		document.write('<a href="mailto:' + prefix + '@' + postfix + '">' + (text ? text.replace(/&quot;/g, '"').replace(/%EMAIL%/, 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); };
}

var sel;
function HideSelects(x,y,w,h) {
	if(xIE4Up && !xMac) {
		var selx, sely, selw, selh, i
		if(!sel)
			sel = document.getElementsByTagName("SELECT");
		for(i = 0; i < sel.length; i++) {
			selx = xPageX(sel[i]);
			sely = xPageY(sel[i]);
			selw = sel[i].offsetWidth;
			selh = sel[i].offsetHeight;
			sel[i].style.visibility = (selx + selw > x && selx < x + w && sely + selh > y && sely < y + h) ? "hidden" : "visible";
		}
	}
}

// Leerzeichen hinten und vorne bei einem String Objekt wegschneiden
function trim(string) {
	return string.replace(/^\s*|\s*$/,'');
}

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) {
	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.replace(/^\s*/, '')
			label = label.replace(/\s*$/, '')
			if (label.charAt(label.length - 1) == '*' && ! fields[i].getElementsByTagName('input')[0].value) {
				alert('Fehler: ' + label.substring(0, label.length -1) + ' nicht eingegeben')
				fields[i].getElementsByTagName('input')[0].focus()
				return false
			}
		}
	}
	return true
}



function showFormErrors (errors) {
	error_message = '';
	for (i=0;i<errors.length;i++) {
		error_message += errors[i] + '\n';
	}
	alert(error_message);
}
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;
}

