

//
//Standard utility scripts
//
function init(){
	stinfo();
	abac();
}

function stinfo(){
	noframe();
	//if(document.getElementById && ! navigator.userAgent.match(/Opera/)){
	if(document.getElementById){
		var x,y,z,c;
		if(x = document.getElementById('snavi')){
			if(! x.firstChild) return; //iCab
			if(y = document.getElementById('pst')){
				x.firstChild.data=y.firstChild.data
			}
			if(y = document.getElementById('stinfo')){
				z = nodeText(y);
				if(c = document.getElementById('mycounter')){
					mct(x,c,z);
				}else{
					x.setAttribute('title',z);
				}
			}
		}
	}
}

function mct(x,c,z){
	var v = c.getAttribute('title').match(/[\d,]+/);
	z = z.replace("invaluable",v);
	x.setAttribute('title',z);
	if(v.toString().match(/000$/)) x.firstChild.data = ("Wow! " + v);
}

function nodeText(m){
	var n, i, res='';
	n = m.childNodes;
	for(i=0;i<n.length;i++){
		if(n.item(i).nodeType == 3){
			res += n.item(i).data;
		}else if(n.item(i).nodeType == 1){
			res += nodeText(n.item(i));
		}
	}
	return res;
}

function abac(){
	if(navigator.userAgent.match(/MSIE.*Win/) && ! navigator.userAgent.match(/Opera/)){
		var ab, abp, m;
		ab = document.getElementsByTagName("abbr"); //For HPR3.01
		while(m = ab.length){
			abp = ab.item(m-1).parentNode;
			abp.innerHTML = abp.innerHTML.replace(/(<\/?)abbr/ig,'$1acronym');
		}
	}
	pflb();
}

// Experimantal pseudo access key
//document.onkeypress = pseudoAKey;
//いったんうち切り

function pseudoAKey(evt){
	var key, prompt;
	if(evt == null) {
		//key = event.keyCode;
		return; //IEはフォーム入力でもインターセプトする
	}else{
		key = evt.which;
	}
	prompt = "Do you need to visit our navigation help page ?";
	if(document.getElementsByTagName){
		if(document.getElementsByTagName("html").item(0).getAttribute('lang') == 'ja')
			prompt = "このサイトの情報の探し方などに関するヘルプページを表示しますか ?";
	}
	key = String.fromCharCode(key).toLowerCase();
	if(key == '?'){
		var helpLoc = "/info/navi"
		if(! location.href.match(helpLoc)){
			if(confirm(prompt)) location.href= helpLoc;
		}else{
			alert("This key should bring you our help, i.e. this page :-)");
		}
		return false;
	}else if(key == '#'){
		scroll(0,0);
		return false;
	}
}

//Pseudo Fixed Link Banner
function pflb(){
	var sl,ns,path;
	if(document.getElementById && (! navigator.userAgent.match(/Opera/)) && (sl = document.getElementById('seclink'))){
		if((path = String(location.pathname)) == '/') return;
		ns = document.getElementById('navskip');
		ns.setAttribute('href',findHome(path));
		ns.firstChild.setAttribute('title','To top of this section');
		sl.style.display='block';
		if(navigator.userAgent.match(/Gecko/)){
			sl.style.position ="fixed";
			if(subm = document.getElementById('smenu1')) subm.style.position ="fixed";
			if(b2t = document.getElementById('b2t-navi')) b2t.setAttribute('style','position:fixed;right:5px;bottom:1em;width:3em;font-size:12px;background:transparent');
		}
	}
}

function findHome(cp){
	var ref;
	if(cp.match(/\/docs\/(html|xml)\//)){
		ref="/docs/htminfo.html";
	}else if(cp.match(/\/(info|test|w3c|art)\//)){
		ref="/";
	}else if(cp.match(/\/music\/(mw|perf|cahier)/)){
		ref="/music/";
	}else{
		ref="./";
	}
	return ref;
}


//misc
function noframe(){
	if(top.frames.length > 0) top.window.location = self.window.location;
}

function h2d(h){
	return ("0123456789abcdef".indexOf(h.charAt(1),0) + "0123456789abcdef".indexOf(h.charAt(0),0) * 16);
}


