// tools.js
// 2006/03/14
//

/// # server dependent
var thehost = ('http://' + window.location.hostname);
thehost +=  '/';
///


//Set Cookie

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;
}


//Set CSS
var cookie = readCookie("style");
var size = ((cookie == "normal") || (cookie == "large")) ? cookie : "small";
document.write("<link rel='stylesheet' href='/common/css/textbase_" + size + ".css' type='text/css'>");




function setcss(mycss) {
	document.write("<link rel='stylesheet' href='/common/css/" + mycss + ".css' type='text/css'>");
}

function pageback() {
	document.write("<a href='../workshop/" + historylnk + ".html' onclick='javascript:return golink(this.href)'>前のページに戻る</a>");
}

function golink(theurl) {
//top.location.href = theurl + myquery;
//return false;
}
function golink2(theurl,theorder) {
orederflg = "=orderflg=" + theorder;
top.location.href = theurl + myquery + orederflg;
return false;
}

function gocgilink(theurl) {
top.location = theurl + "&css=" + mycss;
return false;
}

function choosecss() {
var theurl = (thehost + "/contents/choosecss.html");
choosecsswin = window.open(theurl,"choosecsswin","scrollbars=yes,status=no,resizable=yes,width=300,height=250") ;
choosecsswin.focus();
return false;
}

function getyear() {
var thedate = new Date();
document.write(thedate.getFullYear());
}

function inact(){
if(document.images) {
document['logo'].src=logoimg.src;
 }
}

function act(){
if(document.images) {
document['logo'].src=logoimg2.src;
 }
}

function sendquery(obj,typ) {
//	var obj = document.forms['search'];
	if(obj) {
		if(obj.elements['query'].value =='') {
			alert('検索する文字列を入力してください');
			return false;
		}
		var actionsArray = new Array('namazu.cgi','','glossary_search.cgi');
		var targ = '/cgi-bin/vho/';
		targ += actionsArray[typ];
		obj.action = targ;
//		alert(obj.action);
		return true;
	}
}

function checkquery() {
	var obj = document.forms['search'];
	if(obj) {
		if(obj.elements['query'].value =='') {
			alert('検索する文字列を入力してください');
			return false;
		}
		if(!obj.action) {
			var targ = '/cgi-bin/vho/namazu.cgi';
			obj.action = targ;
		}
		return true;
	}
}



//-----------



d = window.document
loaded = false;
active = '1';
delay=300;
timer = null;
// popped = 0;

function init(){
	prepare_menus();
	loaded = true;
}

// browser detection object

function lib_bwCheck(){
	this.ver = parseInt(navigator.appVersion);
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = document.getElementById?1:0
	this.opera = (this.agent.indexOf("opera")>-1);
	this.opera5 = (this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1);
	this.nav = ((this.agent.indexOf('mozilla')>-1) && (this.agent.indexOf('spoofer')==-1)
	&& (this.agent.indexOf('compatible') == -1) && (this.agent.indexOf('opera')==-1)
	&& (this.agent.indexOf('webtv')==-1) && (this.agent.indexOf('hotjava')==-1));
	this.nav4up = (this.nav && (this.ver == 4));
	this.nav6up = (this.nav && (this.ver >= 5));
	this.gecko = (this.agent.indexOf('gecko')>-1);
	this.ie5 = (this.agent.indexOf("msie 5")>-1 && this.dom && !this.opera)?1:0
	this.ie6 = (this.agent.indexOf("msie 6")>-1 && this.dom && !this.opera)?1:0
	this.ie4 = (document.all && !this.dom && !this.opera)?1:0
	this.ie = ((this.agent.indexOf("msie") != -1) && (this.agent.indexOf("opera") == -1));
	this.ie4up = (this.ie && (this.ver >= 4));
	this.mac = this.agent.indexOf("mac")>-1
	this.ns6 = (this.dom && this.ver>=5)?1:0
	this.ns4 = (document.layers && !this.dom)?1:0
	this.bw = (this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera)
	return this
}
bw = new lib_bwCheck() // Browser object

function lib_pfCheck(){
	this.ver = parseInt(navigator.appVersion);
	this.agent = navigator.userAgent.toLowerCase();	
	this.win = ((this.agent.indexOf("win")!=-1) || (this.agent.indexOf("16bit")!=-1) );
	// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
	// Win32; can't distinguish between Win95 and WinNT.
	this.win95 = ((this.agent.indexOf("win95")!=-1) || (this.agent.indexOf("windows 95")!=-1));

	// is this a 16 bit compiled version?
	this.win16 = ((this.agent.indexOf("win16")!=-1) || (this.agent.indexOf("16bit")!=-1) ||
		(this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("windows 16-bit")!=-1) );
	this.win31 = ((this.agent.indexOf("windows 3.1")!=-1) || (this.agent.indexOf("win16")!=-1) ||
		(this.agent.indexOf("windows 16-bit")!=-1));

	this.winme = ((this.agent.indexOf("win 9x 4.90")!=-1));
	this.win2k = ((this.agent.indexOf("windows nt 5.0")!=-1));
	
	// NOTE: Reliable detection of Win98 may not be possible. It appears that:
	//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
	//       - On Mercury client, the 32-bit version will return "Win98", but
	//         the 16-bit version running on Win98 will still return "Win95".
	this.win98 = ((this.agent.indexOf("win98")!=-1) || (this.agent.indexOf("windows 98")!=-1));
	this.winnt = ((this.agent.indexOf("winnt")!=-1) || (this.agent.indexOf("windows nt")!=-1));
	this.win32 = (this.win95 || this.winnt || this.win98 || ((this.ver >= 4) && (navigator.platform == "Win32")) ||
		(this.agent.indexOf("win32")!=-1) || (this.agent.indexOf("32bit")!=-1));	
	this.os2 = ((this.agent.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) ||
		(this.agent.indexOf("ibm-webexplorer")!=-1));
	this.mac = (this.agent.indexOf("mac")!=-1);
	this.mac68k = (this.mac && ((this.agent.indexOf("68k")!=-1) || (this.agent.indexOf("68000")!=-1)));
	this.macppc = (this.mac && ((this.agent.indexOf("ppc")!=-1) || (this.agent.indexOf("powerpc")!=-1)));
	
	return this
}
pf = new lib_pfCheck() // Platform object

