  
  var searchTerm,
      fullQuery,              // full query
      dataUrl,
      baseSearchUrl = "/sitesearch/results/",
      facetsSelected = false,
      totalResults,
      cto;                // for omniture tracking

      
  initializeSearchTracking();
  
  function atomzSearch( query )
  {      
    fullQuery = query = limitSearchTermLength( query );

    dataUrl = "/fun-search/?" + encodeURIComponent( query ).split( "%3D" ).join( "=" ).split( "%3B" ).join( ";" );    // decode = and ; back for the actual service call
    if( query.indexOf( "q1=" ) != -1 ) facetsSelected = true;
    
    FFAddOnLoad( function() {
      dojo.byId( "bottomSiteSearchQuery" ).value = searchTerm;
      
      dojo.xhrGet( {
        url: dataUrl,
        handleAs: "xml",
        load: function( response, ioArgs ) {          
          clearTimeout( stillSearchingReference );
          dojo.byId( "searchResultsHeader" ).innerHTML = "Search Results";
          populateResults( response );
        },
        error: function( response, ioArgs ) {}
      });
      
/*
      // get sponsored results
      dataUrl = "/sponsored-links/?q=" + searchTerm.split( "/" ).join( "" ).split( "&" ).join( "" );    // remove slash and ampersand from sponsored links call
      dojo.xhrGet( {
        url: dataUrl,
        handleAs: "xml",
        load: function( response, ioArgs ) {
          populateSponsoredResults( response );
        },
        error: function( response, ioArgs ) {}
      });
*/      
    }, true);
  }
  
  
  function populateResults( response )
  {
    var output = "",
        featuredPick,
        sortItems,
        results,
        facets,
        totalPages,
        pages,
        firstResultIndex,
        lastResultIndex;
    
    
    // TOTAL RESULTS
    totalResults = eval( "( response.getElementsByTagName( 'total-results' ) )[ 0 ].childNodes[ 0 ]" + ( dojo.isIE ? ".nodeValue" : ".textContent" ) );
    dojo.byId( "searchResultsFound" ).innerHTML = 'We found ' + totalResults + ( totalResults != 1 ? ' results' : ' result' ) + ' for <span id="searchTerm">"' + searchTerm + '"</span>';
    
    trackSearchResults();
    
    if( totalResults != 0 )
    {
      // FEATURED PICK
      output = "";
      featuredPick = response.getElementsByTagName( "featured-pick" );
      
      if( featuredPick.length != 0 )
      {
        var featuredPickLabel = "",
            featuredPickUrl = "",
            featuredPickDescription = "",
            featuredPickThumbnail = "";

        for( i = 0; i < featuredPick[ 0 ].childNodes.length; i++ )
        {        
          switch( featuredPick[ 0 ].childNodes[ i ].tagName )
          {
            case "featured-pick-label":
              featuredPickLabel = eval( "featuredPick[ 0 ].childNodes[ i ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "featured-pick-url":
              featuredPickUrl = eval( "featuredPick[ 0 ].childNodes[ i ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "featured-pick-description":
              featuredPickDescription = eval( "featuredPick[ 0 ].childNodes[ i ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "featured-pick-thumbnail":
              featuredPickThumbnail = eval( "featuredPick[ 0 ].childNodes[ i ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
          }
        }          

        if( featuredPickThumbnail != null && featuredPickThumbnail != "" ) output += '<div id="featuredPickThumbnail"><a href="' + featuredPickUrl + '"><img border="0" src="' + featuredPickThumbnail + '" class="bordered_image" /></a></div>';
        output += '<div id="featuredPickText">';
        output += '  <div id="featuredPickHeader">Featured Pick</div>';
        output += '  <div id="featuredPickTitle"><a href="' + featuredPickUrl + '">' + featuredPickLabel + '</a></div>';
        output += '  ' + featuredPickDescription;
        output += '</div>';
        output += '<br clear="all">';
      
        dojo.byId( "featuredPick" ).innerHTML = output;        
        dojo.byId( "featuredPick" ).style.display = "block";
      }

      
      // SORT BY
      output = "Sort by: &nbsp; ";
      sortItems = response.getElementsByTagName( "sort-item" );

      var label,
          link;

      for( i = 0; i < sortItems.length; i++ )
      {
        label = "";
        link = "";

        for( k = 0; k < sortItems[ i ].childNodes.length; k++ )
        {        
          switch( sortItems[ i ].childNodes[ k ].tagName )
          {
            case "label":            
              label = eval( "sortItems[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "link":
              link = eval( "sortItems[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );

              if( i != 0 ) { output += ' &nbsp;&nbsp;|&nbsp;&nbsp; '; }

              if( sortItems[ i ].getAttribute( "selected" ) == "true" )
                output += label;
              else
                output += '<a href="' + baseSearchUrl + filterSearchQuery( link ) + '">' + label + '</a>';

              break;
          }
        }      
      }    

      if( output != "Sort by: &nbsp; " ) 
      {
        dojo.byId( "sortBy" ).innerHTML = output;        
        dojo.byId( "sortBy" ).style.display = "block";
      }


      // SEARCH RESULTS    
      output = "";
      results = response.getElementsByTagName( "result" );

      var title,
          url,
          description,
          rating,
          category,
          contentType,
          smallThumb;

      for( i = 0; i < results.length; i++ )
      {
        title = "";
        url = "";
        description = "";
        rating = "";
        contentType = "";
        smallThumb = "";

        for( k = 0; k < results[ i ].childNodes.length; k++ )
        {     
          switch( results[ i ].childNodes[ k ].tagName )
          {
            case "index":
              lastResultIndex = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              if( i == 0 ) firstResultIndex = lastResultIndex;            
              break;
            case "result-title":
              title = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "url":
              url = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "blurb":
              description = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "category":
              category = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "content-type":
              contentType = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              if( contentType != "Your Solutions" ) {
                if( contentType.indexOf( "s" ) == contentType.length - 1 ) contentType = contentType.substring( 0, contentType.length - 1 );
              }
              break;
            case "small-thumbnail-img":
              smallThumb = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
            case "rating":
              rating = eval( "results[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
              break;
          }
        }

        output += '<dl class="searchResult">';
        if( smallThumb != "" ) output += '  <dd class="searchResultThumb"><a href="' + url + '"><img border="0" alt="' + title + '" src="' + smallThumb + '" class="bordered_image" /></a></dd>';
        output += '  <dd class="searchResultMeta">';
        output += '    <ul>';
        output += '      <li class="searchResultMetaContentType">' + contentType + '</li>';  
        if( rating != "" ) output += '      <li class="searchResultMetaRating">' + getRatingOutput( rating ) + '</li>';  
        output += '    </ul>';
        output += '  </dd>';
        output += '  <dt><a href="' + url + '" class="searchResultTitle">' + title + '</a></dt>';
        output += '  <dd class="searchResultDescription' + ( smallThumb == "" ? "_wide" : "" ) + '">' + decodeDescription( description ) + '</dd>';
        output += '  <dd class="searchResultDottedLine"></dd>';
        output += '</dl>';
        output += '<br clear="all"/>';
      }

      dojo.byId( "results" ).innerHTML = output;


      // FACETS
      output = "";
      facets = response.getElementsByTagName( "facet-item" );

      var count,
          itemCount,
          selected,
          selectedCount = 0,
          selectedOutput = "",
          yourSelectionsLabel,
          undoLink,
          outputRestorePoint;

      // label & link are already defined above
      for( i = 0; i < facets.length; i++ )
      {
        label = "";
        link = "";
        count = "";
        itemCount = 0;
        selected = "false",
        yourSelectionsLabel = "";
        undoLink = "";

        outputRestorePoint = output;
        output += '<div class="graybox_160">';

        for( k = 0; k < facets[ i ].childNodes.length; k++ )
        { 
          switch( facets[ i ].childNodes[ k ].tagName )
          {
            case "facet-title":
              output += '  <div class="resultGroup">';
              output += '    <div class="resultGroupTitle">' + eval( "facets[ i ].childNodes[ k ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) ) + '</div>';
              output += '  </div><div class="narrowResultDottedLine"></div>';
              break;
            case "facet-value":
              for( n = 0; n < facets[ i ].childNodes[ k ].childNodes.length; n++ )
              {     
                switch( facets[ i ].childNodes[ k ].childNodes[ n ].tagName )
                {
                  case "selected":                
                    selected = eval( "facets[ i ].childNodes[ k ].childNodes[ n ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );                  
                    break;
                  case "undolink":                
                    undoLink = eval( "facets[ i ].childNodes[ k ].childNodes[ n ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                    break;                
                  case "label":
                    label = eval( "facets[ i ].childNodes[ k ].childNodes[ n ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                    break;
                  case "link":
                    link = eval( "facets[ i ].childNodes[ k ].childNodes[ n ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                    break;
                  case "count":
                    count = eval( "facets[ i ].childNodes[ k ].childNodes[ n ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                    if( count != "" ) count = ' (' + count + ')';

                    itemCount++;
                    if( itemCount == 4 && facetsSelected ) { output += '<div id="moreSection' + i + '" class="moreSection">'; }            

                    output += '  <div class="resultLinkContainer" onclick="linkTrack( \'searchFilter_' + filterForTracking( label ) + '\', \'searchFilter\', this ); window.location.href = \'' + baseSearchUrl + filterSearchQuery( link ) + '\';" onmouseover="highlightResultLink( this );" onmouseout="unhighlightResultLink( this );">';
                    output += '    <div class="resultLinkBullet"></div><div class="resultLink"><a href="' + baseSearchUrl + filterSearchQuery( link ) + '?type=filter">' + label + '</a>' + count + '</div><br clear="all"/>';
                    output += '  </div>';

                    break;
                }
              }

              if( selected == "true" )
              { 
                selectedCount++;
                selected = "false"; 
                if( label != "" ) yourSelectionsLabel = label;
                output = outputRestorePoint;  // This item is selected already so we don't want to show it as a selectable facet.  Instead we will show it as a facet to remove
              }
              break;
          }
        }

        if( yourSelectionsLabel == "" )
        {
          if( itemCount > 3 && facetsSelected )
          {
            output += '</div>';

            output += '<div class="showMoreSpacer"></div>';
            output += '<div class="showMore" id="showMore' + i + '" onclick="showMore( \'' + i + '\' );" onmouseover="highlightResultLink( this );" onmouseout="unhighlightResultLink( this );">';
            output += '  <div class="showMoreIcon"></div><div class="resultLink"><a href="javascript: showMore( \'' + i + '\' );">Show More</a></div><br clear="all"/>';
            output += '</div>';
            output += '<div class="showLess"id="showLess' + i + '" onclick="showLess( \'' + i + '\' );" onmouseover="highlightResultLink( this );" onmouseout="unhighlightResultLink( this );">';
            output += '  <div class="showLessIcon"></div><div class="resultLink"><a href="javascript: showLess( \'' + i + '\' );">Show Less</a></div><br clear="all"/>';
            output += '</div>';        
          }

          output += '</div><div class="graybox_160_bottom"></div>';

          if( i != facets.length - 1 ) { output += '<div class="narrowResultsSpacer"></div>'; }
        }
        else
        {    
          if( selectedCount == 1 )
          {
            selectedOutput += '<div class="graybox_160">';
            selectedOutput += '  <div class="resultGroup_yourSelections">';
            selectedOutput += '    <div class="resultGroupTitle">Your Selections</div>';
            selectedOutput += '  </div><div class="narrowResultDottedLine"></div>';          
          }

          selectedOutput += '<div class="narrowedSelection" onclick="linkTrack( \'searchFilter_remove_' + filterForTracking( label ) + '\', \'searchFilter\', this ); window.location.href = \'' + baseSearchUrl + filterSearchQuery( undoLink ) + '\';" onmouseover="highlightResultLink( this );" onmouseout="unhighlightResultLink( this );">';
          selectedOutput += '  ' + yourSelectionsLabel + ' - <a href="' + baseSearchUrl + filterSearchQuery( undoLink ) + '?type=filter_remove">remove</a>';
          selectedOutput += '</div>';

          yourSelectionsLabel = "";
        }
      }

      if( selectedCount != 0 ) 
      {
        selectedOutput += '</div><div class="graybox_160_bottom"></div>';
        selectedOutput += '<div class="narrowResultsSpacer"></div>';
        dojo.byId( "yourSelections" ).innerHTML = selectedOutput;
      }
      else
      {
        dojo.byId( "narrowInstructions" ).innerHTML = 'To filter your search results, select a filter below.<div class="narrowResultsSpacer"></div>';
        dojo.byId( "narrowInstructions" ).style.display = "block";
      }

      if( totalResults != 0 && output != "" ) dojo.byId( "facets" ).innerHTML = output;      


      if( totalResults > 1 )
      {
        // PAGINATION
        output = "";
        totalPages = eval( "( response.getElementsByTagName( 'total-pages' ) )[ 0 ].childNodes[ 0 ]" + ( dojo.isIE ? ".nodeValue" : ".textContent" ) );
        pages = response.getElementsByTagName( "page" );    

        var position,
            positionUrl,
            pagesOutput = "",
            prevUrl = "",
            nextUrl = "";

        output += '<span class="current_page">Showing ' + ( totalPages > 1 ? firstResultIndex + '-' + lastResultIndex + ' of ' : '' ) + totalResults + ' results</span>';
        output += '<ul class="pagination">';
        
        if( totalPages > 1 )
        {
          for( i = 0; i < pages.length; i++ )
          {
            position = pages[ i ].getAttribute( "position" );

            switch( position )
            {
              case "first":
              case "last":
              case "viewall":
                break;
              case "prev":
                prevUrl = eval( "pages[ i ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                break;
              case "next":
                nextUrl = eval( "pages[ i ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                break;
              default:
                if( pages[ i ].getAttribute( "selected" ) == "true" ) 
                  pagesOutput += '<li>' + position + '</li>';
                else
                {
                  positionUrl = eval( "pages[ i ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );                                
                  pagesOutput += '<li><a class="fontGreen" href="' + baseSearchUrl + filterSearchQuery( positionUrl ) + '">' + position + '</a></li>';
                }
                break;
            }
          }

          if( prevUrl != "" ) output += '  <li><a class="paginationBackOn" href="' + baseSearchUrl + filterSearchQuery( prevUrl ) + '"></a></li>';
          else output += '  <li class="paginationBackOff"></li>';

          output += pagesOutput;

          if( nextUrl != "" ) output += '  <li><a class="paginationNextOn" href="' + baseSearchUrl + filterSearchQuery( nextUrl ) + '"></a></li>';
          else output += '  <li class="paginationNextOff"></li>';
        }
        
        output += '</ul>';
        output += '<div class="clearFloat"/></div>';


        if( pages.length > 0 ) 
        {
          dojo.byId( "searchResultPaginationTop" ).innerHTML = output;
          dojo.byId( "searchResultPaginationBot" ).innerHTML = output;
          dojo.byId( "searchResultPaginationTop" ).style.display = "block";
          dojo.byId( "searchResultPaginationBot" ).style.display = "block";
          
        }
      }
    }
    else
    {
      dojo.byId( "narrowInstructions" ).innerHTML = 'No results were found.<div class="narrowResultsSpacer"></div>';
      dojo.byId( "narrowInstructions" ).style.display = "block";    
    }
  }
  
  
  function populateSponsoredResults( response )
  {    
    var engines = response.getElementsByTagName( 'Engine' );
        topLinksOutput = "",
        bottomLinksOutput = "",
        tempOutput = "",
        title = "",
        baseURI = "",
        redirURI = "",
        abstract = "",
        counter = 0;

    for( var i = 0; i < engines.length; i++ )
    {      
      name = engines[ i ].getAttribute( "name" );

      if( name == "sponsored" )
      {        
        for( var k = 0; k < engines[ i ].childNodes.length; k++ )
        {         
          if( engines[ i ].childNodes[ k ].tagName == "ResultSet" ) 
          { 
            for( var n = 0; n < engines[ i ].childNodes[ k ].childNodes.length; n++ )
            {
              if( engines[ i ].childNodes[ k ].childNodes[ n ].tagName == "Result" )
              {
                for( var q = 0; q < engines[ i ].childNodes[ k ].childNodes[ n ].childNodes.length; q++ )
                {
                  switch( engines[ i ].childNodes[ k ].childNodes[ n ].childNodes[ q ].tagName )
                  {
                    case "Title":
                      title = eval( "engines[ i ].childNodes[ k ].childNodes[ n ].childNodes[ q ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                      break;
                    case "BaseURI":
                      baseURI = eval( "engines[ i ].childNodes[ k ].childNodes[ n ].childNodes[ q ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                      break;
                    case "RedirURI":
                      redirURI = eval( "engines[ i ].childNodes[ k ].childNodes[ n ].childNodes[ q ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );
                      break;
                    case "Abstract":
                      abstract = eval( "engines[ i ].childNodes[ k ].childNodes[ n ].childNodes[ q ]" + ( dojo.isIE ? ".childNodes[ 0 ].nodeValue" : ".textContent" ) );

                      counter++;
                      tempOutput = "";

                      tempOutput += '<div class="sponsoredLinkDescription"><a target="_blank" href="' + redirURI + '">' + encodeSingleQuotes( title ) + '</a> &nbsp; ' + encodeSingleQuotes( abstract ) + ' &nbsp; <a target="_blank" href="' + redirURI + '">' + encodeSingleQuotes( baseURI ) + '</a></div>';
                      tempOutput += '<div class="sponsoredLinkSeparator"></div>';
                      
                      if( counter < 4 ) { topLinksOutput += tempOutput; }
                      else if( counter < 6 ) { bottomLinksOutput += tempOutput; }

                      break;
                  }
                }
              }
            }
          }
        }
      }
    }
    
    // for spacing, strip out the final <div class="sponsoredLinkSeparator"></div> for each sponsored links section
    topLinksOutput = topLinksOutput.substring( 0, topLinksOutput.lastIndexOf( '<div class="sponsoredLinkSeparator"></div>' ) );
    bottomLinksOutput = bottomLinksOutput.substring( 0, bottomLinksOutput.lastIndexOf( '<div class="sponsoredLinkSeparator"></div>' ) );
    
    if( topLinksOutput != "" )
    {      
      dojo.byId( "topSponsoredLinks" ).innerHTML = topLinksOutput;
      dojo.byId( "topSponsoredLinksContainer" ).style.display = "block";
    }
    
    if( bottomLinksOutput != "" )
    {
      dojo.byId( "bottomSponsoredLinks" ).innerHTML = bottomLinksOutput;
      dojo.byId( "bottomSponsoredLinksContainer" ).style.display = "block";
    }
  }
  
  
  function limitSearchTermLength( query )             // also sets global var searchTerm
  {
    var queryParams = query.split( ";" ),
        term = "";
    
    for( i = 0; i < queryParams.length; i++ )
    {
      if( queryParams[ i ].indexOf( "q=" ) == 0 )     // make sure we avoid confusion with other parameters that have q= in the pattern (such as sp_q, a special parameter used by atomz)
      {
        searchTerm = checkSearchQueryLength( queryParams[ i ].replace( "q=", "" ) );      // checkSearchQueryLength is defined in global.js
        queryParams[ i ] = "q=" + searchTerm;
      }
    }
    
    return queryParams.join( ";" );
  }  
  
  
  function decodeDescription( description )
  {
    return description.split( "&lt;" ).join( "<" ).split( "&gt;" ).join( ">" );    // we want the description to display HTML tags
  }
  
  
  function filterSearchQuery( query )
  { 
    query = decodeURIComponent( query );
    
    // before encoding, remove ?, swap + with a space, and decode ampersands so they won't be double encoded
    return encodeURIComponent( query.split( "?" ).join( "" ).split( "+" ).join( " " ).split( "%26" ).join( "&" ) ).split( "'" ).join( "%27" ).split( "%" ).join( "%25" ).toLowerCase().split( "~2f" ).join( "%252f" ) + "/";       // atomz returns slashses (/) as ~2F so we encode this as a final step
  }
  
  
  function encodeSingleQuotes( str )  
  { 
    return str.split( "'" ).join( "&rsquo;" );
  }
  
  
  function getRatingOutput( rating )
  {
    var ratingOutput = "";
    rating = parseInt( rating );
    
    for( var i = 1; i < 6; i++ )
    {
      if( rating >= i ) starImg = "orangeStar11x10.gif";
      else starImg = "greyStar11x10.gif";

      ratingOutput += '<img width="11" height="10" src="http://a.dolimg.com/familyfun/assets/images/mainContent/' + starImg + '" />';    
    }
    
    return ratingOutput;
  }


  function initializeSearchTracking()
  {
    try 
    {
      cto = new CTO();

      // account info
      cto.account = "familyfuncom";
      cto.category = "dfam";
      cto.site = "ffn";
      cto.contentType = "search";

      // omniture values
      cto.siteSection = "search";
      cto.pageName = "search";

      //internal search values
      cto.property = "";
      cto.numSearchResults = "";
      cto.searchRefinement = "";
      cto.searchType = "ffn_reg";
      cto.internalSearchPhrase = "";
      cto.disableTrack = "y";
      cto.track(); 
    } 
    catch( err ) {}
  }
  
  
  function trackSearchResults()
  {
    var searchType = getQueryStringValue( "type" );    // function defined in global.js
    if( typeof( searchType ) != "undefined" && searchType != null && searchType != "" ) cto.searchType = "ffn_" + searchType;
    
    cto.pageName = "success";
    if( totalResults == "0" ) cto.pageName = "failed";
    if( window.location.href == "http://familyfun.go.com/sitesearch/results/q=*/" ) cto.pageName = "no_search_entered";

    cto.numSearchResults = totalResults;
    cto.searchRefinement = getSearchRefinement();
    cto.internalSearchPhrase = searchTerm;
    cto.track(); 
  }
  
  
  function getSearchRefinement()
  {
    var queryParams = fullQuery.split( ";" ),
        refinement = "";

    for( i = 0; i < queryParams.length; i++ )
    {
      if( queryParams[ i ].indexOf( "q=" ) == -1 && queryParams[ i ].indexOf( "q" ) == 0 )
      {
        refinement += queryParams[ i ].substring( queryParams[ i ].indexOf( "=" ) + 1, queryParams[ i ].length ) + "_";
      }
    }

    return refinement.substring( 0, refinement.length - 1 );
  }
  
  
  /*****************************************************************************************************/
  /* Front End functions */
  
  function highlightResultLink( node ) { node.style.backgroundColor = '#ffffff'; }
  function unhighlightResultLink( node ) { node.style.backgroundColor = '#f5f4f4'; }


  function showMore( id )
  {
    document.getElementById( 'moreSection' + id ).style.display = 'block';
    document.getElementById( 'showMore' + id ).style.display = 'none';
    document.getElementById( 'showLess' + id ).style.display = 'block';
  }


  function showLess( id )
  {
    document.getElementById( 'moreSection' + id ).style.display = 'none';
    document.getElementById( 'showMore' + id ).style.display = 'block';
    document.getElementById( 'showLess' + id ).style.display = 'none';
  }


  var stillSearchingOutput = "Searching.",
      stillSearchingReference;
  
  function stillSearching()
  {
    dojo.byId( "searchResultsHeader" ).innerHTML = stillSearchingOutput;

    switch( stillSearchingOutput )
    {
      case "Searching.":
        stillSearchingOutput = "Searching..";
        break;
      case "Searching..":
        stillSearchingOutput = "Searching...";
        break;
      case "Searching...":
        stillSearchingOutput = "Searching.";
        break;
    }

    stillSearchingReference = setTimeout( "stillSearching()", 500 );
  }
