helpstat = false;
stprompt = false;
basic = true;

function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}


function AddText(NewCode) {
	if (document.formEditor.testo.createTextRange && document.formEditor.testo.caretPos) {
		var caretPos = document.formEditor.testo.caretPos;
		caretPos.text = NewCode;
	} else {
		document.formEditor.testo.value+=NewCode;
	}
	document.formEditor.testo.focus();
}

function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}


function getText() {
	if (document.formEditor.testo.createTextRange && document.formEditor.testo.caretPos) {
		return document.formEditor.testo.caretPos.text;
	} else {
		return '';
	}
}


function bold() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Bold cambia il testo in grassetto.\n\nUSO: <b>Questo testo č in grassetto</b>");
	} else if (basic) {
		AddTxt="<b>" + text + "</b>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā formattato in GRASSETTO.",text);
		} else {
			txt=prompt("Il testo sarā formattato in GRASSETTO.","Text");
		}
		if (txt!=null) {
			AddTxt="<b>"+txt+"</b>";
			AddText(AddTxt);
		}
	}
}

function italicize() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Italicize cambia il testo in corsivo.\n\nUSO: <i>Questo testo č in corsivo</i>");
	} else if (basic) {
		AddTxt="<i>" + text + "</i>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā formattato in corsivo",text);
		} else {
			txt=prompt("Il testo sarā formattato in corsivo","Text");
		}
		if (txt!=null) {
			AddTxt="<i>"+txt+"</i>";
			AddText(AddTxt);
		}
	}
}

function underline() {
	var text = getText();
  	if (helpstat) {
		alert("Il Tag Underline cambia il testo in sottolineato.\n\nUSO: <u>Questo testo č sottolineato</u>");
	} else if (basic) {
		AddTxt="<u>" + text + "</u>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā formattato in sottolineato.",text);
		} else {
			txt=prompt("Il testo sarā formattato in sottolineato.","Text");
		}
		if (txt!=null) {
			AddTxt="<u>"+txt+"</u>";
			AddText(AddTxt);
		}
	}
}

function strike() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Strike-Through cambia il testo in barrato.\n\nUSO: <s>Questo testo č barrato</s>");
	} else if (basic) {
		AddTxt="<s>" + text + "</s>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā formattato in barrato.",text);
		} else {
			txt=prompt("Il testo sarā formattato in barrato.","Text");
		}
		if (txt!=null) {
			AddTxt="<s>"+txt+"</s>";
			AddText(AddTxt);
		}
	}
}


function left() {
	var text = getText();
 	if (helpstat) {
		alert("Il Tag Left allinea il testo a Sinistra.\n\nUSO: <div align=left>Questo testo č allineato a Sinistra</div>");
	} else if (basic) {
		AddTxt="<div align=left>" + text + "</div>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā allineato a Sinistra",text);
		} else {
			txt=prompt("Il testo sarā allineato a Sinistra","Text");
		}
		if (txt!=null) {
			AddTxt="<div align=left>"+txt+"</div>";
			AddText(AddTxt);
		}
	}
}

function center() {
	var text = getText();
 	if (helpstat) {
		alert("Il Tag Centered allinea il testo al Centro.\n\nUSO: <div align=center>Questo testo č allineato al Centro</div>");
	} else if (basic) {
		AddTxt="<div align=center>" + text + "</div>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā allineato al Centro",text);
		} else {
			txt=prompt("Il testo sarā allineato al Centro","Text");
		}
		if (txt!=null) {
			AddTxt="<div align=center>"+txt+"</div>";
			AddText(AddTxt);
		}
	}
}


function right() {
	var text = getText();
 	if (helpstat) {
		alert("Il Tag Right allinea il testo a Destra.\n\nUSO: <div align=right>Questo testo č allineato a Destra</div>");
	} else if (basic) {
		AddTxt="<div align=right>" + text + "</div>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā allineato a Destra",text);
		} else {
			txt=prompt("Il testo sarā allineato a Destra","Text");
		}
		if (txt!=null) {
			AddTxt="<div align=right>"+txt+"</div>";
			AddText(AddTxt);
		}
	}
}


function justify() {
	var text = getText();
 	if (helpstat) {
		alert("Il Tag Justify giusitifica il testo.\n\nUSO: <div align=justify>Questo testo č giusitificato</div>");
	} else if (basic) {
		AddTxt="<div align=justify>" + text + "</div>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo sarā giustificato",text);
		} else {
			txt=prompt("Il testo sarā giustificato","Text");
		}
		if (txt!=null) {
			AddTxt="<div align=justify>"+txt+"</div>";
			AddText(AddTxt);
		}
	}
}


function rientroSx() {
	var text = getText();
 	if (helpstat) {
		alert("Rientro del testo a sinistra.\n\nUSO: <p>Questo testo č rientrato a sinistra</p>");
	} else if (basic) {
		AddTxt="<p>" + text + "</p>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo verrā orientato a sinistra",text);
		} else {
			txt=prompt("Il testo verrā orientato a sinistra","Text");
		}
		if (txt!=null) {
			AddTxt="<p>"+txt+"</p>";
			AddText(AddTxt);
		}
	}
}


function rientroDx() {
	var text = getText();
 	if (helpstat) {
		alert("Rientro del testo a destra.\n\nUSO: <blockquote>Questo testo č rientrato a destra</blockquote>");
	} else if (basic) {
		AddTxt="<blockquote>" + text + "</blockquote>";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Il testo verrā orientato a destra",text);
		} else {
			txt=prompt("Il testo verrā orientato a destra","Text");
		}
		if (txt!=null) {
			AddTxt="<blockquote>"+txt+"</blockquote>";
			AddText(AddTxt);
		}
	}
}


function hr() {
	var text = getText();
	if (helpstat) {
		alert("Inserisci una riga orizzontale.\n\nUSO: <hr>");
	} else {
		AddTxt="<hr>" + text;
		AddText(AddTxt);
	}
}