function hstbck() {
  history.back();
}

function hstfwd() {
  history.forward();
}

function updloc() {
  location.reload();
}

function updopw() {
  window.opener.location.reload();
}

function clswin() {
  window.close();
}

function opnwin(urltgt,numhgt,namwin) {
  window.open(urltgt,namwin,'width=500,height='+numhgt+',menubar=no,location=no,toolbar=no,status=no,resizable=yes,scrollbars=yes');
}

function opnupl(objtgt,strhtm,strdir) {
/*関数：アップロード用ウィンドウを開く：親ウィンドウ用*/
/*入力：*/
/*strhtm ... アップロード用ウィンドウのＵＲＬ*/
/*strdir ... アップロードするディレクトリ*/
/*注記：想定する対象ノードの構造：
  <div>...<p><textarea>...</textarea></p>FILE<p><input value="DIR"></p>...<p><a onclick="opnupl(this)"></p>...</div>
*/
  strwin='upload'; /*ウィンドウの名前*/
  strfil=objtgt.parentNode.parentNode.getElementsByTagName('textarea')[0].value; /*アップロードするファイル*/
  objdiv=objtgt.parentNode.parentNode;
  strqry=strfil+'&'+strdir; /*子ウィンドウ（アップロード画面）に渡すクエリ*/
  strurl=strhtm+'?'+strqry; /*ＵＲＬ*/
/*window.open(strurl,strwin);*/
  opnwin(strurl,200,strwin);
}

function setupl() {
/*関数：アップロード用ウィンドウを開く：子ウィンドウ用*/
/*注記：想定する対象ノードの構造：
  <input id="strfil"/>...<input id="strdir"/>
*/
  strqry=location.search.substr(1);
  arrqry=strqry.split('&');
  strfil=arrqry[0];
  strdir=arrqry[1];
  document.getElementById('strfil').value=strfil;
  document.getElementById('strdir').value=strdir;
}

/*------------------------------------------------------------------------*/
/*変数（広域）*/
/*------------------------------------------------------------------------*/
  var extxml='xmlitm_'; /*ＸＭＬ入力フォームの接頭辞（項目の内容）*/
  var tagfrm='noname'; /*ＸＭＬ入力フォームを囲む、特別なタグの名前*/
  var profrm='name'; /*属性の名前*/
  var exppth='..*'; /*ＸＭＬ入力フォームのＸＭＬパス（正規表現）*/
  var expfid='[0-9\.][0-9\.]*'; /*ＸＭＬ入力フォームの連番（正規表現）*/

/*------------------------------------------------------------------------*/
/*関数：クリックされた関数を含むノード群を、複製する*/
/*------------------------------------------------------------------------*/
/*注記：複製するＸＭＬフォーム群の全フォームの位置属性を、他のＸＭＬフォームの間に収まるよう、修正する
  注記：想定する対象ノードの構造：
  <div>...<noname><input|textarea|... name="xmlitm_/XXX/XXX_NNN.NNN"/></noname>...<p><a onclick="addnod(this)"></p>...</div>
  入力：
  nodcmd ... 原本ノードに含まれる、起点となるノード（原則、スクリプト・ノード自身）
  入力（広域）：
  tagfrm, extxml, profrm
*/
/*------------------------------------------------------------------------*/
function addnod(nodcmd) {
  var nodpar; var nodorg; var nodcpy;
  var lstfmc; /*入力フォーム群の配列（複製）*/
  var lstfma; /*入力フォーム群の配列（全体）*/
  var lstpsa; /*入力フォーム群の、位置の配列（全体）*/
  var numpsc; /*複製ノードの、最後の入力フォーム・ノードの位置*/
  var numpsn; /*文書ノードの、原本ノードの次の入力フォーム・ノードの位置*/
  var numpsd; /*新しい位置*/
  var numdif; /*新しい位置の間隔*/
  var numcnt; var nummax;
  var strpos; var strpth;
  var strmsg;
  strmsg='この項目を複製します。よろしいですか？';
/*複製の原本ノードと、その親ノード（複製ノードをその直下に置くノード）を取得*/
/*ただし、スクリプト・ノードの位置に依存（一時的なコード）*/
  nodorg=nodcmd.parentNode.parentNode;
  nodpar=nodcmd.parentNode.parentNode.parentNode;
/*原本ノードを複製*/
  nodcpy=nodorg.cloneNode(true);
/*複製ノードの、入力フォーム・ノード群を取得（特別な名前のタグに包含）*/
  lstfmc=new Array();
  lstfmc=lstchd(nodcpy.getElementsByTagName(tagfrm));
/*文書ノードの、入力フォーム・ノード群を取得（特別な名前のタグに包含）*/
  lstfma=new Array();
  lstfma=lstchd(document.getElementsByTagName(tagfrm));
/*複製ノードの、最後の入力フォームの位置を取得*/
  numpsc=getpos(lstfmc[lstfmc.length-1]);
/*文書ノードの、入力フォームの位置を、配列に格納*/
  lstpsa=new Array();
  numcnt=0;
  nummax=lstfma.length;
  while (numcnt < nummax) {
    lstpsa[numcnt]=getpos(lstfma[numcnt]);
    numcnt=numcnt+1;
  }
/*複製ノードの、最後の入力フォーム・ノードの位置の、次の位置を取得*/
  numcnt=0;
  nummax=lstpsa.length;
  while (numcnt < nummax && lstpsa[numcnt] <= numpsc) {
    numcnt=numcnt+1;
  }
  numpsn=lstpsa[numcnt];
/*複製ノードの入力フォーム・ノード群の、新しい位置を算出*/
/*原本ノードの最後に追加なら、１きざみとする*/
  if (numpsn == undefined) {
    numdif=1;
  }
/*原本ノードの途中に追加なら、次の位置との間を、複製ノード内の入力フォーム・ノードの数だけ等分した位置とする*/
  else {
    numdif=(numpsn-numpsc)/(lstfmc.length+1);
  }
/*位置の差分を加え、それを複写ノードの入力フォーム・ノード群の属性とする*/
  numpsd=numpsc;
  numcnt=0;
  nummax=lstfmc.length;
  while (numcnt < nummax) {
    numpsd=numpsd+numdif;
    strpth=getpth(lstfmc[numcnt]);
    strpos=extxml+strpth+'_'+numpsd;
    lstfmc[numcnt].setAttribute(profrm,strpos);
    lstfmc[numcnt].value='';
    numcnt=numcnt+1;
  }
/*複製ノードを、親ノードに追加*/
/*if (window.confirm(strmsg)) {*/
    nodpar.insertBefore(nodcpy,nodorg.nextSibling);
/*}*/
}

