﻿function se(){
  var sFormDiv = document.getElementById("searchForm");
  var ScDiv = document.getElementById("leftSearchControl");

  this.ScControl = new GSearchControl();
  this.searchForm = new GSearchForm(true, sFormDiv);
  this.searchForm.setOnSubmitCallback(this, se.prototype.onSubmit);
  this.searchForm.setOnClearCallback(this, se.prototype.onClear);
  this.ScControl.setResultSetSize(GSearch.LARGE_RESULTSET);

  var ws = new GwebSearch();
  ws.setUserDefinedLabel("　　Web　　");

  var is = new GimageSearch();
  is.setUserDefinedLabel("　　画像　　");

  var vs = new GvideoSearch();
  vs.setUserDefinedLabel("　　動画　　");

  this.ScControl.addSearcher(ws);
  this.ScControl.addSearcher(is);
  this.ScControl.addSearcher(vs);

  var drawOptions = new GdrawOptions();
  drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

  this.ScControl.setNoResultsString(GSearchControl.NO_RESULTS_DEFAULT_STRING);
  this.ScControl.draw(ScDiv,drawOptions);

  // 初期検索キーワードの設定
  //1. location.searchでクエリストリングを取得
  var query = location.search;
  //2. デリミタを削除
  query = query.replace('?','');
  //3. クエリー文字列の取り出し
  var queryarray = query.split('&');
  var wordarray = queryarray[0].split('=');
  var word = wordarray[1];

  word = decodeURI(word);

  if (word){
     this.searchForm.execute(word);
  }else{
     this.searchForm.execute("ニュース");
  }
}

se.prototype.onSubmit = function(form){
  var q = form.input.value;
  if (q && q!= ""){
     this.ScControl.execute(q);
  }
  return false;
}

se.prototype.onClear = function(form){
  this.ScControl.clearAllResults();
  form.input.value = "";
  return false;
}

function OnLoad(){
  new se();
}

GSearch.setOnLoadCallback(OnLoad);
