﻿
function doPromoClick()
{
	document.location = TopRowPromoLink;
}


function c1(cell,idx)
{
	var c = document.getElementById("lcnc"+idx);
	cell.style.color = "#0000FF";
	cell.style.textDecoration = "underline";
    cell.style.backgroundColor = "#FEFFEF";
    if(c){ c.style.backgroundColor = "#FEFFEF"; }
	c = document.getElementById("lcfv"+idx);
    if(c){ c.style.backgroundColor = "#FEFFEF"; }
}

function c2(cell,idx)
{
	var c = document.getElementById("lcnc"+idx);
    cell.style.color = "#000000";
    cell.style.textDecoration = "none";
    cell.style.backgroundColor = "#EDEEDE";
    if(c){ c.style.backgroundColor = "#EDEEDE"; }
	c = document.getElementById("lcfv"+idx);
    if(c){ c.style.backgroundColor = "#EDEEDE"; }
}

function c3(cell,idx)
{
	var c = document.getElementById("lccc"+idx);
	if(c) {
	c.style.color = "#0000FF";
	c.style.textDecoration = "underline";
    c.style.backgroundColor = "#FEFFEF";
    }
    cell.style.backgroundColor = "#FEFFEF";
	c = document.getElementById("lcfv"+idx);
	if(c){c.style.backgroundColor = "#FEFFEF";}
}

function c4(cell, idx)
{
	var c = document.getElementById("lccc"+idx);
	if(c) {
    c.style.color = "#000000";
    c.style.textDecoration = "none";
    c.style.backgroundColor = "#EDEEDE";
    }
    cell.style.backgroundColor = "#EDEEDE";
	c = document.getElementById("lcfv"+idx);
	if(c){c.style.backgroundColor = "#EDEEDE";}
}

function c5(cell, idx)
{
	cell.style.backgroundColor = "#FEFFEF";
	var c = document.getElementById("lccc"+idx);
	c.style.color = "#0000FF";
	c.style.textDecoration = "underline";
    c.style.backgroundColor = "#FEFFEF";
	c = document.getElementById("lcnc"+idx);
    c.style.backgroundColor = "#FEFFEF";
}

function c6(cell, idx)
{
    cell.style.backgroundColor = "#EDEEDE";
	var c = document.getElementById("lccc"+idx);
	if(c) {
    c.style.color = "#000000";
    c.style.textDecoration = "none";
    c.style.backgroundColor = "#EDEEDE";
    }
	c = document.getElementById("lcnc"+idx);
    if(c){c.style.backgroundColor = "#EDEEDE";}
}

function toggleHDTV(obj)
{
	obj.blur();
    if(isOptionsVisible()) { return; }  
	
	if(obj.checked)
	{
        bHDTVOnlyFilter = true;
        countGridAction("HDTV", "On");    	
	}
	else
	{
        bHDTVOnlyFilter = false;
        countGridAction("HDTV", "Off");    
	}
    showLoadingScreen();
    setTimeout("drawListings()", 1);
}


function doProviderChange(objSelect)
{
    if(objSelect.value == "0")
    {
        document.location = "setup/localizeus.aspx?referrerid=0&returnurl=&regMode=0";
        objSelect.blur();
        return;
    }
    
    var iSID = parseFloat(objSelect.value,10);
    if(iSID>0)
    {
        paramServiceID = iSID;
        forceOptionsCreate = true; 
        if((availChannels)&&(selectChannels))
        {
            availChannels.options.length = 0;
            selectChannels.options.length = 0;
        }
        
        objSelect.blur();
        reloadGrid();
    }
}

function doGenreChange(objSelect)
{
    if(objSelect.value!=6)
    { 
        var optsDiv = document.getElementById("GridOptsDiv");
        if(optsDiv)
        {
            if(optsDiv.style.display == "block")
            {
                doGridOpts();
            }
        }
    }

    switch(objSelect.value)
    {
        case "0" :
            bUseKeywordFilter = false;
    		optionFavChannels = false;
            optionGenreFilter = 0;
            iLastGenreValue = 0;
            countGridAction("FilterChange", "All Channels");
            break;
        case "1" :
            bUseKeywordFilter = false;
            var selList = objSelectedChannelsCombo;
            if(selList)
            {
                if(selList.length>0)
                {
                    optionFavChannels = true;
                    optionGenreFilter = 0;
                    iLastGenreValue = 1;
                    countGridAction("FilterChange", "Favorite Channels");
                }
                else
                {
                    objSelect.value = 6;
                    iLastGenreValue = 0;
                    doOptionsTab(1);
                    objSelect.blur();
                    return;
                }
            }
            break; 
        case "2" :
            /* movies filter */
            optionGenreFilter = 2;
            bUseKeywordFilter = false;
    		optionFavChannels = false;
            iLastGenreValue = 2;
            objSelect.blur();
            countGridAction("FilterChange", "Movie Filter");
            break;
        case "3" :
            /* sports filter */
            optionGenreFilter = 3;
            bUseKeywordFilter = false;
    		optionFavChannels = false;
            iLastGenreValue = 3;
            objSelect.blur();
            countGridAction("FilterChange", "Sports Filter");
            break;
        case "4" :
            /* family filter */
            optionGenreFilter = 4;
            bUseKeywordFilter = false;
    		optionFavChannels = false;
            iLastGenreValue = 4;
            objSelect.blur();
            countGridAction("FilterChange", "Family Filter");
            break;
        case "5" :
            /* ppv filter */
            optionGenreFilter = 5;
            bUseKeywordFilter = false;
    		optionFavChannels = false;
            iLastGenreValue = 5;
            objSelect.blur();
            countGridAction("FilterChange", "PPV Filter");
            break;
        case "6" :
            /* news filter */
            optionGenreFilter = 6;
            bUseKeywordFilter = false;
    		optionFavChannels = false;
            iLastGenreValue = 6;
            objSelect.blur();
            countGridAction("FilterChange", "News Filter");
            break;
        case "7":
            /* OLDER KEYWORD FILTER */
            return;            
        default:
            objSelect.value = iLastGenreValue;
            objSelect.blur();
            return;
    }
    
    if(bhasGridData)
    {
	    showLoadingScreen();
	    setTimeout("drawListings()", 1);
    }
    else
    {
        reloadGrid();	    
    }
}

