//******************************************************************************************//
//* ÀÔ·Â(Å¸ÀÌÇÎ)½Ã ¹®ÀÚ¿­ Ã¼Å©ÇÔ¼ö 
//* 
//* »ç¿ë¹æ¹ý
//*     <input type="text" id="ObjectIDName" °´Ã¼ÀÌº¥Æ®="return input.isNum();" />
//*
//* ¼³¸í
//*     input.isFunc() : ÀÔ·ÂÀÌ ÇØ´çÆã¼ÇÅ°ÀÏ¶§ true ¹ÝÈ¯.
//*     input.isNum()  : ÀÔ·ÂÀÌ ¼ýÀÚ(Å°º¸µå¶Ç´Â Å°ÆÐµå)ÀÏ¶§ true ¹ÝÈ¯.
//*     input.isEng()  : ÀÔ·ÂÀÌ ¿µ¹®ÀÚÀÏ¶§ true ¹ÝÈ¯.
//*     input.isWord() : ÀÔ·ÂÀÌ ¼ýÀÚ¶Ç´Â ¿µ¹®ÀÚÀÏ¶§ true ¹ÝÈ¯.
//------------------------------------------------------------------------------------------//
var input = {
    // Æã¼Ç
    isFunc : function(evt) {
        switch(evt.keyCode) {
            case 8 : //back  
            case 35: //end   
            case 36: //home  
            case 37: //left
            case 38: //top
            case 39: //right
            case 40: //bottom
            case 45: //insert
            case 46: //delete
            case 9 : //tab
            //case 188: //comma
            return true;
        }
        return false;
    },
    // ¼ýÀÚ
    isNum : function(evt) {
        if(!evt.shiftKey && evt.keyCode >= 48 && evt.keyCode <= 57)  { return true; } //keyboard's num
        else if (!evt.shiftKey && evt.keyCode >= 96 && evt.keyCode <= 105) { return true; } //pad's num
        else { return this.isFunc(evt); }
    },
    // ¿µ¹®ÀÚ
    isEng : function(evt) {
        if(evt.keyCode >= 65 && evt.keyCode <= 90) { return true; } //keyboard's char
        else { return this.isFunc(evt); }
    },
    // ¿µ¹®ÀÚ + ¼ýÀÚ
    isWord : function(evt) {
        if(evt.keyCode >= 65 && evt.keyCode <= 90) { return true; } //keyboard's char
        else { return this.isNum(evt); }
    }
}


