//======================================================================
// This file contains FPAS/FSI tracking variables and functions
// trackingPath     - this is the tracking code for the page
// trackingPageName - this is the page title
// NOTE: several variables used here are declared in the meta file
//======================================================================

//---------------------------------------------------------------------
//  _stripTrackingValue(a)
//--------------------------------------------------------------------
function _stripTrackingValue(a) {
  a = a.replace(/\s+$/, '');
  a = a.split(",").join("");
  a = a.split("&").join("");
  a = a.split("'").join("");
  a = a.split("#").join("");
  a = a.split("$").join("");
  a = a.split("%").join("");
  a = a.split("^").join("");
  a = a.split("*").join("");
  a = a.split(":").join("");
  a = a.split("!").join("");
  a = a.split("<").join("");
  a = a.split(">").join("");
  a = a.split("~").join("");
  a = a.split(";").join("");
  a = a.split("\\").join("");
  a = a.split(" ").join("+");
  return a;
}

// values set when page first loads
var fsxTracker = new Object();
fsxTracker.trackingPath    = _stripTrackingValue(pagePathValue);
fsxTracker.pageName        = _stripTrackingValue(pageTitleValue);
fsxTracker.pageContentType = _stripTrackingValue(pageContentTypeValue);
fsxTracker.pageSource      = _stripTrackingValue(pageSourceValue);
fsxTracker.pageAuthor      = _stripTrackingValue(pageAuthorValue);
fsxTracker.hitboxAccount   = hitboxAccountNumber;

//---------------------------------------------------------------------
// function to make any needed site tracking calls 
// make this call in the page footer: <script>sendTrackingInfo()</script>
//--------------------------------------------------------------------
function sendTrackingInfo() {
  sendTrackingToHitbox();
  sendTrackingToGoogleAnalytics();
  //sendTrackingToMsnOmniture();
}

//------------------------------------------
// function to set site tracking values
//---------------------------------------------------
function setTrackingValues(path, pageName) {
  setTrackingPath(path);
  setTrackingPageName(pageName);
  return;
}

//-----------------------------------------
// function to set trackingPath value
//---------------------------------------------------
function setTrackingPath(path) {
  fsxTracker.trackingPath = _stripTrackingValue(path);
  return;
}

//-----------------------------------------
// function to set pageName value
//-----------------------------------------------------
function setTrackingPageName(pageName) {
  fsxTracker.pageName = _stripTrackingValue(pageName);
  return;
}


//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// BEGIN variables and functions for tracking accounts
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


//============================================================
// Google analytics 
//============================================================
var googlePageTracker = _gat._getTracker("UA-4869874-1");

//-------------------------------------
// sendTrackingToGoogleAnalytics()
//-------------------------------------------------------
function sendTrackingToGoogleAnalytics() {
  googlePageTracker._trackPageview(fsxTracker.trackingPath);
  return;
}

//-------------------------------------
// sendTrackingNoPageViewToGoogleAnalytics()
//-------------------------------------------------------
function sendTrackingNoPageViewToGoogleAnalytics() {
  var ga_trackingPath = fsxTracker.trackingPath + "/noPageView";
  googlePageTracker._trackPageview(ga_trackingPath);
  return;
}


//=========================================================== 
//=========================================================== 
var _pn    = "";
var _mlc   = "";
var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx    = _hbEvent("pv");hbx.vpc="HBX0100u";hbx.gn="h.foxsports.com";
hbx.pndef  = "title";
hbx.ctdef  = "full";
hbx.fv     = "";
hbx.lt     = "auto"; //LINK TRACKING
hbx.dlf    = "n";
hbx.dft    = "n";
hbx.elf    = "n";
hbx.seg    = "";
hbx.fnl    = "";
hbx.cmp    = "";
hbx.cmpn   = "CMP";
hbx.dcmp   = "";
hbx.dcmpn  = "DCMP";
hbx.dcmpe  = "";
hbx.dcmpre = "";
hbx.hra    = "";
hbx.hqsr   = "";
hbx.hqsp   = "ATT";
hbx.hlt    = "";
hbx.hla    = "";
hbx.gp     = "";
hbx.gpn    = "GP"; 
hbx.hcn    = "";
hbx.hcv    = "";
hbx.cp     = "null";
hbx.cpd    = "";
hbx.pn     = "";
hbx.mlc    = "";