/*------------------------------------------------------------------------*/
/*関数：ＸＭＬ入力フォーム・ノードを受け取り、属性から、その位置（連番）を取り出す
/*------------------------------------------------------------------------*/
/*入力（広域）：
  extxml, profrm, exppth
*/
/*------------------------------------------------------------------------*/
function getpos(nodtgt) {
  var strpro;
  var strpos;
  var regexp;
  strpro=nodtgt.getAttribute(profrm);
  regexp=new RegExp('^'+extxml+exppth+'_');
  strpos=strpro.replace(regexp,'');
  return Number(strpos);
}

/*------------------------------------------------------------------------*/
/*関数：ＸＭＬ入力フォーム・ノードを受け取り、属性から、そのパスを取り出す
/*------------------------------------------------------------------------*/
/*入力（広域）：
  extxml, profrm, expfid
*/
/*------------------------------------------------------------------------*/
function getpth(nodtgt) {
  var strpro;
  var strpth;
  strpro=nodtgt.getAttribute(profrm);
  regexp=new RegExp('^'+extxml);
  strpth=strpro.replace(regexp,'');
  regexp=new RegExp('_'+expfid+'$');
  strpth=strpth.replace(regexp,'');
  return strpth;
}

/*------------------------------------------------------------------------*/
/*関数：親要素のリストから、その子要素のリストを作る
/*------------------------------------------------------------------------*/
/*注記：
  <taglsp><tablsc>...</tablsc></taglsp>の配列 -> <tablsc>...</tablsc>の配列
  書式：
  lstchd=lstchd(lstpar)
  入力：
  lstpar ... 親要素のリスト
  出力：
  lstchd ... 子要素のリスト*/
/*------------------------------------------------------------------------*/
function lstchd(lstpar) {
  var lstchd;
  var numcnt; var nummax;
  lstchd=new Array();
  numcnt=0;
  nummax=lstpar.length;
  while (numcnt < nummax) {
    lstchd[numcnt]=lstpar[numcnt].firstChild;
    numcnt=numcnt+1;
  }
  return lstchd;
}

/*------------------------------------------------------------------------*/
/*関数：クリックされた関数を含むノード群を、削除する*/
/*------------------------------------------------------------------------*/
function remnod(nodcmd) {
  var nodpar; var nodorg;
  var strmsg;
  strmsg='この項目を削除します。よろしいですか？';
/*削除の原本ノードと、その親ノード（削除ノードをその直下に置くノード）を取得*/
/*ただし、スクリプト・ノードの位置に依存（一時的なコード）*/
  nodorg=nodcmd.parentNode.parentNode;
  nodpar=nodcmd.parentNode.parentNode.parentNode;
/*削除ノードを、親ノードから削除*/
  if (window.confirm(strmsg)) {
    nodpar.removeChild(nodorg);
  }
}

