// ========== ページロード時のイベント定義 ==========

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
    window.onload = func;
    } else {
    window.onload = function() {
     oldonload();
     func();
    }
}
}	// function addLoadEvent() end


// prototype.js(1.6.0 RC1)の機能でドキュメントロード完了時（画像ロード前）に関数実行
document.observe("dom:loaded", function() { PageLoadInit(); });

// ドキュメント及び画像が全てロードされてからの実行の場合はこっちを有効にする
//addLoadEvent(PageLoadInit);

function PageLoadInit(){	// ★ページロード時に実行する処理のファンクションを列挙
  Shadowbox.init();  // ShadowBox
  tableintialize();  // テーブルセルハイライト（tables_util.js）
  searchtypecheck(); // DBF検索フォーム
  CmtandTrbHide();   // コメント・トラバ非表示
  CmtAgreeChkIns();  // コメントフォーム同意確認追加
  NaireGalleryIns(); // 名入れイメージ表示（naire_correspondence.js）
}




// ========== flash呼び出し汎用 ==========

function flashload(url, width, height, title, quality){
  document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab=version=6,0,29,0" width="' + width + '" height="' + height + '" title="' + title + '">' );
  document.write( '<param name="movie" value="' + url + '" />' );
  document.write( '<param name="quality" value="' + quality + '" />' );
document.write( '<embed src="' + url + '" quality="' + quality + '" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>' );
  document.write( '</object>' );
} // function flashload() end


// ========== ブロック要素表示・非表示切り替え汎用 ==========

function disptoggle(targetElemID){
  var ToggleElemID = document.getElementById(targetElemID);
  ToggleElemID.style.display =(ToggleElemID.style.display != 'none')? 'none' : 'block';
}	// function disptoggle() end


// ========== DBF検索表示切替関連 ==========

function searchtypecheck(){	// DBF検索フォーム「商品以外」のとき価格検索を選択不可にする
  if (!document.getElementById('searchtype')) return false;
  if (!document.getElementById('pricesearch')) return false;
  if (!document.getElementById('setprice')) return false;
  //if (!document.getElementById('pricecomparetype')) return false;

  var PriceSearchFlag = (document.getElementById('searchtype').selectedIndex == 2) ? false : true;

  if (PriceSearchFlag == false) document.getElementById('pricesearch').checked = PriceSearchFlag;
  document.getElementById('pricesearch').disabled = !PriceSearchFlag;
  if (PriceSearchFlag == false) document.getElementById('setprice').value = '';
  document.getElementById('setprice').disabled    = !PriceSearchFlag;
  //document.getElementById('pricecomparetype').disabled = !PriceSearchFlag;
  dbfformtgl();
}	// function searchtypecheck() end


function dbfformtgl(){	// DBF検索フォーム「価格で絞込み」の表示切替
  if (!document.getElementById('pricesearch')) return false;
  var disp = (document.getElementById('pricesearch').checked == true)?'inline':'none';
  document.getElementById('setpricesearch').style.display = disp;
}	// function dbfformtgl() end


// ========== コメント・トラバ制御関連 ==========

function CmtandTrbHide(){	// ロード時にコメント一覧・投稿フォーム・トラバ一覧を非表示にする
  if (document.getElementById('comment-cancel')) return false; // キャンセルボタンがある＝確認画面のときは中止
  var InitHideElemIDs = new Array('comments-form','trackbackslist'); // ★隠したいブロックのidを指定
  for (i=0; i<InitHideElemIDs.length; i++){
       try  {document.getElementById(InitHideElemIDs[i]).style.display = 'none';}
       catch(inithideErr){}
  }
}	// function inithide() end





function CmtAgreeChkIns(){	// コメント投稿に「同意して投稿する」段落を追加
  if (!document.getElementById('comments-form')) return false; // 投稿フォームの存在チェック
  if (!document.getElementById('comment-preview')) return false; // 「確認」ボタンの存在チェック
  if (!document.getElementById('commentnotice')) return false; // 「お気軽に投稿下さい」段落の存在チェック

  // [prototype.jsの機能で]「お気軽に投稿下さい」段落の終了タグの後に指定した要素を追加
  new Insertion.After('commentnotice','<p class="agreementcheck"><input type="checkbox" name="agreecheck" id="agreecheckbox" /><label for="agreecheckbox">下記規約、及び <a class="point" href="/company_info/privacy_policy.html">個人情報保護方針</a>に同意して投稿する。</label></p>');

  if (!document.getElementById('agreecheckbox')) return false;

  // 投稿フォームのonsubmitにイベント定義
  document.getElementById('comments-form').onsubmit = function() {return CommentSubmitChk();}
}	// function CmtAgreeChkIns() end


function CommentSubmitChk(){	// コメント投稿送信時の同意・本文入力チェック
  if (document.getElementById('agreecheckbox').checked == false) { // 「同意」チェックされていないとき
      alert('コメントを投稿するには規約への同意が必要です。\n\n「同意して投稿する」チェックボックスをチェックして下さい。');
      return false; // 送信キャンセル
  }
  if (document.getElementById('comment-text').value == '') { // 本文が空のとき
      alert('コメントの本文が入力されていません。');
      return false; // 送信キャンセル
  }
}	// function CommentSubmitChk() end

