var req = null;  
var lastUid=0;
var cnt=0;
var maxRows=15;
var maxRowsFilter=8;
function ssAddNewFilter(uid, song, artist, url)
{
	if(url=="NO STATION ID" || url=="UNKNOWN")
		return;

	var tbl = document.getElementById("streamserfsongs");

	var rowIndex = 1;
	try {
		var newRow = tbl.insertRow(rowIndex);
		
		newRow.id="row" + cnt;

		//if(uid%2==0)
		//	newRow.className='oddRow'
		//else
		//	newRow.className='evenRow'

		newCell = newRow.insertCell(0);
		var artistDisplay=artist;

		if(artistDisplay.length>35)
			artistDisplay=artistDisplay.substring(0,32) + "...";

		var s=artistDisplay;

		newCell.innerHTML = s
		newCell = newRow.insertCell(1);

		var songDisplay=song;

		if(songDisplay.length>55)
			songDisplay=songDisplay.substring(0,52) + "...";

		newCell.innerHTML = songDisplay
		
		newCell = newRow.insertCell(2);
		
		newCell.innerHTML = "<a href='" + url + "/listen.pls'>Listen</a>";

		cnt++;

		if(tbl.rows.length>maxRowsFilter)
			tbl.deleteRow(tbl.rows.length - 1);
	} 
	catch (ex) {}
}

function closeBrief()
{
	var elm = document.getElementById("whatsThis");
	
	if(elm)
	{
		elm.style.display='none';
	}
}
function streamSerf_update()
{
	var url="/newSongs.jsp?RAND=" + Math.random()*1000;
	
	streamSerfHTTP(url);
	
}
function streamSerf_update_filter(uid)
{
	var url="/newSongsFilter.jsp?UID=" + uid + "&RAND=" + Math.random()*1000;
	
	streamSerfHTTP(url);
}
function ssAddNew(uid, song, artist, genre, country, flag)
{

	var tbl = document.getElementById("streamserfsongs");

	var rowIndex = 1;
	try {
		var newRow = tbl.insertRow(rowIndex);
		
		newRow.id="row" + cnt;

		if(uid%2==0)
			newRow.className='oddRow'
		else
			newRow.className='evenRow'

		newCell = newRow.insertCell(0);
		var artistDisplay=artist;

		if(artistDisplay.length>35)
			artistDisplay=artistDisplay.substring(0,32) + "...";

		var s=artistDisplay;

		newCell.innerHTML = s
		newCell = newRow.insertCell(1);

		var songDisplay=song;

		if(songDisplay.length>55)
			songDisplay=songDisplay.substring(0,52) + "...";

		newCell.innerHTML = songDisplay
		newCell = newRow.insertCell(2);

		newCell.innerHTML = country;

		newCell = newRow.insertCell(3);
		newCell.innerHTML = "<center><img src='/img/flags/" + flag + ".gif'></img>";

		cnt++;

		if(tbl.rows.length>maxRows)
			tbl.deleteRow(tbl.rows.length - 1);
	} 
	catch (ex) {}
}

function streamSerfHTTP(URL) 
{

	if(window.XMLHttpRequest) 
	{  
		try 
		{
			req = new XMLHttpRequest();   
		}
		catch (e) 
		{
		}
	} 
	else if (window.ActiveXObject) 
	{
		{
			try 
			{
				req  = new ActiveXObject('Microsoft.XMLHTTP');      
			} catch (e) 
			{}
		}
	}
	else
	{
		alert("Sorry.  Your browser does not support certain functionality on this site.");
		return;
	}


	req.onreadystatechange = streamSerf_dataHandler;
	req.open('GET', URL, true);  
	req.send(null);  
}
function streamSerf_dataHandler()
{

	if (req.readyState == 4) 
	{  

		if (req.status == 200)
		{  
			eval(req.responseText)
		}  
	}  
}