/*Revision 1.0.2 */
    /* Ajax Game page refresh */
    var gameBoxScoreURL = document.URL;
    var gameBoxScoreArray = gameBoxScoreURL.split('/');
    var gameCodeString = gameBoxScoreArray[6];
    var gameCode = null;
    if (gameCodeString != null){
        gameCode = gameCodeString.split('?');
    }    
    var intervalId = null;
	/*Pop up the scorecast window in Game Page*/
	var scPopupWindow = function(gameCode){		
		$("#tOff").trigger("click");
		var popHref = "/nfl-scorecast?gameCode="+gameCode;		
		popupWin(popHref, "scWin", 930, 615);
	};
	var popupWin = function(url, winName, height, width){		
		aWindow = window.open (url,winName,"location=0,status=0,scrollbars=0,width="+height+",height="+width);
};    
// When no player image found
var noImage = function(){ 
	var imgTrgt = arguments[0];
	{
		var noImgSrc='http://o.aolcdn.com/art/sportsdata/nfl/players/no_image.jpg';
		var noImgSrcSm='http://o.aolcdn.com/art/sportsdata/nfl/players/no_image.jpg';
	}
	if (arguments[1] == 132){$(imgTrgt).attr({src:noImgSrc, alt:"No Photo Available for "+ arguments[2], title:"No Photo Available for "+ arguments[2]});
	}else{$(imgTrgt).attr({src:noImgSrcSm, alt:"No player headshot available", title:"No player headshot available"});}
};
// Ad Refresh on Image Change

 var AdRefresh = function(adSpot) {

    try {
        if (adSpot != null && adSpot != 'undefined' && adSpot != '') {
            top.ch_refresher.refresh_ads_by_spot(adSpot);         
        }
    } catch(e) {}
    return true;
};

var refreshGame = function (divContainer, gameCode, pageRefresh, appendParam){
    if(p_o(arguments[0]) != null){
            $("#"+divContainer+"").load("/"+ pageRefresh +"?gameCode=" + gameCode + appendParam);
            }
};

var refreshSchedule = function (divContainer, pageRefresh, appendParam){
    if(p_o(arguments[0]) != null){
            $("#"+divContainer+"").load("/"+ pageRefresh + (appendParm != null && appendParm != ''? ("/" + appendParam) : ""));
            }
};

