/*

###############################################################################

# Copyright (C) 2001 T.Kimata <t_kimata@nk.rim.or.jp>

# http://www.nk.rim.or.jp/~t_kimata/cgi/

# 

# All rights reserved.

# 

# This software is provided 'as-is', without any express or implied warranty.

# In no event will the authors be held liable for any damages arising from the

# use of this software.

# 

# Permission is granted to anyone to use this software for any purpose,

# including commercial applications, and to alter it and redistribute it

# freely, subject to the following restrictions:

# 

# 1. The origin of this software must not be misrepresented; you must not claim

# that you wrote the original software. If you use this software in a product,

# an acknowledgment in the product documentation would be appreciated but is

# not required.

# 

# 2. Altered source versions must be plainly marked as such, and must not be

# misrepresented as being the original software.

# 

###############################################################################

*/

ENGINES = new Array(

	new Array(

			"MAGMA",

			"http://www.magma.ad.jp/NMZ/namazu.cgi",

			"http://www.magma.ad.jp/NMZ/namazu.cgi?query=%s"

	),

	new Array(

        "Google",

        "http://www.google.com/",

        "http://www.google.com/search?num=100&hl=ja&ie=Shift_JIS&safe=off&q=%s&btnG=Google+%8C%9F%8D%F5&lr=lang_ja"

	),

	new Array(

        "Yahoo",

        "http://www.yahoo.co.jp/",

        "http://search.yahoo.co.jp/bin/search?ei=SJIS&p=%s"

	),

	new Array(

        "Goo",

        "http://www.goo.ne.jp/",

        "http://www.goo.ne.jp/default.asp?MT=%s"

	),

	new Array(

        "Fresheye",

        "http://www.fresheye.com/",

        "http://search.fresheye.com/?kw=%s"

	),

	new Array(

        "Excite",

        "http://www.excite.co.jp/",

        "http://www.excite.co.jp/search.gw?search=%s"

	),

	new Array(

        "Lycos",

        "http://www.lycos.co.jp/",

        "http://www.lycos.co.jp/cgi-bin/pursuit?query=%s"

	),

	new Array(

        "Infoseek",

        "http://www.infoseek.co.jp/",

        "http://www.infoseek.co.jp/Titles?qt=%s"

	),

	new Array(

        "GooE2J",

        "http://dictionary.goo.ne.jp/ej/",

        "http://dictionary.goo.ne.jp/search.php?MT=%s&ej.x=37&ej.y=15&ej=%B1%D1%CF%C2&kind=je&kwassist=0&mode=0"

	),

	new Array(

        "GooJ2E",

        "http://dictionary.goo.ne.jp/je/",

        "http://dictionary.goo.ne.jp/search.php?MT=%s&je.x=13&je.y=7&je=%CF%C2%B1%D1&kind=ej&kwassist=0&mode=0"

	),

	new Array(

        "GooJDic",

        "http://dictionary.goo.ne.jp/jp/",

        "http://dictionary.goo.ne.jp/search.php?MT=%s&jn.x=23&jn.y=13&jn=%B9%F1%B8%EC&kind=jn&kwassist=0&mode=0"

	),

	new Array(

        "GooNJDic",

        "http://dictionary.goo.ne.jp/nw/",

        "http://dictionary.goo.ne.jp/cgi-bin/dict_search.cgi?sw=3&MT=%s"

	),

	new Array(

        "E_Words",

        "http://www.e-words.ne.jp/",

        "http://www.e-words.ne.jp/search.asp?word=%s"

	),

	new Array(

        "GoogleImage",

        "http://images.google.com/",

        "http://images.google.com/images?q=%s"

	),

	new Array(

        "Yomimono",

        "http://www.yomimono.co.jp/",

        "http://www.yomimono.co.jp/mag/search.cgi?default=検索&word=%s"

	),

	new Array(

        "ChanceIt",

        "http://www.chance-it.com/",

        "http://search.chance-it.com/bin/search?p=%s&o=new&g=1"

	),

	new Array(

        "NikkeiNewspaper",

        "http://www.nikkei.co.jp/",

        "http://www3.nikkei.co.jp/kensaku/ichiran.cfm?kwd=%s&action=search"

	),

	new Array(

        "MainichiNewspaper",

        "http://www.mainichi.co.jp/",

        "http://search.mainichi.co.jp/cgi-bin/news/search.cgi?keyword=%s"

	),

	new Array(

        "Rakuten",

        "http://www.rakuten.co.jp/",

        "http://search.rakuten.co.jp/search.cgi?&sitem=%s"

	),

	new Array(

        "YahooShopping",

        "http://shopping.yahoo.co.jp/",

        "http://search.shopping.yahoo.co.jp/search?P=all&p=%s"

	),

	new Array(

        "GooShopping",

        "http://shop.goo.ne.jp/",

        "http://shope.goo.ne.jp/se/servlet/result?_d=%s"

	),

	new Array(

        "NTTXStore",

        "http://store.nttx.co.jp/",

        "http://store.nttx.co.jp/FreeFinder/SearchName.asp?FREE_WORD=%s"

	),

	new Array(

        "YahooAuctions",

        "http://auctions.yahoo.co.jp/jp/",

        "http://search.auctions.yahoo.co.jp/search/auc?p=%s"

	),

	new Array(

        "EBayJapan",

        "http://pages.ebayjapan.co.jp/",

        "http://cq-search.ebayjapan.co.jp/search/search.dll?l&ebaytag1code=104&ebaycurr=6&query=%s"

	),

	new Array(

        "Bidders",

        "http://www.bidders.co.jp/",

        "http://www.bidders.co.jp/dap/sv/list1?at=&keyword=%s"

	),

	new Array(

        "Amazon",

        "http://www.amazon.co.jp/",

        "http://www.amazon.co.jp/exec/obidos/external-search/encoding-string-jp=日本語&tag=cstation-22&keyword=%s"

	),

	new Array(

        "KinokuniyaWasyo",

        "http://bookweb.kinokuniya.co.jp/",

        "http://bookweb.kinokuniya.co.jp/guest/cgi-bin/wshosea.cgi?KEYWORD=%s"

	),

	new Array(

        "KinokuniyaYousyo",

        "http://bookweb.kinokuniya.co.jp/",

        "http://bookweb.kinokuniya.co.jp/guest/cgi-bin/booksea.cgi?W-TITLE=%s"

	),

	new Array(

        "Cbook24Com",

        "http://www.cbook24.com/",

        "http://www.cbook24.com/bm_browsing.asp?browsing_type=search&page=0&searchtoken=%s"

	),

	new Array(

        "ZDNet",

        "http://www.zdnet.co.jp/",

        "http://zdsearch.zdnet.co.jp/index.cgi?query=%s"

	),

	new Array(

        "Impress",

        "http://www.impress.co.jp/",

        "http://search.impress.co.jp/cgi-bin/namazu.cgi?query=%s&idxname=internet&idxname=pc&idxname=forest&idxname=ringo&idxname=akiba&idxname=k-tai&idxname=game&idxname=broadband&idxname=av&idxname=finance&idxname=music&idxname=movie&idxname=sonyfan"

	),

	new Array(

        "ASCII",

        "http://www.ascii.co.jp/",

        "http://www.ascii.co.jp/searchA/namazu.cgi?query=%s&idxname=www.ascii.co.jp"

	),

	new Array(

        "ASCII24",

        "http://ascii24.com/",

        "http://ascii24.com/search/?query=%s"

	),

	new Array(

        "BizTech",

        "http://biztech.nikkeibp.co.jp/",

        "http://bizns.nikkeibp.co.jp/cgi-bin/search/title.cgi?NP_DSPN=20&NP_SHTML=easy&NP_THTML=title-sample&NP_BHTML=bun-sample&NP_SORT=1&NP_KEY1=%s"

	),

	new Array(

        "InternetCom",

        "http://japan.internet.com/",

        "http://japan.internet.com/fsearch/search.cgi?key=%s&index=japan"

	),

	new Array(

        "AtmarkIT",

        "http://www.atmarkit.co.jp/",

        "http://www.atmarkit.co.jp/search_exec.shtml?query=%s&searchtype=all"

	),

	new Array(

        "Vector",

        "http://www.vector.co.jp/",

        "http://www.isize.com/computer/cgi-bin/down_search_index.cgi?word=%s&psearch_mode=1&page_no=1&plt=all"

	),

	new Array(

        "Madonomori",

        "http://www.forest.impress.co.jp/",

        "http://search.impress.co.jp/cgi-bin/forest/library/namazu.cgi?query=%s"

	),

	new Array(

        "Ringonomori",

        "http://www.forest.impress.co.jp/ringo/",

        "http://search.impress.co.jp/cgi-bin/ringo/library/namazu.cgi?query=%s"

	),

	new Array(

        "CGIZOO",

        "http://www.i-say.net/cgi/",

        "http://www.i-say.net/cgi/listview.php3?word=%s"

	),

	new Array(

        "NihongoCGI",

        "http://script.lovely.to/",

        "http://script.lovely.to/search.php3?key=%s"

	),

	null

);

