//variabili globali d'utilit? 
var RTB_rngMaster;
var RTB_keyDownFunc;
var RTB_callbackFunc;
var RTB_editor;
var RTB_currentDialog=null;
var previewMode = "off"; 
var RTB_rngObjMaster;
var RTB_object;




 
 



  


//attiva la modalit? preview 
function RTB_Preview()
{		
		//si attiva la previewMode 
		previewMode = "on"; 
		
		//si ottengono tutte la dialog dalla classe di appartenenza 
		var divs = getElementsByClass("dialog"); 
		// si chiudono tutte le dialog 
		for(i=0; i<divs.length; i++)
		{
			if(divs[i].id!="editorDialog")
				divs[i].style.display="none"; 
		}
		
		//si visualizza l'elemento per lo switching della preview 
		document.getElementById("previewSwitch").style.display = "block"; 
		//si elimina il bordo dall'editor di testo
		document.getElementById("richTextBox_ifr").style.border = "0px dashed #A9A9A9"; 
		//si nascondono le toolbar 
		document.getElementById("toolDrag").style.display = "none"; 
		document.getElementById("toolDragCaracter").style.display = "none"; 
		//si rende non editabile l'editor di testo 
		tinyMCE.activeEditor.getBody().contentEditable = "false";
		if(!document.all)
			tinyMCE.activeEditor.getDoc().designMode = "off";
		
}

//disattiva la modalit? preview 
function RTB_PreviewOff()
{	//si attiva la previewMode 
	previewMode = "off"; 
	
	//si ripristina il bordo dell'editor di testo 
	document.getElementById("richTextBox_ifr").style.border = "1px dashed #A9A9A9"; 
	//si visualizzano le toolbar 
	document.getElementById("toolDrag").style.display = "block"; 
	document.getElementById("toolDragCaracter").style.display = "block"; 
	// si rende editabile il contenuto dell'editor 
	tinyMCE.activeEditor.getBody().contentEditable = "true";
	if(!document.all)
		tinyMCE.activeEditor.getDoc().designMode = "on";
	//si nasconde l'elemento per lo switching della preview 
	document.getElementById("previewSwitch").style.display = "none"; 
}



//restituisce informazioni sulla selezione corrente 
function getInfoSelection()
{
  	ed = tinyMCE.activeEditor; 
	n = ed.selection.getNode(); 
  	return n.offsetTop + n.offsetHeight;  
}



//salva il contenuto dell'editor 
function save()
{
	try
		{  	
		//accents
		//htmlText = tinyMCE.activeEditor.getContent();
		
		if(!tinymce.isWebKit)
			htmlText = clearText(tinyMCE.activeEditor.getContent({format : 'html'}));
		else 
		{
			
			htmlText = clearText(tinyMCE.activeEditor.getContent({format : 'html'}));
		}
		//alert(tinyMCE.activeEditor.getContent({format : 'raw'})); 
		//alert(tinyMCE.activeEditor.getContent({format : 'html'})); 
		//se si utilizza il componente jsf 
		if (document.getElementById(selected + '.textarea') != null) {
			document.getElementById(selected + '.textarea').innerHTML = htmlText;	
			title = document.getElementById(selected).title;
			sendRequest(selected, selected);
		}
		else
		{
			title = 'Portfolio';
			sendAjaxRequest(selected, htmlText.replace(/&/g, "#AMP;" ), "ajax-upload" );
		}
		alert("modifiche salvate!");  
		
		document.getElementById("cronoDialog").style.display="block"; 
		 
		data = new Date();
		ora =data.getHours();
		minuti=data.getMinutes();
		secondi=data.getSeconds();
		giorno = data.getDay();
		mese = data.getMonth();
		date= data.getDate();
		year= data.getYear();
		
		if(minuti< 10)minuti="0"+minuti;
		if(secondi< 10)secondi="0"+secondi;
		if(year<1900)year=year+1900;
		if(ora<10)ora="0"+ora; 
		if(giorno == 0) giorno = " Domenica "; 
		if(giorno == 1) giorno = " Luned\? ";
		if(giorno == 2) giorno = " Marted\? "; 
		if(giorno == 3) giorno = " Mercoled\? "; 
		if(giorno == 4) giorno = " Gioved\? ";
		if(giorno == 5) giorno = " Venerd\? ";
		if(giorno == 6) giorno = " Sabato ";
		if(mese == 0) mese = "Gennaio ";
		if(mese ==1) mese = "Febbraio ";
		if(mese ==2) mese = "Marzo ";
		if(mese ==3) mese = "Aprile ";
		if(mese ==4) mese = "Maggio ";
		if(mese ==5) mese = "Giugno ";
		if(mese ==6) mese = "Luglio ";
		if(mese ==7) mese = "Agosto ";
		if(mese ==8) mese = "Settembre ";
		if(mese ==9) mese = "Ottobre ";
		if(mese ==10) mese = "Novembre ";
		if(mese ==11) mese = "Dicembre";
		
	
		 
		 today = new Date(); 
		 var actualBody = document.getElementById("cronoBody").innerHTML; 
		 var newRow = title 
		 			  + " -- " 
					  + " "+date+" "
					  + mese+" "
					  + year+" - "
					  + ora+":"
					  + minuti+":"
					  + secondi 
					  + "<br>" ;
															 
		 document.getElementById("cronoBody").innerHTML = 	clearText(newRow) + 
															actualBody; 
															
		 document.getElementById('crono.textarea').innerHTML = clearText(newRow) + 
		 												   clearText(document.getElementById('crono.textarea').innerHTML);
														   
		 
		 sendRequest("crono", "crono");
		  
		
		var docH = parseInt( $("cronoContent").offsetHeight);
		var scroller = $("cronoScroller");
		var scrollArea = $("cronoScrollArea");
		var container = $("cronoContainer");
		var content = $("cronoContent");
		
		if(!document.all)
			content.style.position="relative";
		
		initScroll(docH, scroller, scrollArea, container, content);
		
		
		var scroller = $("cronoStoryScroller");
		var scrollArea = $("cronoStoryScrollArea");
		var container = $("cronoStoryContainer");
		var content = $("cronoStoryContent");
		
		document.getElementById("cronoStoryBody").innerHTML = clearText(document.getElementById('crono.textarea').innerHTML); 
		
		
		var docH = parseInt( $("cronoStoryContent").offsetHeight);
		
		if(!document.all)
			content.style.position="relative";
		initScroll(docH, scroller, scrollArea, container, content);
		
		
		
		}
		catch(e)
		{
			alert(e.message);
	};
}


