
n4 = (document.layers)?1:0
e4 = (document.all)?1:0;
function heightCenter(OBJ, E) { 

  if(n4) { 

	var ODH = OBJ.document.height 
	var posTop = E.pageY - ODH/2
	var posElementUp = E.pageY - ODH/2
	var posElementDown = E.pageY + ODH/2
	var screenUp = window.pageYOffset +2 // +2´Â nn4¿¡¼­ border¸¦ ÁöÁ¤ÇÒ ¼ö ¾ø¾î¼­ border¸¦ ´Ù »°´Âµ¥ ¾È³»Ã¢À» ÆäÀÌÁö ³¡¿¡¼­ ¾à°£ ¶³¾îÁö°Ô ÇÏ¿© ÀüÃ¼ÀûÀÎ Å©±â¸¦ ¾Ë±â ½±°ÔÇÏ±â À§ÇÔ.
	var screenDown = window.pageYOffset + window.innerHeight -2
		// -2´Â nn4¿¡¼­ border¸¦ ÁöÁ¤ÇÒ ¼ö ¾ø¾î¼­ border¸¦ ´Ù »°´Âµ¥ ¾È³»Ã¢À» ÆäÀÌÁö 
		// ³¡¿¡¼­ ¾à°£ ¶³¾îÁö°Ô ÇÏ¿© ÀüÃ¼ÀûÀÎ Å©±â¸¦ ¾Ë±â ½±°ÔÇÏ±â À§ÇÔ.
	var posY = 0;
	
	if(self != top) { 
		posY += 4 
		if( document.width > window.innerWidth+4 ) posY += -16 ; 
		screenDown += posY
	}
	else if(document.width > window.innerWidth) { 
		posY += -16 
		screenDown += posY
	}

	if(posElementUp > screenUp && posElementDown < screenDown) {
		posTop = posElementUp; 
	}
	else if( posElementDown > document.height ) { 
		while( (posElementDown > screenDown) && (posElementUp > screenUp) ) {
				posElementDown--
				posElementUp--
		}
		if(posElementDown > document.height && document.height > screenDown) 
			posElementUp = document.height - ODH; 
	}
	else if(posElementUp < screenUp && posElementDown < screenDown) {

		while( posElementDown < document.height && posElementUp < screenUp) {
				posElementDown++; 
				posElementUp++
		}
	}
	else if(posElementUp > screenUp && posElementDown > screenDown && posElementDown < document.height ) {

		while( posElementDown > screenDown && posElementUp > screenUp) {
				posElementDown--; 
				posElementUp--
		}
	}
	else if(posElementUp < screenUp && posElementDown > screenDown ) { 

		while( posElementDown < document.height && posElementUp < screenUp) {
				posElementDown++; 
				posElementUp++
		}
	}
	posTop = posElementUp
	if(posTop < 0) posTop=0; //°¡²û topÀÌ -°¡ ³ª¿Ã ¼ö ÀÖ´Ù. ÀÌ °æ¿ì 0À¸·Î ÁØ´Ù. 
	if( posTop+ODH > document.height && document.height > screenDown) { //¹ö±× ¿¹¹æ ÄÚµåÀÓ.
		posTop = document.height - ODH 
	}
  }

  else if(e4) {
	var ODH = OBJ.offsetHeight 
	var posTop = E.clientY + document.body.scrollTop - ODH/2 
	var posElementUp = E.clientY + document.body.scrollTop - ODH/2 
	var posElementDown = E.clientY + document.body.scrollTop + ODH/2 
	var screenUp = document.body.scrollTop + 2
	var screenDown = document.body.scrollTop + document.body.clientHeight - 2

	if(posElementUp > screenUp && posElementDown < screenDown) {
		posTop = posElementUp; 
	}
	else if(posElementUp < screenUp && posElementDown < screenDown) {

		while(posElementUp < screenUp) {
				posTop++
				posElementDown++; 
				posElementUp++
		}
	}
	else if(posElementUp > screenUp && posElementDown > screenDown) { 

		while( posElementDown > screenDown && posElementUp > screenUp) {
				posTop--
				posElementDown--; 
				posElementUp--
		}
	}
	else if(posElementUp < screenUp && posElementDown > screenDown ) { 

		while( posElementUp < screenUp) {
				posTop++
				posElementDown++; 
				posElementUp++
		}
	}
	if( posTop < 0 ) posTop = 0; 
  }
	return posTop
}
function widthCenter(OBJ, E) { 
    if(n4) { 
	var ODW = OBJ.document.width 
	var posLeft = E.pageX - ODW/2
	var posElementL = E.pageX - ODW/2
	var posElementR = E.pageX + ODW/2
	var screenL = window.pageXOffset +2 // +2´Â nn4¿¡¼­ border¸¦ ÁöÁ¤ÇÒ ¼ö ¾ø¾î¼­ border¸¦ ´Ù »°´Âµ¥ ¾È³»Ã¢À» ÆäÀÌÁö ³¡¿¡¼­ ¾à°£ ¶³¾îÁö°Ô ÇÏ¿© ÀüÃ¼ÀûÀÎ Å©±â¸¦ ¾Ë±â ½±°ÔÇÏ±â À§ÇÔ.
	var screenR = window.pageXOffset + window.innerWidth -2
	var posX = 0;
	
	if(self != top) { 
		posX += 4 
		if( document.height > window.innerHeight+4 ) posX += -16 ; 
		screenR += posX
	}
	else if( document.height > window.innerHeight ) { 
		posX += -16 
		screenR += posX
	}
	
	if(posElementL > screenL && posElementR < screenR) {
		posLeft = posElementL; 
	}
	else if( posElementR > screenR ) { 

		while( posElementR > screenR && posElementL > screenL ) {
				posElementR--
				posElementL--
		}
		// À§ÀÇ while¹®À¸·Î º¸³ÂÀ» ¶§ ÆäÀÌÁö Æøº¸´Ù Å« ·¹ÀÌ¾î´Â ¾Æ·¡°¡ Àß¸°´Ù. 
		// ±×·¡¼­ ÆäÀÌÁö °¡Àå ¹Ø¿¡ µÐ´Ù. 
		if(posElementR > screenR && document.width > screenR) 
			posElementL = document.width - ODW; 
	}
	else if(posElementL < screenL && posElementR < screenR) {

		while( posElementR < document.width && posElementL < screenL) {
				posElementR++; 
				posElementL++
		}
	}
	else if(posElementL > screenL && posElementR > screenR && posElementR < document.width ) {

		while( posElementR > screenR && posElementL > 0) {
				posElementR--; 
				posElementL--
		}
	}
	else if(posElementL < screenL && posElementR > screenR ) { 

		while( posElementR < document.width && posElementL < screenL) {
				posElementR++; 
				posElementL++
		}
	}
	posLeft = posElementL
	if(posLeft < 0) posLeft = 0; //°¡²û topÀÌ -°¡ ³ª¿Ã ¼ö ÀÖ´Ù. ÀÌ °æ¿ì 0À¸·Î ÁØ´Ù. 
	if( posLeft+ODW > document.width && document.width > screenR) { //¹ö±× ¿¹¹æ ÄÚµåÀÓ.
		posLeft = document.width - ODW 
	}
    }
    else if(e4) {
	var ODW = OBJ.offsetWidth
	var posLeft = E.clientX + document.body.scrollLeft - ODW/2
	var posElementL = E.clientX + document.body.scrollLeft - ODW/2;
	var posElementR = E.clientX + document.body.scrollLeft + ODW/2;
	var screenL = document.body.scrollLeft + 2
	var screenR = document.body.scrollLeft + document.body.clientWidth - 2

	if(posElementL > screenL && posElementR < screenR) {
		posLeft = posElementL; 
	}
	else if(posElementL < screenL && posElementR < screenR) {

		while(posElementL < screenL) {
				posLeft++
				posElementR++; 
				posElementL++
		}
	}
	else if(posElementL > screenL && posElementR > screenR) { 

		while( posElementR > screenR && posElementL > screenL ) {
				posLeft--
				posElementR--; 
				posElementL--
		}
	}
	else if(posElementL < screenL && posElementR > screenR ) { 

		while( posElementL < screenL) {
				posLeft++
				posElementR++; 
				posElementL++
		}
	}
	if( posLeft < 0 ) posLeft = 0; //¹ö±×¿¹¹æ
    }
	return posLeft
}
function showLayer(X, e) {

	if(n4) { 

		var OBJ = document.layers[X]
		OBJ.top = heightCenter(OBJ, e)
		OBJ.left = widthCenter(OBJ, e)
		OBJ.visibility = "visible"
	}
	else if(e4) {
		var OBJ = document.all[X]
		OBJ.style.pixelTop = heightCenter(OBJ, e)
		OBJ.style.pixelLeft = widthCenter(OBJ, e)
		OBJ.style.visibility = "visible"
	}
}

