// ポップアップ画像表示用関数
// "e" is MouseEvent for FireFox and Netscape
function showPopUp(id, e) {
	e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }else {			//IE
        var de = document.documentElement;	//Strict Mode(offset=2,2)
        var b = document.body;				//Quirks Mode(offset=0,0)
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
	picLayer = document.getElementById(id);
	var picWidth = picLayer.clientWidth;
	var picHeight = picLayer.clientHeight;
	
	if (picLayer.style.visibility.charAt(0) == "v") return;
	picLayer.style.visibility = "visible";
	
	var xOffset = getWinXOffset();
	var yOffset = getWinYOffset();

	picLayer.style.left = xOffset+cursor.x + 15 ;
	picLayer.style.top  = yOffset+cursor.y - (picHeight+50);
}//showPopUp

// ポップアップ画像非表示用関数
function hidePopUp(id) {
	document.getElementById(id).style.visibility = "hidden";
}

// selectProduct( not radio tag ) Change the color and put into the SelectSName clicked
function selectProduct(tr, tdClass) {
	
	oElements = document.getElementById("tb_main").getElementsByTagName("tr");
	oLefts = document.getElementById("tb_left").getElementsByTagName("tr");
		
	for (i = 0; i < oElements.length; i++) {
	
		oElement = oElements[i];
		oLeft = oLefts[i];
		if(oElement.id) {
	
			if(oElement.getAttribute("id") == tr){
				var strProduct = document.getElementById("productNameAnchor"+(i)).name;
				var indexCode = document.SunpouFrm.indexCode.value;
	
				document.SunpouFrm.selectSName.value = strProduct;
				document.SunpouFrm.productName.value = strProduct;
				//boreの設定
				setBore(strProduct, parseInt(indexCode));
				
				//許容トルクリンク先変更
				setLinkOfKgfNm();
				
				if(document.SunpouFrm.hidURL.value) {
					document.SunpouFrm.select3DCADLink.value = document.SunpouFrm.hidURL.value;
				} else {
					document.SunpouFrm.select3DCADLink.value = document.SunpouFrm.hidURL[i].value;
				}
				oElement.className  = "tdSpurHighlight";
			} else{
				if( i % 2 != 0 ) {
					oElement.className  = tdClass;
				} else {
					oElement.className  = "tdDefault";
				}
			}
		}
		if(oLeft.id) {
			if(oLeft.getAttribute("id") == tr){
				oLeft.className  = "tdSpurHighlight";
			} else{
				if( i % 2 != 0 ) {
					oLeft.className  = tdClass;
				} else {
					oLeft.className  = "tdDefault";
				}
			}
		}
	}
}//selectProduct

/*
*	許容トルクのリンク先を変更するメッソドです。<br/>
*/
function setLinkOfKgfNm(){
	var kgfObj0 = document.getElementById("kgfm0");
	var kgfObj1 = document.getElementById("kgfm1");
	var nmObj0 = document.getElementById("Nm0");
	var nmObj1 = document.getElementById("Nm1");
	var strProduct = document.SunpouFrm.selectSName.value;
	
	setTxtCatalog(kgfObj0, strProduct);
	setTxtCatalog(kgfObj1, strProduct);
	setTxtCatalog(nmObj0, strProduct);
	setTxtCatalog(nmObj1, strProduct);	

}//setLinkOfKgfNm

/**
* 選択された製品をパラメータとして入れ替えるメッソドです。<br/>
*
* @param	obj			
* @param	strProduct	selected product
* @return	void  
*/
function setTxtCatalog(obj, strProduct){
	if(obj==null) return;
	var location = obj.getAttribute("href");
	var link;			//結果のリンク先
	var flg = false;	//txtCatalogのパラメータの有無(false：なし、true:あり)
		
	if(location.indexOf("txtCatalog")>0) flg = true;
	
	if(flg){
		index = location.indexOf("&txtCatalog");
		len = location.length - location.substr(index).length;
		link = location.substr(0, len) + "&txtCatalog=" + strProduct; 
	}else{			
		link = location + "&txtCatalog=" + strProduct;
	}//if~else
	
	obj.setAttribute("href", link);
}//setTxtCatalog

