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 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>');
       		}
   		}
   }
   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);
}
function parseResultsMystery(json) {
	if (json.replies) {
		if (json.replies.length>0) {
			$("#commentsContainer").empty();
			//$("#commentsForm")
			//$("#username").val("");
			$("#comment").html("");
			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('<li><p><strong>'+json.replies[k].anonymous_author_name+'&nbsp;-&nbsp;'+jsMakeRoDate(json.replies[k].create_date)+'</strong>'+json.replies[k].message+'</p></li>');
			}
		}
	} else {
		$("#commentsContainer").html("<li><p><strong>Nu exista nici un comentariu</strong></p></li>");
	}
	if (json.pagination && json.pagination.length>0) {
		$("#commentsPagination").html(json.pagination);
	}
}
function openCommentsPageMystery(base_url) {
	//$.getJSON(base_url+'/'+item_id+'/'+page,'', parseResults);
	$("#commentsContainer").html('<li><p><strong>Se incarca</strong></p></li>');
	$.getJSON(base_url,'',parseResultsMystery);
}