// JavaScript Document

//■■■■■画像マウスオーバーfunction■■■■■
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for(i=0;i<(a.length-2);i+=3) {
    if ((x=MM_findObj(a[i]))!=null){
      document.MM_sr[j++]=x;
      if(!x.oSrc) x.oSrc=x.src;
      
      var arr1 = x.oSrc.split("/");
      var arr2 = a[i+2].split("/");
      arr1[arr1.length-1] = arr2[arr2.length-1];
      var src = arr1.join("/");
      x.src=src;
    }
   }
}

//■■■■■別WindowOpen function■■■■■
function WinOpen(winname,url,w,h){
var winop=window.open(url,winname,'scrollbars=1,menubar=0,toolbar=0,status=0,resizable=1,width='+w+',height='+h+'');
winop.focus();
}
// ▼呼び出しソース▼
//<a href="javascript:function voi(){};voi()" onclick="WinOpen('win2','aaa.html',720,480)">リンク</a>


//■■■■■複数チェックボックスを一括選択する function■■■■■
function allChange(FormName,FieldName,Check){
  if(Check){  CHECK = true;
  }else{    CHECK = false;
  }
  for(n=0;n<=FormName.length-1;n++){
    if(FormName.elements[n].type == "checkbox" && FormName.elements[n].name == FieldName){
      FormName.elements[n].checked = CHECK;
    }
  }
}
// ▼呼び出しソース▼
//<input type="checkbox" name="ChangeAll" onClick="javascript:allChange(this.form,'ItemCheck',this.checked);">
//<a href="javascript:allChange(DataForm,'ItemCheck',true);">リンク</a>
//<a href="javascript:allChange(DataForm,'ItemCheck',false);">リンク</a>


function allProductCheck(frm, flg) {
 for (var i = 0; i < frm.elements.length; i++) {
  if (frm.elements[i].type == "checkbox") {
   frm.elements[i].checked = flg;
  }
 }
}

//20070731 NECST ADD START------------->
// deal with (more than)double click and backbutton 
function resetToken2Forward(obj){
  var frmLen = self.document.forms.length; 
  var frm = null;
  var paramObj = null;

  var SUBMIT_URL = "/cart/resetTokenWithNextForward.do";

  //check parameter's ID
  if(obj == null || obj == ""){
    return false;
  }
  
  //check form exists.
  if(frmLen > 0){
    //check parameter(hidden)object exists.
    
    for(var i = 0; i < frmLen; i++){
      frm = self.document.forms[i];
      paramObj = frm.NEXTFORWARD_KEYNAME;

      if( paramObj != null && typeof paramObj != 'undefined' ){
        break;
      }
    }
    //no parameter(hidden)object
    if( paramObj == null || typeof paramObj == 'undefined' ){
      return false; 
    }
    
    //set parameter value and submit form
    paramObj.value = obj;
    frm.action = SUBMIT_URL;
    frm.submit();
  }else{
    //no forms
    return false;
  }
}
//20070731 NECST ADD END<-------------