//styleをキャッシュして選択された製品を表示するメッソドfunction cacheBack() {
	
	oElements = document.getElementById("tb_main").getElementsByTagName("tr");
	oLefts = document.getElementById("tb_left").getElementsByTagName("tr");
	oTdLefts = document.getElementById("tb_left").getElementsByTagName("td");
	var strProduct = document.SunpouFrm.selectSName.value;
	var indexCode = document.SunpouFrm.indexCode.value;
	
	var isAnchor = location.hash;
	var previous = 0;
	var theCookie = new String();
	
	if(readCookie("seriesCookie")!=""){
		theCookie = readCookie("seriesCookie");
	}
	colsInput = theCookie.split(".");
	
	//IE6 only
	if(dojo.isIE==6 && isAnchor && colsInput[0]==1){
		anchorName = isAnchor.substring(1, isAnchor.length);
		//document.location.href = "#" + anchorName;
	}
	
	if(isFireFox || isNS) scrollTableNS();
	
	if(strProduct !=null && strProduct!=""){
		
		for (i = 0; i < oElements.length; i++) {
			oElement = oElements[i];
			oLeft = oLefts[i];
			oTdLeft = oTdLefts[i];
			var productName = oTdLeft.innerHTML;
			productName = productName.replace(/&nbsp;/g,' ').trim();	//innerHTMLに含まれている空白の除去
									
			if(productName.indexOf(strProduct)!=-1){
				oElement.className  = "tdSpurHighlight";
				oLeft.className  = "tdSpurHighlight";
				
				if(document.SunpouFrm.hidURL.value) {
					document.SunpouFrm.select3DCADLink.value = document.SunpouFrm.hidURL.value;
				} else {
					document.SunpouFrm.select3DCADLink.value = document.SunpouFrm.hidURL[i].value;
				}
				//boreの設定				setBore(strProduct, parseInt(indexCode));
								
				return;
			}
			
		}//end for		
	}else{	//選択されたものが無い場合初期値として最初の製品を選択
		if(oElements.length>0){
			oElement = oElements[0];
			oLeft = oLefts[0];
			oTdLeft = oTdLefts[0];
			//var productName = oTdLeft.innerHTML;
			var tdMains = oElement.getElementsByTagName("td");
			var productName = tdMains[0].getElementsByTagName("A")[0].attributes['name'].nodeValue;
			
			productName = productName.replace(/&nbsp;/g,' ').trim();
			
			oElement.className = "tdSpurHighlight";
			oLeft.className = "tdSpurHighlight";
			document.SunpouFrm.selectSName.value = productName;
			
			if(document.SunpouFrm.hidURL.value) {
				document.SunpouFrm.select3DCADLink.value = document.SunpouFrm.hidURL.value;
			} else {
				document.SunpouFrm.select3DCADLink.value = document.SunpouFrm.hidURL[0].value;
			}
			//boreの設定			setBore(productName, parseInt(indexCode));
		}//if
	}//end if~else
	
	
}//cacheBack

/**
*	選択された製品が準標準品かどうかを判断するメッソドです。<br/>
*	0:標準品、 1:準標準品
*
*   @param	productName	製品名
*	@param	indexCode
*
*/
function setBore(productName, indexCode){
	var bore = 0;
	
	//2.SSG, 4.SS, 24.SRFD
	switch(indexCode){
		case 2:
		case 4:
		case 24:
			if(productName.indexOf("J")>0)	bore=1;
			break;	
	 	default:
	 		bore = 0;
	 		break;
	}//switch
	
	document.SunpouFrm.bore.value = bore;
}//setBore

//DXF出力function goDXF(errMsg, khkweb){
	if (document.SunpouFrm.selectSName.value != "") {
		//document.SunpouFrm.target = "blank";
		document.SunpouFrm.action = khkweb + "/search/download.do?fType=dxf";	
		document.SunpouFrm.submit();
	} else {
		alert (errMsg);
	}
}

//ZIP出力function goZIP(errMsg, khkweb){
	if (document.SunpouFrm.selectSName.value != "") {
		//document.SunpouFrm.target = "blank";
		document.SunpouFrm.action = khkweb + "/search/download.do?fType=zip";	
		document.SunpouFrm.submit();
	} else {
		alert (errMsg);
	}
}

//作図
function goZout(errMsg, khkweb) {
	
	if(document.SunpouFrm.selectSName.value != "") {
		document.SunpouFrm.productName.value = document.SunpouFrm.selectSName.value;
		document.SunpouFrm.action = khkweb + "/zout/createPic.do";
		document.SunpouFrm.previous.value=1;
		setPrevious();		
		document.SunpouFrm.submit();
	} else {
		alert (errMsg);
	}
}

//相手作図
function goZoutAite(errMsg, khkweb) {
	document.SunpouFrm.productName.value = document.SunpouFrm.selectSName.value;
	var objProductName = document.SunpouFrm.productName;
	//var objLeftTr = document.getElementById("tb_left").getElementsByTagName("tr");
	var objLeftTr = document.getElementById("tbl_main").getElementsByTagName("tr");
	
	if(objProductName.value) {
		for(i = 0; i < objLeftTr.length; i++) {
			if(objLeftTr[i].title==objProductName.value) {
				objProductName.value = document.SunpouFrm.hidAite[i].value;
				break;
			}
				
//			var chTemp = objLeftTr[i].childNodes;
//			for(j = 0; j < chTemp.length; j++) {
//				if(chTemp[j].firstChild) {
//					if(chTemp[j].firstChild.nodeValue == objProductName.value) {
//						objProductName.value = document.SunpouFrm.hidAite[i].value;
//						break;
//					}
//				}				
//			}
		}
	}
	
	if(document.SunpouFrm.productName.value != "") {
		document.SunpouFrm.action = khkweb + "/zout/createPic.do";
		document.SunpouFrm.previous.value=1;
		setPrevious();
		document.SunpouFrm.submit();
	} else {
		alert (errMsg);
	}
}

