//  採用情報ページの表示モジュール
//
//  構成要素：    職種／応募資格／勤務時間／給与／待遇／応募方法／給与例／会社概要
//
//  付加機能：    無し
//
//  id命名規約：  '職種'表示用<p>           = aboutOccupation
//              '応募資格'表示用<p>        = aboutRequirements
//              '勤務時間'表示用<p>        = aboutWorkingHoures
//              '給与'表示用<p>           = aboutAllowance
//              '待遇'表示用<p>           = aboutTreatment
//              '応募方法'表示用<p>        = aboutApplication
//              '給与例'表示用<p>          = aboutExampleAllowance
//              '会社概要'表示用<p>        = aboutCompanyOutline
//
//  実行に必要なライブラリ：
//              prototype.js
//              Xml2Obj.js
//
//  XMLデータファイル：
//              recruitData.xml
//
//  2008/10/10 (c) Ohsako, Junichi
//



/*---------- 名前空間の初期化 ----------*/
var showRecruit;
if(!showRecruit) {
  showRecruit = Object();
}


/*---------- 読み込み表示用関数 ----------*/
showRecruit.loadContents =
function() {
  /*--- オブジェクトの生成 ---*/
  showRecruit.makeObj(['aboutOccupation',
                      'aboutRequirements',
                      'aboutWorkingHoures',
                      'aboutAllowance',
                      'aboutTreatment',
                      'aboutApplication',
                      'aboutExampleAllowance',
                      'aboutCompanyOutline'
  ]);
  new Ajax.Request('php/recruitData.xml', {
    asynchronous: false,
    method: 'post',
    parameters: '',
    onComplete: function(request) {
                  // 受信データオブジェクトをXMLとして取得し、レコード配列オブジェクトを生成
                  var dbResult = new Xml2Obj(request.responseXML);
                  dbResult.buildRecords();
                  records = dbResult.getRecords();
                  // ここから各エレメントのプロパティに代入
                  // 有効なデータが存在するかを判定
                  if(records.length) { 
                    // プロパティから値を取り出してDOM出力
                    for(var i = 0; i < records.length; i++) {
                      // 職種説明文
                      if(records[i].occupation) {
                        var expBody = records[i].occupation.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutOccupation.innerHTML = expBody;
                      } else {
                        showRecruit.aboutOccupation.style.display = 'none';
                      }
                      // 応募資格説明文
                      if(records[i].requirements) {
                        var expBody = records[i].requirements.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutRequirements.innerHTML = expBody;
                      } else {
                        showRecruit.aboutRequirements.style.display = 'none';
                      }
                      // 勤務時間説明文
                      if(records[i].workingHoures) {
                        var expBody = records[i].workingHoures.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutWorkingHoures.innerHTML = expBody;
                      } else {
                        showRecruit.aboutWorkingHoures.style.display = 'none';
                      }
                      // 給与説明文
                      if(records[i].allowance) {
                        var expBody = records[i].allowance.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutAllowance.innerHTML = expBody;
                      } else {
                        showRecruit.aboutAllowance.style.display = 'none';
                      }
                      // 待遇説明文
                      if(records[i].treatment) {
                        var expBody = records[i].treatment.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutTreatment.innerHTML = expBody;
                      } else {
                        showRecruit.aboutTreatment.style.display = 'none';
                      }
                      // 応募方法説明文
                      if(records[i].application) {
                        var expBody = records[i].application.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutApplication.innerHTML = expBody;
                      } else {
                        showRecruit.aboutApplication.style.display = 'none';
                      }
                      // 給与例説明文
                      if(records[i].exampleAllowance) {
                        var expBody = records[i].exampleAllowance.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutExampleAllowance.innerHTML = expBody;
                      } else {
                        showRecruit.aboutExampleAllowance.style.display = 'none';
                      }
                      // 会社概要
                      if(records[i].companyOutline) {
                        var expBody = records[i].companyOutline.replace(/\r\n/g, "\n");
                        expBody = expBody.replace(/\r/g, '\n');
                        expBody = expBody.replace(/\n/g, '<br />');
                        showRecruit.aboutCompanyOutline.innerHTML = expBody;
                      } else {
                        showRecruit.aboutCompanyOutline.style.display = 'none';
                      }
                    }
                  }
                }
    }
  );
}



/*---------- 要素オブジェクト生成関数 ----------*/
showRecruit.makeObj =
function(ids) {
  for(var i = 0; i < ids.length; i++) {
    showRecruit[ids[i]] = document.getElementById(ids[i]);
  }
}

