﻿/************************************************************************
파 일 명	: /Scripts/FormEvent.js
작성목적	: 공통 폼 속성 및 이벤트 설정
작 성 자	: 김석숭
최초작성일	: 
수정작성자	: 
*************************************************************************/

/************************************************************************
함수명		: fn_GetWebCommonPath()
작성목적		: WebCommonPath 경로를 반환한다.
작 성 자		: 
최초작성일	: 
최종작성일	:
수정내역		:
*************************************************************************/
var WebCommonPath ="/WebCommon";
function fn_GetWebCommonPath()
{
		var strWebCommonPath = WebCommonPath;
 
		if (strWebCommonPath.length > 0 )
		{
			return strWebCommonPath;
		}
		else 
		{
			return "";
		}
}

/************************************************************************
함수명		: fn_GetReportRootPath()
작성목적		: ReportRootPath 경로를 반환한다.
작 성 자		: 
최초작성일	: 
최종작성일	:
수정내역		:
*************************************************************************/
function fn_GetReportRootPath()
{
	try
	{
		var strReportRootPath = window.document.all.reportRootPath.value;
 
			if (strReportRootPath.length > 0 )
			{
				return strReportRootPath;
			}
			else 
			{
				return "";
			}
	}
	catch(exception)
	{
		alert(exception.description);
	}
}

/************************************************************************
함수명		: fn_OpenErrorMessage
작성목적		: 에러 메시지 상자를 띠운다.
Parameter		:	
						sInfo - 출력할 메시지
						strTemp 는 string이 아님. 속성에 dlgtype, errMessage
Return			:
작 성 자		:
최초작성일	: 
최종작성일	:
수정내역		:
*************************************************************************/
function fn_OpenErrorMessage(strTemp)
{
//	try
//	{
		var strImsi;
		if(strTemp == null)
			strImsi = window.document.all.errorMessage.value;
		else
		    strImsi = strTemp;
		/*	strImsi = fn_XmlMsgT(strTemp);*/
		strImsi = strImsi.toString().replace(/\\n\\n/,"<br><br>").replace(/\\r\\n/,"<br>").replace(/\\n/,"<br>").replace(/\r\n/g,"<br>").replace(/\n/,"<br>");
		window.showModalDialog( fn_GetWebCommonPath() + "/Common/ErrorMessage.htm",strImsi, "dialogWidth:320px;dialogHeight:180px;status=no;scroll=no");
//	}
//	catch(exception)
//	{
//		window.alert("Error ! 팝업설정을 확인하세요.");
//	}
}

/************************************************************************
함수명		: fn_OpenInformation
작성목적		: 작업정보 상자를 띠운다.
Parameter		:	
						sInfo - 출력할 메시지
Return			:

작 성 자		: 
최초작성일	: 
최종작성일	:
수정내역		:
*************************************************************************/
function fn_OpenInformation(sInfo)
{
	var w_width = 305;
	var w_height = 240;
        var brVer   = navigator.userAgent;//브라우져 정보
        var brVerId = brVer.indexOf('MSIE');//브라우져 정보에서 'MSIE'라는 부분의 문자열
        
        brNum   = brVer.substr(brVerId,8);//브라우져 버전('MSIE' 포함..)..
        brNum2  = brNum.substr(5,3)//브라우져 버번. 숫자만..
        
        if(brNum2 > 6.0)
        {
            w_height = w_height - 50;
        }
        
	var strImsi = sInfo;// fn_XmlMsgT(sInfo);
    strImsi = strImsi.toString().replace(/\\n\\n/,"<br><br>").replace(/\\r\\n/,"<br>").replace(/\\n/,"<br>").replace(/\r\n/g,"<br>").replace(/\n/,"<br>");
	try
	{		
		window.showModalDialog( fn_GetWebCommonPath() + "/Common/InformationMessage.htm", strImsi, "dialogWidth:320px;dialogHeight:"+w_height+"px;status=no;scroll=no");
	}
	catch(exception)
	{
		alert(exception.description);
	}
}