// 強度計算function goCalc(errMsg, khkweb) {
	if (document.SunpouFrm.selectSName.value != "") {
	// 強度計算コードで開くファイルを決定する		document.SunpouFrm.method = "post";
		document.SunpouFrm.action = khkweb + "/calc/inKyoudo.do";
		//選択製品隠れる問題対処
		document.SunpouFrm.previous.value=1;
		setPrevious();
		document.SunpouFrm.submit();
	} else {
		alert (errMsg);
	}
}

// 商品を購入リストに追加
function goSheet(errMsg, khkweb) {	
	if (document.SunpouFrm.selectSName.value != "") {
		document.SunpouFrm.method = "post";
		document.SunpouFrm.action = khkweb + "/sheet/hyojunCart.do";
		//選択製品隠れる問題対処
		document.SunpouFrm.previous.value=1;
		setPrevious();
		document.SunpouFrm.submit();
	} else {
		alert (errMsg);
	}
}

// change data counts per page (表示件数変更機能は現在未使用)
function changePerPage(khkweb, perPage, indexCode, referrer, unit) {
	document.SunpouFrm.method = "post";
	document.SunpouFrm.action = khkweb + "/search/sunpou.do?indexCode=" + indexCode + "&referrer=" + referrer + "&unit=" + unit + "&perPage="+perPage;
	document.SunpouFrm.submit();
}

// resize layers
function resizeSpecImgDiv(imgObject) {
	return;		// Not Used Temporary, after 2007.10
	browserDetect();
	if(!isIE) {
		var divTag = document.getElementById("dv_keijo");
		divTag.style.width = imgObject.width;
		divTag.style.height = ( imgObject.height + 30 );
	}
}

// モジュールと歯数検索
function goSearch(khkweb, indexCode, perPage) {
	document.SunpouFrm.method = "post";
	document.SunpouFrm.action = khkweb + "/search/sunpou.do?indexCode=" + indexCode + "&referrer=sunpou&perPage="+perPage;
	//cookieの初期化処理
	initPrevious();
	document.SunpouFrm.submit();
}

//3DCADを開く

//2006/07/21 add
function go_3DCad(errMsg1, url, errMsg2) {
	if(document.SunpouFrm.selectSName.value != "") {
		var strUrl = url + document.SunpouFrm.select3DCADLink.value.trim();
		if(strUrl != url) {
			window.open(strUrl, "_blank", "width=800,height=500,resizable=yes,menubar=yes,toolbar=yes,status=yes,location=yes");
		} else {
			window.open("../HTML/error.html?hidErrorMsg="+escape(errMsg2), "_blank", "width=600,height=480,menubar=no");
		}
	} else {
		alert (errMsg1);
	}
}

/*
	別ウィンドウを開くメッソドです。<br/>
*/
function popup(url){
	popupWin = window.open(url, "_blank", "width=" + screen.width/2 + ",height=" + screen.height*0.7 + ",resizable=yes, left="+screen.width/2+", top=0, menubar=no,scrollbars=yes");
	popupWin.focus();
}//popup

//初期寸法表の横長さ(tb_main)
var tdLeftOffset =0;

