﻿function postComment() {

    var postGood = true;
    
    // make sure their comments are good
    if ($("#txtName").val() == "" || 
        $("#txtEmail").val() == "" ||
        $("#txtComments").val() == "" ||
        checkEmail($("#txtEmail").val()) == false ) {
        
            // there would appear to be the fail
            $("#divComments").show();
        
        }
        else {
        
            $("#divPostLink").hide();        
            $("#divPleaseWait").show();        
        
            // all looks good...do an ajax call 
            $("#divComments").hide();
            
            
            var postUrl = "/_blog/";
            
            postUrl = postUrl + 
                "_blogPostComment" + 
                ".aspx";
                
            $.ajax({
                type: "POST",
                url:  postUrl,
                data: "e=" + encodeURI($('#txtEmail').val()) +
                "&n=" + encodeURI($('#txtName').val()) + 
                "&i=" + encodeURI($('#ctl00_ContentPlaceHolder1_hdnArticle').val()) +                 
                "&c=" + encodeURI($('#txtComments').val()),
            
                success: function(msg){
                
                    $("#txtEmail").val("");
                    $("#txtName").val("");
                    $("#txtComments").val("");
                
                    $("#divPostLink").show();                    
                    $("#divPleaseWait").hide();
                    
                        if (msg == "h") {
                        
                            $("#divCommentHeld").show();                        
                            $("#divCommentPosted").hide();                                                    
                        
                        }

                        if (msg == "p") {
                        
                            $("#divCommentHeld").hide();                                               
                            $("#divCommentPosted").show();                        
                        
                        }
        
                    }
                    
                                
             
            }); 
            
        }

}


function checkEmail(emailToCheck) {

    var emailGood = false;
    
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    
    if (filter.test(emailToCheck)) {
            emailGood = true;
        }
        else {
            emailGood = false;
        }

    return emailGood;
}

function popSendtoFriend() {

    var popString = $("#ctl00_ContentPlaceHolder1_hdnSendToFriendURL").val();
    tb_show('', 
    	popString, 
        '');

}

function popPrintThis() {

    var popString = $("#ctl00_ContentPlaceHolder1_hdnPrintURL").val();
	
	popUp = window.open(popString, 'printThis','') ;

	if (popUp) {	
	    popUp.focus();
	}    

}