// 制御用JavaScript：「リンクするファイル」でsecure領域にも書き出しているのでMTテンプレタグ使用不可
// 【カート用デフォルトJSはファイルを別途読み込み】

//if (window.addEventListener) { window.addEventListener("load", PageLoadInit, false); }
//else if (window.attachEvent) { window.attachEvent("onload", PageLoadInit); }

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

function PageLoadInit(){ // ★ページロード時に実行する処理のファンクションを列挙
  Shadowbox.init(); // ShadowBox
  TreeInit();
}


/* =============== 左メニュー展開 =============== */

function TreeInit(){if(!document.getElementById)return false;if(!document.getElementsByName)return false;if(!document.getElementsByTagName)return false;var TreeBlk=document.getElementById("directories");if(!TreeBlk)return false;var ListMarkImgs=TreeBlk.getElementsByTagName("img");var ListMarkImgsCount=ListMarkImgs.length;if(ListMarkImgsCount==0)return false;for(var i=0;i<ListMarkImgsCount;i++){if(ListMarkImgs[i].getAttribute("src").indexOf("plus")!=-1){TreeToggle(ListMarkImgs[i],1);ListMarkImgs[i].onclick=function(){return TreeToggle(this)};ListMarkImgs[i].style.cursor="pointer"}else if(ListMarkImgs[i].getAttribute("src").indexOf("minus")!=-1){ListMarkImgs[i].onclick=function(){return TreeToggle(this)};ListMarkImgs[i].style.cursor="pointer"}}var TreeTglNote=document.createElement("p");TreeTglNote.className="directoriesnote";var TreeTglNoteImg=document.createElement("img");TreeTglNoteImg.setAttribute("src","/images/operation_explanation.gif");TreeTglNoteImg.setAttribute("width",190);TreeTglNoteImg.setAttribute("height",75);TreeTglNoteImg.setAttribute("alt","＋マークをクリックでサブカテゴリを展開します。");TreeTglNote.appendChild(TreeTglNoteImg);var TreeTglNoteTar=TreeBlk.getElementsByTagName("div")[0];TreeTglNoteTar.appendChild(TreeTglNote)}function TreeToggle(Elm,Initflag){var ParentElm=Elm.parentNode;var ParentElmName=ParentElm.nodeName.toLowerCase();while(ParentElmName!="li"){ParentElm=ParentElm.parentNode;ParentElmName=ParentElm.nodeName.toLowerCase();if(ParentElmName=="li")break}var InsideLists=ParentElm.getElementsByTagName("ul");var InsideListsCount=InsideLists.length;if(InsideListsCount==0)return false;if(!Initflag){var ImgSrcPath=Elm.getAttribute("src");if(ImgSrcPath.indexOf("minus")!=-1){Elm.setAttribute("src",ImgSrcPath.replace("minus","plus"))}else if(ImgSrcPath.indexOf("plus")!=-1){Elm.setAttribute("src",ImgSrcPath.replace("plus","minus"))}}DispToggle(InsideLists[0])}


/* =============== デザイン詳細POPUP =============== */

if (window.addEventListener) { window.addEventListener("load", DetailPhotoZoomPopupDefine, false); }
else if (window.attachEvent) { window.attachEvent("onload", DetailPhotoZoomPopupDefine); }


function DetailPhotoZoomPopupDefine(){
  var TargetZone         = document.getElementById("commoditydetail"); if (!TargetZone) return false;
  var TargetAnchors      = TargetZone.getElementsByTagName("a");
  var TargetAnchorsCount = TargetAnchors.length; if (TargetAnchorsCount == 0) return false;

  for (var i=0; i<TargetAnchorsCount; i++){
       if (TargetAnchors[i].getAttribute("rel") == "zoompopup" && TargetAnchors[i].getAttribute("target") == "designpopup") {
           TargetAnchors[i].onclick = function () {DetailPhotoZoomPopup(this);return false;};
       }
       else if (TargetAnchors[i].getAttribute("rel") == "needleworkpopup" && TargetAnchors[i].getAttribute("target") == "descpopup") {
           TargetAnchors[i].onclick = function () {NeedleworkImgPopup(this);return false;};
       }
       else if (TargetAnchors[i].getAttribute("rel") == "nairepopup" && TargetAnchors[i].getAttribute("target") == "naireimgpopup") {
           TargetAnchors[i].onclick = function () {NaireImgPopup(this);return false;};
       }
  }
}	// function DetailPhotoZoomPopupDefine() end