/************************************************************************
함수명		: fn_OpenConfirm
작성목적	: 질문 상자를 띠운다.
Parameter :	
					sInfo - 출력할 메시지
Return		:
					"true", "false"
작 성 자	: 
최초작성일	: 
최종작성일	:
수정내역	:
*************************************************************************/
function fn_OpenConfirm(sInfo)
{
	try
	{
	var w_width = 305;
	var w_height = 220;
        var brVer   = navigator.userAgent;//브라우져 정보
        var brVerId = brVer.indexOf('MSIE');//브라우져 정보에서 'MSIE'라는 부분의 문자열
        
        brNum   = brVer.substr(brVerId,8);//브라우져 버전('MSIE' 포함..)..
        brNum2  = brNum.substr(5,3)//브라우져 버번. 숫자만..
        
        if(brNum2 > 6.0)
        {
            w_height = w_height - 50;
        }
        
		var args = new Object();
		args.win = window;
		args.dlgtype= "Q";
		var strImsi = fn_XmlMsgT(sInfo);
		var res = window.showModalDialog( fn_GetWebCommonPath() + "/Common/ConfirmMessage.htm", strImsi,"dialogWidth:305px;dialogHeight:"+w_height+"px;status=no;scroll=no");
		return res;
	}
	catch(exception)
	{
		alert(exception.description);
	}
}


/************************************************************************
함수명		: fn_OpenDialog
작성목적	: 팝업창을 띠운다.
Parameter :	
				sUrl - 띠울 URL
				sFrame - 띠울 Frame
				sFeature - 창 속성
Return		:

작 성 자	: 
최초작성일	: 
최종작성일	:
수정내역	:
*************************************************************************/
function fn_OpenDialog(sUrl, sFrame, sFeature)
{
	return window.open(sUrl, sFrame, sFeature);	
}

/************************************************************************
함수명		: fn_OpenModalDialog
작성목적		: 팝업창을 띠운다.
Parameter		:	
					sUrl - 띠울 URL
					sFeature - 창 속성
Return			:
작 성 자		: 
최초작성일	: 
최종작성일	:
수정내역		:
*************************************************************************/
function fn_OpenModalDialog(sUrl, sFeature)
{
	try
	{
		var strReturn = "";
		strReturn = window.showModalDialog("/WebCommon/Common/ModalDialog.html", sUrl, sFeature);
		return strReturn;
	}
	catch(exception)
	{
		alert(exception.description);
	}
}

/************************************************************************
함수명		: fn_OpenModalCalendar
작성목적		: 파라메터로 지정한 위치에 모달 카렌더를 띠운다.
Parameter		:	
						oCtrl - 선택된 날짜가 리턴될 컨트롤 이름
						posTop, posLeft = 위치
Return			:	
						날짜 ( YYYY-MM-DD )

*************************************************************************/
function fn_OpenModalCalendar(posTop, posLeft)
{
	try
	{
		var strReturn = window.showModalDialog( fn_GetWebCommonPath() + "/Common/ModalCalendar.html", window, "px;dialogWidth:255px;dialogHeight:283px;status:no;help:no;scroll:no");

		if (strReturn == null)
			return "";
		else
			return strReturn;
		
	}
	catch ( exception )
	{
		return "";
	}
}

/************************************************************************
함수명		: fn_WindowOnLoad
작성목적		: 화면 처리 ASPX가 클라이언트에 Load된 후 실행해야 될 로직 처리
작 성 자		: 
최초작성일	: 
최종작성일	:
수정내역		:
*************************************************************************/

/*###################################################################################*/
// Enter Postback 을 막을 지 여부를 체크 하기 위하여
// javascript 변수를 하나 생성...
var fPreventEnterPostBack = true;
/*#####################################################################################*/
function fn_WindowOnLoad()
{
	// 6. 사용자 정의 폼 로드 함수 호출
	try
	{
		FormLoad();
	}
	catch (exception)
	{
	}
		
	// 7. 각종 환경 설정
	
	// 8. 상태바 Text 변경

	window.status = "";
}

