/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    This file defines a Javascript function that calls the pjirc client to
    access the #twosheds channel on the irc.webmaster.com IRC server.
    The user is prompted to enter a nickname before they are connected.

    Call this with a construct like this ...

    <html>
    <head>
    <script language="JavaScript" src="/chatClient/twoshedsChat.js"></script>
    <title>TwoSheds Live Chat</title>
    </head>
    <body>
      <a href="#" onClick="javascript:twoshedsChat('irc.webmaster.com','#twosheds', 'spanky',
        'http://twosheds.com/chatClient/irchelp.html');">TwoSheds Live Chat</a>
    </body>
    </html>

    Because these functions always return "false" the actual value of the
    href="" is ignored.

    The parms on twoshedsChat() are the server name, the channel name, the
    user's nickname and the url of a help file.  If you leave them blank, then the
    server defaults to "irc.webmaster.com" and the channel to "#twosheds" respectively.
    You'll be prompted for the nickname.  The help file used will be
    http://www.twosheds.com/chatClient/ircHelp.html.

    See readme.txt and pixx-readme.txt for the available applet param settings.

    Twosheds 20041030
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function twoshedsChat(server,channel,nick,helpurl) {

	// If they didn't give us a special help file, use this one ...
	if ((helpurl == "") || (helpurl == null)) {
	  helpurl = "http://www.twosheds.com/chatClient/irchelp.html";
	}

	// If they didn't tell us what chat room to open, we'll go here ...
	if ((server == "") || (server == null)) { server = "irc.webmaster.com"; }
	if ((channel == "") || (channel == null)) { channel = "#twosheds"; }

	// How big we want the applet to be ...
	var xsize = 800;
	var ysize = 600;

	// Figure out much real estate we have to play with ...
	var availWidth;
	var availHeight;
	if (typeof(window.innerWidth) == 'number') {
		// Non-IE browser
		availWidth = window.innerWidth;
		availHeight = window.innerHeight;
  	} else if ((document.documentElement) &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    		//IE 6+ in 'standards compliant mode'
    		availWidth = document.documentElement.clientWidth;
    		availHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		availWidth = document.body.clientWidth;
		availHeight = document.body.clientHeight;
	}

	// Prompt to get the user's nickname
	var message = "Please enter the nickname you'd like to use while chatting: ";
	while ((nick == null) || (nick == "")) {
		nick = prompt(message, "");
		if (nick == "") {
			message = "You must enter a nickname that you'd like to use as your name during the chat session: ";
		} else if (nick == null) {
		        return false;		// Pressed cancel so we just quit
		}
	}

	//  Center the window  ..
	var x = Math.round((screen.availWidth - xsize) / 2);
	var y = Math.round((screen.availHeight - ysize) / 2);
	if (x < 0) { x = 0; }
	if (y < 0) { y = 0; }

	// Open the applet window ...
	var options = "resizable=0,width=" + xsize + ",height=" + ysize + ",screenx=" + x + ",screeny=" + y;
	var win = window.open("", "chatwindow", options);

	// Spit out the HTML to call the applet ...
	win.document.write('<html><head><title>Twosheds Live Chat Client</title></head><body>');
	win.document.write('<applet codebase="http://www.twosheds.com/chatClient" code=IRCApplet.class ' +
		'archive="irc.jar,pixx.jar" width=' + (xsize - 20) + ' height=' + (ysize - 20) + ' align="middle">');

	win.document.write('<param name="CABINETS" value="irc.cab,securedirc.cab,pixx.cab">');
	win.document.write('<param name="nick" value="' + nick + '">');
	win.document.write('<param name="alternatenick" value="guest">');
	win.document.write('<param name="fullname" value="TwoSheds Live Chat">');
	win.document.write('<param name="host" value="'+ server + '">');
	win.document.write('<param name="gui" value="pixx">');
	win.document.write('<param name="quitmessage" value="">');
	win.document.write('<param name="style:bitmapsmileys" value="true">');
	win.document.write('<param name="style:smiley1" value=":) img/sourire.gif">');
	win.document.write('<param name="style:smiley2" value=":-) img/sourire.gif">');
	win.document.write('<param name="style:smiley3" value=":-D img/content.gif">');
	win.document.write('<param name="style:smiley4" value=":d img/content.gif">');
	win.document.write('<param name="style:smiley5" value=":-O img/OH-2.gif">');
	win.document.write('<param name="style:smiley6" value=":o img/OH-1.gif">');
	win.document.write('<param name="style:smiley7" value=":-P img/langue.gif">');
	win.document.write('<param name="style:smiley8" value=":p img/langue.gif">');
	win.document.write('<param name="style:smiley9" value=";-) img/clin-oeuil.gif">');
	win.document.write('<param name="style:smiley10" value=";) img/clin-oeuil.gif">');
	win.document.write('<param name="style:smiley11" value=":-( img/triste.gif">');
	win.document.write('<param name="style:smiley12" value=":( img/triste.gif">');
	win.document.write('<param name="style:smiley13" value=":-| img/OH-3.gif">');
	win.document.write('<param name="style:smiley14" value=":| img/OH-3.gif">');
	win.document.write('<param name="style:smiley15" value=":\'( img/pleure.gif">');
	win.document.write('<param name="style:smiley16" value=":$ img/rouge.gif">');
	win.document.write('<param name="style:smiley17" value=":-$ img/rouge.gif">');
	win.document.write('<param name="style:smiley18" value="(H) img/cool.gif">');
	win.document.write('<param name="style:smiley19" value="(h) img/cool.gif">');
	win.document.write('<param name="style:smiley20" value=":-@ img/enerve1.gif">');
	win.document.write('<param name="style:smiley21" value=":@ img/enerve2.gif">');
	win.document.write('<param name="style:smiley22" value=":-S img/roll-eyes.gif">');
	win.document.write('<param name="style:smiley23" value=":s img/roll-eyes.gif">');
	win.document.write('<param name="pixx:highlight" value="true">');
	win.document.write('<param name="pixx:highlightnick" value="true">');
	win.document.write('<param name="pixx:showchanlist" value="false">');
	win.document.write('<param name="pixx:nickfield" value="true">');
	win.document.write('<param name="pixx:helppage" value="' + helpurl + '">');
	win.document.write('<param name="pixx:color5" value="999999">');   // Client buttons and scroll bars
	win.document.write('<param name="pixx:color6" value="cccccc">');   // General background
	win.document.write('<param name="pixx:color7" value="0000aa">');   // Tab and user buttons
	win.document.write('<param name="pixx:color8" value="aa0000">');   // "Status" button
	win.document.write('<param name="pixx:color9" value="ffffff">');   // Close and maximixe window button
	win.document.write('<param name="command1" value="/join ' + channel + '">');
	win.document.write('</applet>');
	win.document.write('</body>');
	win.document.write('</html>');

	win.document.close();
	return false;
}
