Event.observe( window, 'load', eventHandler );

googleURL          = new Array("http://www.google.co.jp/","http://www.google.co.jp/search?hl=ja&btnG=Google+%E6%A4%9C%E7%B4%A2&lr=&aq=f&oq=&q=");
yahooURL           = new Array("http://www.yahoo.co.jp/","http://search.yahoo.co.jp/search?fr=slv1-fftbtop&p=");
msnURL             = new Array("http://jp.msn.com/","http://search.msn.co.jp/results.aspx?FORM=MSNH&q=");
infoseekURL        = new Array("http://www.infoseek.co.jp/","http://search.www.infoseek.co.jp/Web?col=OW&wd=0&qt=");
ocnURL             = new Array("http://www.ocn.ne.jp/","http://ocnsearch.goo.ne.jp/ocn.jsp?encode=euc&SM=MC&DC=10&IE=sjis&MT=");
biglobeURL         = new Array("http://www.biglobe.ne.jp/","http://cgi.search.biglobe.ne.jp/cgi-bin/search2-b?search=%8C%9F%8D%F5&bt01.x=0&bt01.y=0&q=");
amazonURL          = new Array("http://www.amazon.co.jp","http://www.amazon.co.jp/gp/associates/link-types/searchbox.html?tag=yusamok-22&creative=2131&adid=0NAXPGNDGG85R1BV9WZM&campaign=483&__mk_ja_JP=%83J%83%5E%83J%83i&mode=blended&Submit.x=12&Submit.y=10&Submit=Go&keyword=");
rakutenURL         = new Array("http://www.rakuten.co.jp","http://esearch.rakuten.co.jp/rms/sd/esearch/vc?sv=2&c=2836&sitem=");
kakakucomURL       = new Array("http://kakaku.com/","http://search.kakaku.com/ksearch/search.aspx?search.x=19&search.y=14&query=");
yahooauctionURL    = new Array("http://auctions.yahoo.co.jp/","http://search.auctions.yahoo.co.jp/jp/search/auc?auccat=0&alocale=0jp&acc=jp&p=");
conecoURL          = new Array("http://www.coneco.net/","http://www.coneco.net/PriceList.asp?&SEARCHALL=1&FREE_WORD=");
kizasiURL          = new Array("http://kizasi.jp/","http://kizasi.jp/show.py/detail?x=0&y=0&ref=freeword&label=&kw_expr=");
nichURL            = new Array("http://www.2ch.net/","http://find.2ch.net/?TYPE=TITLE&BBS=ALL&ENCODING=SJIS&COUNT=50&STR=");
womensparkURL      = new Array("http://women.benesse.ne.jp/","http://women.benesse.ne.jp/search/search.cgi?zfrom=http%3A%2F%2Fwomen.benesse.ne.jp%2Findex.html&combtyp=2&kanjiexp=%8A%BF&cwdir=&dicdir=%2FBSwork%2Fproject%2FLX&x=30&y=11&keyexpr=");
wikiURL            = new Array("http://ja.wikipedia.org/","http://ja.wikipedia.org/w/index.php?title=%E7%89%B9%E5%88%A5%3ASearch&ns0=1&fulltext=%E6%A4%9C%E7%B4%A2&search=");
gooallURL          = new Array("http://dictionary.goo.ne.jp/","http://dictionary.goo.ne.jp/search.php?kind=all&mode=0&kwassist=0&MT=");
gookokugoURL       = new Array("http://dictionary.goo.ne.jp/","http://dictionary.goo.ne.jp/search.php?kind=jn&mode=0&kwassist=0&MT=");
gooeiwaURL         = new Array("http://dictionary.goo.ne.jp/","http://dictionary.goo.ne.jp/search.php?kind=ej&mode=0&kwassist=0&MT=");
goowaeiURL         = new Array("http://dictionary.goo.ne.jp/","http://dictionary.goo.ne.jp/search.php?mode=0&kind=je&dhit=0je&MT=");
goousedcarURL      = new Array("http://www.goo-net.com/","http://www.goo-net.com/cgi-bin/fsearch/goo_used_search.cgi?baitai=goo&code=sjis&phrase=");
goonewcarURL       = new Array("http://www.goo-net.com/","http://www.goo-net.com/cgi-bin/fsearch/goo_new_search.cgi?code=sjis&baitai=goo&category=newcar&query=");
goocatalogURL      = new Array("http://www.goo-net.com/","http://www.goo-net.com/cgi-bin/fsearch/goo_catalog_search.cgi?idxname=catalog&whence=0&max=100&query=");
carviewURL         = new Array("http://www.carview.co.jp/","http://search.carview.co.jp/search.exe?query=");
carviewminkaraURL  = new Array("http://www.carview.co.jp/","http://msearch.carview.co.jp/search.exe?query=");
seotoolsURL        = new Array("http://www.seotools.jp/","http://www.seotools.jp/001_seoanalyze/?url=");
w3cvalidateURL     = new Array("http://validator.w3.org/","http://validator.w3.org/check?uri=");
w3cvalidatecssURL  = new Array("http://jigsaw.w3.org/css-validator/","http://jigsaw.w3.org/css-validator/validator?profile=css21&usermedium=all&warning=1&lang=ja&uri=");
harelURL           = new Array("http://harel.nttdata.co.jp/","http://harel.nttdata.co.jp/check?uri=");
webscouterURL      = new Array("http://ja.webscouter.net/","http://ja.webscouter.net/info.phtml?u=");
googleblogURL      = new Array("http://blogsearch.google.co.jp/","http://blogsearch.google.co.jp/blogsearch?hl=ja&q=");
yahooblogURL       = new Array("http://blog-search.yahoo.co.jp/","http://blog-search.yahoo.co.jp/search?fr=top_ga1&ei=UTF-8&p=");
blogmuraURL        = new Array("http://www.blogmura.com/","http://search.blogmura.com/?sch=1&ok=1&keyword=");
technoratiURL      = new Array("http://www.technorati.jp/","http://www.technorati.jp/search/");
fc2URL             = new Array("http://blog.fc2.com/","http://search.fc2.com/?charset=euc-jp&q=");
seesaaURL          = new Array("http://blog.seesaa.jp/","http://tag.seesaa.jp/t/articles+photos+videos+audios+goods+blogs/");

