//==== Root-Sea, Inc. JavaScript Library ====//
/*-----------------------------------------------------/
2001-2004 (C) Root-Sea, Inc. All Rights Reserved.
Author:yoshihiro fujita [last modify 2004/7/23]
/-----------------------------------------------------*/

var gUa = navigator.userAgent.toUpperCase();
var gBrw = navigator.appName.toUpperCase();
var gPlf = navigator.platform.toUpperCase();
var gVer = navigator.appVersion;
var gPlugin = navigator.plugins;

//::::Get Platform
var gWin = (gUa.indexOf("WIN", 0) != -1);
var gMacC = (gUa.indexOf("MAC", 0) != -1);
var gMacX = false;
if (gPlugin) {
	for (var p = 0; p < gPlugin.length; p++) {
		if (gMacC && (gPlugin[p].filename.indexOf("QuickTime Plugin.plugin", 0) != -1)) {
			gMacX = true;
		}
	}
}

//::::Get Browser
var gIE = (gBrw.indexOf("MICROSOFT INTERNET EXPLORER", 0) != -1);
var gNN = (gBrw.indexOf("NETSCAPE", 0) != -1);
var gGecko = (gUa.indexOf("GECKO", 0) != -1);
var gSafari = (gUa.indexOf("APPLEWEBKIT", 0) != -1);
var gOpera = (gUa.indexOf("OPERA", 0) != -1);

//::::Get Version
var gIE3 = (gVer.indexOf("MSIE 3", 0) != -1);
var gIE4 = (gVer.indexOf("MSIE 4", 0) != -1);
var gIE5 = (gVer.indexOf("MSIE 5", 0) != -1);
var gIE6 = (gVer.indexOf("MSIE 6", 0) != -1);
var gNN4 = (gNN && (gVer.indexOf("4.", 0) != -1));


/*::::==== image control Begin ====::::*/
//::::Image Preload
function imagePreload() {
	return;
	if (navigator.appVersion.charAt(0) >= 3) {
		var loadImages = new Array();
		for (var i in gPreImg) {
			loadImages[i] = new Image();
			loadImages[i].src = gPreImg[i];
		}
		gPreloadFlag = "true";
	}
}


//::::1action 1image change
function changeImg1(imgName1, swpImg1, layName) {
	if (gPreloadFlag == "true") {
		if (!!layName && document.layers) {
			document.layers[layName].document.images[imgName1].src = swpImg1;
		}
		else {
			document.images[imgName1].src = swpImg1;
		}
	}
}
/*::::==== image control End ====::::*/


/*::::==== window control Begin ====::::*/
//::::Window Open
function windowOpen(uri, winName, w, h, which, stName) {
	var stVal0, stVal1;
	var setW = parseInt(w);
	var setH = parseInt(h);
	var winStatus, winSize, winValue;
	var wOpen;

// Set Status Value(1 or 0)
	if (which == 'disp') {
		stVal0 = 0;
		stVal1 = 1;
	}
	if (which == 'del') {
		stVal0 = 1;
		stVal1 = 0;
	}

// Set default Status Value
	var directoriesVal = stVal0;
	var statusVal = stVal0;
	var scrollbarsVal = stVal0;
	var toolbarVal = stVal0;
	var locationVal = stVal0;
	var menubarVal = stVal0;
	var resizableVal = stVal0;
	stName.indexOf('directories') != -1 ? directoriesVal = stVal0 : directoriesVal = stVal1;
	stName.indexOf('status') != -1 ? statusVal = stVal0 : statusVal = stVal1;
	stName.indexOf('scrollbars') != -1 ? scrollbarsVal = stVal0 : scrollbarsVal = stVal1;
	stName.indexOf('toolbar') != -1 ? toolbarVal = stVal0 : toolbarVal = stVal1;
	stName.indexOf('location') != -1 ? locationVal = stVal0 : locationVal = stVal1;
	stName.indexOf('menubar') != -1 ? menubarVal = stVal0 : menubarVal = stVal1;
	stName.indexOf('resizable') != -1 ? resizableVal = stVal0 : resizableVal = stVal1;
	winStatus =
		'directories=' + directoriesVal +
		',status=' + statusVal +
		',scrollbars=' + scrollbarsVal +
		',toolbar=' + toolbarVal +
		',location=' + locationVal +
		',menubar=' + menubarVal +
		',resizable=' + resizableVal;

// Window width & height adjust
	if (setW + setH > 0) {
		//Status : YES
		if (statusVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setH += 16;
			}
		}
		//Scroll : YES
		if (scrollbarsVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setW -= 1;
			}
			//NN4 for Mac
			if (gMacC && gNN4) {
				setW += 15;
			}
			//IE5 for Win
			else if (gWin && (gIE4 || gIE5 || gIE6)) {
				setW += 16;
			}
		}
		//Location : YES
		if (locationVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setH += 24;
			}
		}
		//Menu : YES
		if (menubarVal == 1) {
			//IE4 for Mac
			if (gWin && (gIE4 || gIE5 || gIE6)) {
				setH -= 19;
			}
		}
	}

	if (h != 0) {
		winSize = 'width=' + setW;
	}
	else if (w != 0) {
		winSize = 'height' + setH;
	}
	if (w != 0 && h != 0) {
		winSize = 'width=' + setW + ',height=' + setH;
	}
	if (setW + setH > 0) {
		winValue = winStatus + ',' + winSize;
	}
	else {
		winValue = winStatus;
	}
	winOpen = window.open(uri,winName,winValue);
}


