//*************************************************************
//システム名     コア物品／発注者
//サブシステム名 発注者
/**
 * 指名先一覧機能
 * @author NEC
 * @version 1.0, 2002.07.23, 新規作成<BR>
 *          1.1, 2003.06.13, 障害票159対応<BR>
 *          1.2, 2003.06.14, 障害票189対応<BR>
 *          1.3, 2003.06.17, V3-結合-026対応<BR>
 *          1.4, 2003.06.18, V3-結合-032対応<BR>
 *          1.5, 2003.06.21, V3-総合-273対応, V3-結合-042対応<BR>
 *          1.6, 2003.06.23, V3-結合-036対応<BR>
 *          3.1, 2003.10.20, V3.1-総合-016対応<BR>
 */
//*************************************************************

//-------------------------------------------------------------
// クリアボタン押下時処理
//-------------------------------------------------------------
function onClear()
{
  document.formCondition.searchCompanyNumber.value="";
  document.formCondition.searchCompanyName.value="";
  document.formCondition.searchCompanyTelephone.value="";
  document.formCondition.searchCompanyAddress.value="";
  document.formCondition.searchCompanyNumber.focus();
}//onClear

//-------------------------------------------------------------
// 紙入札情報入力画面閉じる処理
//-------------------------------------------------------------
function onInputClose()
{
  window.close();
}//onInputClose

//-------------------------------------------------------------
// 紙入札情報登録画面表示
//-------------------------------------------------------------
function onInsert()
{
  if( document.formRegist.companyNumber.value=="" )
  {
    alert("企業を選択して下さい。");
    return;
  }

  opener.top.wpMain.dispatchInsertRequest( document.formRegist );
  window.close();
}//onInsert

function dispatchInsertRequest( input )
{
  // 入力業者コード
  document.formHPR01103.companyNumber.value=input.companyNumber.value;

  dispatch(document.formHPR01103,"H515HPR010");
}//onInsert



function onInputStart()
{
  // 通信中ダイアログを閉じる
  if( document.common )
  {
    onLoadPopup();
  }
  else
  {
    opener.top.wpMain.closeSubWindow();
    opener.top.wpMain.resetCommandFormObj();
  }

} //onInputStart

//-------------------------------------------------------------
// 選択業者設定処理
//-------------------------------------------------------------
function setInputCompany( companyNumber, companyName )
{
  document.formRegist.companyNumber.value=companyNumber;
}//setInputCompany

//-------------------------------------------------------------
// 紙入札情報登録画面表示
//-------------------------------------------------------------
function onSearch()
{
  var errmsg="";
  
  // 要求処理初期設定
  if( !prepareDispatch( document.formCondition, 'H5135HPR010' ) )
    return;

  // 検索企業IDの入力チェック
  if( !checkId( document.formCondition.searchCompanyNumber.value ) )
    errmsg+="検索企業IDは半角数字で入力してください\n";

  // 検索代表者電話番号の入力チェック
  if( !checkTelephone( document.formCondition.searchCompanyTelephone.value ) )
    errmsg+="検索代表者電話番号は半角数字で入力してください\n";

  if( errmsg!="" )
  {
    alert( errmsg );
    resetCommandFormObj();
    return;
  }

  // ポップアップ検索要求処理呼出し
  callSubmitCall( 'submitCallPopUpSearch' );
}//onSearch

//-------------------------------------------------------------
// ポップアップ検索要求処理
//-------------------------------------------------------------
function submitCallPopUpSearch()
{
  doSubmit();

  // ポップアップウィンドウ作成
  createPopupWindow( 
    800, 570,

    // init
     "document.formRequest.searchCompanyNumber.value=opener.top.wpMain.document.formCondition.searchCompanyNumber.value;"
    +"document.formRequest.searchCompanyName.value=opener.top.wpMain.document.formCondition.searchCompanyName.value;"
    +"document.formRequest.searchCompanyTelephone.value=opener.top.wpMain.document.formCondition.searchCompanyTelephone.value;"
    +"document.formRequest.searchCompanyAddress.value=opener.top.wpMain.document.formCondition.searchCompanyAddress.value;"
    +"document.formRequest.searchPaperFlag.value=opener.top.wpMain.document.formCondition.searchPaperFlag.value;"
    +"document.formRequest.projectNumber.value=opener.top.wpMain.document.formCondition.projectNumber.value;"
    +"submitCall();",

    // params
   getStdParams()
    +"<INPUT type='hidden' name='projectNumber'>"
    +"<INPUT type='hidden' name='searchCompanyNumber'>"
    +"<INPUT type='hidden' name='searchCompanyName'>"
    +"<INPUT type='hidden' name='searchCompanyTelephone'>"
    +"<INPUT type='hidden' name='searchCompanyAddress'>"
    +"<INPUT type='hidden' name='searchPaperFlag'>"
    +"<INPUT type='hidden' name='unavailable' value='" + document.formHPR01001.unavailable.value + "'>"
  );

  //NN対策
  focusSubWindow();

}//submitCallPopUpSearch

/* HTML読込み時の初期処理 */
function onStart() {
  /*HTMLが読み込まれた際に、初期処理用関数を呼び出す*/
  onLoad();
}

/*指名業者編集画面表示処理*/
function setFormHPR01002() {

  /*案件番号*/
  document.formHPR01002.projectNumber.value=document.formHPR01001.projectNumber.value;

  dispatch(document.formHPR01002, "H514HPR011");

}

