/*
function jsMakeRoDate(dateString){
    var months = new Array('ianuarie', 'februarie', 'martie', 'aprilie', 'mai', 'iunie', 'iulie', 'august', 'septembrie', 'octombrie', 'noiembrie', 'decembrie');
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=dateString.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    roDate = new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
    return roDate.getDate()+' '+months[roDate.getMonth()]+' '+roDate.getFullYear();
}
*/
/* TODO?? javascript Paginate ??? 
function jsPaginate(baseUrl,curPage,totalRows,perPage)
{
    if (totalRows==0 || perPage==0) return '';
    var num_pages = Math.ceil(totalRows/perPage);
    if (num_pages==1) return '';
}
*/
function checkComments(json){
  if (json.status=='ok'){
    if (json.message){
      alert(json.message);
    }
    parseResults(json);
  } else {
    alert(json.error);
  }
  $.getJSON(base_url+'/refresh_captcha','',refreshCaptcha);
}

function refreshCaptcha(json){
  $("#captchaImage").attr('src',json.src);
}
function parseResults(json){
   if (json.replies)
   {
   	   if (json.replies.length>0){
       		$("#commentsContainer").empty();
       		//$("#commentsForm")
       		//$("#username").val("");
       		$("#comment").val("");
       		for (k=0;k<json.replies.length;k++)
       		{
           		//$("#commentsContainer").append('<div class="div" style="margin-top:7px;padding-bottom:3px; border-bottom:#e0e0e0 1px solid; width:100%"><span class="grena" >De la: <b>'+json.replies[k].anonymous_author_name+'</b><span style="font-size:11px;">&nbsp;-&nbsp; '+jsMakeRoDate(json.replies[k].create_date)+' </span><br /></span>'+json.replies[k].message+'</div>');
           		$("#commentsContainer").append('<div style="margin-left:20px;width:75px;float:left;">'+json.replies[k].author+'</div><div style="width:400px;float:right;">'+json.replies[k].message+'</div><div style="clear:both;height:5px;"></div>');
       		}
   		}
   }
   else
   {
   		$("#commentsContainer").html("Nu exista nici un comentariu");
   }
   if (json.pagination && json.pagination.length>0){
     $("#commentsPagination").html(json.pagination);
   }
}
function openCommentsPage(base_url)
{
   //$.getJSON(base_url+'/'+item_id+'/'+page,'', parseResults);
   $("#commentsContainer").html('Se incarca');
   $.getJSON(base_url,'',parseResults);
}
