

// 2004.06.15 SoonBok ÃÖÃÊ ÀÛ¼º
// ÀÌ¸ÞÀÏ : Kerry74@Nate.com ( ¿Ø¸¸ÇÏ¸é ¿¬¶ôÇÏÁö ¸»°Í)
// ÀÚÁÖ ¾²ÀÌ´Â JavaScript µé ¸ðÀ½


function asclen(s)
{
	var i, len=0;
	for(i=0;i < s.length; i++) (s.charCodeAt(i) > 255)? len+=2:len++;
	return len;
}


function IsEMail(strEmail)
{
	  /** ±ÝÁö»çÇ×
	    - @°¡ 2°³ÀÌ»ó
	    - .ÀÌ ºÙ¾î¼­ ³ª¿À´Â °æ¿ì
	    -  @.³ª  .@ÀÌ Á¸ÀçÇÏ´Â °æ¿ì
	    - ¸ÇÃ³À½ÀÌ.ÀÎ °æ¿ì **/
	  var regDoNot = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
	  /** ÇÊ¼ö»çÇ×
	    - @ÀÌÀü¿¡ ÇÏ³ªÀÌ»óÀÇ ¹®ÀÚ°¡ ÀÖ¾î¾ß ÇÔ
	    - @°¡ ÇÏ³ªÀÖ¾î¾ß ÇÔ
	    - Domain¸í¿¡ .ÀÌ ÇÏ³ª ÀÌ»ó ÀÖ¾î¾ß ÇÔ
	    - Domain¸íÀÇ ¸¶Áö¸· ¹®ÀÚ´Â ¿µ¹®ÀÚ 2~3°³ÀÌ¾î¾ß ÇÔ **/
	  var regMust = /^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3})$/;
	  
	  if ( !regDoNot.test(strEmail) && regMust.test(strEmail) )
	      return true;
	  else
	      return false;
}

// ÇÑ±Û/¿µ¹® ½ºÆ®¸µ±æÀÌ ÇÑ±ÛÀº 2, ¿µ¹®Àº 1, strlen, string
function jsStrLen( pStr )
{
    var c;
    var nLength = 0;
    var sStr = new String(pStr);

    for(i=0; i < sStr.length; i++)
    {
        c = sStr.charAt(i);
        if(escape(c).length > 4 )   // ÇÑ±Û
            nLength += 2;
        else
            nLength++;
    }

    return nLength;
}


// Trim
function jsTrim(inputString)
{
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { 
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
   }
   return retValue; 
}

// Å©±â Á¶Á¤°¡´É popup
function new_win_open( url, name, w, h) 
{//¿ÞÂÊºÎÅÍ ÁÖ¼Ò, À©µµ¿ìÀÌ¸§, °¡·Î±æÀÌ, ¼¼·Î±æÀÌ
	var imgwnd = null
  type = "width=" + w + ", height=" + h + ", toolbar=no, resizable=yes, directories=no, scrollbars=yes";
  imgwnd = window.open( url, name, type);
  imgwnd.focus();
}

// Å©±â °íÁ¤ popup
function new_win_openfixed( url, name, w, h) 
{//¿ÞÂÊºÎÅÍ ÁÖ¼Ò, À©µµ¿ìÀÌ¸§, °¡·Î±æÀÌ, ¼¼·Î±æÀÌ
	var imgwnd = null
  type = "width=" + w + ", height=" + h + ", toolbar=no, resizable=no, directories=no, scrollbars=no";
  imgwnd = window.open( url, name, type);
  imgwnd.focus();
}

function ConfirmLink( sMsg, sLink)
{
	if( confirm( sMsg) == true) 
	{
		document.location = sLink;
	}else
	{
		return false;
	}
}

function ZoomImage( sImg)
{
	popup1 = window.open('/_platform/common/popImage.php?' + 'fname=' + sImg, 'popIMG','left=10, top=10, width=400,height=400,toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no');
	popup1.opener = self;	
}

/* »ç¿ëÇÒ¶§
<table id="daerew" width="300" height="150" border="0" radius="3" rborder="#999999" rbgcolor="#F8F8F8">
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td colspan="2">´ë·ùÄ¿¹Â´ÏÆ¼</td>
</tr>
</table>
<script>RoundTable("daerew");</script>
*/
function RoundTable(objID)
{
       var obj = document.getElementById(objID);
       var Parent, objTmp, Table, TBody, TR, TD;
       var bdcolor, bgcolor, Space;
       var trIDX, tdIDX, MAX;
       var styleWidth, styleHeight;

       // get parent node
       Parent = obj.parentNode;
       objTmp = document.createElement('SPAN');
       Parent.insertBefore(objTmp, obj);
       Parent.removeChild(obj);

       // get attribute
       bdcolor = obj.getAttribute('rborder');
       bgcolor = obj.getAttribute('rbgcolor');
       radius = parseInt(obj.getAttribute('radius'));
       if (radius == null || radius < 1) radius = 1;
       else if (radius > 6) radius = 6;

       MAX = radius * 2 + 1;
       
       /*
              create table {{
       */
       Table = document.createElement('TABLE');
       TBody = document.createElement('TBODY');

       Table.cellSpacing = 0;
       Table.cellPadding = 0;

       for (trIDX=0; trIDX < MAX; trIDX++) {
              TR = document.createElement('TR');
              Space = Math.abs(trIDX - parseInt(radius));
              for (tdIDX=0; tdIDX < MAX; tdIDX++) {
                     TD = document.createElement('TD');
                     
                     styleWidth = '1px'; styleHeight = '1px';
                     if (tdIDX == 0 || tdIDX == MAX - 1) styleHeight = null;
                     else if (trIDX == 0 || trIDX == MAX - 1) styleWidth = null;
                     else if (radius > 2) {
                            if (Math.abs(tdIDX - radius) == 1) styleWidth = '2px';
                            if (Math.abs(trIDX - radius) == 1) styleHeight = '2px';
                     }

                     if (styleWidth != null) TD.style.width = styleWidth;
                     if (styleHeight != null) TD.style.height = styleHeight;

                     if (Space == tdIDX || Space == MAX - tdIDX - 1) TD.style.backgroundColor = bdcolor;
                     else if (tdIDX > Space && Space < MAX - tdIDX - 1)  TD.style.backgroundColor = bgcolor;
                     
                     if (Space == 0 && tdIDX == radius) TD.appendChild(obj);
                     TR.appendChild(TD);
              }
              TBody.appendChild(TR);
       }

       /*
              }}
       */

       Table.appendChild(TBody);
       
       // insert table and remove original table
       Parent.insertBefore(Table, objTmp);
}

// ¼ýÀÚÀÎÁö °Ë»ç
// ¿¹: <input name="phone1" type="text" maxlength="4" onKeyPress="checknum();">
function checknum()
{
	
	if(event.keyCode<48 || event.keyCode>57 )
	{
		alert('¼ýÀÚ¸¸ ÀÔ·Â°¡´ÉÇÕ´Ï´Ù');
  	event.returnValue=0;
	}
}

function jsCheckAlpha( str)
{
	var i;
	var Alpha= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
	compstr = new String( str);
	for (i =0;i<compstr.length;i++) {
		if (Alpha.indexOf(compstr.substring(i,i+1))<0) {
			 return false;
		}
	}

	return true;
}