//::::Get Window Open
function isOpener(tergetWin) {
	var flag = 0;
	var ua = navigator.userAgent;

	if (!!tergetWin) {
		if (ua.indexOf('Gecko') != -1 || ua.indexOf('MSIE 4') != -1 && ua.indexOf('Win') != -1) {
			if (!tergetWin.closed) {
				flag = 1;
			}
			else {
				flag = 2;
			}
		}
		else {
			if (typeof tergetWin.document  == 'object') {
				flag = 1;
			}
			else {
				flag = 2;
			}
		}
	}
	else {
		flag = 0;
	}
	return flag;
}


//::::Disp On Parent Window
function dispParentWin(uri) {
	if (isOpener(window.opener) == 1) {
		window.opener.location.href = uri;
	}
	else {
		windowOpen(uri, 'pWin', 0, 0, 'disp', '');
	}
}


//::::Get Window Size
function getWinSize(which) {
	var size;
	if (which == "width") {
		if (document.all) {
			size = parseInt(document.body.clientWidth);
		}
		else if (document.layers) {
			size = parseInt(window.innerWidth);
		}
		else if (document.getElementById) {
			size = parseInt(window.innerWidth);
		}
	}
	else if (which == "height") {
		if (document.all) {
			size = parseInt(document.body.clientHeight);
		}
		else if (document.layers) {
			size = parseInt(window.innerHeight);
		}
		else if (document.getElementById) {
			size = parseInt(window.innerHeight);
		}
	}
	return size;
}
/*::::==== window control End ====::::*/


/*::::==== popup navigation Begin ====::::*/
var gSubMenuName = new Array('product', 'company', 'ir', 'recruit', 'support', 'group');
var gSubMenuObj = new Array();
var gNowCategory = '';
var gObj = null;
var gObjId = null;
var gGlobalId = null;
var gNaviTop = 55;
var gNaviLeft;
var gNaviRight;
var gMouseX, gMouseY;
var gResizeFlag = true;
var gSubMenuObjFlag = false;
var gsproduct, gscompany, gsir, gsrecruit, gssupport, gsgroup;

//:::: Initial Setting
function init() {
	return;
// image preload
	imagePreload();

// get sub menu object & now category
	for (var i in gSubMenuName) {
		gSubMenuObj['s' + gSubMenuName[i]] = getLayerObject('s' + gSubMenuName[i]);
		if (document.images['g' + gSubMenuName[i]].src.indexOf('_on.gif') != -1) {
			gNowCategory = document.images['g' + gSubMenuName[i]].src;
		}
	}

	if (document.all) {
		document.all('gnavi').onmouseover = setNowSubMenuObj;
		for (var i in gSubMenuName) {
			document.all('s' + gSubMenuName[i]).onmouseover = setNowSubMenuObj;
		}
	}
	else if (document.getElementById) {
		document.getElementById('gnavi').onmouseover = setNowSubMenuObj;
		for (var i in gSubMenuName) {
			document.getElementById('s' + gSubMenuName[i]).onmouseover = setNowSubMenuObj;
		}
	}
	else {
		return;
	}
	document.onmousemove = subMenuTurnOff;
	document.onclick = hideSubMenu;

// initial position setup of sub menu
	if (gResizeFlag) {
		setMenuPoint();
	}
	gSubMenuObjFlag = true;

}

//:::: Get Sub Menu Object Under Selection
function setNowSubMenuObj() {
	gObj = null;
	gObjId = null;
	gObj = this;
	gObjId = this.id;
}

