function OnLoad() {
  GSearchLoaded();
  new RawSearchControl();
}

function RawSearchControl() {
  this.searcherform = document.getElementById("searcher");
  this.results = document.getElementById("results");
  this.searchform = document.getElementById("searchform");

  // create map of searchers as well as note the active searcher
  this.activeSearcher = "web";
  this.searchers = new Array();

  // wire up a raw GwebSearch searcher
  var searcher = new GwebSearch();
  searcher.setNoHtmlGeneration();
  searcher.setSearchCompleteCallback(this,
                                     RawSearchControl.prototype.searchComplete,
                                     [searcher]
                                     );
  searcher.setResultSetSize(GSearch.LARGE_RESULTSET);

  this.searchers["web"] = searcher;

  // now, create a search form and wire up a submit and clear handler
  this.searchForm = new GSearchForm(true, this.searchform);
  this.searchForm.setOnSubmitCallback(this,
                                      RawSearchControl.prototype.onSubmit);
  this.searchForm.setOnClearCallback(this,
                                      RawSearchControl.prototype.onClear);





}

/////////////検索終了後…/////////////
RawSearchControl.prototype.computeActiveSearcher = function() {
  this.activeSearcher = "web";
  return;
}
/////////検索ボタンが押されたら…/////////
RawSearchControl.prototype.onSubmit = function(form) {
  this.computeActiveSearcher();
  if (form.input.value) {
    this.searchers[this.activeSearcher].execute(form.input.value);
  }
  return false;
}

RawSearchControl.prototype.onClear = function(form) {
  this.clearResults();
}

/////////検索が成功したら…////////
RawSearchControl.prototype.searchComplete = function(searcher) {
  this.clearResults();// always clear old from the page
  if (searcher.results && searcher.results.length > 0) {// if the searcher has results then process them

    //////HTMLを取得する//////
    var div = createDiv("Result Html", "header");
    //this.results.appendChild(div);
    for (var i=0; i<searcher.results.length; i++) {
      var result = searcher.results[i];
      searcher.createResultHtml(result);
      if (result.html) {
        div = result.html.cloneNode(true);
      } else {
        div = createDiv("** failure to create html **");
      }
      this.results.appendChild(div);//resultsに突っ込む
    }
  }
}

RawSearchControl.prototype.clearResults = function() {
  removeChildren(this.results);
}

//Static DOM Helper Functions
function removeChildren(parent) {
  while (parent.firstChild) {
    parent.removeChild(parent.firstChild);
  }
}
function createDiv(opt_text, opt_className) {
  var el = document.createElement("div");
  if (opt_text) {
    el.innerHTML = opt_text;
  }
  if (opt_className) { el.className = opt_className; }
  return el;
}

GSearch.setOnLoadCallback(OnLoad);// register to be called at OnLoad when the page loads

