/*=======================================================================
// ÆÄ ÀÏ ¸í : CommonPrototype.js
// ÀÛ ¼º ÀÚ : ±èÈñÅÂ
// ÀÛ ¼º ÀÏ : 2008/04/15
// ¼³     ¸í : ÇÁ·ÎÅä Å¸ÀÔ ½ºÅ©¸³Æ® Ãß°¡ Á¤ÀÇ
=======================================================================*/
/* ¿µ¹®ÀÔ·Â Ã¼Å© */
String.prototype.isEng = function() 
{
  if (this.search(/^[^A-Za-z]/) == -1)
	 return true;
  else
	 return false;
}
/* ¿µ¹®,¼ýÀÚ ÀÔ·ÂÃ¼Å© */
String.prototype.isEngNum = function() 
{
  if (this.search(/[^A-Za-z0-9]/) == -1)
	 return true;
  else
	 return false;
}
/* °ø¹éÁ¦°Å */
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.isNumber = function() 
{
  if (this.search(/[^0-9]/) == -1)
	 return true;
  else
	 return false;
}
/* E-Mail Ã¼Å© */
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.bytes = function() 
{
	var str = this;
	var l = 0;
	for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
	return l;
}
/* Replace */
String.prototype.replaceAll = function(oldValue, newValue) 
{
	
	var retValue = this;
	
	while (retValue.indexOf(oldValue) >= 0)
	{
		retValue = retValue.replace(oldValue, newValue);
	}
	
	return retValue;
}
