
function initFocus() {
	
	document.login.username.focus();
}


function initDoLogin(sw) {

  	var passwort = document.login.password.value;
	var username = document.login.username.value;
	var mandant = document.login.mandant.value;
  	var oldpass = document.login.oldpassword.value;
  	var confirmpass = document.login.confirmpassword.value;

	if(sw == 0) {
	  	if(username == "") {
	  		alert("Bitte einen Benutzernamen eingeben!");
	  		document.login.username.focus();
	  		}
	  	else if(passwort == "") {
	  		alert("Bitte ein Passwort eingeben!");
	  		document.login.password.focus();
	  		}
	  	else {
		  	str = username+"*"+passwort;
			passwort = "";
			document.send.pass.value = hex_sha1(str);
			document.send.user.value = username;
			document.send.mandant.value = mandant;
			document.send.submit();
			}
		}
  	else {

  		var errorCode = initCheckPw(passwort);

	   	if(oldpass == "") {
	  		alert("Bitte das alte Passwort eingeben!");
	  		document.login.oldpassword.focus();
	  		}
	  	else if(passwort == "") {
	  		alert("Bitte ein neues Passwort eingeben!");
	  		document.login.password.focus();
	  		}
	  	else if(confirmpass == "") {
	  		alert("Bitte das neue Passwort zur Bestätigung erneut eingeben!");
	  		document.login.confirmpassword.focus();
	  		}
	  	else if(passwort != confirmpass){
			alert("Passwort und Passwortbestätigung stimmen nicht überein!");
			document.login.confirmpassword.focus();
	  		}
		else if(errorCode!=false) {
	  		location.href = 'index.php?action=chgpw&user=' + username + '&mandant=' + mandant + '&error=' + errorCode;
	  		}
	  	else {
		    document.send.pass.value = hex_sha1(username+"*"+passwort);
		    document.send.oldpass.value = hex_sha1(username+"*"+oldpass);
		    document.send.user.value = username;
		    document.send.chgpw.value = 1;
		    document.send.mandant.value = mandant;
			document.send.submit();
			passwort = "";
		}
  	}

  }


