function isRegularEmailAddress(email) {
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	
	if (!supported)
		return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);
	
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");

	return (!r1.test(email) && r2.test(email));
}

function checkContactForm() {
	var errormsg = "Das Kontaktformular wurde nicht richtig ausgef\u00FCllt. \n\n";
	var checksum = errormsg;

	if(document.getElementById("name").value == "") {
		errormsg = errormsg + "- Bitte geben Sie Ihren vollst\u00E4ndigen Namen an. \n";
	}
	
	if(document.getElementById("email").value == "") {
		errormsg = errormsg + "- Bitte geben Sie Ihre E-Mail Adresse an. \n";
	}

	if(document.getElementById("email").value != "" && !isRegularEmailAddress(document.getElementById("email").value)) {
		errormsg = errormsg + "- Bitte \u00FCberpr\u00FCfen Sie die Eingabe Ihrer E-Mail Adresse. \n";
	}
	
	if(document.getElementById("topic").value == "nochoice" || document.getElementById("topic").value == "wrongchoice") {
		errormsg = errormsg + "- Bitte w\u00E4hlen Sie einen Grund f\u00FCr Ihre Anfrage. \n";
	}
	
	if(document.getElementById("msg").value == "") {
		errormsg = errormsg + "- Bitte tragen Sie Ihre Anfrage im Feld 'Nachricht' ein. \n";
	}

	if(errormsg == checksum) {
		return true;
	} else {
		alert(errormsg);
		return false;
	}
}

function submitForm(form) {
	form.submit();
}

function openDynPopup(dynUrl, dynId, dynName, dynWidth, dynHeight) {
	var windowpath = dynUrl + dynId;
	var windowname = dynName;
	var windowoptions = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0";
	var windowwidth = dynWidth;
	var windowheight = dynHeight;
	var windowlocationleft = screen.width / 2 - windowwidth / 2;
	var windowlocationtop = screen.height/ 2 - windowheight / 2;
	window.open(windowpath, windowname, 'left=' + windowlocationleft + ',top=' + windowlocationtop + ',' + windowoptions + ',width=' + windowwidth + ',height=' + windowheight);
}

function closePopup(dynUrl) {
	window.close();
	if(dynUrl != '') {
		opener.location.href=dynUrl;
	}
}