function resizeSunpouTable() {

	var isAnchor = location.hash;
	var anchorName;
	var objLeftTr = document.getElementById("tb_left").getElementsByTagName("tr");
	var objMainTr = document.getElementById("tb_main").getElementsByTagName("tr");
	var noteHeight = document.getElementById("td_note").offsetHeight;
	var kyotuHeight = document.getElementById("td_kyotu").offsetHeight
	var bottomHeight = noteHeight+kyotuHeight;
	
	var objMainTd = document.getElementById("tb_main").getElementsByTagName("td");
	var objTitleTh = document.getElementById("tb_title").getElementsByTagName("th");
	var objLeftTd = document.getElementById("tb_left").getElementsByTagName("td");

	/*** Controll of TABLE WIDTH by Browser / Screen ***/
	var nWinWidth = 0; 		// DETECT Browser Width
	var nWinHeight = 0;
	var offsetY = getWinYOffset() ; 	//Window( Frame )のスクリーン上の位置（Y座標）	
	if(isIE){
		nWinWidth = (document.compatMode && document.compatMode=='CSS1Compat')?documentElement.clientWidth:document.body.clientWidth;
		nWinHeight = (document.compatMode && document.compatMode=='CSS1Compat')?documentElement.clientHeight:document.body.clientHeight;
	}else{
		nWinWidth = window.innerWidth;
		nWinHeight = window.innerHeight;	
	}
	
	var nScrollBarWidth = 17;
	var nScrollBarHeight = 17;
	
	// set the height of tb_main
	var topMenuHeight = document.getElementById("td_menu").offsetHeight;
	var nSunpouHeight = nWinHeight - (bottomHeight+topMenuHeight);
	var nTitleHeight = document.getElementById("tb_title").offsetHeight;
	var pagingHeight = 34;
	
	var specHeight =  document.getElementById("tblKyotu").offsetHeight;
	var nDivHeight = nSunpouHeight - (nTitleHeight+nScrollBarHeight+specHeight+pagingHeight);

	var minHeight = 2*objLeftTd[0].offsetHeight;	//最低でも３行は出すように
	if(nDivHeight < minHeight) nDivHeight = minHeight;
	
	var nTbLeftWidth = document.getElementById("tb_left").offsetWidth;
	var nDivWidth = nWinWidth - (nTbLeftWidth+2*nScrollBarWidth+1);
		
	//Important! come first
	document.getElementById("tb_title").style.width = nDivWidth;												// div - sunpou table header
	document.getElementById("tb_main").style.width = nDivWidth+nScrollBarWidth;
	
	
	//sunpouレイヤーのサイズ設定	document.getElementById("td_sunpou").style.top = offsetY+topMenuHeight;
	document.getElementById("td_sunpou").style.width = nWinWidth;
	document.getElementById("td_sunpou").style.height = nSunpouHeight;
		
	//dv_keijo(形状図のサイズ調整)
	var objKyoTd = document.getElementById("tblKyotu").getElementsByTagName("td");
	var divKeijoWidth = nWinWidth -(objKyoTd[0].offsetWidth); 
	if(divKeijoWidth <0) divKeijoWidth = 0; 
	document.getElementById("dv_keijo").style.width = divKeijoWidth;
	document.getElementById("dv_keijo").style.height = 140+nScrollBarHeight+5;
		
	if(isNS) {
		document.getElementById("tb_title").style.overflow = "auto";
		document.getElementById("tb_left").style.overflow = "auto";
		document.getElementById("seihinCol1").style.height = objTitleTh[0].offsetHeight+2;	
	} else {
		document.getElementById("seihinCol1").style.height = objTitleTh[0].offsetHeight + (objTitleTh[0].offsetHeight - objTitleTh[0].clientHeight);
	}
	
	if ( objLeftTd[0].offsetWidth > document.getElementById("seihinCol1").offsetWidth )   {
		document.getElementById("seihinCol1").style.width = objLeftTd[0].offsetWidth;
		tdLeftOffset = objLeftTd[0].offsetWidth;
	} else {
		objLeftTd[0].width = document.getElementById("seihinCol1").offsetWidth;
		tdLeftOffset = document.getElementById("seihinCol1").offsetWidth;
	}
	
		
	//adjust the width of tbl_main's column
	fitMainTd();
		
	Note.prototype.tdNoteHeight = dojo.style("td_note","height");

	/*
	    注釈折り畳みステータスの取得（ページがロードされる前に取得)
	    回答が来るまで待機(同期モード)
	  　スペックが悪いclientの場合、画面が真っ白になる場合がある  
	*/
	getStatus();
	
	if(dojo.byId("divNote")) {	
		if(document.SunpouFrm.display.value=="block") Note.prototype.toggleNote("off");
		else Note.prototype.toggleNote("on");		
	}
		
	adjust(arguments[0]);
	
}//end resizeSunpouTable


/*
	tbl_mainテーブルとtbl_headerテーブルのtd幅を合わせる処理をするメッソド
*/
function fitMainTd(){
	var objMainTd = dojo.byId("tb_main").getElementsByTagName("td");
	var objTitleTh = dojo.byId("tb_title").getElementsByTagName("th");
	var nTableWidth = 0;
	//Firefox 3 対応	
	var offset = 0;
	//if(dojo.isFF==3 && objMainTd[0]) offset = 2*dojo.style(objMainTd[0],"paddingLeft");
	if(dojo.isFF>=3 && objMainTd[0]) offset = 2*dojo.style(objMainTd[0],"paddingLeft");  //FF ver.up対応
  
	for(i = 0; i < objTitleTh.length; i++) {
		
		if(objMainTd[i].offsetWidth > objTitleTh[i].offsetWidth) {
			objTitleTh[i].width = objMainTd[i].offsetWidth+offset;
			objMainTd[i].width = objMainTd[i].offsetWidth;
		} else {
			objMainTd[i].width = objTitleTh[i].offsetWidth-offset;		// VERY IMPORTANT! To be included the border width or not.
			objTitleTh[i].width = objTitleTh[i].offsetWidth;
		}
		nTableWidth = eval( nTableWidth ) + eval(objTitleTh[i].offsetWidth);

	}	// end of for i
	
	dojo.style("tbl_main", "width", nTableWidth);
	dojo.style("tbl_header", "width", nTableWidth);

}//fitMainTd

