/* Event handler */
function addEventToObject(obj,evt,func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}

/* ニュース & マーケットのタブナビゲーション */
function flipTab(t){
	var heikinTab = document.getElementById("heikin-tab");
	var yenTab = document.getElementById("yen-tab");
	var heikin = document.getElementById("heikin");
	var yen = document.getElementById("yen");
	var tab = t.getAttribute("id");

	if ( tab == "yen-tab"){
		heikin.style.display = 'none';
		yen.style.display = 'block';
		heikinTab.style.backgroundImage = 'url("/nboimgs/tab-heikin-off")';
		yenTab.style.backgroundImage = 'url("/nboimgs/tab-yen-on")';
	} else if ( tab == "heikin-tab"){
		heikin.style.display = 'block';
		yen.style.display = 'none';
		heikinTab.style.backgroundImage = 'url("/nboimgs/tab-heikin-on")';
		yenTab.style.backgroundImage = 'url("/nboimgs/tab-yen-off")';
	}
	return false;
}

/* 株価チャートのタブナビゲーション */
function chartTab(t){
	var dailyTab = document.getElementById("daily-tab");
	var weeklyTab = document.getElementById("weekly-tab");
	var monthlyTab = document.getElementById("monthly-tab");
	var daily = document.getElementById("daily");
	var weekly = document.getElementById("weekly");
	var monthly = document.getElementById("monthly");
	var tab = t.getAttribute("id");

	if ( tab == "weekly-tab"){
		daily.style.display = 'none';
		weekly.style.display = 'block';
		monthly.style.display = 'none';

		dailyTab.style.fontSize = '12px';
		dailyTab.style.fontWeight = 'normal';
		dailyTab.style.textDecoration = 'underline';
		dailyTab.style.color = '#4A99E7';

		weeklyTab.style.fontSize = '16px';
		weeklyTab.style.fontWeight = 'bold';
		weeklyTab.style.textDecoration = 'none';
		weeklyTab.style.color = '#0058AF';

		monthlyTab.style.fontSize = '12px';
		monthlyTab.style.fontWeight = 'normal';
		monthlyTab.style.textDecoration = 'underline';
		monthlyTab.style.color = '#4A99E7';

	} else if ( tab == "daily-tab"){
		daily.style.display = 'block';
		weekly.style.display = 'none';
		monthly.style.display = 'none';

		dailyTab.style.fontSize = '16px';
		dailyTab.style.fontWeight = 'bold';
		dailyTab.style.textDecoration = 'none';
		dailyTab.style.color = '#0058AF';

		weeklyTab.style.fontSize = '12px';
		weeklyTab.style.fontWeight = 'normal';
		weeklyTab.style.textDecoration = 'underline';
		weeklyTab.style.color = '#4A99E7';

		monthlyTab.style.fontSize = '12px';
		monthlyTab.style.fontWeight = 'normal';
		monthlyTab.style.textDecoration = 'underline';
		monthlyTab.style.color = '#4A99E7';

	} else if ( tab == "monthly-tab"){
		daily.style.display = 'none';
		weekly.style.display = 'none';
		monthly.style.display = 'block';

		dailyTab.style.fontSize = '12px';
		dailyTab.style.fontWeight = 'normal';
		dailyTab.style.textDecoration = 'underline';
		dailyTab.style.color = '#4A99E7';

		weeklyTab.style.fontSize = '12px';
		weeklyTab.style.fontWeight = 'normal';
		weeklyTab.style.textDecoration = 'underline';
		weeklyTab.style.color = '#4A99E7';

		monthlyTab.style.fontSize = '16px';
		monthlyTab.style.fontWeight = 'bold';
		monthlyTab.style.textDecoration = 'none';
		monthlyTab.style.color = '#0058AF';
	}

	return false;
}


/* フォーム要素 */
function labelTrick() {
	var labels = document.getElementsByTagName("label");
	if (labels) {
		for (var i = 0; i < labels.length; i++){
			if (labels[i].getAttribute("class") == "inside"){
				var labelFor = labels[i].getAttribute("for");
				var inputTag = document.getElementById(labelFor);
				var labelText = labels[i].firstChild.nodeValue;
				var labelColor, inputColor;
	      if (document.defaultView.getComputedStyle){
	      	labelColor = document.defaultView.getComputedStyle(labels[i], null).getPropertyValue("color");
	     	inputColor = document.defaultView.getComputedStyle(inputTag, null).getPropertyValue("color");
	      }
	      else if (labels[i].currentStyle){
	      	labelColor = labels[i].currentStyle.color;
	      	inputColor = inputTag.currentStyle.color;
	      }
				inputTag.value = labelText;
				inputTag.style.color = labelColor;
				labels[i].style.display = "none";
				inputTag.onfocus = makeFocus(labelText, inputColor);
				inputTag.onblur = makeBlur(labelText, labelColor);
			}
		}
		if (labels[0] != null) {
			var currentNode = labels[0].parentNode;
		} else {
			return;
		}
		while (currentNode.tagName != "FORM"){
			currentNode = currentNode.parentNode;
		}
		currentNode.onsubmit = function() {
			for (var i = 0; i < labels.length; i++){
				var labelFor = labels[i].getAttribute("for");
				var inputTag = document.getElementById(labelFor);
				if (inputTag.value == labels[i].firstChild.nodeValue){
					inputTag.value = "";
				}
			}
		}
	}
}
function makeFocus(labelText, changeColor){
	return function(){
		if (this.value == labelText) {
			this.value = "";
			this.style.color = changeColor;
		}
	}
}
function makeBlur(labelText, changeColor){
	return function (){
		if (this.value == "") {
			this.value = labelText;
			this.style.color = changeColor;
		}
	}
}


