﻿//공통 폼 속성 및 이벤트 설정 (주)닷넷소프트 유승호

//화면 처리 ASPX가 클라이언트에 Load된 후 실행해야 될 로직 처리
function fn_WindowOnLoad()
{
	try
	{
		try
		{
			if ( document.all.errorMessage.value.length > 0 )// 1. 에러 메시지가 있는 경우 팝업 출력
				fn_OpenErrorMessage(document.all.errorMessage.value);
			if ( document.all.informationMessage.value.length > 0 )// 2. Information이 있는 경우 팝업 출력
				fn_OpenInformation(document.all.informationMessage.value);
			if ( document.all.confirmMessage.value.length > 0 )// 3. Confirm이 있는 경우 팝업 출력
				return fn_OpenConfirm(document.all.confirmMessage.value);
			var strClose = ""
			strClose = document.all.winClosed.value;
			if ( strClose == "closed" )// 4. 팝업창 닫기
			{
				if ( document.all.winClosed.getAttribute("return").length > 0 )
						window.returnValue = document.all.winClosed.getAttribute("return");
				//top.window.close();
				parent.self.close();
				return;
			}
			document.onkeydown = fn_PreventNavigateBack;// 5. 백스페이스로 이전 페이지로 가는 것을 막는다.
		}
		catch ( exception ){}
		
		try
		{
			// 7. 폼 Unload 확인
			document.body.onbeforeunload = fn_ClosingCheck;
			window.onbeforeprint = beforePrint;
			window.onafterprint = afterPrint;

			// 8. 사용자 정의 폼 로드 함수 호출
			try
			{
    			FormLoad();
			}
			catch(e){}

			try
			{
				//포틀릿이 있다면, 포틀릿초기화
				DotNetSoft_PortletInitialize();
			}
			catch(e){}

			ClientRedirect();
			
		}
		catch(exception){} 
	}
	catch(exception)
	{
		fn_Progressbar(false);
	}
	finally
	{
		fn_Progressbar(false);
	}
}
window.onload = fn_WindowOnLoad;

//Window_OnUnLoad 이벤트 발생전에 발생되는 이벤트, 페이지 닫기 취소를 할 수 있다.
//		  OnBeforeUnLoad 이벤트에 별도의 이벤트 핸들러를 연결하여 처리한다.
//		  ex) window.onbeforeunload = fnClosingChecker;
function fn_ClosingCheck()
{
	try
	{
		var strMsg = FormBeforeUnLoad();
		
		if ( strMsg.length > 0 )
		{
			strMsg = "\n" + strMsg;
			return strMsg;
		}
	}
	catch ( exception ){}
}

//텍스트 박스 이외는 backspace 입력을 제한한다.
function fn_PreventNavigateBack()
{
	var strTagType;
	if ( window.event.keyCode == 8 )
	{
		if ( window.event.srcElement.tagName.toUpperCase() == "INPUT" )
		{
			strTagType = window.event.srcElement.getAttribute("type").toUpperCase();
			if ( strTagType == "TEXT")
			{
				window.event.returnValue = true;
				return;
			}
		}
		else if( window.event.srcElement.tagName.toUpperCase() == "TEXTAREA" )
		{
			window.event.returnValue = true;
			return;
		}
	}
	else
	{
		window.event.returnValue = true;
	}
	
}

//커서셋팅
function fn_SetCursor(toggle)
{
	var oTemp = document.body;
	if(toggle)
	{
		oTemp.style.cursor = "wait";
	}
	else
	{
		oTemp.style.cursor = "default";
	}
}

//그리드에서 LinkCell에 마우스 올렸을때, TR에 스타일 지정하기
function fn_GridLinkCellStyleMouseOver(oThis,strTemp)
{
	var oTemp;
	oTemp = oThis;
	for(i = 0 ; i < 10 ; i++)
	{	
		oTemp = oTemp.parentElement;
		if(oTemp.tagName.toUpperCase() == 'TR')
		{
			oTemp.className = strTemp;
			return;
		}
	}
}

//프린트 하기전에 설정
function beforePrint()
{
	var i = 0 ; 
	for(i = 0 ; i < document.all.length ; i++)
	{
		if(document.all[i].pntOption != null)
		{
			if(document.all[i].pntOption == "true")
			{
				document.all[i].style.display = "inline";					
			}
			else 
			{
				document.all[i].style.display = "none";					
			}
		}
	}
}

//프린트 한후에 설정
function afterPrint()
{
	var i = 0 ; 
	for(i = 0 ; i < document.all.length ; i++)
	{
		if(document.all[i].pntOption != null)
		{
			if(document.all[i].pntOption == "false")
			{
				document.all[i].style.display = "inline";					
			}
			else
			{
				document.all[i].style.display = "none";					
			}
		}
	}
}