function switchon(e,me){
	for(var i=0; i<=$$('.submenue').length-1; i++){
		$$('.submenue')[i].style.display = 'none';
	}
	$(e).style.display = 'block';
	
	var path = $$('.top')[me].src;
	var status = $$('.top')[me].src.match(/([a-z]*)\.[a-z]{3,4}$/)[1];
	var newpath = path.replace(status, "sel");
	$$('.top')[me].src = newpath;
	
	$$('.top')[me].parentNode.parentNode.onmouseout = function(){switchoff(e,me,path);};
	
	if(acttop != null){
		var acttoppath = $$('.top')[acttop].src;
		var acttopstatus = $$('.top')[acttop].src.match(/([a-z]*)\.[a-z]{3,4}$/)[1];
		var acttopnewpath = acttoppath.replace(acttopstatus, "on");
		$$('.top')[acttop].src = acttopnewpath;
	}

}
function switchoff(e,me,path){
	$(e).style.display = 'none';
	$$('.top')[me].src = path;
	current(acttop,actsubm);
}
function imgdo(e){
	var path = e.src;
	var status = e.src.match(/([a-z]*)\.[a-z]{3,4}$/)[1];
	if(!e.parentNode.parentNode.parentNode.id){
		var newpath = path.replace(status, "sel");
	}else{
		var newpath = path.replace(status, "on");
	}
	e.src = newpath;
	e.onmouseout = function(){imgundo(e,path);};
	//alert(e.parentNode.parentNode.parentNode.id)
}
function imgundo(e,path){
	e.src = path;
}
function current(top,subm,down){
	if(top != null){
		var path = $$('.top')[top].src;
		var status = $$('.top')[top].src.match(/([a-z]*)\.[a-z]{3,4}$/)[1];
		var newpath = path.replace(status, "sel");
		$$('.top')[top].src = newpath;
	
	
	if(down != null){
		//alert($$('.submenue')[subm].getElementsByTagName('img')[down]);
		var downpath = $$('.submenue')[subm].getElementsByTagName('img')[down].src;
		var downstatus = $$('.submenue')[subm].getElementsByTagName('img')[down].src.match(/([a-z]*)\.[a-z]{3,4}$/)[1];
		var downnewpath = downpath.replace(downstatus, "sel");
		$$('.submenue')[subm].getElementsByTagName('img')[down].src = downnewpath;
	}
	
	$$('.top')[top].parentNode.parentNode.onmouseover = null;
	
	if(subm != null){
		$$('.submenue')[subm].style.display = 'block';
	}
	acttop = top;
	if(subm != null){ actsubm = subm; }
	if(down != null){ actdown = down; }
	}
}

function check()
	{
		vorname = document.formular.vorname.value;
		name = document.formular.name.value;
		strasse = document.formular.strasse.value;
		plz = document.formular.plz.value;
		ort = document.formular.ort.value;
		telefon = document.formular.telefon.value;
		email = document.formular.email.value;

		if(vorname.length<2)
			{
				alert("Bitte geben Sie Ihren Vornamen ein.");
				return false;
			}
		if(name.length<2)
			{
				alert("Bitte geben Sie Ihren Nachnamen ein.");
				return false;
			}
		if(strasse.length<3)
			{
				alert("Bitte geben Sie die Strasse ein.");
				return false;
			}
		if(ort.length<2)
			{
				alert("Bitte geben Sie den Ort ein.");
				return false;
			}
		if(plz.length<5)
			{
				alert("Bitte geben Sie die PLZ ein.");
				return false;
			}
		if(telefon.length<5)
			{
				alert("Bitte geben Sie Ihre Telefonnummer ein.");
				return false;
			}
		if(email.length<8)
			{
				alert("Bitte geben Sie Ihre Emailadresse ein.");
				return false;
			}
	}

var openCloseNews = function(id)
{
	var obj = document.getElementById(id);
		for (var i = 1; i<=2000; i++) {
		if (document.getElementById('News'+i)){
			document.getElementById('News'+i).className='';}
		}
		if (obj.className == 'active') {
			obj.className = '';
		}
		else {
			obj.className = 'active';
		}

	
};

var showHide = function(aktiv)
{
	document.getElementById(aktiv).style.display = 'block';
};


var pop = null;

function popdown() {
  if (pop && !pop.closed) pop.close();
}

function popup(obj,w,h) {
  var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
  if (!url) return true;
  w = (w) ? w += 20 : 150;  // 150px*150px is the default size
  h = (h) ? h += 25 : 150;
  var args = 'width='+w+',height='+h+',resizable';
  popdown();
  pop = window.open(url,'',args);
  return (pop) ? false : true;
}

window.onunload = popdown;
window.onfocus = popdown;

function TMCheckDelete() {
	var check = confirm("Wollen Sie diesen Eintrag wirklich löschen?");
	if (check == false) return false;
}

function TMPruefeFormular() {
	var fehler = '', nichtausgefuellt = '', a = arguments, formindex = a[0];
	for (var i = 1; i < (a.length-2); i+=3) {
		var feldname = a[i];
		var pruefen = a[i+1];
		var feldbez = a[i+2];
		var feld = document.forms[formindex][feldname];
		var feldwert = feld.value;
		if (feldwert == '' || feldwert == 0) {
			nichtausgefuellt += '- ' + feldbez + '\n';
		} else {
			if (pruefen.indexOf('pMail') != -1) {
				var AT = feldwert.indexOf('@');
				var letztesAT = feldwert.lastIndexOf('@');
				var letzterPunkt = feldwert.lastIndexOf('.');
				var laenge = feldwert.length;
				if ((laenge <= 6) || (laenge < (AT + 6)) || (AT != letztesAT) || (AT < 1) || (letzterPunkt <= (AT + 2)) || (letzterPunkt >= (laenge - 2))) {
					fehler += '- ' + feldbez + ' muss eine korrekte eMail-Adresse enthalten!\n';
				}
			} else if (pruefen.indexOf('pPLZ') != -1) {
				if ((isNaN(feldwert)) || (feldwert.length != 5)) {
					fehler += '- ' + feldbez + ' muss eine korrekte Postleitzahl enthalten!\n';
				}
			} else if (pruefen.indexOf('pZahl') != -1) {
				if (isNaN(feldwert)) {
					fehler += '- ' + feldbez + ' darf nur Zahlen enthalten!\n';
				}			
			}
		}
	}
	if (fehler || nichtausgefuellt) {
		var meldung = 'EINGABEFEHLER\n\n';
		var trenner = '-----------------------------------------------------------------------------------------------\t\t\n\n';
		meldung += trenner;
		if (nichtausgefuellt) {
			meldung += 'Folgende Felder muessen ausgefuellt werden:\n\n'
			meldung += nichtausgefuellt;
			if (fehler) {
				meldung += '\n'+trenner;
			}
		}
		if (fehler) {
			meldung += 'Folgende Felder wurden falsch ausgefuellt:\n\n'
			meldung += fehler;
			meldung += '\n';
		}
		alert(meldung);
		return false;
	}
}
