//#################################################################################
//## Snitz Forums 2000 v3.4.05 - Versione italiana curata da SuperDeeJay.Net
//#################################################################################
//## Copyright (C) 2000-04 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 (at your option) 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 our support forums at:
//## http://forum.snitz.com
//##
//## Correspondence and Marketing Questions can be sent to:
//## manderson@snitz.com
//##
//#################################################################################

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(text) {
	var tarea = document.PostTopic.Message;
	if (tarea.selectionStart){ // if it supports DOM2
		tarea.value = tarea.value.substr(0,tarea.selectionStart)
			+ text + tarea.value.substr(tarea.selectionEnd);
		tarea.focus();
		tarea.selectionStart = tarea.selectionEnd + text.length;
		tarea.selectionEnd = tarea.selectionStart;
	} else {
		if (tarea.createTextRange && tarea.caretPos) {
			var caretPos = tarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?   text + ' ' : text;
		}
		else {
			tarea.value += text;
		}
		tarea.focus(caretPos);
	}
}*/

function AddText(text) {
	var tarea = document.PostTopic.Message;
	if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
		start = tarea.selectionStart;
		end = tarea.selectionEnd;
		tarea.value = tarea.value.substr(0,tarea.selectionStart)
			+ text + tarea.value.substr(tarea.selectionEnd);
		tarea.focus();
		tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
		tarea.selectionEnd = start + text.length;
	} else {
		if (tarea.createTextRange && tarea.caretPos) {
			var caretPos = tarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?   text + ' ' : text;
		}
		else {
			tarea.value += text;
		}
		tarea.focus(caretPos);
	}
}

function bold() {
	var text = getText();
	if (helpstat) {
		alert("Bold Tag rende il testo grassetto.\n\nUSO: [b]Questo teso è 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("Italicize Tag rende il testo corsivo.\n\nUSO: [i]Questo 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("Underline Tag Sottolinea il testo.\n\nUSO: [u]Questo testo è sottolineato[/u]");
	} else if (basic) {
		AddTxt="[u]" + text + "[/u]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo SOTTOLINEATO.",text);
		} else {
			txt=prompt("Testo SOTTOLINEATO.","Text");
		}
		if (txt!=null) {
			AddTxt="[u]"+txt+"[/u]";
			AddText(AddTxt);
		}
	}
}

function strike() {
	var text = getText();
	if (helpstat) {
		alert("Barrato Tag mette una linea sul testo.\n\nUSO: [s]Questo testo ha una linea[/s]");
	} else if (basic) {
		AddTxt="[s]" + text + "[/s]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo con una linea.",text);
		} else {
			txt=prompt("Testo con una linea.","Text");
		}
		if (txt!=null) {
			AddTxt="[s]"+txt+"[/s]";
			AddText(AddTxt);
		}
	}
}

function left() {
	var text = getText();
 	if (helpstat) {
		alert("Left tag allinea il testo a sinistra.\n\nUSO: [left]Questo testo è allineato a sinistra[/left]");
	} else if (basic) {
		AddTxt="[left]" + text + "[/left]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo che deve essere allineato a sinistra",text);
		} else {
			txt=prompt("Testo che deve essere allineato a sinistra","Text");
		}
		if (txt!=null) {
			AddTxt="[left]"+txt+"[/left]";
			AddText(AddTxt);
		}
	}
}

function center() {
	var text = getText();
 	if (helpstat) {
		alert("Centered tag Centra il testo.\n\nUSO: [center]Questo testo è centrato[/center]");
	} else if (basic) {
		AddTxt="[center]" + text + "[/center]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo che deve essere centrato",text);
		} else {
			txt=prompt("Testo che deve essere centrato","Text");
		}
		if (txt!=null) {
			AddTxt="[center]"+txt+"[/center]";
			AddText(AddTxt);
		}
	}
}

