﻿/**************************************************
파 일 명     :   /Scripts/PageEvent.js
최초작성내역 :  인터데브 정재권(2007년 03월 20일) 
작성목적     :  HTML Page의초기화와 관련된 파일
                            1) 메시지 처리 (Information, ConfirmMessage, ErrorMesasge)
                            2) XML 메시지 처리
                            3) 공통 팝업 처리
                            4) Page Load 이벤트[ PageLoad() ]
                            5) window.onbeforeunload에서 사용하는 이벤트 [ PageBeforeUnLoad() ]
**************************************************/

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  JNU의 도메인을 리턴하기 위한 함수
Parameter :
반환 값   :  string 
*******************************************************/
function GetDomain()
{
    var strDomain = "";
    
	try
	{
        strDomain = window.document.domain;
        
        return strDomain;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}


/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  JNU 작업 디렉터리 Path를 반환하기 위한 함수
Parameter :
반환 값   :  string 
*******************************************************/
function GetJNURootPath()
{
    var strJNURootPath = "";
    
	try
	{
        strJNURootPath = window.document.all.JNURootPath.value;
        
        return strJNURootPath;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}


/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  JNU의 WebCommon 디렉터리 Path를 반환하기 위한 함수
Parameter :
반환 값   :  string 
*******************************************************/
function GetJNUWebCommonPath()
{
    var strJNUWebCommonPath = "";
    
	try
	{
        strJNUWebCommonPath = window.document.all.JNUWebCommonPath.value;
        
        return strJNUWebCommonPath;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :   안내 메시지 창을 띄우기 위한 함수
Parameter :
                     infoMessage : 출력할 메시지(XML 정의 코드, 메시지)
반환 값   : 
사용예    : 
                     OpenInformation("I200");
                     OpenInformation("JNU 점검 시간입니다.|^|점검시간은 2006.1.1.~2006.1.2.까지 입니다.")
*******************************************************/
function OpenInformation(infoMessage)
{

    var strDisplayInfo = "";
	
	try
	{
	    strDisplayInfo = GetXmlMessage(infoMessage);
		window.showModalDialog( GetJNUWebCommonPath() + "/Message/InformationMessage.htm", strDisplayInfo, "dialogWidth:206px;dialogHeight:200px;status=no;scroll=no;center:yes;");
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}

/*******************************************************
작 성 자  :  정원 윤대일(2008년 03월 27일)
작성목적  :   안내 메시지 창을 띄우기 위한 함수(사이즈 지정가능)
Parameter :
                     infoMessage : 출력할 메시지(XML 정의 코드, 메시지)
반환 값   : 
사용예    : 
                     OpenInformation("I200");
                     OpenInformation("JNU 점검 시간입니다.|^|점검시간은 2006.1.1.~2006.1.2.까지 입니다.")
*******************************************************/
function OpenInformationWH(infoMessage, mwidth, mheight)
{
    var strDisplayInfo = "";
	if (!mwidth ) mwidth = "300";
	if (!mheight ) mheight = "250";
	
	
	try
	{
	    strDisplayInfo = GetXmlMessage(infoMessage);
		window.showModalDialog( GetJNUWebCommonPath() + "/Message/HAK_InformationMessage.htm", strDisplayInfo, "dialogWidth:"+ mwidth +"px;dialogHeight:"+ mheight +"px;status=no;scroll=no;center:yes;");
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}


/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :   확인 메시지 창을 띄우기 위한 함수
Parameter :
                     confirmMessage : 출력할 메시지(XML 정의 코드, 메시지)
반환 값   : 
사용예    : 
                    OpenConfirm("C200");
                    OpenConfirm("입력한 모든 자료가 삭제됩니다. 삭제하시겠습니까?")
*******************************************************/
function OpenConfirm(confirmMessage)
{
    var strDisplayConfirm = "";
    var bReturn = false; 
    
	try
	{
		var args = new Object();
		args.win = window;
		args.dlgtype= "Q";
		
		strDisplayConfirm = GetXmlMessage(confirmMessage);		
		
		bReturn = window.showModalDialog( GetJNUWebCommonPath() + "/Message/ConfirmMessage.htm", strDisplayConfirm, "dialogWidth:206px;dialogHeight:200px;status=no;scroll=no;center:yes;");
		
		return bReturn;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}

/*******************************************************
작 성 자  :  정원 윤대일(2008년 03월 27일)
작성목적  :   확인 메시지 창을 띄우기 위한 함수 사이즈 조절 가능
Parameter :
                     confirmMessage : 출력할 메시지(XML 정의 코드, 메시지)
반환 값   : 
사용예    : 
                    OpenConfirm("C200");
                    OpenConfirm("입력한 모든 자료가 삭제됩니다. 삭제하시겠습니까?")
*******************************************************/
function OpenConfirmWH(confirmMessage, mwidth, mheight)
{
    var strDisplayConfirm = "";
    var bReturn = false; 

    if (!mwidth ) mwidth = "300";
	if (!mheight ) mheight = "250";

	try
	{
		var args = new Object();
		args.win = window;
		args.dlgtype= "Q";
		
		strDisplayConfirm = GetXmlMessage(confirmMessage);		
		
		bReturn = window.showModalDialog( GetJNUWebCommonPath() + "/Message/ConfirmMessage.htm", strDisplayConfirm, "dialogWidth:"+ mwidth +"px;dialogHeight:"+ mheight +"px;status=no;scroll=no;center:yes;");
		
		return bReturn;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}
/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :   에러 메시지 창을 띄우는 함수
Parameter :
                     errorMessage : 에러 메시지 (XML Code나 출력할 에러 문자열)
반환 값   : 
사용예    : 
                     OpenErrorMessage("E900");
                     OpenErrorMessage("오류가 발생하였습니다|^|관리자에게 문의하세요");     
*******************************************************/
function OpenErrorMessage(errorMessage)
{
    var strDisplayError = "";
	try
	{
		if(errorMessage == null)
			strDisplayError = window.document.all.errorMessage.value;
		else
			strDisplayError = GetXmlMessage(errorMessage);
		window.showModalDialog( GetJNUWebCommonPath() + "/Message/ErrorMessage.htm", strDisplayError, "dialogWidth:280px;dialogHeight:280px;status=no;scroll=no;center:yes;");
	}
	catch(exception)
	{
		window.alert("오류가 발생하였습니다.\r\n다시 확인해 주세요.");
	}
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  aspx 페이지가 클라이언트에 로딩될 때,
                     메시지 변수를 체크하여 메시지 창을 띄움.
                     페이지가 로딩된 후 최초 이벤트 지정

                     페이지가 언로딩되기 전에 이벤트 지정 
Parameter :
반환 값   : 
사용예    :  WindowOnLoad() 함수는 JNU 개발자가 사용할 수 없는 함수입니다.
*******************************************************/
function WindowOnLoad()
{
    // 페이지 로딩 이미지 생성 
//    if(parent.document.all.div_loading)
//    {
//        parent.document.all.div_loading.style.display ='none';
//    }
    try
   { 
        // 1. 에러 메시지가 있는 경우 팝업 출력
        if ( document.all.errorMessage.value.length > 0 )
            OpenErrorMessage(document.all.errorMessage.value);
    }
    catch (exception)
   {
        alert(exception.description);
   } 
            
    try
   { 
        // 2. 안내 메시지가 있는 경우 팝업 출력
        if ( document.all.informationMessage.value.length > 0 )
            OpenInformation(document.all.informationMessage.value);
    }
    catch (exception)
   {
	    OpenErrorMessage(exception.description);
   } 
            
    try
   { 
        // 3. 확인 메시지가 있는 경우 팝업 출력
        if ( document.all.confirmMessage.value.length > 0 )
        return OpenConfirm(document.all.confirmMessage.value);
    }
    catch (exception)
   {
	    OpenErrorMessage(exception.description);
   } 

	
//	try
//	{
//		// 4. TextBox 이외는 백스페이스 입력을 제한
//		document.onkeydown = PreventNavigateBack;
//	}
//	catch (exception) 
//	{ 
//	    alert(exception.description);
//    }
	
	try
	{
		// 5. 화면을 닫기 전 처리할 함수 지정

		window.onbeforeunload = ClosingCheck;
	}
	catch (exception)
	{
	    OpenErrorMessage(exception.description);
	}
	
    try
	{
	    // 6. 페이지 초기에 로딩시 사용되는 함수 호출(PageLoad())
		PageLoad();
	}
	catch (exception)
	{
	}
	
	try
	{
        // 7. 오른쪽 마우스 버튼 금지	
        //document.onmousedown =  PreventRightMouse
         
        document.oncontextmenu = function (e) { 
           return false;
          }
	}
	catch (exception)
	{
	    alert(exception.description);	
	}
	
	// 8. 상태바 Text 변경

	window.status = "";		
	
	// 9. 각종 환경 설정	
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  팝업 aspx 페이지가 클라이언트에 로딩될 때,
                     메시지 변수를 체크하여 메시지 창을 띄움.
                     페이지가 로딩된 후 최초 이벤트 지정
                     페이지가 언로딩되기 전에 이벤트 지정

Parameter :
반환 값   : 
사용예    :  PopupWindowOnLoad() 함수는 JNU 개발자가 사용할 수 없는 함수입니다.
*******************************************************/
function PopupWindowOnLoad()
{
    try
   { 
        // 1. 에러 메시지가 있는 경우 팝업 출력
        if ( document.all.errorMessage.value.length > 0 )
            OpenErrorMessage(document.all.errorMessage.value);
    }
    catch (exception)
   {
        alert(exception.description);
   } 
            
    try
   { 
        // 2. 안내 메시지가 있는 경우 팝업 출력
        if ( document.all.informationMessage.value.length > 0 )
            OpenInformation(document.all.informationMessage.value);
    }
    catch (exception)
   {
	    OpenErrorMessage(exception.description);
   } 
            
    try
   { 
        // 3. 확인 메시지가 있는 경우 팝업 출력
        if ( document.all.confirmMessage.value.length > 0 )
        return OpenConfirm(document.all.confirmMessage.value);
    }
    catch (exception)
   {
	    OpenErrorMessage(exception.description);
   } 

	var strClose = "";        
	try
	{
		// 4. 팝업창 자동으로 닫기
		strClose = document.all.winClosed.value;
		
		if ( strClose == "closed" )
		{
			if ( document.all.winClosed.getAttribute("return").length > 0 )
					window.returnValue = document.all.winClosed.getAttribute("return");
			window.close();
			return;
		}
	}
	catch (exception) 
	{ 
	    OpenErrorMessage(exception.description);
    }
	
//	try
//	{
//		// 5. TextBox 이외는 백스페이스 입력을 제한
//		document.onkeydown = PreventNavigateBack;
//	}
//	catch (exception) 
//	{ 
//	    alert(exception.description);
//    }
	
	try
	{
		// 6. 화면을 닫기 전 처리할 함수 지정

		window.onbeforeunload = ClosingCheck;
	}
	catch (exception)
	{
	    OpenErrorMessage(exception.description);
	}
	
    try
	{
	    // 7. 페이지 초기에 로딩시 사용되는 함수 호출(PageLoad())
		PageLoad();
	}
	catch (exception)
	{
	}
	
	try
	{
        // 8. 오른쪽 마우스 버튼 금지	
        //document.onmousedown =  PreventRightMouse
	}
	catch (exception)
	{
	    alert(exception.description);	
	}
	
	// 9. 상태바 Text 변경

	window.status = "";		
	
	// 10. 각종 환경 설정	
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  Text 박스외에 BackSpace 입력을 제한
Parameter   :
반환 값   : 
사용예    :  
*******************************************************/
function 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" || strTagType == "PASSWORD" || strTagType == "FILE" )
				return;
		}
		else if ( window.event.srcElement.tagName.toUpperCase() == "TEXTAREA" )
			return;
		else	
			window.event.returnValue = false;
	}
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  윈도우의 닫기 버튼을 클릭시 메시지를 출력하기 위한 함수
Parameter :
반환 값   : 
사용예    :  ClosingCheck() 함수는 JNU 개발자가 사용할 수 없는 함수입니다.
*******************************************************/
function ClosingCheck()
{
    var strMsg = "";
    
	try
	{
		strMsg = PageBeforeUnLoad();
		
		if ( strMsg.length > 0 )
		{
			strMsg = "\n" + strMsg;
			return strMsg;
		}
	}
	catch ( exception )
	{
	}
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  XML 파일에서 사용자가 입력한 코드의 메시지를 반환하는 함수
Parameter   :
                     messageCode : XML에서 정의된 Code
반환 값   :  string (XML 코드의 메세지)
사용예    :  GetXmlMessage() 함수는 JNU 개발자는 사용할 수 없는 함수입니다.
*******************************************************/
function GetXmlMessage(messageCode)
{
    var strCheckCode = messageCode     
    var strXmlMessage  = messageCode ;
    var xmlUrl = "";
    var arrTemp; 
    var oXmlDoc, xmlQuery, messageNode;
    var bFlag = false;
    var bCheckMessage = false;  
    var strReturn =  messageCode;
  
	try
	{
	   if ( messageCode.indexOf(PARAMETER_SEPARATOR) > -1)
        {
                arrTemp = messageCode.split(PARAMETER_SEPARATOR);
                strCheckCode = arrTemp[0];
                bFlag = true;
        }
   
		if ((/[a-zA-Z_]{1,1}\d{3,3}$/.test(strCheckCode)))
		{
			 xmlUrl =  GetJNUWebCommonPath()  + "/xml/JNU.ARSAM.Message.xml";
			
			var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			
			xmlDoc.async = "false";
			xmlDoc.load(xmlUrl);
				
			if(xmlDoc.readyState != 4 && !xmlDoc.parseError)
			{
				OpenErrorMessage("XML 파일 로딩시 에러가 발생하였습니다.");
				return strXmlMessage;
			}
			
			oXmlDoc = xmlDoc.documentElement;
			xmlQuery = "//message[@code='" + strCheckCode + "'][@display_yn='Y']";
			messageNode = oXmlDoc.selectSingleNode(xmlQuery);
			
			if ( messageNode != null )
				strXmlMessage = messageNode.text;
				
		    bCheckMessage = true;
		}
		
		if (bFlag && bCheckMessage)
		    strReturn = strXmlMessage + PARAMETER_SEPARATOR +arrTemp[1];
		    
		if (!bFlag && bCheckMessage)
		    strReturn = strXmlMessage;
		
		return strReturn;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  오른쪽 마우스의 버튼 클릭 이벤트를 막는 함수
Parameter   :
반환 값   :  
사용예    :  document.onmousedown = PreventRightMouse;
*******************************************************/
function PreventRightMouse()
{
   if(((navigator.appName=="Microsoft Internet Explorer")&&(event.button > 1)) ||
        ((navigator.appName=="Netscape")&&(event.button> 1)))
    {
        alert("오른쪽 마우스 버튼은 사용할 수 없습니다.");
        return false;
   }
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  모달리스창을 띄우는 함수
Parameter :
                     url : 오픈 창으로 띄울 URL
                     frame : 오픈창을 띄울 Frame 명
                     feature : 오픈 창의 웹 브라우저의 모양
반환 값   :  
사용예    :  OpenDialog("http://www.maf.go.kr/",  null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");  
*******************************************************/
function OpenDialog(url, frame, feature)
{
	return window.open(url, frame, feature);	
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  모달창을 띄우는 함수
Parameter :
                     url : 오픈 창으로 띄울 URL
                     feature : 오픈 창의 웹 브라우저의 모양
반환 값   :  object(모달창에서 전달받은 개체)
사용예    :  OpenModalDialog("http://www.maf.go.kr/", "dialogHeight: 300px; dialogWidth: 250px; dialogTop: 200px; dialogLeft: 150px; help: Yes; resizable: Yes; status: Yes;");
*******************************************************/
function OpenModalDialog(url, feature)
{
    var strReturn = "";
    
	try
	{
		strReturn = window.showModalDialog( GetJNUWebCommonPath() + "/Message/ModalDialog.html", url, feature);
		
		return strReturn;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}


/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  달력창을 띄우는 함수
Parameter :
 반환 값  :  string (2005-12-25 과 같은 날짜 형식의 문자열)
사용예    :  OpenModalCalendar();
*******************************************************/
function OpenModalCalendar()
{
    var strReturn = ""; 

	try
	{
		strReturn = window.showModalDialog( GetJNUWebCommonPath() + "/Message/ModalCalendar.html", window, "px;dialogWidth:260px;dialogHeight:274px;status:no;help:no;scroll:no;center:yes;");
	
	    if (strReturn == null) 
	        return "";
	    if (strReturn.length == 10)
            return strReturn;
	}
	catch ( exception )
	{
		OpenErrorMessage(exception.description);
	}
}

/*******************************************************
작 성 자  :  정원 윤대일(2008년 04월 17일)
작성목적  :  지정일 체크 후 달력창을 띄우는 함수
Parameter :
 반환 값  :  string (2005-12-25 과 같은 날짜 형식의 문자열)
사용예    :  OpenModalCalendar();
*******************************************************/
function OpenModalCalendar1(parameter)
{
    var strReturn = ""; 

	try
	{
		strReturn = window.showModalDialog(GetJNUWebCommonPath() + "/Message/HAK_ModalCalendar.html", [window, parameter], "px;dialogWidth:260px;dialogHeight:274px;status:no;help:no;scroll:no;center:yes;");
	
	    if (strReturn == null || strReturn == '') 
	        return "";
	    if (strReturn.length == 10)
            return strReturn;
	}
	catch ( exception )
	{
		OpenErrorMessage(exception.description);
	}
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  팝업을 띄울 때 공통으로 사용하는 모달창 호출 함수
                     팝업창에서 받은 Data를 각 컨트롤의 Value값으로 설정
Parameter :
                     url (string 팝업에 출력될 URL)
                     objList (object :  컨트롤명 + '|^|' 을 조합한 형태)
                     feature (string : 모달창의 화면)
반환 값   :  
사용예    :  
                    var strURL =  GetJNURootPath()+ '/PopupSample.aspx';
                    var objList = 'txtName|^|txtArea'; // objList는 '컨트롤명|^|컨트롤명' 형태로 조합
                    var strFeature = 'dialogWidth:550px;dialogHeight:370px;status:no;help:no;';
                    OpenCommonPopup(strURL, objList, strFeature)
*******************************************************/
function OpenCommonPopup(url, objList, feature)
{	
	var objArr = new Array();
	var returnValue ;
	var iCheck = -1;
    var strParameter = "&";		
    var strFullURL ;
	
	try
	{
	    objArr = objList.split(PARAMETER_SEPARATOR);

	     iCheck = url.indexOf("?");
    	
	    if (iCheck == -1)
		    strParameter = "?";

	    for(i=0 ; i<objArr.length ; i++)
	    {
		    var controlObject = eval("document.all."+objArr[i]);
		    strParameter = strParameter+ objArr[i] + "=" + controlObject.value+ "&";
	    }
    	
	    strFullURL = url + strParameter;
    			
	     returnValue = window.showModalDialog( GetJNUWebCommonPath() + "/Message/ModalDialog.html", strFullURL, feature);		
    	
	    if(returnValue != null)
	    {	
		    var valueArr = new Array();
		    valueArr = returnValue.split(PARAMETER_SEPARATOR);

		    for(i=0;i<(objArr.length);i++)
		    {  
			    var obj = eval("window.document.all." + objArr[i])
			    obj.value = valueArr[i];
		    }
	    }
	}
	catch (exception)
	{
		OpenErrorMessage(exception.description);	
		//alert("공통 팝업을 띄우는 중 오류가 발생하였습니다.");
	}
}

/*******************************************************
작 성 자  :  인터데브 정재권(2007년 03월 20일)
작성목적  :  팝업을 띄울 때 공통으로 사용하는 모달창 호출 함수
                     리턴되는 값을 개발자가 직접 작업 가능

Parameter :
                     url (string : 팝업에 출력될 URL)
                     feature (string : 모달창의 화면)
반환 값   :  
사용예    :  
                     var strURL =  GetJNURootPath()+ '/PopupSample.aspx';
                     var sFeature = 'dialogWidth:550px;dialogHeight:370px;status:no;help:no;';
                     OpenCommonPopup(strURL, strFeature)
*******************************************************/
function OpenCommonPopupFullValue(url, feature)
{	
	var strReturn = "";
	try
	{
		strReturn = window.showModalDialog( GetJNUWebCommonPath() + "/Message/ModalDialog.html", url, feature);			
			
		return strReturn;
	}
	catch ( exception )
	{
	    OpenErrorMessage(exception.description);
		//alert("공통 팝업을 띄우는 중 오류가 발생하였습니다.");
	}
}


/*******************************************************
작 성 자  :  정원 윤대일(2008년 04월 19일)
작성목적  :   특정메세지 출력
Parameter :
                     confirmMessage : 출력할 메시지(XML 정의 코드, 메시지)
반환 값   : 
사용예    : 
                    
*******************************************************/
function OpenAlert(confirmMessage)
{
    var strDisplayConfirm = "";
    var bReturn = false; 
    
	try
	{
		var args = new Object();
		args.win = window;
		args.dlgtype= "Q";
		
		strDisplayConfirm = GetXmlMessage(confirmMessage);		
		
		bReturn = window.showModalDialog( GetJNUWebCommonPath() + "/Message/HAK_Message.htm", strDisplayConfirm, "dialogWidth:505px;dialogHeight:350px;status=no;scroll=no;center:yes;");
		
		return bReturn;
	}
	catch(exception)
	{
		OpenErrorMessage(exception.description);
	}
}