//:::: Sub Menu Hide Method
function subMenuTurnOff(e) {
	var gMouseX = getMousePointX(e)
	var gMouseY = getMousePointY(e)
	if (!gObj) {
		return;
	}
	if (gObjId == 'gnavi') {
		if (gMouseX < gNaviLeft || gMouseX > gNaviRight || gMouseY < gNaviTop) {
			hideSubMenu();
		}
	}
	else {
		var left = getLayerPositionX(gObj, 'left');
		var right = getLayerPositionX(gObj, 'right');
		var bottom = getLayerPositionY(gObj, 'bottom');
		imgStr = gObjId.substr(1);
		if (gMouseX < left || gMouseX > right || gMouseY > bottom) {
			hideSubMenu();
		}
	}
}

//:::: Display Sub Menu
function dispSubMenu(naviName, gnID) {
	if (gSubMenuObjFlag) {
		hideSubMenu(gnID);
		if (gResizeFlag) setMenuPoint();
		moveLayer(gSubMenuObj[naviName], eval("g" + naviName), 84);
		showLayer(gSubMenuObj[naviName]);
		for (var j in gSubMenuName) {
			if (gnID == gSubMenuName[j]) {
				changeImg1('g' + gSubMenuName[j], '/common/gnavi_' + gSubMenuName[j] + '_on.gif');
				break;
			}
		}
	}
}

//:::: Hide Sub Menu
function hideSubMenu(nowID) {
	if (!nowID) {
		nowID = null;
	}
	if (gSubMenuObjFlag) {
		for (var i in gSubMenuObj) {
			hideLayer(gSubMenuObj[i]);
			gObj = null;
			gObjId = null;
		}
		for (var j in gSubMenuName) {
			if (nowID != gSubMenuName[j] && gNowCategory.indexOf('/common/gnavi_' + gSubMenuName[j]) == -1) {
				changeImg1('g' + gSubMenuName[j], '/common/gnavi_' + gSubMenuName[j] + '_out.gif');
			}
		}
	}
}

//:::: Set Of Menu Point
function setMenuPoint() {
	gNaviLeft = parseInt((getWinSize('width') - 750) / 2);
	if (gNaviLeft <= 0) gNaviLeft = 0;
	gNaviRight = gNaviLeft + 750;
	gsproduct = gNaviLeft;
	gscompany = gNaviLeft + 124;
	gsir = gscompany + 125;
	gsrecruit = gsir + 125;
	gsgroup = gsrecruit - 79;
	gssupport = gsrecruit + 206;
	gResizeFlag = false;
}

//:::: Get Resize Event
function getResizeEvent() {
	gResizeFlag = true;
}
/*::::==== popup navigation End ====::::*/


/*::::==== layer control Begin ====::::*/
//::::Get Layer Object
function getLayerObject(layID, p_layID) {
	var i, o;
	if (document.all) {
		o = document.all[layID];
	}
	else if (document.layers) {
		if (!!p_layID) {
			o = document.layers[p_layID].document.layers[layID];
		}
		else {
			o = document.layers[layID];
		}
	}
	else if (document.getElementById) {
		o = document.getElementById(layID);
	}
	return o;
}

//::::Move Layer
function moveLayer(layID, mvX, mvY) {
	if (document.all) {
		layID.style.posTop = mvY;
		layID.style.posLeft = mvX;
	}
	else if (document.layers) {
		layID.moveTo(mvX, mvY);
	}
	else if (document.getElementById && !document.all) {
		layID.style.top = mvY;
		layID.style.left = mvX;
	}
}

//::::Show Layer
function showLayer(layID) {
	if (document.all || document.getElementById) {
		layID.style.visibility = "visible";
	}
	else if (document.layers) {
		layID.visibility = "show";
	}
}

//::::Hide Layer
function hideLayer(layID) {
	if (document.all || document.getElementById) {
		layID.style.visibility = "hidden";
	}
	else if (document.layers) {
		layID.visibility = "hide";
	}
}

//::::Get Layer Width,Height
function getLayerSize(layID, which) {
	var s;
	// Get Width Size
	if (which == "width") {
		if (document.all || document.getElementById) {
			if (gIE4 && gMacC) {
				s = parseInt(layID.style.pixelWidth);
			}
			else {
				s = parseInt(layID.offsetWidth);
			}
		}
		else if (document.layers) {
			s = parseInt(layID.clip.width);
		}
	}
	// Get Height Size
	if (which == "height") {
		if (document.all || document.getElementById) {
			if (gIE4 && gMacC) {
				s = parseInt(layID.style.pixelHeight);
			}
			else {
				s = parseInt(layID.offsetHeight);
			}
		}
		else if (document.layers) {
			s = parseInt(layID.clip.height);
		}
	}
	return s;
}

