String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)|($\s*)/g, "");
}

String.prototype.isid = function() {
	if (this.search(/[^A-Za-z0-9_-]/) == -1)
		return true;
	else 
		return false;
}

String.prototype.isalpha = function() {
	if (this.search(/[^A-Za-z]/) == -1)
		return true;
	else
		return false;
}

String.prototype.isnick = function() {
	var temp,temp2;
	var mycount = 0;
	
	for( k = 0 ; k < this.length ; k++ ){
		temp = this.charAt(k);
		if( escape(temp).length > 4 ) {
		} else temp2 += temp;
	}
	if (temp2.search(/[^A-Za-z0-9]/) == -1)
		return true;
	else
		return false;
}

String.prototype.iskor = function() {
	var temp;
	var set = 0;
	var mycount = 0;
	for( k = 0 ; k < this.length ; k++ ){
		temp = this.charAt(k);
		if( escape(temp).length > 4 ) {
			mycount += 2; 
		} else set = 1;
	}
	if( set ) return false;
	else return true;
}

String.prototype.isnumber = function() {
	if (this.search(/[^0-9]/) == -1)
		return true;
	else
		return false;
}
String.prototype.istel = function() {
	if (this.search(/[^0-9-]/) == -1)
		return true;
	else 
		return false;
}

String.prototype.isdate = function() {
	if( this.istel() ) {
		var adate = this.split("-");
		if( (adate[0].length == 4 && adate[0] > 999 && adate[0] < 10000 ) && (adate[1].length == 2 && adate[1] > 0 && adate[1] < 13 ) && (adate[2].length == 2 && adate[2] > 0 && adate[2] < 32 ) ) {
			return true;
		} else  {
			return false;
		}
	} else {
		return false;
	}
}

String.prototype.isemail = function() {
	var flag, md, pd, i;
	var str;
	
	if ( (md = this.indexOf("@")) < 0 )
		return false;
	else if ( md == 0 )
		return false;
	else if (this.substring(0, md).search(/[^.A-Za-z0-9_-]/) != -1)
		return false;
	else if ( (pd = this.indexOf(".")) < 0 )
		return false;
	else if ( (pd + 1 )== this.length || (pd - 1) == md )
		return false;
	else if (this.substring(md+1, this.length).search(/[^.A-Za-z0-9_-]/) != -1)
		return false;
	else
		return true;
}

String.prototype.korlen = function() {
	var temp;
	var set = 0;
	var mycount = 0;
	
	for( k = 0 ; k < this.length ; k++ ){
		temp = this.charAt(k);
		if( escape(temp).length > 4 ) {
			mycount += 2; 
		} else mycount++;
	}
	return mycount;
}

String.prototype.isssn = function() {
	var first  = new Array(6);
	var second = new Array(7);
	var total = 0;
	var tmp = 0;
	
	if ( this.length != 13 )
		return false;
	else {
		for ( i = 1 ; i < 7 ; i++ ) first[i] = this.substring(i - 1, i);
		for ( i = 1 ; i < 8 ; i++ ) second[i] = this.substring(6 + i - 1, i + 6);
		for ( i = 1 ; i < 7 ; i++ ) {
			if ( i < 3 )
				tmp = Number( second[i] ) * ( i + 7 );
			else if ( i >= 3 )
				tmp = Number( second[i] ) * ( ( i + 9 ) % 10 );
			total = total + Number( first[i] ) * ( i + 1 ) + tmp;
		}
		if ( Number( second[7] ) != ((11 - ( total % 11 ) ) % 10 ) ) 
			return false;
	}
	return true;
}

String.prototype.bytelength = function() {
	var i,ch;
	var strLength = this.length;
	var count = 0;
	
	for(i=0;i<strLength;i++){
		ch = escape(this.charAt(i));
		if(ch.length > 4)
			count += 2;
		else if(ch!='\r') 
			count++;
	}
	return count;
}

String.prototype.islength = function(val1,val2) {
	var val1 = val1?val1:0;
	var val2 = val2?val2:0;
	var count = this.bytelength();

	if (count != val1 && val1==val2) {
		return false;
	}
	if (count < val1 && val1 ) {
		return false;
	}
	if (count > val2 && val2 ) {
		return false;
	}
	return true;
}

String.prototype.chklength = function(val1,val2) {
	var count = this;
	var val1 = val1?val1:0;
	var val2 = val2?val2:0;

	if (count != val1 && val1==val2) {
		return false;
	}
	if (count < val1 && val1 ) {
		return false;
	}
	if (count > val2 && val2 ) {
		return false;
	}
	return true;
}

/**
 * ¹®ÀÚ¿­À» Çü½ÄÈ­(3ÀÚ¸®¸¶´Ù ÄÞ¸¶ »ðÀÔ)µÈ ½ÄÀ¸·Î ¹ÝÈ¯ÇÕ´Ï´Ù.
 */
String.prototype.numberformat = function(val) {
	var str = this.replace(/,/g,"");
	var strLength = str.length;
	var val = val?val:3;
	if (val.isnumber) val = 3;

	if (strLength<=val) return str;
	var strOutput = "";
	var mod = val-(strLength%val);
	var i;
	
	for (i=0; i<strLength; i++) {
		strOutput+=str.charAt(i); 
		if (i < strLength - 1) {
			mod++; 
			if ((mod%val) == 0) { 
				strOutput +=","; 
				mod = 0; 
			}
		} 
	} 
	return strOutput;
}
