/* Smooth scrolling
   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.
   
   sil, http://www.kryogenix.org/
   
   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    if (!destinationLink) destinationLink = document.getElementById(anchor);

    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 25;

ss.addEvent(window,"load",ss.fixAllLinks);





// 設定

thisDay = new Date();
timeStamp = thisDay.getTime();
myMonth = thisDay.getMonth() + 1;
myDate  = thisDay.getDate();
myHours = thisDay.getHours();
myDay   = thisDay.getDay();
myWeekTbl = new Array( "日","月","火","水","木","金","土" );


// 休日設定
function isHolidays (year, month, date, nday) {
  nofw    = Math.floor((date - 1) / 7) + 1;
  shunbun = Math.floor(20.8431+0.242194*(year-1980)-Math.floor((year-1980)/4));
  syubun  = Math.floor(23.2488+0.242194*(year-1980)-Math.floor((year-1980)/4));
  if (month ==  1 && date >=  2 && date <=  4) { return 1; } // 長期休暇
  if (month ==  1 && date ==  1)               { return 1; } // 元旦
  if (month ==  1 && nday ==  1 && nofw ==  2) { return 1; } // 成人の日
  if (month ==  2 && date == 11)               { return 1; } // 建国記念の日
  if (month ==  3 && date == shunbun)          { return 1; } // 春分の日
  if (month ==  4 && date == 29)               { return 1; } // みどりの日
  if (month ==  5 && date >=  3 && date <=  5) { return 1; } // 憲法記念日〜こどもの日
  if (month ==  7 && nday ==  1 && nofw ==  3) { return 1; } // 海の日
  if (month ==  8 && date == 29)               { return 1; } // DIYショー
  if (month ==  9 && nday ==  1 && nofw ==  3) { return 1; } // 敬老の日
  if (month ==  9 && date == syubun)           { return 1; } // 秋分の日
  if (month ==  9 && nday ==  2 && nofw ==  3 
                  && date+1 == syubun) { return 1; } // 9月第3火曜の翌日が秋分の日→国民の休日
  if (month ==  9 && date == 22)               { return 1; } // 国民の休日★
  if (month == 10 && nday ==  1 && nofw ==  2) { return 1; } // 体育の日
  if (month == 11 && date ==  3)               { return 1; } // 文化の日
  if (month == 11 && date == 23)               { return 1; } // 勤労感謝の日
  if (month == 12 && date == 23)               { return 1; } // 天皇誕生日
  if (month ==  8 && date >=  12 && date <=  16) { return 1; } // お盆
  if (month ==  12 && date >=  28 && date <=  31) { return 1; } // 長期休暇
  if (nday  ==  0)                             { return 2; } // 日曜
  if (nday  ==  6)                             { return 2; } // 土曜
  return 0;
  
}


// 日付設定

function dispDatese2W (n, h) {
  return dispDatese2(n, h, 1);
}
                   

// 曜日設定

function dispDatese (w) {
  return dateFormatse(myMonth,myDate,myDay,w);
}


// 発送日設定

function dispDatese2 (n, h, w) {
  var i = 0;
  while (i <= n) {
    thisDay.setTime(timeStamp + (1000*60*60*24 * i));
    myYear2  = thisDay.getFullYear();
    myMonth2 = thisDay.getMonth() + 1;
    myDate2  = thisDay.getDate();
    myDay2   = thisDay.getDay();
    if (isHolidays(myYear2,myMonth2,myDate2,myDay2) == 0 && i == 0 &&  h <= myHours) { n++; }  // 翌日扱い
    if (isHolidays(myYear2,myMonth2,myDate2,myDay2) >= 1){ n++; }  // 休日
    if (isHolidays(myYear2,myMonth2,myDate2,myDay2) == 1 && myDay2 == 0){ n++; }  // 振替休日
    i++;
  }
  return dateFormatse(myMonth2,myDate2,myDay2,w);
}




// フォーマット   


function dateFormatse (month, date, week, w) {   
   w == 1
   dt = new Date();
   H3 = thisDay.getHours();
   myMonth3 = dt.getMonth() + 1;
   myDate3  = dt.getDate();
  if ((H3 >= 9 ) && (month, date) == (myMonth3,myDate3)) { return "<a href=http://www.diy-tool.com/zaiko.html target=_blank><img src=https://www.diy-tool.com/future-online.jpg border=0><br>１５分以内に納期回答します！</a>"; }
  else { return "<a href=http://www.diy-tool.com/fs/diy/c/zaiko target=_blank><img src=https://www.diy-tool.com/future-offline.jpg  border=0><br>"+month+"月"+date+"日"+"午前中に納期回答します！</a>"; }

}




// 設定

thisDay = new Date();
timeStamp = thisDay.getTime();
myMonth = thisDay.getMonth() + 1;
myDate  = thisDay.getDate();
myHours = thisDay.getHours();
myDay   = thisDay.getDay();
myWeekTbl = new Array( "日","月","火","水","木","金","土" );


// 休日設定
function isHoliday (year, month, date, nday) {
  nofw    = Math.floor((date - 1) / 7) + 1;
  shunbun = Math.floor(20.8431+0.242194*(year-1980)-Math.floor((year-1980)/4));
  syubun  = Math.floor(23.2488+0.242194*(year-1980)-Math.floor((year-1980)/4));
  if (month ==  1 && date >=  2 && date <=  4) { return 1; } // 長期休暇
  if (month ==  1 && date ==  1)               { return 1; } // 元旦
  if (month ==  1 && nday ==  1 && nofw ==  2) { return 1; } // 成人の日
  if (month ==  2 && date == 11)               { return 1; } // 建国記念の日
  if (month ==  3 && date == shunbun)          { return 1; } // 春分の日
  if (month ==  4 && date == 29)               { return 1; } // みどりの日
  if (month ==  5 && date >=  3 && date <=  5) { return 1; } // 憲法記念日〜こどもの日
  if (month ==  7 && nday ==  1 && nofw ==  3) { return 1; } // 海の日
  if (month ==  8 && date == 29)               { return 1; } // DIYショー
  if (month ==  9 && nday ==  1 && nofw ==  3) { return 1; } // 敬老の日
  if (month ==  9 && date == syubun)           { return 1; } // 秋分の日
  if (month ==  9 && nday ==  2 && nofw ==  3 
                  && date+1 == syubun) { return 1; } // 9月第3火曜の翌日が秋分の日→国民の休日
  if (month == 10 && nday ==  1 && nofw ==  2) { return 1; } // 体育の日
  if (month == 11 && date ==  3)               { return 1; } // 文化の日
  if (month == 11 && date == 23)               { return 1; } // 勤労感謝の日
  if (month == 12 && date == 23)               { return 1; } // 天皇誕生日
  if (month ==  12 && date >=  29 && date <=  31) { return 1; } // 長期休暇
  if (nday  ==  0)                             { return 2; } // 日曜
  return 0;
  
}


// 日付設定

function dispDate2W (n, h) {
  return dispDate2(n, h, 1);
}
                   

// 曜日設定

function dispDate (w) {
  return dateFormat(myMonth,myDate,myDay,w);
}


// 発送日設定

function dispDate2 (n, h, w) {
  var i = 0;
  while (i <= n) {
    thisDay.setTime(timeStamp + (1000*60*60*24 * i));
    myYear2  = thisDay.getFullYear();
    myMonth2 = thisDay.getMonth() + 1;
    myDate2  = thisDay.getDate();
    myDay2   = thisDay.getDay();
    if (isHoliday(myYear2,myMonth2,myDate2,myDay2) == 0 && i == 0 && h <= myHours) { n++; }  // 翌日扱い
    if (isHoliday(myYear2,myMonth2,myDate2,myDay2) >= 1){ n++; }  // 休日
    if (isHoliday(myYear2,myMonth2,myDate2,myDay2) == 1 && myDay2 == 0){ n++; }  // 振替休日
    i++;
  }
  return dateFormat(myMonth2,myDate2,myDay2,w);
}




// フォーマット   

function dateFormat (month, date, week, w) {   
   w == 1
   dt = new Date();
   myMonth3 = dt.getMonth() + 1;
   myDate3  = dt.getDate();
  if ((month, date) == (myMonth3,myDate3)) { return "本日"; }
  else { return month+"月"+date+"日（"+myWeekTbl[week]+"）"; }

}






// リンクを開くターゲット
tgt = 'target="_top"';  

url = new Array();
img = new Array();

/* リンク先とそのバナーを記述 */
url[0] = "http://www.diy-tool.com/fs/diy/d10-0003"; img[0] = "/item-img/kore1007-daikin-spot.jpg";
url[1] = "http://www.diy-tool.com/fs/diy/28082"; img[1] = "/item-img/kore1007-prox-28082.jpg";
url[2] = "http://www.diy-tool.com/fs/diy/4971833010145"; img[2] = "/item-img/kore1007-koda-shin.jpg";
url[3] = "http://www.diy-tool.com/fs/diy/k01-6295"; img[3] = "/item-img/kore1007-kaku-head.jpg";
url[4] = "http://www.diy-tool.com/fs/diy/3165140527491"; img[4] = "/item-img/kore1007-bosch-glass.jpg";
url[5] = "http://www.diy-tool.com/fs/diy/h02-2394"; img[5] = "/item-img/kore1007-hakko-mypen.jpg";
url[6] = "http://search.diy-tool.com/?searchbox=1&q=%83A%83T%83q%83y%83%93%81%40%83K%83%89%83X%97p%8E%D5%94M%83V%81%5B%83g&%91%97%90M%82%B7%82%E9="; img[6] = "/item-img/kore1007-asa-uvs.jpg";
url[7] = "http://www.diy-tool.com/fs/diy/10000966"; img[7] = "/item-img/kore1007-kar-hd48.jpg";
url[8] = "http://www.diy-tool.com/fs/diy/g01-0009"; img[8] = "/item-img/kore1007-gar-com.jpg";
url[9] = "http://www.diy-tool.com/fs/diy/h01-0057"; img[9] = "/item-img/kore1007-hase-zippy.jpg";
p = Math.round(Math.random() * (url.length - 1));
DOC = "<a href='" + url[p] + "' " + tgt + "><img src='" + img[p] + "' border=0></a>";


