		var ajaxResponse;

		function checkParams()
		{
			a = document.getElementById('artist').value;
			if (a)
			{
				findArtist();
			}
		}

                function findArtist()
	    	{
		showProcessing();
                url = "aj_findArtistInfo.cgi";
		var artist = escape(document.getElementById('artist').value);
		time = (new Date()).getTime();
                p = {artist: artist, time: time};
                ajaxResponse = new Ajax.Request(
                        url,
                        {
                                method: 'get',
                                parameters: p,
                                onSuccess: showResponse,
                                onFailure: showFailure
                        });
                }

                function showFailure()
	        {
			stopShowProcessing();
		        alert("failure");
		}

                function showResponse(req)
                {
			if (1) 
			{
				var s = '';
	                	var o = eval('(' + req.responseText + ')');
				var artist = o[0];
				var ownSongs = o[1];
				var covers = o[2];
				if (artist.length<1)
				{
					s = describeErrors(artist);
				}
				else
				{
					s = describeSongs(artist, ownSongs, covers);
				}
                        	document.getElementById('results').innerHTML = s;
				paintZebra();
			}
			else
			{
                        	document.getElementById('results').innerHTML = req.responseText;
			}
                }

		function describeSongs(artist, ownSongs, covers)
		{
			var res = '';
			var artistname = unescape(artist[0].data.a);

			if (ownSongs.length < 1)
			{
				res += artistname + 
				' wrote no songs which were covered by other people:<p>';
			}
			else
			{
				res += artistname + 
				' wrote the following songs which were covered by other people:<p>';

				res += drawOwnSongTable(ownSongs) + '<p>';
			}

			if (covers.length < 1)
			{
				res += '<p>and covered none.<p>';
			}
			else
			{
				res += '<p>and covered:<p>';
			
				res += drawSongsCoveredTable(covers) + '<p>';
			}

			return res;
		}

		function tableTop()
		{
			res = '<table border="0" cellpadding="0" cellspacing="0">';
			res += '<tr>';
			res += '<td><img src="art/t_l.gif"/></td>';
			res += '<td STYLE="background-image: url(\'art/t.gif\');"/>';
			res += '<td><img src="art/t_r.gif"/></td>';
			res += '</tr>';

			return res
		}

		function tableBottom()
		{
			res = '<tr>';
			res += '<td><img src="art/b_l.gif"/></td>';
			res += '<td STYLE="background-image: url(\'art/b.gif\');"/>';
			res += '<td><img src="art/b_r.gif"/></td>';
			res += '</tr>';
			res += '</table>';

			return res;
		}


		function drawSongsCoveredTable(covers)
		{
			res = tableTop()

			// left
			res += '<tr>';
			res += '<td STYLE="background-image: url(\'art/l.gif\');"/>';
			res += '<td>';

			// start content
			res += '<table class="zebra scheme1" cellpadding="2" cellspacing="0">';
			res += '<tr>';
			res += '<th align="left">&nbsp;Track</th>';
			res += '<th>&nbsp</th>';
			res += '<th align="left">&nbsp;Artist</th>';
			res += '</tr>';
			for (index=0; index<covers.length; index++)
			{
				oname = unescape(covers[index].data.o);
				tname = unescape(covers[index].data.t);
                       		res += '<tr><td>&nbsp;<a class="intab" href="findTrack.cgi?track=' 
					+ escape(tname) + '">' + tname + '<a/>&nbsp;</td>';
				res += '<td class="faint">&nbsp;<i>by</i>&nbsp;</td>';
                       		res += '<td>&nbsp;<a class="intab" href="findArtist.cgi?artist=' 
					+ escape(oname) + '">' + oname + '<a/>&nbsp;</td></tr>';
			}
			res += '</table>';
			// end content

			// right
			res += '</td>';
			res += '<td STYLE="background-image: url(\'art/r.gif\');"/>';
			res += '</tr>';

			res += tableBottom()

			return res
		}

		function drawOwnSongTable(ownSongs)
		{
			res = "";

			// top row
			res += tableTop()

			// middle row
			res += '<tr>';
			res += '<td STYLE="background-image: url(\'art/l.gif\');"/>';
			res += '<td>';

			// start content
			res += '<table class="zebra scheme1" cellpadding="2" cellspacing="0">';
			res += '<tr>';
			res += '<th align="left">&nbsp;Track</th>';
			res += '<th>&nbsp</th>';
			res += '<th align="left">&nbsp;Artist</th>';
			res += '</tr>';
                        for (index=0; index<ownSongs.length; index++)
                        {
				res += '<tr>';
                                pname = unescape(ownSongs[index].data.p);
                                oname = unescape(ownSongs[index].data.o);
                                tname = unescape(ownSongs[index].data.t);
                                res += '<td>&nbsp;<a class="intab" href="findTrack.cgi?track='
                                        + escape(tname) + '">' + tname + '<a/>&nbsp;</td>';
                                res += '<td class="faint"><i>was&nbsp;covered&nbsp;by</i></td>';
                                res += '<td>&nbsp;<a class="intab" href="findArtist.cgi?artist='
                                        + escape(pname) + '">' + pname + '<a/></td>';
                                res += '</tr>';
                        }
			res += '</table>';

			// end content

			res += '</td>';
			res += '<td STYLE="background-image: url(\'art/r.gif\');"/>';
			res += '</tr>';

			// bottom row
			res += tableBottom()

			return res;
		}


		function describeErrors(artist)
		{
			if (artist.length<1)
			{
				s = 'Couldn\'t find this artist<br>';
				return s;
			}
			else
			{
				
				return 'mystery error<br>';
			}
		}

                function showProcessing()
                {
                        document.getElementById('results').innerHTML = "Processing...";
                }

                function stopShowProcessing()
                {
                        document.getElementById('results').innerHTML = "";
                }


