/* begin Page */

/* Google Custom Search Script */

function findByClass(tagName, className) {
    var r = new RegExp('\\b' + className + '\\b');
    var elements = document.getElementsByTagName(tagName);
    for (var i = 0;  i < elements.length;  i++) {
      var e = elements[i];
      if (e.className && r.test(e.className)) {
        return e;
      }
    }
    return null;
  }

  function searchSubmitted() {
    var e;
    if ((e = findByClass('input', 'gsc-input')) != null) {
      if (e.value === '') {
        searchCleared();
      }
    }
  }

  function searchComplete() {
    document.getElementById('cse-results')
      .style.display = 'block';
    document.getElementById('static-content')
      .style.display = 'none';
  }

  function searchCleared() {
    document.getElementById('static-content')
      .style.display = 'block';
    document.getElementById('cse-results')
      .style.display = 'none';
  }

  function init() {

    var cseId = '014745968771449990184:jxenrcfooqa';

    var customSearchControl =
      new google.search.CustomSearchControl(cseId);

    customSearchControl.setResultSetSize(
      google.search.Search.FILTERED_CSE_RESULTSET);

    customSearchControl.setSearchCompleteCallback(
      null, searchComplete);

    var options = new google.search.DrawOptions();
    options.setSearchFormRoot('cse-search-form');

    customSearchControl.draw('cse-results', options);
	
	customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);

    var e;

    if ((e = findByClass('form', 'gsc-search-box')) != null) {
      if (e.addEventListener) {
        e.addEventListener(
          'submit', searchSubmitted, false);
      } else if (e.attachEvent) {
        e.attachEvent(
          'onsubmit', searchSubmitted);
      }
    }

    if ((e = findByClass('input', 'gsc-search-button')) != null) {
      if (e.addEventListener) {
        e.addEventListener(
          'click', searchSubmitted, false);
      } else if (e.attachEvent) {
        e.attachEvent(
          'onclick', searchSubmitted);
      }
    }

    if ((e = findByClass('div', 'gsc-clear-button')) != null) {
      if (e.addEventListener) {
          e.addEventListener(
            'click', searchCleared, false);
      } else if (e.attachEvent) {
        e.attachEvent(
          'onclick', searchCleared);
      }
    }
  }

  google.load('search', '1');
  google.setOnLoadCallback(init, true);
