/* ---------- start up items ----------
the item in the Array "startup_items" will be executed in order as a function, when the document is loaded.
when you want to add an attribute "onload" in body tag (and that sucks), you'd better make it a function and push into the Array "startup_items".
*/
var startup_items = new Array();
//window.onload = function(){ for(var i=0 ; i<startup_items.length ; i++) startup_items[i](); };
function startup(){ for(var i=0 ; i<startup_items.length ; i++) startup_items[i](); };

/* ---------- common library ---------- */

function getElementsByTagAndClassName(tag_name,class_name){
	/*
	this is not a method but a function.
	This returns it as Array, when the corresponding elements are discovered.
	This returns false, when the corresponding tag name or class name is not able to be discovered.
	when you do not want to limit the kind of tag, you can use "*" for the 1st argument but it's so expensive.
	*/
	var return_array = new Array();
	if(!document.getElementsByTagName(tag_name)) return false;

	var tmp = document.getElementsByTagName(tag_name);
	for(var i=0 ; i<tmp.length ; i++){
		var class_array = tmp[i].className.split(" ");
		for(var c=0 ; c<class_array.length ; c++){
			if(class_array[c] == class_name){
				return_array[return_array.length] = tmp[i];
			}
		}
	}
	if(return_array.length < 1) return false;
	return return_array;
}



/* ----- rollover ----- */

function SwapAndRestoreImage(){
	/*
	when you want to use the rollover effect in any JavaScript, You'd better use this function at window.onload.
	if the sauce file name of an Image object is not a regular form or there is no Image object in children of the node, this will not be executed.
	you have nothing to do to preload swap images :-)
	*/
	SARI_tagName   = "img";
	SARI_className = "SARI";
	SARI_array     = new Array();

	function SARI(obj){
		this.image = obj;
		this.image.f1 = new Image();
		this.image.f1.src = obj.src;
		this.image.f2 = new Image();
		this.image.f2.src = obj.src.replace("_f1","_f2");
		this.image.onmouseover = function(){ if(this.f2) this.src = this.f2.src; }
		this.image.onmouseout  = function(){ if(this.f1) this.src = this.f1.src; }
	}

	var tmp = getElementsByTagAndClassName(SARI_tagName,SARI_className);
	for(var i=0 ; i<tmp.length ; i++){
		if(!tmp[i].src || !tmp[i].src.match(/.*_f1\.[a-zA-Z0-9]+/)) continue;

		SARI_array[SARI_array.length] = new SARI(tmp[i]);
	}
}
startup_items[startup_items.length] = SwapAndRestoreImage;


function SwapAndRestoreImage2(){
	SARI_tagName   = "input";
	SARI_className = "SARI";
	SARI_array     = new Array();

	function SARI(obj){
		this.image = obj;
		this.image.f1 = new Image();
		this.image.f1.src = obj.src;
		this.image.f2 = new Image();
		this.image.f2.src = obj.src.replace("_f1","_f2");
		this.image.onmouseover = function(){ if(this.f2) this.src = this.f2.src; }
		this.image.onmouseout  = function(){ if(this.f1) this.src = this.f1.src; }
	}

	var tmp = getElementsByTagAndClassName(SARI_tagName,SARI_className);
	for(var i=0 ; i<tmp.length ; i++){
		if(!tmp[i].src || !tmp[i].src.match(/.*_f1\.[a-zA-Z0-9]+/)) continue;

		SARI_array[SARI_array.length] = new SARI(tmp[i]);
	}
}
startup_items[startup_items.length] = SwapAndRestoreImage2;


/* ----- label clicker ----- */

