function converte_m2h(str){
	result = str / 60;
	h = Math.floor(result);

	if (h==0)
		hourpart = ''
	
	else if (h==1) 
		hourpart = '1 hr';
	
	else
		hourpart = h + ' hrs';

	m = str - (h * 60);
	
	if (m == 0)
		minutepart = '';
	
	else 
		minutepart = m + ' mins';
	
	if (minutepart == '')
		return hourpart;
		
	else if (hourpart == '')
		return minutepart;
	
	else {
		return hourpart + ' ' + minutepart;
	}
} 

function favoriteChecked(checkboxElement, channelNumber) {
	if(checkboxElement.checked)
		$('favorite_channel_name_' + channelNumber).style.fontWeight = 'bold';
	else
		$('favorite_channel_name_' + channelNumber).style.fontWeight = '';
}

function exitfavoritechanneltooltip(number) {
    $('tooltip').style.display = 'none';
}

function favoritechanneltooltip(channel) {

	    if(!$('tooltip')) newelement('tooltip');
	    var lixlpixel_tooltip = $('tooltip');

		var collection = this.rig.channelCollection;

		var tempDiv1 = document.createElement('div');
		tempDiv1.className = 'channel-row';	
		
		ct = document.createElement('div');
		ct.id = 'channel-' + channel + '-tooltip';
		//ct.className = 'channel-tooltip';
		
		cttop = document.createElement('div');
		cttop.className = 'channel-tooltip-top';
		ct.appendChild(cttop);
		
		ctmiddle = document.createElement('div');
		ctmiddle.className = 'channel-tooltip-middle';
		
		cttitle = document.createElement('div');
		cttitle.className = 'channel-tooltip-title';
		cttitle.innerHTML = '<b>' + collection[channel].channelNumber + '</b> ' + collection[channel].channelName;
		ctmiddle.appendChild(cttitle);
	
		ctdesc1 = document.createElement('div');
		ctdesc1.className = 'channel-tooltip-desc1';	
		ctdesc1.innerHTML = collection[channel].channelTag;	
		ctmiddle.appendChild(ctdesc1);	
		
		ctdesc2 = document.createElement('div');
		ctdesc2.className = 'channel-tooltip-desc2';	
		ctdesc2.innerHTML = collection[channel].channelShortDesc;
		ctmiddle.appendChild(ctdesc2);	
		
		ct.appendChild(ctmiddle);		

		ctbottom = document.createElement('div');
		ctbottom.className = 'channel-tooltip-bottom';
		ct.appendChild(ctbottom);

		tempDiv1.appendChild(ct);
		lixlpixel_tooltip.style.zIndex = '99';
			
	    lixlpixel_tooltip.innerHTML = tempDiv1.innerHTML;
	    lixlpixel_tooltip.style.display = 'block';
	    document.onmousemove = getmouseposition;
    
    
}

function showAddFavoriteShow(channelID, scheduleID) {
	if (navigator.cookieEnabled == 0) {
		showBox('cookiesdisabled');
		return;
	}

	seriesID = this.rig.channelCollection[channelID].programCollection[scheduleID].seriesID;
	showBox('addfavoriteshow');
	$('show_to_add').value = scheduleID + '::' + seriesID;
	$('series_to_add').value = scheduleID;
	if (seriesID != null) {
		$('series_to_add').value = seriesID;
		$('add_favorite_series_option').disabled = false;
	}
	else {
		$('series_to_add').value = '';
		$('add_favorite_series_option').disabled = true;
		$('add_favorite_show_option').checked=true;
	}
}

function showRemoveShowConfirm(id, name) {
	showBox('removeshowconfirm');
	$('removefavoriteshow_text').innerHTML = 'Are you sure you wish to remove the show "' + name + '" from your Favorite Shows List?';
	clickevent = "removeFavoriteShow('" + id + "')";
	$('removeshowconfirmbutton').innerHTML = '<img style="cursor:pointer;cursor:hand" onClick="' + clickevent + '" src="/images/epg/btn/remove_button.gif" alt="">';
}

function showRemoveSeriesConfirm(id, name) {
	showBox('removeseriesconfirm');
	$('removefavoriteseries_text').innerHTML = 'Are you sure you wish to remove the series "' + name + '" from your Favorite Series List?';
	clickevent = "removeFavoriteSeries('" + id + "')";
	$('removeseriesconfirmbutton').innerHTML = '<img style="cursor:pointer;cursor:hand" onClick="' + clickevent + '" src="/images/epg/btn/remove_button.gif" alt="">';

}

