//'***********************************************************************
//'** Copyright (C) 2001 - 2002 Max Yuan All Rights Reserved
//'**
//'** By using this program, you are agreeing to the terms of the
//'** GNU General Public License.
//'**
//'** 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 MaxWebPortal must remain intact
//'** in the scripts and in the outputted HTML.
//'** The "powered by" text/logo with a link back to 
//'** http://www.maxwebportal.com in the footer of the pages MUST
//'** remain visible when the pages are viewed on the internet or intranet.
//'**
//'** Support can be obtained from support forums at:
//'** http://www.maxwebportal.com
//'**
//'** Email: maxwebportal@hotmail.com
//'** ICQ: 148111300
//'***********************************************************************
helpstat = false;
stprompt = true;
basic = false;
text = ""

function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 2) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 0) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}


function getActiveText(selectedtext) { 
	text = (document.all) ? document.selection.createRange().text : document.getSelection();
		if (selectedtext.createTextRange) {	
   			selectedtext.caretPos = document.selection.createRange().duplicate();	
  		}
		return true;
}

function AddText(NewCode) {
if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
var caretPos = document.PostTopic.Message.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
}
else {
document.PostTopic.Message.value+=NewCode
}
setfocus();
}
function setfocus() {
document.PostTopic.Message.focus();
}


function email() {
	if (helpstat) {
		alert("Il Tag Email converte un indirizzo Email in un hyperlink mailto.\n\nUSO #1: [url]qualcuno\@daqualcheparte.com[/url] \nUSO #2: [url=\"qualcuno\@daqualcheparte.com\"]testo del link[/url]");
		}
	else if (basic) {
		AddTxt="[url]"+text+"[/url]";
		AddText(AddTxt);
		}
	else { 
		txt2=prompt("Testo da far apparire come link. Lascia vuoto se vuoi che appaia l'indirizzo.",""); 
		if (txt2!=null) {
			txt=prompt("URL per il link.","mailto:");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}
function showsize(size) {
	if (helpstat) {
		alert("Il Tag Size imposta la dimensione del testo. I valori possibili vanno da 1 a 6.\n1 essendo il più piccolo e 6 il più grande.\n\nUSO: [size="+size+"]Questa è testo a dimensione "+size+"[/size="+size+"]");
	} else if (basic) {
		AddTxt="[size="+size+"]"+text+"[/size="+size+"]";
		AddText(AddTxt);
	} else {                       
		txt=prompt("Testo che deve avere dimensione "+size,"Testo"); 
		if (txt!=null) {             
			AddTxt="[size="+size+"]"+txt+"[/size="+size+"]";
			AddText(AddTxt);
		}        
	}
}

function bold() {
	if (helpstat) {
		alert("Il tag Bold fa apparire il testo in grassetto.\n\nUSO: [b]Questo è un testo in grassetto[/b]");
	} else if (basic) {
		AddTxt="[b]"+text+"[/b]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo che deve essere reso in grassetto.","Testo");     
		if (txt!=null) {           
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}       
	}
}

function italicize() {
	if (helpstat) {
		alert("Il Tag Italicize rende il testo italico.\n\nUSO: [i]Questo è un test in italico[/i]");
	} else if (basic) {
		AddTxt="[i]"+text+"[/i]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Testo che deve essere reso in italico","Testo");     
		if (txt!=null) {           
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}	        
	}
}

function quote() {
	if (helpstat){
		alert("Il Tag Quote permette di evidenziare una citazione.\n\nUSO: [quote]Questa è una citazione[/quote]");
	} else if (basic) {
		AddTxt="[quote]"+text+"[/quote]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Testo che deve essere citato","Testo");     
		if(txt!=null) {          
			AddTxt="[quote]"+txt+"[/quote]";
			AddText(AddTxt);
		}	        
	}
}