function anchorDetect(){

	var isAnchor = location.hash;
	var anchorName;
	var objLeftTr = document.getElementById("tb_left").getElementsByTagName("tr");
	var objMainTr = document.getElementById("tb_main").getElementsByTagName("tr");

	if(isAnchor) {	// Anchor Detect
		anchorName = isAnchor.substring(1, isAnchor.length);
		document.SunpouFrm.selectSName.value = anchorName;
		document.SunpouFrm.productName.value = anchorName;
		document.location.href = "#" + anchorName;	// re-confirm for GET[seihinNm]	
		setLinkOfKgfNm();
	}
	
}//anchorDetect


function scrollTable() {
	var objMain = document.getElementById("tb_main");
	
	document.getElementById("tb_title").scrollLeft = objMain.scrollLeft;
	document.getElementById("tb_left").scrollTop = objMain.scrollTop;
}

function scrollTableNS() {
	var objTitle = dojo.byId("tb_title");
	var objLeft = dojo.byId("tb_left");
	dojo.byId("tb_main").scrollLeft = objTitle.scrollLeft;
	dojo.byId("tb_main").scrollTop = objLeft.scrollTop;
	
}

function isVerticalScrollDetect(objDiv) {
	if(objDiv.scrollHeight > objDiv.clientHeight) {
		return true;
	} else {
		return false;
	}
}

function isHorizontalScrollDetect(objDiv) {
	if(objDiv.scrollWidth > objDiv.clientWidth) {
		return true;
	} else {
		return false;
	}

}

function imageWindowOpen(f_nm){
	newWindow = window.open(f_nm ,"big_image","_blank,width=420,height=350,resizable=0,menubar=0,toolbar=0");
	newWindow.focus();
	return newWindow;
}
var log="";
var count = 1;
var max = 3;	//頭だし検索の時、スクロールが消える問題の解消(3回実行)
var timerId;
var type = null;