function DetailPhotoZoomPopup(Anchor){	/* デザイン拡大用 */
  var ImgSrc = Anchor.getAttribute("href");
  var PopWin = window.open(ImgSrc,"designpopup","toolbar=0,scrollbars=1,status=1,resizable=1,width=275,height=775");
  PopWin.focus(); return false;
}	// function DetailPhotoZoomPopup() end

function NeedleworkImgPopup(Anchor){	/* 縫製仕様詳細用 */
  var ImgSrc = Anchor.getAttribute("href");
  var PopWin = window.open(ImgSrc,"descpopup","toolbar=0,scrollbars=1,status=1,resizable=1,width=540,height=430");
  PopWin.focus(); return false;
}	// function DetailPhotoZoomPopup() end

function NaireImgPopup(Anchor){	/* 名入れ説明用 */
  var ImgSrc = Anchor.getAttribute("href");
  var PopWin = window.open(ImgSrc,"naireimgpopup","toolbar=0,scrollbars=1,status=1,resizable=1,width=530,height=800");
  PopWin.focus(); return false;
}	// function NaireImgPopup() end


/* =============== コンタクトフォームPOPUP =============== */

if (window.addEventListener) { window.addEventListener("load", ContactWinPopupDefine, false); }
else if (window.attachEvent) { window.attachEvent("onload", ContactWinPopupDefine); }


function ContactWinPopupDefine(){
  var OnPageAllAnchors   = document.getElementsByTagName("a");
  var OnPageAnchorsCount = OnPageAllAnchors.length;

  for (var i=0; i<OnPageAnchorsCount; i++){
       if (OnPageAllAnchors[i].getAttribute("rel") == "contactform" && OnPageAllAnchors[i].getAttribute("target") == "contactpopup") {
           OnPageAllAnchors[i].onclick = function () {ContactWinPopup(this);return false;}
       }
  }
}	// function ContactWinPopupDefine() end


function ContactWinPopup(Anchor){
  var ContactForm = Anchor.getAttribute("href");
  var PopWin = window.open(ContactForm,"contactpopup","toolbar=0,scrollbars=1,status=1,resizable=1,width=725,height=700");
  PopWin.focus(); return false;
}	// function ContactWinPopup() end


/* =============== 注文数量入力チェック =============== */

//if (window.addEventListener) { window.addEventListener("load", CartSubmitChkDefine, false); }
//else if (window.attachEvent) { window.attachEvent("onload", CartSubmitChkDefine); }

function CartSubmitChkDefine(){
  var OnPageAllForms   = document.getElementsByTagName("form");
  var OnPageFormsCount = OnPageAllForms.length;
  if (OnPageFormsCount == 0 || !document.getElementById("orderquantity")) return false;

  for (var i=0; i<OnPageFormsCount; i++){
       if (OnPageAllForms[i].getAttribute("action").indexOf("detail.php") != -1) {
           OnPageAllForms[i].onsubmit = function () {	/* デフォルトアクションの抑止がうまく行かないのでべた書き */
              var OrderQtyInput = document.getElementById("orderquantity"); if (!OrderQtyInput) return false;
              var OrderQtyCont  = OrderQtyInput.value;
              if (isNaN(OrderQtyCont) || OrderQtyCont == "" || OrderQtyCont < 1 || OrderQtyCont.indexOf('.',0) != -1) {
                  alert("ご注文枚数を正しく入力して下さい。"); return false;
              }
           }; break;
       }
  }
}


/* =============== デザイン詳細の名入れ/文字差替え領域 =============== */

