function eatCookie(key){
 var dc, cs, i, p;
 dc = document.cookie;
 cs = dc.split(/; ?/);
 for(i=0; i<cs.length; i++){
  p = cs[i].indexOf(key + '=');
  if (p == 0){
   return(cs[i].substr(key.length + 1));
  }
 }
 return('');
}

function popupIM(){
    dispUrl=window.document.URL;
    dispTitle=window.document.title;
    dispTitle=encodeURI(dispTitle);
    mailkicker="mailto:?body="+dispTitle+"%0d%0a"+dispUrl;
    linkobj= window.document.getElementById("popup-mail");
    linkobj.setAttribute('href', mailkicker );

    if( eatCookie('IM-POPUP')=='no' ) {
         return;
    }
    window.open("/common/tool/infomail.html","newsub","width=500, height=380, menubar=no, toolbar=no, scrollbars=yes, status=no");
}

//イベントカレンダー用
function popup(url,width,height,windowName){
 windowName = "GetWindow";
 width = 480;
 height = 600;
 switch (arguments.length){
 default:
 case 4: windowName = arguments[3]; // 第4引数まであれば代入
 case 3: height = arguments[2]; // 第3引数まであれば代入
 case 2: width = arguments[1]; // 第2引数まであれば代入
 case 1: url = arguments[0]; // 第1引数まであれば代入
 case 0:
 }
 params = "resizable=yes,hotkeys=yes,location=yes,menubar=yes,scrollbars=yes,width=" + width + ",height=" + height;
 newWindow=open(url,windowName,params);
}


//タブメニュー用
function changeTab(TGT){
    if(TGT =="C1"){
        document.getElementById("menu01").style.display = 'block';
        document.getElementById("menu02").style.display = 'none';
        document.getElementById("menu03").style.display = 'none';
        document.getElementById("menu04").style.display = 'none';
        document.getElementById("menu05").style.display = 'none';
    }else if(TGT =="C2"){
        document.getElementById("menu01").style.display = 'none';
        document.getElementById("menu02").style.display = 'block';
        document.getElementById("menu03").style.display = 'none';
        document.getElementById("menu04").style.display = 'none';
        document.getElementById("menu05").style.display = 'none';
    }else if(TGT =="C3"){
        document.getElementById("menu01").style.display = 'none';
        document.getElementById("menu02").style.display = 'none';
        document.getElementById("menu03").style.display = 'block';
        document.getElementById("menu04").style.display = 'none';
        document.getElementById("menu05").style.display = 'none';
    }else if(TGT =="C4"){
        document.getElementById("menu01").style.display = 'none';
        document.getElementById("menu02").style.display = 'none';
        document.getElementById("menu03").style.display = 'none';
        document.getElementById("menu04").style.display = 'block';
        document.getElementById("menu05").style.display = 'none';
    }else if(TGT =="C5"){
        document.getElementById("menu01").style.display = 'none';
        document.getElementById("menu02").style.display = 'none';
        document.getElementById("menu03").style.display = 'none';
        document.getElementById("menu04").style.display = 'none';
        document.getElementById("menu05").style.display = 'block';
    }
}


//ココカラ

navigator.getVersion = function(){
 if(navigator.appName == 'Microsoft Internet Explorer'){
 if (navigator.appVersion.match(/MSIE (\d)/)){
 return(RegExp.$1);
 }else{
 return(0);
 }
 }else{
 if (navigator.appVersion.match(/^(\d)/)){
 return(RegExp.$1);
 }else{
 return(0);
 }
 }
 return(0);
}

//ココマデ



//add 2009/02/04 nnakazw@itpro
function getBody(iname){
 if(document.all){
  return(document.all(iname))
 } else if(document.getElementById){
  return(document.getElementById(iname))
 }
}

function callJSONP(Url, code){
 var c = (code) ? code : 'euc-jp';
 var script = document.createElement('script');
 script.src = Url;
 script.charset = c;
 document.body.appendChild(script);
}

