jQuery(document).ready(function() {
	$('input:button').click(function(e) {
		var email=$('#LoginEmail').val();
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (this.id != 'LogOutBtn') {
			if (!filter.test($('#LoginEmail').val())) {
				alert('Please enter a valid Email address');
				$('#LoginEmail').focus();
				return false;
			}
		}
		JeRosubmit(this.id);
	});
	function JeRosubmit(id){
		var options = {
			cache: false,
			dataType: 'html',
			type: 'POST',
			url: '/ajaxlogin.php',
			success: function(responseText, textStatus) {
				try { var response=jQuery.parseJSON(responseText); } 
				catch(e) { alert('JSON error in index: '+responseText); }
				if (response.status==1) {
					window.location=window.location;
				}
				else {
					alert(response.message);
				}
			},
			error: function(xhr, textStatus, errorThrown) {
				alert('An error occurred! ' + (errorThrown ? errorThrown : xhr.status));
			}
		}
		$.ajaxSetup(options);
		$.ajax({data: $('#LoginForm').serialize()+'&action='+id});
		return false;
	};
});

