// JScript File
 var today = new Date();
 
 function ShowMonth( objName ) {
        // scollens 9/26/2007 -- used for HST
       if ((obj=document.getElementById(objName))!=null) 
              obj.style.display = 'block';   
}


function HideMonth( objName ) {
        // scollens 9/26/2007 -- used for HST
       if ((obj=document.getElementById(objName))!=null) 
              obj.style.display = 'none';
}
 
 
function UpdateCalendar_callback(response) {

    var calDiv = document.getElementById("cal");
    //THIS WAS CHANGED FOR HST TO ACCOMODATE STYLES FOR HST, WE NEED TO CHANGE IT FOR COVERS
    var navDiv = document.getElementById("sdi-date-drops");
    var calContainer = document.getElementById("sdi-scores-calendar");
    var confDiv = document.getElementById("conferenceID");
    var calHTML = response.value.CalHTML;
    var navHTML = response.value.NavHTML;
    var scoresRefreshDiv = document.getElementById("scores-note");
    var index = 0;

    if (calHTML.toLowerCase().indexOf("<div id=\"cal\">") == 0)
    {
        calHTML = calHTML.replace(/<div id="cal">/i, "");
        index = calHTML.lastIndexOf("</div>");
        calHTML = calHTML.substring(0, index); 
    }

    if (navHTML.toLowerCase().indexOf("<div id=\"sdi-date-drops\">") == 0)
    {
        navHTML = navHTML.replace(/<div id="sdi-date-drops">/i, "");
        index = navHTML.lastIndexOf("</div>");
        navHTML = navHTML.substring(0, index);
    }
    
//    if (confDiv!=null)
//    {
//        confDiv.innerHTML = response.value.ConferenceHTML;
//    }
    
     if (scoresRefreshDiv!=null)
    {
        scoresRefreshDiv.innerHTML = response.value.ScoresRefreshHTML;
    }

    if (calDiv!=null && navDiv!=null)
    {
        //FIX THIS -- NOT IDEAL SOLUTION
        if(calContainer!=null){ //HST
            calContainer.innerHTML = navHTML + calHTML;
        }else{ //COVERS
            calDiv.innerHTML = calHTML;
            navDiv.innerHTML =  navHTML ;
        }
      
        var ddl = document.getElementById("DropList");
        ddl.value=response.value.CurrentSeason;

        NewScoresFeed(response.value.LeagueID, response.value.SQLDate, response.value.CurrentSeason, 'Matchups', response.value.CurrentWeek )
    }
}

function UpdateDayNav_callback(response){
    var dayNavDiv = document.getElementById("DayNav");
        if (dayNavDiv != null){
            dayNavDiv.innerHTML=response.value;
        }
        //NewScoresFeed(response.value.LeagueID, response.value.SQLDate, response.value.CurrentSeason, 'Matchups', response.value.CurrentWeek )
}



function ClientUpdateSeason(LeagueId){
    var ddl = document.getElementById("DropList");
    var SelectedValue = ddl.value;
    ClientUpdateCalAndNav(LeagueId, SelectedValue, 1, 1, 1, UpdateCalendar_callback);
}

function ClientUpdateCalendar(){
    var ddl = document.getElementById("CalendarList");
    var SelectedValue = ddl.value;
    var arrItem = SelectedValue.split(","); 
    ClientUpdateCalAndNav(arrItem[0], arrItem[1], arrItem[2], arrItem[3], arrItem[4]);
}

