function fx_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=fx_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function winopen(ads,wname,wi,he,tf) {
  if(tf=='yes' || tf=='YES') tf=',scrollbars=yes';
  if(tf=='no' || tf=='NO') tf=',scrollbars=no';
  if(!tf) tf=',scrollbars=no';

  if ( he == '' )
  {
    he = ( screen.availHeight - 30 );
  }
  prop = 'width=' + wi + ',height=' + he + tf;
  CWin = window.open(ads,wname,prop);
  CWin.focus();
}
var xObjwin;
//一覧印刷ポップ
///////////////////////////////////////////////////////////////////////////////
//関数：    fmNewWin()
//
//引数：    
//
//戻値：    なし
//
//機能：    WindowsをOpenする
//
////////////////////////////////////////////////////////////////////////////////
function fx_NewWin(wURL, wFlameNM, wAttr, lIdx)
{

    if(document.forms[0].i_init)
    {
        document.forms[0].i_init.value= '';
    }

    if( !!xObjwin )
    {
        if ( xObjwin.closed == false )
        {
            xObjwin.close();
        }
    }
    if ( wAttr.indexOf('height',0) == -1 )
    {
        wAttr += ',height=' + ( screen.availHeight - 30 )
    }
   if(typeof(lIdx) == "undefined") {
      lIdx= 0;
   }
   
   if ( wAttr=='' )
   {
        wAttr = 'resizable=yes';
   }
   else
   {
        wAttr = wAttr + ',resizable=yes';
   }
    //alert(wAttr);

    xObjwin = window.open('./dummy.html', wFlameNM, wAttr);
    //必要に応じてsubmit
    //xObjwin.location.href = wURL
    //fx_submit(wURL,lIdx,wFlameNM);

   if(typeof(lIdx) == "undefined") {
      lIdx= 0;
   }

   if(typeof(wFlameNM) == "undefined") {
        sTarget = "_self";
   }

   window.document.forms[lIdx].target = wFlameNM;
   window.document.forms[lIdx].action = wURL;
   window.document.forms[lIdx].submit();


}

function fx_submit(sURL,lIdx,sTarget)
{
   var sAttr = '';

   if(typeof(sURL) == "undefined") {
      sURL= '';
   }

   if(typeof(lIdx) == "undefined") {
      lIdx= 0;
   }

   if(typeof(sTarget) == "undefined") {
        sTarget = "_self";
   }
   else
   {
        if ( sTarget == 'insatsu' )
        {
            sAttr = 'left=0,top=0,width=1015,height=550,top=0,left=0,scrollbars=yes,menubar=yes';
            fx_NewWin(sURL,sTarget,sAttr,lIdx);
            return;
        }

        if ( sTarget == 'pdf' )
        {

            if(!!window.screen)
            {
              sAttr = 'left=0,top=0,width=' + screen.availWidth/2;  //N4,N6,Moz,IE,共用
            }
            else
            {
                sAttr = 'left=0,top=0,width=650,height=768';
            }
            fx_NewWin(sURL,sTarget,sAttr,lIdx);
            return;
        }
        if ( sTarget == 'pdf3' )
        {
            sAttr = 'left=0,top=0,width=1250,height=1000';
            fx_NewWin(sURL,sTarget,sAttr,lIdx);
            return;
        }
   }

   
   window.document.forms[lIdx].target = sTarget;
   if ( sURL != '') {
      window.document.forms[lIdx].action = sURL;
   }
   window.document.forms[lIdx].submit();
}


function fx_chkAll_btnClick(wSelObjNm,wChkObjNm)
{
    obj = fx_findObj(wSelObjNm);
    if ( typeof obj == 'undefined' )
    {
        return;
    }
    if ( obj==null )
    {
        return;
    }

    var blFlg = false;
    switch (obj.value)
    {
        case '1':
            blFlg = true;
            break;
        case '2':
            blFlg = false;
            break;
        default :
            alert(obj.value);
            return;
    }

    fx_chkAll(wChkObjNm,blFlg);
}

function fx_chkAll(wObjNm,blFlg)
{
    obj = fx_findObj(wObjNm);

    if ( typeof obj == 'undefined' )
    {
        return;
    }
    
    if ( obj==null )
    {
        return;
    }
    //全選択 Or 全削除  
    if ( typeof obj.length == 'undefined' )
    {
        obj.checked = blFlg;
    }
    else
    {
        for ( i = 0; i < obj.length ; i++ )
        {
            obj[i].checked = blFlg;
        }
    }
}