/************************************************************************
함수명		: fn_ClosingCheck
작성목적		: Window_OnUnLoad 이벤트 발생전에 발생되는 이벤트, 페이지 닫기 취소를 할 수 있다.
					  OnBeforeUnLoad 이벤트에 별도의 이벤트 핸들러를 연결하여 처리한다.
작성	예			: window.onbeforeunload = fn_ClosingChecker;
작 성 자		: 
최초작성일	: 
최종작성일	:
수정내역	:
*************************************************************************/
function fn_ClosingCheck()
{
	try
	{
		var strMsg = FormBeforeUnLoad();
		
		if ( strMsg.length > 0 )
		{
			strMsg = "\n" + strMsg;
			return strMsg;
		}
	}
	catch ( exception )
	{
	}
}

/************************************************************************
함수명			: fn_PreventHistoryBack
작성목적		: 텍스트 박스 이외는 backspace 입력을 제한한다.
작 성 자		: 
최초작성일	: 
최종작성일	:
수정작성일	: 

*************************************************************************/
function fn_PreventNavigateBack()
{
	//alert(window.event.keyCode)
	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;		
	}
	// Enter Key 포스트 백 처리 .. 2005.09.10
	
	if( window.event.keyCode == 13 &&  fPreventEnterPostBack )
	{
		if ( window.event.srcElement.tagName.toUpperCase() == "INPUT" )
		{
			strTagType = window.event.srcElement.getAttribute("type").toUpperCase();
			if ( strTagType == "TEXT" || strTagType == "CHECKBOX" || strTagType == "PASSSWORD" )
				window.event.keyCode = 9;
			else if(strTagType == "FILE")
				return false;
			else
				return;
		}
//		else	
//			window.event.returnValue = false;
	}
}

/************************************************************************
함수명			: fn_PreventRightMouse
작성목적		: 오른쪽 마우스 이벤트를 막는다.
작 성 자		: 
최초작성일	: 
최종작성일	:
수정내역		:
*************************************************************************/
function fn_PreventRightMouse()
{
	//window.event.returnValue = false;	
}

/************************************************************************
함수명			: fn_OpenCommonPopup
작성목적		: 공통 팝업을 띄운 후 리턴값을 받아 해당 html컨트롤에 값을 넣어준다.
작 성 자		: 
최초작성일	:
1차수정일		:
수정내역		: 파라미터가 넘어온 경우에 따라 ? 와 & 문자 선택  로직 추가
*************************************************************************/
function fn_OpenCommonPopup(objList,strUrl,w_width,w_height)
{	
	var objArr = new Array();
	objArr = objList.split("|^|");

	var findStr = strUrl.indexOf("?");
	
	if (findStr == -1)
		var strArg = "?";
	else
		var strArg = "&";
		
    for(i=0 ; i<objArr.length ; i++)
	{
		var vobj = eval("document.all."+objArr[i]);
		strArg = strArg+ objArr[i] + "=" + vobj.value+ "&";
	}
	strUrl = strUrl + strArg;
	
	if(w_width==null)w_width = 330;
	    if(w_height==null)w_height = 280;
        var brVer   = navigator.userAgent;//브라우져 정보
        var brVerId = brVer.indexOf('MSIE');//브라우져 정보에서 'MSIE'라는 부분의 문자열
        
        brNum   = brVer.substr(brVerId,8);//브라우져 버전('MSIE' 포함..)..
        brNum2  = brNum.substr(5,3)//브라우져 버번. 숫자만..
        
        if(brNum2 > 6.0)
        {
            w_height = w_height - 50;
        }
	var returnValue = window.showModalDialog( fn_GetWebCommonPath() + "/Common/ModalDialog.html", strUrl, "dialogWidth:"+w_width+"px;dialogHeight:"+w_height+"px;status=no;scroll=no");		
	
	if(returnValue != undefined)
	{	
		var valueArr = new Array();
		valueArr = returnValue.split("|^|");

		for(i=0;i<(objArr.length);i++)
		{  
			var obj = eval("window.document.all." + objArr[i])
			obj.value = valueArr[i];
		}
	}

}

