(function(){
function is_srch_recept_frame_close(){
	
	var frame = document.getElementById('recept_search_frame');
	frame.parentNode.removeChild(frame);
}

function is_srch_recept_conf(){
	var targets = [
		{
			rgxp: '^http://www\.google\.(co\.jp|com)',
			qt: 'q',
			enc: 'ie'
		},
		{
			rgxp: '^http://search\.yahoo\.(co\.jp|com)',
			qt: 'p',
			enc: 'ei'
		}
	]
	return targets;
}

function is_srch_recept_get_paramMap(ref,targets){
	var param_Map = new Object();
	var param_Map_tmp = new Object();
	for(var target in targets){
		if (ref.match(targets[target].rgxp)){
			if (ref.indexOf('?') > -1) tmp = ref.split('?')[1];
			var params = tmp.split('&');
			for(var param in params){
				var pair = params[param].split('=');
				if(pair[0] != ''){
					try{
						param_Map_tmp[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
					}catch(e){
						param_Map_tmp[pair[0]] = '';
					}
				}
			}
			
			for(var key in targets[target]){
				if (key == 'rgxp') {
					continue;
				}
				if(typeof param_Map_tmp[targets[target][key]] == 'undefined'){
					continue;
				}
				param_Map[key] = param_Map_tmp[targets[target][key]];
			}
		}
	}
	return param_Map;
}

function is_srch_recept_view(query){
	var ref = document.referrer;
	var loc = document.location;
	var dt = new Date();
	var c  = '' + ( dt.getTime() * Math.random() );
	var svx = 's00121';
	var col = 'OW';

	var frame = document.createElement('iframe');
	frame.id                    = 'recept_search_frame';
	frame.style.backgroundColor = '#DCDCDC';

	frame.allowTransparency     = 'true';
	frame.style.height	    = '25px';
	frame.style.width           = '212px';
	frame.style.position        = 'absolute';
	frame.style.top             = '5px';
	frame.style.right           = '5px';
	frame.style.scrolling       = 'no';
	frame.frameBorder           = 0;

	document.getElementsByTagName("body")[0].appendChild(frame);
	var framedoc = document.all ? frame.contentWindow.document : frame.contentDocument;

	framedoc.open();

	framedoc.frame_close = is_srch_recept_frame_close;

	framedoc.writeln(
		[
		'<html lang="ja">\n'
		,'<head>\n'
		,'<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n'
		,'<meta http-equiv="Content-Style-Type" content="text/css" />\n'
		,'</head>\n'
		,'<body style="margin: 0; padding: 0; font-weight: bold; background-color: transparent; overflow: hidden;">\n'
		,'<img src="http://image.infoseek.rakuten.co.jp/content/search/motto_search/msform_bg.png" style="margin: 0; padding: 0; filter: alpha(opacity=80);opacity:0.8;" />\n'
		,'<a href="http://search.www.infoseek.co.jp/" target="_blank"><img border="0" width="15" height="14" src="http://image.infoseek.rakuten.co.jp/content/search/motto_search/msform_logo.gif" style="margin: 0; padding: 0; position: absolute; top: 5px; left : 10px; z-index: 1;" /></a>\n'
		,'<form action="http://search.www.infoseek.co.jp/Web" method="get" name="FORMTEXT" target="_blank">\n'
		,'<input type="text" name="qt" value="' + query + '" maxlength="256" size="15" style="margin: 0; padding: 0; width: 110px; height: 18px; position: absolute; top: 3px; left:28px;" >\n'
		,'<input type="hidden" name="svx" value="'+ svx +'" > \n'
		,'<input type="hidden" name="col" value="'+ col +'" > \n'
		,'<input type="image" src="http://image.infoseek.rakuten.co.jp/content/search/motto_search/msform_btn.gif" style="margin: 0; padding: 0; position: absolute; top:3px; right:23px;" onclick=" this.form.submit(); return false; " />\n'
		,'</form>\n'
		,'<a href="javascript:void(0);" onclick="document.frame_close()" >\n'
		,'<img border="0" width="16" height="15" src="http://image.infoseek.rakuten.co.jp/content/search/motto_search/msform_close.gif" style="margin: 0; padding: 0; position: absolute; top: 4px; right : 3px; z-index: 1;" />\n'
		,'</a>\n'
		,'</body>\n</html>\n'
		].join('')
	);
	framedoc.close();
	
}

function is_srch_recept_main(){
	var ref = '';
	var tmp = '';
	var query = '';
	var enc = '';
	var param_Map = new Object();
	ref = document.referrer;
	if (ref == ""){return;}

	if(navigator.userAgent.toLowerCase().indexOf("msie")    > -1 || 
	   navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ){
		void(0);
	}else{
		return;
	}

	var exclude = "^http://isweb.www.infoseek.co.jp/|^http://iswlite.www.infoseek.co.jp/";
	var owner_url = document.URL;
	if (!owner_url){return;}
	if (owner_url.match(exclude)){
		return;
	}

	var targets = is_srch_recept_conf();
	if(typeof targets == 'undefined'){
		return;
	}
	param_Map = is_srch_recept_get_paramMap(ref,targets);
	query =param_Map['qt'];

	if (query == ''| typeof query == 'undefined' ){
		return;
	}
	enc = param_Map['enc'];
	switch (enc) {
		case '' :
			break;

		case 'utf-8' :
			break;

		case 'UTF-8' :
			break;

		case undefined :
			break;

		default :
			return;
	}
	is_srch_recept_view(query);
}

function bindReady(callback){
    var isReady = false;
    function ready(){
        if(isReady)return;
        isReady = true;
        callback();
    }
    bindReady = function(){};
    var userAgent = navigator.userAgent.toLowerCase();
    var browser = {
        safari: /webkit/.test( userAgent ),
        opera: /opera/.test( userAgent ),
        msie: /msie/.test( userAgent ) && !/opera/.test( userAgent )
    };
    // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
    if ( document.addEventListener && !browser.opera)
        // Use the handy event callback
        document.addEventListener( "DOMContentLoaded", ready, false );
 
    // If IE is used and is not in a frame
    // Continually check to see if the document is ready
    if ( browser.msie && window == top ) (function(){
        if (isReady) return;
        try {
            // If IE is used, use the trick by Diego Perini
            // http://javascript.nwbox.com/IEContentLoaded/
            document.documentElement.doScroll("left");
        } catch( error ) {
            setTimeout( arguments.callee, 0 );
            return;
        }
        // and execute a waiting function
        ready();
    })();
 
    if ( browser.opera )
        document.addEventListener( "DOMContentLoaded", function () {
            if (isReady) return;
            for (var i = 0; i < document.styleSheets.length; i++)
                if (document.styleSheets[i].disabled) {
                    setTimeout( arguments.callee, 0 );
                    return;
                }
            // and execute a waiting function
            ready();
        }, false);
 
    if ( browser.safari ) {
        var numStyles;
        function countNumStyles(){
            var d = document;
            var stylesLength = d.getElementsByTagName('style').length;
            var links = d.getElementsByTagName('link');
            for(var i = 0; i++; i < links.length){
                if(links[i].rel == 'stylesheet'){
                    stylesLength++;
                }
            }
            return stylesLength;
        }
        (function(){
            if (isReady) return;
            if ( document.readyState != "loaded" && document.readyState != "complete" ) {
                setTimeout( arguments.callee, 0 );
                return;
            }
            if ( numStyles === undefined )
                numStyles = countNumStyles();
            if ( document.styleSheets.length != numStyles ) {
                setTimeout( arguments.callee, 0 );
                return;
            }
            // and execute a waiting function
            ready();
        })();
    }
    var oldOnload = window.onload;
    window.onload=function(){
        if(oldOnload)oldOnload();
        ready();
    };
}
bindReady(is_srch_recept_main);

})();