function doTimeSelectChange(select)
{	
	if(select)
	{			
		var strTime = select[select.selectedIndex].value;
		var hrmin = strTime.split(":");

		if (hrmin.length >= 2) {
		    paramGridHour = hrmin[0];
		    paramGridMinute = hrmin[1];
		}
		else {
		    paramGridHour = "-1";
		}
        countGridAction("TimeSelect", select[select.selectedIndex].text);    
    }
	
	var theDiv = document.getElementById("TimeSelectDiv");
	if(theDiv)
	{
	    theDiv.style.visibility = "hidden";
	    theDiv.style.display = "none";	
    }
    select.blur(); 
    
    if(optionDontUseGoButton)
    { 
	    reloadGrid();
    }
}

function doArrowClick(nDirection, nMode)
{
	var timeDelta = iGridSpanMinutes * 60 * 1000 * nDirection;
	var strAction = "ArrowClick";
	var strValue = "";
	
	/* if mode = 1 move ahead/back 24 hrs */
	if(nMode==1)
	{
	    timeDelta = 24* 60 * 60 * 1000 * nDirection;
	    strAction = "DblArrowClick";
	    if(nDirection>0){strValue='Next Day';}
	    else{strValue='Previous Day';}
	}
	else
	{
	    strValue = (parseInt(timeDelta,10)/60000);
	}
	
	dtGridLocalStartTime.setTime(dtGridLocalStartTime.getTime()+timeDelta);

    paramGridYear       = dtGridLocalStartTime.getFullYear();   
    paramGridMonth      = dtGridLocalStartTime.getMonth()+1;
    paramGridDay        = dtGridLocalStartTime.getDate();
    paramGridHour       = dtGridLocalStartTime.getHours();
    paramGridMinute     = dtGridLocalStartTime.getMinutes();
    
    countGridAction(strAction, strValue);

	if(iSingleSourceID>0)
	{
		loadSingleChannel();
	}  
	else
	{
		reloadGrid();   
	}
}

function doDateDropSelect(objDateSelect)
{
    var str = objDateSelect.value;
    var dds = str.split(",");
    paramGridYear = dds[0];     
    paramGridMonth = dds[1];
    paramGridDay = dds[2];
    objDateSelect.blur();
    
    var strValue = '';
    var iDays = objDateSelect.selectedIndex;
    
    switch(iDays)
    {
        case 0:
            strValue = "Yesterday";
            break;
        case 1: 
            strValue = "Today";
            break;
        case 2: 
            strValue = "Tomorrow";
            break;
        default:
            strValue = (iDays-1) + " days ahead"; 
            break;    
    }
    
    countGridAction("DateSelect", strValue);
    
    if(optionDontUseGoButton)
    {    
		if(iSingleSourceID>0)
		{
			loadSingleChannel();
		}  
		else
		{
			reloadGrid();   
		}
	}
}


