/*** For Omniture ***/
var spTracking = {

  _accountId: null,
  _category: null,
  _pageName: null,
  _environment: null,

  _guid: null,
  isLoggedIn: false,
  entitlements:null,

  pcode: null,
  cpath: null,
  rsrc: null,
  lsrc: null,

  pageRegion:null,
  _domain:null,
  _browser:null,

  okToDebug: false,

  debugElement: null,

  setPageName: function( pn ){
      this._pageName = pn;
  },

  setCategory: function( cat ){
      this._category = cat;
  },

  setEntitlements: function(){
    var work = new Array();
    var work2= new Array();
    var cookie=getCookieValue("RNPlayer");
    work=cookie.split("SN=");
    work2=work[1].split("&");
    this.entitlements = work2[0];
  },
  getPageName: function(){
    return this._pageName;
  },

  getCategory: function(){
    return this._category;
  },


  getLinkInternalFilters: function(){
      return "javascript:,superpass.real.com,broadband.real.com";
  },
  getCustomMetric: function( cmName, castTo ){
      var cmReturn = this[ cmName ];
      if( ( cmReturn != null ) && ( castTo == 'String' ) ) cmReturn = cmReturn.toString();
      return cmReturn != null?cmReturn:"";
  },
  setCustomMetric: function( cmName, cmValue ){
      if( cmValue.strip != '' ) this[ cmName ] = cmValue;
      return cmValue;
  },
  sendPageView: function( overridesObj, optionsObj ){
      var disableCall = false;
      var persistPreviousOverrides = ( optionsObj && optionsObj.persistPreviousOverrides )? ( optionsObj && optionsObj.persistPreviousOverrides ): false;
      try{
          s = s_gi( this.getAccountId() );
      } catch( e ){ disableCall = true }
      if( !persistPreviousOverrides ) this.setDefaultConfig();
      if( !disableCall ){
          this._setOverrides( overridesObj );
          void( s.t() );
          if( this.okToDebug ) this.debug();
      }
  },
  sendLinkEvent: function( overridesObj, optionsObj ){
      // if i want original data set s.linkTrackVars = ""; and s.linkTrackEvents = "";
      var disableCall = false;
      try{
          s = s_gi( this._accountId );
      } catch( e ){ disableCall = true }
      var linkTypeHash = new Object();
      linkTypeHash[ 'exit' ] = 'e';
      linkTypeHash[ 'download' ] = 'd';
      linkTypeHash[ 'custom' ] = 'o';
      var linkTypeAbbrev = optionsObj.type?linkTypeHash[ optionsObj.type ]:null;
      var linkName =  optionsObj.linkName?optionsObj.linkName:null;
      var ltvString = "eVar18";
      var moreThanOne = false;
      if( !disableCall && optionsObj && overridesObj ){
          s.eVar18 = this._pageName;
          for( var i in overridesObj ){
              s[ i ] = overridesObj[ i ];
              ltvString += "," + i;
              moreThanOne = true;
          }
          if( optionsObj.events ){
              s.linkTrackEvents = optionsObj.events;
              s.events = optionsObj.events;
              ltvString += ",events";
          }
          s.linkTrackVars = ltvString;
           if( linkTypeAbbrev && linkName ){
              void( s.tl( this, linkTypeAbbrev, linkName ) );
           }
      }
  },

  _setOverrides: function( or ){
      for( var i in or ){
          s[ i ] = or[ i ];
      }
  },

  // Event omniture function used when business defines a link action as an EVENT with an eventName
  // eventCode O = custom (standard) Link, E is Exit Link, D download link ---- eventCode,

  defaultTracking: function (eventName, pageRegion, clipTitle, clipID, eventCode){
    if(s==null){
     var s=s_gi(this._accountId);
       this.setDefaultConfig(s);
    }
    var eventNameStr = "nav:";
    var clipStr = "";
    if(eventName != ""){
      s.linkTrackVars="eVar7,eVar10,eVar17,eVar18,eVar37,prop29,events";
      s.events = 'event8';
      eventNameStr += clipTitle?eventName + ":":eventName;
    }else{
      clipStr = this._pageName + ":" + pageRegion + ":";
    }
    var eCode = eventCode?eventCode:"O";
    clipStr += clipTitle?clipTitle:"";
    clipStr += clipID? "|" + clipID:"";
    s.linkTrackEvents="event8";
    s.eVar17 = eventNameStr + clipStr;                                                             // example: carouselClick...
    s.prop18 = eCode + ":" + this._pageName + ":" + pageRegion + ":" + eventNameStr + clipStr;        // example: O:bb11:carousel:carouselClick
    s.prop29 = this._pageName + ":" + pageRegion;                                     //pageregion variable including pagename to distinguish region actions.
    //alert("s.eVar17-eventName: " + eventName + "\ns.prop18: " + s.prop18 + "\nclipStr: " + clipStr + "\ns.pageName: " + s.pageName + "\ns.prop29: " + s.prop29);
    s.tl(this,'o', eventNameStr + clipStr);
    return true;
  }
};