function channeltooltip(number)
{
    if(!$('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = $('tooltip');
    lixlpixel_tooltip.innerHTML = $('channel-' + number + '-tooltip').innerHTML;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
	$(number + '-channel-cell').style.background = "url('/images/epg/bkgd/channel-bg-selected.gif')";    
}



function exitchanneltooltip(number)
{
    $('tooltip').style.display = 'none';
    if (!(this.rig.channelCollection[number].detailsVisible))
	   	$(number + '-channel-cell').style.background = "url('/images/epg/bkgd/channel-bg.gif')";
}

function removeItems(originalArray, itemsToRemove) {
	var j;
	for (var i = 0; i < itemsToRemove.length; i++) {
		j = 0;
		while (j < originalArray.length) {
			if (originalArray[j] == itemsToRemove[i]) {
				originalArray.splice(j, 1);
			} else {
				j++;
			}
		}
	}
	return originalArray;
}

Array.prototype.remove=function(s){
  for(i=0;i<this .length;i++){
    if(s==this[i]) this.splice(i, 1);
  }
}

Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 }
 return a;
}

Array.prototype.in_array = function(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}

function isFavorite(number) {
	if(saved_favorites_array.indexOf(number) > -1) 
		return true;
	else
		return false;
}

function isFavoriteShow(number) {
	var return_value = false;
	saved_favorite_shows_array.each(function(show){
		show_split = show.split('::');
		if (show_split[0] == number) 
			return_value = true;
				});			
				
	return return_value;
}

function isFavoriteSeries(number) {
	var return_value = false;
	saved_favorite_series_array.each(function(show){
		if (show == number) 
			return_value = true;
				});		
	return return_value;				
}

function addRemoveFavoriteChannel(number) {

	if (navigator.cookieEnabled == 0) {
		showBox('cookiesdisabled');
		return;
	}

	if (isFavorite(number))
		showBox('editfavorites');
	else {
		showBox('editfavorites');
		saved_favorites_array.push(number.toString());
		updateFavoriteCheckboxes();
	}
		
	updateFavoriteCheckboxes();
	//createCookie('saved_favorites',saved_favorites_array, 7);	
	//rig.displayResults();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function updateFavoriteCheckboxes() {
	var favorites_checkbox;
		
	for(channel in this.rig.channelCollection) {
		favorites_checkbox = document.getElementById('channel_checkbox_' + channel);
		if(favorites_checkbox) {
			if(saved_favorites_array.in_array(favorites_checkbox.value)) {
				favorites_checkbox.checked = true;
			} else {
				favorites_checkbox.checked = false;
			}
		}
	}
			
	saved_favorites_array.each(function(node){	
		if($('favorite_channel_name_' + node))
			$('favorite_channel_name_' + node).style.fontWeight = 'bold';
	});
				
}

function loadPage(onxm) {
	if(onxm != true) {
		loadDates(0);
	
		if (readCookie('show_only_favorites') == 'true')
			$('show_only_favorites').checked = true;	
	
		if(readCookie('saved_favorites')) {
			saved_favorites_array	= readCookie('saved_favorites').split(",");
			updateFavoriteCheckboxes();
		}	
	}
	
	if (readCookie('timezone') != null)
		$('timezone').value = readCookie('timezone');	
		
	if(readCookie('saved_favorite_shows')) {	
	// added replace to fix bug w/ extra commas getting stored in the cookie
		saved_favorite_shows_array	= readCookie('saved_favorite_shows').replace(/,+/g, ",").split(",");
	}	

	if(readCookie('saved_favorite_series')) {
	// added replace to fix bug w/ extra commas getting stored in the cookie
		saved_favorite_series_array	= readCookie('saved_favorite_series').replace(/,+/g, ",").split(",");
	}		
}

function storeFilterCookies() {
	//save all the filters into the cookie
	
	if($('channel_category'))
		createCookie('channel_category',$('channel_category').value, 7);
	
	if($('channel_genre'))
		createCookie('channel_genre',$('channel_genre').value, 7);
		
	if($('timezone'))
		createCookie('timezone',$('timezone').value, 7);			
		
	if($('show_only_favorites'))
		createCookie('show_only_favorites',$('show_only_favorites').checked, 7);
}

function storeTimezoneCookie() {
	createCookie('timezone',$('timezone').value, 7);
}

function unselectCells() {
	var channel_div;
	var program_div;
	
	for(channel in this.rig.channelCollection) {
		channel_div = document.getElementById(channel + '-channel-cell');
		if(channel_div) {
			channel_div.style.background = "url('/images/epg/bkgd/channel-bg.gif')";
			
			for(program in this.rig.channelCollection[channel].programCollection) {
				program_div = document.getElementById(program + '-program-cell');
				program_div.style.background = "#FFFFFF";			
			}
		}
	}	
}

function hideAllChannels() {
	var details_div;
			
	for(channel in this.rig.channelCollection) {
		details_div = document.getElementById('details_' + channel);
		if(details_div)
			Element.hide(details_div);
		
		for(i in this.rig.channelCollection[channel].programCollection) {
			this.rig.channelCollection[channel].programCollection[i].detailsVisible = false;
		}
		this.rig.channelCollection[channel].detailsVisible = false;
	}
}


