/* DT-forum.js - javascript used for forum interactions */
//var count = 0;

$(document).ready(function() {
  $(".reply-link").click(function() {
    //alert('hi there');
    //$('#addNewComment').slideToggle('slow');
    $("#addComment").slideToggle();
    $("#toggleAddComment").focus();
  });
});

function tryAddThread() {
   var title = $("#threadTitle").val();
   var comment = $("#threadComment").val();
   
   /* check for comment length and thread value > 0 */
   if (comment.length < 1) {
     alert('Enter an initial comment to start the discussion.');
     return false;
   }  
   $("#addThread").slideToggle('slow');   
   $.post('/budget/forum.php?q=1', 
    {title:title, comment:comment }, 
    function(data) {
      //alert(data);
      if (data==-1) {
        $("#threadTitle").val('');
        $("#threadComment").val('');

        // alert modify title slightly??
      } else if (data.length > 0) {
        $("#threadTitle").val('');
        $("#threadComment").val('');
        window.location.reload();
        //$("#newThread").addClass('tip-container');      
        // after the comment box, add the following content..
        //$("#addNewThread").after('<div class="tip-container"><div class="tip-abstract"'+data+'</div></div>');
        //$("#forum-pagination").after(data);
        // reset the thread area
        
      }
   });
}

function replyClick() {
  //alert('hi there');
  //$(\'#addThread\').slideToggle()
}
function tryThreadComment() {
  var comment = $("#dt_forum_comment").val();
  var captcha = $("#dt_forum_captcha").val();
  var thread = $("#dt_forum_thread").val();
  
  $("#addComment").slideToggle('slow');
  $.post('/budget/forum.php?q=2', 
    {comment:comment, captcha:captcha, thread:thread }, 
    function(data) {
      //alert(data);
      if (data==-1) {
        $("#dt_forum_comment").val('');
        $("#dt_forum_captcha").val('');
        alert('DollarTimes users can post messeges and create new threads on the site.  \nIf you believe this message is in error, please go to the contact us link on the bottom of the page.');
      } else if (data.length > 0) {
        $("#dt_forum_comment").val('');
        $("#dt_forum_captcha").val('');
        window.location.reload();
        //$("#forum-pagination").after('<div class="forum-thread-container"><div class="forum-thread">'+data+'</div></div>');                          
        /*
        if (count%2==0) {
          $("#forum-pagination").after('<div class="tip-comment-a">'+data+'</div>');                          
        } else {
          $("#forum-pagination").after('<div class="tip-comment-b">'+data+'</div>');      
        }
        */
        //count++;
      }
     //alert('data returned: '+data);
   });
}


