// Dom判別
var ua=0;
if(document.layers)
	ua='lay';
else if(document.getElementById)
	ua='dom';
else if(document.all)
	ua='msdom';
else{alert('This page is not suppoted by the browser')}
//alert(ua)

// ブラウザの判別
var ap = navigator.appName;
var uagent = navigator.userAgent;
var spstr=uagent.split(' ');
if(spstr[6]=='Opera'){
	ap='op'
}
else if(ap=='Netscape'){
	ap = 'nn';
}
else if(ap=='Microsoft Internet Explorer'){
	ap = 'ie';
}
else{
	ap='at';
}

var isMSIE4 = ( (uagent.toLowerCase()).indexOf('msie 4') != -1 ) ;

if(ua=='lay'){
	document.write('<style type="text/css">.valign-hdr{vertical-align:top;}<');
	document.write('/style>');
}

	function isNull( str ){
		if( str == null )	return true ;
		if( str == '' )	return true ;
		if( typeof( str ) == "undefined" )	return true ;
		return false ;
	}

	function SetCookie (name, value) {
		document.cookie = (name + '=' + escape(value) + "; path=/" );
	}

	function SetCookie2(name, value) {
		var nextyear = new Date();
		nextyear.setFullYear(nextyear.getFullYear() + 1);
		document.cookie = (name + '=' + escape(value) + "; path=/" +
				   "; expires=" + nextyear.toGMTString() );
	}

	function GetCookie (name) {
		var pos = document.cookie.indexOf(name + '=');
		if (pos != -1) {
			var start = pos + name.length + 1;
			var end = document.cookie.indexOf(';', start);
			if (end == -1) end = document.cookie.length;
			var value = document.cookie.substring(start, end);
			return unescape(value);
		}
	}

// search

	var path = /search_results.htm$/;
	var path2 = /search_ix.htm$/;

	function getpathname () {
		// location.pathname for ie4 has bug.
		var iev;
		if (navigator.appName == "Microsoft Internet Explorer") {
			var apv   = navigator.appVersion;
			var iel   = "MSIE ";
			var iepos = apv.indexOf(iel);
			iev   = parseInt(apv.substring(iepos+iel.length));
		}
		if (iev != null && iev == 4) {
			var pathname = location.href;
			var p = pathname.indexOf('#');
			if (p != null && p != -1) {
				pathname = pathname.substring(0, p);
			}
			p = pathname.indexOf('?');
			if (p != null && p != -1) {
				pathname = pathname.substring(0, p);
			}
			return pathname;
		} else {
			return location.pathname;
		}
	}
		

	function SearchWord(word) {
		SetCookie('search', word);
		var b = getpathname();
		if (b.match(path) == null && b.match(path2) == null) {
			SetCookie('backto', b);
		}
		location.href = 'search_ix.htm';
        }

	function SetWord_i () {
		var value;
//		if (ua != 'lay') {
			value = document.search.seek.value;
//		} else {
//			value = document.layers[ divname ].document.search.seek.value;
//		}
		SetCookie('search', value);
		var b = getpathname();
		if (b.match(path) == null && b.match(path2) == null) {
			SetCookie('backto', b);
		}
		return true;
	}

	function SetWord2_i () {
		SetWord_i();
//		if (ua != 'lay') {
			document.search.submit();
//		} else {
//			document.layers[ divname ].document.search.submit();
//		}
	}

	function SetWord_a () {
		value = document.search.seek.value;
		SetCookie('search', value);
		var b = getpathname();
		if (b.match(path) == null && b.match(path2) == null) {
			SetCookie('backto', b);
		}
		return true;
	}

	function SetWord2_a (divname) {
		SetWord_a();
		document.search.submit();
	}

	function back_to_index () {
		var s = GetCookie('where');
		back_to_index2(s,true,false);
	}

	function back_to_index_or_text () {
		var s = GetCookie('backto');
		back_to_index2(s,false,false );
	}

	function index_other_window () {
		var s = GetCookie('where');
		back_to_index2(s,true,true );
	}

	function back_to_index2 (s, flag, winFlag) {
		var p;
		if ( !isNull( s ) ) {
			if (s.indexOf("\\") >= 0) {
				p = s.lastIndexOf("\\");
			}
			else {
				p = s.lastIndexOf("/");
			}

			if (p != -1 && p != null) {
				s = s.substring(p+1, s.length);
			}
			if( flag ){
				var cnts , i ;
				var cntsFlag = false ;
				for( i = 1 ; i <= 0 ; i ++ ){
					cnts = 'contents_' ;
					if( i < 10 )	cnts += '0' ;
					cnts += ( i + '.htm' ) ;
					if( s == cnts ){
						cntsFlag = true ;
						break ;
					}
				}
				if( !cntsFlag ) s = 'index.htm' ;
			}
			if( winFlag ){
				window.open( s );
			}else{
				location.href = s ;
			}
		} else {
			if( winFlag ){
				window.open( 'index.htm' );
			}else{
				location.href = 'index.htm';
			}
		}
	}

