//#################################################################################
//## Copyright (C) 2000-02 Michael Anderson, Pierre Gorissen,
//##                       Huw Reddick and Richard Kinser
//##
//## This program is free software; you can redistribute it and/or
//## modify it under the terms of the GNU General Public License
//## as published by the Free Software Foundation; either version 2
//## of the License, or any later version.
//##
//## All copyright notices regarding Snitz Forums 2000
//## must remain intact in the scripts and in the outputted HTML
//## The "powered by" text/logo with a link back to
//## http://forum.snitz.com in the footer of the pages MUST
//## remain visible when the pages are viewed on the internet or intranet.
//##
//## This program is distributed in the hope that it will be useful,
//## but WITHOUT ANY WARRANTY; without even the implied warranty of
//## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//## GNU General Public License for more details.
//##
//## You should have received a copy of the GNU General Public License
//## along with this program; if not, write to the Free Software
//## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//##
//## Support can be obtained from support forums at:
//## http://forum.snitz.com
//##
//## Correspondence and Marketing Questions can be sent to:
//## reinhold@bigfoot.com
//##
//## or
//##
//## Snitz Communications
//## C/O: Michael Anderson
//## PO Box 200
//## Harpswell, ME 04079
//#################################################################################

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) {
//	document.PostTopic.Message.value+=NewCode
//}

function AddText(NewCode) {
	if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
		var caretPos = document.PostTopic.Message.caretPos;
		caretPos.text = NewCode;
	} else {
		document.PostTopic.Message.value+=NewCode;
	}
	document.PostTopic.Message.focus();
}

function bold() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Bold scrive in grassetto il testo incluso.\n\nUSO: [b]Questo e' un testo in grassetto[/b]");
	} else if (basic) {
		AddTxt="[b]" + text + "[/b]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da scrivere in grassetto.",text);
		} else {
			txt=prompt("Testo da scrivere in grassetto.","Text");
		}
		if (txt!=null) {
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}
	}
}

function italicize() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Italicize scrive in italico il testo incluso.\n\nUS0: [i]Questo e' un testo in italico[/i]");
	} else if (basic) {
		AddTxt="[i]" + text + "[/i]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da scrivere in italico",text);
		} else {
			txt=prompt("Testo da scrivere in italico","Text");
		}
		if (txt!=null) {
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}
	}
}

function underline() {
	var text = getText();
  	if (helpstat) {
		alert("Il Tag Underline sottilinea il testo incluso. \n\nUS0: [u]Questo e' un testo 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 strike() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Strike-Through scrive sbarrato il testo incluso.\n\nUSO: [s]Questo testo e' sbarrato[/s]");
	} else if (basic) {
		AddTxt="[s]" + text + "[/s]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da sbarrare.",text);
		} else {
			txt=prompt("Testo da sbarrare.","Text");
		}
		if (txt!=null) {
			AddTxt="[s]"+txt+"[/s]";
			AddText(AddTxt);
		}
	}
}

function left() {
	var text = getText();
 	if (helpstat) {
		alert("Il Tag Left  allinea a sinistra il testo incluso.\n\nUSO: [left]Questo testo e' allineato a sinistra[/left]");
	} else if (basic) {
		AddTxt="[left]" + text + "[/left]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da allineare a sinistra",text);
		} else {
			txt=prompt("Testo da allineare a sinistra","Text");
		}
		if (txt!=null) {
			AddTxt="[left]"+txt+"[/left]";
			AddText(AddTxt);
		}
	}
}

function center() {
	var text = getText();
 	if (helpstat) {
		alert("Il Tag Centered centra il testo incluso.\n\nUSO: [center]Questo testo e' centrato[/center]");
	} else if (basic) {
		AddTxt="[center]" + text + "[/center]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da centrare",text);
		} else {
			txt=prompt("Testo da centrare","Text");
		}
		if (txt!=null) {
			AddTxt="[center]"+txt+"[/center]";
			AddText(AddTxt);
		}
	}
}

function right() {
	var text = getText();
 	if (helpstat) {
		alert("Il Tag Right allinea a destra il testo incluso.\n\nUSO: [right]Questo testo e' allineato a destra[/right]");
	} else if (basic) {
		AddTxt="[right]" + text + "[/right]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo da allineare a destra",text);
		} else {
			txt=prompt("Testo da allineare a destra","Text");
		}
		if (txt!=null) {
			AddTxt="[right]"+txt+"[/right]";
			AddText(AddTxt);
		}
	}
}

