 
var bHtmlMode = false;
var str_iFrameDoc = (document.all)? "document.frames(\"Composition\").document\;": "document.getElementById(\"Composition\").contentDocument\;";
var testo;		
// Inizializzazione
//onload = initialize;
function initialize() {

iFrameDoc = eval(str_iFrameDoc);

var kids = document.getElementsByTagName('DIV');

  for (var i=0; i < kids.length; i++) {
    if (kids[i].className == "imagebutton") {
       kids[i].onclick = formatC;
    }
	}	
iFrameDoc.designMode = "On";


	if (!document.all) {
	    document.getElementById("cut").style.visibility = "hidden";
	    document.getElementById("copy").style.visibility = "hidden";
	    document.getElementById("paste").style.visibility = "hidden";
	}	 

 	setFocus();		

}

// Porta il focus al riquadro di testo
function setFocus() {
if (document.all)	
	document.frames("Composition").focus();	
	else
	document.getElementById('Composition').contentWindow.focus()
return;
}

// Controlla se la toolbar è abilitata nella modalità testo
function validateMode() {
	if (! bHtmlMode)
		return true;
	alert("Deselezionare \"Visualizza HTML\" per utilizzare le barre degli strumenti");
	
	setFocus();
	return false;
}

// Formatta il testo
function formatC(what,opt) {
	if (!validateMode())
		return; 

 iFrameDoc = eval(str_iFrameDoc);
 if (this.id != 'createLink') {
		iFrameDoc.execCommand(this.id,false,opt);
 }else{

 var szURL = prompt("Digita un url:", "http://");
 iFrameDoc.execCommand(this.id,false,szURL);
 }
	setFocus();
}

//Scambia tra la modalità testo e la modalità HTML.
function setMode(newMode) {
	var testo;
	
	bHtmlMode = newMode;
	
	iFrameDoc = eval(str_iFrameDoc);
	riquadro = iFrameDoc.body;
	
	if (document.all) {
		if (bHtmlMode) {
			testo = riquadro.innerHTML;
			riquadro.innerText = testo; 
		} else {
			testo = riquadro.innerText;
			riquadro.innerHTML = testo;
		}
		
	} else if(document.getElementById && document.createTextNode) {
		if (bHtmlMode) {
			testo = document.createTextNode(riquadro.innerHTML);
			riquadro.innerHTML = "";
			riquadro.appendChild(testo);
		} else {
			testo = document.createRange();
			testo.selectNodeContents(riquadro);
			riquadro.innerHTML = testo.toString();
		}	
	}

	setFocus();
}		
function SetInvia(){
		 iFrameDoc = eval(str_iFrameDoc);
		 riquadro  = iFrameDoc.body;
		 testoHtml = riquadro.innerHTML;
		 document.forms[0].html.value = testoHtml;
	   document.forms[0].action='submitQ.asp'//?html='+testoHtml
		 document.forms[0].submit();
}				
function replaceWithBr(){
 	
var text = document.forms[0].html.value;
var obj = document.forms[0].obj.value;
if(text != '' && obj != ''){
document.forms[0].html.value = text.replace(/\n/g,'<br />');return true
}else {alert("Tutti i campi sono obbligatori.");return false}	
}