Array.prototype.find = function(s){
 var i;
 for(i=0; i<this.length; i++)
  if (this[i] == s) return(i);
 return(-1);
}

function addOnload2(){
 if (typeof(document.onload2) == 'undefined'){
  document.onload2 = {};
  document.onload2.add = function(f){
   if (document.onload2.load)
    return(f());
   if(typeof(document.onload2.funcs) == 'undefined' || document.onload2.funcs.length == 0){
    document.onload2.funcs = [f];
   }else{
    document.onload2.funcs.push(f);
   }
    if (document.onload2.running){
    return;
   }else{
    document.onload2.running = function(){
     document.onload2.load = true;
     while(document.onload2.funcs.length > 0){
      document.onload2.funcs[0]();
      document.onload2.funcs.shift();
     }
     document.onload2.running = null;
    }
   }
    //mac safari
   if(/WebKit/i.test(navigator.userAgent)){
    setInterval(function(){
     if (/loaded|complete/.test(document.readyState)) {
      document.onload2.running();
     }
    }, 10);
   //Firefox
   }else if (window.addEventListener){
    document.addEventListener("DOMContentLoaded", document.onload2.running, false);
   //MSIE
   }else if(document.readyState && !!(window.attachEvent && !window.opera)){
    document.write('<script defer src="javascript:void(0)" onreadystatechange="if (this.readyState == \'complete\')  document.onload2.running();"><\/script>');
   //その他
   }else{
    if (window.onload){
     if (window.attachEvent){
      window.attachEvent('onload', document.onload2.running);
     }else if (window.addEventListener){
      window.addEventListener('load', document.onload2.running, true);
     }else{
      window.onload = document.onload2.running;
     }
    }else{
     window.onload = document.onload2.running;
    }
   }
  }
 }
}
addOnload2();

//add 2010/08/27 nnakazw@itpro
Number.prototype.toStringNum = function(n){
 var s, i;
 s = '';
 for(i=0; i<n; i++){
  s += '0';
 }
 s += this.toString();
 return(s.substr(s.length - n, n));
}

Date.prototype.format = function(s){
 return(s.replace(/yyyy/, this.getFullYear()).replace(/MM/, (this.getMonth() + 1).toStringNum(2)).replace(/M/, (this.getMonth() + 1).toString()).replace(/dd/, (this.getDate()).toStringNum(2)).replace(/d/, (this.getDate()).toString()).replace(/hh/, (this.getHours()).toStringNum(2)).replace(/mm/, (this.getMinutes()).toStringNum(2)).replace(/ss/, (this.getSeconds ()).toStringNum(2)));
}

//add 2011/07/07 nnakazw@hensei
function getopt(s, name){
 var i;
 if (s.indexOf('#') >= 0)
  s = s.substring(0, s.indexOf('#'));
 if (s = s.split('?')[1]){
  var opts = new Array();
  opts = s.split('&');
  for(i = 0; i < opts.length; i++){
   if (opts[i].substring(0, name.length + 1).toLowerCase() == (name.toLowerCase() + '=')){
    return(opts[i].substring(name.length + 1));
   }
  }
 }
 return('');
}

function entopt(s, name, value){
 var opt, i, flg, aname;
 flg = true;
 if (s.indexOf('#') >= 0){
  aname= s.substring(s.indexOf('#') + 1, s.length);
  s = s.substring(0, s.indexOf('#'));
 }else{
  aname = '';
 }
 if (opt = s.split('?')[1]){
  var opts = new Array();
  opts = opt.split('&');
  for(i = 0; i < opts.length; i++){
   if (opts[i].match(new RegExp('^' + name + '=', 'i'))){
    opts[i] = name + '=' + value;
    flg = false;
    break;
   }
  }
  s = s.split('?')[0] + '?' + opts.join('&');
  if (flg){
   s = s + '&' + name + '=' + value;
  }
 }else{
  s = s + '?' + name + '=' + value;
 }
 if (aname == '')
  return(s);
 else
  return(s + '#' + aname);
}