function hr() {
	var text = getText();
	if (helpstat) {
		alert("Horizontal Rule crea una linea orizzontale nel messaggio.\n\nUSO: [hr]");
	} else {
		AddTxt="[hr]" + text;
		AddText(AddTxt);
	}
}

function hyperlink() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Hyperlink \nconverte un url in un hyperlink.\n\nUSO: [url]http://www.anywhere.com[/url]\n\nUSO: [url=http://www.anywhere.com]testo di link[/url]");
	} else if (basic) {
		AddTxt="[url]" + text + "[/url]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("Testo da mostrare per il link. Lascia blank se desideri che l'url appaia come link.","");
		if (txt2!=null) {
			txt=prompt("URL for the link.","http://");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}
			}
		}
	}
}

function email() {
	if (helpstat) {
		alert("Il Tag E-mail converte un indirizzo e-mail in un hyperlink a mailto.\n\nUSO #1: someone\@anywhere.com \nUSO #2: [url=\"someone\@anywhere.com\"]testo di link[/url]");
		}
	else {
		txt2=prompt("Testo da mostrare per il link. Lascia blank se desideri che l'indirizzo e-mail appaia come link.","");
		if (txt2!=null) {
			txt=prompt("URL per il link.","mailto:");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt=txt;
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}
			}
		}
	}
}

function image() {
	var text = getText();
	if (helpstat){
		alert("Il Tag Image inserisce un'immagine nel messaggio.\n\nUSO: [img]http://www.anywhere.com/image.gif[/img]");
	} else if (basic) {
		AddTxt="[img]" + text + "[/img]";
		AddText(AddTxt);
	} else {
		txt=prompt("URL per l'immagine","http://");
		if(txt!=null) {
			AddTxt="[img]"+txt+"[/img]";
			AddText(AddTxt);
		}
	}
}

function showcode() {
	var text = getText();
	if (helpstat) {
		alert("Il Tag Code preserva la formattazione del testo incluso.\nUtile per spedire codice.\n\nUSO: [code]questo e' un testo formattato[/code]");
	} else if (basic) {
		AddTxt="[code]" + text + "[/code]";
		AddText(AddTxt);
	} else {
		txt=prompt("Inserisci il codice","");
		if (txt!=null) {
			AddTxt="[code]"+txt+"[/code]";
			AddText(AddTxt);
		}
	}
}

function quote() {
	var text = getText();
	if (helpstat){
		alert("Il Tag Quote quote il testo incluso riferito a qualcosa di specifico che qualcuno ha scritto.\n\nUSO: [quote]Questo e' un quote[/quote]");
	} else if (basic) {
		AddTxt=" [quote]" + text + "[/quote]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo che deve essere scritto quotato",text);
		} else {
			txt=prompt("Testo che deve essere scritto quotato","Text");
		}
		if(txt!=null) {
			AddTxt=" [quote] "+txt+" [/quote]";
			AddText(AddTxt);
		}
	}
}

function list() {
	if (helpstat) {
		alert("Il Tag List costruisce una lista per punti, numeri o lettere.\n\nUSO: [list] [*]item1[/*] [*]item2[/*] [*]item3[/*] [/list]");
	} else if (basic) {
		AddTxt=" [list][*]  [/*][*]  [/*][*]  [/*][/list]";
		AddText(AddTxt);
	} else {
		type=prompt("Tipi di enumerazione della lista \'A\' per quella alfabetica, \'1\' per quella numerica, blank per qualla grafica.","");
		while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
			type=prompt("ERRORE! I soli valori possibili per il tipo lista sono blank 'A' e '1'.","");
		}
		if (type!=null) {
			if (type=="") {
				AddTxt="[list]";
			} else {
				AddTxt="[list="+type+"]";
			}
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("List item lasciato blank per terminare la lista","");
				if (txt!="") {
					AddTxt+="[*]"+txt+"[/*]";
				}
			}
			if (type=="") {
				AddTxt+="[/list] ";
			} else {
				AddTxt+="[/list="+type+"]";
			}
			AddText(AddTxt);
		}
	}
}