function showcolor(color) {
	if (helpstat) {
		alert("Il Tag Color imposta il colore del testo. Tutti i colori con un nome possono essere utilizzati.\n\nUSO: ["+color+"]Questo è un "+color+" testo colorato[/"+color+"]");
	} else if (basic) {
		AddTxt="["+color+"]"+text+"[/"+color+"]";
		AddText(AddTxt);
	} else {  
     	txt=prompt("Text to be "+color,"Testo");
		if(txt!=null) {
			AddTxt="["+color+"]"+txt+"[/"+color+"]";
			AddText(AddTxt);        
		} 
	}
}

function center() {
 	if (helpstat) {
		alert("Il Tag Center centra il testo.\n\nUSO: [center]Questo testo è centrato[/center]");
	} else if (basic) {
		AddTxt="[center]"+text+"[/center]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da centrare","Testo");     
		if (txt!=null) {          
			AddTxt="[center]"+txt+"[/center]";
			AddText(AddTxt);
		}	       
	}
}

function hyperlink() {
	if (helpstat) {
		alert("Il Tag Hyperlink\nConverte un URL in un hyperlink.\n\nUSO: [url]http://www.qualcosa.com[/url]\n\nUSO: [url=http://www.qualcosa.com]testo del link[/url]");
	} else if (basic) {
		AddTxt="[url]"+text+"[/url]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("Testo da visualizzare per il link.\nLascia vuoto se vuoi l'URL come testo del 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 image() {
	if (helpstat){
		alert("Il Tag Image inserisce un immagine nel messaggio.\n\nUSO: [img]http://www.qualcosa.com/immagine.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() {
	if (helpstat) {
		alert("Il Tag Code rende il testo citato e preserva la formattazione.\nUtile per inviare porzioni di codice.\n\nUSO: [code]Questo è 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 list() {
	if (helpstat) {
		alert("Il Tag List costruisce liste puntate, numerate, alfabetiche.\n\nUSO: [list] [*]oggetto1[/*] [*]oggetto2[/*] [*]oggetto3[/*] [/list]");
	} else if (basic) {
		AddTxt="[list]"+text+"[*]  [/*]"+text+"[*]  [/*]"+text+"[*]  [/*]"+text+"[/list]";
		AddText(AddTxt);
	} else {  
		type=prompt("Tipo di lista: \'A\' per alfabetica, \'1\' per numerata, lascia vuoto per lista puntata.","");               
		while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
			type=prompt("ERRORE! Gli unici valori di scelta per liste sono 'A' e '1'.","");               
		}
		if (type!=null) {
			if (type=="") {
				AddTxt="[list]";
			} else {
				AddTxt="[list="+type+"]";
			} 
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("Inserisci un oggetto o lascia vuoto per terminare la lista",""); 
				if (txt!="") {             
					AddTxt+="[*]"+txt+"[/*]"; 
				}                   
			} 
			if (type=="") {
				AddTxt+="[/list] ";
			} else {
				AddTxt+="[/list="+type+"]";
			} 
			AddText(AddTxt); 
		}
	}
}

function underline() {
  	if (helpstat) {
		alert("Il Tag Underline sottolinea il testo.\n\nUSO: [u]Questo testo è sottolineato[/u]");
	} else if (basic) {
		AddTxt="[u]"+text+"[/u]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da sottolineare.","Testo");     
		if (txt!=null) {           
			AddTxt="[u]"+txt+"[/u]";
			AddText(AddTxt);
		}	        
	}
}

function showfont(font) {
 	if (helpstat){
		alert("Il Tag Font seleziona il carattere.\n\nUSO: [font="+font+"]Il carattere di questo testo è "+font+"[/font]");
	} else if (basic) {
		AddTxt="[font="+font+"]"+text+"[/font="+font+"]";
		AddText(AddTxt);
	} else {                  
		txt=prompt("Testo da visualizzare in "+font,"Testo");
		if (txt!=null) {             
			AddTxt="[font="+font+"]"+txt+"[/font="+font+"]";
			AddText(AddTxt);
		}        
	}  
}

function red() {
	if (helpstat) {
		alert("Il TAG Red rende il testo rosso.\n\nUSO: [red]Questo è un testo rosso[/red]");
	} else if (basic) {
		AddTxt="[red]"+text+"[/red]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere ROSSO.","Testo");     
		if (txt!=null) {           
			AddTxt="[red]"+txt+"[/red]";
			AddText(AddTxt);
		}       
	}
}

function blue() {
	if (helpstat) {
		alert("Il TAG Blue rende il testo blu.\n\nUSO: [blue]Questo è un testo blu[/blue]");
	} else if (basic) {
		AddTxt="[blue]"+text+"[/blue]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere BLU.","Testo");     
		if (txt!=null) {           
			AddTxt="[blue]"+txt+"[/blue]";
			AddText(AddTxt);
		}       
	}
}

