					function formatXMLDate(tmpdate)
					{

						tmpdate = tmpdate.slice(0,10);
						tmpdate = tmpdate.replace(/-/g,"/");

						var d = new Date(tmpdate);

						var curr_date = d.getDate();
						var curr_month = d.getMonth()+1;
						var curr_year = d.getFullYear();

						return curr_date + "/" +  curr_month + "/" + curr_year;

					}

					/*
						These are global variables that define
						how many items to view at once (itemsPerPage),
						and our current position (curPos).

						"itemsPerPage" is an accurate descriptor only
						within the context of the application, since
						we are not actually browsing "pages".
					*/

					itemsPerPage = 50;
					curPos = 0;

					/*
						The next code block is the jQuery implementation
						of the XMLHttpRequest object. The outer function
						sPBLfies that when the page loads we want to
						execute a function:

						$(function() {});

						Now within that function, make a request for an
						XML file, and upon success, execute another
						function. The data we get back is assigned to
						"xmlData". This is only available within the
						scope of this function. By assigning it to
						"xmlDataSet", we can now use the XML data
						throughout the application. Now we call the
						"browseXML()" function, which will manage
						our browse functionality.

						NOTE: In a production environment, you may want
						to account for any instance when the request
						for the XML fails. Please see the jQuery
						documentation on the $.ajax() object.
					*/

					jQuery.noConflict(); //Need this to resolve conflict with other Javascript libraries used in Wordpress.

					var currentTime = new Date();

					//currentTime.setFullYear(2009,2,14);

					jQuery(document).ready(function(){

						jQuery("select").change(function () {
						
								var mySelect=document.getElementById("dropChannel");
								theIndx=mySelect.selectedIndex;

								jQuery('#logos > a').removeClass('selected');
								jQuery('#logos a:eq(' + theIndx + ')').addClass('selected');	

								GrabXML();

							})
							.change();
							
						jQuery("#logos > a").click(function () {

								jQuery('#logos > a').removeClass('selected');
								jQuery(this).addClass('selected');

								document.getElementById("dropChannel").selectedIndex=jQuery('#logos > a').index(this);

								GrabXML();
						})		

					});

					function DayAdd()
					{
						var msecsInADay = 86400000;

						var currentTime1 = new Date(currentTime);

						currentTime = new Date(currentTime1.getTime() + msecsInADay);

						GrabXML();
					}

					function DaySubtract()
					{
						var msecsInADay = 86400000;

						var currentTime1 = new Date(currentTime);

						currentTime = new Date(currentTime1.getTime() - msecsInADay);

						GrabXML();
					}

					function GrabXML()
					{

								var mySelect=document.getElementById("dropChannel");
								theIndx=mySelect.selectedIndex;

								var str = "";
								jQuery("select option:selected").each(function () {
									str += jQuery(this).text() + " ";
								});

								curPos = 0;

								var month = currentTime.getMonth() + 1;

								if(month < 10)
								{
									var month = "0" + month;
								}

								var day = currentTime.getDate();

								if((currentTime.getDate()) < 10)
								{
									var day = "0" + day;
								}

								var year = currentTime.getFullYear();

								var date = year + "-" + month + "-" + day;

								var tmpURL = "ReadChannelXML.php?channel="+str+"&date="+date;

								jQuery.ajax({
									type: "GET",
									url: tmpURL,
									dataType: "xml",
									success: function(xmlData)
									{
										xmlDataSet = xmlData;

										resultSetLength = jQuery("progs",xmlDataSet).length;

										if(resultSetLength > 1)
										{
											browseXML();
										}

									}
								});
}


								function browseXML()
								{

								strToAppend = "<p>";

								/*
								if (curPos + itemsPerPage > resultSetLength)
								{
								showingThrough = resultSetLength;
								}
								else
								{
								showingThrough = parseInt(curPos + itemsPerPage);
								}
								strToAppend += "Showing <b>" + parseInt(curPos + 1) + "</b> through <b>" + showingThrough + "</b> of <b>" + resultSetLength + "</b>";

								strToAppend += "</p>";
								*/
								/*	strToAppend += "<p>Show Me:&nbsp; ";*/

								/*
								strToAppend += "<a href='#' onclick='itemsPerPage = 2;curPos = 0;browseXML();return false;'>2 at a time</a> &nbsp;|&nbsp; ";
								strToAppend += "<a href='#' onclick='itemsPerPage = 3;curPos = 0;browseXML();return false;'>3 at a time</a> &nbsp;|&nbsp; ";
								strToAppend += "<a href='#' onclick='itemsPerPage = 4;curPos = 0;browseXML();return false;'>4 at a time</a> &nbsp;|&nbsp; ";
								strToAppend += "<a href='#' onclick='itemsPerPage = " + resultSetLength + ";curPos = 0;browseXML();return false;'>All</a></p>";
								*/

								/*	strToAppend += "<p>";*/

								var i = 0;

								strToAppend += "<div id='channelbuttons'>"



								if (itemsPerPage != resultSetLength)
								{

								/*;
								if (curPos == 0) // First page. Go forward only.
								{
								strToAppend += "<div><img src='/images/schedule_03.gif' alt=''/></div>";
								strToAppend += "<div id=channel_date>" + formatXMLDate(jQuery("properdt:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text()) + "</div>";
								strToAppend += "<div><a href='#' onclick='DayMove('+');return false;'><img src='/images/schedule_05.gif' alt=''/></a></div>";
								}
								*/

								//if (curPos > 0 && parseInt(curPos + itemsPerPage) < resultSetLength) // Somewhere inbetween.
								//{

								strToAppend += "<div><a href='#' onclick='DaySubtract();'>< Prev</a></div>";
								strToAppend += "<div id=channel_date>" + formatXMLDate(jQuery("properdt:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text()) + "</div>";
								strToAppend += "<div><a href='#' onclick='DayAdd();'>Next ></a></div>";

								//}

								/*
								if (parseInt(curPos + itemsPerPage) >= resultSetLength) // Last page. Go back only.
								{
								strToAppend += "<div><a href='#' onclick='DayMove(''-'');return false;'><img src='/images/schedule_03.gif' alt=''/></a></div>";
								strToAppend += "<div id=channel_date>" + formatXMLDate(jQuery("properdt:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text()) + "</div>";
								strToAppend += "<div><img src='/images/schedule_05.gif' alt=''/>";
								}
								*/
								}

								strToAppend += "</div>"
								strToAppend += "<div class='programmetitle'>Programme</div><div class='timetitle'>Time</div>"
								strToAppend += "<div id='channel-container'>";

								//jQuery("P_TITLE:lt(" + parseInt(curPos + itemsPerPage) + ")",xmlDataSet).filter(":gt(" + parseInt(curPos - 1) + ")").each(function(i) {
								jQuery("P_TITLE:lt(" + parseInt(curPos + itemsPerPage) + ")",xmlDataSet).each(function(i) {

								strToAppend += "<div class=channelitem><div class=programme>" + jQuery(this).text() + "</div>";
								strToAppend += "<div class=time>" + jQuery("m_time:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text() + " " + formatXMLDate(jQuery("properdt:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text()) + "</div>";
								strToAppend += "</div>";


								});

								strToAppend += "</div>";
								strToAppend += "<div id='schedule-footer'></div>"
								jQuery("#widget").html(strToAppend);

								} //End BrowseXML