function hideChannelDetails(id) {
	unselectCells();
	Element.hide(id + '-expanded');	
}

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 

        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
}

function getmouseposition(e)
{
    if($)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = $('tooltip');
        var offsety = lixlpixel_tooltip.offsetHeight;

		var x_position = 0;
		var y_position = 0;
		
		if(document.all) {
			if(offsety == 0) {
				offsety = 95;
			}
			x_position = event.clientX + iebody.scrollLeft + 15;
			y_position = event.clientY + iebody.scrollTop - offsety;
		} else {
			x_position = mousex+pagex+offsetx;
			y_position = mousey+pagey-offsety;
		}

        lixlpixel_tooltip.style.left = (x_position) + 'px';
        lixlpixel_tooltip.style.top = (y_position) + 'px';
    }
}


function switchMainTab(selected_tab) {

	$('schedule_tab').style.background = "url('/images/epg/tabs/schedule_tab_off.gif')";
	$('favorites_tab').style.background = "url('/images/epg/tabs/favorites_tab_off.gif')";
	$(selected_tab + '_tab').style.background = "url('/images/epg/tabs/" + selected_tab + "_tab_on.gif')";


	var tabnames = new Array('schedule','favorites');
	for(i=0;i<tabnames.length;i++)
		$(tabnames[i] + '_content').style.display = 'none';
	
	$(selected_tab + '_content').style.display = 'block';	
	
	if (selected_tab == 'favorites') {
		this.rig.selectedTab = "favorites";
		document.getElementById("genreContainer").style.visibility = "hidden";
		document.getElementById("timeContainer").style.visibility = "hidden";	
		document.getElementById("favoriteChannelContainer").style.visibility = "hidden";		
		
		if (rig.isDirty == true)
			updateMyFavoriteShows();
	} else if (selected_tab == 'schedule') {
		this.rig.selectedTab = "schedule";
		
		this.rig.buildGenreSelect(document.getElementById("channel_category").value);
		document.getElementById("timeContainer").style.visibility = "visible";	
		document.getElementById("favoriteChannelContainer").style.visibility = "visible";

		if (rig.isDirty == true)
			this.rig.displayResults();
	}
	
	rig.isDirty = false;

}

function switchTab(toShow) {

	var tabnames = new Array('music','news','sports','talk_ent');
	
	for(i=0;i<tabnames.length;i++)
		$(tabnames[i] + '_favorites').style.display = 'none';

	$(toShow + '_favorites').style.display = 'block';

	for(i=0;i<tabnames.length;i++)
		$(tabnames[i] + '_favorites_tab').style.background = "url('/images/epg/tabs/" + tabnames[i] + "_tab_off.gif')";
	
	$(toShow + '_favorites_tab').style.background = "url('/images/epg/tabs/" + toShow + "_tab_on.gif')";
}

function highlightBox(the_div_id, direction) {

	if (!(document.getElementById(the_div_id))) {
		if(typeof(direction) != 'undefined') {
			loadDates(direction);
			
			if (!(document.getElementById(the_div_id)))
				return;
		} else {
			return;
		}
	}
	
	var the_div = $(the_div_id);
	var date_container = document.getElementById("dategrid_inner");
	var children = date_container.childNodes;

	for (var i=0; i<children.length; i++) {
		children[i].style.backgroundColor = '#fff';
		children[i].style.fontWeight = '';
	}
		
	selected_date = the_div_id;
	the_div.style.backgroundColor = '#FFDB05';
	the_div.style.fontWeight = 'bold';
}

function loadDates(direction) {
	if (offset >= 7 && direction == 1)
		return;
	else if (offset <= 0 && direction == -1)
		return;	
	offset += (direction * 7);
	var day = new Date();
	
	var innerdivs = '';
	var j = 0;

	for (var i=offset; i < (offset + 7); i++) {
	
		var day = new Date();
		day.setDate(day.getDate()+i);
		
		if (j==0) {
			border_style = 'border-width: 1px 0px 1px 0px';
		}
		
		else
			border_style = '';
		
		if (day.formatDate('nj') == selected_date || (direction == 0 && i == 0)) {
			innerdivs += '<div id="' + day.formatDate("Ymd") + '" style="background-color: #FFDB05; font-weight: bold; ' + border_style + '" class="dategrid_box" onClick="rig.setDirty();highlightBox(this.id); rig.navDate(this.id);updateMyFavoriteShows();">' + day.formatDate('D') + '<br>' + day.formatDate('n/j') + '</div>';
		}
		else 
			innerdivs += '<div id="' + day.formatDate("Ymd") + '" style=" ' + border_style + '" class="dategrid_box" onClick="rig.setDirty();highlightBox(this.id);rig.navDate(this.id);updateMyFavoriteShows();">' + day.formatDate('D') + '<br>' + day.formatDate('n/j') + '</div>';
			
		j++;	
	}

	if ($('dategrid_inner')) 
		$('dategrid_inner').innerHTML = innerdivs;
	
	//if we switch, make sure the current grid date is highlighted
	var gridStart = new Date(this.rig.gridStart).formatDate('Ymd');
	highlightBox(gridStart);	
}