if (window.addEventListener) { window.addEventListener("load", DesignNoboriOptTglDefine, false); }
else if (window.attachEvent) { window.attachEvent("onload", DesignNoboriOptTglDefine); }


function DesignNoboriOptTglDefine(){
  var OptionZone     = document.getElementById("cmdtputincart");	// オプション選択（親）ブロック：親のチェック
  if (!OptionZone) return false;

  var NamedZone      = document.getElementById("namedoption");	// 名入れ選択ブロック
  var TxtReplaceZone = document.getElementById("txtreplaceoption");	// 文字差替えブロック
  if (!NamedZone || !TxtReplaceZone) return false;

  var NamedChk       = document.getElementById("namedoptioncheck");	// 名入れ選択チェック
  var TxtReplaceChk  = document.getElementById("txtreplaceoptioncheck");	// 文字差替えチェック
  if (!NamedChk || !TxtReplaceChk) return false;

  NamedChk.onclick      = function () {DesignNoboriOptTgl(this);};
  TxtReplaceChk.onclick = function () {DesignNoboriOptTgl(this);};

  DesignNoboriOptTgl(NamedChk);
  DesignNoboriOptTgl(TxtReplaceChk);
}	// function DesignNoboriOptTglDefine() end

function DesignNoboriOptTgl(SrcChk){
  var CheckedSrcID = SrcChk.getAttribute("id");
  var TargetZoneID = CheckedSrcID.replace("check","");
  //alert("Target=" + TargetZoneID + "\n\nChecked=" + SrcChk.checked);
  document.getElementById(TargetZoneID).style.display = (!SrcChk.checked) ? "none" : "" ;	// 表示切替
  InputElmsDisabledChg(document.getElementById(TargetZoneID),!SrcChk.checked);	// 使用可不可の切替
}	// function DesignNoboriOptTgl() end


/* =============== 汎用のfunction =============== */

function DispToggle(Elm){
  var DispStatus = Elm.style.display;
  Elm.style.display = (DispStatus == "none") ? "" : "none" ;
}


function addClass(element,value) {
  if (!element.className) {
      element.className = value;
  } else {
      newClassName = element.className;
      newClassName += " ";
      newClassName += value;
      element.className = newClassName;
  }
}


// 指定したidを持つブロック内にある入力項目の使用可・不可一括切替
function InputElmsDisabledChg(TargetZone,Flag){
  var TargetNodeNames      = new Array("input","select","textarea");	// 切替対象のnodeName
  var TargetNodeNamesCount = TargetNodeNames.length;

  for (var Nodes=0; Nodes<TargetNodeNamesCount; Nodes++){
       var InsideInputs      = TargetZone.getElementsByTagName(TargetNodeNames[Nodes]);
       var InsideInputsCount = InsideInputs.length;
       for (var Elm=0; Elm<InsideInputsCount; Elm++){
            InsideInputs[Elm].disabled = Flag ;
            InsideInputs[Elm].style.backgroundColor = (Flag == true) ? "#cccccc" : "" ;
       }
  }
}


/* ----- 汎用ポップアップ：【イベント定義してないので現在使えません】 ----- */

function ImagePopup(Anchor){
  var ImgSrc = Anchor.getAttribute("href");
  var RelAttrValue  = Anchor.getAttribute("rel");	// alert(RelAttrValue);
  var RelAttrArray  = RelAttrValue.split(',');	// alert(RelAttrArray);
  var RelAttrsCount = RelAttrArray.length;	//alert(RelAttrsCount);
  var WinWidth  = RelAttrArray[1];
  var WinHeight = RelAttrArray[2];	//alert(WinWidth+"×"+WinHeight);
  if (RelAttrsCount != 3 || isNaN(WinWidth) || isNaN(WinHeight)) {location.href = ImgSrc;}
  else {
      var PopWin = window.open(ImgSrc,"imagepopup","toolbar=0,scrollbars=1,status=1,resizable=1,width="+WinWidth+",height="+WinHeight);
      PopWin.focus(); return false;
  }
}