function fx_tabchg()
{
    var blF = true;
    for(var i=0;i<arguments.length;i++)
    {
        obj = fx_findObj(arguments[i]);
        if (blF)
        {
            obj.style.display = "block";
            blF = false;
        }
        else
        {
            obj.style.display = "none";
        }
    }
}

function fx_is_opener(NW)
{
    var ua = navigator.userAgent
    if( !!NW.opener )
        if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1 ) 
            return !window.opener.closed
        else return typeof window.opener.document == 'object'
    else return false
}

function fx_eval(strCmd)
{
    //セキュリティ対応必要？？？
    eval(strCmd);
}


//セレクト
//function fiSetList(oListLeft, oListRight, oHdnSelId, act_no) {
function fiSetList(oListLeft, oListRight, act_no) {
    var sID;
    var iLen;
    
    //--- set list ---
    // add button
    if (act_no == "1"){
        oFromList = oListLeft;
        oToList   = oListRight;
    // delete button
    }else{
        oFromList = oListRight;
        oToList   = oListLeft;
    }
    
    //--- add to list ---
    fiAddList(oFromList, oToList);
    
    //--- delete from list ---
    //fiDelList(oFromList);
    
    //--- reconfiguration ---
/*
    with (document.forms[0]){
        // get phrase
        sID = "";
        for (var i=0; i<oListRight.length; i++) {
            sID = sID + "," + oListRight.options[i].text;
        }
        // setting
        iLen = sID.length;
        oHdnSelId.value = sID.substring(1, iLen);

    }
*/
}


/***********************************************************************/
/*  add/delete value                                                   */
/*      parameter1     : from list                                     */
/*      parameter2     : to list                                       */
/*      追加の場合     : oFromList(左のリスト)  oToList(右のリスト)    */
/*      取消の場合     : oFromList(右のリスト)  oToList(左のリスト)    */
/***********************************************************************/
function fiSetList2(oFromList, oToList) {
    
    //--- add to list ---
    fiAddList(oFromList, oToList);
    
    //--- delete from list ---
    fiDelList(oFromList);
    
    //--- reconfiguration ---
    with (document.forms[0]){

    }
}

/************************************************************************/
/*  move selected value in From list to To list                         */
/*      parameter1     : From list                                      */
/*      parameter2     : To list                                        */
/************************************************************************/
function fiAddList(oFromList, oToList) {

    //alert("開始");
    for (var i=0; i<oFromList.length-1; i++) {
        chk = 0;
        // handle following processing if option is selected
        oFromList.options[oFromList.length-1].selected  = false;
        if (oFromList.options[i].selected) {
             oToList.length++;
             oToList.options[oToList.length-2].text = oFromList.options[i].text;
             oToList.options[oToList.length-2].value = oFromList.options[i].value;
        }
    }
    oToList.options[oToList.length-1].text = "　";
    oToList.options[oToList.length-1].value = "";
    oToList.options[oToList.length-1].selected  = false;

    //削除
    //while ( oFromList.selectedIndex != -1)
    //{
        //alert(oFromList.selectedIndex);
        fiDelList(oFromList);
    //}
    //alert("終了");
    return;
}

/************************************************************************/
/*  delete selected value from From list                                */
/*      parameter1     : From list                                      */
/************************************************************************/
function fiDelList(oFromList) {

/*
    var iIdx = -1;
    
    // get selected location
    while ( oFromList.selectedIndex != -1)
    {
        //alert('ループ１');
        for (var i=0; i<oFromList.length-1; i++) {
        //alert('ループ２');
            if (oFromList.options[i].selected ) 
            {
                oFromList.options[i].selected  = false
                if (  oFromList.options[i].value != "" )
                {
                    oFromList.options[i] = null;
                }
                break;
            }
        }
    }
    
    return;
*/

    //alert('削除開始');
    obj = oFromList
    selectLen = obj.length;         //項目数
    selectchk = obj.selectedIndex;  

    if(selectchk != -1){ //選択されている項目があるときだけ処理する
      objstr = "";
      num = 0;
      valueTbl = new Array(selectLen);
      textTbl  = new Array(selectLen);

      for (i=0; i<selectLen; i++){
        //alert('ループ');
        //選択されてるかどうか false：選択されてない　true：選択されてる
        if( (obj.options[i].selected  == true) &&
            (obj.options[i].value     != ""  ) ){
          obj.options[i].selected  = false;
        }else{
          //削除しない項目だけとっておく
          obj.options[i].selected  = false;
          valueTbl[num] = obj.options[i].value;
          textTbl[num]  = obj.options[i].text;
          num++;
        }
      }
      // selectフィールドの中身を、削除しない項目だけに書き換える
      for (i=0; i<num; i++){
          obj.options[i].text = textTbl[i];
          obj.options[i].value = valueTbl[i];
      }
      obj.length = num;
    }

    //alert("削除終了");
}

