
//auth procedure for the login form
$(document).ready(function(){
	
$("#login_form").ajaxForm({
	dataType : 'json',
	type: 'POST',
	url: '/modules/user/login.php',
	beforeSubmit: validate,
	success: doResponse
	
});

function doResponse(responseText, statusText){
	if(responseText.status == "valid"){
		window.location.href = '/my_account.html';
	}else{
		//send the text lines back!
		$("#error_bar").html(responseText.status).show();
	}	
}

function validate(formData, jqForm, options) { 
    // jqForm is a jQuery object which wraps the form DOM element 
    // 
    // To validate, we can access the DOM elements directly and return true 
    // only if the values of both the username and password fields evaluate 
    // to true 
	
	$("#error_bar").hide();
	
    var form = jqForm[0]; 

    if (!form.user.value) { 
    	$("#error_bar").html("Please type your email address!").show();
        return false; 
    }
    if (!form.password.value) { 
    	$("#error_bar").html("Please type your password!").show();
        return false; 
    } 
}

});

