
var NN=(document.layers);
var IE=(document.all);
var DefaultStr="";
var StartMark="myStart";
var FindBox;
var yoffset=5;

var n=0;
var newFind=true;
var notFound;
var txt;
var yoffset=10;

function reinit(){
  if(IE){
	if(txt == null) return false;
	txt.move("textedit", -1);
	document.selection.empty();
  }else{
	while(window.find(StartMark, false, true));
  }
  n=0;
  newFind=true;
}

function findInPage(str) {
  var i, found;
  notFound=false;

  if(str == "") return false;

  // Find next occurance of the given string on the page, wrap around to the
  // start of the page if necessary.
  if(IE){
	txt=window.document.body.createTextRange();

	// Find the nth match from the top of the page.
	for(i=0; i <= n && (found=txt.findText(str)); i++){
	  txt.moveStart("character", 1);
	  txt.moveEnd("textedit");
	}

	// If found, mark it and scroll it into view.
	if(found){
	  txt.moveStart("character", -1);
	  txt.findText(str);
	  txt.select();
	  txt.scrollIntoView();
	  n++;
	}else{	// Otherwise, start over at the top of the page and find first match.
	  notFound=true;
	}
  }else{
	// Look for match starting at the current point. If not found, rewind
	// back to the first match.

	n=0;
	if(window.find(str)){
	  n++;
	  self.scrollBy(-50,-65);		// 調整找到資料的顯示位置不致被本程式操作框所遮住
	}

	// If not found in either direction, give message.
	if(n == 0) notFound=true;
  }

  if(notFound){
	if(newFind){
	  alert("未找到符合條件的資料！");
	}else{
	  alert("已無其它符合條件的資料了！");
	}
  }else{
	newFind=false;
  }

  return false;
}

function setReload(){
  window.location.reload()
}

function setReset(){
  if(NN){
    setTimeout("window.onresize=setReload",500)
  }
}

function rePosition(){
  var positionY, positionX;

  if(IE){
    positionY= document.body.scrollTop;
    positionX= document.body.scrollLeft;
  }else{
    positionY= window.pageYOffset;
    positionX= window.pageXOffset;
  }

  FindBox.top=positionY;
  FindBox.left=positionX;
}

function init(){
  setInterval("rePosition()",50);
  setReset();
}

if(IE){
  document.write("<div id='ieBox' style='color: #FFFF00; visibility: hidden'>");
}else{
  document.write("<layer id='nnBox' visibility='hidden'>");
}

document.write('<form name="search" onsubmit="return findInPage(this.keyword.value);">\n');
document.write('<table width="50%"  border="0" cellspacing="0" cellpadding="1">\n');
document.write('<tr><td align="center"><font style="font-size: 9pt; color: #ffffaa">搜尋怪物名稱</font></td>\n');
document.write('<td align="center"><input style="font-size: 9pt" type="text" size="15" name="keyword" value="'+DefaultStr+'" onchange="n=0;"></td>');
document.write('<td align="center"><input style="font-size: 9pt" type="submit" value="搜尋">&nbsp;');
document.write('<input style="font-size: 9pt" type="button" value="重打" onclick="reset()"></td></tr>');
document.write('</form></table>');

if(IE){
  document.write("</div>");
  FindBox=document.all.ieBox.style;
  document.all.ieBox.style.visibility='visible';
}else{
  document.write("</layer>");
  FindBox=document.layers.nnBox;
  document.layers.nnBox.visibility='visible';
}

onload=init;

