$(document).ready(function(){
   $("#newvoices_submission").bind('click',function(){
     var nm = $("#name").val();
     var em = $("#email").val();
     var ws = $("#website").val();
     var ttl = $("#title").val();
     var cm = $("#comment").val();
     var sid = $("#story_id").val();
     var email_regex = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
     // validate required fields
     if (!email_regex.test(em)) {
       if (cm.length < 2) {
         alert("You must provide a comment and a valid email address to submit."); 
        }
       else {
         alert("You must provide a valid email address to submit your comment.");
        }
       }
     else if (cm.length < 2) {
        alert("You must provide a comment.");
       }
     else {      
       $('#loading_gif').show();
       $('#comments_results').load(
          '/scripts/process.comments.php',
           { name: nm, email: em, website: ws, title: ttl, comment: cm, story_id: sid, approved: 0, form_tools_form_id: 13 },
           function(){
             $('#loading_gif').hide();
             // you have to use either 'get(0) here or '[0]' or the reset function won't work
             $('#newvoices').get(0).reset(); 
            //$("#leave_comments").hide();
       });   
    } // regex else closing
 });
});
