/* 3.8.5.3 (2006/08/07) change CSS file userd. */
/* 3.8.9.1 (2007/06/15) Correspondence of case with frame division into three or more.	*/

$(function(){
	$('.toggleTop').click( function(){ toggleTopFrame(this); } );
	$('.toggleSub').click( function(){ toggleSubFrame(this); } );
	$('.toggleAll').click( function(){ toggleAllFrame(this); } );
});

var old_cols = null ;
var old_rows = null ;
var old_prnt = null ;
var toggleCol = false;	// true: FrameOpen false: FrameClose
var toggleRow = false;	// true: FrameOpen false: FrameClose
var toggleAll = false;	// true: FrameOpen false: FrameClose
var togglePrnt = false;	// true: FrameOpen false: FrameClose

function toggleTopFrame( tdx ) {
	var sTopFrameNM = "TOP_FRAME";
	var oTopFrame = top.document.getElementById(sTopFrameNM);			//IE,Opera
    if(!oTopFrame) {
		var oFramesets = top.document.getElementsByName(sTopFrameNM);	//IE,FireFox
		if( oFramesets.length == 1 ) { oTopFrame = oFramesets[0]; }
	}

	if(!oTopFrame) { return; }

	if( toggleCol ) {
		toggleCol = false;
//		oTopFrame.cols  = old_cols;
//		if( old_cols.split(",")[0] == 0 ) { // 4.2.0.1 (2008/3/31)
		if( old_cols.split(",")[0] <= 10 ) { // 4.3.6.3 (2009/04/22)
			oTopFrame.cols  = "160,*";
		}
		else {
			oTopFrame.cols  = old_cols;
		}
		if( tdx != null ) {
			if( tdx.className.length == 0 ) { tdx.style.backgroundColor  = "Red"; }
			else { tdx.className = "toggleTop"; }
		}
	}
	else {
		toggleCol = true;
		old_cols = oTopFrame.cols ;
		oTopFrame.cols = "10,*";
		if( tdx != null ) {
			if( tdx.className.length == 0 ) { tdx.style.backgroundColor  = "Gray"; }
			else { tdx.className = "toggleOff"; }
		}
	}
}

function toggleSubFrame( tdx ) {
	var sSubFrameNM = "SUB_FRAME";
	var oSubFrame = parent.document.getElementById(sSubFrameNM);			//IE,Opera
	if(!oSubFrame) {
		var oFramesets = parent.document.getElementsByName(sSubFrameNM);	//IE,FireFox
		if( oFramesets.length == 1 ) { oSubFrame = oFramesets[0]; }
	}

	if(!oSubFrame) { return; }

	if( toggleRow ) {
		toggleRow = false;
		oSubFrame.rows = old_rows;
		if( tdx != null ) {
			if( tdx.className.length == 0 ) { tdx.style.backgroundColor  = "Green"; }
			else { tdx.className = "toggleSub"; }
		}
	}
	else {
		toggleRow = true;
		old_rows = oSubFrame.rows ;
		if( parent.QUERY != null ) {
			var tbl = parent.QUERY.document.getElementById( "QUERY_TBL" );
			if( tbl != null ) {
				// 3.8.9.1 (2007/06/15)
				var orgRows = oSubFrame.rows.split( "," ) ;
				var tempRows = (tbl.offsetTop +  tbl.offsetHeight + tbl.parentNode.offsetTop) + ",*" ;
				for(var i=2; i<orgRows.length; i++){
					tempRows = tempRows + "," + orgRows[i] ;
				}
				oSubFrame.rows = tempRows;
			}
		}
		if( tdx != null ) {
			if( tdx.className.length == 0 ) { tdx.style.backgroundColor  = "Gray"; }
			else { tdx.className = "toggleOff"; }
		}
	}
}

function toggleAllFrame( tdx ) {
	if( toggleAll ) {
		toggleAll = false;
		if( toggleCol ) { toggleTopFrame(); }
		if( toggleRow ) { toggleSubFrame(); }
		if( tdx != null ) {
			if( tdx.className.length == 0 ) { tdx.style.backgroundColor  = "Blue"; }
			else { tdx.className = "toggleAll"; }
		}
	}
	else {
		toggleAll = true;
		if( ! toggleCol ) { toggleTopFrame(); }
		if( ! toggleRow ) { toggleSubFrame(); }
		if( tdx != null ) {
			if( tdx.className.length == 0 ) { tdx.style.backgroundColor  = "Gray"; }
			else { tdx.className = "toggleOff"; }
		}
	}
}

/* indx is frame address */
function toggleFrame( mark ) {
	var oFramesets = parent.document.getElementsByTagName("FRAMESET");
	if( oFramesets.length == 1 ) { oSubFrame = oFramesets[0]; }

	if(!oSubFrame) { return; }

	if( togglePrnt ) {
		togglePrnt = false;
		oSubFrame.rows = old_prnt;

		if( mark ) {
			mark.innerHTML = "(-)" ;
		}

	}
	else {
		togglePrnt = true;
		old_prnt = oSubFrame.rows ;

		var indx = -1;
		for( var j=0; j<parent.frames.length; j++ ) {
			if( self.frames.name == parent.frames[j].name ) {
				indx = j;
				break;
			}
		}

		var orgRows = oSubFrame.rows.split( "," ) ;
		if( mark == null ) { orgRows[indx] = "0"; }
		else {
			orgRows[indx] = (mark.offsetTop +  mark.offsetHeight + mark.parentNode.offsetTop);
			mark.innerHTML = "(+)" ;
		}

		var tempRows = orgRows[0] ;
		for(var i=1; i<orgRows.length; i++){
			tempRows = tempRows + "," + orgRows[i] ;
		}
		oSubFrame.rows = tempRows;
	}
}