//
//	function go_acc_or_int (dir) {
//		var w = getpathname();
//		var p;
//		if (w.indexOf("\\") >= 0) {
//			p = w.lastIndexOf("\\");
//		}
//		else {
//			p = w.lastIndexOf("/");
//		}
//		if (p != -1 && p != null) {
//			location.href = dir + w.substring(p+1, w.length);
//		} else {
//			location.href = dir;
//		}
//	}

	function getwhere () {
	        var w = getpathname();
		var p;
		if (w.indexOf("\\") >= 0) {
		    p = w.lastIndexOf("\\");
		} else {
		    p = w.lastIndexOf("/");
		}
//		if (p != -1 && p != null) {
//          	    w = w.substring(0, p+1) + filename; // filename is defined in HTML.
//		} else {
//		    w = filename;
//		}
		return w;
	}

	function go_older_version (toindex) {

		if (navigator.appName == "Netscape" &&
		    parseInt(navigator.appVersion) >= 5) {
	            var ua = navigator.userAgent;
                    var l = "Netscape6/";
		    var l2 = "Netscape/";
		    var pos = ua.indexOf(l);
		    var v = parseFloat(ua.substring(pos+l.length)); // 6.2.3 -> 6.2
								    // in future, it should be 6.2.3 -> 6.23

		    if (pos == -1) {
			pos = ua.indexOf(l2);
		        v = parseFloat(ua.substring(pos+l2.length));
		    }

		    if (v >= 6.2) {
		        return;
                    }

		    if (pos == -1) { // assume mozilla.
		    	l = "Gecko/"
			pos = ua.indexOf(l);
		    	v = parseInt(ua.substring(pos+l.length, pos+l.length+4));
		    	if (v >= 2002) {
				return;
		    	}
		    }

		}

		if (navigator.appName == "Microsoft Internet Explorer") {
		    var apv = navigator.appVersion;
		    var iel = "MSIE ";
		    var iepos = apv.indexOf(iel);
		    var iev = parseFloat(apv.substring(iepos+iel.length));
		    if (iev >= 5 || (parseInt(iev) == 4 &&
			navigator.appMinorVersion.indexOf("SP2") != -1)) {
			return;
		    }
		}

		dir = '../unv/';
		var w = getpathname();
		var p;
		if (w.indexOf("\\") >= 0) {
			p = w.lastIndexOf("\\");
		}
		else {
			p = w.lastIndexOf("/");
		}

		var ie3;
		if (navigator.appName == "Microsoft Internet Explorer" &&
		    parseInt(navigator.appVersion < 4)) {
			ie3 = true;
		} else {
			ie3 = false;
		}
		
		if ( !isNull( toindex ) ) {
			if (ie3) {
				location = dir + toindex;				
			} else {
				location.href = dir + toindex;
			}

		} else {
			if (p != -1 && p != null) {
				var dst = w.substring(p+1, w.length);

//				if (dst.indexOf("contents_",0) != -1){
//				  dst = "index.htm";
//				}

				if (ie3) {
					location = dir + dst;
				} else {
					location.href = dir + dst;
				}
			} else {
				if (ie3) {
					location = dir;
				} else {
					location.href = dir;
				}
			}
		}

	}

	function goto_preference (mode,prefhtml,fromix) {
		var color = GetCookie('color');
		if ( !isNull( color ) ) {
			SetCookie('color_orig', color);
		}
//		if (fromix) {SetCookie('from_ix', true);}
		if (mode == 'acc') {
			SetCookie('backto',getpathname());
			location.href = prefhtml;
		} else if (mode == 'int') {
			// preference
			window.open(prefhtml);
			return;
		}
	}

	function read_css() {
		if (!document.layers) {
			var color, has;
			color = GetCookie('color');
			if (color) {
				has = hasStyleSheet(color);
			}
			if ( isNull( color ) || !has) {
				var pref = getPreferredStyleSheet();
				if (pref) {
					color = pref;
				}
				else {
					color = 'default';
				}
			}
			setActiveStyleSheet(color);
		}
		return;
	}

