away = 'no';
if (document.images) {
	away_1 = new Image
	away_2 = new Image
	away_1.src = 'setaway.gif'
	away_2.src = 'setback.gif'
}
function setmsg (type) {
	msg = prompt("Inserisci il messaggio di "+ type +" :", "");
	if (msg != null) { return msg; }
	else { return false; }
}
function jpilot(type,action) {
	if (type == 'serv1') { document.jchat.processJInput('/server irc.azzurra.org '); }
	if (type == 'whois') { document.jchat.processJInput('/whois %$HN '); }
	if (type == 'memoserv') {
		if (action == 'send') {
			to = prompt('Invia MEMO a: ','');
			if (to != null) {
				msg = prompt('Scrivi MEMO: '+to+' ?','');
				if (msg != null) {
	
				 		document.jchat.processJInput('/msg memoserv send '+to +' '+msg ); 
				}
			
			}
		}
		if (action == 'cancel') {
			to = prompt('Cancellare il Memo? ','');
			if (to != null) {
		 		document.jchat.processJInput('/msg memoserv cancel '+to ); 		
			}
		}
		if (action == 'list') { document.jchat.processJInput('/msg memoserv list'); }
		if (action == 'readlast') { document.jchat.processJInput('/msg memoserv read last'); }
		if (action == 'read') {
			num = prompt('Leggi i Memo','1');
			if (num != null) {
		 		document.jchat.processJInput('/msg memoserv read '+num ); 		
			}
		}
		if (action == 'delete') {
			num = prompt('Cancella i Memo','1');
			if (num != null) {
		 		document.jchat.processJInput('/msg memoserv del '+num ); 		
			}
		}
		if (action == 'delall') {
			doit = confirm('Cancellare tutti i Memo, confermi? ');
			if (doit != false) {
		 		document.jchat.processJInput('/msg memoserv del all'); 		
			}
		}
		if (action == 'setnotify') {
			when = prompt(' Avvisi di nuovi Memo \n Opzioni: ON | LOGON | NEW | OFF','ON');
			if (when != null) {
		 		document.jchat.processJInput('/msg memoserv set notify '+when ); 		
			}
		}
		if (action == 'setlimit') {
			max = prompt('Numero MAX di memo? max 20','20');
			if (max != null) {
				if (max <= '20') {
			 		document.jchat.processJInput('/msg memoserv set limit '+max ); 		
				}
				else { alert('Scegli fino a un max di 20'); }
			}
		}

	}
	
	if (type == 'join') { 
		if (document.jform.channels.indexOf != '0') {
			if (document.jform.channels.options[document.jform.channels.selectedIndex].value != 'Chan') {
			document.jchat.processJInput('/join '+ document.jform.channels.options[document.jform.channels.selectedIndex].value);
			return true;
			}
			else {
				chan = prompt('Inserisci il canale','#0721');
				if (chan != null) {
					if (chan.indexOf('#') != -1 ) { chan = '/join '+chan; }
						else { chan = '/join #'+chan; }
				 		document.jchat.processJInput(chan); 
				 }
			}
		}
		document.jform.channels.selectedIndex = 0;
	}
		if (type == 'me') { 
			if (document.jform.actions.selectedIndex != '0') {
				if (document.jform.actions.options[document.jform.actions.selectedIndex].value != 'others') {
					document.jchat.processJInput('/me '+ document.jform.actions.options[document.jform.actions.selectedIndex].value)
				}
			else {
				action = prompt('Azione','Azione');
				if (action != null) {
					action = '/me '+action;
				 	document.jchat.processJInput(action); 
				 }
			}
		}
		document.jform.actions.selectedIndex = 0;
	}
	if (type == 'limit') {
				action = prompt('Inserire limite: (se campo vuoto = non attivo)','');
				if (action != null) {
					if (action != '') {
						action = '/mode #%$C +l '+action;
				 		document.jchat.processJInput(action); 
				 	}
				 	else { document.jchat.processJInput('/mode #%$C -l')  }
				}
			}
	if (type == 'invite') {
			nick = prompt('Invita il Nick in canale:','');
			if (nick != null) {
				if (nick != '') {
		 			document.jchat.processJInput('/invite '+nick +' #%$C '); 
				}
			}
	}

	if (type == 'opmode') {
		document.jchat.processJInput('/cs op #0721 '+ action +' %$HN ');
	}
	if (type == 'cmode') {
		document.jchat.processJInput('/mode #%$C '+ action );
	}
	
	if (type == 'kick') {
		if (action == 'fast') { kickmsg = 'Kick'; }
			else { kickmsg = setmsg('kick'); }
			document.jchat.processJInput('/kick #0721 %$HN '+ kickmsg);
	}
	if (type == 'kickban') {
		kickmsg = setmsg('KickBan');
		if (kickmsg != false) {
			document.jchat.processJInput('/mode #0721 +b %$HN ');
			document.jchat.processJInput('/kick #0721 %$HN '+ kickmsg);
		}
	}
	if (type == 'away') {
		if (away == 'yes') { action = 'back' }
		if (away == 'no') { action = 'away' }
		if (action == 'away') {
			awaymsg = setmsg('away');
			if (awaymsg != false) {
				document.jchat.processJInput('/away ' + awaymsg);
				document.jchat.processJInput('/me č assente \('+awaymsg+'\).');
				away = 'yes';
				document.away.src=away_2.src
			}
		}
			else {
				document.jchat.processJInput('/away');
				document.jchat.processJInput('/me č tornato \('+awaymsg+'\).');
				away = 'no';
				document.away.src=away_1.src
			}
		}
	if (type == 'nickserv') {
		if (action == 'register') {
			nickpass = prompt('Inserire la TUA PASSWORD:','');
			if (nickpass != null) {
				document.jchat.processJInput('/ns register '+ nickpass);
			}
		}
		if (action == 'identify') {
			nickpass = prompt('/NS IDENTIFY: inserire tua password','');
			document.jchat.processJInput('/msg nickserv identify '+ nickpass);
		}
		if  (action == 'ghost') {
			nickpass = prompt('Eliminare GHOST (cioč il tuo Nick rimasto dopo una disconnessione involontaria): inserire la tua password','');
			if (nickpass != null) {
				nick = prompt('inserire il NICK da disconnettere','');
					if (nick != null) {
						document.jchat.processJInput('/msg nickserv ghost '+ nick +' ' +nickpass);
					}
			}
		}
			
		if  (action == 'setkill') {
			kill = prompt('Set kill on/off','on');
			if (kill != null) {
				document.jchat.processJInput('/msg nickserv set kill '+ kill );
			}
		}
		if  (action == 'setsecure') {
			kill = prompt('Set secure on/off','on');
			if (kill != null) {
				document.jchat.processJInput('/msg nickserv set secure '+ kill );
			}
		}				
		if  (action == 'setpassword') {
			newpass = prompt ('Inserire la NUOVA PASSWORD','');
				if (newpass != null) {
					document.jchat.processJInput('/msg nickserv set password '+ newpass );
				}
			}
		}
	

}