function adjust(e){
	var nWinWidth = 0; 		// DETECT Browser Width
	var nWinHeight = 0;
	var noteHeight = dojo.byId("td_note").offsetHeight;
	var kyotuObj = dojo.byId("td_kyotu");
	var kyotuHeight = kyotuObj.offsetHeight;
	var objPagingTd = dojo.byId("tbl_paging").getElementsByTagName("td");
	var bottomHeight = noteHeight+kyotuHeight;
	var tblButtonObj = dojo.byId("tbl_button");
	
			
	/*
	* 共通変数の宣言
	*/
	var nScrollBarWidth = 17;
	var nScrollBarHeight = 17;
	var pagingHeight = objPagingTd[0].offsetHeight;
	var topMenuHeight = dojo.byId("td_menu").offsetHeight;
		
	e = e || window.event;
	if(e!=null) type=e.type;	//save event's type	
		
	//形状図の最小幅 : 150px
	var minKeijoWidth = 100;		//800×600解像度で見えるように
	var offsetY = getWinYOffset(); 	//Window( Frame )のスクリーン上の位置（Y座標）
	var objLeftTd = dojo.byId("tb_left").getElementsByTagName("td");
	
	if(isIE){
		nWinWidth = (document.compatMode && document.compatMode=='CSS1Compat')?documentElement.clientWidth:document.body.clientWidth;
		nWinHeight = (document.compatMode && document.compatMode=='CSS1Compat')?documentElement.clientHeight:document.body.clientHeight;
	}else{
		nWinWidth = window.innerWidth;
		nWinHeight = window.innerHeight;	
	}
		
	//sunpouレイヤーのサイズ設定（初期値設定)
	dojo.style("td_sunpou", "top", offsetY+topMenuHeight);
	dojo.style("td_sunpou", "width",nWinWidth );
	
	//①寸法表の窓高さ	
	var nSunpouHeight = nWinHeight - (bottomHeight+topMenuHeight);
	
	if(nSunpouHeight<0) nSunpouHeight = 0;
	
	dojo.style("td_sunpou", "height", nSunpouHeight);
	
	//②td_leftの幅設定	dojo.style("tb_left", "width", tdLeftOffset);
	
	//#変数
	var nTbLeftWidth = dojo.byId("tb_left").offsetWidth;
	// real main width
	var nTableWidth = dojo.byId("tbl_main").offsetWidth;
	
	
	//real main height
	var nTableHeight = dojo.byId("tbl_main").offsetHeight;
	var minHeight = 2*objLeftTd[0].offsetHeight;	//最低でも2行は出すように
	var specHeight =  dojo.byId("tblKyotu").offsetHeight;		//共通仕様の高さ
	var nTitleHeight = dojo.byId("tb_title").offsetHeight;	//tb_titleの高さ	
	var nDivWidth = 0;	//tb_mainレイヤーの幅	var nDivHeight = 0;	//tb_mainレイヤーの高さ
				
	//③nDivHeightの計算(td_sunpouレイヤーのhorizontal scrollbarがあるかどうかによって振り分ける)
	if(isHorizontalScrollDetect(dojo.byId("td_sunpou"))){		
		nDivHeight = nSunpouHeight - (specHeight+nTitleHeight+pagingHeight+2*nScrollBarHeight);
	}else{
		nDivHeight = nSunpouHeight - (specHeight+nTitleHeight+pagingHeight+1*nScrollBarHeight);
	}
	
	//④nDivWidthの計算(td_sunpouレイヤーのvertical scrollbarがある場合、nScrollBarWidthだけ引く)
	//nSunpouHeight>specHeight+pagingHeight+nTitleHeight+minHeight+nScrollBarHeight(count=1の場合)	
	if(!isVerticalScrollDetect(dojo.byId("td_sunpou"))){	
		nDivWidth = nWinWidth - (nTbLeftWidth+1*nScrollBarWidth);
	}else{
		nDivWidth = nWinWidth - (nTbLeftWidth+2*nScrollBarWidth);
	}
	
	
	
	//画面を縮めた時の対応(IE)	
	if(nDivWidth < 0) nDivWidth = 0;
		
	//dv_keijo(形状図のサイズ調整)
	var objKyoTd = dojo.byId("tblKyotu").getElementsByTagName("td");
		
	//⑤寸法表の幅最小値計算	var minTbMainWidth =　objKyoTd[0].offsetWidth+ minKeijoWidth-nTbLeftWidth;
	
		
	//⑥Windowサイズに合わせてnDivWidth, nDivHeightの再計算	//enlarge the width of tb_main adjusted to window size
	if(nDivWidth > minTbMainWidth){
		if(nDivWidth > nTableWidth) nDivWidth = nTableWidth;
	}else{
		if(minTbMainWidth >nTableWidth) minTbMainWidth = nTableWidth;
		nDivWidth = minTbMainWidth;
	}
		
	if(nDivHeight > minHeight ){	//初期値より大きい場合		if(nDivHeight>nTableHeight) nDivHeight = nTableHeight;
	}else{	////初期値より小さい場合		if(minHeight > nTableHeight) minHeight = nTableHeight;
		nDivHeight = minHeight;
	}
		
	//⑦tb_leftの高さ設定	
	dojo.style("tb_left", "height", nDivHeight);
	

	//⑧tb_titleの幅設定	dojo.style("tb_title", "width", nDivWidth);
		
	var resultWidth = 0;	//tb_mainの幅計算結果
	var resultHeight = 0;	//tb_mainの高さ計算結果
	
	//⑨tb_mainのスクロール検査
	var isHorizontal = false;
	var isVertical = false;

	if(nDivWidth < nTableWidth ) isHorizontal = true;
	if(nDivHeight < nTableHeight) isVertical = true;

	//if(isHorizontal && nDivWidth == nTableWidth) isHorizontal = false;
	//log += "{"+nDivWidth+", "+nTableWidth+"}" +" ";
	//dojo.byId("console").innerHTML = log;
		
	//⑩tb_mainの幅、高さ計算	if(!isHorizontal && !isVertical ){
		
		dojo.byId("tb_main").style.overflowX = "hidden";
		dojo.byId("tb_main").style.overflowY = "hidden";
		
		resultWidth = nDivWidth;
		resultHeight = nDivHeight;
		
	}else if(isHorizontal && !isVertical ){
		
		dojo.byId("tb_main").style.overflowX = "scroll";
		dojo.byId("tb_main").style.overflowY = "hidden";
			
		resultWidth = nDivWidth;
		resultHeight = nDivHeight+nScrollBarHeight;
		
	}else if(!isHorizontal && isVertical ){
		
		dojo.byId("tb_main").style.overflowX = "hidden";
		dojo.byId("tb_main").style.overflowY = "scroll";
				
		resultWidth = nDivWidth+nScrollBarWidth;
		resultHeight = nDivHeight;
		
	}else{
		
		dojo.byId("tb_main").style.overflowX = "scroll";
		dojo.byId("tb_main").style.overflowY = "scroll";
		
		resultWidth = nDivWidth+nScrollBarWidth;
		resultHeight = nDivHeight+nScrollBarHeight;

	}
		
	//⑪tb_mainの幅、高さ設定	
	dojo.style("tb_main", "width", resultWidth);
	dojo.style("tb_main", "height", resultHeight);
		
	//⑫件数が少ないシリーズに対してtd_sunpouの高さ再設定( ex)KTSCPテーパー平歯)  
	var temp = specHeight+nTitleHeight+pagingHeight+resultHeight
	if(dojo.byId("td_sunpou").offsetHeight> temp+nScrollBarHeight){
		if(isHorizontalScrollDetect(dojo.byId("td_sunpou")))	temp+=nScrollBarHeight;
		if(temp<0) temp = 0;
		dojo.style("td_sunpou","height", temp);
	}
	
	//注釈レイヤーのサイズ設定	var tdSunpouHeight = dojo.byId("td_sunpou").offsetHeight;
	var noteOffsetY = offsetY + topMenuHeight + tdSunpouHeight;
	
	var kyotuOffsetY = offsetY + nWinHeight-(kyotuHeight);
	
	//⑬注釈、ボタン群の幅設定(ウィンドウサイズで設定)
	dojo.style("td_kyotu","width", nWinWidth);
	dojo.style("td_note", "width", nWinWidth);
	
	//⑭注釈の位置設定	dojo.style("td_note", "top", noteOffsetY);
							
	//⑮ボタン群の縦位置設定	var buttonHeight=28;	//IE6?	
	if(isIE){
		if(kyotuObj.offsetWidth<tblButtonObj.offsetWidth){
			dojo.style("td_kyotu", "height", buttonHeight + nScrollBarHeight);
		}else{
			dojo.style("td_kyotu", "height", buttonHeight);
		}
	}
	
	dojo.style("td_kyotu", "top", kyotuOffsetY);
		
	//⑯tdKeijo(形状タイトルのサイズ調整)
	//var tdKeijoWidth = tdLeftOffset+resultWidth-objKyoTd[0].offsetWidth;
	var tdKeijoWidth = nWinWidth-objKyoTd[0].offsetWidth;
	if(isVerticalScrollDetect(dojo.byId("td_sunpou"))) tdKeijoWidth -= nScrollBarWidth;
		
	if(tdKeijoWidth<minKeijoWidth) tdKeijoWidth = minKeijoWidth;
	
	//寸法表が短いにもかかわらず形状図の横スクロールバーがでる場合のスクロールバーをなくす処理		
	
	//<td>形状図の幅設定	
	dojo.style("tdKeijo","width",tdKeijoWidth);
		
	//⑰dv_keijo(形状図のサイズ調整)
	dojo.style("dv_keijo","width", tdKeijoWidth);
	
	//⑱tblSpecの幅設定
	//dojo.style("tblSpec", "width", dojo.byId("tblKyotu").offsetWidth);  

	//⑲全体画面にした時のずれ防止
	var objMain = dojo.byId("tb_main");
	if(dojo.byId("tb_title").scrollLeft!=objMain.scrollLeft){
		dojo.byId("tb_title").scrollLeft = objMain.scrollLeft;
		dojo.byId("tb_left").scrollTop = objMain.scrollTop;
	}
	
	//⑳pagingのtable幅調整(扉リンクをテーブル右端基準に)
	var tableWidth = dojo.byId("tb_main").offsetWidth + nTbLeftWidth;
	if(nWinWidth > tableWidth)	dojo.style("tbl_paging","width",tableWidth);
	else	dojo.style("tbl_paging","width",nWinWidth);
	
	if(count<max) {
		count++;
		timerId = setTimeout('adjust()', 10);
				
	}else{
							
		clearTimeout(timerId);
		count= 1;
				
		//ハイライト部分が隠れる現象の対応(IE)
		if(isIE && window.location.href.indexOf("#")>0){
			if(type=="resize"){	//ウィンドウサイズ変更の場合は処理を抜ける		 		return;
			}
		}	
		//IE6 only
		//if(dojo.isIE==6) scrollToAnchor();

		cacheBack();		
	}
		
}//adjust

