/** * ************************************************ * ¾÷¹«±×·ì¸í : °øÅë ÀÚ¹Ù½ºÅ©¸³Æ® * ¼­ºê¾÷¹«¸í : DOM Event ó¸® * ¼³¸í : Windows ¿¡ ÀԷµǴ Dom Event¸¦ ó¸®ÇÔ * ÀÛ¼ºÀÚ : ±è¼®Ã¶ (indark9@gmail.com) * ÀÛ¼ºÀÏ : 2007. 7. 31 ¿ÀÈÄ 5:25:55 * ************************************************* */ var TYPE_NONE = 0; var TYPE_WON = 1; var TYPE_YEAR = 2; var TYPE_YEARMONTH = 3; var TYPE_DATE = 4; var TYPE_TIME = 5; var TYPE_TIMEHMS = 6; var TYPE_RESNO = 7; var TYPE_ZIPCODE = 8; var TYPE_NUMCODE = 9; var TYPE_ENGCODE = 10; var TYPE_KOR = 20; var TYPE_ENG = 21; var TYPE_NUM = 22; var TYPE_KORENG = 23; var TYPE_KORNUM = 24; var TYPE_ENGNUM = 25; var TYPE_EMAIL = 30; var TYPE_URL = 31; var TYPE_TEL = 32; /** * Àüü Æû¿¡ Àû¿ë µÈ Æ÷¸Ë Çü½Ä Á¦°Å */ function unformat() { for (i = 0; i < document.forms.length; i++) { var form = document.forms[i]; for (j = 0; j < form.elements.length; j++) { if (form.elements[j].type == "text" || form.elements[j].type == "password") form.elements[j].value = form.elements[j].value.replace(/(\,|\-)/g, ""); } } } /** * Æ÷¸Ë ÁöÁ¤ */ function __fomat() { switch (this.elementType) { case TYPE_WON : // ÅëÈ­ Ç¥½Ã var sWon = this.value.replace(/(^(0)*|,)/g, ""); // ¹«ÀǹÌÇÑ 0°ú ÄÞ¸¶ Á¦°Å var tWon = ""; var i; var j = 0; var tLen = sWon.length; for (i = 0; i < tLen; i++) { if (i != 0 && (i % 3 == tLen % 3)) tWon += ","; if (i < sWon.length) { tWon += sWon.charAt(i); } } this.value = tWon; break; case TYPE_YEAR : // ³âµµ Ç¥½Ã this.value = __fomatMask(this.value, "9999"); break; case TYPE_YEARMONTH : // ³âµµ¿Í ¿ù Ç¥½Ã this.value = __fomatMask(this.value, "9999-99"); break; case TYPE_DATE : // ³â¿ùÀÏ Ç¥½Ã this.value = __fomatMask(this.value, "9999-99-99"); break; case TYPE_TIME : // ½Ã°£ Ç¥½Ã this.value = __fomatMask(this.value, "99:99"); break; case TYPE_TIMEHMS : // ½Ã°£ (ÃÊ) Ç¥½Ã this.value = __fomatMask(this.value, "99:99:99"); break; case TYPE_RESNO : // ÁֹιøÈ£ Ç¥½Ã this.value = __fomatMask(this.value, "999999-9999999"); break; case TYPE_ZIPCODE : // ¿ìÆí¹øÈ£ Ç¥½Ã this.value = __fomatMask(this.value, "999-999"); break; } } /** * Æ÷¸Ë ¸¶½ºÅ© ó¸® * @param str ¹®ÀÚ¿­ * @param mask ¸¶½ºÅ© ¹®ÀÚ¿­ */ function __fomatMask(str, mask) { var sStr = str.replace(/(\$|\^|\*|\(|\)|\+|\.|\?|\\|\{|\}|\||\[|\]|-|:)/g, ""); var tStr = ""; var i; var j = 0; var tLen = sStr.length + 1 ; for (i = 0; i < sStr.length; i++) { tStr += sStr.charAt(i); j++; if (j < mask.length && mask.charAt(j) != "9") tStr += mask.charAt(j++); } return tStr; } /** * Űº¸µå°¡ ´­¸± °æ¿ì ó¸® (ÀԷ°¡´ÉÇÑ ¹®ÀÚ Ã³¸®) */ function __onkeypress() { var sKey = String.fromCharCode(event.keyCode); var sFilter; var re; switch (this.elementType) { case TYPE_WON : sFilter = "[0-9.-]"; break; case TYPE_YEAR : case TYPE_YEARMONTH : case TYPE_DATE : case TYPE_TIME : case TYPE_TIMEHMS : case TYPE_RESNO : case TYPE_ZIPCODE : sFilter = "[0-9]"; break; case TYPE_NUMCODE : sFilter = "[0-9]"; break; case TYPE_ENGCODE : sFilter = "[0-9A-Za-z]"; break; case TYPE_KOR : sFilter = "[^0-9A-Za-z ]"; break; case TYPE_ENG : sFilter = "[A-Za-z ]"; break; case TYPE_NUM : sFilter = "[0-9.-]"; break; case TYPE_KORENG : sFilter = "[^0-9 ]"; break; case TYPE_KORNUM : sFilter = "[^A-Za-z ]"; break; case TYPE_ENGNUM : sFilter = "[0-9A-Za-z ]"; break; case TYPE_EMAIL : sFilter = "[0-9a-z@.]"; break; case TYPE_URL : sFilter = "[0-9a-z:/.]"; break; case TYPE_TEL : sFilter = "[0-9]"; break; } if (sFilter) { re = new RegExp(sFilter); if (!re.test(sKey)) { event.returnValue = false; } } if (this.getAttribute("filter")) { re = new RegExp(this.getAttribute("filter")); if (!re.test(sKey)) { window.event.returnValue = false; } } if (this.elementType == TYPE_WON || this.elementType == TYPE_NUM) { // TYPE_WON, TYPE_NUMÀÇ °æ¿ì ÄÞ¸¶´Â ÇѰ³¸¸ ÀÌ¿ë if (sKey == "." && this.value.indexOf(".") != -1) window.event.returnValue = false; } if (this.getAttribute("keypress")) { var fn = eval(this.getAttribute("keypress")); } } /** * Űº¸µå°¡ ¶¼¾îÁú °æ¿ì ó¸® */ function __onkeyup() { var nKeyCode = window.event.keyCode; if (nKeyCode == 9 || (nKeyCode >= 33 && nKeyCode <= 40) || nKeyCode == 45 || nKeyCode == 46) return; switch (this.elementType) { case TYPE_WON : insertSeperatorByWon(this, ","); break; case TYPE_YEAR : break; case TYPE_YEARMONTH : insertSeperatorByYearMonth(this, "-"); break; case TYPE_DATE : insertSeperatorByDate(this, "-"); break; case TYPE_TIME : insertSeperatorByTime(this, ":"); break; case TYPE_TIMEHMS : insertSeperatorByTimeHms(this, ":"); break; case TYPE_RESNO : insertSeperatorByResno(this, "-"); break; case TYPE_ZIPCODE : insertSeperatorByZipcode(this, "-"); break; case TYPE_NUMCODE : case TYPE_ENGCODE : case TYPE_KOR : case TYPE_ENG : case TYPE_NUM : case TYPE_KORENG : case TYPE_KORNUM : case TYPE_ENGNUM : case TYPE_EMAIL : case TYPE_URL : case TYPE_TEL : break; } if (this.getAttribute("keyup")) { var fn = eval(this.getAttribute("keyup")); } } /** * Űº¸µå°¡ ´­·È´Ù ¶¼¾îÁø °æ¿ì ó¸® */ function __onkeydown() { if (this.getAttribute("keydown")) { var fn = eval(this.getAttribute("keydown")); } } /** * Æ÷Ä¿½º¸¦ ¹Þ´Â °æ¿ì ó¸® */ function __onfocus() { if (this.select) this.select(); if (this.getAttribute("focus")) { var fn = eval(this.getAttribute("focus")); } } /** * Æ÷Ä¿½º°¡ À̵¿µÉ °æ¿ì ó¸® */ function __onblur() { if (window.event.keyCode == 9) return; var title = this.getAttribute("title") ? this.getAttribute("title") : "ÀÔ·ÂÀÚ·á"; var str = ""; var sep = ""; var arr; // ¹üÀ§ °Ë»ç if (this.getAttribute("range")) { var range = this.getAttribute("range").split("-"); if (range.length == 2) { str = trim(this.value); if (strlen(str) != 0 && !(strlen(str) >= range[0] && strlen(str) <= range[1])) { if (range[0] == range[1]) { window.alert(title + "Àº(´Â) " + range[0] + "ÀÚ·Î ÀÔ·ÂÇϼ¼¿ä."); this.focus(); } else { window.alert(title + "Àº(´Â) ÃÖ¼Ò " + range[0] + "ÀÚ, ÃÖ´ë " + range[1] + "ÀÚ·Î ÀÔ·ÂÇϼ¼¿ä."); this.focus(); } this.value = str; this.focus(); return; } this.value = str; } } // À¯È¿¼º °Ë»ç switch (this.elementType) { case TYPE_YEAR : str = this.value; if (str != "") { if (str != "" && !(parseInt(str) >= 1900 && parseInt(str) <= 2100)) { window.alert("[" + str + "]Àº(´Â) À¯È¿ÇÑ " + title + "ÀÌ(°¡) ¾Æ´Õ´Ï´Ù."); this.focus(); this.value = str; return; } this.value = str; } break; case TYPE_YEARMONTH : sep = "-"; // ±¸ºÐÀÚ str = this.value; if (str != "") { arr = new Array(); arr = str.split(sep); if (arr.length != 2) { window.alert(title + "Àº(´Â) [" + sep + "]·Î ±¸ºÐÇØ¾ß ÇÕ´Ï´Ù."); this.value = str; return; } if (!ValidYear(arr[0]) || !ValidMonth(arr[1])) { window.alert("[" + str + "]Àº(´Â) À¯È¿ÇÑ " + title + "ÀÌ(°¡) ¾Æ´Õ´Ï´Ù."); this.focus(); this.value = str; return; } if (arr[1].length == 1) arr[1] = "0" + arr[1]; this.value = arr[0] + sep + arr[1]; } break; case TYPE_DATE : sep = "-"; str = this.value; if (str != "") { arr = new Array(); arr = str.split(sep); if (arr.length != 3) { window.alert(title + "Àº(´Â) [" + sep + "]·Î ±¸ºÐÇØ¾ß ÇÕ´Ï´Ù."); this.focus(); this.value = str; return; } if (!ValidDate(arr[0], arr[1], arr[2])) { window.alert("[" + str + "]Àº(´Â) À¯È¿ÇÑ " + title + "ÀÌ(°¡) ¾Æ´Õ´Ï´Ù."); this.focus(); this.value = str; return; } if (arr[1].length == 1) arr[1] = "0" + arr[1]; if (arr[2].length == 1) arr[2] = "0" + arr[2]; this.value = arr[0] + sep + arr[1] + sep + arr[2]; } break; case TYPE_TIME : sep = ":"; // ±¸ºÐÀÚ str = this.value; if (str != "") { arr = new Array(); arr = str.split(sep); if (arr.length != 2) { window.alert(title + "Àº(´Â) [" + sep + "]·Î ±¸ºÐÇØ¾ß ÇÕ´Ï´Ù."); this.focus(); this.value = str; return; } if (!ValidHour(arr[0]) || !ValidMinute(arr[1])) { window.alert("[" + str + "]Àº(´Â) À¯È¿ÇÑ " + title + "ÀÌ(°¡) ¾Æ´Õ´Ï´Ù."); this.focus(); this.value = str; return; } if (arr[1].length == 1) arr[1] = "0" + arr[1]; this.value = arr[0] + sep + arr[1]; } break; case TYPE_TIMEHMS : sep = ":"; // ±¸ºÐÀÚ str = this.value; if (str != "") { arr = new Array(); arr = str.split(sep); if (arr.length != 3) { window.alert(title + "Àº(´Â) [" + sep + "]·Î ±¸ºÐÇØ¾ß ÇÕ´Ï´Ù."); this.focus(); this.value = str; return; } if (!ValidHour(arr[0]) || !ValidMinute(arr[1]) || !ValidMinute(arr[2])) { window.alert("[" + str + "]Àº(´Â) À¯È¿ÇÑ " + title + "ÀÌ(°¡) ¾Æ´Õ´Ï´Ù."); this.focus(); this.value = str; return; } if (arr[1].length == 1) arr[1] = "0" + arr[1]; if (ar[2].length == 1) arr[2] = "0" + arr[2]; this.value = arr[0] + sep + arr[1] + sep + arr[2]; } break; case TYPE_RESNO : sep = "-"; str = this.value; if (str != "") { arr = new Array(); arr = str.split(sep); if (arr.length != 2) { window.alert(title + "Àº(´Â) [" + sep + "]·Î ±¸ºÐÇØ¾ß ÇÕ´Ï´Ù."); this.focus(); this.value = str; return; } if (!ValidSize(arr[0], 6, 6)) { window.alert(title + "ÀÇ ¾ÕÀÚ¸®´Â " + 6 + "ÀÚ·Î ÀÔ·ÂÇϼ¼¿ä."); this.focus(); this.value = str; return; } if (!ValidSize(arr[1], 7, 7)) { window.alert(title + "ÀÇ µÞÀÚ¸®´Â " + 7 + "ÀÚ·Î ÀÔ·ÂÇϼ¼¿ä."); this.focus(); this.value = str; return; } var year = (parseInt(arr[0].substring(0, 2)) < 5) ? "20" : "19"; if (!ValidDate(year + arr[0].substring(0, 2), arr[0].substring(2, 4), arr[0].substring(4, 6))) { window.alert(title + "ÀÇ »ý³â¿ùÀÏÀÌ Á¤È®ÇÏÁö ¾Ê½À´Ï´Ù."); this.focus(); this.value = str; return; } var hap = 0; for (var i = 0; i < 6; i++) { hap = hap + (arr[0].charAt(i) * (i + 2)); } if (!(arr[0] == "000000" && arr[1] == "0000000")) { var n1 = arr[1].charAt(0); var n2 = arr[1].charAt(1); var n3 = arr[1].charAt(2); var n4 = arr[1].charAt(3); var n5 = arr[1].charAt(4); var n6 = arr[1].charAt(5); var n7 = arr[1].charAt(6); hap += n1 * 8 + n2 * 9 + n3 * 2 + n4 * 3 + n5 * 4 + n6 * 5; hap %= 11; hap = 11 - hap; hap %= 10; if (hap != n7) { window.alert(title + "ÀÌ(°¡) À¯È¿ÇÏÁö ¾Ê½À´Ï´Ù. È®ÀÎ ÈÄ ´Ù½Ã ÀÔ·ÂÇϼ¼¿ä."); this.focus(); this.value = str; return; } } this.value = str; } break; case TYPE_NONE : // TYPE_NONEÀÇ °æ¿ì document ³»ÀÇ ¸ðµç element°¡ ÇØ´çµÇ¹Ç·Î validation °Ë»ç¸¦ ÇÏÁö¾Ê´Â´Ù. break; } if (this.getAttribute("blur")) { var fn = eval(this.getAttribute("blur")); } } /** * DomEvent À̿밡´ÉÅä·Ï ¼³Á¤ */ function enableDomEvent() { for (i = 0; i < document.forms.length; i++) { var form = document.forms[i]; for (j = 0; j < form.elements.length; j++) { switch (form.elements[j].type) { // ³»ÀåµÈ Ű¿öµå°¡ ÀÖÀ» °æ¿ì ¿À¸¥ÂÊ Á¤·Ä, ¿µ¼ýÀÚ¸¸ ÀÔ·ÂÀÌ °¡´ÉÇϵµ·Ï ¼³Á¤ÇÑ´Ù. case "password" : case "text" : if (form.elements[j].getAttribute("won") != null) { form.elements[j].elementType = TYPE_WON; form.elements[j].style.textAlign = "right"; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("year") != null) { form.elements[j].elementType = TYPE_YEAR; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("yearmonth") != null) { form.elements[j].elementType = TYPE_YEARMONTH; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("date") != null) { form.elements[j].elementType = TYPE_DATE; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("time") != null) { form.elements[j].elementType = TYPE_TIME; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("timehms") != null) { form.elements[j].elementType = TYPE_TIMEHMS; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("resno") != null) { form.elements[j].elementType = TYPE_RESNO; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("zipcode") != null) { form.elements[j].elementType = TYPE_ZIPCODE; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("kor") != null) { form.elements[j].elementType = TYPE_KOR; form.elements[j].style.imeMode = "active"; } else if (form.elements[j].getAttribute("eng") != null) { form.elements[j].elementType = TYPE_ENG; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("num") != null) { form.elements[j].elementType = TYPE_NUM; form.elements[j].style.textAlign = "right"; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("numcode") != null) { form.elements[j].elementType = TYPE_NUMCODE; form.elements[j].style.textAlign = "right"; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("engcode") != null) { form.elements[j].elementType = TYPE_ENGCODE; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("koreng") != null) { form.elements[j].elementType = TYPE_KORENG; form.elements[j].style.imeMode = "active"; } else if (form.elements[j].getAttribute("kornum") != null) { form.elements[j].elementType = TYPE_KORNUM; form.elements[j].style.imeMode = "active"; } else if (form.elements[j].getAttribute("engnum") != null) { form.elements[j].elementType = TYPE_ENGNUM; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("email") != null) { form.elements[j].elementType = TYPE_EMAIL; form.elements[j].style.imeMode = "disabled"; } else if (form.elements[j].getAttribute("url") != null) { form.elements[j].elementType = TYPE_URL; form.elements[j].style.imeMode = "inactive"; } else if (form.elements[j].getAttribute("tel") != null) { form.elements[j].elementType = TYPE_TEL; form.elements[j].style.imeMode = "disabled"; } else { form.elements[j].elementType = TYPE_NONE; form.elements[j].style.imeMode = "active"; } form.elements[j].onkeypress = __onkeypress; form.elements[j].onkeyup = __onkeyup; form.elements[j].onkeydown = __onkeydown; form.elements[j].format = __fomat; form.elements[j].onfocus = __onfocus; form.elements[j].onblur = __onblur; break; default: break; } } } } /** * END OF SCRIPT */