var NewsContainer = {};

function getAbstract(s,len){
	len = len||150; s = s||"";
	return len<s.length?s.substr(0,s.lastIndexOf(" ",len))+" [...]":s;
}
function addHideTxtLink(id){
	return '<a href="javascript:void(0)" '+
		   'onclick="return hideNews(\''+id+'\')" class="showHide">nascondi testo</a>';
}
function addShowTxtLink(id){
	return '<a href="default.asp?idA=5&amp;id='+id.replace(/[^\d]/g,"")+'&amp;cmd=get" '+
		   'onclick="return showNews(\''+id+'\')" class="showHide">leggi tutto</a>';
}
function hideNews(id){
	if(id){
		document.getElementById(id).innerHTML = getAbstract(NewsContainer[id],250)+addShowTxtLink(id);
		return false;
	}
	for(var prop in NewsContainer)
		document.getElementById(prop).innerHTML = getAbstract(NewsContainer[prop],250)+addShowTxtLink(prop);
}
function showNews(id){
	if(id){
		document.getElementById(id).innerHTML = addHideTxtLink(id)+NewsContainer[id];
		return false;
	}
	for(var prop in NewsContainer)
		document.getElementById(prop).innerHTML = NewsContainer[prop];
}
onload = function(){
	if( (location.search.indexOf("cmd=get")!=-1 && location.search.search(/id=\d+/g)!=-1) || !document.getElementById)
		return;
	var els = document.getElementsByTagName("p");
	for(var i=0;i<els.length;i++)
		if(els[i].id.search(/^news_\d+$/)!=-1)
			NewsContainer[els[i].id] = els[i].innerHTML;
	hideNews();
}