/************************************************************************/
/*  all selected value from From list                                   */
/*      parameter1     : From list                                      */
/*      parameter1     : To list                                        */
/************************************************************************/
function AllList(oListLeft, oListRight, md) {
    var cnt;
    if (md == "1"){
        oFromList = oListLeft;
        oToList   = oListRight;
        cnt = oListLeft.length;
    // delete button
    }else{
        oFromList = oListRight;
        oToList   = oListLeft;
        cnt = oListRight.length;
    }
    //alert(cnt);
    oFromList.options[oFromList.length-1].selected  = false;
    for (var i=0; i<oFromList.length-1; i++) {
        oToList.length++;
        oFromList.options[i].selected  = false;
        oToList.options[oToList.length-2].selected  = false;
        oToList.options[oToList.length-2].text = oFromList.options[i].text;
        oToList.options[oToList.length-2].value = oFromList.options[i].value;
    }
    oToList.options[oToList.length-1].text = "　";
    oToList.options[oToList.length-1].value = "";
    oToList.options[oToList.length-1].selected  = false;

/*
    //alert(i);
    for (var n=0; n<cnt-1; n++) {
        oFromList.options[0] = null;
    }
    //fiDelList(oFromList);
    return;
*/
    //alert('削除開始');
    obj = oFromList
    selectLen = obj.length;         //項目数
    selectchk = obj.selectedIndex;  

      objstr = "";
      num = 0;
      valueTbl = new Array(selectLen);
      textTbl  = new Array(selectLen);

      for (i=0; i<selectLen; i++){
        //alert('ループ');
        //選択されてるかどうか false：選択されてない　true：選択されてる
        if( (obj.options[i].value     != ""  ) ){
          obj.options[i].selected  = false;
        }else{
          //削除しない項目だけとっておく
          obj.options[i].selected  = false;
          valueTbl[num] = obj.options[i].value;
          textTbl[num]  = obj.options[i].text;
          num++;
        }
      }
      // selectフィールドの中身を、削除しない項目だけに書き換える
      for (i=0; i<num; i++){
          obj.options[i].text = textTbl[i];
          obj.options[i].value = valueTbl[i];
      }
      obj.length = num;
}
function nosel(ToList)
{
    for (var i=0; i<ToList.length; i++) {
        ToList.options[i].selected=false;
    }
}
function sel(ToList)
{
    for (var i=0; i<ToList.length; i++) {
        ToList.options[i].selected=true;
    }
}

function is_check(nm)
{
    obj = fx_findObj(nm);
    var intRet = false;
    if ( typeof obj == 'undefined' )
    {
        alert('対象データが選択されていません。');
        return intRet;
    }
    
    if ( obj==null )
    {
        alert('対象データが選択されていません。');
        return intRet;
    }

    if ( typeof obj.length == 'undefined' )
    {
        if ( obj.checked )
        {
            intRet = true;
        }
    }
    else
    {
        for ( i = 0; i < obj.length ; i++ )
        {
            if ( obj[i].checked )
            {
                intRet = true;
                break;
            }
        }
    }

    if (intRet==false)
    {
        alert('対象データが選択されていません。');
    }
    return intRet
}

function is_check2(nm,msg)
{
    obj = fx_findObj(nm);
    var intRet = false;
    if ( typeof obj == 'undefined' )
    {
        alert(msg);
        return intRet;
    }
    
    if ( obj==null )
    {
        alert(msg);
        return intRet;
    }
    if ( obj.value=='' )
    {
        alert(msg);
        return intRet;
    }
}