function label_click(){
	var ua = navigator.userAgent.toLowerCase();
	if(ua.indexOf("safari") != -1){
		var tmp = document.getElementsByTagName("label");
		for(var i=0 ; i<tmp.length ; i++){
			if(tmp[i].getAttribute("for",0) == "") continue;

			tmp[i].onclick = function(){
				document.getElementById(this.getAttribute("for",0)).click();
			}
		}
	}

	if(ua.indexOf("msie") != -1 && ua.indexOf("windows") != -1){
		var tmp = document.getElementsByTagName("label");
		for(var i=0 ; i<tmp.length ; i++){
			if(tmp[i].getAttribute("for",0) == "") continue;
			if(tmp[i].getElementsByTagName("img").length < 1) continue;

			var target = tmp[i].getElementsByTagName("img");
			for(var j=0 ; j<target.length ; j++){
				target[j].self = tmp[i];
				target[j].onclick = function(){
					if(!document.getElementById(this.self.htmlFor)) return;
					document.getElementById(this.self.htmlFor).click();
				}
			}
		}
	}

	return;
}
startup_items[startup_items.length] = label_click;



/* ----- FAQ折りたたみ  ----- */

function faq_init(){
	var a = getElementsByTagAndClassName('div','faq_a');
	for(var i=0;i<a.length;i++){
		a[i].style.display='none';
	}
}

function expand(a){
	var obj=document.getElementById(a).style;
	if (obj.display=='none') {
		obj.display='block';
	}else{
		obj.display='none';
	}
}

function expandAll(src,n1,n2){
	var a = getElementsByTagAndClassName('div','faq_a');
	if(!n1){
		for(var i=0;i<a.length;i++){
			if(src=="hide")a[i].style.display='none';
			else if(src=="show")	a[i].style.display='block';
		}
	}else{
		for(var i=n1-1;i<n2;i++){
			if(src=="hide")a[i].style.display='none';
			else if(src=="show")	a[i].style.display='block';
		}
	}
}

function getHover(q){
		// カーソル、マウスオーバー
		var obj2=document.getElementById(q).style;
		obj2.cursor='pointer';
		document.getElementById(q).onmouseover = function() {
			obj2.backgroundColor='#fffae5'
		}
		document.getElementById(q).onmouseout = function() {
			obj2.backgroundColor='#ffffff'
		}
}

// 外部からページ内部へのリンク
function anchorLinkOpen(){
	if(window.location.search){
		var a = window.location.search.split("=");
		if(a[0]=="?q"){
			document.getElementById("a"+a[1]).style.display='block';
			location.href = "#q"+a[1];
		}
	}
}
startup_items[startup_items.length] = faq_init;
startup_items[startup_items.length] = anchorLinkOpen;



/* ----- 汎用折りたたみ  ----- */

function info_init(){
	var a = getElementsByTagAndClassName('div','info_a');
	for(var i=0;i<a.length;i++){
		a[i].style.display='none';
	}
}

function info_expandAll(src){
	var a = getElementsByTagAndClassName('div','info_a');
	for(var i=0;i<a.length;i++){
		if(src=="hide")a[i].style.display='none';
		else if(src=="show")	a[i].style.display='block';
	}
}

function info_expandAll(src,n1,n2){
	var a = getElementsByTagAndClassName('div','info_a');
	if(!n1){
		for(var i=0;i<a.length;i++){
			if(src=="hide")a[i].style.display='none';
			else if(src=="show")	a[i].style.display='block';
		}
	}else{
		for(var i=n1-1;i<n2;i++){
			if(src=="hide")a[i].style.display='none';
			else if(src=="show")	a[i].style.display='block';
		}
	}
}



/* ----- fontサイズ変更  ----- */