function ClientUpdateLastViewedCookie(LeagueId, season, year, month, day){
      Delete_Cookie("LastDayViewed_"+LeagueId);

        //create cookie for the last date the user selected    
        var expires =  1000 * 60 * 15 ;
        var expires_date = new Date( today.getTime() + (expires) );
   
     //  This is a future fix for the Back Button problem - please don't delete
     //   document.cookie = "LastDayViewed_"+LeagueId + "=" +escape( season+"."+year+"."+month+"."+day ) +";expires=" 

     document.cookie = "LastDayViewed_"+LeagueId + "=" +escape( season+"."+year+"."+month+"."+day ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" )

}


function UpdateSelector_callback(selectresponse){
      var selector_data  = selectresponse.value;
      
      
        var hiddenScoreboardTypeId  = document.getElementById("ScoreboardTypeId");
     if (hiddenScoreboardTypeId != null){
        hiddenScoreboardTypeId.value = selector_data.ScoreboardTypeId;
     }
      
    var selectorTitle = document.getElementById("scoreboardSelectorTitle");
          if (selectorTitle != null){
            if(selector_data.ScoreboardTypeId == '3'){
                if (displayLanguage == 'fr-CA')
                {
                    selectorTitle.innerHTML='Choisir Tournoi:';
                }
                else
                {
                    selectorTitle.innerHTML='Choose Tournament:';
                }
                
            }else if(selector_data.ScoreboardTypeId == '2'){
                if (displayLanguage == 'fr-CA')
                {
                    selectorTitle.innerHTML='Choisir Conférence:';
                }
                else
                {
                    selectorTitle.innerHTML='Choose Conference:';
                }
            }
            
        }
    var selectorDiv = document.getElementById("conferenceID");
        if (selectorDiv != null){
            selectorDiv.innerHTML=selector_data.SelectorHTML;
        }
        
}

function ClientUpdateCalAndNav(LeagueId, season, year, month, day){

      var playDate = month + '-' + day + '-' + year;
      
      if(LeagueId == '2' || LeagueId == '7' || LeagueId == '15' || LeagueId == '16'){
      
          var week = '';
          var CalendarList = document.getElementById("CalendarList");
          if (CalendarList != null){
                var arrItem = CalendarList.value.split(","); 
                week = 'week ' + arrItem[3];
          }
          
          var scoreboardTypeID = '';
          var hiddenscoreboardType = document.getElementById("ScoreboardTypeId");
          if (hiddenscoreboardType != null){
                scoreboardTypeID= hiddenscoreboardType.value;
          }
          
          
            var sbID = '';
            var sbName = '';
            var selectedScoreboard;
            var confScoreboard = document.getElementById("confSelect");
            if (confScoreboard != null)
            {   
            
                var selectedScoreboard = confScoreboard.selectedIndex;       
              
                if (selectedScoreboard != null)
                {
                    sbID = confScoreboard.options[selectedScoreboard].value;     
                    sbName = confScoreboard.options[selectedScoreboard].text;       
                }
             }
          
            ScoreboardSelector.UpdateSelector(LeagueId, playDate, scoreboardTypeID, week, sbID, sbName, UpdateSelector_callback);
   
       }


    var calDiv = document.getElementById("CalTable");
     
    if (calDiv != null){
        Delete_Cookie("LastDayViewed_"+LeagueId);

        //create cookie for the last date the user selected    
        var expires =  1000 * 60 * 15 ;
        var expires_date = new Date( today.getTime() + (expires) );
   
     //  This is a future fix for the Back Button problem - please don't delete
     //   document.cookie = "LastDayViewed_"+LeagueId + "=" +escape( season+"."+year+"."+month+"."+day ) +";expires=" 

     document.cookie = "LastDayViewed_"+LeagueId + "=" +escape( season+"."+year+"."+month+"."+day ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" )
        
       ScoresCalendar.changeDay(LeagueId, season, year, month, day, UpdateCalendar_callback);
    }
    var dayNavDiv = document.getElementById("DayNav");
    if (dayNavDiv != null){
      DayNav.updateNav(LeagueId, season, year, month, day, -1 ,UpdateDayNav_callback);
    //}else{
     // ScoresCalendar.updateNav(LeagueId, season, year, month, day, -1 ,UpdateDayNav_callback);
    }
    
  
    
}

function ClientUpdateTeamNav(LeagueId, season, year, month, day, team){
    DayNav.updateNav(LeagueId, season, year, month, day, team, UpdateDayNav_callback);
}





