/*
/*	Copyright 2010 Google Inc.
*
*	Licensed under the Apache License, Version 2.0 (the "License");
*	you may not use this file except in compliance with the License.
*	You may obtain a copy of the License at
*
*     	http://www.apache.org/licenses/LICENSE-2.0
*
*	Unless required by applicable law or agreed to in writing, software
*	distributed under the License is distributed on an "AS IS" BASIS,
*	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*	See the License for the specific language governing permissions and
*	limitations under the License
*
*	Reference: http://googleajaxsearchapi.blogspot.com/2010/03/search-form-and-results-on-two.html
*
*/


//loads google search engine

      google.load("search", "1");


      /**
       * Extracts the users query from the URL.
       */ 
      function getQuery() {
        var url = '' + window.location;
        var queryStart = url.indexOf('?') + 1;
        if (queryStart > 0) {
          var parts = url.substr(queryStart).split('&');
          for (var i = 0; i < parts.length; i++) {
            if (parts[i].substr(0, 1) == 'q') {
              return decodeURIComponent(
                  parts[i].split('=')[1].replace(/\+/g, ' '));
            }
          }
        }
        return '';
      }

      function onLoad() {
        // Create a custom search control that uses a CSE restricted to
        // code.google.com
        var customSearchControl = new google.search.CustomSearchControl(
            '017691145399580414372:69j5bpc-j4s');

        // Draw the control in content div
        customSearchControl.draw('results');

        // Run a query
        customSearchControl.execute(getQuery());
      }

      google.setOnLoadCallback(onLoad);
    
