/* WT-Frontend v1.2 by Martin Nielsen http://jirc.webt.dk
No need to change anything in this file
*/

away = 'no';
if (document.images) {
	away_1 = new Image
	away_2 = new Image
	away_1.src = 'img/setaway.gif'
	away_2.src = 'img/setback.gif'
}
function setmsg (type) {
	msg = prompt("Tasteaza mesajul de "+ type +" :", "");
	if (msg != null) { return msg; }
	else { return false; }
}
function jpilot(type,action) {
	if (type == 'sclear') { document.PJirc.sendString('/clear '); }
	if (type == 'time') { document.PJirc.sendString('/time ');applet.requestSourceFocus(); }
	if (type == 'version') { document.PJirc.sendString('/ctcp %$HN version');applet.requestSourceFocus(); }
	if (type == 'whois') { document.PJirc.sendString('/whois %$HN ');applet.requestSourceFocus(); }
	if (type == 'ping') { document.PJirc.sendString('/ping ctcp %$HN');applet.requestSourceFocus(); }
	if (type == 'memoserv') {
		if (action == 'send') {
			to = prompt('Care e destinatarul?','');
			if (to != null) {
				msg = prompt(' mesajul tau '+catre +' ?','');
				if (msg != null) {
	
				 		document.PJirc.sendString('/msg memoserv send '+to +' '+msg );PJirc.requestSourceFocus(); 
				}
			
			}
		}
		if (action == 'cancel') {
			to = prompt('Anulati MEMO?','');
			if (to != null) {
		 		document.PJirc.sendString('/msg memoserv cancel '+to );PJirc.requestSourceFocus(); 		
			}
		}
		if (action == 'list') { document.PJirc.sendString('/msg memoserv list'); }
		if (action == 'readlast') { document.PJirc.sendString('/msg memoserv read last'); }
		if (action == 'read') {
			num = prompt('Care nota o citesti?','1');
			if (num != null) {
		 		document.PJirc.sendString('/msg memoserv read '+num ); 		
			}
		}
		if (action == 'delete') {
			num = prompt('Memo de sters?','1');
			if (num != null) {
		 		document.PJirc.sendString('/msg memoserv del '+num ); 		
			}
		}
		if (action == 'delall') {
			doit = confirm('stergem toate notele?');
			if (doit != false) {
		 		document.PJirc.sendString('/msg memoserv del all'); 		
			}
		}
		if (action == 'setnotify') {
			when = prompt('Vrei sa fi anuntat daca ai mesaje MEMO?\n options are: ON/LOGON/NEW/OFF','ON');
			if (when != null) {
		 		document.PJirc.sendString('/msg memoserv set notify '+when ); 		
			}
		}
		if (action == 'setlimit') {
			max = prompt('Numar maxim de MEMO de receptionat? max 20','20');
			if (max != null) {
				if (max <= '20') {
			 		document.PJirc.sendString('/msg memoserv set limit '+max ); 		
				}
				else { alert('Nu poti fixa un numar mai mare de 20'); }
			}
		}

	}
	if (type == 'chanserv') {
		if (action == 'register') {
			pass = prompt('Introdu parola','');
			if (pass != null) {
				description = prompt('Numele canalului cu # in fata un spatiu si descrierea canalului','#canalul descriere');
				if (description != null) {
					document.PJirc.sendString('/msg chanserv register %$C '+ pass +' '+description);				
				}
			}
		}
		if (action == 'identify') {
			pass = prompt('Introdu parola','');
			if (pass != null) {
				document.PJirc.sendString('/msg chanserv identify %$C '+ pass );
			}			
		}
		if (action == 'drop') {
			doit = confirm('Aceasta anuleaza inregistrarea nick-ului tau, esti sigur?');
			if (doit != false) {
		 		document.PJirc.sendString('/msg chanserv DROP %$C '); 		
			}		
		}
		if (action == 'accesslist') {
			document.PJirc.sendString('/msg chanserv access %$C list'); 
		}
		if (action == 'add') {
			nickname = prompt('introdu numele, el trebuie sa fie inregistrat','');
			if (nickname != null) {
				level = prompt('Enter level:\n 3 = voice\n4 = halfop\n5 = op');
				if (level != null) {
					document.PJirc.sendString('/msg chanserv access %$C add '+nickname +' '+level); 
				}
			}
		}
		if (action == 'del') {
			nickname = prompt('introdu numele de sters','');
			if (nickname != null) {
				document.PJirc.sendString('/msg chanserv access %$C del '+nickname ); 
			}
		}

	}

	if (type == 'botserv') {
		if (action == 'list') {
			document.PJirc.sendString('/msg botserv botlist'); 
		}
		if (action == 'assign') {
			botnick = prompt('Enter botname to assign remember to do list bots to see avaliable bots','Atomiccat');
			if (botnick != null) {
				document.PJirc.sendString('/msg botserv assign %$C '+botnick ); 
			}
		}
		if (action == 'inassign') {
			botnick = prompt('Enter botname to unassign','');
			if (botnick != null) {
				document.PJirc.sendString('/msg botserv unassign %$C '+botnick ); 
			}
		}

	}

	if (type == 'join') { 
		if (document.jform.channels.indexOf != '0') {
			if (document.jform.channels.options[document.jform.channels.selectedIndex].value != 'other') {
			document.PJirc.sendString('/join '+ document.jform.channels.options[document.jform.channels.selectedIndex].value);
			return true;
			}
			else {
				chan = prompt('Canalul pt intrare','#canalul');
				if (chan != null) {
					if (chan.indexOf('#') != -1 ) { chan = '/join '+chan; }
						else { chan = '/join #'+chan; }
				 		document.PJirc.sendString(chan); 
				 }
			}
		}
		document.jform.channels.selectedIndex = 0;
	}
		if (type == 'actions') { 
			if (document.jform.actions.selectedIndex != '0') {
				if (document.jform.actions.options[document.jform.actions.selectedIndex].value != 'other') {
					document.PJirc.sendString('/me '+ document.jform.actions.options[document.jform.actions.selectedIndex].value)
				}
			else {
				action = prompt('Action to perform','Smiles innocently');
				if (action != null) {
					action = '/me '+action;
				 	document.PJirc.sendString(action); 
				 }
			}
		}
		document.jform.actions.selectedIndex = 0;
	}
	if (type == 'limit') {
				action = prompt('Set limit to this, leave blank to unset','');
				if (action != null) {
					if (action != '') {
						action = '/mode %$C +l '+action;
				 		document.PJirc.sendString(action); 
				 	}
				 	else { document.PJirc.sendString('/mode %$C -l')  }
				}
			}
	if (type == 'invite') {
			nick = prompt('Invita persoana pe canal','');
			if (nick != null) {
				if (nick != '') {
		 			document.PJirc.sendString('/invite '+nick +' %$C '); 
				}
			}
	}

	if (type == 'opmode') {
		document.PJirc.sendString('/mode %$C '+ '+o' +' %$HN ');
	}
	if (type == 'cmode') {
		document.PJirc.sendString('/mode %$C '+ action );
	}
	
	if (type == 'kick') {
		if (action == 'fast') { kickmsg = 'Iesi afara de aici'; }
			else { kickmsg = setmsg('kick'); }
			document.PJirc.sendString('/kick %2 %1 '+ kickmsg);
	}
	if (type == 'kickban') {
		kickmsg = setmsg('kick');
		if (kickmsg != false) {
			document.PJirc.sendString('/mode %$C +b %$HN ');
			document.PJirc.sendString('/kick %$C %$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.PJirc.sendString('/away ' + awaymsg);PJirc.requestSourceFocus();
				document.PJirc.sendString('/me is AWAY \('+awaymsg+'\).');PJirc.requestSourceFocus();
				away = 'yes';
				document.away.src=away_1.src
			}
		}
			else {
				document.PJirc.sendString('/away');PJirc.requestSourceFocus();
				document.PJirc.sendString('/me nu mai este AWAY \('+awaymsg+'\).');PJirc.requestSourceFocus();
				away = 'no';
				document.away.src=away_2.src
			}
		}
	if (type == 'nickserv') {
		if (action == 'register') {
			nickpass = prompt('introdu parola si mailul tau separate de o pauza','');
			if (nickpass != null) {
				document.PJirc.sendString('/msg nickserv register '+ nickpass);PJirc.requestSourceFocus();
			}
		}
		if (action == 'identify') {
			nickpass = prompt('Parola ta?','');
			document.PJirc.sendString('/msg nickserv identify '+ nickpass);PJirc.requestSourceFocus();
		}
		if  (action == 'ghost') {
			nickpass = prompt('Parola ta?','');
			if (nickpass != null) {
				nick = prompt('Your Nick?','');
					if (nick != null) {
						document.PJirc.sendString('/msg nickserv ghost '+ nick +' ' +nickpass);PJirc.requestSourceFocus();
					}
			}
		}
		if  (action == 'recover') {
			nickpass = prompt('Parola ta?','');
			if (nickpass != null) {
				nick = prompt('Your Nick?','');
				if (nick != null) {
					document.PJirc.sendString('/msg nickserv recover '+ nick +' ' +nickpass);PJirc.requestSourceFocus();
				}
			}
		}
		if  (action == 'release') {
			nickpass = prompt('Parola ta?','');
			if (nickpass != null) {
				nick = prompt('Your Nick?','');
				if (nick != null) {
					document.PJirc.sendString('/msg nickserv release '+ nick + ' ' +nickpass);PJirc.requestSourceFocus();
				}
			}
		}
		if  (action == 'drop') {
			doit = confirm('Aceasta operatiune sterge inregistrarea nick-ului tau, esti sigur ca asta vrei?');
			if (doit != false) {
				document.PJirc.sendString('/msg nickserv drop ');PJirc.requestSourceFocus();
			}
		}
		if  (action == 'setkill') {
			kill = prompt('Set Kill on/off','on');
			if (kill != null) {
				document.PJirc.sendString('/msg nickserv set kill '+ kill );PJirc.requestSourceFocus();
			}
		}
		if  (action == 'setsecure') {
			kill = prompt('Set secure on/off','on');
			if (kill != null) {
				document.PJirc.sendString('/msg nickserv set secure '+ kill );PJirc.requestSourceFocus();
			}
		}				
		if  (action == 'setpassword') {
			oldpass = prompt ('Parola ta noua?','');
			if (oldpass != null) {
				newpass = prompt ('Parola ta veche?','');
				if (newpass != null) {
					document.PJirc.sendString('/msg nickserv set password '+ oldpass +' '+ newpass );PJirc.requestSourceFocus();
				}
			}
		}
	}

}