/* 東京事務所専用JavaScript */
var isIE = (document.documentElement.getAttribute("style") == document.documentElement.style);

/*
 * 親のhrefを変更する。
 */
function chageParentHref(uri) {
	parent.location.href = uri;
}

/*
 * データピックアップを表示する。
 */
var openPickup = (function() {
	var features = "toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=no,"
	
	return function(url, name, width, height) {
		window.open(url, name, features + "width=" + width + ",height=" + height);
	}
})();

function DataPickup(pickups) {
	var width = 640;
	var height = 510;
	var name = "pickup";
	var features = "toolbar=no,location=yes,status=yes,menubar=no,scrollbars=yes,resizable=no"
	
	var num = Math.floor(Math.random() * pickups.length);
	var pickup = pickups[num];
	
	var msg = '<a href="javascript:openPickup(\'' + pickup.url + '\',\'' + name + '\',\'';
	msg += (!!pickup.width ? pickup.width : width) + '\',\''
	msg += (!!pickup.height ? pickup.height : height)
	msg += '\')"><img border="0" src="' + pickup.banner + '" alt="データピックアップ" width="265" height="139"><br /></a>';
	
	document.write(msg);
}

/*
 * 親のパスを表示
 */
function getParentPathname() {
	try {
		return parent.location.pathname;
	}
	catch(e){}
}

/*
 * obj内アンカーの先頭ディレクトリを取得する。
 * ディレクトリは、/hoge/ の形式。
 * ディレクトリを含まない場合はnullを返す。
 */
function getOwnDirectory(obj) {
	var anchors = obj.getElementsByTagName("a");
	if (!anchors || anchors.length == 0) {
		return null;
	}
	var m = anchors[0].href.match(/\/.+?\//i);
	return !!m ? m[0] : null;
}

/*
 * メニュー内の要素を選択済みにする。
 * 選択済み＝"selected"CSSクラスを付与
 */
function selectNavbar(id) {
	var menu = document.getElementById(id);
	if (!menu) {
		return;
	}
	var objs = menu.getElementsByTagName("li");
	if (!objs || objs.length == 0) {
		return;
	}
	
	var pathName = getParentPathname();
	if (!pathName || pathName.length == 0) {
		return;
	}
	
	var classNM = (isIE) ? "className" : "class";
	
	for (var i = 0; i < objs.length; i++) {
		var obj = objs[i];
		var directory = getOwnDirectory(obj);
		if (pathName.indexOf(directory) == 0) {
			var val = obj.getAttribute(classNM) + " selected";
			obj.setAttribute(classNM, val);
		}
	}
}