function showEditFavorites() {
	if (navigator.cookieEnabled == 0) {
		showBox('cookiesdisabled');
		return;
	}
	
	showBox('editfavorites');
}

function showBox(id){	
	if($('date_channel_ribbon_inner'))
		$('date_channel_ribbon_inner').style.visibility = 'hidden';

	if($('subnav_UL'))
		$('subnav_UL').style.visibility = 'hidden';

	if($('channel_genre'))		
   		$('channel_genre').style.visibility = 'hidden';

	if($('timezone'))		
   		$('timezone').style.visibility = 'hidden';
   		
	embeds = document.getElementsByTagName('embed');
	for(i = 0; i < embeds.length; i++) {
	    embeds[i].style.visibility = 'hidden';
	}	

	embeds = document.getElementsByTagName('object');
	for(i = 0; i < embeds.length; i++) {
	    embeds[i].style.visibility = 'hidden';
	}	
		
    $('overlay').style.display = '';
    $('overlay').style.height = document.body.clientHeight + 50 + 'px';
    $('overlay').style.width = document.body.clientWidth;
    $(id).style.display = '';    
    center(id);
    return false;
}

function hideBox(id){
	if($('date_channel_ribbon_inner'))
		$('date_channel_ribbon_inner').style.visibility = '';

	if($('subnav_UL'))
		$('subnav_UL').style.visibility = '';

	if($('channel_genre'))		
   		$('channel_genre').style.visibility = '';
   	
	if($('timezone'))		
   		$('timezone').style.visibility = '';

	embeds = document.getElementsByTagName('embed');
	for(i = 0; i < embeds.length; i++) {
	    embeds[i].style.visibility = 'visible';
	}	
   	
	embeds = document.getElementsByTagName('object');
	for(i = 0; i < embeds.length; i++) {
	    embeds[i].style.visibility = 'visible';
	}	

    $(id).style.display = 'none';
    $('overlay').style.display = 'none';

    return false;
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement &&
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body &&
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    //var elementDimensions = Element.getDimensions(element);

	var setX = ( my_width - element.offsetWidth ) / 2;
    var setY = ( my_height - element.offsetHeight ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;
    
    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}

function updateFavoriteChannels() {

	saved_favorites_array.length = 0;
	var favorites_checkbox;

	for(channel in this.rig.channelCollection) {
		favorites_checkbox = document.getElementById('channel_checkbox_' + channel);
		if(favorites_checkbox) {
			if(favorites_checkbox.checked) {
					saved_favorites_array.push(favorites_checkbox.value);
			}
		}
	}

	hideBox('editfavorites');
	showBox('addfavoriteshowconfirm');
	
	if($F('show_only_favorites') == 'on')
		rig.displayResults();

	createCookie('saved_favorites',saved_favorites_array, 7);	
}

function addProgFavoriteShow() {
	hideBox('addfavoriteshow');
	if ($F('add_favorite_show_option') == 'on') {
		saved_favorite_shows_array.push($F('show_to_add'));
		saved_favorite_shows_array = saved_favorite_shows_array.unique();
	}

	else if ($F('add_favorite_series_option') == 'on') {
		saved_favorite_series_array.push($F('series_to_add'));
		saved_favorite_series_array = saved_favorite_series_array.unique();
	}
	
	createCookie('saved_favorite_shows',saved_favorite_shows_array, 7);	
	createCookie('saved_favorite_series',saved_favorite_series_array, 7);
}

function addFavoriteShow() {
	hideBox('addfavoriteshow');
	if ($F('add_favorite_show_option') == 'on') {
		saved_favorite_shows_array.push($F('show_to_add'));
		saved_favorite_shows_array = saved_favorite_shows_array.unique();
	}

	else if ($F('add_favorite_series_option') == 'on') {
		saved_favorite_series_array.push($F('series_to_add'));
		saved_favorite_series_array = saved_favorite_series_array.unique();
	}
	this.rig.setDirty();
}

function removeFavoriteShow(entry) {
	hideBox('removeshowconfirm');
	saved_favorite_shows_array.remove(entry);
	updateMyFavoriteShows();
	
}

function removeFavoriteSeries(entry) {
	hideBox('removeseriesconfirm');
	new_favorites = new Array();
		saved_favorite_shows_array.each(function(node){
				if (!(node.split('::').in_array(entry))) {	
					new_favorites.push(node);
				}
		});
	
	saved_favorite_shows_array = new_favorites;
	saved_favorite_series_array.remove(entry);

	updateMyFavoriteShows();	
}

function getShowsOnly(array) {
	shows_only = new Array();
	saved_favorite_shows_array.each(function(node){
		node_r = node.split('::');
		shows_only.push(node_r[0]);
	});
	
	return shows_only;
}

function updateMyFavoriteShows() {

		if(!$('favorites_content'))
			return;
			
		if ($('favorites_content').style.display == 'none')
			return;

		$('favorites_content').innerHTML = '<img style="padding-left: 90px" id="featured_this_week_loading" src="/images/epg/main_loading_white.gif">';

		var channel_string = this.rig.channelArray.join(',');
		


		var catSelect = document.getElementById('channel_category');

		if(catSelect.value != '' && catSelect.value != 'default') {
			channel_string = rig.categoryCollection[catSelect.value].channelArray.join(',');
		}


		channel_string = channel_string.replace(/-/g,"");
		
		var tempStartDate = new Date();
		var tempEndDate = new Date();
		
		var timeAdjust = 1000 * 60 * 60 * this.rig.timezoneOffset;
		var threeHours = 1000 * 60 * 180;	
	
		start_timezone_array = new Array("00", "01", "02", "03");
		end_timezone_array = new Array("23", "00", "01", "02");
		
		tempStartDate.setTime(this.rig.gridStart.getTime() + timeAdjust);
		
		// if the timezone is not eastern, we need the end date to be tomorrow
		if(this.rig.timezoneOffset == 0) 
			tempEndDate.setTime(tempStartDate.getTime());
		else
			tempEndDate.setTime(tempStartDate.getTime() + (1000 * 60 * 60 * 24));

		var startDate = tempStartDate.formatDate('dmY') + start_timezone_array[this.rig.timezoneOffset] + '0000';	
		var endDate = tempEndDate.formatDate('dmY') + end_timezone_array[this.rig.timezoneOffset] + '5900';	

		var param_string = 'channelNums=' + channel_string + '&schIds=' + getShowsOnly(saved_favorite_shows_array) + '&groupIds=' + saved_favorite_series_array + '&startDate=' + startDate + '&endDate=' + endDate;

		var handlerFunc = function(t) {
			$('favorites_content').innerHTML = '';
			var JSON_string = t.responseText;
			var myObject = eval('(' + JSON_string + ')');
			
//			if ((myObject.programScheduleList.length < 1) || (!(myObject.programScheduleList.length)) {
		if (!navigator.cookieEnabled || typeof myObject.programScheduleList == "undefined" || (myObject.programScheduleList.length < 1)) {

				empty = document.createElement('div');
				empty.id = 'empty_favorites';

				emptyh1 = document.createElement('h1');
				emptyh1.innerHTML = 'There are no Favorite Shows that match the specified criteria';
				
				emptyh3 = document.createElement('h3');
				emptyh3.innerHTML = 'Why don\'t I see any Favorite Shows?';

				emptyul = document.createElement('ul');
				
				emptyli1 = document.createElement('li');
				emptyli1.innerHTML = 'You must have cookies enabled in your browser to add Favorite Shows.  Also if you are using a different computer or browser from which you previously used to add Favorite Shows, you won\'t be able to access them.';

				emptyli2 = document.createElement('li');
				emptyli2.innerHTML = 'You may not have added any Favorite Shows yet.';


				emptyli3 = document.createElement('li');
				emptyli3.innerHTML = 'You may be viewing a Date/Channel Category combination that doesn\'t have any associated Favorite Shows.';

	
				empty.appendChild(emptyh1);			
				empty.appendChild(emptyh3);				
				empty.appendChild(emptyul);				
				emptyul.appendChild(emptyli1);						
				emptyul.appendChild(emptyli2);	
				emptyul.appendChild(emptyli3);	
				
				
				$('favorites_content').appendChild(empty);

				return;

			}
			
			for (var i=0; i<myObject.programScheduleList.length; i++) {	
			
				show = myObject.programScheduleList[i];
			
				channelNum = myObject.programScheduleList[i].channelNum;
				channelName = this.rig.channelCollection[channelNum].channelName;
				channelLink = this.rig.channelCollection[channelNum].channelLink;
				
				fav = document.createElement('div');
				fav.className = 'fav';

				favleft = document.createElement('div');
				favleft.className = 'fav-left';

				var adjustTime = 1000 * 60 * 60 * rig.timezoneOffset;

				programStartTime = show.startTime;
				parsedProgramStartTime = new Date(programStartTime.substring(0,4),(programStartTime.substring(5,7)-1),programStartTime.substring(8,10),programStartTime.substring(11,13),programStartTime.substring(14,16));
				parsedProgramStartTime.setTime(parsedProgramStartTime.getTime() - adjustTime);				
				formattedProgramStartTime = parsedProgramStartTime.formatDate("g:i A");

				programEndTime = show.endTime;
				parsedProgramEndTime = new Date(programEndTime.substring(0,4),(programEndTime.substring(5,7)-1),programEndTime.substring(8,10),programEndTime.substring(11,13),programEndTime.substring(14,16));
				parsedProgramEndTime.setTime(parsedProgramEndTime.getTime() - adjustTime);				
				formattedProgramEndTime = parsedProgramEndTime.formatDate("g:i A");
				
				$('favorites_content').appendChild(fav);
				fav.appendChild(favleft);
				time = document.createElement('p');
				time.className = 'time';
				time.innerHTML = formattedProgramStartTime + ' - ' + formattedProgramEndTime;
				favleft.appendChild(time);
				
				pgm_img = document.createElement('img');
				pgm_img.src = '/images/channels/logos/large/' + channelNum + '.jpg';
				favleft.appendChild(pgm_img);
				
				showname = document.createElement('p');
				showname.className = 'show-name';
				showname.innerHTML = "<a href='" + channelLink + "'>" + channelName + "</a><br/><a href='" + channelLink + "'>XM " + channelNum + "</a>";
				favleft.appendChild(showname);
				
				favright = document.createElement('div');
				favright.className = 'fav-right';
				
				showtitle = document.createElement('p');
				showtitle.className = 'show-title';
				showtitle.innerHTML = show.epgProgram.name;
				
				showinfo = document.createElement('p');
				showinfo.className = 'show-info';
				showinfo.innerHTML = show.epgProgram.description;
				
				viewpage = document.createElement('p');
				viewpage.className = 'view-page';
				viewpage.innerHTML = '<a href="' + show.showLink + '">View Show Page</a>';
				
				favright.appendChild(showtitle);
				favright.appendChild(showinfo);	
				
				if (show.showLink != undefined) {	
					favright.appendChild(viewpage);
				}

				remove = document.createElement('div');	
				remove.className = 'remove';
				remove_img = document.createElement('img');	
				
				
				var programName = show.epgProgram.name.replace("'", "\\&apos;");	
				programName = programName.replace("\"", "&quot;", "gi");		
				
				if(typeof show.epgProgram.series != 'undefined')
					groupID = show.epgProgram.series.programGroupId.toString();
				else
					groupID = "null";			

				if (saved_favorite_series_array.in_array(groupID)) {	
					remove_action = "showRemoveSeriesConfirm('" + groupID + "','" +  programName + "');";
					remove_img_html = '<img style="cursor:pointer; cursor: hand" src="/images/epg/btn/remove_series.gif" onClick="' + remove_action + '">';
				}
				
				else {	
					remove_action = "showRemoveShowConfirm('" + show.scheduleId + "::" + groupID + "','" + programName  + "');";
					remove_img_html = '<img style="cursor:pointer; cursor: hand" src="/images/epg/btn/remove.gif" onClick="' + remove_action + '">';
				}
														
				remove.innerHTML += remove_img_html;
				
				fav.appendChild(favright);
				fav.appendChild(remove);

				
			}
		}
		
		var errFunc = function(t) {
		    alert('Error ' + t.status + ' -- ' + t.statusText);
		}	

		new Ajax.Request('/epg.fav_program_schedules.cfm', {parameters:param_string, onSuccess:handlerFunc, onFailure:errFunc});

	createCookie('saved_favorite_shows',saved_favorite_shows_array, 7);	
	createCookie('saved_favorite_series',saved_favorite_series_array, 7);			
			
} 

function loadFeaturedThisWeek() {
	$('featured_this_week_content').innerHTML = '<img id="featured_this_week_loading" src="/images/epg/main_loading_white.gif">';
	var handlerFunc = function(t) {
		var JSON_string = t.responseText;
		var myObject = eval('(' + JSON_string + ')');

		highlightScheduleList = myObject.highlightScheduleList;

		$('featured_this_week_content').innerHTML = '<img src="/images/epg/main_loading.gif">';

		$('featured_this_week_content').innerHTML = '';

		if (highlightScheduleList.length==0) {
		
			$('featured_this_week_content').innerHTML = '<br>Highlights for this date are not available yet. Check back soon to see additional highlights.</div>';
		}

		for (var i=0; i<highlightScheduleList.length; i++) {
			var channelNum = highlightScheduleList[i].channelNum;

			var featured_this_week_box = document.createElement('div');
			featured_this_week_box.className = 'featured_this_week_box';
			
			var featured_this_week_left = document.createElement('div');
			featured_this_week_left.className = 'featured_this_week_left';

			var adjustTime = 1000 * 60 * 60 * $F('timezone');
			
			programStartTime = myObject.highlightScheduleList[i].startTime;
			parsedProgramStartTime = new Date(programStartTime.substring(0,4),(programStartTime.substring(5,7)-1),programStartTime.substring(8,10),programStartTime.substring(11,13),programStartTime.substring(14,16));
			parsedProgramStartTime.setTime(parsedProgramStartTime.getTime() - adjustTime);

			formattedProgramStartTime = parsedProgramStartTime.formatDate("g:i A");	
			
			programEndTime = myObject.highlightScheduleList[i].endTime;
			parsedProgramEndTime = new Date(programEndTime.substring(0,4),(programEndTime.substring(5,7)-1),programEndTime.substring(8,10),programEndTime.substring(11,13),programEndTime.substring(14,16));		
			parsedProgramEndTime.setTime(parsedProgramEndTime.getTime() - adjustTime);
			formattedProgramEndTime = parsedProgramEndTime.formatDate("g:i A");				
			
			featured_highlight_time = document.createElement('span');
			featured_highlight_time.className = 'featured_highlight_time';			
			featured_highlight_time.innerHTML = formattedProgramStartTime + '&ndash;' + formattedProgramEndTime;
			
			var channel_logo = document.createElement('img');
			channel_logo.src = '/images/channels/logos/large/' + highlightScheduleList[i].channelNum + '.jpg';
			
			var channel_link = document.createElement('a');			
			channel_link.href = rig.channelCollection[channelNum].channelLink;			
			channel_link.innerHTML = rig.channelCollection[channelNum].channelName;
			
			var channel_link2 = document.createElement('a');
			channel_link2.href = rig.channelCollection[channelNum].channelLink;
			channel_link2.innerHTML = 'XM ' + highlightScheduleList[i].channelNum;
			
			var featured_this_week_right = document.createElement('div');
			featured_this_week_right.className = 'featured_this_week_right';
		
			var show_title = document.createElement('h5');
			show_title.innerHTML = highlightScheduleList[i].epgProgram.name;

			var show_desc = document.createElement('p');
			show_desc.innerHTML = highlightScheduleList[i].epgProgram.description;
			
			var show_link = document.createElement('a');
			if (highlightScheduleList[i].epgProgram.showPageLink != undefined) {
				show_link.href = highlightScheduleList[i].epgProgram.showPageLink.url;
			}
			show_link.innerHTML = 'View Show Page';
		
			var pipe1 = document.createElement('span');	
			pipe1.innerHTML = '|';
			pipe1.style.padding = '0px 3px';
		
			var addfav = document.createElement('span');	

			if((isFavoriteShow(highlightScheduleList[i].scheduleId))) {
				addfav.innerHTML = 'Already a Favorite: <a href="/onxm/index.cfm?view=favorites">View My Favorite Shows</a>';
			}
			
			else if (highlightScheduleList[i].epgProgram.series) {
				if (isFavoriteSeries(highlightScheduleList[i].epgProgram.series.programGroupId)) 
					addfav.innerHTML = 'Already a Favorite: <a href="/onxm/index.cfm?view=favorites">View My Favorite Shows</a>';			
				else if (!(isFavoriteSeries(highlightScheduleList[i].epgProgram.series.programGroupId)))
					addfav.innerHTML = '<a onClick="showWeekAddFavoriteShow(' + channelNum + ',' + highlightScheduleList[i].scheduleId + ',' + highlightScheduleList[i].epgProgram.series.programGroupId + ')">Add to My Favorite Shows</a>';
			}
			
			else
				addfav.innerHTML = '<a onClick="showWeekAddFavoriteShow(' + channelNum + ',' + highlightScheduleList[i].scheduleId + ', null)">Add to My Favorite Shows</a>';
			
			
			var featured_this_week_hr = document.createElement('div');
			featured_this_week_hr.className = 'featured_this_week_hr';
			$('featured_this_week_content').appendChild(featured_this_week_box);
			featured_this_week_box.appendChild(featured_this_week_left);
			featured_this_week_left.appendChild(featured_highlight_time);
			featured_this_week_left.appendChild(channel_logo);
			featured_this_week_left.appendChild(document.createElement('br'));
			featured_this_week_left.appendChild(channel_link);
			featured_this_week_left.appendChild(document.createElement('br'));
			featured_this_week_left.appendChild(channel_link2);		
			
			featured_this_week_box.appendChild(featured_this_week_right);	
			featured_this_week_right.appendChild(show_title);
			featured_this_week_right.appendChild(show_desc);

			if (highlightScheduleList[i].epgProgram.showPageLink != undefined) {
				featured_this_week_right.appendChild(show_link);
				featured_this_week_right.appendChild(pipe1);				
			}
			featured_this_week_right.appendChild(addfav);
			$('featured_this_week_content').appendChild(featured_this_week_hr);

		}
	}
	var errFunc = function(t) {
	    alert('Error ' + t.status + ' -- ' + t.statusText);
	}	

	var startDate = selected_date.substring(6,8) + selected_date.substring(4,6) + selected_date.substring(0,4) + '000000';


	var startDate = new Date();
	startDate.setDate(selected_date.substring(6,8));
	startDate.setMonth(selected_date.substring(4,6)-1);	
	startDate.setYear(selected_date.substring(0,4));	
	startDate.setHours(0);	
	startDate.setMinutes(0);
	
	var endDate = new Date();
	endDate.setDate(selected_date.substring(6,8));
	endDate.setMonth(selected_date.substring(4,6)-1);	
	endDate.setYear(selected_date.substring(0,4));	
	endDate.setHours(0);	
	endDate.setMinutes(0);

		var tempStartDate = new Date();
		var tempEndDate = new Date();
		
		var timezoneOffset = $F('timezone');
		
		var timeAdjust = 1000 * 60 * 60 * $F('timezone');
		var threeHours = 1000 * 60 * 180;	
	
		start_timezone_array = new Array("00", "01", "02", "03");
		end_timezone_array = new Array("23", "00", "01", "02");
		
		tempStartDate.setTime(startDate.getTime() + timeAdjust);
		
		// if the timezone is not eastern, we need the end date to be tomorrow
		if(timezoneOffset == 0) 
			tempEndDate.setTime(tempStartDate.getTime());
		else
			tempEndDate.setTime(tempStartDate.getTime() + (1000 * 60 * 60 * 24));

		var startDate = tempStartDate.formatDate('dmY') + start_timezone_array[timezoneOffset] + '0000';	
		var endDate = tempEndDate.formatDate('dmY') + end_timezone_array[timezoneOffset] + '5900';		
		
	var channel_cat = $F('channel_category');

	if (channel_cat == 'default' || channel_cat == '') {
		channel_string = '';
	}
		
	else {	
		channel_string = rig.categoryCollection[channel_cat].channelArray.join(',');
		channel_string = channel_string.replace(/-/g,"");
	}

	var param_string = 'channelNums=' + channel_string + '&startDate=' + startDate + '&endDate=' + endDate + '&resultCount=100';
	new Ajax.Request('/epg.highlight_schedules.cfm', {parameters:param_string, onSuccess:handlerFunc, onFailure:errFunc});
	

}

function loadFeaturedDates(direction) {
	if (offset >= 7 && direction == 1)
		return;
	else if (offset <= 0 && direction == -1)
		return;	
	offset += (direction * 7);
	var day = new Date();
	
	var innerdivs = '';
	var j = 0;

	for (var i=offset; i < (offset + 7); i++) {
		var day = new Date();
		day.setDate(day.getDate()+i);
		
		if (j==0) {
			border_style = 'border-width: 1px 0px 1px 0px';
		}
		
		else
			border_style = '';
		
		if (day.formatDate('nj') == selected_date || (direction == 0 && i == 0)) {
			innerdivs += '<div id="' + day.formatDate("Ymd") + '" style="background-color: #FFDB05; font-weight: bold; ' + border_style + '" class="dategrid_box" onClick="highlightBox(this.id);loadFeaturedThisWeek();">' + day.formatDate('D') + '<br>' + day.formatDate('n/j') + '</div>';
		}
		else 
			innerdivs += '<div id="' + day.formatDate("Ymd") + '" style=" ' + border_style + '" class="dategrid_box" onClick="highlightBox(this.id);loadFeaturedThisWeek();">' + day.formatDate('D') + '<br>' + day.formatDate('n/j') + '</div>';
			
		j++;	
	}

	$('dategrid_inner').innerHTML = innerdivs;
	
	//if we switch, make sure the current grid date is highlighted
	var gridStart = new Date();
	gridStart.formatDate('Ymd');
	highlightBox(gridStart);	
}

function showWeekAddFavoriteShow(channelID, scheduleID, seriesID) {
	if (navigator.cookieEnabled == 0) {
		showBox('cookiesdisabled');
		return;
	}
	showBox('addfavoriteshow');
	$('show_to_add').value = scheduleID + '::' + seriesID;
	$('series_to_add').value = scheduleID;
	if (seriesID != null) {
		$('series_to_add').value = seriesID;
		$('add_favorite_series_option').disabled = false;
	}
	else {
		$('series_to_add').value = '';
		$('add_favorite_series_option').disabled = true;
	}
}

function addWeekFavoriteShow() {
	hideBox('addfavoriteshow');
	if ($F('add_favorite_show_option') == 'on') {
		saved_favorite_shows_array.push($F('show_to_add'));
		saved_favorite_shows_array = saved_favorite_shows_array.unique();
	}

	else if ($F('add_favorite_series_option') == 'on') {
		saved_favorite_series_array.push($F('series_to_add'));
		saved_favorite_series_array = saved_favorite_series_array.unique();
	}
	createCookie('saved_favorite_shows',saved_favorite_shows_array, 7);	
	createCookie('saved_favorite_series',saved_favorite_series_array, 7);	
	//loadFeaturedThisWeek();
}

