//<![CDATA[
/****************************************************************************
* ブラウザごとのイベントハンドラ設定（onloadイベント）
*/
function attachLoadListener(functionReference)
{
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', functionReference, false);
	}else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', functionReference, false);
	}else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', functionReference);
	}else {
		return false;
	}
	return true;
};
/****************************************************************************
* イベントハンドラ設定（onSubmitイベント）
*/
function attachListener(target, eventType, functionRef, capture)
{
	if (typeof target.addEventListener != "undefined") {
		target.addEventListener(eventType, functionRef, capture);
	}else if (typeof target.attachEvent != "undefined") {
		target.attachEvent("on" + eventType, functionRef);
	}else {
		return false;
	}
	return true;
};
/****************************************************************************
* ブラウザ解釈ごとのdomオブジェクト取得
*/
function getElementId (id)
{
	return document.all && document.all(id) || document.getElementById && document.getElementById(id);
};
/****************************************************************************
* 初期化
*/
function initialize()
{
	if (window.name == 'gswindow') {
		window.name = '';
	}

	// 2008-09-26
	try
	{
		var gs = getElementId('gs');
		attachListener(gs, 'submit', function(e){ return gsSubmit(e); });
	}
	catch(e)
	{

	}
	// 2008-09-26
};

/******************************************************************************
* onSubmitイベントのフック
*/
function gsSubmit(e)
{
	// ********** 変数宣言 **********
	var isMSIE = /*@cc_on!@*/false;
	var gsattribute = '';
	var delimiter = '?'; //初期デリミタ
	var gs = getElementId('gs'); //google検索フォームの取得
	var uri = '';
	uri = gs.action;//フォームのactionメソッドを挿入
	
	// *********** URLクエリ作成 **********
	// ----- inputタグのdomを参照 -----
	var input = gs.getElementsByTagName('input');
	
	// ----- inputタグの数だけ繰り返す -----
	for(var i = 0; i < input.length; i++) {
		// ------ i番目のinputタグがradioだった時 -----
		if(input[i].type == "radio"){
			// ------ radioが選択されている時 -----
			if(input[i].checked == true){
				// ------ URLクエリを追加 -----
				gsattribute = gsattribute + delimiter + input[i].name + '=' + encodeURI(input[i].value);
			}
		// ------ i番目のinputタグがradioではない時 -----
		} else {
			// ------ URLクエリを追加 -----
			gsattribute = gsattribute + delimiter + input[i].name + '=' + encodeURI(input[i].value);
		}
		
		// ----- 2回目以降はデリミタを変更 -----
		if (gsattribute.length > 0) {
			delimiter = '&';
		}
	}
	
	// *********** 新しいウインドウで開く ***********
	window.open(uri + gsattribute, 'gswindow');
	// ----- Submitイベントをキャンセルする -----
	if (isMSIE) {
		e.returnValue = false;
	}else { 
		e.preventDefault();
	}
	return false;
};
attachLoadListener(initialize);
//]]>
