//----------------------------------------------------------
// 본 스크립트의 기능을 이용하기 위해서는 스크립트가 적용될 jsp 페이지에
// <div id="screenMask" style="position:absolute;z-index:100;"></div> 
// 를 반드시 추가해야만 한다.
//----------------------------------------------------------

var gScreenMask = null;
var gMaskIsShown = false;
var gHideSelect = false;
var gDivObject = null;
var gDivObjectIsShown = false;

function addEvents(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}

function maskScreen()
{
	gScreenMask = document.getElementById("screenMask");	
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) gHideSelect = true;	
	gMaskIsShown = true;
	centerScreen();
	gScreenMask.style.display = "block";
	if (gHideSelect == true) hideSelectBox();
	
	addEvents(window, "resize", centerScreen);
	addEvents(window, "scroll", centerScreen);
	
}

function unmaskScreen()
{
	gScreenMask = document.getElementById("screenMask");	
	gMaskIsShown = false;
	gDivObjectIsShown = false;
		
	if (gScreenMask == null) return;	
	gScreenMask.style.display = "none";	
	if (gHideSelect == true) displaySelectBox();
	
}

function centerScreen()
{
	var fullHeight = getScreenHeight();
	var fullWidth = getScreenWidth();

	var theBody = document.documentElement;

	var scTop
	
	if (document.documentElement && document.documentElement.scrollTop)
	{
		scTop = parseInt(theBody.scrollTop,10);
	}
	else if (document.body)
	{
		scTop = parseInt(document.body.scrollTop,10)
	}
	else
	{
		scTop = parseInt(theBody.scrollTop,10);
	}

	var scLeft = parseInt(theBody.scrollLeft,10);				
	
	gScreenMask.style.height = fullHeight + "px";
	gScreenMask.style.width = fullWidth + "px";
	gScreenMask.style.top = scTop + "px";
	gScreenMask.style.left = scLeft + "px";
	
	if(gDivObject != null && gDivObjectIsShown)
	{
		var width = gDivObject.style.width;
		var height = gDivObject.style.height;
		
		if(height <fullHeight)
		{
			gDivObject.style.top = (scTop + ((fullHeight - height) / 2)) + "px";
		}
		else
		{
			gDivObject.style.top = "-5px";
		}
			
		if(width <fullWidth)
		{
			gDivObject.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
		}
		else
		{
			gDivObject.style.left =  "-2px";				
		}
	}
}

function centerDiv(divId)
{
	var fullHeight = getScreenHeight();
	var fullWidth = getScreenWidth();

	var theBody = document.documentElement;

	var scTop
	
	if (document.documentElement && document.documentElement.scrollTop)
	{
		scTop = parseInt(theBody.scrollTop,10);
	}
	else if (document.body)
	{
		scTop = parseInt(document.body.scrollTop,10)
	}
	else
	{
		scTop = parseInt(theBody.scrollTop,10);
	}

	var scLeft = parseInt(theBody.scrollLeft,10);				
	
	gDivObject = document.getElementById(divId);
	var width = gDivObject.style.width;
	var height = gDivObject.style.height;
	
	if(height <fullHeight)
	{
		gDivObject.style.top = (scTop + ((fullHeight - height) / 2)) + "px";
	}
	else
	{
		gDivObject.style.top = "-5px";
	}
		
	if(width <fullWidth)
	{
		gDivObject.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
	}
	else
	{
		gDivObject.style.left =  "-2px";				
	}
	
	gDivObjectIsShown = true;
}



function getScreenHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}

function getScreenWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}


function hideSelectBox() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
	
}

function displaySelectBox() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}