function pink() {
	if (helpstat) {
		alert("Il TAG Pink rende il testo rosa.\n\nUSO: [pink]Questo è un testo rosa[/pink]");
	} else if (basic) {
		AddTxt="[pink]"+text+"[/pink]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere ROSA.","Testo");     
		if (txt!=null) {           
			AddTxt="[pink]"+txt+"[/pink]";
			AddText(AddTxt);
		}       
	}
}

function brown() {
	if (helpstat) {
		alert("Il TAG Brown rende il testo marrone.\n\nUSO: [brown]Questo è un testo marrone[/brown]");
	} else if (basic) {
		AddTxt="[brown]"+text+"[/brown]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere MARRONE.","Testo");     
		if (txt!=null) {           
			AddTxt="[brown]"+txt+"[/brown]";
			AddText(AddTxt);
		}       
	}
}

function black() {
	if (helpstat) {
		alert("Il TAG Black rende il testo nero.\n\nUSO: [black]Questo è un testo nero[/black]");
	} else if (basic) {
		AddTxt="[black]"+text+"[/black]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere NERO.","Testo");     
		if (txt!=null) {           
			AddTxt="[black]"+txt+"[/black]";
			AddText(AddTxt);
		}       
	}
}

function orange() {
	if (helpstat) {
		alert("Il TAG Orange rende il testo arancione.\n\nUSO: [orange]Questo è un testo arancione[/orange]");
	} else if (basic) {
		AddTxt="[orange]"+text+"[/orange]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere ARANCIONE.","Testo");     
		if (txt!=null) {           
			AddTxt="[orange]"+txt+"[/orange]";
			AddText(AddTxt);
		}       
	}
}

function violet() {
	if (helpstat) {
		alert("Il TAG Violet rende il testo violetto.\n\nUSO: [violet]Questo è un testo violetto[/violet]");
	} else if (basic) {
		AddTxt="[violet]"+text+"[/violet]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere VIOLETTO.","Testo");     
		if (txt!=null) {           
			AddTxt="[violet]"+txt+"[/violet]";
			AddText(AddTxt);
		}       
	}
}

function yellow() {
	if (helpstat) {
		alert("Il TAG Yellow rende il testo giallo.\n\nUSO: [yellow]Questo è un testo giallo[/yellow]");
	} else if (basic) {
		AddTxt="[yellow]"+text+"[/yellow]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere GIALLO.","Testo");     
		if (txt!=null) {           
			AddTxt="[yellow]"+txt+"[/yellow]";
			AddText(AddTxt);
		}       
	}
}

function green() {
	if (helpstat) {
		alert("Il TAG Green rende il testo verde.\n\nUSO: [green]Questo è un testo verde[/green]");
	} else if (basic) {
		AddTxt="[green]"+text+"[/green]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere VERDE.","Testo");     
		if (txt!=null) {           
			AddTxt="[green]"+txt+"[/green]";
			AddText(AddTxt);
		}       
	}
}

function gold() {
	if (helpstat) {
		alert("Il TAG Gold rende il testo oro.\n\nUSO: [gold]Questo è un testo oro[/gold]");
	} else if (basic) {
		AddTxt="[gold]"+text+"[/gold]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da reedere ORO.","Testo");     
		if (txt!=null) {           
			AddTxt="[gold]"+txt+"[/gold]";
			AddText(AddTxt);
		}       
	}
}

