function showGallery(url, target, param)
{
	var win = window.open(url, target, param);
	win.focus();
}

function showPlayer(url)
{
	var win = window.open(url, "rteplayer", "height=560,width=860,status=yes,toolbar=no,menubar=no,location=no");
	win.focus();
}

function showMediaPlayer(url)
{
	var win = window.open(url, "gaamediaplayer", "height=695,width=987,status=yes,toolbar=no,menubar=no,location=no,left=12,top=0");
	win.focus();
}

function ChangeListingChannel(el)
{
	if(el && el.selectedIndex && el.selectedIndex > 0)
	{
		var value = el.options[el.selectedIndex].value;
		var str = location.href;
		
		if(location.search.indexOf("type=") > 0)
		{
			location.href = "?channel=" + value;
			return;
		}
		
		var re = /[&\?]channel=\d+/gim;
		
		if(str.search(re) > 0)
		{
			str = str.replace(/([&\?])channel=\d+/, "$1channel=" + value);
		}
		else if(str.indexOf("?") > 0)
		{
			str += "&channel=" + value;
		}
		else
		{
			str += "?channel=" + value;
		}
		
		location.href = str;
	}
}

function ChangeListingDate(value)
{
		var str = location.href;
		var re = /[&\?]date=\d+/gim;
		
		if(str.search(re) > 0)
		{
			str = str.replace(/([&\?])date=\d+/, "$1date=" + value);
		}
		else if(str.indexOf("?") > 0)
		{
			str += "&date=" + value;
		}
		else
		{
			str += "?date=" + value;
		}
		
		location.href = str;
}


function PrintPreview()
{
	var win = window.open();
	win.document.write("<html>");
	win.document.write("<head>");	
	win.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/radio/style/print.css\" />");
	win.document.write("</head>");
	win.document.write("<body>");
	var str = location.href;
	if (location.href.search(/radio1/) == 18){win.document.write("<img src=\"/radio1/images/logo_printable_radio1.gif\">\n");}
	else if (location.href.search(/[2]fm/) == 18){win.document.write("<img src=\"/2fm/images/logo_printable_2fm.gif\">\n");}
	else if (location.href.search(/lyricfm/) == 18){win.document.write("<img src=\"/lyricfm/images/logo_printable_lyric.gif\">\n");}
	else if (location.href.search(/rnag/) == 18){win.document.write("<img src=\"/rnag/images/logo_printable_rnag.gif\">\n");}
	else {win.document.write("<img src=\"/radio/images/logo_printable_radio.gif\">\n");}
	win.document.write("<hr>");		
	win.document.write(document.getElementById("insideRightContainer").innerHTML);

	if (location.href.search(/radio1/) == 18){win.document.write("<p><strong>Story from RT&Eacute; Radio 1:<br />"+document.location+"</strong></p>");}
	else if (location.href.search(/[2]fm/) == 18){win.document.write("<p><strong>Story from RT&Eacute; 2fm:<br />"+document.location+"</strong></p>");}
	else if (location.href.search(/lyricfm/) == 18){win.document.write("<p><strong>Story from RT&Eacute; Lyric fm:<br />"+document.location+"</strong></p>");}
	else if (location.href.search(/rnag/) == 18){win.document.write("<p><strong>Story from RT&Eacute; Raidió na Gaeltachta:<br />"+document.location+"</strong></p>");}
	else {win.document.write("<p><strong>Story from RT&Eacute; Radio:<br />"+document.location+"</strong></p>");}

	win.document.write("</body>");
	win.document.write("</html>");	
	win.document.close();
}


function gotoDate(dt)
{
	var new_date = new Date(dt);
	
	if(new_date > today)
		return;
	
	var month = new_date.getMonth()+1;
	if(month < 10) month = "0" + month;

	var date = new_date.getDate();
	if(date < 10) date = "0" + date;

	var new_loc = String(window.location);
	if(re_url.exec(String(window.location)))
	{
		new_loc = new_loc.replace(re_url, "/" + new_date.getFullYear() + "/" +  month + date + "/");
		var pos = new_loc.lastIndexOf("/");
		new_loc = new_loc.substr(0, pos + 1) + "index.html";
	}
	else
	{
		var pos = new_loc.lastIndexOf("/");
		new_loc = new_loc.substr(0, pos + 1) + "/" + new_date.getFullYear() + "/" +  month + date + "/" + "index.html";
	}
	
	window.location = new_loc;
}

function gotoDateProg(dt)
{
	var new_date = new Date(dt);
	
	if(new_date > today)
		return;
	
	var month = new_date.getMonth()+1;
	if(month < 10) month = "0" + month;
	var date = new_date.getDate();
	if(date < 10) date = "0" + date;

	var new_loc = String(window.location);
	
	//new_loc = "http://www.rte.ie/radio1/arena/archive1/index1.html";
	new_loc = "/radio1/" + PROG_FILENAME + "/archive1/" + new_date.getFullYear() + "/" +  month + date + "/" + PROG_FILENAME + ".html";
	
	window.location = new_loc;
}

function gotoDateSportProg(dt)
{
	var new_date = new Date(dt);
	
	if(new_date > today)
		return;
	
	var month = new_date.getMonth()+1;
	if(month < 10) month = "0" + month;
	var date = new_date.getDate();
	if(date < 10) date = "0" + date;

	var new_loc = String(window.location);
	new_loc = "/sport/" + new_date.getFullYear() + "/" +  month + date + "/" + PROG_FILENAME + ".html";
	
	window.location = new_loc;
}


var CALENDAR_DATE = new Date();
var PROG_FILENAME="index";
function getCalendarDatesAsync(url, dt)
{
	if(Sarissa)
	{
		CALENDAR_DATE = dt;
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET", url, true);
		
		xmlhttp.onreadystatechange = function() {
		    if (xmlhttp.readyState == 4) {
		        renderCalendar(CALENDAR_DATE, "gotoDateProg", xmlhttp.responseText)
		    }
		}
		xmlhttp.send(null);
	}
}

function getCalendarDatesAsyncSport(url, dt)
{
	if(Sarissa)
	{
		CALENDAR_DATE = dt;
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET", url, true);
		
		xmlhttp.onreadystatechange = function() {
		    if (xmlhttp.readyState == 4) {
		        renderCalendar(CALENDAR_DATE, "gotoDateSportProg", xmlhttp.responseText)
		    }
		}
		xmlhttp.send(null);
	}
}

function changeMonth(dt)
{
	dt = new Date(dt);
	getCalendarDatesAsync("/radio1/" + PROG_FILENAME + "/archive1/inc/archive.inc", dt.valueOf());
}

function changeMonth_sport(dt)
{
	dt = new Date(dt);
	getCalendarDatesAsyncSport("/sport/" + PROG_FILENAME + "/inc/archive.inc", dt.valueOf());
}

