function AuthOmat() {

	this.willAuthentificate = willAuthentificate;
	this.auhentificationFailed = auhentificationFailed;
	this.authentificationSucceeded = authentificationSucceeded;
	this.authentificationWorking = authentificationWorking;
	this.hideBox = hideBox;
	this.isSuperEvilPassword = isSuperEvilPassword;
	this.isAuthentificated = isAuthentificated;
}

function willAuthentificate(callback) {

	var loginbox = document.getElementById('login');
	var a = "<input type='text' name='password' value='Zauberwort' id='zauberwort'/><button onclick=\"didPressLogin(\'";
	var b = "\');\" value='true'>Los jetzt!</button><p id='loginstatus'></p>"
	loginbox.innerHTML = a+callback+b;
	loginbox.style.opacity = "1.0";
	fuckieshow(loginbox);
}

function isSuperEvilPassword(pw, successfunction) {

	authentificationWorking();

	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		//xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		//Fahr zur Hölle!!
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//alert(xmlhttp.responseText);

			if (xmlhttp.responseText == "Yep") {
				window[successfunction](); //successfunction();
				authentificationSucceeded();
			} else {
				auhentificationFailed()
			}
		}
	}
	var url = "authOmatHelper.php";
	var params = "ultrasecret="+pw.value;
	xmlhttp.open("POST", url, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
}


function authentificationWorking() {

	var loginbox = document.getElementById('loginstatus');
	i = new ActivityIndicator;
	loginbox.innerHTML = "<p>"+i.active();+"</p>";
	/*Kein Bock innerHTML Bug vom IE zu fixen.*/
}


function auhentificationFailed() {

	var loginbox = document.getElementById('loginstatus');
	loginbox.innerHTML = "<p>Derber fehlschlag, Junge echt!</p>";
}

function authentificationSucceeded() {

	var loginbox = document.getElementById('loginstatus');
	i = new ActivityIndicator;
	loginbox.innerHTML = "<p>"+i.success();+"</p>";
	createCookie('YourAwesomeFF', 'Yep', 28);
	hideBox();
}

function hideBox() {

	var loginbox = document.getElementById('login');
	loginbox.style.opacity = "0.0";
	fuckiehide(loginbox);
}

function isAuthentificated() {

	var isAwesome = readCookie('YourAwesomeFF')
	if (isAwesome) {
		if(isAwesome == 'Yep') {
			return true;
		} else {
			return false;
		}
	}

	return false;
}