function eventHandler(){
	
	if( document.getElementById('siteset') ) {
		Event.observe( 'siteset' , 'change', siteset );
	}
	
	if( document.getElementById('searchButton') ) {
		Event.observe( 'searchButton' , 'click', get );
	}

	if( document.getElementById('google') ) {
		Event.observe( 'google'         , 'click' , get );
	}
	if( document.getElementById('yahoo') ) {
		Event.observe( 'yahoo'          , 'click' , get );
	}
	if( document.getElementById('msn') ) {
		Event.observe( 'msn'            , 'click' , get );
	}
	if( document.getElementById('infoseek') ) {
		Event.observe( 'infoseek'            , 'click' , get );
	}
	if( document.getElementById('ocn') ) {
		Event.observe( 'ocn'            , 'click' , get );
	}
	if( document.getElementById('biglobe') ) {
		Event.observe( 'biglobe'            , 'click' , get );
	}
	if( document.getElementById('amazon') ) {
		Event.observe( 'amazon'         , 'click' , get );
	}
	if( document.getElementById('rakuten') ) {
		Event.observe( 'rakuten'        , 'click' , get );
	}
	if( document.getElementById('kakakucom') ) {
		Event.observe( 'kakakucom'      , 'click' , get );
	}
	if( document.getElementById('yahooauction') ) {
		Event.observe( 'yahooauction'   , 'click' , get );
	}
	if( document.getElementById('coneco') ) {
		Event.observe( 'coneco'   , 'click' , get );
	}
	if( document.getElementById('kizasi') ) {
		Event.observe( 'kizasi'         , 'click' , get );
	}
	if( document.getElementById('nich') ) {
		Event.observe( 'nich'           , 'click' , get );
	}
	if( document.getElementById('womenspark') ) {
		Event.observe( 'womenspark'     , 'click' , get );
	}
	if( document.getElementById('wiki') ) {
		Event.observe( 'wiki'           , 'click' , get );
	}
	if( document.getElementById('gooall') ) {
		Event.observe( 'gooall'         , 'click' , get );
	}
	if( document.getElementById('gookokugo') ) {
		Event.observe( 'gookokugo'      , 'click' , get );
	}
	if( document.getElementById('gooeiwa') ) {
		Event.observe( 'gooeiwa'        , 'click' , get );
	}
	if( document.getElementById('goowaei') ) {
		Event.observe( 'goowaei'        , 'click' , get );
	}
	if( document.getElementById('goousedcar') ) {
		Event.observe( 'goousedcar'     , 'click' , get );
	}
	if( document.getElementById('goonewcar') ) {
		Event.observe( 'goonewcar'      , 'click' , get );
	}
	if( document.getElementById('goocatalog') ) {
		Event.observe( 'goocatalog'     , 'click' , get );
	}
	if( document.getElementById('carview') ) {
		Event.observe( 'carview'        , 'click' , get );
	}
	if( document.getElementById('carviewminkara') ) {
		Event.observe( 'carviewminkara' , 'click' , get );
	}
	if( document.getElementById('seotools') ) {
		Event.observe( 'seotools' , 'click' , get );
	}
	if( document.getElementById('w3cvalidate') ) {
		Event.observe( 'w3cvalidate' , 'click' , get );
	}
	if( document.getElementById('w3cvalidatecss') ) {
		Event.observe( 'w3cvalidatecss' , 'click' , get );
	}
	if( document.getElementById('harel') ) {
		Event.observe( 'harel' , 'click' , get );
	}
	if( document.getElementById('webscouter') ) {
		Event.observe( 'webscouter' , 'click' , get );
	}
	if( document.getElementById('googleblog') ) {
		Event.observe( 'googleblog' , 'click' , get );
	}
	if( document.getElementById('yahooblog') ) {
		Event.observe( 'yahooblog' , 'click' , get );
	}
	if( document.getElementById('blogmura') ) {
		Event.observe( 'blogmura' , 'click' , get );
	}
	if( document.getElementById('technorati') ) {
		Event.observe( 'technorati' , 'click' , get );
	}
	if( document.getElementById('fc2') ) {
		Event.observe( 'fc2' , 'click' , get );
	}
	if( document.getElementById('seesaa') ) {
		Event.observe( 'seesaa' , 'click' , get );
	}

}

