/*
* Login part
*/
$(document).ready(function($) {

        //Remove login li
        $('.login').remove();


	//Attach form
	var options = {
                target:        '#messageBox1',   // target element(s) to be updated with server response
                beforeSubmit:  validateForm,  // pre-submit callback
                success:       showResponse  // post-submit callback
              };

        var parentForm = $('#loginForm');

        parentForm.ajaxForm(options); //add ajaxForm

});

//form validation
function validateForm() {

	//

	if( ($('#inputUser').val().length) < 3) {

		$('#inputUser').css('border', '1px solid red');
		$('#messageBox1').html('Nickname ist mindestens 3 Zeichen lang');
		return false;

	}

	else if( ($('#inputPassword').val().length) < 3) {

		$('#inputPassword').css('border', '1px solid red');
		$('#messageBox1').html('Passwort ist mindestens 3 Zeichen lang');
		return false;

	} else {
                $('#messageBox1').html('<div class="loginLoader">Logging...</div>');
                $('input').css('border', '1px solid #999999');
        return true;
        }

}
//Show response
function showResponse(responseText, statusText) {

        //You are logged now we must show
		if (responseText == 'logged') {
				if ($('#inputUser').val() == 'manager') {
						$('#messageBox1').html('Welcome admin.');
						window.location = absolutePath + "admin.html";

				} else {
						$('#messageBox1').html('You are logged in.');
						window.location = absolutePath + "member.html";
				}
		}

}