function resetLoginMessages(){
	resetLoginSuccessMessages();
	resetLoginErrorMessages();
}

function resetLoginSuccessMessages() {
	$("#loginAjaxLoading").hide();
}

function resetLoginErrorMessages(){
	$("#loginAjaxLoading").hide();
	$("#loginAjaxErrors").hide();
}

function handleLoginErrorMessage(errormessage){
	$("#loginAjaxLoading").hide();
	$("#loginAjaxErrorsMessage").html(errormessage);
	$("#loginAjaxErrors").show();
}

function loginUser(){
	resetLoginMessages();
	$("#loginAjaxLoading").show();
	$.getJSON("/jobsrep/ctrl/ajaxSubmitController/?registeredaction=1023&_="+(new Date().getTime())+"&"+$("#loginForm").serialize(),
		function(response){
			var errors = response.errors;
	        var theDataObject = response.data.login_data;
	        if(theDataObject.login_valid == "true"){
	        	if(theDataObject.person_id && theDataObject.person_id!=""){
	           		WM_setCookie("person_id", theDataObject.person_id, 8760, "/", "", false);
	        	}
	            if( theDataObject.extra_roles && theDataObject.extra_roles!=""){
	                WM_setCookie("extra_roles", theDataObject.extra_roles, 8760, "/", "", false);
	            }
	        	if(theDataObject.default_menu_id && theDataObject.default_menu_id!=""){
	       			WM_setCookie("default_menu_id", theDataObject.default_menu_id, 8760, "/", "", false);
	        	}
	        	if(theDataObject.dienst_company_id && theDataObject.dienst_company_id != "" && theDataObject.dienst_company_id != "-1") {
	        		WM_setCookie("dienst_company_id", theDataObject.dienst_company_id, 8760, "/", "", false);
	        	}
	        	if(theDataObject.viadesk_session_id && theDataObject.viadesk_session_id != "") {
	        		WM_setCookie("viadeskSessionId", theDataObject.viadesk_session_id, 8760, "/", theDataObject.viadesk_domain, false);
	        	}
	        	document.location = theDataObject.redirect_url;
	        }
	        else {
	        	handleLoginErrorMessage(errors[0].error);
	        }
		});
	
}
