function rollover(idx)
{
	var a;
	
	if(document.all)
		a = document.all("hl");
	else
		a = document.getElementsByName("hl");
	
	if(idx >= a.length)
	{
		return;
	}
	
	for(i=0; i<a.length;i++)
	{
		if(idx != i)
			a[i].style.display = "none";
		else
			a[i].style.display = "block";
	}
}

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 ShowWON(id1, id2)
{
	var el1 = document.getElementById("listingscontainer" + id1);
	var el2 = document.getElementById("listingscontainer" + id2);
	
	if(el1 && el2)
	{
		el2.style.display = "none";
		el1.style.display = "block";
	}
}

function showPlayer(url)
{
	var win = window.open(url, "rteplayer", "height=560,width=860,status=yes,toolbar=no,menubar=no,location=no");
	win.focus();
}


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 = "/tv/" + PROG_FILENAME + "/" + PROG_FILENAME_EXTRA + date + month + new_date.getFullYear() + ".html";
	
	window.location = new_loc;
}


var CALENDAR_DATE = new Date();
var PROG_FILENAME="index";
var PROG_FILENAME_EXTRA="av_";
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 changeMonth(dt)
{
	dt = new Date(dt);
	getCalendarDatesAsync("/tv/" + PROG_FILENAME + "/inc/archive.inc", dt.valueOf());
}



/* Player strip  - JD - 21st April 2008 */

function writePlayerStrip(programme) {
	document.write("<div id=\"player_bug\"></div>");
	var programmeTitle = programme;
	var feedUrl = "http://www.rte.ie/vodfeeds/feedgenerator/json/programme/";
	try {
		var jsonRequest = new Request.JSON({
			url : feedUrl + "?id=" + programmeTitle,
			method : "get",
			secure : false,
			async : false,
			headers : {'X-Request': 'JSON', 'Last-Modified' : 'Sat, 1 Jan 2005 05:00:00 GMT'},
			onComplete : function(obj, text) {
							if (obj.length > 0 && obj[0].pk) {
								holder = $('player_bug');
								holder.setStyle('display','block');
								holder.setStyle('border-width','1px');
								holder.setStyle('height','33px');
								var link = new Element("a", {
									"class": "watch",
									"href": "/player/#v=" + obj[0].pk
								}).inject(holder);
								var link = new Element("p", {
									"html": obj.length + " episode" + (obj.length > 1 ? "s" : "") + " available"
								}).inject(holder);
							}
						},
			onFailure : function () {},
			onException : function () {}
		}).send();
	}
	catch(e) {}
}

