
/**********************************************************
* onload */

function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}




/**********************************************************
* rollover */

function initRollovers() {
	if(document.getElementsByTagName) {
	
		var aPreLoad = new Array();
		var sTempSrc;
		var aImages = document.getElementsByTagName('img');

		for (var i = 0; i < aImages.length; i++) {
			if (aImages[i].className == 'rollover') {
				var src = aImages[i].getAttribute('src');
				if (!src.match(/_over|_on/)) {
					var ftype = src.substring(src.lastIndexOf('.'), src.length);
					var hsrc = src.replace(ftype, '_over'+ftype);

					aImages[i].setAttribute('hsrc', hsrc);
					
					aPreLoad[i] = new Image();
					aPreLoad[i].src = hsrc;
					
					aImages[i].onmouseover = function() {
						sTempSrc = this.getAttribute('src');
						this.setAttribute('src', this.getAttribute('hsrc'));
					}	
					
					aImages[i].onmouseout = function() {
						if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
						this.setAttribute('src', sTempSrc);
					}
				}
			}
		}

	}
}
addEvent(window,"load",function(){initRollovers()});




/**********************************************************
* setStyleSheet */
function fontM() {
	if (navigator.userAgent.indexOf("Mac") != -1) {
		setStyleSheet('fontsize_m_mac');
		return false;
	} else {
		setStyleSheet('fontsize_m');
		return false;
	}
}
function fontL() {
	if (navigator.userAgent.indexOf("Mac") != -1) {
		setStyleSheet('fontsize_l_mac');
		return false;
	} else {
		setStyleSheet('fontsize_l');
		return false;
	}
}
function setStyleSheet(title) {
	var i, a, main;
	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") == title) a.disabled = false;
		}
	}
}
function getStyleSheet() {
	var i, a;
	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");
	}
	return null;
}
function getPreferredStyleSheet() {
	var i, a;
	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");
	}
	return null;
}
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 onloadCookie(e) {
	var cookie = readCookie("style");
	if (cookie == null) {
		if (navigator.userAgent.indexOf("Mac") != -1) {
			cookie = 'fontsize_m_mac';
		} else {
			cookie = 'fontsize_m';
		}
	} 
	var title = cookie ? cookie : getPreferredStyleSheet();
	setStyleSheet(title);
}
function onunloadCookie(e) {
	var title = getStyleSheet();
	createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setStyleSheet(title);

addEvent(window,"load",function(){onloadCookie()});
addEvent(window,"unload",function(){onunloadCookie()});





/**********************************************************
* globalNavi */

function globalNavi(id) {
	var obj = document.getElementById(id).getElementsByTagName('img');
	var url = document.location.href;
	
	for (var i = 0; i < obj.length; i++) {
		var src = obj[i].getAttribute('src');
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var hsrc = src.replace(ftype, '_over'+ftype);
		

		if (i == 1 && url.match(/\/yutaka24\//)) obj[i].src = hsrc;
		if (i == 2 && url.match(/\/yutakacfd\//)) obj[i].src = hsrc;
		if (i == 3 && url.match(/\/market/)) obj[i].src = hsrc;
		if (i == 3 && url.match(/\/reports/)) obj[i].src = hsrc;
		if (i == 3 && url.match(/\/cftc_reports/)) obj[i].src = hsrc;
		if (i == 3 && url.match(/\/rates/)) obj[i].src = hsrc;
		if (i == 3 && url.match(/\/mail_magazines/)) obj[i].src = hsrc;
		if (i == 4 && url.match(/\/seminar/)) obj[i].src = hsrc;
		if (i == 5 && url.match(/\/support\//)) obj[i].src = hsrc;

	}
}





/**********************************************************
* sideNavi */

function sideNavi(id,cate) {
	var obj = document.getElementById(id).getElementsByTagName('img');
	var btn = document.getElementById(id).getElementsByTagName('a');
	var lis = document.getElementById(id).getElementsByTagName('li');
	var url = document.location.href;
	
	var check1 = new RegExp('\/' + cate + '\/$');
	var check2 = new RegExp('\/' + cate + '\/index');
	for (var i = 0; i < obj.length; i++) {
		var src = obj[i].getAttribute('src');
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var hsrc = src.replace(ftype, '_over'+ftype);
		var link = btn[i].getAttribute('href','2');
		
		if (url.match(link)) {
			obj[i].src = hsrc;
			if (i != 0) {
				obj[0].src = obj[0].getAttribute('src').replace('_over','');
			}
		}
	}
	
	if (cate == 'yutaka24') {
		for (var i = 0; i < lis.length; i++) {
			if (url.match(/\/structure\//)) {
				if (lis[i].className == 'top3') obj[i].src = obj[i].getAttribute('src').replace('s_navi_03','s_navi_03a');
				if (lis[i].className == 'top4') obj[i].src = obj[i].getAttribute('src').replace('s_navi_04','s_navi_04a');
			} else if (url.match(/\/start\//)) {
				if (lis[i].className == 'top4') obj[i].src = obj[i].getAttribute('src').replace('s_navi_04','s_navi_04a');
			} else if (url.match(/\/learn\//)) {
				
			} else if (url.match(/\/yutaka24\//)) {
				if (lis[i].className == 'top2') obj[i].src = obj[i].getAttribute('src').replace('s_navi_02','s_navi_02a');
				if (lis[i].className == 'top3') obj[i].src = obj[i].getAttribute('src').replace('s_navi_03','s_navi_03a');
				if (lis[i].className == 'top4') obj[i].src = obj[i].getAttribute('src').replace('s_navi_04','s_navi_04a');
			}
		}
	}
	
	if (cate == 'yutakacfd') {
		for (var i = 0; i < lis.length; i++) {
			if (url.match(/\/structure\//)) {
				if (lis[i].className == 'top3') obj[i].src = obj[i].getAttribute('src').replace('s_navi_03','s_navi_03a');
				if (lis[i].className == 'top4') obj[i].src = obj[i].getAttribute('src').replace('s_navi_04','s_navi_04a');
			} else if (url.match(/\/start\//)) {
				if (lis[i].className == 'top4') obj[i].src = obj[i].getAttribute('src').replace('s_navi_04','s_navi_04a');
			} else if (url.match(/\/learn\//)) {
				
			} else if (url.match(/\/yutakacfd\//)) {
				if (lis[i].className == 'top2') obj[i].src = obj[i].getAttribute('src').replace('s_navi_02','s_navi_02a');
				if (lis[i].className == 'top3') obj[i].src = obj[i].getAttribute('src').replace('s_navi_03','s_navi_03a');
				if (lis[i].className == 'top4') obj[i].src = obj[i].getAttribute('src').replace('s_navi_04','s_navi_04a');
			}
		}
	}
}




/**********************************************************
* search block */

function ShowFormGuide(obj,GuideSentence) {
   if( obj.value == '' ) {
      obj.value = GuideSentence;
      obj.style.color = '#999';
   }
}
function HideFormGuide(obj,GuideSentence) {
   if( obj.value == GuideSentence ) {
      obj.value='';
      obj.style.color = '#000';
   }
}




/**********************************************************
* objHeight */

function objHeight(id,tag,c) {
	var obj = document.getElementById(id).getElementsByTagName(tag);
	var h = 0;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].className == c || !c) {
			if (h < obj[i].offsetHeight) h = obj[i].offsetHeight;
		}
	}
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].className == c || !c) {
			if (h != 0) obj[i].style.height = h + 'px';
		}
	}
}




/**********************************************************
* objChange */

function objChange(tabID, boxID) {
	
	var aPreLoad = new Array();
	var objTab = document.getElementById(tabID).getElementsByTagName('img');
	var objLink = document.getElementById(tabID).getElementsByTagName('a');
	
	for (var i = 0; i < objTab.length; i++) {
		var src = objTab[i].getAttribute('src');
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var hsrc = src.replace(ftype, '_over'+ftype);
		objTab[i].setAttribute('hsrc', hsrc);
		
		aPreLoad[i] = new Image();
		aPreLoad[i].src = hsrc;
		
		var btn = objTab[i].parentNode.getAttribute('href','2').replace('#','');
		if (btn == boxID) {
			setSrc = objTab[i].getAttribute('src');
			objTab[i].setAttribute('src', objTab[i].getAttribute('hsrc'));
		}
		
		objTab[i].onmouseover = function() {
			setSrc = this.getAttribute('src');
			this.setAttribute('src', this.getAttribute('hsrc'));
		}
		
		objTab[i].onmouseout = function() {
			if (!setSrc) setSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
			this.setAttribute('src', setSrc);
		}
		
		objTab[i].onclick = function() {
			for (var i = 0; i < objTab.length; i++) {
				var tab1 = objTab[i].getAttribute('src');
				var tab2 = this.getAttribute('src');
				if (tab1 == tab2) {
					setSrc = objTab[i].getAttribute('src');
				} else {
					setSrc = objTab[i].getAttribute('src').replace('_over'+ftype, ftype);
				}
				objTab[i].setAttribute('src', setSrc);
			}
			setSrc = this.getAttribute('src');
			this.setAttribute('src', this.getAttribute('hsrc'));
		}
		
	}

	for (var i = 0; i < objLink.length; i++) {
		var link = objLink[i].getAttribute('href','2').replace('#','');
		if (link == boxID) {
			document.getElementById(link).style.display = 'block';
		} else {
			document.getElementById(link).style.display = 'none';
		}
		
		objLink[i].onclick = function() {
			for (var i = 0; i < objLink.length; i++) {
				var link1 = objLink[i].getAttribute('href','2').replace('#','');
				var link2 = this.getAttribute('href','2').replace('#','');
				if (link1 == link2) {
					document.getElementById(link2).style.display = 'block';
				} else {
					document.getElementById(link1).style.display = 'none';
				}
			}
			return false;
		}
	}

}





/**********************************************************
* openWindow */

function openWindow(winURL,winName,winW,winH) {
	var winFeatures = 'toolbar=no,resizable=no,menubar=no,directories=no,scrollbars=yes,status=no,location=no,width=' + winW + ',height=' + winH + '';
	window.subwin = window.open(winURL,winName,winFeatures);
	window.subwin.focus();
}


function newsWin(winURL) {
	var winFeatures = 'toolbar=no,resizable=no,menubar=no,directories=no,scrollbars=yes,status=no,location=no,width=740,height=600';
	window.subwin = window.open(winURL,'news',winFeatures);
	window.subwin.focus();
}