function siteset(){

	if( $( 'keyword' ).value != "" ){
		location.href = $( 'siteset' ).value + "?q=" + EscapeUTF8( $( 'keyword' ).value );
	}else{
		location.href = $( 'siteset' ).value;
	}
}

function get(event){

	var eID = Event.element(event);
	
	var target;
	
	if(eID.id == "keyword" || eID.id == "searchButton"){
		target = $( 'site' ).value;
	}else{
		target = eID.id;
	}

	url = "";
	keyword = "";

	if( $( 'keyword' ).value != "" ){
	
		url = eval(target + "URL")[1];

		if(target == "rakuten" || target == "gooall" || target == "gookokugo" || target == "gooeiwa" || 
		   target == "goowaei" || target == "womenspark" || target == "yahooauction" || target == "blogmura" || target == "fc2")
		{
			keyword = EscapeEUCJP( $( 'keyword' ).value );
		}
		else if(target == "nich" || target == "goousedcar" || target == "goonewcar" || target == "goocatalog" ||
		        target == "kakakucom" || target == "amazon" || target == "ocn" || target == "biglobe" || target == "coneco"  )
		{
			keyword = EscapeSJIS( $( 'keyword' ).value );
		}
		else
		{
			keyword = $( 'keyword' ).value;
		}
		
	}
	//キーワードの入力がない場合、トップページ表示
	else
	{
		url = eval(target + "URL")[0];
	}
	
	$( 'site' ).value = target;
	
    new Ajax.Request
    (
        '/webservices/gettab/',
	    {                                                                                 
	      method     : 'post',
	      parameters : Form.serialize( 'searchForm' ),
	      onComplete : function( httpObject ){
	                       $( 'tabresultarea' ).innerHTML = '<iframe id="tabresult" src="' + url + keyword + '" frameborder="0" scrolling="yes" width="100%" height="92%"></iframe>';
	                   }
	    }
    );
}