function searchWikipedia(str){
  var qword=str;
  var url  ='/wikipedia/getwikipedia.php';
  var pars ='w='+qword;

  strTitle=$("strtmp").value;

  win=new Window({className:"alphacube",width:350,height:200,destroyOnClose:true,recenterAuto:false});
  win.showCenter();
  win.getContent().update("<div align='center'><br><br><img src='/prototype/themes/alphacube/ajax-loader.gif' width=31 height=31><br></div>");
  win.setTitle("Searching....");

  if(qword){
    var myAjax=new Ajax.Request(
      url, 
      {
        method: 'get', 
        parameters: pars, 
        onComplete: function(req){
          if(req.responseText){
            text=get_text("<div style='font-size:xx-small;' align='right'>検索には<a href='#' onClick=location.href='http://wikipedia.simpleapi.net/'>WikipediaAPI</a>を利用しています。</div>"+req.responseText);
            win.getContent().update(text);
            win.setTitle("Wikipediaで 『"+strTitle+"』を検索！");
            //win.setStatusBar("<div style='font-size:xx-small;' align='right'>検索には<a href='#' onClick=location.href='http://wikipedia.simpleapi.net/'>WikipediaAPI</a>を利用しています。</div>");
          }else{
            win.getContent().update("<div align='center'><br>ごめんなさい。<br><br>検索対象の語句が存在しないか、<br>wikipediaへの問い合わせに失敗したっぽいです...orz<br></div>");
            //win.showCenter();
            win.setTitle("Sorry....");
          }
        }
      }
    );
  }
}

function displayAlert(){
  var str=window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text;
  if(str){
    var strtmp=$("strtmp");
    strtmp.value=str;
    if(str!=""){
      searchWikipedia(str);
    }
  }
}

function get_text (text) {
  if(navigator.appVersion.indexOf("KHTML") > -1){
    var esc=escape(text);
    if(esc.indexOf("%u") < 0 && esc.indexOf("%") > -1){
      text=decodeURIComponent(esc);
    }
  }
  return text;
}