//lib_cssCheck();

///////
function lib_obj(obj){
	this.el = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval('document.' + obj):0;
	this.css = bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
	this.moveIt = lib_moveIt;
	this.showIt = lib_showIt;
	this.hideIt = lib_hideIt;
	return this;
}

function lib_moveIt(x,y){
	if (x){this.x=x; this.css.left = x;}
	if (y){this.y=y; this.css.top = y;}
}

function lib_showIt(){this.css.visibility = "visible"}
function lib_hideIt(){this.css.visibility = "hidden"}
///////

function changeactive(which) {
	if (loaded){
		clearTimeout(timer);
		//m_rollover('item' + which);
//		popped = 1;
		mDiv['m' + active].hideIt();
		m_rollout('item' + active);
		active =which;
		theleft = m_move(active);
		mDiv['m' + active].css.left = theleft + "px";
		mDiv['m' + active].showIt();
		m_rollover('item' + active);		
	}
}

function killIt(){
	if (loaded){
		mDiv['m' + active].hideIt();
		m_rollout('item' + active);	
	}
}

function killmenu(){
	if (loaded){
		timer = setTimeout("killIt()",delay);
	}
}

function sleep(){
	clearTimeout(timer);
}

function prepare_menus() {
	mDiv = new Array();
	for (var i=0;i<7;i++){
		mDiv['m' +i] = new lib_obj('m' +i);
	}
}

function get_menus() {
	// requires a global "rootpath" variable
	// menu items
	var mitems = new Array(
		"",
		"ネットワーキングの会とは,会則,会員登録について,活動指針,用語解説,VHO-net委員,お問い合わせ",
		"疾患別一覧,50音別一覧",
		"",
		"ワークショップとは,第9回報告,書籍申し込み",
		"",
		"地域学習会とは,北海道学習会,東北学習会,関東学習会,東海学習会,北陸学習会,関西学習会,九州学習会,沖縄学習会,地域学習会運営要項"
	);


	// link directories
	//var mdurls = new Array(
	//	"",
	//	"contents/profile/",
	//	"contents/schedule/",
	//	"contents/report/",
	//	"contents/library/",
	//	"contents/essay/",
	//	"contents/link/"
	//);

	// link file destinations
	var mfurls = new Array(
		"",
		"/contents/profile/index.html,/contents/profile/02.html,/contents/profile/06.html,/contents/profile/03.html,/contents/profile/04.html,/contents/profile/05.html,/contents/profile/08.html",
		"/contents2/jp/organization/index.html,/contents2/jp/organization/index50.html",
		"",
		"/contents/workshop/index.html,/contents/workshop/01-09.html,/contents/workshop/order.html",
		"",
		"/contents/regional/index.html,/contents/regional/01-1.html,/contents/regional/01-2.html,/contents/regional/01-3.html,/contents/regional/01-4.html,/contents/regional/01-5.html,/contents/regional/01-6.html,/contents/regional/01-7.html,/contents/regional/01-8.html,/contents/regional/02.html"
	);
	for(i=0;i<mitems.length;i++) {
		var mid = 'm' + i;
		var subitems =mitems[i].split(',');
		var suburls = mfurls[i].split(',');
		//var subpath = rootpath + mdurls[i];
		document.write("<table id='");
		document.write(mid);
		document.write("' onmouseout='killmenu()' onmouseover='sleep()'>");	
		for(j=0;j<subitems.length;j++) {
			document.write("<tr class='mitem'><td><a href='");
			if(suburls[j].charAt(0) == "/"){
				document.write(suburls[j]);
			}else{
				document.write("/" + suburls[j]);
			}
			document.write("'>");
			document.write(subitems[j]);
			document.write("</a></td></tr>");
		}
		document.write("</table>");
	}
}

//menu left
menu_left = new Array();
menu_left = ["0","104","213","","392","","529"]

// rollover functions
menu_ar = new Array();
menu_ar[0] = 'item0';
menu_ar[1] = 'item1';
menu_ar[2] = 'item2';
menu_ar[3] = 'item3';	
menu_ar[4] = 'item4';
menu_ar[5] = 'item5';
menu_ar[6] = 'item6';


function load_menu_rollovers(){
	mro_ar = new Array();
	for (var i=0;i<menu_ar.length;i++){
		mro_ar[menu_ar[i]] = new Array();
		mro_ar[menu_ar[i]]['off']=new Image();
		mro_ar[menu_ar[i]]['on']=new Image();
		mro_ar[menu_ar[i]]['off'].src="/common/menuimg/topmn_"+menu_ar[i]+".gif";
		mro_ar[menu_ar[i]]['on'].src="/common/menuimg/topmn_"+menu_ar[i]+"_on.gif";
	}
}

///////
load_menu_rollovers();

function m_rollover(which){
	document.images[which].src =mro_ar[which]['on'].src;
}

function m_rollout(which){
	document.images[which].src =mro_ar[which]['off'].src;
}

function m_move(active){
	if(document.body.clientWidth){
		thewidth = document.body.clientWidth;
	}else if(window.outerWidth){
		thewidth = window.outerWidth;
	}
	thewidth = Math.round((thewidth - 750)/2);
	thewidth += Number(menu_left[active]);
	return thewidth;
}