//■■20070805■ブラウザ判別CSS■■■
function envSet() {
  // ブラウザ判別
  var ua = navigator.userAgent;
  this.NN4  = (document.layers);
  this.IE5 = (ua.indexOf("MSIE 5") != -1);
  this.IE50 = (ua.indexOf("MSIE 5.0") != -1);
  this.IE55 = (ua.indexOf("MSIE 5.5") != -1);
  this.IE6 = (ua.indexOf("MSIE 6") != -1);
  this.IE7 = (ua.indexOf("MSIE 7") != -1);
  this.IE70 = (ua.indexOf("MSIE 7.0") != -1);
  this.IE8 = (ua.indexOf("MSIE 8") != -1);
  this.IE80 = (ua.indexOf("MSIE 8.0") != -1);
  this.IE9 = (ua.indexOf("MSIE 9") != -1);
  this.IE90 = (ua.indexOf("MSIE 9.0") != -1);
  this.IE4  = (ua.indexOf("MSIE 4") != -1);
  this.IE   = (ua.indexOf("MSIE") != -1);
  this.Moz  = (ua.indexOf("Gecko") != -1);
  this.Op6  = (ua.match(/Opera.6/) != null); // Opera "6" only
  this.Omn  = (ua.indexOf("OmniWeb") != -1);
  this.Win  = (ua.indexOf("Windows") != -1);
  this.Mac  = (ua.indexOf("Mac") != -1);
  if (this.Op6) this.IE50 = this.IE = false; // WinIE を騙っていた時の対策
  if (this.Omn) this.NN4            = false; // document.layers に反応してるので

  // CSS ファイルのあるディレクトリ（絶対パス）
  this.cssDir = "/include/script/";
  
  // 各ブラウザ用補正 CSS のファイル名
  if (this.IE50 && this.Win) this.patchCSS = "default_ie6.css";
  if (this.IE55 && this.Win) this.patchCSS = "default_ie6.css";
  if (this.IE6 && this.Win)  this.patchCSS = "default_ie6.css";
  if (this.IE7 && this.Win)  this.patchCSS = "default_ie6.css";
  if (this.IE70 && this.Win) this.patchCSS = "default_ie6.css";
  if (this.IE8 && this.Win)  this.patchCSS = "default_ie6.css";
  if (this.IE80 && this.Win) this.patchCSS = "default_ie6.css";
  if (this.IE9 && this.Win)  this.patchCSS = "default_ie6.css";
  if (this.IE90 && this.Win) this.patchCSS = "default_ie6.css";
  if (this.IE4 && this.Win)  this.patchCSS = "default_mozilla.css";
  if (this.NN4)              this.patchCSS = "default_mozilla.css";
  if (this.IE5 && this.Mac)  this.patchCSS = "default_mozilla.css";
  if (this.Op6)              this.patchCSS = "default_mozilla.css";
  if (this.Omn)              this.patchCSS = "default_mozilla.css";

  // DOM 処理関係
  this.DOMenabled =  (document.getElementsByTagName) ? true : false;
  this.firstLoad = n2.isFirstLoad;

  return this;
}

function nyan2Func() {}

nyan2Func.prototype = {
  getAfter : function(_str, _word) {
    // 文字列 _str 中から _word 以降の残りを抽出する\
    var offset = _str.indexOf(_word)
    if (offset == -1) return _str;
      else return _str.substring(offset + _word.length, _str.length);
  },

  makeTag : function() {
    // makeTag( tagName, [attr=value, ... ] , content|null )
    var me = this.makeTag;
    var n = me.arguments.length;
    var tag = "<" + me.arguments[0];

    for (var i=1; i<n-1; i++) {
      if (!me.arguments[i]) continue;
      var attrs = me.arguments[i].split("=");
      var attr = attrs[0];
      var value = attrs.slice(1, attrs.length).join("=");
      tag += ' ' + attr + '="' + value + '"';
    }
    if (me.arguments[n-1]) tag += ">" + me.arguments[n-1] + "</" + me.arguments[0] + ">";
      else tag += " />";
    return tag;
  },

  loadCSS : function(_file) {
    if (!_file) return;

    // NN4, Opera6 は document.styleSheets を理解しない。
    var title;
    title = (document.styleSheets && document.styleSheets.length > 0) ? document.styleSheets[0].title : null;
    title = (title) ? "title=" + title : null;
    var media = (!env.NN4) ? "media=screen,tv" : null;

    var cLINK = this.makeTag(
      "link",
      "rel=styleSheet",
      "type=text/css",
      "href=" + env.cssDir + _file,
      media,
      title,
      null
    );
    document.write(cLINK);
  }
}

var n2 = new nyan2Func();
var env = new envSet();

n2.loadCSS(env.patchCSS);