//Window( Frame )のスクリーン上の位置（Y座標）を取得するメソッドですfunction getWinYOffset(){
	if(window.scrollY) return window.scrollY; // Mozilla
	if(window.pageYOffset) return window.pageYOffset; // Opera, NN4
	if(document.documentElement && document.documentElement.scrollTop){ // 以下 IE
   		return document.documentElement.scrollTop;		//Strict Mode	
  	}else if(document.body && document.body.scrollTop){
   		return document.body.scrollTop;					//Quirks Mode
  	}
  return 0;
}//getWinYOffset

function getWinXOffset(){
  if(window.scrollX) return window.scrollX; // Moziila
  if(window.pageXOffset) return window.pageXOffset; // Opera, NN4
  if(document.documentElement && document.documentElement.scrollLeft){ // 以下 IE
   return document.documentElement.scrollLeft;
  }else if(document.body && document.body.scrollLeft){
   return document.body.scrollLeft;
  }
  return 0;
}//getWinXOffset

/**
*	ハイライト部分が隠れるのを防ぐ為に使うメソッド
*/
function scrollToAnchor(){

	//adjust the top positionig of a selected row
	var element = dojo.byId("tb_main");
	var intElemScrollTop =  element.scrollTop;
	if(isIE){	
		element.scrollTop = intElemScrollTop-6;
	}else{
		element.scrollTop = intElemScrollTop-5;
	}
	
}//scrollToAnchor

/*
	初期呼び出し関数登録
*/
dojo.addOnLoad(function(){
	
	if(dojo.byId("toggleNote")) dojo.connect(dojo.byId("toggleNote"), "onclick", Note.prototype, function(event){
		this.toggleNote();
		adjust(event);
		setStatus(dojo.style("divNote","display"));
	});
	
	dojo.connect(window, "onresize", function(event){
		adjust(event);

	});
	
	if(!isIE){
		initPrevious();
		scrollToAnchor();
	}
	
});

