$(document).ready(function() {
    
    $("#BlogComments").load("/LoadBlogComments.ashx?id=" + blogPostId);
    
    $("#BlogCommentSubmit").RecaptchaFacebox(
        {
            url: '/Handlers/Recaptcha.ashx',
            successCallback: RecaptchaSuccessCallback
        }
    );
    
    $("#blog_comment_name").focus(function() {
        if($(this).val().toLowerCase() == 'name') $(this).val('');
    });
    
    $("#blog_comment_name").blur(function() {
        if($(this).val() == '') $(this).val('Name');
    });
    
    $("#blog_comment_email").focus(function() {
        if($(this).val().toLowerCase() == 'email') $(this).val('');
    });
    
    $("#blog_comment_email").blur(function() {
        if($(this).val() == '') $(this).val('Email');
    });
    
    $("#blog_comment_url").focus(function() {
        if($(this).val().toLowerCase() == 'your web site') $(this).val('http://');
    });
    
    $("#blog_comment_url").blur(function() {
        if($(this).val() == '' || $(this).val() == 'http://') $(this).val('Your Web Site');
    });
    
    $("#blog_comment_title").focus(function() {
        if($(this).val().toLowerCase() == 'comment title') $(this).val('');
    });
    
    $("#blog_comment_title").blur(function() {
        if($(this).val() == '') $(this).val('Comment Title');
    });
    
    $("#blog_comment_message").focus(function() {
        if($(this).val().toLowerCase() == 'comments...') $(this).val('');
    });
    
    $("#blog_comment_message").blur(function() {
        if($(this).val() == '') $(this).val('Comments...');
    });

});

function RecaptchaSuccessCallback() {
    
    $(blogCommentDivId).hide();
    $("#BlogCommentSave").show();
    
    commentName = encodeURIComponent($("#blog_comment_name").val());
    commentTitle = encodeURIComponent($("#blog_comment_title").val());
    commentEmail = encodeURIComponent($("#blog_comment_email").val());
    commentUrl = encodeURIComponent($("#blog_comment_url").val());
    commentMessage = encodeURIComponent($("#blog_comment_message").val());
    postId = $("#blog_comment_id").val();

    //$("#captchaStatus").html(" ");
    // Uncomment the following line in your application
    $.ajax({
        url: "/PostBlogComment.ashx?title=" + commentTitle + "&name=" + commentName + "&email=" + commentEmail + "&url=" + commentUrl + "&message=" + commentMessage + "&id=" + postId, 
        success: function(result) {
            if(result.toLowerCase() == "true") {
                $("#BlogCommentSave").hide();
                $("#BlogComments").load("/LoadBlogComments.ashx?id=" + blogPostId);
            }
        }
    });
    
}
