//Hook the Validation methods to the login form
$(document).ready(function(){	
	var login = $("#login").validate({
		rules: {
			Username: "required",
			Password: "required"
		},
		messages: {
			Username: "Username is missing",
			Password: "Password is missing"
		},
		submitHandler: function() {
			EDB_Login();
		}
	});
	
})


/** 
 * Call API Login 
 */
function EDB_Login() {
	var query = $("#login").serialize();
	var Response = null;
	$("#login-form").hide();
	$("#loading").show();
	$.ajax({
	  type: "GET",
	  url: "proxy.php",
	  dataType: "json",
	  data: query,
	  async: false,
	  success: function(obj) { 
	  	Response = obj;
		if(Response.Success) {
			$.getScript("http://www.send4results.com/api.php?" + query, function() {
				document.location.href="http://www.send4results.com/user/subscriber_lists.php";
			});
		}
		else {
			$("#loading").hide();
			$("#login-form").show();
			$("#login-error").text("The entered credentials where incorrect");
		}
	  }
	});
}