//******************************************************************************************//
//* ¹®ÀÚ¿­ Ã³¸® ÇÔ¼ö //* 
//* »ç¿ë¹æ¹ý
//*     var TempString = "abcd1234";
//*     alert(TempString.isValues());
//*
//* ¼³¸í
//*      1. String.isValues() : ¹®ÀÚ°¡ ÇÏ³ª¶ó·Î ÀÖÀ»½Ã true ¹ÝÈ¯.
//*      2. String.isValidFormat(format) : Argument¿¡ µû¸¥ Á¤±ÔÇ¥Çö½Ä Ã³¸®.
//*      3. String.isWord() : ¿µ¹®ÀÚ¿Í ¼ýÀÚ Á¶ÇÕÀÏ¶§ true ¹ÝÈ¯.
//*      4. String.isNum() : ¼ýÀÚ Á¶ÇÕÀÏ¶§¸¸ true ¹ÝÈ¯.
//*      5. String.isEng() : ¿µ¹®ÀÚÀÏ¶§¸¸ true ¹ÝÈ¯.
//*      6. String.isParticular() : Æ¯¼ö¹®ÀÚ°¡ ¹®ÀÚ¿­³»¿¡ ÀÖÀ»°æ¿ì true ¹ÝÈ¯.
//*      7. String.isKor() : ÇÑ±ÛÀÏ¶§¸¸ true ¹ÝÈ¯.
//*      8. String.isPhone() : "2,3ÀÚ¸®-3,4ÀÚ¸®-4ÀÚ¸®"ÀÇ ¼ýÀÚÁ¶ÇÕÀÏ °æ¿ì¿¡¸¸ true ¹ÝÈ¯.
//*      9. String.isEmail() : ÀÌ¸ÞÀÏ Çü½ÄÀÏ °æ¿ì¿¡¸¸ true ¹ÝÈ¯.
//*     10. String.isSpace() : °ø¹éÀÌ ÇÏ³ª¶óµµ ÀÖÀ»°æ¿ì true ¹ÝÈ¯.
//*     11. String.trim() : °ø¹é ¸ðµÎÁ¦°Å
//*     12. String.replaceAll(replace, string) : replace¹®ÀÚ¸¦ string¹®ÀÚ·Î ¸ðµÎ º¯È¯
//*     13. String.isIDPWD() : 4~12ÀÚ¸®ÀÇ ¿µ¹®ÀÚ+¼ýÀÚ Á¶ÇÕÀÏ °æ¿ì¿¡¸¸ true ¹ÝÈ¯.
//*     14. String.isSSN() : ÇöÀç ÁÖ¹Îµî·Ï¹øÈ£ ¾Ë°í¸®Áò¿¡ ¸ÂÀ»°æ¿ì¸¸ true ¹ÝÈ¯. [-¾øÀÌ 13ÀÚ¸®°ª ÀÔ·Â]
//*     15. String.isPost() : ¿ìÆí¹øÈ£. [3ÀÚ¸®¼ýÀÚ - 3ÀÚ¸®¼ýÀÚ]
//*     16. String.isLen(len) : ¹®ÀÚ¿­ÀÌ ºñ±³±æÀÌ º¸´Ù Å¬°æ¿ì True, ÀÛ°Å³ª °°À»°æ¿ì False¹ÝÈ¯
//*     17. String.Length() : ¹®ÀÚ¿­ÀÇ ±æÀÌ(Byte) ¹ÝÈ¯
//*     18. String.Slice(len) : ÀÔ·ÂµÈ ±æÀÌ¸¸Å­ ¹®ÀÚ¿­À» Àß¶ó¼­ ¹ÝÈ¯.
//------------------------------------------------------------------------------------------//
//* Á¤±ÔÇ¥Çö½Ä ÆÐÅÏ.
var Pattern = {
      PARTICULAR : /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\'\"\|]/ 
    , ENGLISH : /^([a-zA-Z]+)$/ /* /^(\w[^0-9_]+)$/ */
    , NUMBER : /^(\d+)$/ 
    , ENGNUM : /^(\w+)$/ 
    , SPACE : /(^\s*)|(\s*$)/gi 
    , EMAIL : /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/ 
    , PHONE : /^(0(\d{1,2}))-(\d{3,4})-(\d{4})$/ 
    , IDPWD : /^(\w{4,12})$/
    , SSN : /^(\d{13})$/
    , POST : /^((\d{3}))-(\d{3})$/ 
}
//* ÆÐÅÏ¿¡ µû¸¥ °ª À¯¹« Ã¼Å©
String.prototype.isValues = function() {
return this.length > 0 && this != null;
}
//* Á¤±ÔÇ¥Çö½Ä °Ë»ç
String.prototype.isValidFormat = function(format) {
    return this.search(format) != -1
}
//* ¿µ¹®ÀÚ + ¼ýÀÚ
String.prototype.isWord = function() {
    return this.isValidFormat(Pattern.ENGNUM);
}
//* ¼ýÀÚ
String.prototype.isNum = function() {
    return this.isValidFormat(Pattern.NUMBER);
}
//* ¿µ¹®ÀÚ
String.prototype.isEng = function() {
    return this.isValidFormat(Pattern.ENGLISH);
}
//* Æ¯¼ö¹®ÀÚ ¿©ºÎ
String.prototype.isParticular = function() {
    return this.isValidFormat(Pattern.PARTICULAR);
}
//* ÇÑ±Û
String.prototype.isKor = function() {
    for (var i=0; i<this.length; i++) {
        chrCode = this.charCodeAt(i);
        if (chrCode > 128) { return true; break; }
    }
    return false;
}
//* ÀüÈ­¹øÈ£
String.prototype.isPhone = function() {
    return this.isValidFormat(Pattern.PHONE);
}
//* ÀÌ¸ÞÀÏ
String.prototype.isEmail = function() {
    return this.isValidFormat(Pattern.EMAIL);
}
//* °ø¹é
String.prototype.isSpace = function() {
    return this.isValidFormat(Pattern.SPACE);
}
//* °ø¹éÁ¦°Å
String.prototype.trim = function() {
    return this.replace(Pattern.SPACE, "");
}
//* ¹®ÀÚ ÀüÃ¼ Ä¡È¯
String.prototype.replaceAll = function(replace, string) {
    var tmpStr = this.trim();
    if (tmpStr != "" && replace != string) 
        while ( tmpStr.indexOf(replace) > -1 ) { tmpStr = tmpStr.replace(replace, string); }
    return tmpStr;
}
//* ¾ÆÀÌµð/ºñ¹Ð¹øÈ£
String.prototype.isIDPWD = function() {
     return this.isValidFormat(Pattern.IDPWD);
}
//* ÁÖ¹Îµî·Ï¹øÈ£
String.prototype.isSSN = function() {
     if (this.isValidFormat(Pattern.SSN)) {
        var chk = 0;
        for (var i=0; i<6; i++)  { chk += ( (i+2) * parseInt( this.charAt(i) )); }
        for (var i=6; i<12; i++) { chk += ( (i%8+2) * parseInt( this.charAt(i) )); }
        chk = (11 - (chk % 11)) % 10;
        if ( chk = parseInt(this.charAt(12)) ) return true;
        return false;
     }
     return false;
}
//* ¿ìÆí¹øÈ£
String.prototype.isPost = function() {
     return this.isValidFormat(Pattern.POST);
}
//* ¹®ÀÚ¿­ ±æÀÌ °Ë»ç(Byte´ÜÀ§)
String.prototype.isLen = function(len) {		
    return rtn = (len < this.Length()) ? true : false ;
}

