function closeWindow() {
  window.opener = window;
  var win = window.open( location.href, "_self" );
  win.close();
}

function next_page(frm_name, url){
  document.forms[frm_name].action=url;
  document.forms[frm_name].submit();
}

function view_ligdic(db_name){
  window.open('ligdic.php?db='+db_name, 'ligdic', 'width=820,height=750,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes');
}

function view_kwdic(db_name){
  window.open('kwdic.php?db='+db_name, 'kwdic', 'width=820,height=750,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes');
}

function checkHankaku(str){
  flg = false;
  strVal = mb_Trim(Trim(str));
  if( strVal.length == 0 ){
    flg = true; // space is OK
  }
  if(!flg){
    cnt = ByteCount(strVal);
    if(cnt != strVal.length ){
      return(false);
    }
  }
  return true;
}

function Trim(str) {
  return RTrim(LTrim(str));
}

function LTrim(str) {
  return str.replace(/^\s+/,"");
}

function RTrim(str) {
  return str.replace(/\s+$/,"");
}

function mb_Trim(str) {
  return mb_RTrim(mb_LTrim(str));
}

function mb_LTrim(str) {
  return str.replace(/^ +/,"");
}

function mb_RTrim(str) {
  return str.replace(/ +$/,"");
}

function ByteCount(str){
  var count = 0;
  for (i=0; i<str.length; i++){
    n = escape(str.charAt(i));
    if (n.length < 4) {
      count++; // 1 bite string
    } else{
      count+=2; // 2 bites string
    }
  }
  return count;
}

function Tscroller(Tid,tHeight)
{
	if(! document.createElement) return;
	if(navigator.userAgent.match('Opera')) return;
	var oTBL = document.getElementById(Tid);
	for( var i = 0; i < oTBL.tHead.rows[0].cells.length; i++ )
	{
		oTBL.tHead.rows[0].cells[i].style.width = 
		oTBL.tBodies[0].rows[0].cells[i].style.width = 
			(oTBL.tBodies[0].rows[0].cells[i].clientWidth - oTBL.cellPadding *2)+ 'px';
	}

	// ヘッダ部のオフセットヘイトを取得
	var ThHeight = oTBL.tHead.offsetHeight;

	// テーブルオブジェクトの高さをヘッダ部の高さに
	oTBL.style.width = oTBL.offsetWidth + 'px';

	// オフセット+1の長さ
	var tWidth = oTBL.offsetWidth+1;

	// テーブルオブジェクトの複製を作成
	var oTBL1 = oTBL.cloneNode(true);

	// IDに＿Hを付加
	oTBL1.id += '_H';

	// 行を全削除
	while(oTBL1.tBodies[0].rows.length) {
		oTBL1.tBodies[0].deleteRow(0);
	}

	// DIVエレメントを新規作成
	var newDiv1 = document.createElement('div');
	newDiv1.id='D_'+oTBL1.id;
	newDiv1.style.width = tWidth+'px';
	newDiv1.style.height = ThHeight+'px';
	newDiv1.style.overflow = 'hidden';
	newDiv1.style.position = 'relative';

	oTBL1.style.position = 'absolute';
	oTBL1.style.left = '0';
	oTBL1.style.top = '0';
	newDiv1.appendChild(oTBL1);
	oTBL.parentNode.insertBefore(newDiv1,oTBL);
	newDiv1.style.width = (oTBL1.offsetWidth+2)+'px';

	var oTBL2 = oTBL.cloneNode(false);
	oTBL2.id += '_B';
	var bd = oTBL.getElementsByTagName("tbody");
	oTBL2.appendChild(bd[0].cloneNode(true));
	var newDiv2 = document.createElement('div');
	newDiv2.id='D_'+oTBL2.id;
	newDiv2.style.width = (tWidth+18)+'px';
	newDiv2.style.width = (oTBL1.offsetWidth+18)+'px';
	newDiv2.style.height = tHeight+'px';
	newDiv2.style.overflow = 'auto';
	newDiv2.appendChild(oTBL2);
	oTBL.parentNode.insertBefore(newDiv2,oTBL);
	oTBL.parentNode.removeChild(oTBL);
}

//----------------------------------------------------------------------
// 表示微調整処理
//----------------------------------------------------------------------
function mTscroller()
{
	// 新規エレメントが生成できない場合終了
	if(! document.createElement) return;

	// ブラウザがOperaの場合終了
	if(navigator.userAgent.match('Opera')) return;

	// 最後尾の列を取り出し
	var ohTBL = document.getElementById( "lastdata" );

	// ヘッダ部とデータ部のクライアント描画領域の差分を追加
	ohTBL.width = ohTBL.width +
		document.getElementById("headerlist").clientWidth -
		document.getElementById("mainlist").clientWidth;
}