/* 削除チェックボタンを全て選択状態にする。 */
function allSelectDeleteCheck() {
  var changeSelectFlg = false;

  if (formProject_length >= 2) {
    for (i = 0; i < document.formHPR01001.checkDelete.length; i++) {
      if (document.formHPR01001.checkDelete[i].type == "checkbox") {
        if (!document.formHPR01001.checkDelete[i].checked) {
          changeSelectFlg = true;
          break;
        }
      }
    }

    for (i = 0; i < document.formHPR01001.checkDelete.length; i++) {
      if (document.formHPR01001.checkDelete[i].type == "checkbox") {
        document.formHPR01001.checkDelete[i].checked = changeSelectFlg;
      }
    }

  } else {
    if (document.formHPR01001.checkDelete.type == "checkbox") {
      if (!document.formHPR01001.checkDelete.checked) {
        changeSelectFlg = true;
      }
    }

    if (document.formHPR01001.checkDelete.type == "checkbox") {
      document.formHPR01001.checkDelete.checked = changeSelectFlg;
    }
  }
}

/* 指名業者削除処理 */
function setFormHPR01003() {
  var changeSelectFlg = false;

  //削除業者対象のチェック
  if (formProject_length >= 2)
  {
    for (i = 0; i < document.formHPR01001.checkDelete.length; i++)
    {
      if (document.formHPR01001.checkDelete[i].type == "checkbox")
      {
        if (document.formHPR01001.checkDelete[i].checked)
        {
          changeSelectFlg = true;
        }
      }
    }
  }
  else
  {
    if (document.formHPR01001.checkDelete.type == "checkbox")
    {
      if (document.formHPR01001.checkDelete.checked)
      {
        changeSelectFlg = true;
      }
    }
  }
  if(changeSelectFlg==false){
    alert("削除する業者を選択してください");
  }

  if (formProject_length == 0 ) {
    return ;
  }

  j = 0;

  if (formProject_length >= 2) {
    for (i = 0; i < document.formHPR01001.checkDelete.length; i++) {
      if (document.formHPR01001.checkDelete[i].type == "checkbox") {
        if (document.formHPR01001.checkDelete[i].checked == true) {
          
          document.formHPR01003["companyNumber_" + j ].value = document.formHPR01001.companyNumber[i].value;
          j = j + 1;

        }
      }
    }

  } else if (formProject_length == 1) {
    if (document.formHPR01001.checkDelete.type == "checkbox") {
      if (document.formHPR01001.checkDelete.checked == true) {
                  document.formHPR01003.companyNumber_0.value = document.formHPR01001.companyNumber.value;
                  j = j + 1;
      }
    }
  }

  if (j > 0) {

    /* request()を呼出す */
    dispatch(document.formHPR01003, "H5141HPR010");
  }
  else {
    return;
  }
}

/* 通知書一括発行処理 */
function setFormHPR01004() {
  var addFlg = false;
  var companyNumber = "";

  j = 0;


  if (formProject_length >= 2) {
    for (i = 0; i < document.formHPR01001.checkDelete.length; i++) {
      if (document.formHPR01001.checkDelete[i].type == "checkbox") {
        document.formHPR01004["companyNumber_" + j ].value = document.formHPR01001.companyNumber[i].value;
        j = j + 1;
      }
    }

  } else if (formProject_length == 1)  {
    if (document.formHPR01001.checkDelete.type == "checkbox") {
      document.formHPR01004.companyNumber_0.value = document.formHPR01001.companyNumber.value;
      j = j + 1;
    }
  }

  if (j > 0) {

    /* request()を呼出す */
    dispatch(document.formHPR01004, "H5143HPR012");
  }
  else {
    return;
  }
}

/* 通知書発行画面表示処理 */
function setFormHPR01005(row) {

  if (formProject_length >= 2) {
    /* 受注者番号 */
    document.formHPR01005.companyNumber.value = document.formHPR01001.companyNumber[row].value;

    /* 企業名称 */
    document.formHPR01005.companyName.value = document.formHPR01001.companyName[row].value;

    /* 企業代表者名 */
    document.formHPR01005.companyRepresent.value = document.formHPR01001.companyRepresent[row].value;

  } else {
    /* 受注者番号 */
    document.formHPR01005.companyNumber.value = document.formHPR01001.companyNumber.value;

    /* 企業名称 */
    document.formHPR01005.companyName.value = document.formHPR01001.companyName.value;

    /* 企業代表者名 */
    document.formHPR01005.companyRepresent.value = document.formHPR01001.companyRepresent.value;
  }

  /* request()を呼出す */
  dispatch(document.formHPR01005, "H514HPR012");
}

function moveBackScreen() {

  /* request()を呼出す */
  dispatch(document.formHPR01006, "H513HPR009");
}

/* 通知書発行画面表示処理 */
function setFormHPR01007(row) {

  if (formProject_length >= 2) {
    /* 受注者番号 */
    document.formHPR01007.companyNumber.value = document.formHPR01001.companyNumber[row].value;

  } else {
    /* 受注者番号 */
    document.formHPR01007.companyNumber.value = document.formHPR01001.companyNumber.value;

  }

  /* request()を呼出す */
  dispatch(document.formHPR01007, "H619HTS048");
}