var refreshOnload = function(loadObj){
    /* Ajax request for Boxscore summary/gameview */
    clearInterval(intervalId);

    switch (loadObj.id){
        case 'expdVw':
            $("#smryVw").removeClass("selected");
            $("#expdVw").addClass("selected");
            refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-boxscore', '&view=expand');
            if (document.getElementById("gameBoxScore")){intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-boxscore', '&view=expand')",30000);}
        break;
        case 'smryVw':
            $("#expdVw").removeClass("selected");
            $("#smryVw").addClass("selected");
            refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-boxscore', '');
            if (document.getElementById("gameBoxScore")){intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-boxscore', '')",30000);}
        break;
        case 'ptchByPtch':
            refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-playbyplay', '&pitches=true');
            if (document.getElementById("pBpContainer")){intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-playbyplay', '&pitches=true')",30000);}
        break;
        case 'ptchByPly':
            refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-playbyplay', '&pitches=false');
            if (document.getElementById("pBpContainer")){intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-playbyplay', '&pitches=false')",30000);}
        break;  
        case 'inning.0':
            refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-playbyplay', '&show=all');
            if (document.getElementById("pBpContainer")){intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-playbyplay', '&show=all')",30000);}
        break;
        default:
        var inning = loadObj.id.split(".");
            if (inning[1] != null){
                clearInterval(intervalId);
                refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-playbyplay', '&inning='+inning[1]);
            }
        break;
        }
    };



var F;
var browser=navigator.appName;
var ie ='Microsoft Internet Explorer';


var LoadCalendar = function(){
$('#month0,#month1,#month3,#month4,#month5').datePicker({
    createButton:false,
    showYearNavigation:false,
    verticalOffset:"25px",
    horizontalOffset:"0px",
    showHeader:false,
    setDisplayedMonth:false,
    startDate:'01/01/2007',
    displayClose: true
}).css('cursor','pointer').bind('mouseover', function(){
        $(this).addClass('divToggle');
}).bind('mouseout', function(){
        $(this).removeClass('divToggle');
}).bind('click', function(){
            //debugger;
            //$(this).dpSetDisplayedMonth($(this).attr("value"), myYear($(this).attr("value")));
            var month = 1;
            var year = 2008;

            if(document.getElementById("filterDate")){
                    var monthStr = document.getElementById("filterDate").value.split('/')[0];
                    if(monthStr.substring(0,1) == '0'){
                            monthStr=monthStr.substring(1,2);
                            }
                    var yearStr = document.getElementById("filterDate").value.split('/')[2];
                    month = parseInt(monthStr);
                    year = parseInt(yearStr); 

            }
            month-=1;
            $(this).dpSetDisplayedMonth(month, year);
            $(this).dpDisplay();
            $("a.dp-nav-next-month")[0].innerHTML = "Next&nbsp;&gt;";
            $("a.dp-nav-prev-month")[0].innerHTML = "&lt;&nbsp;Prev";
            this.blur();
            return false;
    }
    ).bind('dateSelected',
function(e, selectedDate, $td)
        {
                var slctDate = selectedDate;
                Date.format = "mm/dd/yyyy";
                slctDate = slctDate.asString();
                if(document.getElementById("filterDate")){
                        document.getElementById("filterDate").value = slctDate;
                        var dateStr = document.getElementById("filterDate").value.split("/");
                        document.location="/mlb-scores-and-schedules/"+dateStr[2]+dateStr[0]+dateStr[1]+document.location.search;
                    }
                return(false);
        }
    ).bind('blur',function(){$(this).dpClose();return(false);});
    };
    
/****
    Variables/Arrays used to populate
    the position and stat drop down menus 
*/
var posStatus = new Boolean();
var pitcherOption = new Array(
   {txt:"Select", val:"", a:true, b:false}, 
   {txt:"G", val:"G", a:false, b:false},
   {txt:"GS", val:"GS", a:false, b:false},
   {txt:"W", val:"W", a:false, b:false},
   {txt:"L", val:"L", a:false, b:false},
   {txt:"SV", val:"SV", a:false, b:false},
   {txt:"CG", val:"CG", a:false, b:false},
   {txt:"SHO", val:"SHO", a:false, b:false},
   {txt:"IP", val:"IP", a:false, b:false},
   {txt:"H", val:"H", a:false, b:false},
   {txt:"ER", val:"ER", a:false, b:false},
   {txt:"HR", val:"HR", a:false, b:false},
   {txt:"BB", val:"BB", a:false, b:false},
   {txt:"K", val:"K", a:false, b:false},
   {txt:"ERA", val:"ERA", a:false, b:false},
   {txt:"WHIP", val:"WHIP", a:false, b:false},
   {txt:"BAA", val:"BAA", a:false, b:false});
var standardOption = new Array (
    {txt:"Select", val:"", a:true, b:false},
    {txt:"G", val:"G", a:false, b:false},
    {txt:"AB", val:"AB", a:false, b:false},
    {txt:"R", val:"R", a:false, b:false},
    {txt:"H", val:"H", a:false, b:false},
    {txt:"2B", val:"2B", a:false, b:false},
    {txt:"3B", val:"3B", a:false, b:false},
    {txt:"HR", val:"HR", a:false, b:false},
    {txt:"RBI", val:"RBI", a:false, b:false},
    {txt:"BB", val:"BB", a:false, b:false},
    {txt:"K", val:"K", a:false, b:false},
    {txt:"SB", val:"SB", a:false, b:false},
    {txt:"CS", val:"CS", a:false, b:false},
    {txt:"AVG", val:"AVG", a:false, b:false},
    {txt:"OBP", val:"OBP", a:false, b:false},
    {txt:"SLG", val:"SLG", a:false, b:false},
    {txt:"OPS", val:"OPS", a:false, b:false});

var loadPosStats = function (position) {  
var opt = document.statsFltr; 
	if (position == "Pitcher") {
        for (var i=0; i<pitcherOption.length; i++){
             opt.category[i]=new Option(pitcherOption[i].txt, pitcherOption[i].val, pitcherOption[i].a, pitcherOption[i].b);
         }
         posStatus = false;
	} else {
                if (posStatus == false){
                       for (var j=0; j<standardOption.length; j++){
                        opt.category[j]=new Option(standardOption[j].txt, standardOption[j].val, standardOption[j].a, standardOption[j].b);
                       }
                       posStatus = true;
                }else{
              return false;
          }
         }
};

/**
 * Check expanded state of the search options - playerSearchResults.
 * @return {Boolean} isExp
 */
var checkExpanded = function(){
                var isExp = false;
                if($(".expand").length > 0){
                        if($(".expand")[0].style.display == "inline" || $(".expand")[0].style.display == "block"){
                                isExp = true;					
                        }else{
                                isExp = false;										
                        }
                }
                return isExp;
};

/** 
 * Collapse or expand search options based on expanded state via checkExpaned()
 * go through elem[].  If any elem does not have a classname of "visible" then 
 * toggle the elem to a hidden state.
 * Also toggle the expand an collapse links to the opposite of whatever the are. 
 * @param {Array} elem
 * @see checkExpaned()
 */
var searchCollapseExpand = function(elem){
        var isExpanded = checkExpanded();
        $.each(elem, function(i, n){
                if((n).className.indexOf("visible") == -1)
                {
                        $(n).toggle();
                }
        });
        $(".expand").toggle();
        $(".collapse").toggle();
};

var nflTeamName = "";
function getNflTeamName(){ 
   if($("#team, #teams").val()){
      nflTeamName = $("#team, #teams").val(); 
   } else if($(".persInfo .persInfo1 a").length > 0){
      nflTeamName = $(".persInfo .persInfo1 a")[0].href.substring($(".persInfo .persInfo1 a")[0].href.lastIndexOf("/")+1);
   }
   return nflTeamName;
}
/* onload functions */
onload = function() {
    /**
        Loads popup calendar
    */
            LoadCalendar();
            
    /**
        Loads header channel name highlighter defined in sports_common.js
    */
//            hghLghtCurrChnnl();
    nflTeamName = getNflTeamName();
    if(nflTeamName != ""){
       $("#nflTeamName").html(nflTeamName.replace(/[_-]/g,' '));
       document.nflTeamName = nflTeamName;
    }

$("#nflTeamRoster").bind("click", function() {
  if(nflTeamName != ""){
      window.location="/KOL/2/Sports/NFL/team-roster/"+nflTeamName;
  }
});
$("#nflTeamStats").bind("click", function() {
  if(nflTeamName != ""){
     window.location="/KOL/2/Sports/NFL/team-stats/"+nflTeamName;
  }
});
$("#nflTeamSchedule").bind("click", function() {
  if(nflTeamName != ""){
     window.location="/KOL/2/Sports/NFL/team-schedule/"+nflTeamName;
  }
});
$("#nflTeamScores").bind("click", function() {
  if(nflTeamName != ""){
     window.location="/KOL/2/Sports/NFL/team-scores/"+nflTeamName;
  }
});

    // initialize table sorter for specificied tables 
    $(".stndngs .sortable").tablesorter({
        headers:{0:{sorter:false},7:{sorter:false},8:{sorter:false},9:{sorter:false},10:{sorter:false},11:{sorter:false},12:{sorter:false}}
    });
	
    $(".trnsctions .sortable").tablesorter({
        headers:{}
    });

    $(".stats .sortable").tablesorter({
        headers:{}
    });
    $(".gameLog .sortable").tablesorter({
        headers:{}
    });
    $(".splitStats .sortable").tablesorter({
        headers:{}
    });
    $(".sitStats .sortable").tablesorter({
        headers:{}
    });
    $(".careerStats .sortable").tablesorter({
        headers:{}
    });
    $(".plyrSearch .sortable").tablesorter({
    	headers:{}
    });
    $(".plyrStats .sortable").tablesorter({
    	headers:{}
    });
    $(".teamStats .sortable").tablesorter({
    	headers:{}
    });        
		
/** 
    Actions for Basic Expanded v. Divions Standings toggle
*/
$(".fltrOptns #bscFltr").addClass("selected");
$('#bscFltr').bind("click", function(){
    if (browser == ie){
        $('table').find('.statPrim').css('display', 'block');
    }else{
        $('table').find('.statPrim').css('display', 'table-cell');
    }
    $('table').find('.statSec').css('display', 'none');
    $('table').find('.statTert').css('display', 'none');
    $(".fltrOptns a").removeClass("selected");
    $(".fltrOptns #bscFltr").addClass("selected");

});

$('#expdFltr').bind("click", function(){
    $('table').find('.statPrim').css('display', 'none');
    if (browser == ie){
        $('table').find('.statSec').css('display', 'block');
    }else{
        $('table').find('.statSec').css('display', 'table-cell');}
    $('table').find('.statTert').css('display', 'none');
    $(".fltrOptns a").removeClass("selected");
    $(".fltrOptns #expdFltr").addClass("selected");
});

$('#vsDvsion').bind("click", function(){
    $('table').find('.statPrim').css('display', 'none');
    $('table').find('.statSec').css('display', 'none');
    if (browser == ie){
        $('table').find('.statTert').css('display', 'block');
        $(".fltrOptns a").removeClass("selected");
    	$(".fltrOptns #vsDvsion").addClass("selected");
    }else{
    	$('table').find('.statTert').css('display', 'table-cell');
    	$(".fltrOptns a").removeClass("selected");
    	$(".fltrOptns #vsDvsion").addClass("selected");
	}
});

/* Player Profile Statistical comparison widget events */
$("#s1").click( function() {
	$("#playerComp table").css('display','none');
	$("#tab1").css('display', 'table');
	$("#playerComp a").removeClass('plyrCompOn');
	$("#s1").addClass('plyrCompOn');
});
$("#s2").click( function() {
	$("#playerComp table").css('display','none');
	$("#tab2").css('display', 'table');
	$("#playerComp a").removeClass('plyrCompOn');
	$("#s2").addClass('plyrCompOn');
});
$("#s3").click( function() {
	$("#playerComp table").css('display','none');
	$("#tab3").css('display', 'table');
	$("#playerComp a").removeClass('plyrCompOn');
	$("#s3").addClass('plyrCompOn');
});
$("#s4").click( function() {
	$("#playerComp table").css('display','none');
	$("#tab4").css('display', 'table');
	$("#playerComp a").removeClass('plyrCompOn');
	$("#s4").addClass('plyrCompOn');
});
/* Team Roster events */
$(".rosterFltr #teams").bind("change", function() {
    F=this.form;
        if (F.teams.value ==''){return false;}
    F.action=F.action+'/'+ F.teams.value;F.submit();
});
/* Team Stats events */
$(".teamStatsFltr #teams").bind("change", function() {
    F=this.form;
        if (F.teams.value ==''){return false;}
    F.action=F.action+'/'+ F.teams.value;F.submit();
});
/* Team Depth Chart events */
$(".dpthChrtFltr #teams").bind("change", function() {
    F=this.form;
        if (F.teams.value ==''){return false;}
        if (document.location.search == '?view=graphic'){F.action=F.action+'/'+ F.teams.value +'/depth-chart?view=graphic';}
    	else{F.action=F.action+'/'+ F.teams.value +'/depth-chart';}
    F.submit();

});
/* Team Injuries & Transactions events */
$(".injTransFltr #teams").bind("change", function() {
    F=this.form;
        if (F.teams.value ==''){return false;}
    F.action=F.action+'/'+ F.teams.value +'/injuries-and-transactions/';F.submit();
});


/* Schedule events */
$(".teamSchedFltr #calFltr #month, .teamSchedFltr #calFltr #team, .teamSchedFltr #lstFltr #month, .teamSchedFltr #lstFltr #team").bind("change", function() {
    F=this.form;
        if (F.team.value ==''){return false;}
        if (F.id == 'calFltr'){F.action=F.action+'schedule/'+ F.team.value ;}
        else{F.action=F.action+'schedule/'+ F.team.value +'?view=list';}
        F.submit();

});
$(".teamSchedFltr #calView").bind("click", function() {
        var F = document.getElementById('lstFltr');
        if (F.team.value ==''){return false;}
        F.action=F.action+'schedule/'+ F.team.value;F.submit();
});
$(".teamSchedFltr #lstView").bind("click", function() {
        var F = document.getElementById('calFltr');
        if (F.team.value ==''){return false;}
        F.action=F.action+'schedule/'+ F.team.value +'?view=list';F.submit();
});
/* Team Scores events */
$(".teamScoresFltr #month, .teamScoresFltr #team").bind("change", function() {
        F=this.form;
        if (F.team.value ==''){return false;}
        F.action=F.action+'scores/'+ F.team.value;F.submit();
});

/* Prev/Next Form Actions for Calendar Schedule */
$("#prvMonth").bind("click", function() {
var F=document.getElementById('calMonthSched');F.month.value=(F.month.value*1)-1; F.action=F.action+'/'+ $("#team").val() +'/schedule';F.submit();
});
$("#nxtMonth").bind("click", function() {
var F=document.getElementById('calMonthSched');F.month.value=(F.month.value*1)+1; F.action=F.action+'/'+ $("#team").val() +'/schedule';F.submit();
});


/* Bind Transaction/Injury events to filter form */

$(".trnsctionsFltr #team, .injrysFltr #team, .trnsctionsFltr #month").bind("change", function() {
    F=this.form;F.submit();
});

/* Binds change action to position drop down on stats page*/
$("#position").bind("change", function() {
    F=this.form;loadPosStats(F.position.value);
});

/* Player search text field clears out on focus */
$("#plyrSrch, #playerNameQuery").bind("focus", function () {
if (this.value=='Enter Player Name'){this.value='';this.style.color='#000';}else{this.style.color='#000';this.style.border='1px solid #7F9DB9';}
});

$(".gmtvcov").bind("mouseover", function () {
    var day = "#"+this.id;
    $(day).next(".tvLstng").css('display', 'block');
});
$(".gmtvcov").bind("mouseout", function () {
    $(".tvLstng").css('display', 'none');
    });
    
/* View Stats form Search Submision*/
$("#viewStats").bind("click", function(){
        F=this.form;
	var dt=F.season;
        if (F.categoryType.value ==""){
         alert("Please Select a SubCategory From the Filter");
         return false;
        }
        if (F.category.value ==""){
         alert("Please Select a Stat Type From the Filter");
         return false;
        }
        if (F.viewBy.value ==""){
         alert("Please Select a Group From the Filter");
         return false;
        }
         F.action=F.action+"?season="+F.season.value+"&categoryType="+F.categoryType.value+'&league='+F.league.value+'&category='+F.category.value+'&viewBy='+F.viewBy.value;F.submit();return true;
});

/* Team Stats select actions */
$("#activity").bind("change", function () {
F=this.form;F.action=F.action+'/'+ F.teams.value +'/stats?activity=' + this.value;F.submit();
});

/* Validate and submit player search */
$("#srchPlyrs").bind("click", function(){
F=this.form;if(F.playerNameQuery.value =="Enter Player Name" || F.playerNameQuery.value ==""){$("#playerNameQuery").css("border","1px solid #C90202");$("#playerNameQuery").css("color","#C90202");$("#playerNameQuery").val("Enter Player Name");$("#errorEval").text("Please Enter a Name to Search");return false;}else{F.submit();}
});

$("#selectroster").bind("change", function () {
document.location = "/KOL/2/Sports/NFL/player/" + this.value;
});

/* Player Profile Split stats season filter */
$("#selectseason").bind("change", function() {
document.location = document.location.pathname + "?selectedTab="+document.getElementById("selectedtab").innerHTML+"&season=" + this.value + "#statsNav";
});
/* Events for Scores and Schedules */
$(".scoresSchedFltr #filterDate").bind("keypress", function (e) {

    if (e.which == 13){
    F=this.form;
	var dt=F.filterDate;
	if (isDate(dt.value)==false){
		dt.focus();
		return false;
	}
         if (F.name == 'slctDate'){
             F.action=F.action+"/"+dateFrmtURL;F.submit();return true;
         }
         }
}); 
$(".scoresSchedFltr #season").bind("change",function(){
    F=this.form;F.action=F.action+"?season="+F.season.value+"&seasonType="+F.seasonType.value;F.submit();return true;
});


/* Events for Standings Filter */
$(".stndngsFltr #breakdown").bind("change",function(){
    F=this.form;F.action=F.action+"/"+F.season.value+"?breakdown="+F.breakdown.value;F.submit();return true;
});
$(".stndngsFltr #season").bind("change",function(){
    F=this.form;F.action=F.action+"/"+F.season.value+"?breakdown="+F.breakdown.value;F.submit();return true;
});

    /** look for a collapse-able container on the Player search page */
    if($("form.canCollapse").length)
    {
            $(".expand").toggle();
            searchCollapseExpand($(".plyrSearch form div"));
    }

    /** bind click to collapse link */
    $(".collapse").bind("click", function(){
            searchCollapseExpand($(".plyrSearch form div"));
            return false;
    });

    /**  bind click to expand link */
    $(".expand").bind("click", function(){
            searchCollapseExpand($(".plyrSearch form div"));
            return false;
    });
     /*Make ajax On when page loaded */   
     $("#tOn").addClass("on");   
		/* Initialize Ajax request for Game Boxscore */
         if (document.getElementById("gameBoxScore") ){
              intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-boxscore', '')",30000);
              $("#tOn").addClass("on");
                  $("#tOn").bind("click", function(){
                    refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-boxscore', '');
                    intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-boxscore', '')",30000);
                    $("#tOff").removeClass("on");
                    $("#tOn").addClass("on");
                 });              
             }
 
        
 /* Initialize Ajax request for Game PlayByPlay */
         if (document.getElementById("pBpContainer"))
             {
              intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-playbyplay', '')",30000);    
               $("#tOn").addClass("on");
               $("#tOn").bind("click", function(){
                 refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-playbyplay', ''); 
                 intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-playbyplay', '')",30000);
                    $("#tOff").removeClass("on");
                    $("#tOn").addClass("on");
                 });   
         }

 /* Initialize Ajax request for Score & Schedule page */

        if (document.getElementById("scoresSched")){
            intervalId = setInterval("refreshSchedule('scoresSched', 'KOL/sports/nfl/boxscore.jsp', '')",30000);
               $("#tOn").addClass("on");               
               $("#tOn").bind("click", function(){
                 refreshSchedule('scoresSched', 'KOL/sports/nfl/boxscore.jsp', '');
				 intervalId = setInterval("refreshSchedule('scoresSched', 'KOL/sports/nfl/boxscore.jsp', '')",30000);
                    $("#tOff").removeClass("on");
                    $("#tOn").addClass("on");
                 });
        }

         /* Turn Ajax off */
         $("#tOff").bind("click", function(){
         clearInterval(intervalId);
             $("#tOn").removeClass("on");
             $("#tOff").addClass("on");
         });
         
         /* Turn Ajax On */
         $("#tOn").bind("click", function(){
         clearInterval(intervalId);
             $("#tOff").removeClass("on");
             $("#tOn").addClass("on");
         });
         
         /* Ajax requests for tabbed game pages */
         $("#aPreview").bind("click", function(){
                 AdRefresh('300x250_1');             
                  clearInterval(intervalId);
                  $("#tabSection").find("a").removeClass("selected");
                  $("#tabSection").find("a").addClass("active");
                  $("#tabSection").find("#aPreview").addClass("selected");
                  refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-preview', '');      
            });
         $("#aBox").bind("click", function(){
                  AdRefresh('300x250_1');
                  clearInterval(intervalId);
                  $("#tabSection").find("a").removeClass("selected");
                  $("#tabSection").find("a").addClass("active");
                  $("#tabSection").find("#aBox").addClass("selected");
                  $("#tOn").unbind("click");
                  $("#tOn").bind("click", function(){
                     
                    refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-boxscore', '');
                    intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-boxscore', '')",30000);
                    $("#tOff").removeClass("on");
                    $("#tOn").addClass("on");
                  });
                  refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-boxscore', '');
                  if (document.getElementById("gameBoxScore")){intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-boxscore', '')",30000);}
            });
         $("#aPlay").bind("click", function(){
                 AdRefresh('300x250_1');
                  clearInterval(intervalId);
                  $("#tabSection").find("a").removeClass("selected");
                  $("#tabSection").find("a").addClass("active");
                  $("#tabSection").find("#aPlay").addClass("selected");
                  $("#tOn").unbind("click");
                 $("#tOn").bind("click", function(){
                 clearInterval(intervalId);    
                 refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-playbyplay', ''); 
                 intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-playbyplay', '')",30000);
                    $("#tOff").removeClass("on");
                    $("#tOn").addClass("on");
                 });   
                  refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-playbyplay', '');
                  if (document.getElementById("gameBoxScore")){intervalId = setInterval("refreshGame('gamesPreviewTable', "+gameCode[0]+", 'nfl-game-playbyplay', '')",30000);}
            });
         $("#aRecap").bind("click", function(){
                 AdRefresh('300x250_1');
                  clearInterval(intervalId);
                  $("#tabSection").find("a").removeClass("selected");
                  $("#tabSection").find("a").addClass("active");
                  $("#tabSection").find("#aRecap").addClass("selected");

                  refreshGame('gamesPreviewTable', gameCode[0], 'nfl-game-recap', '');
            });
            
            $(".dblhdrLnk").bind("click", function(){
                var dblHdrId= this.id.split("_");
                    $("#game_"+dblHdrId[1]+"_1").css('display', 'none');
                    $("#game_"+dblHdrId[1]+"_2").css('display', 'block');

            });
             $(".dblhdrLnk2").bind("click", function(){
                var dblHdrId= this.id.split("_");
                    $("#game_"+dblHdrId[1]+"_2").css('display', 'none');
                    $("#game_"+dblHdrId[1]+"_1").css('display', 'block');

            });  
            // Depth chart events
            $("#posP a").addClass("on");
            
            $("#posCF a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#posCF a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=CF&teamName="+teamName);
            });
            $("#posLF a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#posLF a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=LF&teamName="+teamName);
            });
            $("#posRF a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#posRF a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=RF&teamName="+teamName);
            });            
            $("#pos2B a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#pos2B a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=2B&teamName="+teamName);
            });
            $("#posSS a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#posSS a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=SS&teamName="+teamName);
            });
            $("#posP a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#posP a").addClass("on");
            $("#dpthLnup").load("/mlb-teams-depth-chart?position=SP&teamName="+teamName);
            });
            $("#posC a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#posC a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=C&teamName="+teamName);
            });
            $("#pos3B a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#pos3B a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=3B&teamName="+teamName);
            });
             $("#pos2B a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#pos2B a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=2B&teamName="+teamName);
            });
            $("#pos1B a").bind("click", function() {
            $(".dpthChrt a").removeClass("on"); 
            $("#pos1B a").addClass("on");
                $("#dpthLnup").load("/mlb-teams-depth-chart?position=1B&teamName="+teamName);
            });               
            
        };

		var typeOpts = { //{text:"QB Rating",value:"QBRating"},
		offense:[{text:"Passing",value:"passing"},{text:"Receiving",value:"receiving"},{text:"Rushing",value:"rushing"},{text:"Scoring",value:"scoring"},{text:"Kicking",value:"kicking"}],
		defense:[{text:"Sacks",value:"sacks"},{text:"Interceptions",value:"interceptions"},{text:"Tackles",value:"tackles"},{text:"Returning",value:"returning"}],
		'special teams':[{text:"Kicking",value:"kicking"},{text:"Punting",value:"punting"},{text:"Returns",value:"returns"}]
		};	
		function validateParameters(){
			var allSeasons = new Array(7);
   			allSeasons[0] ="2008";
   			allSeasons[1] ="2008 Pre";
   			allSeasons[2] ="2007";
   			allSeasons[3] ="2007 Pre";
   			allSeasons[4] ="2006";
   			allSeasons[5] ="2005";
   			allSeasons[6] ="2004";			
			var allCategory = new Array(3);
   			allCategory[0] = "offense";
   			allCategory[1] = "defense";
   			allCategory[2] = "special teams";
   				var season = document.statsForm.season.value;	
				var x, seasonStatus;
				for(x in allSeasons){
					if(season === allSeasons[x]){
						seasonStatus = true;
						break;
					}					
				}
				if(!seasonStatus){
					return;
				}				
   				var category = document.statsForm.category.value;
				x=0;
				var categoryStatus;
				for(x in allCategory){
					if(category === allCategory[x]){
						categoryStatus = true;
						break;
					}					
				}
				if(!categoryStatus){
					return
				}
   				var allCategoryTypes = getAllCategoryType(category); 				
   				var categoryType = document.statsForm.categoryType.value;
				x=0;
				var allCategoryStatus;
				for(x in allCategoryTypes){
					if(categoryType === allCategoryTypes[x]){
						allCategoryStatus = true;
						break;
					}					
				}
				if(!allCategoryStatus){
					return;
				}
   				var viewBy = document.statsForm.viewBy.value;
				var allViewBy = new Array(2);
   				allViewBy[0] = "Team Stats";
   				allViewBy[1] = "Individual Stats";
				x=0;
				var viewByStatus;
				for(x in allViewBy){
					if(viewBy === allViewBy[x]){
						viewByStatus = true;
						break;
					}					
				}
				if(!viewByStatus){
					return;
				}
   				var league = document.statsForm.league.value; 
				var allLeague = new Array(3);
	   			allLeague[0] = "NFL";
	   			allLeague[1] = "AFC";
   				allLeague[2] = "NFC";
				x=0;
				var leagueStatus;
				for(x in allLeague){
					if(league === allLeague[x]){
						leagueStatus = true;
						break;
					}
				}
				if(!leagueStatus){
					return;
				}
				document.statsForm.action="/nfl-stats";
				document.statsForm.submit();
	}	
	function getAllCategoryType(category)
	 {
	 	var allCategoryType = new Array();
		 if (category === "offense")
		 {
		   allCategoryType[0] = "passing";
		   allCategoryType[1] = "receiving";
		   allCategoryType[2] = "rushing";
		   allCategoryType[3] = "scoring";
		   allCategoryType[4] = "kicking";
		 }
		 else if (category === "defense")
		 {
			   allCategoryType[0] = "sacks";
			   allCategoryType[1] = "interceptions";
			   allCategoryType[2] = "tackles";
			   allCategoryType[3] = "returning";
		 }
		 else if (category === "special teams")
		 {
			 allCategoryType[0] = "kicking";
			 allCategoryType[1] = "punting";
			 allCategoryType[2] = "returns";
		 }
		 return allCategoryType;
	}	
	function refreshOptions(chosen)
	 {
		 var selbox = document.nflStatsForm.categoryType;
		 selbox.options.length = 0;
		 if (chosen == 'offense')
		 {
		   selbox.options[0] = new Option('Passing','passing');
		   selbox.options[1] = new Option('Receiving','receiving');
		   selbox.options[2] = new Option('Rushing','rushing');
		   selbox.options[3] = new Option('Scoring','scoring');
		   selbox.options[4] = new Option('Kicking','kicking');
		 }
		 else if (chosen == 'defense')
		 {
			   selbox.options[0] = new Option('Sacks','sacks');
			   selbox.options[1] = new Option('Interceptions','interceptions');
			   selbox.options[2] = new Option('Tackles','tackles');
			   selbox.options[3] = new Option('Returning','returning');
		 }
		 else if (chosen == 'special teams')
		 {
			 selbox.options[0] = new Option('Kicking','kicking');
			 selbox.options[1] = new Option('Punting','punting');
			 selbox.options[2] = new Option('Returns','returns');
		 }
	}
	
