function blog(){

	this._blogMain;					//contenitore dei contenitori di questa sezione
	this.blogMain;
	
	this.myBpostBuff=new Array();			//buffer che conterra i post in lettura miei
	this.myBpostBuffLength=10;
	this.myBpostBuffStart=0;

	this.every1BpostBuff=new Array();		//buffer che conterra i post in lettura di TUtti
	this.every1BpostBuffLength=10;
	this.every1BpostBuffStart=0;

	this.otherBpostBuff=new Array();		//buffer che conterra i post in lettura dell'ultimo utente visitato
	this.otherBpostBuffLength=10;
	this.otherBpostBuffStart=0;
	
	this.mybpost_buf_start=0;
	this.mybpost_buf_len=5;
	
	this.bpostBuffCont='bpostList';	//elemento contenitore della lista di post
	//this.bpostCont='';				
	this.bpostRow='';				//elemento che conterrà le info relative al singolo post
	this.bpostTitle='';
	this.bpostAuth='';				//elemento che conterra la mini identita
	this.bpostData='';
	this.bpostCommNumber='';		//area with the number of comments and clickable to have the comment list
	this.bpostPreview='';
	
	this.owner='';				//flag is 1 if the user is reading his blog, 0 otherwise
	this.every1='';
	
	this.bpostDel='';				//link to delete the single blog post (will be avaiable only to its owner...)
	this.bpostClickToComm='';		//clickable item to write comment about the post
	this.bpostCommArea='';
	this.bpostCommListCont='';		//container element of the comment list
	
	this.commItem='';				//contenitore del singolo commento
	this.commAuth='';				//contenitore dell'autore del commento
	this.commDel='';				//link per cancellare il commento (will be available only for the owner of the comment's bpost owner)
	
	this.blogMode='';	//my,other,every
	
	this.printAllPostFirst=1;
	this.readblogFirst=1;
	this.readcommFirst=1;
	this.never=1;
	
	
	this.readblogAreaContainer='content_blog';
	this.readblog_postAreaContainer='content_blog_post';
	this.readblog_commAreaContainer='content_blog_comm';
	this.fillBlogWriterPath='#'+this.readblog_postAreaContainer+' > >#visita';
	this.fillCommWriterPath='#'+this.readblog_commAreaContainer+' > #visita';
	
	this.Autor='';		//when we are surfing between the post this variable tell us who is the author of them
	this.CurrentBid='';	//last bid read in surfing between post
	
	this.bodyRowLength=85;
	this.titleLength=20;
	
	this.deletedcomm=function(tex,o){
		//deve esserci un layer floattante pronto a ricever
		//creare il contenuto html in funzione di tex/ans e metterlo nel content del this.floatlayer;
		ans= JSON.parse(tex);
		if (ans.status == 200) {
			//alert(tex);
			h='Commento cancellato correttamente';
		}
		else {
			h='Operazione non andata a buon fine per momentanei problemi tecnici, ce ne scusiamo';
		}
		$('#'+_msg.msgNotifContainer).empty().append(h).parent().show();	
		$('#menucontent > input[@name="blog"]').trigger('click');
	}
	this.deletedblog=function(tex,o){
		//deve esserci un layer floattante pronto a ricever
		//creare il contenuto html in funzione di tex/ans e metterlo nel content del this.floatlayer;
		ans= JSON.parse(tex);
		if (ans.status == 200) {
			//alert(tex);
			h='Post cancellato correttamente';
		}
		else {
			h='Operazione non andata a buon fine per momentanei problemi tecnici, ce ne scusiamo';
		}
		$('#'+_msg.msgNotifContainer).empty().append(h).parent().show();	
		$('#menucontent_my input[@name="blog"]').trigger('click');
	}

	this.insertedpost=function(tex,o){
		//deve esserci un layer floattante pronto a ricever
		//creare il contenuto html in funzione di tex/ans e metterlo nel content del this.floatlayer;
		ans= JSON.parse(tex);
		if (ans.status == 200) {
			//alert(tex);
			h='Post inserito correttamente';
		}
		else {
			if (ans.status == 410) h='Attenzione non hai scritto il titolo del post!';
			else if (ans.status == 422) h='Attenzione titolo troppo lungo (max 30 caratteri)!';
			else h='Operazione non andata a buon fine per momentanei problemi tecnici, ce ne scusiamo';
		}
		$('#'+_msg.msgNotifContainer).empty().append(h).parent().show();	
		if (ans.status == 200)	$('#menucontent_my input[@name="blog"]').trigger('click');
		else if ((ans.status == 422) || (ans.status == 410)) $('#creablog').trigger('click');
	}

	this.insertedcomm=function(tex,o){
		//deve esserci un layer floattante pronto a ricever
		//creare il contenuto html in funzione di tex/ans e metterlo nel content del this.floatlayer;
		ans= JSON.parse(tex);
		if (ans.status == 200) {
			h='Commento inserito correttamente';
		}
		else {
			h='Operazione non andata a buon fine per momentanei problemi tecnici, ce ne scusiamo';
		}
		$('#'+_msg.msgNotifContainer).empty().append(h).parent().show();	
		if (_blog.mode == 'all') $('#menu_sup > a[name="blog"]').trigger('click');
		else $('#menucontent_my input[@name="blog"]').trigger('click');
		
	}




	//this.fillBlogWriterPath=_blog.readblog_postAreaContainer+' > >#visita';
	this.fillBlogWriter=function(from){
		
		//alert('VCARD:'+from);
		//alert(_blog.fillBlogWriterPath);
		str=from;
		url='/profile/getuserpart2?str='+str;
			$.getJSON(url,function(ans){
				usrs = new Array();
				usrs = ans.usrs;
				for (r=0;r<usrs.length;r++){
					userthumb=_nav.userthumb2(usrs[r]);
					$(_blog.fillBlogWriterPath).empty().append(userthumb);
					_blog.currentReadBlog.from_nick=usrs[r].nick;//nn ha senso per la lista msg ma lo ha per il readMsg()
					//$('#mainContent > #content_inbox_messaggi > >#visita').empty().append(userthumb);
					}
				});
	}
	this.fillCommWriter=function(from){
		
		//alert('VCARD:'+from);
		//alert(_blog.fillBlogWriterPath);
		str=from;
		url='/profile/getuserpart2?str='+str;
			$.getJSON(url,function(ans){
				usrs = new Array();
				usrs = ans.usrs;
				for (r=0;r<usrs.length;r++){
					userthumb=_nav.userthumb2(usrs[r]);
					$(_blog.fillCommWriterPath).empty().append(userthumb);
					_blog.currentReadComm.from_nick=usrs[r].nick;//nn ha senso per la lista msg ma lo ha per il readMsg()
					//$('#mainContent > #content_inbox_messaggi > >#visita').empty().append(userthumb);
					}
				});
	}
	this.createReadBlogHtmlStruct=function(){
	 h=' <div id="numerazione_pagine">'  
	+'<div id="precedente"><a class="linkr"><<-- precedente</a></div>  '
	+'<div id="numerazione">1/110</div>   '
	+'<div id="successivo" ><a class="linkr">successivo -->></a></div>'
	+'</div>'
	+'<div style="background-color:#E6E6E6;height:200px;overflow:auto"> <!--#E6E6E6-->'
	+'<br> '
	+'<div id="data_messaggio"></div>';
	if (_blog.mode == 'all')	h+='<div id="visita"></div>';
	
	h+='<div id="messaggio_inbox_blog" style="padding-left:10px;"> '
	+'<span class="rosso"><strong id="msg_title">titolo</strong></span><br />'
	+'<div id="msg_body"></div><br><br><br>'
   +' </div>'
    +' </div>';
    if (_blog.owner==1)
    h+='<div id="barra_contatto" name="cancella">  <img src="../application/views/img/trash.gif" alt="cancella" align="absbottom" /> <a class="link">Cancella</a>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>'
    +'';
	//else 
    //h+='<div id="barra_contatto" name="commenta">  <img src="../application/views/img/comment.gif" alt="commenta" align="absbottom" /> <a class="link">Commenta</a>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>';
    h+='<br />';
	return h;
	}

//////////////////////////////////////////////////////////////////////////	
	this.createReadCommHtmlStruct=function(what){
	 if (what=='comm'){
	 h=' <div id="numerazione_pagine">'  
	+'<div id="precedente"><a class="linkr"><<-- Commento precedente</a></div>  '
	+'<div id="numerazione">1/110</div>   '
	+'<div id="successivo" ><a class="linkr">Commento successivo -->></a></div>'
	+'</div>';
 
	h+='<div id="titolo_commento" style="width:673px; height:25px;"> '
	+'<div id="titolo_commento">Commenti:</div>'
	+'<div id="aggiungi_commento"> <a class="link">Aggiungi commento >></a></div>'
	+'</div> <div id="visita"></div><div id="commento"></div><div id="data_messaggio"></div>';
  if (_blog.mode=='my')
         h+='<div id="cancella_comm" name="cancella_comm" style="floal:right;whidt:100px;text-align:right;margin-right:5px"><a class="link">Cancella >></a></div>';
	}
	else {
	h='<div id="titolo_commento" style="width:673px; height:25px;"> '
	+'<br>Nessun commento per questo post<br>'
	+'<div id="aggiungi_commento"> <a class="link">Aggiungi commento >></a></div>'
	+'</div>';
	}	
	return h;
	}
/////////////////////////////////////////////////////////////////////////	
	
	this.fill_nextlnk=function(nextinf,nextsup,tot,pos,what){
		if (what == 'post'){
			cont=_blog.readblog_postAreaContainer;
			bindsup='nextsup_post';
			bindinf='nextinf_post';
		}
		else {
			cont=_blog.readblog_commAreaContainer;
			bindsup='nextsup_comm';
			bindinf='nextinf_comm';
		}		
		if (nextsup>-1) {
			$('#'+cont+' > #numerazione_pagine > #successivo > a').attr('nextsup',nextsup);
			//$('#content_inbox_messaggi > #numerazione_pagine > #successivo > a').livequery
			this.bindevent_loc(bindsup);
		}	
		else $('#'+cont+' > #numerazione_pagine > #successivo > a').text('');
		if (nextinf>-1) {
			$('#'+cont+' > #numerazione_pagine > #precedente > a').attr('nextinf',nextinf);
			this.bindevent_loc(bindinf);
		}	
		else $('#'+cont+' > #numerazione_pagine > #precedente > a').text('.');
		//n=this.Msg_bufInd+1;
		pos++;
		//$('#content_inbox_messaggi > #numerazione_pagine > #numerazione').text(n+'/'+this.totMsg);
		$('#'+cont+' > #numerazione_pagine > #numerazione').text(pos+'/'+tot);
	}

	this.readblogcomm_fill=function(comm){
		//$('#content_blog_comm #commento').html(decodeURI(comm.body));
		$('#content_blog_comm #commento').html(comm.body);
		$('#content_blog_comm #data_messaggio').text(comm.data);
	}

	this.readblogpost_fill=function(blog){
		//_blog.bodyRowLength
		//_blog.titleLength
		$('#content_blog_post > > #messaggio_inbox_blog > #msg_body').css('overflow','auto').html(blog.body);
		//$('#content_blog_post > > #messaggio_inbox_blog > #msg_body').text(blog.body);
		$('#content_blog_post > > #messaggio_inbox_blog > span > #msg_title').text(blog.title);
		$('#data_messaggio').text(blog.data);
	}


	this.readBlogpost=function(tex,o){
		
		ans= JSON.parse(tex);
		
		if (ans.status == 200) {
			//title,body,from,to
				ans.blog.title=decodeURI(ans.blog.title);
				ans.blog.body=decodeURI(ans.blog.body);
				_blog.currentReadBlog=ans.blog;
				
				_container=_blog._blogMain;
				//_nav.setupMainContent("readBlog",_container);//questo deve creaer content_blog & content_blog_post & content_blog_comm
				var ur='/blog/readcomm2?cid=0&bid='+CurrentBid;
				_blog.never=1;
				updtElem(ur,_blog,'readBlogcomm','mainContent');
				
				struct=_blog.createReadBlogHtmlStruct();
				$('#'+_blog.readblog_postAreaContainer).empty().append(struct);
				
				//ora riempio il div "visita" che contiene il thumb microidentita che venendo caricato asincronicamente è meglio che venga caricato una volta che ho la struttura atta a contenerlo
				if (_blog.mode == 'all')
				_blog.fillBlogWriter(ans.blog.autid);
				//gli bindo il click
				if (_blog.readblogFirst){
					bindevent('readmsgThumb');
					//		è da bindare
					//			-blocca contatto
					//			-aggiungi agli amici
					//			-rispondi
					//BINDARE GLI ELEMENTI DELLA STRUCT
					bindevent('readBlogHtmlStruct');
					_blog.readblogFirst=0;
				}
			nextinf=ans.prev;
			nextsup=ans.next;
			tot=ans.totBlog;
			pos=ans.pos;
			_blog.fill_nextlnk(nextinf,nextsup,tot,pos,'post');
				_blog.readblogpost_fill(ans.blog);
		}	
		else {
			alert(ans.errormsg);
		}
	}	

	this.readBlogcomm=function(tex,o){
		ans= JSON.parse(tex);
		if (ans.status == 200) {
			if (ans.comments == 1){
				//title,body,from,to
					_blog.currentReadComm=ans.comm;
               		ans.comm.body=decodeURI(ans.comm.body);
               		
               		if ((ans.pos==0) && this.never==1) {
               			this.never=0;
               			CurrentCid=ans.comm.cid; //se leggo il primo commento il cid lo so da qui
               		}	
					struct=_blog.createReadCommHtmlStruct('comm');
					$('#'+_blog.readblog_commAreaContainer).empty().append(struct);
					
					//ora riempio il div "visita" che contiene il thumb microidentita che venendo caricato asincronicamente è meglio che venga caricato una volta che ho la struttura atta a contenerlo
					//if (_blog.mode == 'my')
					_blog.fillCommWriter(ans.comm.autid);
					//gli bindo il click
					if (_blog.readcommFirst){
						//bindevent('readmsgThumb');
						//		è da bindare
						//			-blocca contatto
						//			-aggiungi agli amici
						//			-rispondi
						//BINDARE GLI ELEMENTI DELLA STRUCT
						bindevent('readCommHtmlStruct');
						_blog.readcommFirst=0;
					}
					
				nextinf=ans.prev;
				nextsup=ans.next;
				tot=ans.totComm;
				pos=ans.pos;
				_blog.fill_nextlnk(nextinf,nextsup,tot,pos,'comm');
				_blog.readblogcomm_fill(ans.comm);
				//alert('commento letto id:'+CurrentCid);
				sync('blog_com');
			}
			else {
				struct=_blog.createReadCommHtmlStruct('NoComm');
				$('#'+_blog.readblog_commAreaContainer).empty().append(struct);
					if (_blog.readcommFirst){
						//bindevent('readmsgThumb');
						//		è da bindare
						//			-blocca contatto
						//			-aggiungi agli amici
						//			-rispondi
						//BINDARE GLI ELEMENTI DELLA STRUCT
						bindevent('readCommHtmlStruct');
						_blog.readcommFirst=0;
					}
			}	
		}	
		else {
			alert(ans.errormsg);
		}
	}	



this.readSurf=function(bpost){
}

this.fill_nextListLnk=function(nextinf,nextsup,buf_start,buf_len,tot){
		if (nextsup>-1) {
			$('#numerazione_pagine_blog > #successivo > a').attr('nextsup',nextsup);
			$('#numerazione_pagine_blog > #successivo > a').text('successivo -->>');
			this.bindevent_loc('nextsupL');
		}
		else $('#numerazione_pagine_blog > #successivo > a').text('');	
		if (nextinf>-1) {
			$('#numerazione_pagine_blog > #precedente > a').attr('nextinf',nextinf);
			$('#numerazione_pagine_blog > #precedente > a').text('<<-- precedente');
			this.bindevent_loc('nextinfL');
		}	
		else $('#numerazione_pagine_blog > #precedente > a').text('.');
		buf_start=parseInt(buf_start);
		buf_len=parseInt(buf_len);
		var n=Math.ceil((1+buf_start)/buf_len);
		//alert(this.msg_buf_start+'  '+this.msg_buf_len+'   '+n);
		var totPag=Math.ceil(parseInt(tot)/parseInt(buf_len));
		//alert(this.totMag+'dddd'+parseInt(this.msg_buf_len));
		if (totPag > 0) $('#numerazione_pagine_blog > #numerazione').text(n+'/'+totPag);
		else $('#numerazione_pagine_blog > #numerazione').text(n+'/1');
}



	this.mybpost=function(tex,o){
		var nextsupL_my;
		var nextinfL_my;
		m_js = JSON.parse(tex);
		ans=JSON.parse(tex);
		//alert(tex);
		if (_blog.mode=='my') $('#creablog').show();
		if (ans.status == 200){
			_blog.mybpost_buf=m_js.dati;
			if (_blog.mybpost_buf) {
				//
				for (var r=0;r<_blog.mybpost_buf.length;r++){
					_blog.mybpost_buf[r].preview=decodeURI(_blog.mybpost_buf[r].preview);
					_blog.mybpost_buf[r].title=decodeURI(_blog.mybpost_buf[r].title);
				}
			}
			_blog.totMybpost=parseInt(m_js.tot);
			if ((_blog.mybpost_buf_start-_blog.mybpost_buf_len)<0) {
				if (_blog.mybpost_buf_start > 0) nextinfL_my=0;
				else nextinfL_my=-1;
			}	
			else nextinfL_my=_blog.mybpost_buf_start-_blog.mybpost_buf_len;
			var s= 0 +parseInt(_blog.mybpost_buf_start) + _blog.mybpost_buf_len;
			if ((s)>=_blog.totMybpost)  nextsupL_my=-1;
			else {
				nextsupL_my=parseInt(_blog.mybpost_buf_start)+parseInt(_blog.mybpost_buf_len);
			}	
			_blog.fill_nextListLnk(nextinfL_my,nextsupL_my,_blog.mybpost_buf_start,_blog.mybpost_buf_len,_blog.totMybpost);
			//alert(_blog.mybpost_buf);
			this.printAllPost(_blog.mybpost_buf);
		}
		else {
			_nav.error('mybpost');
		}
	}


	this.creablog=function(){
		
		h='<div id="header_inbox" style="border:none"> Aggiungi/Modifica Blog'
	+'</div>'
	+'<div id="content_blog">'
	+'<div style="height:300px; background-color: #E6E6E6; ">'
	+'<br> '
	+'<div id="messaggio_inbox" style="height:280px"> '
	+'<span class="rosso"><strong id="title">titolo</strong></span>'
	+':'
	+'<form id="form1" name="form1" method="post" action="">'
	+'<label>'
	+'<input type="text" name="titolo" id="textfield" />'
	+'</label>'
	+'</form><br>'
	+'<div><br><br>'
	+'<span class="rosso">Testo:</span><br />'
	+'<textarea name="testo" id="textarea_bpost" cols="45" rows="16" onKeyPress=check_length("textarea_bpost","bpost","contatore"); onKeyDown=check_length("textarea_bpost","bpost","contatore");></textarea></div><div id="contatore">1000</div>'
	//+'<textarea name="testo" id="textarea_bpost" cols="45" rows="16" onChange=check_length("textarea_bpost","bpost","contatore") ></textarea></div><div id="contatore">1000</div>'
	+'</div>'
	+'</div>'
	+'<div id="barra_contatto"  align="right"><img src="../application/views/img/voce.gif" width="16" height="16" align="absbottom"> <a class="link">Salva</a>&nbsp;&nbsp;&nbsp;&nbsp;</div>';
	$('#blog').empty().append(h);
				$('#content_blog > #barra_contatto').livequery(function(){
					$(this).unbind('click').click(function(event) {
						var testo=$(this).parent().parent().find('textarea[@name="testo"]').attr('value');
						var title=$(this).parent().parent().find('input[@name="titolo"]').attr('value');
						testo=(testo + '').replace(/([^>]?)\n/g, '$1'+ '<br>' +'\n');
						testo=encodeURI(testo);
						title=encodeURI(title);
						//alert('title:'+title);
				ur='/blog/insert2?titolo='+title+'&testo='+testo;
				_container='vvvvvv';
				updtElem(ur,_blog,'insertedpost',_container);
					});
				});		
	}	

	this.creacomm=function(){
	h='<div id="header_inbox" style="border:none"> Aggiungi Commento'
	+'</div>'
	+'<div id="content_blog">'
	+'<div style="background-color: #E6E6E6;">'
	+'<br>'
	+'<span class="rosso">Testo:</span><br />'
	//+'<textarea name="testo_comm" id="textarea_bcomm" cols="105" rows="4" onKeyPress=check_length("textarea_bcomm","bcomm","contatore"); onKeyDown=check_length("textarea_bcomm","bcomm","contatore"); ></textarea></div><div id="contatore">500</div>'
	//+'<form accept-charset="utf-8">'
	+'<textarea name="testo_comm" id="textarea_bcomm" cols="105" rows="4" onKeyPress=check_length("textarea_bcomm","bcomm","contatore"); onKeyDown=check_length("textarea_bcomm","bcomm","contatore"); ></textarea></div><div id="contatore">500</div>'
	//+'</form>'
	+'</div>'
	+'<div id="barra_contatto"  align="right" style="margin-top:-280px"><img src="../application/views/img/voce.gif" width="16" height="16" align="absbottom"> <a class="link" >Salva</a>&nbsp;&nbsp;&nbsp;&nbsp;</div>';
	//alert(h);
	$('#content_blog_comm').empty().append(h);
				$('#content_blog_comm > #barra_contatto').livequery(function(){
					$(this).unbind('click').click(function(event) {
						var testo=$(this).parent().parent().find('textarea[@name="testo_comm"]').attr('value');
						testo=(testo + '').replace(/([^>]?)\n/g, '$1'+ '<br>' +'\n');
						//alert(testo.length);
						testo=encodeURI(testo);
						
						//alert('testo:'+testo);
						//alert('title:'+title);
				
				ur='/blog/addcom2?bid='+CurrentBid+'&testo='+testo;
				_container='';
				updtElem(ur,_blog,'insertedcomm',_container);
				
					});
				});		
	}


	/*
	shows the bpost that are currently in buffer for my blog post
	*/
	this.persBlogList=function(tex,o){
		/*
		qui arrivo quando leggo il blog di un utente singolo (che posso essere io o un'altro utente ma solo di un utente)
		sara il flag _blog.owner a indicare se sto leggendo il mio o quello di un altro
		se leggo il mio avro anche la possibilita di 
			-scrivere/cancellare post
			-cancellare commenti
		*/
		
		ans= JSON.parse(tex);
		if (ans.status == 200) {
			this.myBpostBuff=ans.bpost;
			this.printPersPost(ans.bpost);
		}
		else {
			h='Spiacente ma non è stato possibile effettuare l\'operazione richiesta';
			_nav.error('persBlogList');
		}
	}
	/*
	shows the bpost that are currently in buffer for all blog post
	*/
	this.every1BlogList=function(tex,o){
		ans= JSON.parse(tex);
		if (ans.status == 200) {
			this.every1BpostBuff=ans.bpost;
			this.printAllPost(ans.bpost);
		}
		else {
			h='Spiacente ma non è stato possibile effettuare l\'operazione richiesta';
			_nav.error('every1BlogList');
		}
	}
	
	this.PersBpostHtmlStruc=function(bpost){
		this.bpostRow='bpostRow';
		this.bpostTitle='bpostTitle';
		this.bpostCommNumber='bpostNumberOfComm';		
		this.bpostData='bpostData';
		h='<div id="'+this.bpostRow+'" bid="'+bpost.id+'">'
		+'<div id="'+this.bpostTitle+'">'+bpost.title+'</div>'
		+'<div id="'+this.bpostData+'">'+bpost.data+'</div>'
		+'<div id="'+this.bpostCommNumber+'">'+bpost.com+'</div>'
		+'</div>';
		return h;
	}
	this.Every1BpostHtmlStruc=function(bpost){
		this.bpostRow='bpostRow';
		this.bpostTitle='bpostTitle';
		this.bpostAuth='visita';				
		this.bpostCommNumber='bpostNumberOfComm';		
		this.bpostData='bpostData';
		
		h='<div id="'+this.bpostRow+'" bid="'+bpost.id+'">'
		+'<div id="'+this.bpostTitle+'">'+bpost.title+'</div><div id="'+this.bpostAuth+'" uid='+bpost.usr_id+'/>'
		+'<div id="'+this.bpostData+'">'+bpost.data+'</div>'
		+'<div id="'+this.bpostCommNumber+'">'+bpost.com+'</div>'
		+'</div>';
		return h;
	}

	this.printPersPost=function(bpost){
		newh='';
		str='';
		if (bpost.length > 0){
			for (r=0;r<bpost.length;r++){
				newh+=this.PersBpostHtmlStruc(bpost[r]);
			}	
				id='#'+_blog.bpostBuffCont;
				$(id).empty().append(newh);
				bindevent('blogPersListItem');
		}	
		else {
				newh='Nessun blog scritto fino a questo momento. Inizia ora -->>';	
				id='#'+_blog.bpostBuffCont;
				$(id).empty().append(newh);
		}		
	}		
this.bpostRowHtmlStruc=function(bpost){
		this.bpostTitle='bpostTitle';
		//this.bpostAuth='visita';				
		this.bpostCommNumber='bpostCommNumber';		
		this.bpostData='bpostData';
		this.bpostPreview='bpostPreview';
		this.bpostPreview1='bpostPreview1';
//alert(_blog.mode);

		var preview='';
		var r=0;
		//alert(bpost.preview);
		while (r<bpost.preview.length){
			//alert (preview.substring(preview.length-4));
			if ((preview.substring(preview.length-4)=='<br>') || (preview.substring(preview.length-5)=='<br/>') || (preview.substring(preview.length-6)=='<br />')) 
			{
				r=bpost.preview.length;
				if (preview.substring(preview.length-4)=='<br>') preview=preview.substring(0,preview.length-4);
				else if (preview.substring(preview.length-5)=='<br/>') preview=preview.substring(0,preview.length-5);
				else preview=preview.substring(0,preview.length-6);
			}
			//else	preview+=bpost.preview[r];
			else preview+=bpost.preview.substring(r,r+1);
			r+=1;
		}
		preview='['+preview+'..]';


	if (_blog.mode == 'all'){
		this.bpostRow='bpostRows_blog';
h='<div id="bpostRows_blog" usr_id="'+bpost.usr_id+'" bid="'+bpost.id+'">'
+' <div id="visita_inbox" uid="'+bpost.usr_id+'" style="height:55px; width:200px;float:left;margin-top:3px;  float:left; padding-left:3px"></div>'
+'<div id="'+this.bpostTitle+'">'+bpost.title+'</div>'
+'<div id="'+this.bpostPreview+'">'+preview+'</div>'
+'<div id="'+this.bpostCommNumber+'" ><span class="rosso">'+bpost.com+'</span>  commenti</div>'
+'<div id="'+this.bpostData+'" >'+bpost.data+'</div>'
+'</div>';
//alert(bpost.preview);
	}
	else {
		this.bpostRow='bpostRows';
h='<div id="bpostRows" usr_id="'+bpost.usr_id+'" bid="'+bpost.id+'" style="border:solid 1px #999999; font:Verdana; font-size:12px; color:#999999; width:683px; height:45px; padding-top:5px">'
+'<div id="'+this.bpostTitle+'" style="float:left; width:380px; height:20px; font-family:Verdana; color:#999999; font-size:12px; padding-left:5px;cursor:pointer">'+bpost.title+'</div>'
+'<div id="'+this.bpostPreview1+'">'+preview+'</div>'
+'<div id="'+this.bpostCommNumber+'" style="margin-left:120px;float:left;width:120px; height:20px; font-family:Verdana; color:#999999; font-size:10px; "><span class="rosso">'+bpost.com+'</span>  commenti</div>'
+'<div id="'+this.bpostData+'" >'+bpost.data+'</div></div>'
	}
	return h;	
}	

	this.printAllPost=function(bpost){
		var newh='';
		var str='';
		var container='#'+_blog.bpostBuffCont;
		var id='';
		//alert(bpost.length);
		//alert(bpost.length);
		if (bpost) {
			if (bpost.length > 0){
				for (r=0;r<bpost.length;r++){
					str+=bpost[r].usr_id+',';
					newh+=this.bpostRowHtmlStruc(bpost[r]);
				}	
					//alert(newh);
					id='#'+_blog.bpostBuffCont;
					$(id).empty().append(newh);
					str=str.substr(0,str.length-1);
					url='/profile/getuserpart2?str='+str;
					//alert (url);
				//alert(url);
				$.getJSON(url,function(ans){
					usrs = new Array();
					usrs = ans.usrs;
					for (r=0;r<usrs.length;r++){
						userthumb=_nav.userthumb2(usrs[r]);
						//$('#visita_inbox').parent().parent().find('div[@uid="'+usrs[r].uid+'"]').empty().append(userthumb);
						$('#bpostList').find('div[@uid="'+usrs[r].uid+'"]').empty().append(userthumb);
						////$('#visita_inbox[@uid="'+usrs[r].uid+'"]').empty().append(userthumb);
					}
					//bindevent('blogThumb');
				});
				
				//if (this.printAllPostFirst) {
					bindevent('blogThumb');
					bindevent('blogPersListItem');	
				//	this.printAllPostFirst=0;
				//}	
			}	
			else {
					newh='Nessun blog aperto fino a questo momento.';	
					id='#'+_blog.bpostBuffCont;
					$(id).empty().append(newh);
			}
		}
		else 	{
					newh='Nessun blog aperto fino a questo momento.';	
					id='#'+_blog.bpostBuffCont;
					$(id).empty().append(newh);
			}		
	}		



//////////////////////////////////////////////////////////////////////////////////////////
	this.createBpostHtmlStruct_empty=function(){
		h='<div id="'+this.bpostCont+'">'
		+'<div id="'+this.bpostRow+'"/>'
		+'<div id="'+this.bpostTitle+'"/><div id="'+this.bpostAuth+'"/>'
		+'</div>'
		+'<div id="'+this.bpostButtons+'">'
		+'<a id="'+this.bpostClickToComm+'">Aggiungi commento</a><a id="'+this.bpostDel+'">Elimina</a>'
		+'</div>'
		+'<div id="'+this.bpostCommArea+'">'
		+'<div id="'+this.bpostNumberOfComm+'"/>'
		+'</div>'
		+'</div>';
	}

	this.bindevent_loc=function(what){
		switch (what) {
		
		case "nextsupL":
		
			idstr='#numerazione_pagine_blog > #successivo > a';
			$(idstr).livequery(function(){
				$(this).unbind('click').click(function(){
					nextsup=$(this).attr('nextsup');
						
					_container=_blog._blogMain;
					_blog.mybpost_buf_start=nextsup;
					if (_blog.mode == 'all') ur='/blog/listrecent2?blength='+_blog.mybpost_buf_len+'&startbid='+_blog.mybpost_buf_start;
					else if (_blog.mode == 'my')	ur='/blog/listmyrecent2?blength='+_blog.mybpost_buf_len+'&startbid='+_blog.mybpost_buf_start;
					else ur='/blog/listmyrecent2?rid='+_chisono.oid+'&blength='+_blog.mybpost_buf_len+'&startbid='+_blog.mybpost_buf_start;
				updtElem(ur,_blog,'mybpost',_container); //updtElem(ur,_msg,'inbox',_container);	
				});
			});		
		break;
		case "nextinfL":
		//alert(_msg.totMsg);
			idstr='#numerazione_pagine_blog > #precedente > a';
			$(idstr).livequery(function(){
				$(this).unbind('click').click(function(){
				//alert('oooo');
					nextinf=$(this).attr('nextinf');
					_container=_msg._msgAreaContainer;
					_blog.mybpost_buf_start=nextinf;	
					if (_blog.mode == 'all') ur='/blog/listrecent2?blength='+_blog.mybpost_buf_len+'&startbid='+_blog.mybpost_buf_start;
					else if (_blog.mode == 'my')	ur='/blog/listmyrecent2?blength='+_blog.mybpost_buf_len+'&startbid='+_blog.mybpost_buf_start;
					else ur='/blog/listmyrecent2?rid='+_chisono.oid+'&blength='+_blog.mybpost_buf_len+'&startbid='+_blog.mybpost_buf_start;
					updtElem(ur,_blog,'mybpost',_container);//updtElem(ur,_msg,'inbox',_container);	
				});
			});		
		break;

		case "nextsup_post":
			idstr='#'+_blog.readblog_postAreaContainer+' > #numerazione_pagine > #successivo > a';
			$(idstr).livequery(function(){
				$(this).unbind('click').click(function(){
				bid=$(this).attr('nextsup');
				CurrentBid=bid;
				ur='/blog/read2?uid='+_blog.Autor+'&bid='+bid;
				_container=document.getElementById(_msg.allmsgViewElement);
				updtElem(ur,_blog,'readBlogpost',_container);
				});
			});		
		break;

		case "nextinf_post":
			idstr='#'+_blog.readblog_postAreaContainer+' > #numerazione_pagine > #precedente > a';
			$(idstr).livequery(function(){
				$(this).unbind('click').click(function(){
				bid=$(this).attr('nextinf');
				CurrentBid=bid;
				ur='/blog/read2?uid='+_blog.Autor+'&bid='+bid;
				_container=document.getElementById(_msg.allmsgViewElement);
				updtElem(ur,_blog,'readBlogpost',_container);
				});
			});
		break;			
		case "nextsup_comm":
			
			idstr='#'+_blog.readblog_commAreaContainer+' > #numerazione_pagine > #successivo > a';
			$(idstr).livequery(function(){
				$(this).unbind('click').click(function(){
				cid=$(this).attr('nextsup');
				//_blog.currentComm=cid;
				CurrentCid=cid;//alert(CurrentCid);
				ur='/blog/readcomm2?cid='+cid+'&bid='+CurrentBid;
				updtElem(ur,_blog,'readBlogcomm','');
				});
			});		
		break;

		case "nextinf_comm":
			idstr='#'+_blog.readblog_commAreaContainer+' > #numerazione_pagine > #precedente > a';
			$(idstr).livequery(function(){
				$(this).unbind('click').click(function(){
				cid=$(this).attr('nextinf');
				//_blog.currentComm=cid;
				CurrentCid=cid;//alert(CurrentCid);
				ur='/blog/readcomm2?cid='+cid+'&bid='+CurrentBid;
				updtElem(ur,_blog,'readBlogcomm','');
				});
			});
		break;			
	}	
	}	


	this.readblogpost_fill_=function(blog){
		//_blog.bodyRowLength
		//_blog.titleLength
		rows = new Array();
		var word='';
		var row='';
		var row_ind=0;
		var word_piece='';
		chars=blog.body.split("");
		//for (word in words) alert (word); 
		for (r=0;r<chars.length;r++){
			//alert ('caratt:'+chars[r]+' word:'+word+' row:'+row+' ind:'+row_ind);
			if (chars[r]==' ') {
				// ho uno spazio quindi la parola è finita e la aggiungo alla riga se la lung nuova riga < limite riga
					// altrimenti devo spezzare la parola
				if ((row.length + word.length) > _blog.bodyRowLength) {
					//bisogna spezzare la word
					word_chars=word.split("");
					word_second_piece_switch=0;
					//alert('word_chars:'+word_chars);
					for (rr=0;rr<word_chars.length;rr++){
						//alert('row length:'+row.length);
						if ((row.length + 1) > _blog.bodyRowLength) {
							//alert('if');
							rows[row_ind]=row;
							row_ind+=1;
							row='';
							word_second_piece_switch=1;
							word='';
						}
						else if (!word_second_piece_switch) row+=word_chars[rr]; 
						if (word_second_piece_switch) word+=word_chars[rr];
					}
					row+=word;
				}
				else row+=word;
				word='';
				row+=chars[r];
			}
			else {
				word+=chars[r];
					if ((word.substring(word.length-4)=='<br>') || (word.substring(word.length-5)=='<br/>')){
					word=word.substring(0,word.length-4);
					if ((row.length + word.length) > _blog.bodyRowLength) {
						//bisogna spezzare la word
						word_chars=word.split("");
						word_second_piece_switch=0;
						for (rr=0;rr<word_chars.length;rr++){
							if ((row.length + 1) > _blog.bodyRowLength) {
								rows[row_ind]=row;
								row_ind+=1;
								row='';
								word_second_piece_switch=1;
								word='';
							}
							else  if (!word_second_piece_switch) row+=word_chars[rr]; 
							if (word_second_piece_switch) word+=word_chars[rr];
						}
						row+=word;
					}
					else {
						row+=word;
						rows[row_ind]=row;
						row_ind+=1;
						row='';word='';
					}
					rows[row_ind]='<br>';
					row_ind+=1;
				}
			}	
			//else word+=chars[r];
		}
		///////////////////////////// control on last row and last word remained
				//alert (row+'-----'+word);
				if ((row.length + word.length) > _blog.bodyRowLength) {
					//bisogna spezzare la word
					word_chars=word.split("");
					word_second_piece_switch=0;
					//alert('word_chars:'+word_chars);
					for (rr=0;rr<word_chars.length;rr++){
						
						if ((row.length + 1) > _blog.bodyRowLength) {
							rows[row_ind]=row;
							row_ind+=1;
							row='';
							word_second_piece_switch=1;
							word='';
						}
						else if (!word_second_piece_switch)  row+=word_chars[rr];
						if (word_second_piece_switch) word+=word_chars[rr];
					}
				}
				row+=word;
				rows[row_ind]=row;
		/////////////////////////////
		var formatted='';
		for (rrr=0;rrr<rows.length;rrr++) formatted+=rows[rrr]+'<br>';
		//alert (rows.length);
		//alert (formatted);	
		$('#content_blog_post > > #messaggio_inbox_blog > #msg_body').html(formatted);
		//$('#content_blog_post > > #messaggio_inbox_blog > #msg_body').text(blog.body);
		$('#content_blog_post > > #messaggio_inbox_blog > span > #msg_title').text(blog.title);
		$('#data_messaggio').text(blog.data);
	}



}	
	
//function check_length(my_form)
//{
//maxLen = 50; // max number of characters allowed
//if (my_form.my_text.value.length >= maxLen) {
//// Alert message if maximum limit is reached.
//// If required Alert can be removed.
//var msg = "You have reached your maximum limit of characters allowed";
//alert(msg);
//// Reached the Maximum length so trim the textarea
//my_form.my_text.value = my_form.my_text.value.substring(0, maxLen);
//}
//else{ // Maximum length not reached so update the value of my_text counter
//my_form.text_num.value = maxLen - my_form.my_text.value.length;}
//}