function setActiveStyleSheet(color) {
	var i, a;
	if (document.getElementById) {
		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") == color) {
					a.disabled = false;
				}
			}
		}
	}
	else if (document.all) {
		for (i = 0; i < document.styleSheets.length; i++) {
			a = document.styleSheets[i];
			if (a.title) {
				a.disabled = true;
				if (a.title == color) {
					a.disabled = false;
				}
			}
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	if (document.getElementById) {
		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");
			}
		}
	}
	else if (document.all) {
		for (i = 0; i < document.styleSheets.length; i++) {
			a = document.styleSheets[i];
			if (a.title && !a.disabled) {
				return a.title;
			}
		}
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	if (document.getElementById) {
		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");
			}
		}
	}
	else if (document.all) {
		for (i = 0; i < document.styleSheets.length; i++) {
			a = document.styleSheets[i];
			if (a.title == 'default') {
				return a.title;
			}
		}
	}
	return null;
}

function hasStyleSheet(color) {
	var i, a;
	if (document.getElementById) {
		for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") == color) {
				return true;
			}
		}
	}
	else if (document.all) {
		for (i = 0; i < document.styleSheets.length; i++) {
			a = document.styleSheets[i];
			if (a.title == color) {
				return true;
			}
		}
	}
	return false;
}

var type='type'
var nam='nam'
var num='num'
var current='current'
var child='child'

//  ロールオーバーのスクリプト
function Mover(type,nam,num){
	// NN4x
	if(ua=='lay'){
		if(type == 'btn'){
			document.layers['areacontentm'].document.images[type + nam+num].src = eval(type + nam +num+ '[1].src');
		}
		if(type == 'totop'){
			document.layers['areacontentm'].document.images[type + nam].src = totop[1].src;
		}
		if(type == 'num'){
			document.layers['areacontentm'].document.images[type + num].src = eval(type +'_r[num].src');
		}
		if(type == 'chap'){
			document.layers['areacontentm'].document.images[type + nam].src = chap[1].src ;
		}
	}
	// NN4x以外
	else{
		if(type == 'btn'){
			document.images[type + nam+num].src = eval(type + nam +num+ '[1].src');
		}
		if(type == 'totop'){
			document.images[type + nam].src = totop[1].src;
		}
		if(type == 'num'){
			document.images[type + num].src = eval(type +'_r[num].src');
		}
		if(type == 'chap'){
			document.images[type + nam].src = chap[1].src ;
		}
		if(type == 'topich2'){
			document.images[type + nam].src = topich2[1].src ;
		}
		if(type == 'topich3'){
			document.images[type + nam].src = topich3[1].src ;
		}
	}
}
//  ロールアウトのスクリプト
function Mout(type,nam,num){
	// NN4x
	if(ua=='lay'){
		if(type == 'btn'){
			document.layers['areacontentm'].document.images[type + nam+num].src = eval(type + nam +num+ '[0].src');
		}
		if(type == 'totop'){
			document.layers['areacontentm'].document.images[type + nam].src = totop[0].src;
		}
		if(type == 'num'){
			document.layers['areacontentm'].document.images[type + num].src = eval(type +'_n[num].src');
		}
		if(type == 'chap'){
			document.layers['areacontentm'].document.images[type + nam].src = chap[0].src ;
		}
	}
	// NN4x以外
	else{
		if(type == 'btn'){
			document.images[type + nam+num].src = eval(type + nam +num+ '[0].src');
		}
		if(type == 'totop'){
			document.images[type + nam].src = totop[0].src;
		}
		if(type == 'num'){
			document.images[type + num].src = eval(type +'_n[num].src');
		}
		if(type == 'chap'){
			document.images[type + nam].src = chap[0].src ;
		}
		if(type == 'topich2'){
			document.images[type + nam].src = topich2[0].src ;
		}
		if(type == 'topich3'){
			document.images[type + nam].src = topich3[0].src ;
		}
	}
}

