window.onDomReady = initReady;

// Initialize event depending on browser
function initReady(fn) {
	//W3C-compliant browser
	if(document.addEventListener) {
		document.addEventListener("DOMContentLoaded", fn, false);
	} else { //IE
		document.onreadystatechange = function(){readyState(fn)}
	}
}

//IE execute function
function readyState(func) {
	// DOM is ready
	if(document.readyState == "interactive" || document.readyState == "complete") {
		func();
	}
}

function checkRegistration() {
	var mail1	= document.getElementById("email").value;
	var mail2 	= document.getElementById("email2").value;
	var atPos	= mail1.indexOf("@");
	var ptPos 	= mail1.indexOf(".", atPos); // Position of '.' aftter @:
	var allowed = "abcdefghijklmnopqrstuvwxyz"; // Zulässige Zeichen für eMails
	allowed += allowed.toUpperCase() + "0123456789.-_@";
	
	if (atPos == -1 || atPos == 0 || mail1.indexOf("@", atPos + 1) > atPos ) {
		alert("Validate your e-mail address!");
		return false;
	} else if ( (ptPos == -1) || (ptPos - atPos < 2) || (mail1.length - ptPos < 3) ) {
		alert("Validate your e-mail address!");
		return false;
	} else if(mail1 != mail2) {
		alert("E-mail addresses do not match!");
		return false;
	} else if( !checkLetters(mail1, allowed) || !checkLetters(mail2, allowed) ) {
		alert("Your e-mail contains invalid letters!");
		return false;
	}
	return true;
}


//--- Unterprogramm, welches die Zeichen prüft
function checkLetters(Feld, allowed) {
	for (var Pos = 0; Pos < Feld.value.length; Pos++) {
		if ( allowed.indexOf(Feld.value.charAt(Pos)) == -1 ) { 
			return false;
		}
	}
	return true;
}