/**
*	作図画面から戻ることを感知する為にcookieに格納するメッソド<br/>
*/
function setPrevious(){
	var sunpouFrm = document.forms['SunpouFrm'];
	
	var tmp = "";
	tmp += sunpouFrm.previous.value;

	setCookie("seriesCookie", tmp);
	
}//setPrevious

/**
*	cookieからpreviousの値を削除するメッソド<br/>
*/
function initPrevious(){

	document.forms['SunpouFrm'].previous.value=0;
	document.cookie = "seriesCookie=; expires=Thu,01-Jan-1970 00:00:01 GMT";

}//initPrevious

function setCookie(Name,Val)
{
	document.cookie = Name + "=" + Val + ".";
}//setCookie

function readCookie(STR)
{
	theData = "";
	theName = STR + "=";
	theCookie = document.cookie + ":";
	start = theCookie.indexOf(theName);
	if (start != -1)
	{
		end = theCookie.indexOf(":",start);
		theData = unescape(theCookie.substring(start + theName.length,end));
		
	}
	return theData;
}//readCookie

/*
	注釈ブロックを表示・非表示するメッソドです。
*/
Note.prototype.toggleNote = function(toggle){
	var divNote = dojo.byId("divNote");
	var hideCautL = dojo.byId("hideCautL");
	var hideCautR = dojo.byId("hideCautR");
	
	if((toggle==null && dojo.style("divNote","display")=="block") || toggle=="on") {
		//this.tdNoteHeight = dojo.style("td_note","height");
		this.toggleNoteHeight = dojo.style("toggleNote","height");
		dojo.style("divNote","display","none");
		hideCautL.src = "../img/up.gif";
		hideCautR.src = "../img/up.gif";
		dojo.style("td_note","height", this.toggleNoteHeight);
		document.SunpouFrm.display.value="none";
	}else{
		dojo.style("divNote","display","block");
		hideCautL.src = "../img/down.gif";
		hideCautR.src = "../img/down.gif";
		dojo.style("td_note","height", this.tdNoteHeight);
		document.SunpouFrm.display.value="block";
	}//if~else
	
	//寸法表高さ調整
	var nWinHeight = getWinHeight();
			
	var noteHeight = dojo.style("td_note", "height");
	var topMenuHeight = dojo.style("td_menu","height");
	var kyotuHeight = dojo.style("td_kyotu", "height");
	var bottomHeight = noteHeight+kyotuHeight;
	var nSunpouHeight = nWinHeight - (bottomHeight+topMenuHeight);
		
	if(nSunpouHeight<0) nSunpouHeight = 0;
	
	var noteOffsetY = getWinYOffset() + topMenuHeight + nSunpouHeight;
	
	dojo.style("td_note","top", noteOffsetY);
	

}//toggleNote

/*
	注釈レイヤーの折り畳みステータスを保持する非同期メッソドです。
*/
function setStatus(arg){
	var params = new Array();
	
	params['display'] = arg;
	params['method'] = "update";
	
	var bindArgs = {
    	url: "status.do",
    	preventCache: true,
        load: function(responseObject, ioArgs){
            return responseObject;
        },
        handleAs: "xml",
        content: params,
        error: function(response, ioArgs){
		      return response;
		}
	};
        
    dojo.xhrGet(bindArgs);
}//setStatus

/*
	注釈レイヤーの折り畳みステータスを取得する非同期メッソドです。
*/
function getStatus(){
	var params = new Array();
	
	params['method'] = "view";
	
	var bindArgs = {
    	url: "status.do",
    	sync: true,
    	preventCache: true,
    	load: function(responseObject, ioArgs){
        	var status = responseObject.getElementsByTagName("status")[0].firstChild.nodeValue;
        	document.SunpouFrm.display.value = status;
        	        	
            return responseObject;
        },
        handleAs: "xml",
        content: params,
        error: function(response, ioArgs){
		      return response;
		}
	};
        
    dojo.xhrGet(bindArgs);
}//getStatus

function goPage(obj){
	var location = obj.getAttribute("href");
	
	var strProduct = document.SunpouFrm.selectSName.value;
	var link = location;
		
	if(location.indexOf("txtCatalog")>0) {
		link += "&txtCatalog=" + strProduct;
	}
	
	
	obj.setAttribute("href", link);
}//goPage

function getWinHeight(){
	if(isIE){
		nWinHeight = (document.compatMode && document.compatMode=='CSS1Compat')?documentElement.clientHeight:document.body.clientHeight;
	}else{
		nWinHeight = window.innerHeight;	
	}
	return nWinHeight;
}//getWinHeight

function getWinWidth(){
	if(isIE){
		nWinWidth = (document.compatMode && document.compatMode=='CSS1Compat')?documentElement.clientWidth:document.body.clientWidth;
	}else{
		nWinWidth = window.innerWidth;
	}
	return nWinWidth;
}//getWinWidth

function Note(){
	this.tdNoteHeight = 0;	//注釈レイヤーの高さ
	this.toggleNoteHeight = 0;

}

Note.prototype = new Note;

