function generatePassword() {
	var password = "";
	//var codearray = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
	var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	var codearray = letters.split('');
	var random = 0;
	for(var i = 0; i < 10; i ++) {
		random = Math.round(61*Math.random());
		password = password + codearray[random];
	}
	document.getElementById('generatedpw').style.display = '';
	document.getElementById('generated').innerHTML = password;
}

function checkifsame() {
	if(document.passwordform.password.value == document.passwordform.password2.value) {
		var Strongness = checkPass(document.passwordform.password.value, 'strongness', 'strongness', 'strongness', new Array('Unbrauchbar', 'Schlecht', 'Mittel', 'Super'));
		if(Strongness < 75) {
			return confirm("Wirklich unsicheres Passwort verwenden?");
		}
		
		return true;
	}
	else {
		return false;
	}
}

function pw2matches() {
	if(document.passwordform.password.value == document.passwordform.password2.value) {
		document.getElementById('pw2matches').innerHTML = "Stimmt &uuml;berein";
		document.getElementById('pw2matches').style.color = "green";
	}
	else {
		document.getElementById('pw2matches').innerHTML = "Stimmt NICHT &uuml;berein";
		document.getElementById('pw2matches').style.color = "red";
	}
}


var nCrackrate = 1000;
var nTreshholddays = 365 * 10000;
var nSteps = 100;

function contains(strText, strPattern)
{
 for (i = 0; i < strText.length; i++)
 {
 if (strPattern.indexOf(strText.charAt(i)) > -1) return true;
 }
 return false;
}

function checkPass(strPass, strId, strClassname, strTextId, aTexts)
{
	pw2matches();
	nCombinationCount = 0;
	
	strToCheck = "0123456789";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;
	strToCheck = "abcdefghijklmnopqrstuvwxyz";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;
	strToCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;
	strToCheck = ",;:-_=+|//?^&!.@$£#*()%~<>{}[]";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;
	var nDays = ((Math.pow(nCombinationCount, strPass.length) / nCrackrate / 2) / 86400);
	var nStrongness = Math.round(nDays / nTreshholddays * 100);
	if (nStrongness < (strPass.length * 5)) nStrongness += strPass.length * 5;
	if (nStrongness > 100) nStrongness = 100;
	nStrongness = Math.round(nStrongness / (100 / nSteps));
	
	oId = document.getElementById(strId);
	oId.style.width = nStrongness+"%";
	otId = document.getElementById(strTextId);
	
	if (aTexts)
	{
	nKey = Math.round((aTexts.length - 1) / nSteps * nStrongness);
	otId.innerHTML = aTexts[nKey];
	}
	return nStrongness;
}


function email2matches() {
	if(document.emailform.email.value == document.emailform.email2.value) {
		document.getElementById('email2matches').innerHTML = "Stimmt &uuml;berein";
		document.getElementById('email2matches').style.color = "green";
	}
	else {
		document.getElementById('email2matches').innerHTML = "Stimmt NICHT &uuml;berein";
		document.getElementById('email2matches').style.color = "red";
	}
}

function checkifsameemail() {
	if(document.emailform.email.value == document.emailform.email2.value) {
		return true;
	}
	else {
		return false;
	}
}

function submitpassword() {
	var dosubmit = checkifsame();
	if(dosubmit == true) {
		document.passwordform.submit();
	}
}

function submitemail() {
	var dosubmit = checkifsameemail();
	if(dosubmit == true) {
		document.emailform.submit();
	}
}
