
/* liveHarmony chat generator
 * (C) 2002-2006 liveHarmony
 *
 * Generates applet code based on user-provided parameters.
 *
 * WEBMASTERS: Do NOT copy this file to your site. It MUST
 * be loaded from liveHarmony to receive important updates.
 *
 * $Id: jsgen.php 2219 2007-02-13 20:34:49Z alambert $
 */


function lh_go(lh_prm_input) // Legacy applet
{
	var lh_channel = 'JeeGa';

	// name: [ locked, in applet tag, value ]
	var lh_prm_output =
	{
		_id: [ false, true, 'lhchat' ],
		_codebase: [ true, true, 'http://chat1.liveharmony.org:8000/java/' ],
		codebase: [ true, false, 'http://chat1.liveharmony.org:8000/java/' ],
		_archive: [ true, true, 'cr.zip' ],
		archive: [ true, false, 'cr.zip' ],
		_name: [ false, true, 'cr' ],
		name: [ false, false, 'cr' ],
		_code: [ true, true, 'ConferenceRoom.class' ],
		code: [ true, false, 'ConferenceRoom.class' ],
		cache_archive: [ true, false, 'cr.zip' ],
		cache_version: [ true, false, '1.9.155.0' ],
		join: [ true, false, lh_channel ],
		port: [ true, false, '7000' ],
		height: [ false, true, '350' ],
		width: [ false, true, '500' ],
		lh_sounds: [ false, false, 'true' ],
		lh_actions: [ false, false, 'true' ]
	};

	var lh_prm_macros =
	{
		lh_sounds: ['sounds', 'Bell;bell.au rings the bell;Computer Geek;computer.au is a computer geek :-);CowBell;cowbell.au waits for the cows to come home;Crash;crash.au forgot to hit the brakes!;Cuckoo;cuckoo.au says wake up!;Door;door.au opens the door and steps inside.;Drip;drip.au thinks silence is golden!;Bang;explosion.au lights the fuse!;Flush;flush.au flushes the toilet!;Gong;gong.au gongs you.;Knock;knock.au wants to come inside.;Laugh;laugh.au thinks thats very funny...;Moo;moo.au has a cow!;Music;music.au that\'s music to my ears!;Notice;notice.au news flash!;Sci-Fi;sci_fi.au It\'s the Twilight Zone!;Scoping;scoping.au Up Periscope!;Swish;swish.au SCORES 2 points!!;Train;train.au here comes the train!;Attention;whistle.au wants everyone\'s attention!'],
		lh_actions: ['actions', 'Bored;is really very bored.;Smile;smiles at everyone in the room :-);Slap Everyone;slaps everyone in the room.;Slap Person;slaps %u around with a large trout!;Laugh at someone;looks at %u and laughs.;Away;is going to be away from the channel.;Bounce;bounces around the channel.;LOL;Laughs-Out-Loud!!'],
		lh_chanlock: ['chanlock', '#' + lh_channel + ',#support' ]
	};

	lh_doloop(lh_prm_output, lh_prm_input, lh_prm_macros);
}

function lh_cn(lh_prm_input, theme) // ChatNow: all themes
{
	var lh_channel = 'JeeGa';

	// name: [ locked, in applet tag, value ]
	var lh_prm_output =
	{
                // global cn settings
		_code: [ true, true, 'chatnow.ChatNow.class' ],
		code: [ true, false, 'chatnow.ChatNow.class' ],
		_codebase: [ true, true, 'http://chat1.liveharmony.org:8000/java/' ], 
		codebase: [ true, false, 'http://chat1.liveharmony.org:8000/java/' ],
		_archive: [ true, true, 'chatnow.jar' ], 
		archive: [ true, false, 'chatnow.jar' ],
		_id: [ false, true, 'lhcn' ],
		_name: [ false, true, 'cn' ],
		_type: [ false, true, 'application/x-java-applet;version=1.4'],
		type: [ false, false, 'application/x-java-applet;version=1.4'],
		cache_archive: [ true, false, 'chatnow.jar' ],
		cache_version: [ true, false, '2.9.304.0' ],
		join: [ true, false, lh_channel ],
		port: [ true, false, '7000' ],
		height: [ false, true, '500' ],
		width: [ false, true, '725' ],
		connect: [ true, false, 'false' ],

		// theme specific settings
		themebaseurl: [ true, false, 'http://chat1.liveharmony.org:8000/themes/' + encodeURIComponent(theme) ],
		splashscreenimage: [ true, false, '/themes/' + encodeURIComponent(theme) + '/splashscreen.jpg' ],
		initialtheme: [ true, false, encodeURIComponent(theme) ],

		// misc cn settings
		usestandardthemes: [ true, false, 'true' ],
		scriptable: [ true, false, 'false' ]

	};

	var lh_prm_macros =
	{
		// chatnow macro array
	};

	lh_doloop(lh_prm_output, lh_prm_input, lh_prm_macros);
}


function lh_escape_html(lh_str)
{
	if (typeof(lh_str) == 'string')
	{
		var lh_newstr = lh_str.replace(/&/g, '&amp;');
		lh_newstr = lh_newstr.replace(/</g, '&lt;');
		lh_newstr = lh_newstr.replace(/>/g, '&gt;');
		lh_newstr = lh_newstr.replace(/"/g, '&quot;');
		return lh_newstr;
	}
	else
		return lh_str;
}

function lh_doloop(lh_prm_output, lh_prm_input, lh_prm_macros)
{

	for (var i = 0; i < lh_prm_input.length; i++)
	{
		var lh_prm_name = (lh_prm_input[i][0]).toLowerCase();
		var lh_prm_value = lh_prm_input[i][1];

		if (!lh_prm_output[lh_prm_name])
			lh_prm_output[lh_prm_name] =
				[ false, false, lh_prm_value ];
		else if (!lh_prm_output[lh_prm_name][0])
			lh_prm_output[lh_prm_name] =
				[ false, lh_prm_output[lh_prm_name][1], lh_prm_value ];
	}

	document.write('<center>');

	document.write('<applet');
	for (var lh_prm_name in lh_prm_output)
		if (lh_prm_output[lh_prm_name][1])
		{
			var lh_prm_value = lh_prm_output[lh_prm_name][2];
			if (lh_prm_name.substring(0, 1) == '_')
				lh_prm_name = lh_prm_name.substring(1);

			document.write(' ' + lh_escape_html(lh_prm_name)
				+ '="' + lh_escape_html(lh_prm_value) + '"');
	}
	document.write('>');

	for (var lh_prm_name in lh_prm_output)
		if (!lh_prm_output[lh_prm_name][1])
		{
			if ((lh_prm_macros[lh_prm_name]) && lh_prm_output[lh_prm_name][2] == "true")
			{
				document.write('<param name="' + lh_escape_html(lh_prm_macros[lh_prm_name][0]) + '" '
					+ 'value="' + lh_escape_html(lh_prm_macros[lh_prm_name][1]) + '">');
			}
			else
			{
				var lh_prm_value = lh_prm_output[lh_prm_name][2];

				document.write('<param name="' + lh_escape_html(lh_prm_name) + '" '
					+ 'value="' + lh_escape_html(lh_prm_value) + '">');
			}
		}
        
	document.write('<a href="http://www.liveharmony.org/needjava.html?source=jusr" target="_new">');
	document.write('The chat system requires Java. Please use this link to install Java.');
	document.write('</a>');

	document.write('</applet>');            
	document.write('</center>');                
                                
	return true;
		
}