function doOptionsTab(nTab) 
{
    /* nTab = 0 for PREFERENCES */
    /* nTab = 1 for FAV CHANNELS */
    var optsDiv = document.getElementById("GridOptsDiv");
    var othrDiv = document.getElementById("FavChansDiv");
    
    if(nTab==1)
    {
		/* reverse the "us and them" objects */
		othrDiv = document.getElementById("GridOptsDiv");
        optsDiv = document.getElementById("FavChansDiv");
    }

    var theGrid = document.getElementById("gridDiv");
    var theTBar = document.getElementById("timebarDiv");
    var grdtabs = document.getElementById("gridtabdiv");
    var legend  = document.getElementById("gridLegendDiv");
        
    if ((optsDiv !== null) && (theGrid !== null)) 
    {
        if (optsDiv.style.display != "none") 
        {
			/* enable genre tabs for normal grid only */
			if(iSingleSourceID<=0)
			{
				disableTabs(false,true);
			}
			else
			{
				/* weirdness for Single Source */
				disableTabs(true,false);
				disableNavigation(false);
			}
            /* hide the options panel */
            optsDiv.style.display = "none";

            if(othrDiv)
            {
                othrDiv.style.display = "none";
            }
            
            switch(iCurrentTab)
            {
				case 7:
					if(divSearchResults){divSearchResults.style.display = "block";}
					disableNavigation(true);
					break;
				default:
					theGrid.style.display = "block";
				    legend.style.display = "block";
		            if(theTBar){theTBar.style.display = "block";}
		            break;
            }
	                        			

            countGridAction("Preferences", "Hide");
        }
        else 
        {
            /* show the options panel */

            /* first close flyover */
            getFlyoverInfo(0);

            /* disable tabs */
            /* clearTabCursors(); */
            disableTabs(true,true);

            /* hide non-selected option tab */
            if(othrDiv)
            {
                othrDiv.style.display = "none";
            }
            
            /* hide the grid div */
            /* theGrid.style.visibility = "hidden"; */
            theGrid.style.display = "none";
            
            /* hide the search div */
			if(divSearchResults)
			{divSearchResults.style.display = "none";} 
            
            legend.style.display = "none";

            if (theTBar !== null) {
                theTBar.style.display = "none";
            }
            
            /* now show grid options */
            optsDiv.style.display = "block";
            countGridAction("Preferences", "Show");
        }
    }
}

function doGridOpts()
{
	var optsDiv = document.getElementById("GridOptsDiv");
	var theGrid = document.getElementById("gridDiv");
	var theTBar = document.getElementById("timebarDiv");
	var grdtabs = document.getElementById("gridtabdiv");	
	var legend = document.getElementById("gridLegendDiv"); 
	
	 	
	if((optsDiv)&&(theGrid))
	{	    
		if(optsDiv.style.visibility == "visible")
		{
		    /* enable genre tabs */
            disableTabs(false,true);           

		    /* hide the options panel */
			optsDiv.style.display = "none";
			optsDiv.style.visibility = "hidden";
			if(theTBar)
			{
		        theTBar.style.visibility = "visible";
		        theTBar.style.display = "block";			
		    }
			theGrid.style.visibility = "visible";
			theGrid.style.display = "block";
			
			legend.style.visibility = "visible";
			legend.style.display = "block";
			
            countGridAction("Preferences", "Hide");    
		}
		else 
		{
		    /* show the options panel */
		    
		    /* first close flyover */
            getFlyoverInfo(0);	

            /* disable tabs */
            /* clearTabCursors(); */
            disableTabs(true,true);           
            
		    /* now show grid options */
			theGrid.style.visibility = "hidden";
			theGrid.style.display = "none";	
				
			legend.style.visibility = "hidden";
			legend.style.display = "none";		

			if(theTBar)
			{	
		        theTBar.style.visibility = "hidden";
		        theTBar.style.display = "none";	
		    }		
		    optsDiv.style.visibility = "visible";
		    optsDiv.style.display = "block";
            countGridAction("Preferences", "Show");    
		}
	}
}


function doFixedHeightClick()
{
	setOptionsChanged();
	
	/* enable pixel height selector */
	var subOption = document.getElementById("selGridHeightPx");
	if(subOption)
	{
	    subOption.disabled = false;
	}
	
	/* disable timebar repeat selector */
	subOption = document.getElementById("selTimebarRepeat");
	if(subOption)
	{
	    subOption.disabled = true;
	}

	/* disable repeat selector text */
	subOption = document.getElementById("timeBarRepeatText");
	if(subOption)
	{
	    subOption.style.color = "#999999";
    }
}

function doScrollingGridClick()
{
	setOptionsChanged();
	
	/* enable timebar repeat selector */
	var subOption = document.getElementById("selTimebarRepeat");
	if(subOption)
	{
	subOption.disabled = false;
    }
    
	/* enable repeat selector text */
	subOption = document.getElementById("timeBarRepeatText");
	if(subOption)
	{
    	subOption.style.color = "#000000";
    }
    
	/* disable pixel height selector */
	subOption = document.getElementById("selGridHeightPx");
	if(subOption)
	{
	    subOption.disabled = true;
    }	    
}


function doGoClick(btnGO) 
{
    if (!isOptionsVisible()) 
    {
        if(optionGenreFilter==7)
        {
            tabClick(null, 0);
            /* toggleSearch(false); */
        }
        else
        {
			if(iSingleSourceID>0)
			{
				loadSingleChannel();
			}  
			else
			{
				reloadGrid();   
			}
        }
    }
}

function toggleGoButton(val)
{
    var btnGO = document.getElementById("btnGoButton");
    if(btnGO)
    {
        if(!val)
        {
            btnGO.style.display = "block";
        }
        else
        {
            btnGO.style.display = "none";
        }
    }
}

