/* ◎◇ */
/*{
-------------------------------------------------------------------------------
Type:Object
Topic.
	Dynamic HTML 
MakeBy
	1.00	2006/12/07	hical_satow
-------------------------------------------------------------------------------
}*/

window.DHTML = {

/*{
-------------------------------------------------------------------------------
Type:Value
Topic.
	各種フラグ
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/

m_fCSS    : false,
m_fW3C    : false,
m_fIE4    : false,
m_fNN4    : false,
m_fIE6CSS : false,

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	文字列名から入れ子になったNN4レイヤを探す
Parameter
Return
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
layerSeek: function( doc, name )
{
	var obj = null;
	for ( var nIdx = 0 ; nIdx < doc.layers.length ; nIdx++ ) {
		if ( name == doc.layers[ nIdx ].name ) {
			return ( doc.layers[ nIdx ] );
		}
		if ( 0 < doc.layers[ nIdx ].document.layers.length ) {
			obj = this.layerSeek( doc.layers[ nIdx ].document, name );
			if ( null != obj ) {
				return ( obj );
			}
		}
	}
	return ( obj );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	オブジェクト名文字列やオブジェクト参照を正当な要素オブジェクト参照に変換
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
Return
	該当するオブジェクト
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
rawObject: function( prm )
{
	if ( 'string' != typeof prm ) {
		return ( prm );
	}
	if ( this.m_fW3C ) {
		return ( document.getElementById( prm ) );
	}
	if ( this.m_fIE4 ) {
		return ( document.all( prm ) );
	}
	if ( this.m_fNN4 ) {
		return ( this.layerSeek( document, prm ) );
	}
	return ( 0 );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	オブジェクト名やオブジェクト参照を正当なスタイル(またはNN4のレイヤ)参照に変換
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
Return
	該当するオブジェクトのスタイル
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
objectStyle: function( prm )
{
	var obj = this.rawObject( prm );
	if ( obj && this.m_fCSS ) {
		return ( obj.style );
	}
	return ( obj );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	ブラウザウィンドウの利用可能なコンテンツ空間を取得
Return
	高さおよび幅
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
insideHeight: function(  )
{
	if ( window.innerHeight ) {
		return ( window.innerHeight );
	}
	if ( this.m_fIE6CSS ) {
		return ( document.body.parentElement.clientHeight );
	}
	if ( document.body && document.body.clientHeight ) {
		return ( document.body.clientHeight );
	}
	return ( 0 );
},

insideWidth: function(  )
{
	if ( window.innerWidth ) {
		return ( window.innerWidth );
	}
	if ( this.m_fIE6CSS ) {
		return ( document.body.parentElement.clientWidth );
	}
	if ( document.body && document.body.clientWidth ) {
		return ( document.body.clientWidth );
	}
	return ( 0 );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	位置指定可能なオブジェクトの座標を取得
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
	xy -- 上または左
Return
	処理が成功すれば座標。エラーで undefined
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
objectTopLeft: function( prm, xy )
{
	var objElem = this.rawObject( prm );
	if ( document.defaultView ) {
		var style = document.defaultView;
		var cssDecl = style.getComputedStyle( objElem, '' );
		var nResultDef = cssDecl.getPropertyValue( ( 'y' == xy ) ? 'top' : 'left' );
		if ( 'auto' != nResultDef ) {
			return ( parseInt( nResultDef ) );
		}
	}
	if ( objElem.currentStyle ) {
		var nResult = ( ( 'y' == xy ) ? objElem.currentStyle.top : objElem.currentStyle.left );
		if ( nResult && '' != nResult && 'auto' != nResult ) {
			return ( parseInt( nResult ) );
		}
	}
	if ( objElem.style ) {
		var nResult = ( ( 'y' == xy ) ? objElem.style.top : objElem.style.left );
		if ( nResult && '' != nResult && 'auto' != nResult ) {
			return ( parseInt( nResult ) );
		}
	}
	if ( this.m_fW3C ) {
		if ( objElem.parentNode ) {
			var nResult = 0;
			//for ( var objParent = objElem ; objParent ; objParent = objParent.parentNode ) {
			for ( var objParent = objElem ; objParent ; objParent = objParent.offsetParent ) {
				if ( 'BODY' == objParent.tagName ) {
					break ;
				}
				nResult += parseInt( ( ( 'y' == xy ) ? objParent.offsetTop : objParent.offsetLeft ) );
			}
			return ( nResult );
		}
		if ( 0 != ( ( 'y' == xy ) ? objElem.offsetTop : objElem.offsetLeft ) ) {
			var nResult = 0;
			for ( var objParent = objElem ; objParent ; objParent = objParent.offsetParent ) {
				nResult += parseInt( ( 'y' == xy ) ? objParent.offsetTop : objParent.offsetLeft );
			}
			return ( nResult );
		}
		var nResult = objElem.y;
		if ( nResult && '' != nResult && 'auto' != nResult ) {
			return ( parseInt( nResult ) );
		}
		nResult = ( ( 'y' == xy ) ? objElem.top : objElem.left );
		if ( nResult && '' != nResult && 'auto' != nResult ) {
			return ( parseInt( nResult ) );
		}
	}
	if ( this.m_fNN4 ) {
		var nResult = ( ( 'y' == xy ) ? objElem.top : objElem.left );
		if ( nResult && '' != nResult && 'auto' != nResult ) {
			return ( parseInt( nResult ) );
		}
	}
	return ( undefined );
},

objectTop: function( prm )
{
	return ( this.objectTopLeft( prm, 'y' ) );
},

objectLeft: function( prm )
{
	return ( this.objectTopLeft( prm, 'x' ) );
},

objectHeight: function( prm )
{
	var objElem = this.rawObject( prm );
	if ( ! objElem ) {
		return ( undefined );
	}
	var nResult = 0;
	if ( objElem.offsetHeight ) {
		nResult = objElem.offsetHeight;
	}
	else if ( objElem.clip && objElem.clip.height ) {
		nResult = objElem.clip.height;
	}
	else if ( objElem.style && objElem.style.pixelHeight ) {
		nResult = objElem.style.pixelHeight;
	}
	return ( parseInt( nResult, 10 ) );
},

objectWidth: function( prm )
{
	var objElem = this.rawObject( prm );
	if ( ! objElem ) {
		return ( undefined );
	}
	var nResult = 0;
	if ( objElem.offsetWidth ) {
		nResult = objElem.offsetWidth;
	}
	else if ( objElem.clip && objElem.clip.width ) {
		nResult = objElem.clip.width;
	}
	else if ( objElem.style && objElem.style.pixelWidth ) {
		nResult = objElem.style.pixelWidth;
	}
	return ( parseInt( nResult, 10 ) );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	指定されたピクセル座標にオブジェクトを移動
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
	nLeft, nTop -- 座標
		<nTop>が省略された場合、x をオブジェクト{ x: X座標, y:Y座標 } とみなす。
Return
	処理が成功すれば真。エラーで偽。
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
shiftTo: function( prm, nLeft, nTop )
{
	if ( 'object' == typeof nLeft && ( null == nTop || undefined == nTop ) ) {
		nTop = nLeft.y;
		nLeft = nLeft.x;
	}
	var style = this.objectStyle( prm );
	if ( ! style ) {
		return ( false );
	}
	if ( this.m_fCSS ) {
		var units = ( ( 'string' == typeof style.left ) ? 'px' : null );
		style.top  = nTop  + units;
		style.left = nLeft + units;
		return ( true );
	}
	else if ( this.m_fNN4 ) { 
		style.moveTo( nLeft, nTop );
		return ( true );
	}
	return ( false );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	オブジェクト移動
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
	x, y -- 座標
		<y>が省略された場合、x をオブジェクト{ x: X座標, y:Y座標 } とみなす。
Return
	処理が成功すれば真。エラーで偽。
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
shiftBy: function( prm, x, y )
{
	if ( 'object' == typeof x && ( null == y || undefined == y ) ) {
		y = x.y;
		x = x.x;
	}
	var style = this.objectStyle( prm );
	if ( ! style ) {
		return ( false );
	}
	if ( this.m_fCSS ) {
		var units = ( ( 'string' == typeof style.left ) ? 'px' : 0 );
		style.top = styleectTop( style ) + y + units;
		style.left = styleectLeft( style ) + x + units;
		return ( true );
	}
	else if ( this.m_fNN4 ) { 
		style.moveBy( x, y );
		return ( true );
	}
	return ( false );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	表示/非表示
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
Return
	処理が成功すれば真。エラーで偽。
MakeBy
	1.00	2006/12/08	hical_satow
	1.01	2007/01/26	hical_satow
		IEにて既存の<tr>に対して'table-row'を設定するとエラーになるので回避
-------------------------------------------------------------------------------
}*/
objectShow: function( prm, disp )
{
	var style = this.objectStyle( prm );
	if ( ! style ) {
		return ( false );
	}
	if ( disp ) {
		if ( DHTML.m_fIE4 && 'table-row' == disp ) {
			disp = 'block';
		}
		style.display = disp;
	}
	style.visibility = 'visible';
	return ( true );
},

objectHide: function( prm, disp )
{
	var style = this.objectStyle( prm );
	if ( ! style ) {
		return ( false );
	}
	style.visibility = 'hidden';
	if ( disp ) {
		style.display = disp;
	}
	return ( true );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	Z座標を設定
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
	zOrder -- Z座標
Return
	処理が成功すれば真。エラーで偽。
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
ZorderSet: function( prm, zOrder )
{
	var style = this.objectStyle( prm );
	if ( ! style ) {
		return ( false );
	}
	style.zIndex = zOrder;
	return ( true );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	オブジェクトのスタイルを変更
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
	style -- スタイル名
Return
	処理が成功すれば真。エラーで偽。
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
styleChg: function( prm, style )
{
	var objElem = this.rawObject( prm );
	if ( ! objElem ) {
		return ( false );
	}
	objElem.className = style;
	return( true );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	innerHTML
Parameter
	prm -- オブジェクトやオブジェクト名文字列など
	contents -- コンテンツ
Return
	処理が成功すれば真。エラーで偽。
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
innerHTMLSet: function( prm, contents )
{
	var obj = this.rawObject( prm );
	if ( ! obj ) {
		return ( false );
	}
	obj.innerHTML = contents;
	return( true );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	イベントオブジェクト
Parameter
Return
MakeBy
	1.00	2006/12/12	hical_satow
-------------------------------------------------------------------------------
}*/
eventTarget: function( evt )
{
	var evt = ( ( evt ) ? evt : ( window.event ) ? window.event : null );
	var obj = ( ( evt.target ) ? evt.target : ( event.srcElement ) ? event.srcElement : null );
	if ( ! obj ) {
		return ( undefined );
	}
	return ( obj );
},

/*{
-------------------------------------------------------------------------------
Type:Function
Topic.
	初期化
		(各種フラグを初期化)
MakeBy
	1.00	2006/12/08	hical_satow
-------------------------------------------------------------------------------
}*/
initialize: function(  )
{
	if ( document.images ) {
		this.m_fCSS = ( ( document.body && document.body.style ) ? true : false );
		this.m_fW3C = ( ( this.m_fCSS && document.getElementById ) ? true : false );
		this.m_fIE4 = ( ( this.m_fCSS && document.all ) ? true : false );
		this.m_fNN4 = ( ( document.layers ) ? true : false );
		this.m_fIE6CSS = ( ( document.compactMode && 0 <= document.compactMode.indexOf( 'CSS1' ) ) ? true : false );
	}
}

};	/* window.DHTML */