function showLayer2(X, e) {

	if(n4) { 
		var OBJ = document.layers[X]
		OBJ.top = e.pageY + 20
		OBJ.left = widthCenter(OBJ, e)
		OBJ.visibility = "visible"

	}
	else if(e4) {
		var OBJ = document.all[X]
		OBJ.style.pixelTop = document.body.scrollTop + 20
		OBJ.style.pixelLeft = widthCenter(OBJ, e)
		OBJ.style.visibility = "visible"
	}
}

function hideLayer(X) {
	if(n4) { 
		document.layers[X].visibility = "hidden"
	}
	else if(e4) {
		document.all[X].style.visibility = "hidden"
	}
}
function runEx() {
	if(n4) var barH = parseInt(document.height/10)
	else if(e4) var barH = parseInt((document.body.scrollTop + document.body.clientHeight)/10)

	for(var i=1; i<11; i++) {
		if(n4) { 
			document.layers["B"+i].visibility = "visible"
			document.layers["B"+i].top = barH * i
		}
		else if(e4) {
			document.all["B"+i].style.visibility = "visible"
			document.all["B"+i].style.top = barH	 * i
		}
	}
}

function Select_visibility(val)
{
	var obj = document.getElementsByName('element_option[]');
	var chk_cnt = obj.length;

	for(i=0;i<chk_cnt;i++)
	{
		if(n4) { 
			obj[i].visibility=val;
		}
		else if(e4) {
			obj[i].style.visibility=val;
		}
	} 

	return;
}


