var	cur_mnu	= new Array();
cur_mnu[0]	= null;
cur_mnu[1]	= null;
cur_mnu[2]	= null;


//================================================
// ctlPulldown
//------------------------------------------------
// ひとつでも開いているプルダウンがあれば全て消去
// そうでなければプルダウン表示
//================================================
function ctlPulldown( owner, target, level ,rows){
	var flag	= false;
	
	for( var i = 0; i < cur_mnu.length; i++ ){
		if( cur_mnu[i] )	flag	= flag | true;
	}
	
	if( flag )	closeAllPulldown();
	else		showPulldown( owner, target, level ,rows );
}


//================================================
// showPulldown
//------------------------------------------------
// 指定されたレベルのプルダウン表示
//================================================
function showPulldown( owner, target, level,rows){
	//----------------------------------
	// ＩＥとＦｉｒｅｆｏｘでは
	// ｃｅｎｔｅｒ属性のかかるエレメント位置が違う
	//----------------------------------
	var ox	= document.getElementById( owner ).offsetLeft	+ document.getElementById( "src-table" ).offsetLeft	+	document.getElementById( "src-tr" ).offsetLeft	+	document.body.offsetLeft;
	var oy	= document.getElementById( owner ).offsetTop	+ document.getElementById( "src-table" ).offsetTop	+ document.body.offsetTop;
	//var ox	= document.getElementById( owner ).offsetLeft	+ ctlY	+	document.getElementById( "src-tr" ).offsetLeft	+	document.body.offsetLeft;
	//var oy	= document.getElementById( owner ).offsetTop	+ ctlX	+	document.body.offsetTop;
	var ow	= document.getElementById( owner ).offsetWidth;
	var oh	= document.getElementById( owner ).offsetHeight;
	
	var to	= document.getElementById( target );

//alert('ox='+ox+'\r\noy='+oy+'\r\now='+ow+'\r\noh='+oh);

	closePulldown( level );		// 同じレベルの先に開いているプルダウン消去
	
	
	//alert( "bx1 = " + document.getElementById( "bx1" ).offsetLeft );
	//alert( "t4 = " + document.getElementById( "t_4_layout" ).offsetLeft );
	//alert( "tr = " + document.getElementById( "src_tr" ).offsetLeft );
	//alert( "src = " + document.getElementById( "src-table" ).offsetLeft );
	//alert( "ox = " + ox + " : oy = " + oy + " : ow = " + ow + " : oh = " + oh );
	//----------------------------------
	// プルダウンメニューの表示位置設定
	// ＨＴＭＬエレメントのマージン・パディング・ボーダーの値によって
	// 各ブラウザ表示位置に補正を加える必要がある
	// 現在の値はＩＥ限定
	//----------------------------------
	if(!rows){
		rows=2;
	}
	
	if( level == 1 ){
		//------------------------------
		// 縦に接続
		//------------------------------
		to.style.top	= oy + oh + 7;
		to.style.left	= ox - 2;
	}else if( level == 2 ){
		//------------------------------
		// 横に接続
		//------------------------------
		to.style.top	= oy + oh + 7;
		to.style.left	= ox + ow + 2;
	}else if( level == 3 ){
		var oy2	= document.getElementById( cur_mnu[1] ).offsetTop+ document.getElementById( "src-table" ).offsetTop	+ document.body.offsetTop;
		to.style.top	= oy + (oh*rows) + 7;
		to.style.left	= ox + ow + ow + 2;
	}
	
	to.style.display	= "block";
	
	cur_mnu[level-1]	= target;	// 開いたプルダウンのｉｄを登録
}


//================================================
// changeBGC
//------------------------------------------------
// プルダウンの背景色変更
//================================================
function changeBGC( target, color ){
	var tmp	= document.getElementById( target );
	tmp.style.backgroundColor	= color;
	tmp.style.color				= "#fff";
}


//================================================
// undoBGC
//------------------------------------------------
// プルダウンの背景色を戻す
//================================================
function undoBGC( target, color ){
	var tmp	= document.getElementById( target );
	tmp.style.backgroundColor	= "#fff";
	if( color )	tmp.style.color	= color;
	else		tmp.style.color	= "#666";
}

function setValue( target, selected, owner, value ){
	//alert( "setValue" );
	//----------------------------------
	// 擬似セレクトボックスの中身を変更する
	//----------------------------------
	document.getElementById( selected ).innerHTML	=	document.getElementById( owner ).innerHTML;
	//----------------------------------
	// ｈｉｄｄｅｎフォームの中身を変更する
	//----------------------------------
	//alert( document.getElementById( "hide_" + target ) );
	//----------------------------------
	//if( value )	document.getElementById( "hidden_form" ).innerHTML	= "<input type='text' name='" + target + "' value='" + value + "'/>";
	//else		document.getElementById( "hidden_form" ).innerHTML	= "<input type='text' name='" + target + "' value=''/>";
	if( value ){
		document.getElementById( "hidden_form" ).name	= target;
		document.getElementById( "hidden_form" ).value	= value;
	}else{
		document.getElementById( "hidden_form" ).name	= target;
		document.getElementById( "hidden_form" ).value	= "";
	}
	//----------------------------------
	// 変更後、プルダウンを閉じる
	//----------------------------------
	//alert( document.getElementById( "hidden_form" ).innerHTML );
	closeAllPulldown();
}
function setValue2( target, selected, text, value ){
//	alert( "setValue" );
	//----------------------------------
	// 擬似セレクトボックスの中身を変更する
	//----------------------------------
	document.getElementById( selected ).innerHTML	=	text;
	//----------------------------------
	// ｈｉｄｄｅｎフォームの中身を変更する
	//----------------------------------
	//alert( document.getElementById( "hide_" + target ) );
	//----------------------------------
	//if( value )	document.getElementById( "hidden_form" ).innerHTML	= "<input type='text' name='" + target + "' value='" + value + "'/>";
	//else		document.getElementById( "hidden_form" ).innerHTML	= "<input type='text' name='" + target + "' value=''/>";
	if( value ){
		document.getElementById( "hidden_form" ).name	= target;
		document.getElementById( "hidden_form" ).value	= value;
	}else{
		document.getElementById( "hidden_form" ).name	= target;
		document.getElementById( "hidden_form" ).value	= "";
	}
}

//------------------------------------------------
// プルダウンメニューを閉じる
//------------------------------------------------
function closePulldown( level ){
	//alert( level );
	//alert( cur_mnu.length );
	//----------------------------------
	// 指定されたレベル以下のプルダウンをクローズする
	//----------------------------------
	for( var i = 0; i < cur_mnu.length; i++ ){
		if( i >= level-1 && cur_mnu[i] ){
			document.getElementById( cur_mnu[i] ).style.display	= "none";
			cur_mnu[i]	= null;
		}
	}
}


//------------------------------------------------
// すべてのプルダウンメニューを閉じる
//--------------------------------------
// 例１）項目が決定されたとき
// 例２）ウインドウがリサイズされたとき
//------------------------------------------------
function closeAllPulldown(){
	//alert( cur_mnu.length );
	for( var i = 0; i < cur_mnu.length; i++ ){
		if( cur_mnu[i] ){
			document.getElementById( cur_mnu[i] ).style.display	= "none";
			cur_mnu[i]	= null;
		}
	}
}