/************************************************************************
함수명			: fn_OpenCommonPopupValue
작성목적		: 공통 팝업을 띄운 후 리턴값을 받아 해당 html컨트롤에 값을 넣어준다.
작 성 자		: 
최초작성일	: 
수정작성일	: 
수정내역		: 파라미터가 넘어온 경우에 따라 ? 와 & 문자 선택  로직 추가
*************************************************************************/
function fn_OpenCommonPopupValue(strUrl,sFeature,w_width,w_height)
{	
	try
	{
		if(w_width==null)w_width = 330;
	    if(w_height==null)w_height = 280;
        var brVer   = navigator.userAgent;//브라우져 정보
        var brVerId = brVer.indexOf('MSIE');//브라우져 정보에서 'MSIE'라는 부분의 문자열
        
        brNum   = brVer.substr(brVerId,8);//브라우져 버전('MSIE' 포함..)..
        brNum2  = brNum.substr(5,3)//브라우져 버번. 숫자만..
        
        if(brNum2 > 6.0)
        {
            w_height = w_height - 50;
        }
        
		var strReturn = window.showModalDialog( fn_GetWebCommonPath() + "/Common/ModalDialog.html", strUrl, "dialogWidth:"+w_width+"px;dialogHeight:"+w_height+"px;status=no;scroll=no");				

		if (strReturn == null)
			return "";
		else
			return strReturn;
	}
	catch ( exception )
	{
		return "";
	}

}



/************************************************************************
함수명			: fn_XmlMsgT
Parameter 	:
						messageID : string (XML error Number)
작성목적		: 메시지 XML 함수에서 정의한 메시지 Return
작 성 자			: 
최초작성일		: 
최종작성일		:
수정내역		:
		1.	정규식 [a-zA-Z_]{3,3}\d{3,3}$에서 [a-zA-Z]{2}[a-zA-Z_]\d{3}$으로 수정
*************************************************************************/
 
function fn_XmlMsgT(messageID)
{
	var regBool = false; 
	var xmlMsg  = messageID ;
	
	try
	{
	
		if (!(/[a-zA-Z_]{2,2}[a-zA-Z_]{1,1}\d{3,3}$/.test(messageID)))
		{
			regBool = false; 
		}
		else
		{
			regBool = true; 
		}
	

		if (regBool)
		{
		
			var XmlUrl = "/WebCommon/xml/Neo.Message.xml";
			
			var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.load(XmlUrl);
				
			if(xmlDoc.readyState != 4 && !xmlDoc.parseError)
			{
				alert("Error Retry!!");
				return xmlMsg;
			}
			
			var oXmlDoc = xmlDoc.documentElement;
			var strXQry = "//message[@code='" + messageID + "'][@display_yn='Y']";
			var msgNode = oXmlDoc.selectSingleNode(strXQry);
			if ( msgNode != null )
				xmlMsg = msgNode.text;
		}
		
		return xmlMsg;
	}
	catch(exception)
	{
		alert(exception.description);
	}
}

/************************************************************************
함수명			: fn_OpenExcelSaveDialog
Parameter 	:
				
작성목적		: ExcelUpload 공통 팝업을 띄우는 함수
작 성 자			:
최초작성일		: 
최종작성일		:
수정내역		:
*************************************************************************/
 
function fn_OpenExcelSaveDialog()
{
	var sUrl = "/WebCommon/POPUP/Common/ExcelSave_Pop.aspx";
	var feature = "dialogWidth:405px;dialogHeight:200px;status=no;scroll=no";
	var strReturn = "";
	strReturn = window.showModalDialog( fn_GetWebCommonPath() + "/Common/ModalDialog.html", sUrl, feature);
	if(strReturn == undefined)strReturn = "";
	return strReturn;
}

/************************************************************************
함수명			: fn_ExportTypeSelect
Parameter 	:
				
작성목적		: 그리드의 출력형식(Excel , Tab 구분자)을 선택하기 위한 팝업.
*************************************************************************/

function fn_OpenExportTypeSelect()
{
		var strReturn = "";
		var feature = "dialogWidth:405px;dialogHeight:150px;status=no;scroll=no";
		var sUrl = "ExportTypeSelect.htm";
		strReturn = window.showModalDialog( fn_GetWebCommonPath() + "/Common/ModalDialog.html", sUrl, feature);
		
		if(strReturn == null || strReturn == "")
		{
			return false;
		}
		else
		{
			document.all.htxtExportType.value = strReturn;
		}
		
}
