
function get_lang_from_path() {
	pathname = document.location.pathname;
	lang = pathname.substring(1, 3);
	return lang;
}

function get_nick_from_cookie(){
	$.ajax({
		type: "POST",
		url: "/"+get_lang_from_path()+"/user/get_nick_from_cookie",
		dataType: "json",
		success: add_nick_to_menu,
		data: "js=1" 
	});
}

function add_nick_to_menu(data){
	if(data.nickname != null && data.nickname != ''){
		$('#menu_0').html('Ciao '+data.nickname);
	}
}

function getModerationComment(nid) {
	   $.ajax({
	     type: "POST",
	     url: "/it/dea/comment/getownortomoderate",
	     dataType: "text",
	     success: handleModerationCommentResponse,
	     data: "nid="+nid 
	   	});
}

function handleModerationCommentResponse(data) {
    eval(data);
    idprevious = 'comments';
    for(i=0; i<data.comments.length; i++) {
        cid = data.comments[i].cid;
        idcomm = 'comment_' + cid;
        if(document.getElementById(idcomm) == null) {
          if(idprevious=='comments') {
             $('#'+idprevious).prepend(data.comments[i].html);
             idprevious = idcomm;
          } else{
             $('#'+idprevious).before(data.comments[i].html);
             idprevious = idcomm;
          }
        } else {
            idprevious = idcomm;
        }
    }
}		

function getModerationBlogComment(nid) {
	   $.ajax({
	     type: "POST",
	     url: "/it/dea/comment/getownortomoderateblog",
	     dataType: "text",
	     success: handleModerationCommentResponse,
	     data: "nid="+nid 
	   	});
}

function getCookie(c_name){
 if (document.cookie.length>0)
 {
 c_start=document.cookie.indexOf(c_name + "=");
 if (c_start!=-1)
 {
 c_start=c_start + c_name.length+1;
 c_end=document.cookie.indexOf(";",c_start);
 if (c_end==-1) c_end=document.cookie.length;
 	return unescape(document.cookie.substring(c_start,c_end));
 }
 }
 return false;
}