/*Javascript for Bubble Tooltips by Alessandro Fulciniti http://pro.html.it -  */
/* Tool Tipエフェクト modifed by yh  */
function enableTooltips(id){
	var links,i,h;
	if(!document.getElementById || !document.getElementsByTagName) return;
	AddCss();
	h=document.createElement("span");
	h.id="btc";
	h.setAttribute("id","btc");
	h.style.position="absolute";
	document.getElementsByTagName("body")[0].appendChild(h);
	links = document.getElementsByTagName("a");
	if (links) {
		for (var j = 0; j < links.length; j++){
			if (links[j].getAttribute("class") == "tooltip"){
				Prepare(links[j]);
			}
		}
	}
}

function Prepare(el){
	var tooltip,t,b,s,l;
	t=el.getAttribute("title");
	if(t==null || t.length==0) t="link:";
	el.removeAttribute("title");
	tooltip=CreateEl("span","tooltip");
	s=CreateEl("span","top");
	s.appendChild(document.createTextNode(t));
	tooltip.appendChild(s);
	b=CreateEl("b","bottom");
	// l=el.getAttribute("href");
	// if(l.length>28) l=l.substr(0,25)+"...";
	// b.appendChild(document.createTextNode(l));
	tooltip.appendChild(b);
	setOpacity(tooltip);
	el.tooltip=tooltip;
	el.onmouseover=showTooltip;
	el.onmouseout=hideTooltip;
	el.onmousemove=Locate;
}

function showTooltip(e){
	document.getElementById("btc").appendChild(this.tooltip);
	Locate(e);
}

function hideTooltip(e){
	var d=document.getElementById("btc");
	if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
	el.style.filter="alpha(opacity:85)";
	el.style.KHTMLOpacity="0.85";
	el.style.MozOpacity="0.85";
	el.style.opacity="0.85";
}

function CreateEl(t,c){
	var x=document.createElement(t);
	x.className=c;
	x.style.display="block";
	return(x);
}

function AddCss(){
	var l=CreateEl("link");
	l.setAttribute("type","text/css");
	l.setAttribute("rel","stylesheet");
	l.setAttribute("href","/css/bt.css");
	l.setAttribute("media","screen");
	document.getElementsByTagName("head")[0].appendChild(l);
}

function Locate(e){
	var posx=0,posy=0;
	if(e==null) e=window.event;
	if(e.pageX || e.pageY){
		posx=e.pageX; posy=e.pageY;
	} else if(e.clientX || e.clientY){
		if(document.documentElement.scrollTop){
			posx=e.clientX+document.documentElement.scrollLeft;
			posy=e.clientY+document.documentElement.scrollTop;
		} else{
			posx=e.clientX+document.body.scrollLeft;
			posy=e.clientY+document.body.scrollTop;
		}
	}
	document.getElementById("btc").style.top=(posy-35)+"px";
	document.getElementById("btc").style.left=(posx-60)+"px";
}

	/* サーチリンク関連 */
	/* イベントリスナー登録 */
	function addListener(elem, eventType, func, cap) {
		if(elem.addEventListener) {
			elem.addEventListener(eventType, func, cap);
		} else if(elem.attachEvent) {
			elem.attachEvent('on' + eventType, func);
		} else {
			//alert('ご利用のブラウザーはサポートされていません。');
			return false;
		}
	}
	function search_exec(word){
		obj = document.getElementById("keyword");
		obj.value=word;
		obj.form.submit();
	}
	function makeSearchLink(e){
		var objs=document.getElementsByTagName('span');
		for(i=0;i<objs.length;i++){
			if(objs[i].className=="wblSearchLink"){
				word = objs[i].innerHTML;
				objs[i].innerHTML="<a href=\"#\" onclick=\"search_exec('"+word+"')\"><img src=\"/nboimgs/icon-search2.gif\" border=\"0\" width=\"23\" height=\"17\" style=\"vertical-align:baseline;\" />"+word+"</a>";
			}
		}
	}
	function makeStockLink(e){
		var objs=document.getElementsByTagName('span');
		for(i=0;i<objs.length;i++){
			if(objs[i].className=="Code"){
				word = objs[i].innerHTML;
				objs[i].innerHTML="<a href=\"/market/market.jsp?CODE="+word+".T\"><img height=\"20\" alt=\"株価\" width=\"45\" border=\"0\" src=\"/nboimgs/stock2.gif\" /></a>";
			}
		}
	}


function swapImage(btnObj,sURL)
{
	btnObj.src = sURL;
}

/* NBonlineサイト内ナビ用 */
/* addHoverクラスの追加 */

function addHover() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.defaultView) {	
		nav = document.getElementById("nbonavi");
		if (!nav) return false;
		navListItems = nav.getElementsByTagName("li");
		for (i = 0; i < navListItems.length; i++) {
			var node = navListItems[i];
			if (node.nodeName == "LI") {
				node.onmouseover = function() {
					this.className += " hover";
				};
				node.onmouseout = function() {
					this.className = this.className.replace(" hover", "");
				};
			}
		}
	}
}