///// vlilnk
var xmlUtils = {
 'xmlElement' : function(xml){
  this.node = xml;
  this.getName = function(){
   return(this.node.nodeName);
  }
  this.getText = function(){
   var i, res;
   res = '';
   for(i=0; i<this.node.childNodes.length; i++)
    if ((this.node.childNodes[i].nodeType == 3) || (this.node.childNodes[i].nodeType == 4))
     res += this.node.childNodes[i].nodeValue;
   return(res);
  }
  this.getChildText = function(n){
   var i, j, res;
   for(i=0; i<this.node.childNodes.length; i++){
    if ((this.node.childNodes[i].nodeType == 1) && (this.node.childNodes[i].nodeName == n)){
     res = '';
     for(j=0; j<this.node.childNodes[i].childNodes.length; j++)
      if ((this.node.childNodes[i].childNodes[j].nodeType == 3) || (this.node.childNodes[i].childNodes[j].nodeType == 4))
       res += this.node.childNodes[i].childNodes[j].nodeValue;
     return(res);
    }
   }
   return('');
  }
  this.getAttributeValue = function(n){
   return(this.node.getAttribute(n));
  }
  this.getChild = function(n){
   var i, j;
   for(i=0; i<this.node.childNodes.length; i++){
    if (this.node.childNodes[i].nodeType == 1 && (this.node.childNodes[i].nodeName == n))
     return(new xmlUtils.xmlElement(this.node.childNodes[i]));
   }
   return(null);
  }
  this.getName = function(n){
   return(this.node.nodeName);
  }
  this.getChildren = function(n){
   var i, j, res;
   res = [];
   for(i=0; i<this.node.childNodes.length; i++){
    if (this.node.childNodes[i].nodeType == 1)
     if (typeof(n) == 'undefined' || this.node.childNodes[i].nodeName == n)
      res.push(new xmlUtils.xmlElement(this.node.childNodes[i]));
   }
   return(res);
  }
 },
 'xmlhttp': function(){
  try {
   return new XMLHttpRequest();
  }catch(e){
   try {
    return new ActiveXObject ("Microsoft.XMLHTTP");
   }catch(e){
    try {
     return new ActiveXObject('Msxml2.XMLHTTP');
    }catch(e){
     return(null);
    }
   }
  }
  return(null);
 },
 'getXml': function(xmlFile, func){
  var i, xmlhttp;
  xmlhttp = xmlUtils.xmlhttp();
  if (xmlhttp){
   xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4){
      if (xmlhttp.status == 200){
       i = 0;
       while(i < xmlhttp.responseXML.childNodes.length){
        if (xmlhttp.responseXML.childNodes[i].nodeType == 1){
         func(new xmlUtils.xmlElement(xmlhttp.responseXML.childNodes[i]), 200);
         break;
        }
        i++
       }
       return(null, 0);
      }else
       func(null, xmlhttp.status);
    }
   }
   xmlhttp.open('GET', xmlFile, true);
   xmlhttp.send('');
  }
 },
 'getFile': function(fileName, func){
  var i, xmlhttp;
  xmlhttp = xmlUtils.xmlhttp();
  if (xmlhttp){
   xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4){
     if (xmlhttp.status == 200)
      func(xmlhttp.responseText, 200);
     else
      func(null, xmlhttp.status);
    }
   }
   xmlhttp.open('GET', fileName, true);
   xmlhttp.send('');
  }else
   return('');
 }
};


