  
  /* global.js - includes calls used sitewide
  ========================================================================================================================= */ 

  
  function deliverPopDisclaimer( link ) { popupDisclaimer( link ); }    // old function name - go back and clean up all pages (and SWFs) that use this call

  function popupDisclaimer( link )
  {
    var popDisclaimer = window.open( "","disclaimer","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=370,height=210,top=100,left=150,screenX=180,screenY=100" );
    popDisclaimer.document.write( '<html>' );
    popDisclaimer.document.write( '  <head>' );
    popDisclaimer.document.write( '    <title>FamilyFun.com - Disclaimer</title>' );
    popDisclaimer.document.write( '    <scr'+'ipt type="text/javascript">' );
    popDisclaimer.document.write( '      sendTimer = setTimeout( "sendToClientSide()", 1500 ); closeTimer = setTimeout( "window.close()", 45000 );' );    
    popDisclaimer.document.write( '      function sendToClientSide() { window.open( "' + link + '", "_blank", "menubar=yes,toolbar=yes,location=yes,directories=yes,resizable=yes,scrollbars=yes" ); this.focus(); }' );
    popDisclaimer.document.write( '    </scr'+'ipt>' );
    popDisclaimer.document.write( '  </head>' );
    popDisclaimer.document.write( '  <body bgcolor="#FFFFFF" text="#0065CE" link="#FFFF80" vlink="#FFFF80" alink="#FFFF80" leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>' );
    popDisclaimer.document.write( '    <table width="370" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="/Resources/global/ff_disclaimer_top.gif" width="370" height="27" alt="" border="0"></td></tr><tr><td><table width="330" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td><br><FONT FACE="Verdana,sans-serif" SIZE="2" COLOR="#0065CE"><b>The web site you are about to link to is not controlled by FamilyFun.com and different terms of use and privacy policy will apply. By proceeding you agree and understand that FamilyFun.com is not responsible for the site you are about to access.</b></FONT><br><br><FONT FACE="Verdana,sans-serif" SIZE="2" COLOR="red"><b>If the window does not open, <a href="javascript:window.open( \'' + link + '\', \'_blank\', \'menubar=yes,toolbar=yes,location=yes,directories=yes,resizable=yes,scrollbars=yes\' ); clearTimeout( sendTimer );"><FONT FACE="Verdana,sans-serif" SIZE="2" COLOR="red">click here</A></font><FONT FACE="Verdana,sans-serif" SIZE="2" COLOR="red">.</b></font></td></tr></table>' );
    popDisclaimer.document.write( '    </td></tr><tr bgcolor="#ffffff"><td align="center" height="20"><a href="javascript:window.close();"><FONT FACE="Verdana,sans-serif" SIZE="1" COLOR="#006699"><b>Close this window</b></font></a><BR></td></tr></table>' );
    popDisclaimer.document.write( '  </body>' );
    popDisclaimer.document.write( '</html>' );
    popDisclaimer.document.close();
  }



  var hitbox_leaveDailyInPath = false;
  function addHitboxPageView( path, page )        // parameters are optional
  {
    addPageView( path, page );
  }   
      
  
        
  function flashLinkTrack( lid, lpos ) { linkTrack( lid, lpos ); }        // old function name - go back and clean up all pages (and SWFs) that use this call
  
  /* Note: the obj parameter is optional - it represents the object of the element that is clicked on for the Omniture Click Map tool.
   * For more info, see http://dol.online.disney.com/wiki/index.php/Web_Analytics:Link_Tracking */
  function linkTrack( lpos, lid, obj )
  {
    try
    {
      if( obj != undefined ) cto.linkObj = obj;
      cto.linkId = lid;
      cto.linkPosition = lpos;
      cto.linkType = 'o';
      cto.trackLink();
     }
     catch( e ) {}
  } 
  
  
  var pageViewPageName = "",          // for tracking a page name with a different value than the URL (ex: a login page can have "login" or "loginFailed" on the same page)
      pageViewSiteSection = "";       // for tracking a site section with a different value than the URL (ex: JAS apps or Atomz search)
  
  var searchTerm = "",                // for search tracking
      numResults = "";
      
  var debug_FF_Tracking = false;
  
  function addPageView( path, page )        // parameters are optional
  {
    var pageURL = window.location.href + "";      // add "" to convert to string

    if(pageURL.indexOf( "&CMP=" ) != -1)   // takes out campaign code (i.e. ?CMP=ILC-FR7011799234 and &CMP=ILC-FR7011799234)
    {
      var cmpAmp = pageURL.lastIndexOf( "&CMP=" ) + 1;  
      pageURL = pageURL.substring( 0, cmpAmp - 1);
    }
    if(pageURL.indexOf( "?CMP=" ) != -1 )
    {
      var cmpQues = pageURL.lastIndexOf( "?CMP=" ) + 1;
      pageURL = pageURL.substring( 0, cmpQues - 1);
    }
    
    if( !debug_FF_Tracking ) { if( pageURL.indexOf( "familyfun.go.com/" ) == -1 ) return; }   // don't track from test domains 
    
    cto = new CTO();
    cto.contentType = "regular";

    var siteSection = "",
        pageName = "";

    if( pageURL.indexOf( "http://searcha.familyfun.go.com/" ) != -1 || pageURL.indexOf( "http://search.familyfun.go.com/" ) != -1 )         // search
    {
      cto.contentType = "search";
      
      cto.numSearchResults = numResults;
      cto.searchRefinement = "";
      cto.searchType = "ff_reg";
      
      
      siteSection = path = "search";
      if( searchTerm == "" ) 
      {
        pageName = page = "blank";
        cto.internalSearchPhrase = "no_search_entered";
      }
      else if( numResults == "0" )
      {
        pageName = page = "failed";
        cto.internalSearchPhrase = searchTerm;
      }
      else
      {
        pageName = page = "success";
        cto.internalSearchPhrase = searchTerm;
      }
    }
    else if( pageURL.indexOf( "http://jas.familyfun.go.com/arts-and-crafts" ) != -1 || pageURL.indexOf( "http://jas.familyfun.go.com/crafts" ) != -1 )         // craft finder
    {
      if( pageViewPageName != "" ) page = pageName = pageViewPageName;
      else page = pageName = getQuerystringValue( "page" );

      siteSection = "arts_and_crafts:finder";
      path = "CraftFinder";
    }
    else if( pageURL.indexOf( "http://jas.familyfun.go.com/recipefinder" ) != -1 )                                 // recipe finder
    {
      if( pageURL.indexOf( "/recipefinder/search" ) != -1 )
      {
        cto.contentType = "search";

        cto.numSearchResults = numResults;
        cto.searchRefinement = "";
        cto.searchType = "ff_recipe";


        siteSection = path = "search";
        if( searchTerm == "" ) 
        {
          pageName = page = "blank";
          cto.internalSearchPhrase = "no_search_entered";
        }
        else if( numResults == "0" )
        {
          pageName = page = "failed";
          cto.internalSearchPhrase = searchTerm;
        }
        else
        {
          pageName = page = "success";
          cto.internalSearchPhrase = searchTerm;
        }
      }
      else
      {
        if( pageViewPageName != "" ) page = pageName = pageViewPageName;
        else page = pageName = getQuerystringValue( "page" );

        siteSection = "recipes:finder";
        path = "RecipeFinder";
      }
    }
    else if( pageURL.indexOf( "http://jas.familyfun.go.com/guestsubmit" ) != -1 )         // my great idea
    {
      if( pageViewPageName != "" ) page = pageName = pageViewPageName;
      else page = pageName = getQuerystringValue( "action" ) + "_" + getQuerystringValue( "topic_id" );

      siteSection = "my_great_idea";
      path = "MyGreatIdea";
      
      if( pageName == "_" ) path = pageName = "home";
    }
    else if( pageURL.indexOf( "http://familyfun.go.com/cake-recipe-face-off/" ) != -1 )         // cake-recipe-face-off
    {
      pageURL = pageURL.replace( "http://familyfun.go.com/cake-recipe-face-off", "" );
      path = "/cake-recipe-face-off";
      siteSection = "recipes:cake_recipe_face_off";
      if( pageURL.charAt( pageURL.length - 1 ) == "/" )
      {
        page = "index.html";
        pageName = "home";
      }
      else
      {
        var lastSlash = pageURL.lastIndexOf( "/" ) + 1;
        page = pageURL.substring( lastSlash, pageURL.length );
        pageName = pageURL.substring( lastSlash, pageURL.length - 5 ).replace(/-/g,"_");
        if ( pageName == "index" )
        {
          pageName = "home";
        }
      }        
    }       
    else if( pageURL.indexOf( "http://jas.familyfun.go.com/" ) != -1 ) { return; }                                 // ignore all other JAS apps
    else                                                                                  // static content
    {          
      // if this function was called with no parameters, use javascript to gather the values from the browser URL
      if( path == null || page == null )
      {
        pageURL = pageURL.replace( "http://familyfun.go.com", "" );
        pageURL = pageURL.replace( "http://zaxxon.online.disney.com:88", "" );      // for Production Manager environment
        pageURL = pageURL.replace( "http://zaxxon.online.disney.com", "" );         // for Production Manager environment

        if( pageURL.indexOf( "?" ) != -1 ) pageURL = pageURL.substring( 0, pageURL.indexOf( "?" ) );

        if( pageURL.charAt( pageURL.length - 1 ) == "/" )
        {
          path = pageURL;
          page = "index.html";
        }
        else
        {        
          var lastSlash = pageURL.lastIndexOf( "/" ) + 1;
          path = pageURL.substring( 0, lastSlash );
          page = pageURL.substring( lastSlash, pageURL.length );        
        }


        // if page is a daily, remove "/Daily/mmddyyyy/" from the path
        var dailyIndex = path.indexOf( "/Daily/" ),
            date;
        if( dailyIndex != -1 )                                      
        {
          var dailyPath = path.substring( dailyIndex, dailyIndex + 15 );        
          path = path.replace( dailyPath, "" );        
        }       
      }
      
      siteSection = path.substring( 1, path.lastIndexOf( "/" ) );
      pageName = "";

      if( path.split( "/" ).length <= 4 ) pageName = "home";
      else 
      {
        contentNameIndex = siteSection.lastIndexOf( "/", siteSection.length - 1 );      
        pageName = siteSection.substring( contentNameIndex + 1, siteSection.length ).split( "-" ).join( "_" ).toLowerCase();
        siteSection = siteSection.substring( 0, contentNameIndex );      
      }

      siteSection = siteSection.split( "/" ).join( ":" ).split( "-" ).join( "_" ).toLowerCase();

      /* FILTER SPECIAL CASES */    
      if( pageName == "fftv_archive_video_player" )
      {
        siteSection = "video";
        pageName = "player";
      }
      else if( siteSection == "holidays" && pageName == "home" )
      {
        siteSection = "";
        pageName = "holidays";
      }
      else if( siteSection.indexOf( "Resources") == 1 )
      {
        siteSection = "resources";
      }
      else
      {
        siteSection += ":";       // add marker for easy filtering    

        if( siteSection.indexOf( ":feature:" ) != -1 ) siteSection = siteSection.replace( ":feature:", ":" );
        else if( siteSection.indexOf( ":specialfeature:" ) != -1 ) siteSection = siteSection.replace( ":specialfeature:", ":" );
        else if( siteSection.indexOf( ":minisite2:" ) != -1 ) siteSection = siteSection.replace( ":minisite2:", ":" );
        else if( siteSection.indexOf( ":minisite:" ) != -1 ) siteSection = siteSection.replace( ":minisite:", ":" );

        if( siteSection.indexOf( "utilities:" ) == 0 ) siteSection = "utilities:";

        siteSection = siteSection.replace( ":season:", ":holiday:" );
        siteSection = siteSection.replace( ":holiday_seasonal:", ":holiday:" );
        siteSection = siteSection.replace( ":special:", ":holiday:" );

        siteSection = siteSection.substring( 0, siteSection.length - 1 );

        if( siteSection.length == 1 ) siteSection = "";
      }
      /* END FILTERING */
    }    
    
    if( pageViewPageName != "" ) page = pageName = pageViewPageName;
    pageName = pageName.split( "-" ).join( "_" ).split( "+" ).join( "_" ).toLowerCase();

    cto.h.mlc = path;
    cto.h.pageName = page;
    cto.account = "familyfuncom";
    cto.category = "dfam";
    cto.site = "ffn";
    cto.siteSection = siteSection;
    cto.pageName = pageName;
    cto.property = "ffn";
    
    cto.track();    
  }
  


  function openAsset( url )   // open asset in new window (smaller than default 800x600 size) - return false so the link that is clicked on doesn't go anywhere
  {
     window.open( url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400,left=150,top=100,screenX=150,screenY=100' ); 
     return false;
  }
  
  
  
  // utility
  function getQsValue( name ) { return getQuerystringValue( name ); }
  function getQuerystringValue( name )
  { 
    var value;

    try { value = unescape( location.search.match( new RegExp( name + "=+([^&]*)" ) )[ 1 ] ); } 
    catch( e ) { value = ""; } 

    return value;
  }



  function sendToPrinter()
  {
    if( window.print ) 
    { window.print(); } 
    else 
    { alert( 'Sorry, your browser does not support this feature.  Please try printing from the File menu of your browser.' ); }
  }



  var chromeEnabled = true;
  var chromeLinks = [
        [ "Great Ideas and Parent Advice: ", "Disney Family.com", "http://family.go.com/?CMP=BAC-E9T116847203" ],
        [ "Find Super-Useful Craft Sites: ", "Family 1000", "http://family.go.com/entertainment/article-210804-Super-Useful-Crafts-Sites-t/?CMP=BAC-LT1953720925" ]
      ];
  
  function insertFamilyChrome()
  {
    if( chromeEnabled )
    {
      var chromeOutput = '<link rel="stylesheet" href="http://familyfun.go.com/Resources/familyfun2005/css/familyChrome.css" type="text/css">';    // output will be collected here
        
      chromeOutput += '<tr><td colspan="3" id="FC_container"><div id="FC_leftBorder"><img src="http://familyfun.go.com/Resources/images/family-chrome/corner_lt.gif" width="12" height="24" border="0"></div><div id="FC_textContainer"><div id="FC_text">';
      
      for( i = 0; i < chromeLinks.length; i++ )
      {
        chromeOutput += chromeLinks[ i ][ 0 ] + '<a target="_blank" href="' + chromeLinks[ i ][ 2 ] + '" onclick="linkTrack( \'chrome\', \'' + chromeLinks[ i ][ 1 ] + '\' );">' + chromeLinks[ i ][ 1 ] + '</a>';
         
        if( i < ( chromeLinks.length - 1 ) )
          chromeOutput += '&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;';
      }
      
      chromeOutput += '</div></div><div id="FC_rightBorder"><img src="http://familyfun.go.com/Resources/images/family-chrome/corner_rt.gif" width="12" height="24" border="0"></div></td></tr>';
        
      //document.write( chromeOutput );
      //document.write('<scr' + 'ipt type="text/javascript" language="JavaScript" src="http://family.go.com/js/chrome.js"></scr' + 'ipt>');
    }    
  }
  
  
  var belowTheFoldAdActive = false;
  
  function insertBelowTheFoldAdSlug_top()
  {
    if( belowTheFoldAdActive )
    { 
      document.write( '              <!-- googleoff: all -->' );
      document.write( '               <table width="738" height="90" border="0" cellpadding="0" cellspacing="0">' );
      document.write( '                 <tr>' );
      document.write( '                   <td width="10"><img src="http://adimages.go.com/ad/sponsors/slug/family/ad_slug_SuperBanner_728x90.gif" alt="728x90" width="10" height="90" border="0" /></td>' );
      document.write( '                   <td>' );
    }
  }
  
  function insertBelowTheFoldAdSlug_bottom()
  {
    if( belowTheFoldAdActive )
    {
      document.write( '                   </td>' );
      document.write( '                 </tr>' );
      document.write( '               </table>' );
      document.write( '               <!-- googleon: all -->' );
    }
  }

  var cliffHangerAdActive = false;
  
  function insertCliffHangerAdSlug_top()
  {
    if( cliffHangerAdActive )
    { 
      document.write( '              <!-- googleoff: all -->' );
      document.write( '               <div id="cliffhangerAdSlug"><img src="http://adimages.go.com/ad/sponsors/slug/family/ad_slug_skyscraper_120x600_cropped.gif" width="70" height="10" ></div>' );
    }
  }

  function insertCliffHangerAdSlug_bottom()
  {
    if( cliffHangerAdActive )
    {
      document.write( '               <!-- googleon: all -->' );
    }
  }




  // the code below is for running surveys accross the site  
  document.write( '<script type="text/javascript" src="http://familyfun.go.com/Resources/javascripts/cookies.js"></script>' );
  document.write( '<script type="text/javascript" src="http://familyfun.go.com/Resources/javascripts/survey.js"></script>' );
  
  
  function regPageURL(linkText) {
    var redirectURL;
    var pageURL = window.location.href + "";
    pageURL = pageURL.replace(/&/g, "%26"); // Replaces all the & with the urlencoded %26
    pageURL = pageURL.replace(/\?/g, "%3F"); // Replaces all the ? with the urlencoded %3F
    redirectURL = "<a href=\"https://family.go.com/accounts/login/?appName=familyfun&redirectUrl=" + pageURL + "\" rel=\"noindex,nofollow\">" + linkText + "</a>";
    return(redirectURL);
  }

  function printRegPageURL(linkText) {
    var redirectURL;
    redirectURL = regPageURL(linkText);
    document.write(redirectURL); 
  }  
  
  function checkForEmptyTextBoxInlineAds()
  {
    // since this version uses InlineReplace tags, check the DOM for empty nodes
    var textADsContainer = document.getElementById( "text_ads_fcom" );
    var textADs = document.getElementById( "text_ads_inner_container" );
    var domTree = textADs.childNodes;

    for( i = 0; i < domTree.length; i++ )
    {
      if( domTree[ i ].nodeName == "DL" )
      {
        var nodeText = domTree[ i ].innerHTML;
        if(( nodeText.replace(/^\s+|\s+$/g, '') != "" )&&(nodeText.indexOf( "<!-- Blank -->" ) == -1))
          textADsContainer.style.display = "block";
      }
    }
  } 
  
  function checkForEmptyInlineAds( adNode, adContainer )
  {
    // since this version uses InlineReplace tags, check the DOM for empty nodes
    var adContainerObj = document.getElementById( adContainer );
    var adNodeObj = document.getElementById( adNode );
    
    var nodeText = adNodeObj.innerHTML;
    if(( nodeText.replace(/^\s+|\s+$/g, '') != "" )&&(nodeText.indexOf( "<!-- Blank -->" ) == -1))
      adContainerObj.style.display = "block";
  }

  function checkForEmptyCsarAd( csarAdType, csarAdContainer ) { 
    if( csarAdType == "TextBox1" ) 
    { 
      // in this case, show the text box ads as long as at least one of them are active 
      if( ( digAdData[ 'TextBox1' ] != undefined && digAdData[ 'TextBox1' ][ 'creative' ][ 'text' ].indexOf( "<!-- Blank -->" ) == -1 ) || 
          ( digAdData[ 'TextBox2' ] != undefined && digAdData[ 'TextBox2' ][ 'creative' ][ 'text' ].indexOf( "<!-- Blank -->" ) == -1 ) || 
          ( digAdData[ 'TextBox3' ] != undefined && digAdData[ 'TextBox3' ][ 'creative' ][ 'text' ].indexOf( "<!-- Blank -->" ) == -1 ) ) 
      { document.getElementById( csarAdContainer ).style.display = 'block'; } 
    } 
    else 
    { 
      if( digAdData[ csarAdType ] != undefined && digAdData[ csarAdType ][ 'creative' ][ 'text' ].indexOf( "<!-- Blank -->" ) == -1 ) 
      { document.getElementById( csarAdContainer ).style.display = 'block'; } 
    } 
  }  