/** ÆÄÀϸí : common.js ¸ñ Àû : ÀÛ¼ºÀÚ : À̼º¿ø ³» ¿ë : ---------------------------------------------------------------------------- **/ var gFunctionName; //disableRightButton(); enableEnterKey(); /** * ÀÔ·Â °´Ã¼¿¡ ¼ÓÇÑ ¸ðµç ¼Ó¼º°ú ÇÔ¼ö¸¦ º¸¿©ÁØ´Ù. */ function showProps(obj) { var element = this.getObject(obj); var msgHead = "°´Ã¼ÀÇ ¼Ó¼º"; var msgBody = ""; var i = 0; if(obj) { for(prop in obj) { i++; msgBody += i + ". " + prop + "=" + obj[prop] + "\n"; if(i % 10 == 0) { window.alert(msgHead + " " + i/10 + " ÆäÀÌÁö\n\n" + msgBody); msgBody = ""; } } if(i < 10) window.alert(msgBody); } } /** * ÀÔ·Â °´Ã¼°¡ ½ÇÁ¦·Î ÆäÀÌÁö»ó¿¡ Á¸ÀçÇÏ´Â HTML°´Ã¼ÀÎÁö¸¦ °Ë»çÇÑ´Ù. */ function isObject(obj) { if(typeof(obj) == "undefined") { // window.alert("°´Ã¼°¡ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù. °´Ã¼ÀÇ Ã¶ÀÚ¸¦ È®ÀÎÇϼ¼¿ä."); return(false); } return(true); } /** * ÀÔ·Â °´Ã¼°¡ Array ÇüÅÂÀÎÁö °Ë»çÇÑ´Ù. */ function isArray(obj) { if((typeof(obj) != "object") || (typeof(obj[0]) != "object")) { // window.alert("element(checkbox)°¡ Array°¡ ¾Æ´Õ´Ï´Ù."); return(false); } return(true); } //////////////////////////////////////////////////////////////////////////////// // ¹®ÀÚ °ü·Ã ÇÔ¼ö //////////////////////////////////////////////////////////////////////////////// /** * ÀÔ·Â ¹®ÀÚ¿­ÀÇ ¾ÕµÚ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù. */ function trim(str) { var n = str.length; var i; for(i = 0; i < n; i++) { if(str.charAt(i) != " ") { break; } } var j; for(j = n - 1; j >= 0; j--) { if(str.charAt(j) != " ") { break; } } if(i > j) { return(""); } else { return(str.substring(i, j + 1)); } } /** * ÀÔ·Â ¹®ÀÚ¿­ÀÇ ¾Õ¿¡¼­ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù. */ function trimByFront(str) { var n = str.length; var i; for(i = 0; i < n; i++) { if(str.charAt(i) != " ") { break; } } return(str.substring(i)); } /** * ÀÔ·Â ¹®ÀÚ¿­ÀÇ µÚ¿¡¼­ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù. */ function trimByBack(str) { var n = str.length; var j; for(j = n - 1; j >= 0; j--) { if(str.charAt(j) != " ") { break; } } return(str.substring(0, j + 1)); } /** * ÀÔ·Â °´Ã¼ÀÇ °ªÀÌ ³Î(null)ÀÎÁö¸¦ °Ë»çÇÑ´Ù. */ function isNull(obj) { var str = obj.value; if(strlen(str) == 0) { return(true); } return(false); } /** * ÀÔ·Â °´Ã¼ÀÇ ¹ÙÀÌÆ®´ÜÀ§ÀÇ ±æÀ̸¦ ±¸ÇÑ´Ù. */ function strlen(str) { var j = 0; for(var i = 0; i < str.length; i++) { if(escape(str.charAt(i)).length == 6) j++; j++; } return(j); } /** * ¹®ÀÚ¿­ÀÇ °ø¹é(white space)À» Á¦°ÅÇÑ´Ù. */ function removeSpace(str) { return(removeString(str, " ")); } /** * ¹®ÀÚ¿­À» µÚ¿¡¼­ºÎÅÍ 3ÀÚ¸®¾¿ ,(comma)·Î ²÷´Â´Ù. */ function insertComma(str) { str = removeComma(str); var strIdx = str.indexOf("."); if(strIdx == -1) { return(insertCharacterByBack(str, ",", 3)); } else { var str1 = str.substring(0, strIdx); var str2 = str.substring(strIdx); return(insertCharacterByBack(str1, ",", 3) + str2); } } /** * ,(comma)¸¦ »èÁ¦ÇÑ´Ù. */ function removeComma(str) { return(removeString(str, ",")); } /** * ¹®ÀÚ¿­À» ±³È¯ÇÑ´Ù. */ function replace(source, target, replace) { var sourceData = ""; sourceData=source; if(sourceData == null) return(""); if(target == null || target == "") { return(source); } iTargetLen = target.length; sbfReplace = ""; i = 0; j = 0; while(j > -1) { j = sourceData.indexOf(target, i); if(j > -1) { sbfReplace += sourceData.substring(i, j); sbfReplace += replace; i = j + iTargetLen; } } sbfReplace += sourceData.substring(i, sourceData.length); return(sbfReplace); } /** * ÀÔ·Â ¹®ÀÚ¿­ÀÇ ÁöÁ¤¹®ÀÚ¸¦ Á¦°ÅÇÑ´Ù. */ function removeString(str, delStr) { var oldVal = str; var newVal = ""; var n = oldVal.length; for(var i = 0; i < n; i++) { if(oldVal.charAt(i) == delStr) { continue; } else { newVal += oldVal.charAt(i); } } return(newVal); } /** * ÁöÁ¤ÇÑ ÀÚ¸®¼öÀÇ ³­¼ö¸¦ ¹ß»ý½ÃŲ´Ù. */ function getRandom(size) { var random; while((random = Math.random() * Math.pow(10, size) - 1) < Math.pow(10, size - 1)) { ; } return(parseInt(random)); } /** * ¼Ò¼öÁ¡À» Æ÷ÇÔÇÑ ¼ýÀÚ¸¦ ¼Ò¼öÁ¡À» Á¦°ÅÇÑ Á¤¼ö·Î º¯È¯ÇÑ´Ù. */ function toInteger(str) { if(str.indexOf(".") == -1) { return(str); } else { return(str.substring(0, str.indexOf("."))); } } /** * ¼Ò¼öÁ¡À» Æ÷ÇÔÇÏÁö ¾ÊÀº ¼ýÀÚ¸¦ ¼Ò¼öÁ¡À» Æ÷ÇÔÇÑ ½Ç¼ö·Î º¯È¯ÇÑ´Ù. */ function toReal(str) { var strIdx = str.indexOf(".") if(strIdx == -1) return(str + ".0"); else if(strIdx == str.length-1) return(str + "0"); else return(str); } //////////////////////////////////////////////////////////////////////////////// // ³¯Â¥ °ü·Ã ÇÔ¼ö //////////////////////////////////////////////////////////////////////////////// /** * ÀÚ¹Ù½ºÅ©¸³Æ® Date °´Ã¼¸¦ Time ¹®ÀÚ¿­·Î º¯È¯ÇÑ´Ù. */ function toTimeString(date) { var year = date.getFullYear(); var month = date.getMonth() + 1; // 1¿ù=0, 12¿ù=11 var day = date.getDate(); var hour = date.getHours(); var min = date.getMinutes(); var sec = date.getSeconds(); if(("" + month).length == 1) {month = "0" + month;} if(("" + day).length == 1) {day = "0" + day;} if(("" + hour).length == 1) {hour = "0" + hour;} if(("" + min).length == 1) {min = "0" + min;} if(("" + sec).length == 1) {sec = "0" + sec;} return("" + year + month + day + hour + min + sec) } /** * Time ½ºÆ®¸µÀ» ÀÚ¹Ù½ºÅ©¸³Æ® Date °´Ã¼·Î º¯È¯ÇÑ´Ù. */ function toTimeObject(time) { var year = time.substr(0,4); var month = time.substr(4,2) - 1; // 1¿ù=0, 12¿ù=11 var day = time.substr(6,2); var hour = time.substr(8,2); var min = time.substr(10,2); return(new Date(year,month,day,hour,min)); } /** * D-3. ÇöÀç ½Ã°¢À» Time Çü½ÄÀ¸·Î ¸®ÅÏÇÑ´Ù. * * @return */ function getCurrentTime() { return(toTimeString(new Date())); } /** * ÇöÀç Ò´À» YYYYÇü½ÄÀ¸·Î ¸®ÅÏ */ function getYear() { return(getCurrentTime().substr(0,4)); } /** * ÇöÀç êÅÀ» MMÇü½ÄÀ¸·Î ¸®ÅÏ */ function getMonth() { return(getCurrentTime().substr(4,2)); } /** * ÇöÀç ìíÀ» DDÇü½ÄÀ¸·Î ¸®ÅÏ */ function getDay() { return(getCurrentTime().substr(6, 2)); } /** * ¿À´Ã³¯Â¥¿¡ ÇØ´çÇÏ´Â ¿äÀÏÀ» ±¸ÇÑ´Ù. */ function getDayOfWeek() { var now = new Date(); var day = now.getDay(); var week = new Array("ÀÏ", "¿ù", "È­", "¼ö", "¸ñ", "±Ý", "Åä"); return(week[day]); } /** * ÁÖ¾îÁø Time °ú y³â m¿ù dÀÏ h½Ã Â÷À̳ª´Â TimeÀ» ±¸ÇÑ´Ù. */ function shiftTime(time, y, m, d, h) { var date = toTimeObject(time); date.setFullYear(date.getFullYear() + y); // y³âÀ» ´õÇÔ date.setMonth(date.getMonth() + m); // m¿ùÀ» ´õÇÔ date.setDate(date.getDate() + d); // dÀÏÀ» ´õÇÔ date.setHours(date.getHours() + h); // h½Ã¸¦ ´õÇÔ return(toTimeString(date)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü½Ã°£À» ±¸ÇÑ´Ù. */ function getHourBefore(nHour) { nHour = eval(nHour); return(shiftTime(getCurrentTime(), 0, 0, 0, -nHour)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀüÀÏÀ» ±¸ÇÑ´Ù. */ function getDayBefore(nDay) { nDay = eval(nDay); return(shiftTime(getCurrentTime(), 0, 0, -nDay, 0)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü¿ùÀ» ±¸ÇÑ´Ù. */ function getMonthBefore(nMonth) { nMonth = eval(nMonth); return(shiftTime(getCurrentTime(), 0, -nMonth, 0, 0)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÀü¿¬µµ¸¦ ±¸ÇÑ´Ù. */ function getYearBefore(nYear) { nYear = eval(nYear); return(shiftTime(getCurrentTime(), -nYear, 0, 0, 0)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈĽð£À» ±¸ÇÑ´Ù. */ function getHourAfter(nHour) { nHour = eval(nHour); return(shiftTime(getCurrentTime(), 0, 0, 0, nHour)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄÀϸ¦ ±¸ÇÑ´Ù. */ function getDayAfter(nDay) { nDay = eval(nDay); return(shiftTime(getCurrentTime(), 0, 0, nDay, 0)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ¿ùÀ» ±¸ÇÑ´Ù. */ function getMonthAfter(nMonth) { nMonth = eval(nMonth); return(shiftTime(getCurrentTime(), 0, nMonth, 0, 0)); } /** * ÇöÀç·ÎºÎÅÍ ÁöÁ¤ÇÑ ¸¸Å­ÀÇ ÀÌÈÄ¿¬µµ¸¦ ±¸ÇÑ´Ù. */ function getYearAfter(nYear) { nYear = eval(nYear); return(shiftTime(getCurrentTime(), nYear, 0, 0, 0)); } /** * µÎ ½Ã°£ÀÌ ¸î °³¿ù Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù. */ function getMonthInterval(time1,time2) { var date1 = toTimeObject(time1); var date2 = toTimeObject(time2); var years = date2.getFullYear() - date1.getFullYear(); var months = date2.getMonth() - date1.getMonth(); var days = date2.getDate() - date1.getDate(); return(years * 12 + months + ((days >= 0)?0:-1)); } /** * µÎ ½Ã°£ÀÌ ¸îÀÏ Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù. */ function getDayInterval(time1, time2) { var date1 = toTimeObject(time1); var date2 = toTimeObject(time2); var day = 1000 * 3600 * 24; return(parseInt((date2 - date1) / day, 10)); } /** * µÎ ½Ã°£ÀÌ ¸î½Ã°£ Â÷ÀÌÀÎÁö ±¸ÇÑ´Ù. */ function getHourInterval(time1, time2) { var date1 = toTimeObject(time1); var date2 = toTimeObject(time2); var hour = 1000 * 3600; return(parseInt((date2 - date1) / hour, 10)); } /** * À±³â¿©ºÎ¸¦ ³ªÅ¸³½´Ù. **/ function isLeapYear(aYear) { if ((aYear % 4 == 0) && ((aYear % 100 != 0) || (aYear % 400 == 0))) { return(true); // À±³â } else { return(false); // Æò³â } } /** * °ªÀÌ YYYY-MM-DD Çü½ÄÀÌ ¸Â´ÂÁö °Ë»çÇÑ´Ù. */ function isValidFormattedDate(strDate) { if(strDate.length != 10 ) { return(false); } var str1 = replace( strDate, '-', ''); var yyyy = str1.substring(0, 4); var mm = str1.substring(4, 6); var dd = str1.substring(6, 8); if(!ValidDate(yyyy, mm, dd)) { return(false); } return(true); } //////////////////////////////////////////////////////////////////////////////// // ÄíŰ °ü·Ã ÇÔ¼ö //////////////////////////////////////////////////////////////////////////////// /** * Äí۰ªÀ» ÁöÁ¤ÇÑ´Ù. */ function setCookie(name, value, expiredays) { var today = new Date(); var nextDate = today.getDate() + (expiredays - 1) today.setDate(nextDate); var newDate = new Date( today.getYear(), today.getMonth(), today.getDate(), 23, 59, 59 ); document.cookie = name + "=" + escape( value ) + "; domain=kbstar.com; path=/; expires=" + newDate.toGMTString() + ";"; } /** * Äí۰ªÀ» °¡Á®¿Â´Ù. */ function getCookie(name) { var nameOfCookie = name + "="; var x = 0; while(x <= document.cookie.length) { var y = (x+nameOfCookie.length); if(document.cookie.substring(x, y) == nameOfCookie) { if((endOfCookie=document.cookie.indexOf(";", y)) == -1 ) { endOfCookie = document.cookie.length; } return(unescape(document.cookie.substring( y, endOfCookie))); } x = document.cookie.indexOf(" ", x ) + 1; if(x == 0) { break; } } return(""); } /** * ÁöÁ¤ÇÑ ÄíŰÀ̸§ÀÇ Äí۸¦ »èÁ¦ÇÑ´Ù. */ function deleteCookie(name) { var expire = new Date(); expire.setTime(expire.getTime() - 1); var value = GetCookie(name); document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); } //////////////////////////////////////////////////////////////////////////////// // À©µµ¿ì °ü·Ã ÇÔ¼ö //////////////////////////////////////////////////////////////////////////////// /** * âÀ» Á¤ÇØÁø ¼Ó¼ºÀ¸·Î ¿¬´Ù. */ function openWindow(url, name, W, H, scroll, resize, option) { var X = 0; var Y = 0; if(option == 8) { X = (window.screen.width - W) / 2; Y = window.screen.height - H - 83; } else { if(parseInt(W) <= 400 && parseInt(H) <= 400) { // X = (window.screen.width/2) - (W/2+10); // Y = (window.screen.height/2) - (H/2+50); if(window.screen.width < W + window.event.screenX) X = window.event.screenX - W - 10; else X = window.event.screenX; if(window.screen.height < H + window.event.screenY) Y = window.event.screenY - H - 30; else Y = window.event.screenY; } } var win = window.open(url, name, "status=no, height=" + H + ",width=" + W + ", left=" + X + ", top=" + Y + ", screenX=" + X + ", screenY=" + Y + ", scrollbars=" + scroll + ", resizable=" + resize); win.focus(); return(win); } //////////////////////////////////////////////////////////////////////////////// // Select °ü·Ã ÇÔ¼ö //////////////////////////////////////////////////////////////////////////////// /** * SELECT °´Ã¼°¡ Ãʱâ»óÅÂ(index == 0)¿¡¼­ º¯°æµÇ¾ú´ÂÁö °Ë»çÇÑ´Ù. */ function isSelected(obj, msg) { if(!isObject(obj)) { return(false); } if(obj.selectedIndex == 0) { if(msg) { window.alert("[" + msg + "]ÀÌ(°¡) ¼±ÅõÇÁö ¾Ê¾Ò½À´Ï´Ù."); } obj.focus(); return(false); } return(true); } /** * SELECT-VALUE°¡ µ¿ÀÏÇÑÁö ºñ±³ÇÑ´Ù. */ function compareOptionValues(a, b) { // Radix 10: for numeric values // Radix 36: for alphanumeric values var sA = parseInt(a.value, 36); var sB = parseInt(b.value, 36); return(sA - sB); } /** * SELECT-TEXT°¡ µ¿ÀÏÇÑÁö ºñ±³ÇÑ´Ù. */ function compareOptionText(a, b) { // Radix 10: for numeric values // Radix 36: for alphanumeric values var sA = parseInt(a.text, 36); var sB = parseInt(b.text, 36); return(sA - sB); } /** * SELECT ¸®½ºÆ®¿¡¼­ ´Ù¸¥ ¸®½ºÆ®·Î Ç׸ñÀ» À̵¿ÇÑ´Ù. */ function moveDualList(srcList, tarList, moveAll) { if(srcList.length == 0) { window.alert("À̵¿ÇÒ Ç׸ñÀÌ ¾ø½À´Ï´Ù."); return(false); } if((srcList.selectedIndex == -1) && (moveAll == false)) { window.alert("À̵¿ÇÒ Ç׸ñÀ» ¼±ÅÃÇϼ¼¿ä."); return(false); } newtarList = new Array(tarList.options.length); var len = 0; for(len = 0; len < tarList.options.length; len++) { if(tarList.options[ len ] != null) { newtarList[ len ] = new Option(tarList.options[ len ].text, tarList.options[ len ].value, tarList.options[ len ].defaultSelected, tarList.options[ len ].selected); } } for(var i = 0; i < srcList.options.length; i++) { if(srcList.options[i] != null && (srcList.options[i].selected == true || moveAll)) { newtarList[ len ] = new Option(srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected); len++; } } newtarList.sort(compareOptionValues); // BY VALUES //newtarList.sort(compareOptionText); // BY TEXT for(var j = 0; j < newtarList.length; j++) { if(newtarList[ j ] != null) { tarList.options[ j ] = newtarList[ j ]; } } for(var i = srcList.options.length - 1; i >= 0; i--) { if(srcList.options[i] != null && (srcList.options[i].selected == true || moveAll)) { srcList.options[i] = null; } } } /** * ÀÔ·Â ¹®ÀÚ¿­À» µÚ¿¡¼­ºÎÅÍ ÁöÁ¤ÇÑ Å©±â¸¸Å­ ±¸ºÐ¹®ÀÚ·Î ²÷´Â´Ù. */ function insertCharacterByBack(strMain, strIns, size) { var returnStr = ""; var tempStrMain = strMain + ""; var tempStrIns = strIns + ""; var strMainLength = tempStrMain.length; if (strMainLength < size) { return(tempStrMain); } else { var strLengthDiv = parseInt(strMainLength / size); var strLengthRemnant = parseInt(strMainLength % size); if (strLengthRemnant > 0) { returnStr = tempStrMain.substring(0, strLengthRemnant) + strIns; } for (i = 0; i < strLengthDiv; i++) { if (i == 0) { returnStr = returnStr + tempStrMain.substring(strLengthRemnant, strLengthRemnant + size); } else { returnStr = returnStr + tempStrIns + tempStrMain.substring(strLengthRemnant + (size * i), strLengthRemnant + (size * i) + size); } } return(returnStr); } } //////////////////////////////////////////////////////////////////////////////// // ±âŸ ÇÔ¼ö //////////////////////////////////////////////////////////////////////////////// /** * ¿À¸¥ÂÊ ¹öưÀ» »ç¿ëÇÏÁö ¸øÇÏ°Ô ÇÑ´Ù. */ function disableRightButton() { if(window.Event) document.captureEvents(Event.MOUSEUP); function nocontextmenu() { window.event.cancelBubble = true window.event.returnValue = false; return(false); } function norightclick(e) { if(window.Event) { if(e.which == 2 || e.which == 3) return(false); } else if(window.event.button == 2 || window.event.button == 3) { window.event.cancelBubble = true window.event.returnValue = false; return(false); } } document.oncontextmenu = nocontextmenu; document.onmousedown = norightclick; } /** * ¿£ÅÍ۸¦ ´©¸£¸é __submit() ÇÔ¼ö¸¦ È£ÃâÇÏ°Ô ÇÑ´Ù. */ function enableEnterKey() { function onkeypress(e) { if(window.event.keyCode == 13 && window.event.srcElement.type != "textarea" && window.event.srcElement.type != "button") { // 13 : Enter __submit(); if(window.event.srcElement.type == "text" || window.event.srcElement.type == "password") return(false); } } document.onkeypress = onkeypress; } /** * ´Ù¿î·Îµå âÀ» ¿¬´Ù. */ function jsOpenFileWindow(fileId) { location.replace("/new/eng/common/commonDownloadFile.php?fileId=" + fileId); } /** * ´Ù¿î·Îµå âÀ» ¿¬´Ù. */ function jsOpenIRWindow(fileId) { location.replace("/new/eng/common/commonDownloadIR.php?fileId=" + fileId); } /** * ´Ù¿î·Îµå âÀ» ¿¬´Ù. */ function jsOpenRecruitWindow(fileId, i) { location.replace("/new/eng/common/commonDownloadRecruit.php?fileId=" + fileId + "&i=" + i); }