/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
$(function() {
  $(".button").click(function() {

    document.getElementById( "sendingform" ).innerHTML =  "<br><p>Checking Credentials<p>";
    $("input#submit_btn").hide();
    var media =  [];
    $(":checked").each(function() {
      media.push($(this).val());
    });
    $.post("/trade/register/ajax" , {   'title'     : $("input#title").val(),
                                        'last_name' : $("input#last_name").val(),
                                        'first_name': $("input#first_name").val(),
                                        'tel'       : $("input#tel").val(),
                                        'email'     : $("input#email").val(),
                                        'country'   : $("select#country").val(),
                                        'publication': $("input#publication").val(),
                                        'position'  : $("input#position").val(),
                                        'media[]'   : media,
                                        'other'     : $("input#other").val(),
                                        'website'   : $("input#website").val()
                                    },
      function(data){
        $("input#submit_btn").show();
        
        if(data.result === true){
            //window.location = "/trade/gallery";
			window.location = "/thank_you_message/presslogin/";
        } else {
            document.getElementById( "sendingform" ).innerHTML =  "";
            var str = data.message;
            str.replace("&lt;", '<');
            str.replace("&gt;", '>');
            document.getElementById( "form_error" ).innerHTML =  '<span class="alert">' + str + '</span>';
            for ( var i in data.fields )
            {
                document.getElementById("sendingform").innerHTML =  "";
                document.getElementById(data.fields[i]+"_label").innerHTML = '<span class="alert">' +data.errors[i] + '</span>';
            }
        }
      }, "json");
    return false;
	});

});

$(function(){
  $("input#title").select().focus();
});



