
<script type="text/javascript">
  google.load('search', '1');
  
  // the cse class encapsulates a left and right search control
  // both controls are driven by a shared search form
  function cse() {
    var leftScDiv = document.getElementById("gcsSearchControl");

    // create a left, right search control
    // create a custom search form
    this.gcsControl = new google.search.SearchControl();

    // bind clear and submit functions

    // set up for large result sets
    this.gcsControl.setResultSetSize(GSearch.LARGE_RESULTSET);
    this.gcsControl.setLinkTarget(GSearch.LINK_TARGET_SELF);

    var searcher;
    var options;

    // configure left control
    // Site Restrict to CSE ID for Curriculum Search
    var cseId = "005771911645923837355:arphh7vmcnq";
    searcher = new google.search.WebSearch();
    options = new google.search.SearcherOptions();
    searcher.setSiteRestriction(cseId);
    searcher.setUserDefinedLabel("Relevant Pages");
    options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
    this.gcsControl.addSearcher(searcher, options);

    // add the Voyager Dynamic Searcher to the page
    this.voySearcher = new VoyDynamicSearch();
    this.voySearcher.placeSearcher(
      document.getElementById('voy_search_div')
    );

    // draw the left and right controls
    // the right control is drawn in tabbed mode
    var drawOptions = new google.search.DrawOptions();
    drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

    this.gcsControl.draw(leftScDiv);

    // attach "powered by Google" branding
    google.search.Search.getBranding(document.getElementById(
        "google_branding"
    ));

    // execute the search
    var query = '<?php echo trim($_GET['q']); ?>';
    this.gcsControl.execute(query);
    this.voySearcher.execute(query);

  }

  /************************************************************************
   * VoyDynamicSearch
   * (constructor function), DHZ style
   * (I have to make this look somewhat familiar in order to think straight)
   * Dynamic search of voyager store using hidden iframe and jquery calls
   ***********************************************************************/
  VoyDynamicSearch = function() {
    /// general variables---------------------------------------------------
    var _dom_parent = null;
    var _raw_results = null;

    /// methods-------------------------------------------------------------
    this.placeSearcher = function(dom_parent) {
      var _dom_parent = dom_parent;
    }
    this.execute = function(query) {
      /// poll the server and load search results
      // load dynamic hidden iframe
      var hidden_content = 
       document.getElementById('voy_hidden_content').appendChild(
        document.createElement('iframe')
       );
      hidden_content.id = 'hidden_content';
      hidden_content.style.height = '0px';
      hidden_content.style.border = '0px';
      hidden_content.style.padding = '0px';
      hidden_content.src = 'http://www.voyagercomponents.com/store/index.php?main_page=advanced_search_result&search_in_description=1&keyword='+'<?php echo trim($_GET['q']); ?>';
//      hidden_content.src = 'http://localhost/vciSiteTemplate/test/index2.php.html';

      // pull results in and display
      $('#hidden_content').load(function(){       
          // pull results into a variable
          _raw_results = $('#hidden_content').contents().find(
            '#productListing'
          );

          // generate the display content
          var results_qty = _raw_results.find(
            '#productsListingTopNumber>strong:last'
          );
          if (results_qty.html() > 0){
              // write results into google-ish template
              var voy_results_link = $('#voy_results_link');
              voy_results_link.attr('href',hidden_content.src);
              voy_results_link.text(
                results_qty.html()+' Results Found'
              );
              $('#voy_search_stats').text(results_qty.html());
              $('#voy_search_title').text(
                'Voyager Components Inventory Matches'
              );
              $('#voy_results_snippet').html(
//                'Our premier <strong>purchasing</strong> solution<br/>'+
//                '<strong>Exceptional</strong> customer service<br/>'+
//                'Great return <strong>customers</strong>'
                'Order Your Components Online Here'
              );
              $('#voy_results_url').text(hidden_content.src);
              
              // reveal the display element
              $('#voy_results_root').show();
          }
      });
    }
  }

  function OnLoad() {
    new cse();
  }
  google.setOnLoadCallback(OnLoad, true);
</script>