var vlink = {
 'targId': [],
 'eatCookie': function(key){
  var dc, cs, i, p;
  dc = document.cookie;
  cs = dc.split(/; ?/);
  for(i=0; i<cs.length; i++){
   p = cs[i].indexOf(key + '=');
   if (p == 0){
    return(cs[i].substr(key.length + 1));
   }
  }
  return('');
 },
 'getBody':function(iname){
  if(document.all){
   return(document.all(iname))
  } else if(document.getElementById){
   return(document.getElementById(iname))
  }
 },

 'bakeCookie':  function(name, value){
  var expire;
  expire = new Date();
  expire.setTime(expire.getTime() + (60 * 60 * 24 * 90 * 1000));
  document.cookie =  name + "=" + encodeURIComponent(value) + '; domain=' + location.hostname + '; path=/; expires=' + expire.toGMTString();
 },
 
 'throwCookies': function(name){
  var d = new Date();
  d.setTime(d.getTime() -1);
  document.cookie = name + '=;path=/; domain=' + location.hostname + '; expires=' + d.toGMTString();
  document.cookie = name + '=;path=/; domain=.' + location.hostname + '; expires=' + d.toGMTString();
  document.cookie = name + '=;path=/; expires=' + d.toGMTString();
 },

 'find': function(a, s){
  var i;
  for(i=0; i<a.length; i++)
   if (a[i] == s) return(i);
  return(-1);
 },



 'to62c': function(s){
  var c, r, n;
  n = parseInt(s) % 3844;
  c = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  r = c.charAt(Math.floor(n / c.length)) + c.charAt(n % c.length);
  return(r);
 },

 'isHold': function(key){
  var r;
  r = new RegExp('^(..)*' + key + '(..)*$');
  return(vlink.eatCookie('vlink').match(r) ? true : false)
 },

 'init': function(){
  xmlUtils.getXml('/js/techon/2011/article.xml.dat', vlink.cb_init);
 },

 'cb_init':function(d){
  var kid, idx, i, items, targetFlag, r, c, c2, html;
  items = d.getChild('vlink').getChildren('item');
  for(i=0; i<items.length; i++){
   vlink.targId.push(vlink.to62c(items[i].getAttributeValue('id')));
  }
  if(location.pathname.match(/\/article\/.+\/(\d+)\/$/)){
   kid = RegExp.$1;
   idx = vlink.to62c(kid);
   c = vlink.eatCookie('vlink');
   if (vlink.find(vlink.targId, idx) >= 0){
    if (!vlink.isHold(idx))
     c += idx;
   }
   c2 = '';
   for(i=0; i<c.length / 2; i++){
    if (vlink.find(vlink.targId, c.substr(i * 2, 2)) >= 0)
     c2 += c.substr(i * 2, 2);
   }
   vlink.bakeCookie('vlink', c2);
  }

  if (!vlink.getBody('vlink')) return;
  items = d.getChild('rcmd').getChildren('item');
  html = '<h3 class="titleBar"><div class="title">読者の関心が高い記事　<span>--あなたは読んだ?</span></div></h3><ul>';
  c = 0;
  for(i=0; i<items.length; i++){
   if (!items[i].getChildText('url').match(/\/[0-9]+\/([0-9]+)\//))
    continue;
   r = RegExp.$1;
   if (vlink.isHold(vlink.to62c(r)))
    continue;
   html += '<li><span class="category-small">' + items[i].getChildText('toptitle') + '</span><br><span class="title-small"><a href="' + items[i].getChildText('url') + '">' + items[i].getChildText('title') + '</a></span><span class="date">（' + items[i].getChildText('date') + '）</span></li>';
   if (++c >= 6) break;
  }
  html += '</ul>';
  vlink.getBody('vlink').innerHTML = html;
 }

}



function integBanner(){
 var g;
 if (!eatCookie('integrate').match(/^\d{9}(\d{15})\d{78}$/))
  return;
 g = RegExp.$1;

 if ((g == '005003005025018')||(g == '005003005025010'))
  xmlUtils.getXml('/js/techon/2011/article_tms.xml.dat', cb_integBanner);
}

function cb_integBanner(d, code){
 var kid, idx, c, i, nodes, tids, cids;

 if (code != 200)
  return;
 if(!location.pathname.match(/\/article\/.+\/(\d+)\/$/))
  return;
 kid = vlink.to62c(RegExp.$1);

 tids = [];
 nodes = d.getChildren('item');
 for(i=0; i<nodes.length; i++){
  tids.push(vlink.to62c(nodes[i].getText()));
 }

 c = eatCookie('integBanner');
 cids = [];
 for(i=0; i<c.length / 2; i++){
  if (tids.find(c.substr(i*2, 2)) >= 0)
   cids.push(c.substr(i*2, 2));
 }
 if ((cids.find(kid) < 0) && (tids.find(kid) >= 0))
  cids.push(kid);

 vlink.bakeCookie('integBanner', cids.join(''));
}

document.onload2.add(vlink.init);
document.onload2.add(integBanner);

//画像切り替え表示
function topRandom(){
 var g, url, flag, targ;
 if (getBody('toprandom')){
  url = ['/include/randomparts/top_kikai.incl', '/include/randomparts/top_yusou.incl', '/include/randomparts/top_def.incl'];
 }else if (getBody('random')){
  url = ['/include/randomparts/obs_kikai.incl', '/include/randomparts/obs_yusou.incl', '/include/randomparts/obs_def.incl'];
 }else{
  return;
 }

 if (eatCookie('integrate').match(/^\d{9}(\d{15})\d{78}$/)){
  g = RegExp.$1;
  if (eatCookie('integBanner').length >= 3 * 2)
   flag = true;
  else
   flag = false;
 }else{
  g = '';
  flag = false;
 }


 url = (flag && (g == '005003005025018')) ? url[0] :	//機械
  (flag && (g == '005003005025010')) ? url[1] :		//輸送
  url[2];						//その他

 xmlUtils.getFile(url, cb_topRandom);
}

function cb_topRandom(d, code){
 if (code != 200) return;
 if (getBody('toprandom')){
  getBody('toprandom').innerHTML = d;
 }else if (getBody('random')){
  getBody('random').innerHTML = d;
 }
}

document.onload2.add(topRandom);


//mypage button
function pdsBookmark(){
 var meta, i, tt, t, escapeMark;
 escapeMark = function(s){
  return(s.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'));
 };
 t = tt = '';
 meta = document.getElementsByTagName('meta')
 for(i=0; i<meta.length; i++){
  if (meta[i].name == 'TopTitle')
   tt = meta[i].content;
  else if (meta[i].name == 'MainTitle')
   t = meta[i].content;
 }
 if (t != '')
  location.href = '/pds/pdsif.jsp?TP=bm_add&tt=' + encodeURIComponent(escapeMark(tt)) + '&t=' + encodeURIComponent(escapeMark(t)) + '&u=' + location.pathname + '&r=' + encodeURIComponent(location.href);
 return(false);
}

function pdsBookmark2(tt, t, url){
 var escapeMark = function(s){
  return(s.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'));
 };

 location.href = '/pds/pdsif.jsp?TP=bm_add&tt=' + encodeURIComponent(escapeMark(tt)) + '&t=' + encodeURIComponent(escapeMark(t)) + '&u=' + escapeMark(url) + '&r=' + encodeURIComponent(location.href);
 return(false);
}

function pdsSeriesWatch(){
 var meta, i, tt, tid;
 tid = tt = '';
 meta = document.getElementsByTagName('meta')
 for(i=0; i<meta.length; i++){
  if (meta[i].name == 'TopTitle')
   tt = meta[i].content;
  else if (meta[i].name == 'TopId')
   tid = meta[i].content;
 }
 if (tid != '')
  location.href = '/pds/pdsif.jsp?TP=sw_add&tt=' + encodeURIComponent(tt) + '&tid=' + encodeURIComponent(tid) + '&r=' + encodeURIComponent(location.href);
 return(false);
}


function pdsKeywordList(kw){
 if (kw == ''){
  alert('キーワードを入力してください');
 }else{
  location.href = '/pds/pdsif.jsp?TP=kw_add&kw=' + encodeURIComponent(kw.replace(/[<>'&]/g, '')) + '&r=' + encodeURIComponent(location.href);
 }
 return(false);
}