//* ¹®ÀÚ¿­ ±æÀÌ °Ë»ç(Byte´ÜÀ§)
String.prototype.isLens = function(len) {		
    return rtn = (len <= this.Length()) ? true : false ;
}


//* ¹®ÀÚ¿­ ±æÀÌ Ã¼Å©(Byte´ÜÀ§)
String.prototype.Length = function() {
    var bytLen = 0, strSlice = "";
    for (var i=0; i<this.length; i++) {
        strSlice = this.substring(i, i+1);
        bytLen += Math.sqrt(Math.abs(escape(strSlice).length - 2));
    }
    return bytLen;
}
//* ¹®ÀÚ¿­ ±æÀÌ¸¸Å­ ÀÚ¸£±â.
String.prototype.Slice = function(len) {
    var bytLen = 0, strSlice = "", strRtn = "";
    for (var i=0; i<this.length; i++) {
        strSlice = this.substring(i, i+1);
        bytLen += Math.sqrt(Math.abs(escape(strSlice).length - 2));
        strRtn += strSlice;
        if (bytLen >= len) { return strRtn; break; }
    }
    return strRtn;
}

String.prototype.cut = function(len) {
	var str = this;
	var l = 0;
	for (var i=0; i<str.length; i++) {
		l += (str.charCodeAt(i) > 128) ? 2 : 1;
		if (l > len) return str.substring(0,i) + "..";
	}
	return str;
}

String.prototype.checkWord = function() {
	var cn = this;
	if (cn.indexOf('"')>=0 || cn.indexOf("@")>=0 || cn.indexOf("'")>=0
		|| cn.indexOf("_")>=0 || cn.indexOf("-")>=0 || cn.indexOf("+")>=0
		|| cn.indexOf("[")>=0 || cn.indexOf("]")>=0 || cn.indexOf("{")>=0
		|| cn.indexOf("}")>=0 || cn.indexOf("<")>=0 || cn.indexOf("<")>=0
		|| cn.indexOf(">")>=0 || cn.indexOf("$")>=0) {
		return true;
		//alert("[°æ°í] Å¬·´¸í¾È¿¡ Æ¯¼ö¹®ÀÚ¸¦ »ç¿ëÇÏ½Ç¼ö ¾ø½À´Ï´Ù.\n\nÆ¯¼ö¹®ÀÚ(\_, \-, \+, \", \', \@, \$, \<, \>, \[, \], \{, \} ...)¸¦ Á¦¿ÜÇÏ°í ´Ù½Ã ÀÔ·ÂÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.");
	}
	return false;
}