var fn;
var f_arr = ['/common/css/fontsize/base.css','/common/css/fontsize/large.css'];
// css置換
function replaceCss(n){
  if(!document.getElementById) return false;
	fn = n;
	createCookie("fontsize", fn, 365);
  var element = document.getElementById('fsize');
  if(!element || !element.cloneNode) return false;
  var new_node = element.cloneNode(true);
  new_node.href = f_arr[fn];
  element.parentNode.replaceChild(new_node,element);
	setFontArea();
}
// フォントサイズ変更エリアの書出し
function setFontArea(){
	fn = readCookie("fontsize");
	var element = document.getElementById('f_area');
	if(fn==0||fn=="null"){
		element.innerHTML = "<img src=\/common\/images\/head_fsize.gif width=60 height=17 alt=文字サイズ hspace=2><img src=\/common\/images\/head_fsize_btns_f2.gif width=17 height=17 alt=小 hspace=3><a href='javascript:void(0);' onClick='javascript:replaceCss(1);'><img src=\/common\/images\/head_fsize_btnl_f1.gif width=17 height=17 alt=大 class=SARI></a>";
	}else if(fn==1){
		element.innerHTML = "<img src=\/common\/images\/head_fsize.gif width=60 height=17 alt=文字サイズ hspace=2><a href='javascript:void(0);' onClick='javascript:replaceCss(0);'><img src=\/common\/images\/head_fsize_btns_f1.gif width=17 height=17 alt=小 hspace=3 class=SARI></a><img src=\/common\/images\/head_fsize_btnl_f2.gif width=17 height=17 alt=大></a>"
	}
}
// クッキー発行
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;
}
// 初期設定
function initFont(){
	if(readCookie("fontsize")!="null"){
		fn = readCookie("fontsize");
	}else{
		fn = 0;
	}
	if(f_arr[fn]){
		document.write('<link rel="stylesheet" type="text\/css" id="fsize" href="' + f_arr[fn] + '" \/>');
	}
}
// アンロード時の設定保存
window.onunload = function(e) {
  createCookie("fontsize", fn, 365);
}
initFont();

/* ----- バナーランダム表示  ----- */

function setRandomImage(){
	var n = img_arr.length;
	var r = Math.floor(Math.random()*n);
	// リンクのtargetを_selfにしたい場合、頭に"s"をつける
	//（/test/index.html→s/test/index.html）
	var tgt = "_blank";
	if(img_arr[r].link.substr(0,1)=="s"){
		tgt = "_self";
		img_arr[r].link = img_arr[r].link.slice(1);
	}
	var src = '<a href="'+ img_arr[r].link +'" target="'+ tgt +'"><img src="' +img_arr[r].src+ '" border="0" alt="'+ img_arr[r].alt +'"></a>';
	document.write(src);
}


///////////////////////////////////////////////////////////////
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Konstantin Jagello | http://javascript-array.com/ */

var TimeOut         = 1000;
var currentLayer    = null;
var currentitem     = null;
var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

function mopen(n) {
  var l  = document.getElementById("menu"+n);
  var mm = document.getElementById("mmenu"+n);

  if(l) {
    mcancelclosetime();
    l.style.visibility='visible';
    if(currentLayer && (currentLayerNum != n))
      currentLayer.style.visibility='hidden';
    currentLayer = l;
    currentitem = mm;
    currentLayerNum = n;
  } else if(currentLayer) {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentitem = null;
    currentLayer = null;
 	}
}

function mclosetime() {
  closeTimer = window.setTimeout(mclose, TimeOut);
}

function mcancelclosetime() {
  if(closeTimer) {
    window.clearTimeout(closeTimer);
    closeTimer = null;
  }
}

function mclose() {
  if(currentLayer && noClose!=1)   {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentLayer = null;
    currentitem = null;
  } else {
    noClose = 0;
  }
  currentLayer = null;
  currentitem = null;
}

// document.onclick = mclose;















///////////////////////////////////////////////////////////////

//ポップアップ各種

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//■ [ Mac_Ie_Flag ]
function MacIeFlag(){
	var UA = navigator.userAgent.toUpperCase();
	var AN  = navigator.appName.toUpperCase();
	if( ( UA.indexOf( "MAC" ) >= 0 ) && ( AN.indexOf( "MICROSOFT" ) >= 0 ) ){
		return "MacIe";
	}
}
MacIeFlag = MacIeFlag();

//■ [ window_open ]

function JsWin( JsUrl , JsWinName) {
	var JsProperty = "scrollbars=1,toolbar=1,location=1,directories=1,status=1,menubar=1,resizable=1";
	var JsObjWin = window.open( JsUrl , JsWinName , JsProperty );
	if( MacIeFlag == "MacIe" ){
		return;
	}
	else{
		JsObjWin.focus();
	}
}


// ==========================
// 変数名：p_xxx
// 関数名：flets_xxx

var p_Age = navigator.userAgent;
var p_App = navigator.appName;
var p_IeVer = p_Age.substr(p_Age.indexOf("MSIE") + 5,3);

