$(document).ready(function(){
    //$('#name').keypress(function(){$('#name').css({background:"white",color:"#000000"});});
    //$('#email').keypress(function(){$('#email').css({background:"white",color:"#000000"});});
    //$('#message').keypress(function(){$('#message').css({background:"white",color:"#000000"});});

    $('#f_again').click(function(){
        $('#success_text').hide();
        $('#feedback-form').hide();
        $('#feedback-form').show();

        $('#name').val('');
        $('#email').val('');
        $('#message').val('');
    });

    $('#bform').click(function(){

        $("#feedback-form").validate(
            {
                rules: {
                    name: "required",
                    message: "required",
                    email: {
                        required: true,
                        email: true
                    }
                }
            }
        );

        if ($("#feedback-form").valid())
        {
            name = $('#name').val();
            email = $('#email').val();
            message = $('#message').val();
            pg = $('#pg').val();

            $.ajax({
               url: "emailsend.php",
               type:'POST',
               dataType: "text",
               data: "name="+name+"&email="+email+"&message="+message+"&pg="+pg,
               beforeSend: function(){
                    $('#preload_text').show();
                    $('#feedback-form').hide();
               },
               success: function(data){
                    //$('#success_text').show();
                    $('#preload_text').hide();
                    $('#feedback-form').show();

                    $('#name').val('');
                    $('#email').val('');
                    $('#message').val('');
                    
                    var currentTime = new Date();
					var month = currentTime.getMonth() + 1;
					var day = currentTime.getDate();
					var year = currentTime.getFullYear();
					var minutes = currentTime.getMinutes();
					var hours = currentTime.getHours();
					month = (month < 10)? "0" + month : month;
    				day = (day < 10)? "0" + day : day;
    				hours = (hours < 10)? "0" + hours : hours;
					var datetime = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes;

                    comment_block = $('#comment_block').html();
                    $('#comment_block').html('<span class="description"><span class="reviewer">'+name+'</span>, <span class="dtreviewed"><span class="value-title" title="' + datetime + '" >' + datetime + '</span></span><span class="summary">'+message+'</span></span>' + comment_block);
               }
             });
        }
    });
});
