tvgReferrer='Freeview';
tvgBranding='Freeview';
tvgBroadcaster='BDSFreeview';
tvgRegion='London';
tvgClockStyle='ampm';
tvgFirstChannelNumber=0;
tvgLastChannelNumber=899;
tvgEPGNumberChannels =10;
tvgEPGNumberHours =3;
tvgMagazineNumberChannels =4;
tvgMagazineNumberHours =4;
tvgListingsHeaderText='%dayname% %ordinal% %month% %broadcasteregionpopup%%';
tvgListingsRepeatHeaderAtBottom="YesAndButtons";
tvgListingsAreaWidth=520;
tvgChannelColumnWidth=0;
tvgShowDetailsDiv='tvgShowDetails';
tvgTVSearchDiv='tvgSearchDiv';
tvgShowChannelLogo="Yes";
tvgChannelLogoURL="http://demos.tvgenius.net/freeview/img/logos/small/"; 
tvgListingsDiv='tvgListingCompHidden';
tvgConfirmDiv='tvg_remind_me';
tvgEncoding='UTF-8';
tvgTVSearchURL='search.html';
tvgRepeatSearchNav='Yes';
tvgScrollTimer=10;
tvgScrollStep=20;
tvgDescriptionNumberCharacters=90;
tvgListingsShowMyAllButton='Yes';
tvgSearchSummaryLength = 150;
tvgExactRelatedSearches ='Yes';
tvgListingShowDaysDropDown='Yes';
tvgListingShow24hDropDown='Yes';
tvgIgnoreFavouriteChannels='Yes';
tvgMouseOverNumberCharacters = 100;
tvgFoundText='Freeview found ';
tvgSearchNavAccessible='Yes';

function tvgAjaxPreback(id)
{
switch (id)
    {
    case 'tvgListingCompHidden':

    tvgPrepareScrolling('tvgListingComp');
  
    break;
    default:
    break;
    }
}


function tvgAjaxCallback(id)

    {

    switch (id)

        {

        case 'tvgListingCompHidden':

        tvgImplementScrolling('tvgListingComp');
        try
        {pageTracker._trackPageview("/epgscroll.html" );
        }
        catch (e){}
        

        case 'tvgListingComp':

        tvgClose('tvgShowDetailsWrapper');

        tvgClose('tvgSearchWrapper');

        tvgPreLoadLinks("tvg_listings_nav_next");



        break;

        

        case 'tvgShowDetails':
        try
        {pageTracker._trackPageview("/epgdetails.html" );
        }
        catch (e){}
        
        
        if (document.getElementById('tvg_remind_me_form') == null)
            { 
            document.getElementById('tvgReminder').style.display='block';
            }
        else
         { 
            document.getElementById('tvgReminder').style.display='none';
            }

        var wrapper = document.getElementById('tvgShowDetailsWrapper');

        var box = document.getElementById('tvgDescription');

        wrapper.style.display='none';

        wrapper.style.display='block';

        if (box.style.visibility == 'visible')

        {

            wrapper.style.left = "95px";

            wrapper.style.top = "160px";

            box.style.zIndex=-1;

            }

        else

        {

          

            //position the details box...

            var listingID = tvg_qs.match(/tvgListingID=\d*/);



            var els= document.getElementsByTagName('div');

            for (var i  = els.length -1; i >= 0; i--)

            {

                if (els[i].className.indexOf('tvg_search_result') == 0 | els[i].className.indexOf('tvg_listings_channel_bit') >=0)

                {

                    if (els[i].innerHTML.indexOf(listingID) > 0)

                        {

                        var chann_offset = tvgGetOffset(els[i]);

                        var chan_top = (els[i].offsetTop != undefined) ? parseInt(els[i].offsetTop,10):0;

                

                        //Calculate the offset of the pop-up...

                        var popup_offset = tvgGetOffset(wrapper); 

                        var idealPosition = chann_offset[1] - popup_offset[1] + chan_top - 100;



                        wrapper.style.top = idealPosition + 'px';



                        break;

                        }

                }

            

            }

        }

        break;



        case 'tvgSearchDiv':
        try
        {pageTracker._trackPageview("/epgsearch.html" );
        }
        catch (e){}
        
		
		if (document.getElementById('genres') != undefined)
		{
		document.getElementById('genres').style.display='none';
		}
        document.getElementById('tvgSearchWrapper').style.display='block';
		if (document.getElementById('tvgListingsWrapper') != undefined)
		{
		document.getElementById('tvgListingsWrapper').style.height="0px";
		}
		if (document.getElementById('tvgTextWrapper') != undefined)
		{
		document.getElementById('tvgTextWrapper').style.height="0px";
		}

		document.getElementById('tvgDescription').style.zIndex=1;
		document.getElementById('tvgShowDetailsWrapper').style.display='none';
		

        break;

      case 'tvgTextOnly':

		
		

        break;

        }

    }

function tvgClose(div)

{
    var el = document.getElementById(div);
    
    if (el.style.display != 'none')
        {

       el.style.display='none';

        if (div == 'tvgSearchWrapper')

            {
		    if (document.getElementById('tvgListingsWrapper') != undefined)
			{
			document.getElementById('tvgListingsWrapper').style.height="100%";
			}
			if (document.getElementById('tvgTextWrapper') != undefined)
			{
			document.getElementById('tvgTextWrapper').style.height="100%";
			}
			document.getElementById('genres').style.display='block';
		    tvgClearParameter("tvgPageNumber");
		    tvgClearParameter("tvgSearchPhrase");
		    document.getElementById('tvgDescription').style.zIndex=1;
            }

        if (div == 'tvgShowDetailsWrapper')

            {

            document.getElementById('tvgDescription').style.zIndex=1;
			tvgClearParameter("tvgShowID");
			tvgClearParameter("tvgEpisodeID");

            }

        }
}

function tvgSearchKeyDown(e)

{

if (e.keyCode == 13)

            {

            tvgDoSearch();

            }

 }

function tvgDoSearch()

{

if (tvgVerifySearch('tvgSearchBox'))

    {
    tvgTVSearchDiv='tvgSearchDiv';
    tvgLinkTo('search', 'tvgSearchDiv', '', '?tvgPageNumber=1&tvgEpisodeID=&tvgShowID=&tvgSearchPhrase=' + encodeURIComponent (document.getElementById('tvgSearchBox').value) );

    }

 }
 
var tvgIntervalId = window.setInterval (tvgCheckReminderRemoval, 10000);
 
 function tvgCheckReminderRemoval()
  {
  
  clearInterval(tvgIntervalId);

  if (window.location.search.match("tvgAction="))
      {
      var wrapper = document.getElementById('tvgShowDetailsWrapper');
      var box = document.getElementById('tvgDescription');
      wrapper.style.display='none';
      wrapper.style.display='block';
      wrapper.style.left = "95px";
      wrapper.style.top = "160px";
      box.style.zIndex=-1; 
      var el= document.createElement('div');
      el.id = 'tvg_remind_me';
      el.className = 'tvg_remind_me';
      document.getElementById('tvgShowDetails').appendChild(el);
      document.getElementById('tvgReminder').style.display='none';

      tvgLinkTo('confirm', 'tvg_remind_me', '','');   
      
      
      }
  }
  
