﻿// JavaScript Document
function addEvent(func) {
  if (window.addEventListener) {
    window.addEventListener("load", func, false);
  } else if (window.attachEvent) {
    window.attachEvent("onload", func);
  }
}
/* fontsizechange */
function setFontsize(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
	  setCookie("style", title, 365);

      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  fontsizeimg(title);
}

function getFontsize() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreFontsize() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function setCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

addEvent(function(e) {
  var cookie = getCookie("style");
  var title = cookie ? cookie : getPreFontsize();
  setFontsize(title);
});

addEvent(function(e) {
  var title = getFontsize();
  setCookie("style", title, 365);
});

var cookie = getCookie("style");
var title = cookie ? cookie : getPreFontsize();
setFontsize(title);

function fontsizeimg(title){
  var currentstyle = title;
  var area = document.getElementById("fsizechange");
  if (area){
  var imgtag = area.getElementsByTagName("a");
  var l = imgtag[1];
  var m = imgtag[0];
//  var s = imgtag[0];
  var fname = "/assets/img/common/b_style_";
  switch(currentstyle)
  {
  case "default":
      l.style.backGroundImage=fname+"l.gif";
      m.style.backGroundImage=fname+"m_on.gif";
//      s.src=fname+"s.gif";
      break;
/*  case "large":
      l.src=fname+"l.gif";
      m.src=fname+"m.gif";
      s.src=fname+"s_on.gif";
      break;*/
  case "large":
      l.style.backGroundImage=fname+"l_on.gif";
      m.style.backGroundImage=fname+"m.gif";
//      s.src=fname+"s.gif";
      break;
  default:
      l.style.backGroundImage=fname+"l.gif";
      m.style.backGroundImage=fname+"m_on.gif";
//      s.src=fname+"s.gif";
      break;
  }
  }

}

function mapOpen(url){
mapwin = open(url,"mapwin","left=0,top=0,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,favorites=yes,resizable=yes");
	mapwin.focus();
}
function imgOpen(url){
mapwin = open(url,"mapwin","left=0,top=0,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,favorites=yes,resizable=yes");
	mapwin.focus();
}

/*CONTACTPOPUP*/
function OpenWin2(url){
openwin = open(url,"openwin","width=850,height=800,left=0,top=0,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,favorites=yes,resizable=yes");
	openwin.focus();
}



function drawRandomImg(){
img = new Array();
img[0] = "imgs/txt_copy.jpg";
img[1] = "imgs/txt_copy02.jpg";
img[2] = "imgs/txt_copy03.jpg";
alt = new Array();
alt[0] = "Our Mission 21世紀のデジタル社会だからこそ、人と人との直接の対話が重要です。それがビーオースタジオのコミュニケーション。 会社情報へ";
alt[1] = "Our Mission 戦略思考と確かな技術。ビーオースタジオは御社の成長を支援するwebコンサルティング企業です。 会社情報へ";
alt[2] = "Our Mission webサイトをどうしていいか、わからない！取り組んではいるが、混乱している！担当者のモチベーションが上がらない！ビーオースタジオは、こんな悩みにお応えします。 会社情報へ";
n = Math.floor(Math.random()*img.length);
document.write("<img src='" + img[n] + "' alt='" + alt[n] + "' width='590' height='120' />");
}