function right() {
	var text = getText();
 	if (helpstat) {
		alert("Right tag allinea il testo a destra.\n\nUSO: [right]Questo testo è allineato a destra[/right]");
	} else if (basic) {
		AddTxt="[right]" + text + "[/right]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo che deve essere allineato a destra",text);
		} else {
			txt=prompt("Testo che deve essere allineato 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("Hyperlink Tag \nConverte un URL in link.\n\nUSO: [url]http://www.anywhere.com[/url]\n\nUSA: [url=\"http://www.anywhere.com\"]Testo linkato[/url]");
	} else if (basic) {
		AddTxt="[url]" + text + "[/url]";
		AddText(AddTxt);
	} else { 
		if (text!=null) {
			txt2=text;
		} else {
			txt2=prompt("Testo che compare con il link.\nLascia bianco se vuoi che l'url sia mostrata come link.","");
		}
		if (txt2!=null) {
			txt=prompt("URL per il 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("E-mail Tag Converto un indirizzo e.mail in un link mailto.\n\nUSA #1: qualcuno\@ovunque.com \nUSA #2: [url=\"qualcuno\@ovunque.com\"]Testo linkato[/url]");
		}
	else {
		txt2=prompt("Testo mostrato per il link. Lascia bianco se vuoi che l'indirizzo e-mail sia visualizzato nel 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("Image Tag Inserisce una immaggine 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 dell'immaggine","http://");
		if(txt!=null) {
			AddTxt="[img]"+txt+"[/img]";
			AddText(AddTxt);
		}
	}
}

function showcode() {
	var text = getText();
	if (helpstat) {
		alert("Code Tag Blocca il testo da eventuali formattazioni.\nUtile per inserire codice.\n\nUSA: [code]Questo è testo formattato[/code]");
	} else if (basic) {
		AddTxt="[code]" + text + "[/code]";
		AddText(AddTxt);
	} else {
		txt=prompt("Inserisci Codice","");
		if (txt!=null) {
			AddTxt="[code]"+txt+"[/code]";
			AddText(AddTxt);
		}
	}
}

function quote() {
	var text = getText();
	if (helpstat){
		alert("Quote tag Cita il testo per riportare la frase postata da qualcuno.\n\nUSA: [quote]Questa è una citazione[/quote]");
	} else if (basic) {
		AddTxt=" [quote]" + text + "[/quote]";
		AddText(AddTxt);
	} else {
		if (text) {
			txt=prompt("Testo che deve essere citato",text);
		} else {
			txt=prompt("Testo che deve essere citato","Text");
		}
		if(txt!=null) {
			AddTxt=" [quote] "+txt+" [/quote]";
			AddText(AddTxt);
		}
	}
}

function list() {
	if (helpstat) {
		alert("List Tag Crea una lista puntata, numerata o alfabetica.\n\nUSA: [list] [*]Valore1[/*] [*]Valore2[/*] [*]Valore3[/*] [/list]");
	} else if (basic) {
		AddTxt=" [list][*]  [/*][*]  [/*][*]  [/*][/list]";
		AddText(AddTxt);
	} else {
		type=prompt("Tipo di lista. Digita \'A\' per alfabetica, \'1\' per numerata, lascia vuoto per puntata.","");
		while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
			type=prompt("ERRORE! I soli valori possibili per i tipi di lista sono vuoto 'A' e '1'.","");
		}
		if (type!=null) {
			if (type=="") {
				AddTxt="[list]";
			} else {
				AddTxt="[list="+type+"]";
			}
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("Lista dei valori. Lascia bianco 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("Font Tag Imposta il carattere per il testo.\n\nUSO: [font="+font+"]Il caratere di questo testo è "+font+"[/font]");
		} else if (basic) {
			AddTxt="[font="+font+"]" + text + "[/font="+font+"]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt("Testo in "+font,text);
			} else {
				txt=prompt("Testo 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("Size Tag Imposta la dimensione del testo. I valori possibili sono da 1 a 6.\n1 è il più piccolo e 6 il più grande.\n\nUSA: [size="+size+"]Questo testo ha dimensione "+size+"[/size="+size+"]");
		} else if (basic) {
			AddTxt="[size="+size+"]" + text + "[/size="+size+"]";
			AddText(AddTxt);
		} else {
			if (text) {
				txt=prompt("Testo di dimensione "+size,text);
			} else {
				txt=prompt("Testo 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("Color Tag Imposta il colore del testo. Si possono usare alcuni nomi di colore.\n\nUSA: ["+color+"]Questo testo è di color "+color+"[/"+color+"]");
		} else if (basic) {
			AddTxt="["+color+"]" + text + "[/"+color+"]";
			AddText(AddTxt);
		} else {
			if (text) {
		     		txt=prompt("Testo di colore "+color,text);
			} else {
	     			txt=prompt("Testo di colore "+color,"Text");
			}
			if(txt!=null) {
				AddTxt="["+color+"]"+txt+"[/"+color+"]";
				AddText(AddTxt);
			}
		}
	document.PostTopic.Color.selectedIndex = 0;
	}
}

function resizeTextarea(tmpCookieURL)
{
	var today = new Date();
	var expires = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus 365 days
	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;
	}
	document.cookie = tmpCookieURL + "strSelectSize=" + document.PostTopic.SelectSize.value + "; expires=" + expires.toUTCString()
}

function storeCaret(ftext) {
	if (ftext.createTextRange) {
		ftext.caretPos = document.selection.createRange().duplicate();
	}
}

function getText() {
	var tarea = document.PostTopic.Message;
	if (tarea.createTextRange && tarea.caretPos) {
		return tarea.caretPos.text;
	} else if (typeof tarea.selectionStart != 'undefined'){
		return tarea.value.substr(tarea.selectionStart,tarea.selectionEnd-tarea.selectionStart)
	}
	return '';
}

function OpenPreview()
{
	if (document.PostTopic.Message) {
		if (trim(document.PostTopic.Message.value)=="") {
			alert("Nessun testo da mostrare 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("Nessun contenuto da mostrare 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 l'Oggetto!")
			return false
		}
	}
	if (document.PostTopic.Message) {
		if (trim(document.PostTopic.Message.value)=="") {
			alert("Devi inserire il messaggio!")
			return false
		}
	}
	document.PostTopic.Submit.disabled = true
	return true
}

function ResetForm(form) {
	var where_to= confirm("Vuoi veramente cancellare il contenuto dei campi?");
	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));
}