// Hitbox registration additions
//----------------------
// findAge(yr, mon, day, unit, decimal, round)
//------------------------------------------------------
function findAge(yr, mon, day, unit, decimal, round) {
  //Sample usage
  //findAge (year, month, day, unit, decimals, rounding)
  //Unit can be "years", "months", or "days"
  //Decimals specifies demical places to round to (ie: 2)
  //Rounding can be "roundup" or "rounddown"
  //findAge(1997, 11, 24, "years", 0, "rounddown")
  var one_day   = 1000*60*60*24;
  var one_month = 1000*60*60*24*30;
  var one_year  = 1000*60*60*24*30*12;
  today         = new Date();
  var pastdate  = new Date(yr, mon-1, day);
  var countunit = unit;
  var decimals  = decimal;
  var rounding  = round;
  finalunit     = (countunit=="days")? one_day : (countunit=="months")? one_month : one_year;
  decimals      = (decimals<=0)? 1 : decimals*10;
  if (unit != "years") {
    if (rounding=="rounddown")
      return(Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit);
    else
      return(Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit);
  }
  else {
    yearspast = today.getFullYear()-yr-1;
    tail      = (today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0;
    pastdate.setFullYear(today.getFullYear());
    pastdate2 = new Date(today.getFullYear()-1, mon-1, day);
    return(yearspast+tail);
  }
}

//-----------------------
// returnAge()
//-------------------------------------------
function returnAge() {
  var age = -1;
  if (user.MONTH_CODE == "0" || user.MONTH_CODE == "" ||
      user.DATE_CODE  == "0" || user.DATE_CODE  == "" ||
      user.BIRTH_YEAR == "0" || user.BIRTH_YEAR == "") {
  } else {
    var bdayMonth = user.MONTH_CODE;
    var bdayDate = user.DATE_CODE;
    var bdayYear = user.BIRTH_YEAR;
    age = findAge(bdayYear, bdayMonth, bdayDate, "years", 0, "rounddown");
  }
  if (age > 12 && age < 18) { (age = 1); }
  if (age > 17 && age < 25) { (age = 2); }
  if (age > 24 && age < 35) { (age = 3); }
  if (age > 34 && age < 45) { (age = 4); }
  if (age > 44 && age < 55) { (age = 5); }
  if (age > 54 && age < 65) { (age = 6); }
  if (age > 64)             { (age = 7); }
  return age;
}
if (typeof(user.USER_ID) == 'undefined') { user.USER_ID = ''; }

var user_status = "";
if (rme.length > 0) {
  if (user.USER_ID == '0') { (user_status = "No-Log"); }
  else                     { (user_status = "Yes|" + returnAge()); }
} else { 
  (user_status = "Not-Reg"); 
}

//CUSTOM VARIABLES - page variables are created in meta file
if (typeof(user.USER_ID) == 'undefined') { user.USER_ID = ''; }
hbx.ci  = user.USER_ID;
hbx.hc1 = fsxTracker.pageContentType + "|" + fsxTracker.pageSource;
hbx.hc2 = fsxTracker.pageAuthor      + "|" + fsxTracker.pageName;
hbx.hc3 = user_status;
hbx.hc4 = "";
hbx.hrf = "";
hbx.pec = "";
hbx.acct       = fsxTracker.hitboxAccount;
var _acct      = fsxTracker.hitboxAccount;
var _acctMedia = fsxTracker.hitboxAccount;


//-------------------------------
// sendTrackingToHitbox()
//-------------------------------------------
function sendTrackingToHitbox() {
  hbx.pn  = fsxTracker.pageName; // sets the hbx page name
  hbx.mlc = fsxTracker.trackingPath;     // sets the hbx tracking path
  _pn     = fsxTracker.pageName; // sets the hbx page name
  _mlc    = fsxTracker.trackingPath;     // sets the hbx tracking path
  var head     = document.getElementsByTagName('head')[0]; // get the header tag
  var script   = document.createElement('script'); // create a script tag
  script.type  = "text/javascript"; // set the type
  script.src   = "http://msn.foxsports.com/fe/js/hbx.js";   // set the script source
  head.appendChild(script); // place the script on the page
}
//== END Hitbox ==============================================


//---------------------------------
// sendTrackingToMsnOmniture()
//------------------------------------------------
function sendTrackingToMsnOmniture() {
  return;
}

