// rollover

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;


// switch base stylesheet

function setActiveStyleSheet(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;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  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 getPreferredStyleSheet() {
  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 createCookie(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 readCookie(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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// 関西館バーチャルツアー
function subWin1(p1){
 window.open(p1,"window1","width=780,height=600,scrollbars=1,resizable=1");
}
// 刊行物バックナンバー
var mado;
function hiraku(url)
{
mado=window.open(url,"myWin","tooler=yes,scrollbars=yes,resizable=yes");
mado.focus();
}

function win_open( FileName, Width, Height, Extension )
{
	window.open( FileName,'image','width=' + Width + ',height=' + Height + ',resizable=yes,menubar=no,location=yes,scrollbars=yes,status=yes,' + Extension );
}

//納本制度クイズ
function answercheck(no) {
	var file_url;
	var number = 0;
	var flag = 0;
	for(i = 0; i < document.question.q.length; i++) {
		if(document.question.q[i].checked) {
			flag = 1;

			file_url = location.href;
			file_url = file_url.substring(file_url.lastIndexOf("/")+1, file_url.length)
			file_url = file_url.substring(0, file_url.indexOf("."));

			number = document.question.q[i].value;

			if(no == "q1") choice = "c";
			if(no == "q2" || no == "q6") choice = "d";
			if(no == "q3") choice = "b";
			if(no == "q4" || no == "q5") choice = "a";
			if(no == "q7") {
				count = 0;
				for (i=0; i<9; i++) if(document.question.q[i].checked) count++;
				if(count == 9) {
					number = "e";
					choice = "e";
				} else {
					number = "e";
					choice = "z";
				}
			}

			if(number == choice) location.href = file_url + "_c.html";
			else location.href = file_url + "_e.html";
		}
	}
	if(flag == 0) {
		alert('解答を選択してください。');
	}
}