/*** * * System Global Function * common.jsp의 함수는 함수 앞에 common을 붙임. * 함수는 [ 동사(소문자로 시작)+명사(대문자로 시작)]으로 명명. ex}common_calendar() * 전역변수는[ common_변수명 ] 으로 명명. ex)common_trStatus * 함수내에 선언된 것은 prefix 없이 쓴다. * ***/ var common_divLength = 3; //한글 한자를 1byte로 환산하는 기준 (한글1자 = 3byet) /** * IE 설계변경으로 인한 ActiveX 활성화 함수 * * @param __ELEMENT_ID * @return * * @since 2005. 11. 22(안가희) */ function __ShowEmbedObject(__ELEMENT_ID) { document.write(__ELEMENT_ID.innerHTML); __ELEMENT_ID.id = ""; } /** * 달력을 표시하는 함수(달력을 호출하여 선택된 일자를 EMEdit Object에 담는다. * * @param obj 달력에서 선택된 일자를 보여줄 Object * @return * * @since 2004. 05. 25(전수일) */ function common_calendar(obj) { var result = common_popUpCalendar(); if (result == "") { return; } if(obj.classid == undefined) { obj.value = result; } else if (obj.classid == "CLSID:D7779973-9954-464e-9708-DA774CA50E13") { obj.text = result; } } /** * 달력을 PopUp으로 호출한다. * * @param * @return 달력을 PopUp창으로 반환 * * @since 2004. 05. 25(전수일) */ function common_popUpCalendar() { var s_pos = "dialogWidth:200px; dialogHeight:225px;status:no;help:no;scroll:no"; var s_url = "/app/ems/common/ems_common_calendar.jsp"; var result = window.showModalDialog(s_url, window , s_pos) ; if (result == "" || result == null) result = ""; return result; } /** * Excel Upload용 Cell의 내용을 읽어오는 함수 * VB Script에 return type이 number로도 넘어오는데 * 이때문에 문제가 발생하므로 자바스크립트에서 String형으로 변환하여 준다. * * @param aGrid 그리드 객체(스프레드) * @param aCol 스프레드의 컬럼 * @param aRow 스프레드의 로우 * @return String * * @since 2005. 11. 01(김철현) */ function common_getGridText(aGrid, aCol, aRow){ var returnValue = vb_vbGetGridText(aGrid, aCol, aRow); if (typeof(returnValue) == "number") { returnValue = returnValue.toString(10); } else if (typeof(returnValue) != "string") { returnValue = ""; } return returnValue; } /** * Excel Upload용 저장 다이얼로그 Open * * @return true: 정상 open, false: 취소 버튼 * * @since 2005. 11. 01(김철현) */ function common_commonDialog() { var commonDialog = document.myForm.MSComDlg; var returnValue = true; try { commonDialog.DialogTitle = "Microsoft Excel"; commonDialog.Filter = "Excel(*.xls)|*.xls"; commonDialog.Flags = 4; commonDialog.CancelError = true; //취소버튼 클릭에 대한 처리를 위하여 에러를 발생시킨다. commonDialog.ShowOpen(); } catch(e) { returnValue = false; //취소버튼이 클릭되었으므로 false를 return } finally { return returnValue; } } /** * Excel Upload용 그리드 초기화 * * @param aGrid 그리드 개체(스프레드) * @return * * @since 2005. 11. 01(김철현) */ function common_excelUploadGridInit(aGrid) { aGrid.MaxRows = 0; aGrid.MaxCols = 0; //Sets or returns whether methods and events that are enhanced for scripting environments are enabled aGrid.ScriptEnhanced = true; } //--------------------------파일 업로드 다운로드 관련----------------------------------------------------- /** * 특수파일 확장자 업로드 금지하게 하기 위하여 * * @param fileObj : 첨부파일을 선택하는 파일 객체 * @return true/false * * @since 2005. 08. 01(김철현). */ function common_checkUploadFile(objFile) { //전체 파일경로에서 순수 파일명만 추출한다. var aFilePath = objFile.value.split("\\"); var sFileName = aFilePath[aFilePath.length - 1]; //업로드 제한 화일을 셋팅한다. var uploadDeniedExtensions = "php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi|html|htm"; var aLimitedExt = uploadDeniedExtensions.split("|"); //현재 선택된 파일의 확장자를 구한다. var sFileExt = sFileName.slice(sFileName.indexOf(".") + 1).toLowerCase(); for (var i = 0; i < aLimitedExt.length; i++) { if (aLimitedExt[i] == sFileExt) { alert("확장자가 " + aLimitedExt[i] + "인 파일은 업로드 할수 없습니다."); return false; } } return true; } /** * 파라미터로 넘어온 FORM OBJECT 에 HIDDEN ELEMENT 를 설정한다. * * @param documentObject Document Object * @param formObject Form Object * @param objectName Object Name * @param objectValue Object Value * @return null * * @since 2004. 12. 23(전수일). */ function common_setHiddenElement(documentObject, formObject, objectName, objectValue){ if(formObject[objectName]=="" || formObject[objectName]==undefined){ var objectString = ""; var hiddenElement = documentObject.createElement(objectString); formObject.insertBefore(hiddenElement); } else{ formObject[objectName].value = objectValue; } } //--------------------------파일 업로드 다운로드 관련----------------------------------------------------- /** * 첨부파일을 추가시 multipart로 파일을 첨부하는 기능 * * @param formObj : 해당 페이지의 Form Object * @param fileObj : 첨부파일을 선택하는 파일 객체 * @param tdObjName : 첨부파일 객체가 그려지는 TD Object명 * @return null * * @since 2005. 08. 01(김철현). * @see common#gfn_msgBox(s_msg,s_type) * @see common#gfn_setHiddenElement(documentObject, formObject, objectName, objectValue) * @see common#gfn_GetGV(arg) */ function common_addAppend(formObj, fileObj, tdObjName){ var queryString = ""; if (fileObj.value == ""){ alert("업로드할 파일을 선택하십시오."); fileObj.focus(); return false; } //업로드 금지파일을 체크한다. if (!common_checkUploadFile(fileObj)) { fileObj.focus(); return false; } //파일이 있는 td개체에 insertBefore로 히든 컨트롤을 만드는것으로 처리 넘기는 것으로 한다. document.all[tdObjName] //td개체도 form안에 있으므로 request에서 받을수 있으므로. [김철현] common_setHiddenElement(document, document.all[tdObjName], "fileObjName", fileObj.name); common_setHiddenElement(document, document.all[tdObjName], "tdObjName", tdObjName); formObj.encoding = "multipart/form-data"; formObj.method = "post"; formObj.target = "executeFileFrame"; formObj.action = "/commonIncFile.ds"; formObj.submit(); } /** * 파라미터로 넘어온 FORM OBJECT 에 HIDDEN ELEMENT 를 설정한다. * 동일한 Hidden Name이 존재할경우에도 생성한다. (배열생성을 위해) * * @param documentObject Document Object * @param formObject Form Object * @param objectName Object Name * @param objectValue Object Value * @return null * * @since 2004. 12. 23(전수일). */ function common_removeHiddenElement(removeElementStr) { while(eval(removeElementStr)){ if (eval(removeElementStr)[0]){ eval(removeElementStr)[0].removeNode(true); } else { eval(removeElementStr).removeNode(true); } } } /** * 첨부파일 DownLoad * * @param orgFileName : 첨부한 파일명 * @param sysFileName : 첨부한 파일을 시스템 규칙에 의하여 바꾼 파일명 * @return * * @since 2005. 08. 01(김철현). * @see common#common_setHiddenElement(documentObject, formObject, objectName, objectValue) */ function common_fileDownload(orgFileName, sysFileName){ var commonForm = document.forms[0]; var commonDocument = document; common_setHiddenElement(commonDocument, commonForm, "append_file_nm", encodeURI(orgFileName)); common_setHiddenElement(commonDocument, commonForm, "append_sys_code", sysFileName); commonForm.action = "/commonIncFileDownload.ds"; commonForm.method = "post"; commonForm.target = "executeFileFrame"; commonForm.submit(); } /** * 날짜의 표기를 바꾸는 함수 * * @param sdate : 기준일자 (string : yyyymmdd) * @param stype : 변환형식 (1:yyyy/mm/dd, 2:yyyy-mm-dd, 3:dd/mm/yyyy, 4:mm/dd/yyyy) * @return 날짜의 표기를 변환하여 변환된 형식으로 날짜를 반환 * * @since 2005. 08. 01(김철현). */ function common_DateMask(sdate,stype) { var yy = sdate.substring(0,4); var mm = sdate.substring(4,6); var dd = sdate.substring(6,8); switch (stype) { case 2 : return yy + "-" + mm + "-" + dd; break; case 3 : return dd + "/" + mm + "/" + yy; break; case 4 : return mm + "/" + dd + "/" + yy; break; default : return yy + "/" + mm + "/" + dd; break; } } /** * 이미지 데이터셋을 셋팅한다. * * @param imageDataSet : 이미지데이터셋 Obj * @return null * * @since 2005. 09. 22(전수일). */ function common_setImageDataSet(imageDataSet) { imageDataSet.CacheLoad = true; imageDataSet.SyncLoad = true; imageDataSet.DataID = "/app/ems/common/ems_common_get_image.jsp"; imageDataSet.reset(); imageDataSet.SyncLoad = false; } /** * 이벤트 핸들러를 등록한다. * * dispName : 보여줄 이름 * minValue : 최소값 * maxValue : 최대값 * len : 정해진길이입력의 경우 * notNull : 필수항목 * minLength : 최소길이 * * dataType : 입력폼데이타 타입 * date * dateMonth * email * float * integer * number * zipcode * jumin * saup * corporate * @return null * * @since 2005. 01. 11(전수일). * @since 2005. 02. 28(김철현). radio와 checkbox에서는 색변화를 주지 않도록 수정 * @since 2005. 05. 16(김철현). ReadOnly 항목에 대하여 특정색을 주도록 변경 * @since 2006. 12. 07(김인숙). EMS內 함수에서 backgroudcolor는 지정하지 않고 HTML style sheet처리함. * @see common#common_addColorAtEventObject() * @see common#common_deleteColorAtEventObject() */ function common_setEventHandler(){ for (i = 0; i < document.forms.length; i++) { var elements = document.forms(i).elements; for (j = 0; j < elements.length; j++) { //김철현 추가[2005.05.16] readonly는 색을 틀리게 주기위하여 //EMS內 함수에서 backgroudcolor는 지정하지 않고 HTML style sheet처리함. //if (elements(j).readOnly) elements(j).style.backgroundColor = "#F2F1E3"; //radio나 checkBox일경우엔 색변화를 주지 않도록 처리[김철현] if (elements(j).type == "radio" || elements(j).type == "checkbox") { } else { //elements(j).onblur = common_addColorAtEventObject; //elements(j).onfocus = common_deleteColorAtEventObject; } } } } /** * 배경색을 추가한다. * * @return null * * @since 2005. 01. 11(전수일). */ function common_addColorAtEventObject(){ var obj = window.event.srcElement; common_addColorAtObject(obj); } /** * 배경색을 삭제한다. * * @return null * * @since 2005. 01. 11(전수일). */ function common_deleteColorAtEventObject(){ var obj = window.event.srcElement; common_deleteColorAtObject(obj); } /** * 배경색을 추가한다. * * @param obj Object * @return null * * @since 2005. 01. 11(전수일). * @since 2005. 05. 16(김철현). readonly의 경우 색변화를 주지 않는다. */ function common_addColorAtObject(obj){ if (obj.readOnly) { obj.style.backgroundColor = "#F2F1E3"; } else { obj.style.backgroundColor = ""; } } /** * 데이터 유효성을 체크한다. * * @param form Form Object * @return null * * @since 2005. 01. 11(전수일). */ function common_isValidateAtForm(form) { var obj; var err="";//전체 에러 메시지 var index; for (i = 0; i < form.elements.length; i++) { obj = form.elements(i); if(common_isValidateAtObject(form, obj) != ""){ if(err == "") { index = i; } err = err + common_isValidateAtObject(form, obj); } } if(err != "") { alert(err); form.elements(index).focus(); err=""; return false; } return true; } /** * 데이터 유효성을 체크한다. * 하나의 오브젝트에 대한 것임. * * @param form * @param obj * @return boolean * @since 2004.12. (전수일) * @since 2004.12.27(김철현) Object와 Applet에 대해선 유효성 체크를 하지않도록 수정 * @since 2004.12.27(김철현) **주의 maxLength등 사용자 property에 대해 대소문자 구분함 */ function common_isValidateAtObject(form, obj) { var errorMessage = ""; if (obj.tagName == "APPLET"){ //Tree는 Validate check안함 return true; } var dispName; var dataType; var minValue; var maxValue; var isValid; var value; //EMEdit if(obj.classid == "CLSID:D7779973-9954-464e-9708-DA774CA50E13"){ value = common_trim(obj.text); //LUXE COMBO } else if(obj.classid == "CLSID:BB4533A0-85E0-4657-9BF2-E8E7B100D47E") { return ""; //GRID } else if(obj.classid == "CLSID:71E7ACA0-EF63-4055-9894-229B056E9C31") { return ""; //DATASET } else if(obj.classid == "CLSID:AF989B7C-8AC3-40bc-B749-EB335BDFD190") { return ""; //IMAGE DATASET } else if(obj.classid == "CLSID:9F0AA341-1D10-4b18-B70B-6AA49CE7F5D6") { return ""; //TREE } else if(obj.classid == "CLSID:C1781C5C-0C32-40f2-8927-46FE4BCB5B87") { return ""; //ELEMENT } else { value = common_trim(obj.value); } dispName = obj.getAttribute("dispName"); dataType = obj.getAttribute("dataType"); minValue = obj.getAttribute("minValue"); maxValue = obj.getAttribute("maxValue"); minLength = obj.getAttribute("minLength"); len = obj.getAttribute("len"); if (dispName == null) { dispName = obj.name; } // 필수 입력 항목 체크 if (obj.getAttribute("notNull") != null) { isValid = false; if (obj.type == "radio" || obj.type == "checkbox") { if (form.elements(obj.name).length) { for (j = 0; j < form.elements(obj.name).length; j++) { if (form.elements(obj.name)[j].checked) { isValid = true; break; } } } else { if (obj.checked) { isValid = true; } } } else { if (value != "") { isValid = true; } } if (!isValid) { errorMessage = errorMessage + dispName + "을(를) 입력하십시오.\n"; } } // 데이터 길이 체크 if (len != null) { if (value.length != eval(len)) { errorMessage = errorMessage + dispName + "은(는) " + len + "자리를 입력해야 합니다.\n"; } } // 최소길이 체크 if (minLength != null) { if (value.length < eval(minLength)) { errorMessage = errorMessage + dispName + "은(는) " + minLength + "자리이상 입력해야 합니다.\n"; } } if (obj.type == "text" || obj.type == "textarea") { // 데이터 타입 체크 if (dataType == null) { // 2002.01.30 추가 if (obj.readOnly == false && common_getByteLenght(value) > obj.maxLength) { errorMessage = errorMessage + dispName + " 길이가 " + obj.maxLength + " (한글 " + parseInt(obj.maxLength / 3) + ") 을(를) 넘습니다.\n"; } }else if(dataType == "Number"){//2007.03.09추가 if(!common_isNumber(obj.value)){ errorMessage = errorMessage + dispName + " 숫자가 아닙니다.\n"; } } } //EMEdit일 경우 if (obj.classid == "CLSID:D7779973-9954-464e-9708-DA774CA50E13") { if(obj.dataType == "jumin" && value!="" && obj.format == "999999-9999999") { if(!common_isJumin(value)) { errorMessage = errorMessage + "주민번호 형식이 올바르지 않습니다.\n"; } } if(value!="" && obj.format == "9999-99-99") { if(!common_isDate(value)) { errorMessage = errorMessage + "날짜 형식이 올바르지 않습니다.\n"; } } else if(value!="" && obj.format == "9999-99") { if(!common_isDateMonth(value)) { errorMessage = errorMessage + "날짜 형식이 올바르지 않습니다.\n"; } } else if(value!="" && obj.format == "999-99-99999") { if(!common_isSaup(value)) { errorMessage = errorMessage + "사업자번호 형식이 올바르지 않습니다.\n"; } } if (minValue != null) { if (eval(minValue) > eval(value)) { errorMessage = errorMessage + dispName + " 값은 최소값(" + minValue + ") 이상이여야 합니다.\n"; } } if (maxValue != null) { if (eval(maxValue) < eval(value)) { errorMessage = errorMessage + dispName + " 값이 최대값(" + maxValue + ")을 미만이여야 합니다.\n"; } } } return errorMessage; } /** * 좌우 양쪽의 공백제거 * * @param text * @return String text 에서 좌우공백을 제외한 String * * @since 2005. 01. 11(전수일). */ function common_trim(text) { return common_trimRight(common_trimLeft(text)); } /** * 왼쪽공백제거 * * @param text * @return String text 에서 왼쪽공백을 제외한 String * * @since 2005. 01. 11(전수일). */ function common_trimLeft(text) { if (text == "") { return text; } var len = text.length; var st = 0; while ((st < len) && (text.charAt(st) <= ' ')) { st++; } return (st > 0) ? text.substring(st, len) : text; } /** * 오른쪽공백제거 * * @param text * @return String text 에서 오른쪽공백을 제외한 String * * @since 2005. 01. 11(전수일). */ function common_trimRight(text) { if (text == "") { return text; } var len = text.length; var st = 0; while ((st < len) && (text.charAt(len - 1) <= ' ')) { len--; } return (len < text.length) ? text.substring(st, len) : text; } /** * 날짜 체크 * * @param date Object * @return boolean * * @since 2005. 01. 11(전수일). * 파라미터에 공백을 제거하기 위해 common_rtnMsg으로 공백 처리 추가(2007. 10. 18 김도형) */ function common_isDate(date) { if (date == null || common_rtnMsg(date, " ", "").length != 8) { return false; } var year = eval(date.substring(0, 4)); var month = eval(date.substring(4, 6)); var day = eval(date.substring(6, 8)); if (month < 1 || month > 12) { return false; } var totalDays; switch (eval(month)){ case 1 : totalDays = 31; break; case 2 : if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) totalDays = 29; else totalDays = 28; break; case 3 : totalDays = 31; break; case 4 : totalDays = 30; break; case 5 : totalDays = 31; break; case 6 : totalDays = 30; break; case 7 : totalDays = 31; break; case 8 : totalDays = 31; break; case 9 : totalDays = 30; break; case 10 : totalDays = 31; break; case 11 : totalDays = 30; break; case 12 : totalDays = 31; break; } if (day > totalDays) { return false; } return true; } /** * 문자열의 byte length를 얻는다. * * @param str Byte 길이를 체크할 문자열 * @return str 의 byte 길이 * * @since 2005. 01. 11(전수일). */ function common_getByteLenght(str) { if (str == "") { return 0; } var len = 0; for (var i = 0; i < str.length; i++) { if (str.charCodeAt(i) > 128) { // len++; //한글은 3byte가 적용된다 [2007.01.25 박성남] len=len+2; } len++; } return len; } /** * 날짜[년월] 체크 * * @param date Object * @return boolean * * @since 2005. 01. 11(전수일). */ function common_isDateMonth(date) { if (date == null || common_rtnMsg(date, " ", "").length != 6) { return false; } var year = eval(date.substring(0, 4)); var month = eval(date.substring(4, 6)); if (month < 1 || month > 12) { return false; } return true; } /** * 주민번호에서 "-"를 없앤다. * * @param str String * @return null * * @since 2005. 01. 11(전수일). */ function deleteJuminFormatAtString(str){ var temp = ''; for (var i = 0; i < str.length; i++){ if (str.charAt(i) == '-'){ continue; } else { temp += str.charAt(i); } } return temp; } /** * 주민번호 형식인지 체크 한다. * * @param str 주민등록번호 * @return boolean * * @since 2005. 01. 11(전수일). */ function common_isJumin(str) { str = deleteJuminFormatAtString(str); var tmp = 0; var sex = str.substring(6, 7); var birthday; if (str.length != 13) { return false; } if (sex == 1 || sex == 2) { birthday = "19" + str.substring(0, 6); } else if (sex == 3 || sex == 4) { birthday = "20" + str.substring(0, 6); } else { return false; } if (!common_isDate(birthday)) { return false; } for (var i = 0; i < 12 ; i++) { tmp = tmp + ((i%8+2) * parseInt(str.substring(i,i+1))); } tmp = 11 - (tmp %11); tmp = tmp % 10; if (tmp != str.substring(12, 13)) { return false; } return true; } /** * 오직 숫자로만 이루어져 있는지 체크 한다. * * @param num Numeric * @return boolean * * @since 2005. 01. 11(전수일). */ function common_isNumber(num) { num = common_trimRight(num); if (num.match(/^\b\d+\b$/)) { return true; } return false; } /** * 배경색을 삭제한다. * * @param obj Object * @return null * * @since 2005. 01. 11(전수일). * @since 2005. 05. 16(김철현). readonly의 경우 색변화를 주지 않는다. */ function common_deleteColorAtObject(obj){ if (obj.readOnly) { obj.style.backgroundColor = "#F2F1E3"; } else { obj.style.backgroundColor = "#D5EAEE"; } } /** * 현재일자를 가져오는 함수 * * @param * @return 현재일자를 반환 * * @since 2005. 08. 01(김철현). */ function common_getDate() { var currDate = new Date(); var tmpYy = currDate.getYear(); var yy = (tmpYy > 99) ? tmpYy : 1900 + tmpYy; var tmpMon = currDate.getMonth(); var mon = (tmpMon < 9) ? "0" + (tmpMon + 1) : tmpMon + 1 ; var tmpDay = currDate.getDate(); var day = (tmpDay < 10) ? "0" + tmpDay : tmpDay ; return yy.toString() + mon.toString() + day.toString() ; } /** * 라디오버튼의 선택된 Value 리턴 * * @param radioObj * @return * * @since 2005. 08. 01(김철현). */ function common_getRadioValue(radioObj){ for(var i=0; i= 0){ replaceMsg = replaceMsg + "|"; msgParm = replaceMsg.split("|"); for (var i=0; i < msgParm.length-1; i++) { index = argErrMsg.indexOf("@"); if (index != -1){ index++; argErrMsg = argErrMsg.substring(0, index+1).replace("@",msgParm[i]) + argErrMsg.substring(index+1); } } } if(argLine == undefined){ if (argIndex != undefined && argIndex != "") argErrMsg = argIndex + " LINE : " + argErrMsg; }else{ if (argIndex != undefined && argIndex != "") argErrMsg = argLine + argErrMsg; } errMsg = errMsg + " " + argErrMsg + "\n"; return errMsg; } /** * 지정된 객체의 문자열의 길이를 계산 * * @param str : 문자값 * @return strByte : 문자길이 * * @since 2004. 05. 25(전수일). */ function common_checkByte(str) { var i; var strLen; var strByte; strLen = str.length; for(i=0, strByte=0;i= ' ' && str.charAt(i) <= '~' ) strByte++; else strByte += common_divLength; } return strByte; } /** * comboBox 에서 특정값을 가진 option 을 선택하기(기존 검색 조건의 복구를 위해 사용) * @comboBoxObj Target comboBox name * @optoionValue 선택할 값 * @return null * @since 2006.07.14(황용연) */ function selectComboBoxOption(comboBoxObj,optionValue){ for (var i=0; i < comboBoxObj.length; i++) { if(comboBoxObj[i].value==optionValue){ comboBoxObj[i].selected = true ; } } } /** * CheckBox 에서 특정값을 가진 option 을 선택하기(기존 검색 조건의 복구를 위해 사용) * @CheckBoxObj Target comboBox name * @optoionValue 선택할 값 * @return null */ function common_checkValueByRadio(radioObj,value){ for (var i=0; i < radioObj.length; i++) { if(radioObj[i].value==value){ radioObj[i].checked = true ; } } } /** * 특정값으로 selectbox의 option을 세팅하는 함수 * * @param ObjSelect: document.폼이름.selectbox이름, selectedValue:options와 비교하여 세팅해줄 값. * @return * * @since 2005. 11. 22(안가희). */ function common_setSelectOptionValue(ObjSelect, selectedValue) { var coll = ObjSelect.options; if (coll.length>0) { if(selectedValue == "") { coll.options(0).selected = true; } else { for (i=0; i< coll.length; i++) { if(coll.options(i).value == selectedValue){ coll.options(i).selected = true; } } } } } /** * 버튼 클릭에 따라 left menu의 visible 결정 * * @return * * @since 2006. 11. 02(정창혁) */ function common_leftAreaControl(totalWidth) { if(totalWidth=="1000"){ document.all.left_area.style.display = "none"; document.all.supTable.width = totalWidth; for(var i=0; i