NAME			= 0;

JUMP_LOCATION   = 1;

SEARCH_LOCATION = 2;

function SubmitHandler(targetForm) {

	engineName	= "";

	keyword		= "";

	engine		= null;

	for (var i = 0; i < document.forms.length; i++) {

		for (var j = 0; j < document.forms[i].elements.length; j++) {

			element = document.forms[i].elements[j];

			if ((engineName == "") && (element.name == "engine")) {

				engineName = element.options[element.selectedIndex].value;

			}

			if ((keyword == "") && (element.name == "keyword")) {

				keyword = element.value;

			}

		}

		if ((engineName != "") && (keyword != "")) {

			break;

		}

	}

	if (escape("漢字") == "%u6F22%u5B57") {

		keyword = keyword.replace("%", "%25").replace("#", "%23").replace("?", "%3F");

	}

	else {

		keyword = escape(keyword);

	}

	if (engineName == "") {

		return Error("検索エンジンを指定してください。");

	}

	for (var i = 0; i < ENGINES.length; i++) {

		if (ENGINES[i] != null && ENGINES[i][NAME] == engineName) {

			engine = ENGINES[i];

			break;

		}

	}

	if (engine == null) {

		return Error("未知の検索エンジンが指定されました。");

	}

	if (keyword == "") {

		location.href = engine[JUMP_LOCATION];

	}

	else {

		location.href = SimpleSprintf(engine[SEARCH_LOCATION], keyword);

	}

}

function SimpleSprintf(format, string) {

	var buffer = '';

	var isFormat = false;

	for (var i = 0; i < format.length; i++) {

		var c = format.charAt(i);

		if (isFormat) {

			isFormat = false;

			if (c == 's') {

				buffer += string;

				continue;

			}

			else {

				buffer += '%';

			}

		}

		if (c == '%') {

			isFormat = true;

		}

		else {

			buffer += c;

		}

	}

	return buffer;

}

function Error(message) {

	alert(message);

}
