helpstat = false;
stprompt = true;
basic = false;

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.f.GDescrizione.createTextRange && document.f.GDescrizione.caretPos) {
		var caretPos = document.f.GDescrizione.caretPos;
		caretPos.text = NewCode;
	} else {
		document.f.GDescrizione.value+=NewCode;
	}
	document.f.GDescrizione.focus();
}

function bold() {
	var text = getText();
	if (helpstat) {
		alert("Il Testo Diventa in Grassetto.\n\nUSE: [b]Testo in Grassetto[/b]");
	} else if (basic) {
		AddTxt="[b]" + text + "[/b]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo in Grassetto.",text);
		} else {
			txt=prompt("Testo in Grassetto.","Text");
		}
		if (txt!=null) {
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}
	}
}

function italicize() {
	var text = getText();
	if (helpstat) {
		alert("Il testo viene reso in Corsivo.\n\nUSE: [i]Testo in Corsivo[/i]");
	} else if (basic) {
		AddTxt="[i]" + text + "[/i]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo in Corsivo",text);
		} else {
			txt=prompt("Testo in Corsivo","Text");
		}
		if (txt!=null) {
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}
	}
}

function underline() {
	var text = getText();
  	if (helpstat) {
		alert("Sottolinea il Testo.\n\nUSE: [u]Il testo e' Sottolineato[/u]");
	} else if (basic) {
		AddTxt="[u]" + text + "[/u]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da Sottolineare.",text);
		} else {
			txt=prompt("Testo da Sottolineare.","Text");
		}
		if (txt!=null) {
			AddTxt="[u]"+txt+"[/u]";
			AddText(AddTxt);
		}
	}
}

function hr() {
	var text = getText();
	if (helpstat) {
		alert("Inserisce una Linea Orizzontale.\n\nUSE: [hr]");
	} else {
		AddTxt="[hr]" + text;
		AddText(AddTxt);
	}
}

function pallino() {
	var text = getText();
  	if (helpstat) {
		alert("Paragrafo del Testo con Puntino.\n\nUSE: [li]Testo Paragrafato[/li]");
	} else if (basic) {
		AddTxt="[li]" + text + "[/li]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da Paragrafare.",text);
		} else {
			txt=prompt("Testo da Paragrafare.","Text");
		}
		if (txt!=null) {
			AddTxt="[li]"+txt+"[/li]";
			AddText(AddTxt);
		}
	}
}

function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}

function getText() {
	if (document.f.GDescrizione.createTextRange && document.f.GDescrizione.caretPos) {
		return document.f.GDescrizione.caretPos.text;
	} else {
		return '';
	}
}

function validate(){
	if (document.f.Subject) {
		if (trim(document.f.Subject.value)=="") {
			alert("You must enter a Subject")
			return false
		}
	}
	if (document.f.GDescrizione) {
		if (trim(document.f.GDescrizione.value)=="") {
			alert("You must enter a GDescrizione")
			return false
		}
	}
	document.f.Submit.disabled = true
	return true
}

function ResetForm(form) {
	var where_to= confirm("Do you really want to Reset the Form Fields?");
	if (where_to== true) {
		form.reset();
	}
}

//code below found here:  http://www.marzie.com/devtools/javascript/functions.asp

function ltrim(s) {
	return s.replace( /^\s*/, "" );
}
function rtrim(s) {
	return s.replace( /\s*$/, "" );
}
function trim ( s ) {
	return rtrim(ltrim(s));
}