function white() {
	if (helpstat) {
		alert("Il TAG White rende il testo bianco.\n\nUSO: [white]Questo è un testo bianco[/white]");
	} else if (basic) {
		AddTxt="[white]"+text+"[/white]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere BIANCO.","Testo");     
		if (txt!=null) {           
			AddTxt="[white]"+txt+"[/white]";
			AddText(AddTxt);
		}       
	}
}

function purple() {
	if (helpstat) {
		alert("Il TAG Purple rende il testo viola.\n\nUSO: [purple]Questo è un testo viola[/purple]");
	} else if (basic) {
		AddTxt="[purple]"+text+"[/purple]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere VIOLA.","Testo");     
		if (txt!=null) {           
			AddTxt="[purple]"+txt+"[/purple]";
			AddText(AddTxt);
		}       
	}
}

function beige() {
	if (helpstat) {
		alert("Il TAG Beige rende il testo Beige.\n\nUSO: [beige]Questo è un testo beige[/beige]");
	} else if (basic) {
		AddTxt="[beige]"+text+"[/beige]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere BEIGE.","Testo");     
		if (txt!=null) {           
			AddTxt="[beige]"+txt+"[/beige]";
			AddText(AddTxt);
		}       
	}
}

function teal() {
	if (helpstat) {
		alert("Il TAG Teal rende il testo teal.\n\nUSO: [teal]Questo è un testo teal[/teal]");
	} else if (basic) {
		AddTxt="[teal]"+text+"[/teal]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere TEAL.","Testo");     
		if (txt!=null) {           
			AddTxt="[teal]"+txt+"[/teal]";
			AddText(AddTxt);
		}       
	}
}

function navy() {
	if (helpstat) {
		alert("Il TAG Navy rende il testo navy.\n\nUSO: [navy]Questo è un testo navy[/navy]");
	} else if (basic) {
		AddTxt="[navy]"+text+"[/navy]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere NAVY.","Testo");     
		if (txt!=null) {           
			AddTxt="[navy]"+txt+"[/navy]";
			AddText(AddTxt);
		}       
	}
}

function maroon() {
	if (helpstat) {
		alert("Il TAG Maroon rende il testo maroon.\n\nUSO: [maroon]Questo è un testo maroon[/maroon]");
	} else if (basic) {
		AddTxt="[maroon]"+text+"[/maroon]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere MAROON.","Testo");     
		if (txt!=null) {           
			AddTxt="[maroon]"+txt+"[/maroon]";
			AddText(AddTxt);
		}       
	}
}

function limegreen() {
	if (helpstat) {
		alert("Il TAG Limegreen rende il testo verde lime.\n\nUSO: [limegreen]Questo è un testo verde lime[/limegreen]");
	} else if (basic) {
		AddTxt="[limegreen]"+text+"[/limegreen]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere VERDE LIME.","Testo");     
		if (txt!=null) {           
			AddTxt="[limegreen]"+txt+"[/limegreen]";
			AddText(AddTxt);
		}       
	}
}

function strike() {
	if (helpstat) {
		alert("Il Tag strike rende il testo barrato.\n\nUSO: [s]Questo è un testo barrato[/]");
	} else if (basic) {
		AddTxt="[s]"+text+"[/s]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Testo da rendere barrato","Testo");     
		if (txt!=null) {           
			AddTxt="[s]"+txt+"[/s]";
			AddText(AddTxt);
		}	        
	}
}

function aleft() {
 	if (helpstat) {
		alert("Align left tag aligns the enclosed text left.\n\nUSO: [left]Questo è un testo allineato a sinistra[/left]");
	} else if (basic) {
		AddTxt="[left]"+text+"[/left]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da allineare a sinistra","Testo");     
		if (txt!=null) {          
			AddTxt="[left]"+txt+"[/left]";
			AddText(AddTxt);
		}	       
	}
}

