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


$(document).ready(function(){
	$('#skip_top').click(function() {
		$( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
		return false;
	});
    $('#go').click(function() {
        var j = 'pz';
        if($('#lang').val() == 'pl') {
            j = 'pl';
        }

        $('.newsletterBox #infon').removeClass().addClass('waiting').html('<p>' + trans[j] + '</p>').show();

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

        $.ajax({
            type : 'POST',
            url : 'modules/newsletter/ajax.php',
            dataType : 'json',
            data: {
                    newsletter : $('#newsletter').val(),
                    lang: $('#lang').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) {
                        $('.newsletterBox #' + data.msg[i].pole).addClass('input_error');
                        if(j == 0) {
                            $('.newsletterBox #' + data.msg[i].pole).focus();
                        }
                        j++;
                    }
                }
                $('.newsletterBox #infon').removeClass().addClass((data.status === true) ? 'successA' : 'errorA').html(msg).show();
                if(data.status === true) {
                    $('#newsletter').val("");
                }

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Error with Ajax.');
            }
        });
        return false;
    });
    $('#contact_send').click(function() {
        var j = 'pz';
        if($('#lang').val() == 'pl') {
            j = 'pl';
        }

        $('.contactBox #infoc').removeClass().addClass('waiting').html('<p>' + trans[j] + '</p>').show();

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

        $.ajax({
            type : 'POST',
            url : 'modules/contact/ajax.php',
            dataType : 'json',
            data: {
                    contact_name : $('#contact_name').val(),
                    contact_title : $('#contact_title').val(),
                    contact_mail : $('#contact_mail').val(),
                    contact_text : $('#contact_text').val(),
                    lang: $('#lang').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) {
                        $('.contactBox #' + data.msg[i].pole).addClass('input_error');
                        if(j == 0) {
                            $('.contactBox #' + data.msg[i].pole).focus();
                        }
                        j++;
                    }
                }
                $('.contactBox #infoc').removeClass().addClass((data.status === true) ? 'successA' : 'errorA').html(msg).show();
                if(data.status === true) {
                    $('#contact_name').val("");
                    $('#contact_title').val("");
                    $('#contact_mail').val("");
                    $('#contact_text').val("");
                }

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Error with Ajax.');
            }
        });
        return false;
    });
    $('#comment_send').click(function() {
        var j = 'pz'
        if($('#lang').val() == 'pl') {
            j = 'pl'
        }
		j = 'pl';
        $('.commentBox #cmt_info').removeClass().addClass('waiting').html('<p>' + trans[j] + '</p>').show();

        $('.input input, .input textarea').blur(function(){
            $(this).removeClass();
        });
        var ident = $('#ident').val();
        var lang = $('#lang').val();
        $.ajax({
            type : 'POST',
            url : 'modules/comments/ajax.php',
            dataType : 'json',
            data: {
                    name : $('#name').val(),
                    come : $('#come').val(),
                    code_captcha : $('#code_captcha').val(),
                    ident : $('#ident').val(),
					mail: $('#mail').val(),
                    lang: $('#lang').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) {
                        $('.commentBox #' + data.msg[i].pole).addClass('input_error');
                        if(j == 0) {
                            $('.commentBox #' + data.msg[i].pole).focus();
                        }
                        j++;
                    }
                }
                $('.commentBox #cmt_info').removeClass().addClass((data.status === true) ? 'successA' : 'errorA').html(msg).show();
                if(data.status === true) {
                    $('#name').val("");
                    $('#come').val("");
                    $('#code_captcha').val("");
                    $('#comments_h3').addClass('comments_h');
                    $.ajax({
                      type : 'POST',
                      url: 'modules/comments/get_posts.php',
                      dataType : 'html',
                      data: {
                            ident : ident,
                            lang: lang
                        },
                      success: function(data) {
                        $('#comments_list').html(data);
                      }
                    });
                }
				var timestamp = new Date().getTime();
				
                $('#token').attr('src','include/token.php?' + timestamp);
                

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Error with Ajax.');
            }
        });
        return false;
    });
	$('#polls_send').click(function() {
        var j = 'pz';
        if($('#lang').val() == 'pl') {
            j = 'pl';
        }

        $('#sonda #infop').removeClass().addClass('waiting').html('<p>' + trans[j] + '</p>').show();

        $.ajax({
            type : 'POST',
            url : 'modules/polls/ajax.php',
            dataType : 'html',
            data: {
                    poll_id : $('#poll_id').val(),
                    vote : $('input[name=vote]:checked').val(),
					lang_polls : $('#lang_polls').val()
            },
            success: function(data){
                $('#polls_content').html(data);
                $('#polls_content #infop').removeClass();
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Error with Ajax.');
            }
        });
        return false;
    });
});