//::::Get Layer Position X
function getLayerPositionX(layID, which) {
	var x;
	// Get Left Position
	if (which == "left") {
		if (document.all) {
			x = parseInt(layID.style.posLeft);
		}
		else if (document.layers) {
			x = parseInt(layID.left);
		}
		else if (document.getElementById && !document.all) {
			x = parseInt(layID.style.left);
		}
	}
	// Get Right Position
	else if (which == "right") {
		if (document.all) {
			x =  parseInt(layID.style.posLeft) + getLayerSize(layID, "width");
		}
		if (document.layers) {
			x = parseInt(layID.left) + getLayerSize(layID, "width");
		}
		else if (document.getElementById && !document.all) {
			x = parseInt(layID.style.left) + getLayerSize(layID, "width");
		}
	}
	return x;
}


//::::Get Layer Position Y
function getLayerPositionY(layID, which) {
	var y;
	// Get Top Position
	if (which == "top") {
		if (document.all) {
			y = parseInt(layID.style.posTop);
		}
		else if (document.layers) {
			y = (layID.top);
		}
		else if (document.getElementById && !document.all) {
			y = parseInt(layID.style.top);
		}
	}
	// Get Bottom Position
	else if (which == "bottom") {
		if (document.all) {
			y = parseInt(layID.style.posTop) + getLayerSize(layID, "height");
		}
		else if (document.layers) {
			y = parseInt(layID.top) + getLayerSize(layID, "height");
		}
		else if (document.getElementById && !document.all) {
			y = parseInt(layID.style.top) + getLayerSize(layID, "height");
		}
	}
	return y;
}
/*::::==== layer control End ====::::*/


/*::::==== mouse control Begin ====::::*/
//::::Get Mouse Point
function getMousePointX(e) {
	var x;
	if (document.all) {
		x = document.body.scrollLeft + event.clientX;
	}
	else if (document.layers || document.getElementById) {
		x = e.pageX;
	}
	return x;
}

function getMousePointY(e) {
	var y;
	if (document.all) {
		y = document.body.scrollTop + event.clientY;
	}
	else if (document.layers || document.getElementById) {
		y = e.pageY;
	}
	return y;
}
/*::::==== mouse control End ====::::*/


//::::Products Quick Search Open
function qSearchOpen() {
	windowOpen('/product/qsearch/', 'quicksearch', 665, 530, 'del', 'scrollbars_resizable');
}


//::::Access Map Open
function mapOpen(uri) {
	windowOpen(uri, 'accessmap', 660, 540, 'del', 'menubars_scrollbars');
}


//::::Press Open
function pressOpen(uri) {
	windowOpen(uri, 'press', 660, 540, 'del', 'scrollbars_resizable_menubars');
}

//::::Ndetail Open 2 for news_detail_small_window
function NdetailOpen(uri) {
	windowOpen(uri, 'ndetail', 660, 370, 'del', 'scrollbars_resizable');
}

//::::Shiwake no Tsubaki Open
function shiwakeOpen() {
	windowOpen('/matehan/classification/', 'classification', 660, 580, 'del', '');
}

//::::Close Button Change
function closeToBack() {
	if (isOpener(window.opener) == 1) {
		document.write('<a href="javascript:window.close();"><img src="/common/b_close.gif" width="74" height="18" border="0" alt=""></a>');
	}
	else {
		document.write('<a href="javascript:history.back();"><img src="/common/b_customback.gif" width="74" height="18" border="0" alt=""></a>');
	}
	document.write('<img src="/common/spacer.gif" width="12" height="18" alt=""><br>');
}

//::::Custom Window Header
function dispHeader() {
	//document.write('<img src="/common/spacer.gif" width="12" height="56" alt="">');
	if (isOpener(window.opener) == 1) {
		//document.write('<img src="/common/logo.jpg" width="328" height="56" alt="つばきグループ"><br>');
		document.write('<div id="wrapper"><p class="openWin-logo"><img src="/common/img/openwin_logo.gif" alt="つばきグループ 株式会社 椿本チエイン" width="300" height="42" /></p></div>');

	}
	else {
		document.write('<a href="/"><img src="/common/logo.jpg" width="328" height="56" border="0" alt="つばきグループ"></a><br>');
	}
}