function aright() {
 	if (helpstat) {
		alert("Align right tag aligns the enclosed text right.\n\nUSO: [right]Questo è un testo allineato a destra[/right]");
	} else if (basic) {
		AddTxt="[right]"+text+"[/right]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da allineare a destra","Testo");     
		if (txt!=null) {          
			AddTxt="[right]"+txt+"[/right]";
			AddText(AddTxt);
		}	       
	}
}

function pre() {
 	if (helpstat) {
		alert("Il Tag Pre ti permette di scrivere liberamente.\n\nUSO: [pre]Questo è un testo scritto liberamente[/pre]");
	} else if (basic) {
		AddTxt="[pre]"+text+"[/pre]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da renedere preformattato","Testo");     
		if (txt!=null) {          
			AddTxt="[pre]"+txt+"[/pre]";
			AddText(AddTxt);
		}	       
	}
}

function marquee() {
 	if (helpstat) {
		alert("Il Tag Marquee rende mobile il testo.\n\nUSO: [marquee]Questo è un testo che si muove[/marquee]");
	} else if (basic) {
		AddTxt="[marquee]"+text+"[/marquee]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da renedere mobile","Testo");     
		if (txt!=null) {          
			AddTxt="[marquee]"+txt+"[/marquee]";
			AddText(AddTxt);
		}	       
	}
}

function sup() {
 	if (helpstat) {
		alert("Il Tag Sup rende il testo apice.\n\nUSO: [sup]Questo è un apice[/sup]");
	} else if (basic) {
		AddTxt="[sup]"+text+"[/sup]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da renedere apice","Testo");     
		if (txt!=null) {          
			AddTxt="[sup]"+txt+"[/sup]";
			AddText(AddTxt);
		}	       
	}
}

function sub() {
 	if (helpstat) {
		alert("Il Tag Sub rende il testo pedice.\n\nUSO: [sub]questo è un pedice[/sub]");
	} else if (basic) {
		AddTxt="[sub]"+text+"[/sub]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere pedice","Testo");     
		if (txt!=null) {          
			AddTxt="[sub]"+txt+"[/sub]";
			AddText(AddTxt);
		}	       
	}
}

function tt() {
 	if (helpstat) {
		alert("Il Tag Teletype rende il testo come da telescrivente.\n\nUSO: [tt]Questo è un testo TeleType[/tt]");
	} else if (basic) {
		AddTxt="[tt]"+text+"[/tt]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da rendere TeleType","Testo");     
		if (txt!=null) {          
			AddTxt="[tt]"+txt+"[/tt]";
			AddText(AddTxt);
		}	       
	}
}





function hl() {
  	if (helpstat) {
		alert("Il Tag Highlight evidenzia in giallo il testo.\n\nUSO: [hl]Questo è un testo evidenziato[/hl]");
	} else if (basic) {
		AddTxt="[hl]"+text+"[/hl]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Testo da Evidenziare.","Testo");     
		if (txt!=null) {           
			AddTxt="[hl]"+txt+"[/hl]";
			AddText(AddTxt);
		}	        
	}
}


function hr() {
  	if (helpstat) {
		alert("Il Tag Horizontal Rule aggiunge una riga rizzontale.\n\nUSO: Horizontal Rule[hr]");
	} else if (basic) {
		AddTxt="[hr]";
		AddText(AddTxt);
	} else {  
		AddTxt="[hr]";
		AddText(AddTxt);
	}
}

function validate(){
	if (document.PostTopic.Subject) {
		if (trim(document.PostTopic.Subject.value)=="") {
			alert("Devi immettere un oggetto")
			return false
		}
	}
	if (document.PostTopic.Message) {
		if (trim(document.PostTopic.Message.value)=="") {
			alert("Devi immettere un messaggio")
			return false
		}
	}
	return true
}

function ltrim(s) {
	return s.replace( /^\s*/, "" );
}
function rtrim(s) {
	return s.replace( /\s*$/, "" );
}
function trim ( s ) {
	return rtrim(ltrim(s));
}
