var trans = new Array();
trans['pl'] = 'Wysy\u0142anie...';

$(document).ready(function(){
    $('#run').click(function() {
        $('#info').removeClass().addClass('waiting').html('<p>' + trans[$('#jezyk').val()] + '</p>').show();

        $('.input input, .input textarea').blur(function(){
            $(this).removeClass();
        });

        $.ajax({
            type : 'POST',
            url : 'ajax.php',
            dataType : 'json',
            data: {
                    imie_nazwisko : $('#imie_nazwisko').val(),
                    adres : $('#adres').val(),
                    mail : $('#mail').val(),
                    telefon : $('#telefon').val(),
                    tresc : $('#tresc').val()
            },
            success: function(data){
                var msg = '';
                var l = data.msg.length;
                var j = 0;
                for(var i = 0; i < l; i++) {
                    msg += '<p>' + data.msg[i].text + '</p>';
                    if(data.msg[i].pole !== false) {
                        $('#' + data.msg[i].pole).addClass('input_error');
                        if(j == 0) {
                            $('#' + data.msg[i].pole).focus();
                        }
                        j++;
                    }
                }
                $('#info').removeClass().addClass((data.status === true) ? 'success' : 'error').html(msg).show();
                if(data.status === true) {
                    $('#imie_nazwisko').val("");
                    $('#adres').val("");
                    $('#mail').val("");
                    $('#telefon').val("");
                    $('#tresc').val("");
                }

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Error with Ajax.');
            }
        });
        return false;
    });
});


