/************************************************************************
 * Copyright (C) 2009 Thomas Krehbiel
 * http://uvteksoftware.com, mailto:tom@uvteksoftware.com
 * Distributed under the terms of the GNU GPL version 3
 ************************************************************************/

/* Javascript for post.php */

function reloadComments()
{
  var q = $('#commentlist');
  //q.html('<img src="'+mapPath('images/load_spinner.gif')+'" alt="" width="16" height="16" border="0" />');
  $.get(mapPath('callback.php')+'?f=getcomments&id='+postid,
    null, 
    function(data){ q.html(data); },
    'text'
  );
}

function postComment(id)
{
  var q = $('#addcommentresponse');

  var nameval = $('#txtName').val();
  
  var commentval = $('#txtComment').val();
  if( commentval == '' )
  {
    q.html('<span class="error">Please enter your comment in the box above.</span>');
    $('#txtComment').focus();
    return false;
  }

  q.html('<img src="'+staticPath('images/load_spinner.gif')+'" alt="" width="16" height="16" border="0" />');
  
  $.ajax({
	  type:"POST",
	  url:mapPath('callback.php')+'?f=postcomment',
	  data:{
	  	id: id,
	  	name: nameval,
	  	comment: commentval
  		},
  	  dataType:'html',
  	  cache:false,
  	  success:function(data){
        q.html(data);
        $('#txtComment').val('');
        reloadComments();
        $('#txtComment').focus();
  		},
  	  error:function(XMLHttpRequest, textStatus, errorThrown){
  			q.html('<span class="error">'+XMLHttpRequest.responseText+'</span>');
  		}
  	});
  
  return true;
}
