﻿// JScript File

function GetWeekInfo(catID,matchWeek,IsBack)
{
var isContinue = true;
var tmpMatchWeek = matchWeek;
  
switch (IsBack)
{
case 0:
  tmpMatchWeek = 0;
  break;
case 1:
  tmpMatchWeek = matchWeek - (-1);
  matchWeek = matchWeek - (-1);
  break;
default:
  tmpMatchWeek = matchWeek - 1;
  matchWeek = matchWeek - 1;
} 

var ClearCache = false;
if(getQueryParameter("fc") == 'ok')
    ClearCache = true;
$.ajaxSetup({

    cache: false

});

if (matchWeek != 999) {
    var lastWeek = $("#hdnLastWeek").val();
    if (lastWeek < matchWeek || matchWeek == 0)
      return;
}

$.getJSON("/D/Api/GetTeamFiksturInfo.ashx", { categoryID: catId, matchWeek: tmpMatchWeek, cacheInfo: ClearCache, IsBackInfo: IsBack },
  function(res) {
      if (res == null)
          return;
      $("#hdnLastWeek").val(res[10]);
      if (res[10] == matchWeek) {
          $('#btnNext').attr({ src: '/D/i/1/nextgame_btn2.gif' });
      }
      else
          $('#btnNext').attr({ src: '/D/i/1/' + $('#nextImage').val() });


      if (matchWeek == 1) {
          $('#btnPrevious').attr({ src: '/D/i/1/prevgame_btn2.gif' });
      }
      else {

          $('#btnPrevious').attr({ src: '/D/i/1/' + $('#prevImage').val() });
      }
      if (res != null && isContinue) {

          document.getElementById("team1Logo").src = 'http://foto.fanatik.com.tr/news/' + res[7];
          document.getElementById("team2Logo").src = 'http://foto.fanatik.com.tr/news/' + res[8];

          var headerText = res[9]; //"Süper Lig 2009/10 ";
          var headerTextLast = ". Hafta";
          if (catID == 91) {
              headerText = "Euro 2012 Elemeleri A Grubu "
              headerTextLast = ". Maç"
          }
          document.getElementById("MATCHWEEK").innerHTML = headerText + ' ' + res[3] + headerTextLast;
          $('#hMatchWeek').val(res[3]);
          //document.getElementById("hMatchWeek").value = res[3];
          document.getElementById("FIRSTTEAM").innerHTML = res[5];
          document.getElementById("SECONDTEAM").innerHTML = res[6];

          if (res[1] < 0) {
              document.getElementById("FIRSTSCORE").innerHTML = ' - '
              document.getElementById("FIRSTSCORE").className = "macskoru";
          }
          else {
              if (res[11] != "") {
                  document.getElementById("FIRSTSCORE").innerHTML = '<a href="' + res[11] + '" style="cursor:pointer;text-decoration:none;text-align:center;width:65px;float:left;font:bold 20px Arial,Verdana,Helvetica,sans-serif">' + res[1] + ' - ' + res[2] + '</a>';
              }
              else
              { document.getElementById("FIRSTSCORE").innerHTML = res[1] + ' - ' + res[2]; }
              document.getElementById("FIRSTSCORE").className = "macskoru";

          }
          document.getElementById("MATCHDATE").innerHTML = res[0];
          jQuery("#hrefMatchLink").attr("href", res[11]);
          /*if(res[9] == "")
          document.getElementById("MATCHDATE").innerHTML = res[0];
          else
          document.getElementById("MATCHDATE").innerHTML = res[9] + ' Stadı -  ' + res[0];
          */
      }

  });
  return false;
}

function getQueryParameter ( parameterName ) {
  var queryString = window.top.location.search.substring(1);
  var parameterName = parameterName + "=";
  if ( queryString.length > 0 ) {
    begin = queryString.indexOf ( parameterName );
    if ( begin != -1 ) {
      begin += parameterName.length;
      end = queryString.indexOf ( "&" , begin );
        if ( end == -1 ) {
        end = queryString.length
      }
      return unescape ( queryString.substring ( begin, end ) );
    }
  }
  return "null";
} 

