/* 
	Create the new window 
	(needed for extern windows)
*/ 
function openInNewWindow() { 
	// Change "_blank" to something like "newWindow" to load all links in the same new window 
	var newWindow = window.open(this.getAttribute('href'), '_blank'); 
	newWindow.focus(); 
	return false; 
} 

/* 
	Add the openInNewWindow function to the onclick event of links with a class name of "bin_extern" 
	(needed for targets)
*/ 
function getNewWindowLinks() { 
	
	// Check that the browser is DOM compliant 
	if (document.getElementById && document.createElement && document.appendChild) { 
		// Find all links 
		var link; 
		var links = document.getElementsByTagName('a'); 
		for (var i = 0; i < links.length; i++) { 
			link = links[i]; 
			// Find all links with a class name of "bin_extern" 
			if (/bin\_extern/.exec(link.className)) { 
				link.onclick = openInNewWindow; 
			} 
		} 
	} 
} 

/*
	Create a new event (needed for targets)
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

/*
	Delete a event (needed for targets)
*/
function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

/*
	Add the target link event to the eventhandler
*/
addEvent(window, 'load', getNewWindowLinks); 


/*
	Formulartest
*/

function checkTextObj(textobj, minlen, defaultText) {
	var str = new String(textobj.value);
	if (str.length < minlen) {
		textobj.focus();
		return (-1);
	}
	if (textobj.value.indexOf(defaultText) >= 0) {
		textobj.focus();
		return (-1);
	}
	if (textobj.name.indexOf("email") >= 0) {
		if ((str.indexOf("@") < 1) || (str.indexOf(".", str.indexOf("@")) < str.indexOf("@"))) {
			textobj.focus();
			return (-1);
		}

		var goodcount = 0;
		var goodchars = new String("@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_0123456789");
		for (i=0; i < str.length; i++) { 
			for (j=0; j < goodchars.length; j++) {
				if (str.charAt(i) == goodchars.charAt(j)) { goodcount++ }
			}
		}
		if (goodcount != str.length) {
			textobj.focus();
			alert("Dieses Feld beinhaltet illegale Zeichen!");
			return (-1);
		}
	}
	return 0;
}

function submitKontaktTo(myForm) {
	err = checkTextObj(myForm.name, 2, "Name, Vorname");
	if (err < 0) { alert ("Bitte geben Sie Ihren Namen ein!"); return false;}
	err = checkTextObj(myForm.email, 1, "E-Mail");
	if (err < 0) { alert ("Bitte geben Sie eine korrekte E-Mail-Adresse ein!"); return false;}
	err = checkTextObj(myForm.frage, 12, "Ihre Frage");
	if (err < 0) { alert ("Bitte geben Sie Ihre Anfrage ein!"); return false;}
	
	if (String(myForm.name.value) == String(myForm.ort.value)) {
		alert ("Bitte ueberpruefen Sie Ihre Eingaben!"); 
		return false;
	}
	
	//myForm.submit();
	return true;
}
