ie = (document.all) ? 1 : 0;
var def_info;
occt = new Array("any","title","body","url","links");
sv = new Array("google.com", "google.co.jp", "www.google.com", "www.google.co.jp", "64.233.161.99", "64.233.161.100", "64.233.161.101", "64.233.161.102", "66.102.7.98", "66.102.7.99", "66.102.7.100", "66.102.7.101", "66.102.7.104", "66.102.9.99", "66.102.9.100", "66.102.9.101", "66.102.9.102", "66.102.11.98", "66.102.11.99", "66.102.11.100", "66.102.11.101", "66.102.11.102", "66.102.11.104", "66.249.93.98", "66.249.93.99", "66.249.93.100", "66.249.93.101", "66.249.93.102", "66.249.93.104", "216.239.59.99", "216.239.59.100", "216.239.59.101", "216.239.59.102", "216.239.59.103", "216.239.59.104");

function init(t) {

	if (! document.getElementById)
		alert("このコンテンツは現在ご使用のブラウザではご利用いただけません。");
	else if (ie) {
		fr = document.all.tags("iframe");
		limit_wid = Math.floor((document.body.clientWidth - 5) / 4);
		limit_hei = document.body.clientHeight - document.all("box").clientHeight - document.all("server_name").clientHeight - 5;
	}
	else if (document.getElementById) {
		fr = document.getElementsByTagName("iframe");
		document.getElementById("box").style.height = 46;
		document.getElementById("server_name").style.height = 18;
		limit_wid = Math.floor((self.innerWidth - 5) / 4);
		limit_hei = self.innerHeight - parseInt(document.getElementById("box").style.height) - parseInt(document.getElementById("server_name").style.height) - 5;
	}

	if (t) {
		for (i = 0; i < 4; i ++) {
			fr[i].style.width = limit_wid;
//			fr[i].style.height = limit_hei;
		}
	}
	else {
		document.forms[0].reset();

		if (ie) obj = document.all("info");
		else obj = document.getElementById("info");
		if (! def_info) def_info = obj.innerHTML;
		obj.className = "open";
		obj.innerHTML = def_info;

		if (ie) obj = document.all("disp");
		else obj = document.getElementById("disp");
		obj.style.visibility = "hidden";

		for (i = 0; i < 4; i ++) {
			fr[i].style.width = limit_wid;
			fr[i].style.height = 10;
		}
	}
}

function send(f) {

	ky = f.q.value.replace(/ |　/, "+");

	if (document.google_dance.q.value == "") {
		alert("検索キーが未入力です！");
		return false;
	}

	f = document.forms["google_dance"];
	er = 0;
	server = new Array();
	sub = new Array();
	check = new Array();
	for (i = 0; i < 4; i ++) {
		v = sub[i] = sv[f.elements["data" + i].selectedIndex];
		if (check[v]) er = 1;
		check[v] = 1;
		server[i] = v;
	}

	if (er) {
		alert("同じデータベースが選択されています！");
		return false;
	}

	query = (f.md.selectedIndex) ? "search?" : "ie?";
	query += (f.tl.selectedIndex) ? "lr=lang_ja" : "lr=";
	query += "&num=" + f.num.options[f.num.selectedIndex].text;
	query += "&as_occt=" + occt[f.oc.selectedIndex];
	query += "&ie=Shift_JIS&q=" + ky;

	if (ie) obj = document.all("info");
	else obj = document.getElementById("info");
	obj.className = "close";
	obj.innerHTML = "";

	for (i = 0; i < 4; i ++) {
		fr[i].style.height = limit_hei;
		parent.frames[i].location.href = "about:blank";
		setTimeout("print_loading(" + i + ")",0);
		with (document.links[i + 1]) {
			href = title = "http://" + server[i] + "/" + query.replace(/ie/,"search");
			innerHTML = server[i];
		}
	}

	if (ie) obj = document.all("disp");
	else obj = document.getElementById("disp");
	obj.style.visibility = "visible";

	n = 0;
	setTimeout("loading()",0);

	return false;
}

function print_loading(p) {

	with (parent.frames[p].document) {
		open();
		write("<div align=center style='margin-top:",Math.floor(limit_hei / 2)
		 	  ,"px;font:italic bold 11pt Times New Roman;'>",sub[p]," is loading...</div>");
		close();
	}
}

function loading() {

	parent.frames[n].location.href = "http://" + server[n] + "/" + query + "&time=" + escape(new Date());
	n ++;
	if (n < 4) setTimeout("loading()",0);
}

function next() {
	f = document.forms[0];
	for (i = 0; i < 4; i ++) {
		nx = f.elements["data" + i].selectedIndex + 4;
		if (nx >= f.elements["data" + i].length)
			nx -= f.elements["data" + i].length;
		f.elements["data" + i].options[nx].selected = true;
	}
}

function url_open(h) {

	if (! ie) return true;
	url = document.links[h].href;
	document.jump.action = url.substring(0,url.indexOf("?"));
	buffer = url.substring(url.indexOf("?") + 1,url.length);
	buffer = buffer.replace(/\+/g," ");
	buffer = buffer.split(/&/);
	for (i in buffer) {
		buf = buffer[i].split(/=/);
		if (buf[1] && document.jump.elements[buf[0]])
			if (buf[0] == "q")
				document.jump.elements[buf[0]].value = document.google_dance.q.value;
			else
				document.jump.elements[buf[0]].value = buf[1];
	}
	document.jump.submit();
	return false;
}

function context() {

	if (! ie) return true;
	alert("このリンクはフォーム送信を使用して開かれます。\n別ウィンドウが開きますので左クリックして下さい。");
	return false;
}

onload = init;
