function MyReplaceSelectedText() {

	strText = "";
	if (window.getSelection) {
		// for Firefox.
		strText = window.getSelection().toString();
	} else if (document.getSelection) {
		// for NN
		strText = document.getSelection();
	} else if (document.selection) {
		// for IE
		strText = document.selection.createRange().htmlText;
	}
	if (strText!="")
		return strText.replace(/<.+?>/g, "");

	return strText;
}

function OnSubmit() {

	if (strText = MyReplaceSelectedText())
		document.search.keyword.value = strText;
	document.search.submit();
}

function disableSelection(target) {

	if (typeof target.onselectstart!="undefined") //IE route
	    target.onselectstart=function() { return false; }
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	    target.style.MozUserSelect="none";
	else //All other route (ie: Opera)
	    target.onmousedown=function(){ return false; }
	target.style.cursor = "default";
}

function MyDetachEvent(menu) {

	menu.onmousedown = null;
	menu.onblur = null;
}


var ntimer = 0;
var ntimeout = 800;	// time out.
function ResetTimer() {

	if (ntimer)
		clearTimeout(ntimer);
	ntimer = 0;
}

function MyDeleteMenu(menu) {

	MyDetachEvent(menu);

	document.getElementById('butmenu').src = "/archiver/img/butmenu.gif";
	menu.style.display = "none";
	ResetTimer();
}

function MyCloseMenu(n) {

	MyDeleteMenu(document.getElementById("popmenu"));

	if (n) {

		switch (n)
		{
		case 2:			// Google Web 検索
			document.search.mode.value = "google";
			document.search.cx.value = "partner-pub-5740219073237864:7r3pt0-gp98";
			break;
//		case 3:			// Namazu 基本ページ検索
//			document.search.mode.value = "namazu";
//			document.search.idxname.value = "base";
//			break;
//		case 4:			// Namazu FAQ/ヘルプ検索
//			document.search.mode.value = "namazu";
//			document.search.idxname.value = "faq";
//			break;
//		case 5:			// Namazu ML 検索
//			document.search.mode.value = "namazu";
//			document.search.idxname.value = "ml";
//			break;
		case 6:			// google Help 検索
			document.search.mode.value = "google";
			document.search.cx.value = "partner-pub-5740219073237864:k491t3-qnsa";
			if (document.search.keyword.value!="")
				document.search.keyword.value += " site:www.ponsoftware.com/archiver/help";
			break;
		case 7:			// google faq 検索
			document.search.mode.value = "google";
			document.search.cx.value = "partner-pub-5740219073237864:k491t3-qnsa";
			if (document.search.keyword.value!="")
				document.search.keyword.value += " site:www.ponsoftware.com/archiver/faq";
			break;
		case 8:			// google ml 検索
			document.search.mode.value = "google";
			document.search.cx.value = "partner-pub-5740219073237864:k491t3-qnsa";
			if (document.search.keyword.value!="")
//				document.search.keyword.value += " site:www.ponsoftware.com/archiver/mllog";
				document.search.keyword.value += " site:www.ponsoftware.com/archiver/mllog OR site:ml.ponsoftware.com/pipermail/explzh-ml.ponsoftware.com";
			break;
		default:		// Google サイト内検索
			document.search.mode.value = "google";
			document.search.cx.value = "partner-pub-5740219073237864:k491t3-qnsa";
			break;
		}
		OnSubmit();
	}
}

function MyMouseOut() {

	ntimer = setTimeout("MyDeleteMenu(document.getElementById('popmenu'))", ntimeout);
}

function MyEnableImg(obj, flag) {

	obj.src = flag ? "/archiver/img/but_a.gif" : "/archiver/img/but.gif";
}

function MyHotMenuItem(obj, flag) {

	if (flag) {

		obj.style.border = "solid 1px #9cdefc";	// DrawFocusRect()
//		obj.style.backgroundColor = "#e4f2f4";
		obj.style.backgroundImage = "url('/archiver/img/menubkimg.png')";

	} else {

		// fous out
		obj.style.border = "solid 1px #f8f8f8";	// !DrawFocusRect()
//		obj.style.backgroundColor = "#f8f8f8";
		obj.style.backgroundImage = "";

	}
}

function MyHotMenuItemD(obj, flag) {

	if (flag) {
//		obj.style.backgroundColor = "#e4f2f4";
		obj.style.backgroundImage = "url('/archiver/img/menubkimg.png')";
	} else {
//		obj.style.backgroundColor = "#f8f8f8";
		obj.style.backgroundImage = "";
	}
}

function MyKillFocus() {

	MyDeleteMenu(document.getElementById("popmenu"));
}

function MyMouseDown() {

	MyDetachEvent(document.getElementById("popmenu"));
}

function MyKeyDown(e) {

	var n = 0;
	switch (e.keyCode)
	{
	case 27:	// ESC
		MyDeleteMenu(document.getElementById("popmenu"));
		break;
	case 71:	// Google サイト内検索(G)
	case 56:
		n = 1;
		break;
	case 72:	// Google ヘルプ検索(H)
	case 57:
		n = 6;
		break;
	case 70:	// Google FAQ 検索(F)
	case 55:
		n = 7;
		break;
	case 69:	// Google Explzh-ML 検索(E)
	case 54:
		n = 8;
		break;
	case 87:	// Google Web 検索(W)
	case 72:
		n = 2;
		break;
//	case 78:	// Namazu 基本ページ検索(N)
//	case 63:
//		n = 3;
//		break;
//	case 81:	// Namazu FAQ/ヘルプ検索(Q)
//	case 66:
//		n = 4;
//		break;
//	case 77:	// Namazu ML 検索(M)
//	case 62:
//		n = 5;
//		break;
	default:
		break;
	}

	if (n)
		MyCloseMenu(n);
}

function MyMouseOver() {

	var container = document.getElementById("container");
	var popmenu = document.getElementById("popmenu");
	var button = document.getElementById("butmenu");
	var parent = button.offsetParent;

	button.src = "/archiver/img/butmenu_a.gif";
	popmenu.style.top = (parent.offsetTop + button.offsetTop + button.offsetHeight + 12) + "px";
	popmenu.style.left = container.offsetLeft + 880 - 216 + "px";

	popmenu.style.display = '';
	if (document.all)
		popmenu.tabIndex = -1;	// XP 以前の IE でフォーカス枠が表示される為
	ResetTimer();

	if (strText = MyReplaceSelectedText())
		document.search.keyword.value = strText;
	disableSelection(popmenu);
	popmenu.focus();

	popmenu.onmousedown = MyMouseDown;
	popmenu.onblur = MyKillFocus;

}