if( p_App == "Microsoft Internet Explorer" ){
	if( p_IeVer < 5.0 ){
		var p_Navtype = "IE4";
	}
	if( p_IeVer >= 5.0 && p_Age.indexOf('Mac') >= 0 ){
		var p_Navtype = "MacIE5";
	}
}

// ----- popup(1) -----
// ウインドウ体裁　：リサイズボックス・スクロールバーあり
// ウインドウサイズ：HTML側で指定
// ウインドウ名    ：HTML側で指定

function flets_pop1(p_URL,p_WinName,p_WinWidth,p_WinHeight){
	var p_WinOptions = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,width=" + p_WinWidth + ",height=" + p_WinHeight;
	var p_Win = window.open(p_URL,p_WinName,p_WinOptions);
	if( p_Navtype == "IE4" ){
		return;
	}
	else{
		p_Win.focus();
	}
}

// ----- popup(2) -----
// ウインドウ体裁　：すべてナシ
// ウインドウサイズ：HTML側で指定
// ウインドウ名    ：HTML側で指定

function flets_pop2(p_URL,p_WinName,p_WinWidth,p_WinHeight){
	var p_WinOptions = "toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,width=" + p_WinWidth + ",height=" + p_WinHeight;
	var p_Win = window.open(p_URL,p_WinName,p_WinOptions);
	if( p_Navtype == "IE4" ){
		return;
	}
	else{
		p_Win.focus();
	}

}

// ----- popup(3) -----
//ウインドウ体裁　：_blank
//ウインドウサイズ：指定なし
//ウインドウ名    ：HTML側で指定

function flets_pop3(p_URL,p_WinName){
	var p_WinOptions = "toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes";
	var p_Win = window.open(p_URL,p_WinName,p_WinOptions);
	if( p_Navtype == "IE4" ){
		return;
	}
	else{
		p_Win.focus();
	}
}


// ----- opener -----
//（↓openerが存在しないときに開くウインドウ）
//ウインドウ体裁　：_blank
//ウインドウサイズ：指定なし
//ウインドウ名    ：BLANK

function flets_repop(p_reURL){
	var p_WinOptions = "toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes";
	var p_Win = window.open(p_reURL,"BLANK",p_WinOptions);
	if( p_Navtype == "IE4" ){
		return;
	}
	else{
		p_Win.focus();
	}
}

// ----- puWindow -----

function puWindow(url,nam,wid,hei,prop){
	var offset = 0;
	var w = window.screen.width;
	var h = window.screen.height;
	var l = (w-wid)/2;
	var t = ((h-hei)/2)-offset;
	sty = prop;
	sty+= ",width=";
	sty+= wid;
	sty+= ",height=";
	sty+= hei;
	sty+= ",left=";
	sty+= l;
	sty+= ",top=";
	sty+= t;
	window.open(url,nam,sty);
}

function popup0(url,nam,wid,hei){
	prop = "status=yes,scrollbars=no,resizable=yes";
	puWindow(url,nam,wid,hei,prop);
}

function popup1(url,nam,wid,hei){
	prop = "status=yes,scrollbars=yes,resizable=yes";
	puWindow(url,nam,wid,hei,prop);
}

function popup2(url,nam,wid,hei){
	var max = window.screen.height - 20;
	hei = (hei < max) ? hei : max * 0.8;
	prop = "status=yes,scrollbars=yes,resizable=yes";
	puWindow(url,nam,wid,hei,prop);
}

// ----- mailto -----

function mailto2link(){
	var tmp = getElementsByTagAndClassName("span",mailto_className);
	for(var i=0 ; i<tmp.length ; i++){
		tmp[i].onclick = function(){
			var address = this.childNodes[0].nodeValue;
			window.location.href = "mailto:" + address;
		}
	}
}

// ----- 用語辞典（/first/jiten/index.html） -----
function openWin(){
  newWin = window.open('/first/jiten/index.html','jiten','width=600,height=750,top=10,left=10,scrollbars=yes,status=no,toolbar=no,location=no,menubar=no,resizable=yes');
  newWin.focus();
}

///////////////////////////////////////////////////////////////