function showfont(font) {
	var text = getText();
 	if (font) {
	 	if (helpstat) {
			alert("Il Tag Font stabilisce l'aspetto del testo incluso.\n\nUS): [font="+font+"]Il font di questo testo e' "+font+"[/font]");
		} else if (basic) {
			AddTxt="[font="+font+"]" + text + "[/font="+font+"]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt("Testo che deve essere scritto in "+font,text);
			} else {
				txt=prompt("Testo che deve essere scritto in "+font,"Text");
			}
			if (txt!=null) {
				AddTxt="[font="+font+"]"+txt+"[/font="+font+"]";
				AddText(AddTxt);
			}
		}
	document.PostTopic.Font.selectedIndex = 0;
	}
}

function showsize(size) {
	var text = getText();
	if (size) {
		if (helpstat) {
			alert("Il  Tag Size stabilisce la dimensione del testo. I valori possibili vanno da 1 a 6.\ndove il piu' piccolo e' 1 ed il piu' grande e' 6.\n\nUSO: [size="+size+"]Queste e' un testo di dimensione "+size+"[/size="+size+"]");
		} else if (basic) {
			AddTxt="[size="+size+"]" + text + "[/size="+size+"]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt("Testo che deve essere di dimensione "+size,text);
			} else {
				txt=prompt("Testo che deve essere di dimensione "+size,"Text");
			}
			if (txt!=null) {
				AddTxt="[size="+size+"]"+txt+"[/size="+size+"]";
				AddText(AddTxt);
			}
		}
	document.PostTopic.Size.selectedIndex = 0;
	}
}

function showcolor(color) {
	var text = getText();
	if (color) {
		if (helpstat) {
			alert("Il Tag Color stabilisce il colore del testo. Ogni nome di colore &egrave; valido.\n\nUSO: ["+color+"]Questo e' del testo color "+color+"[/"+color+"]");
		} else if (basic) {
			AddTxt="["+color+"]" + text + "[/"+color+"]";
			AddText(AddTxt);
		} else {
			if (text) {
		     		txt=prompt("Testo che deve essere scritto in "+color,text);
			} else {
	     			txt=prompt("Testo che deve essere scritto in "+color,"Text");
			}
			if(txt!=null) {
				AddTxt="["+color+"]"+txt+"[/"+color+"]";
				AddText(AddTxt);
			}
		}
	document.PostTopic.Color.selectedIndex = 0;
	}
}

function resizeTextarea()
{
	if (document.PostTopic.SelectSize.value == 1)
	{
		document.PostTopic.Message.cols = 45;
		document.PostTopic.Message.rows = 11;
	}
	if (document.PostTopic.SelectSize.value == 2)
	{
		document.PostTopic.Message.cols = 70;
		document.PostTopic.Message.rows = 12;
	}
	if (document.PostTopic.SelectSize.value == 3)
	{
		document.PostTopic.Message.cols = 90;
		document.PostTopic.Message.rows = 12;
	}
	if (document.PostTopic.SelectSize.value == 4)
	{
		document.PostTopic.Message.cols = 130;
		document.PostTopic.Message.rows = 15;
	}
}

function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}

function getText() {
	if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
		return document.PostTopic.Message.caretPos.text;
	} else {
		return '';
	}
}

function OpenPreview()
{
	if (document.PostTopic.Message) {
		if (trim(document.PostTopic.Message.value)=="") {
			alert("Niente da visualizzare in anteprima!")
			return false
		}
		popupWin = window.open('pop_preview.asp', 'preview_page', 'scrollbars=yes,width=750,height=450')	
		return true
	}
}

function OpenSigPreview()
{
	if (document.Form1.Sig) {
		if (trim(document.Form1.Sig.value)=="") {
			alert("Niente da visualizzare in anteprima!")
			return false
		}
		popupWin = window.open('pop_preview_sig.asp', 'preview_page', 'scrollbars=yes,width=750,height=450')	
		return true
	}
}

function validate(){
	if (document.PostTopic.Subject) {
		if (trim(document.PostTopic.Subject.value)=="") {
			alert("Devi inserire un Soggetto")
			return false
		}
	}
	if (document.PostTopic.Message) {
		if (trim(document.PostTopic.Message.value)=="") {
			alert("Devi inserire un Messaggio")
			return false
		}
	}
	return true
}

function ResetForm(form) {
	var where_to= confirm("Vuoi davvero cancellare i campi della Form?");
	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));
}

