/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
$(function() {
  $(".button").click(function() {
	  $("input#submit_btn").hide();
      document.getElementById( "sendingform" ).innerHTML =  "<br><p>Checking Credentials<p>";
    $.post("/trade/login/ajax" , { 'email': $("input#email").val(), 'password': $("input#password").val()},
      function(data){
        
        $("input#submit_btn").show();
        document.getElementById("sendingform").innerHTML =  "";
        if(data.success === true){
            window.location="/trade/gallery/";
        } else {
            document.getElementById( "sendingform" ).innerHTML =  "";
            if (data.message != undefined ) document.getElementById( "login_error" ).innerHTML =  "" + data.message;
            for ( var i in data.fields )
            {
            	try {
            		document.getElementById( data.fields[i]+"_label" ).innerHTML = '<span class="alert">' +data.errors[i] + '</span>';
				} catch (e) {
					// TODO: handle exception
				}
            }
            
        }
      }, "json");
    return false;
	});

});

$(function(){
  $("input#email").select().focus();
});



