//------------------------------------------------
//
//   JavaScript Document
//
//   2009.06.12 M.Iuchi
//
//------------------------------------------------
//------------------------------------------------
//   ロールオーバー
//------------------------------------------------
(function(onLoad) {
    try {
        window.addEventListener('load', onLoad, false);
    } catch (e) {
        window.attachEvent('onload', onLoad);
    }
})(function() {
  var tags = ["img","input"];
  for( var i=0, len=tags.length; i<len; i++ ) {
    var over = function() { this.src = this.src.replace('_off.', '_on.'); };
    var out  = function() { this.src = this.src.replace('_on.', '_off.'); };
    var el = document.getElementsByTagName(tags[i]);
    for (var j=0, len2=el.length; j<len2; j++) {
      var attr = el[j].getAttribute('src');
      if (!el[j].src.match(/_off\./)&&attr) continue;
      el[j].onmouseover = over;
      el[j].onmouseout  = out;
    }
  }
});
//------------------------------------------------
//   フォーム　フォーカス
//------------------------------------------------
//form.style.backgrounColor
function onF(my) {
	my.style.backgroundColor='#EBF4FF';
	} 
function onB(my) {
	my.style.backgroundColor='#FFFFFF';
}
var scrj = 1;
function softScrollBack() {
   if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat") {
      var scdist = document.body.parentNode.scrollTop;
   } else {
      var scdist = document.body.scrollTop;
   }
   if(scrj<50 && scdist) {
      scdist = (scdist>2) ? Math.ceil(scdist*.2) : 1;
      scrj++;
      scrollBy(0,-scdist);
      setTimeout("softScrollBack()",30);
   } else {
      scrollTo(0,0);
      scrj = 1;
   }
}
//------------------------------------------------
//　ページTOPへ戻る
//------------------------------------------------
function backToTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  if (document.body) {
      x2 = document.body.scrollLeft || 0;
      y2 = document.body.scrollTop || 0;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
  if (x > 0 || y > 0) {
      window.setTimeout("backToTop()", 25);
  }
}
//------------------------------------------------
//
//　１２のポイント　表示・非表示
//
//------------------------------------------------
function openWindow(targetName) {

  obj = document.getElementById(targetName);

  if("none" == obj.style.display) {
    obj.style.display = "inline";
  } else {
    obj.style.display = "none";
  }

  return false;
}

//------------------------------------------------
//　cookieをセット
//------------------------------------------------
function setCookie(theName,theValue) {

  if(location.hostname == 'www.sapporo-cci.or.jp'){ //本番環境の場合
    document.cookie = theName+"="+theValue+";path=/content/;";
  }else{ //テスト環境の場合
    document.cookie = theName+"="+theValue+";path=/;";
  }
}
//------------------------------------------------
//　cookieの特定の値を取得
//------------------------------------------------
function getCookie(theName) {

  theName += "="; //　= を追加
  theCookie = document.cookie+";"; //　検索時最終項目で-1になるのを防ぐ
  start = theCookie.indexOf(theName); //　指定されたセクション名を検索する
  if (start != -1)
  {
    end = theCookie.indexOf(";",start); //　データを抜きだす
    return unescape(theCookie.substring(start+theName.length,end));
  }
  return false;
}

//------------------------------------------------
//　cookieを削除
//------------------------------------------------
function clearCookie(theName) {

  time = new Date(new Date().getTime()-10000).toGMTString();
  document.cookie = theName+"=1;expires="+time+";";
  if(location.hostname == 'www.sapporo-cci.or.jp'){ //本番環境の場合
    document.cookie = theName+"=1;expires="+time+";path=/content/;";
  }else{ //テスト環境の場合
    document.cookie = theName+"=1;expires="+time+";path=/;";
  }
}
//------------------------------------------------
//　別ページからのリンクによる公開表示
//------------------------------------------------
function displayOpen() {
  //クッキーの値を取得
  var targetName = getCookie("Links");

  //文字列として生成
  idName = new String(targetName);

  //クッキーの値が存在するときだけ指定のバナーを開く
  if(targetName != false){
    openWindow(idName);
  }

  //クッキーの値を削除
  clearCookie("Links");

  return false;
}
