/*******************************************************************************
 1. ÇÁ·Î±×·¥ ID	: ticom001.js
 2. ÇÁ·Î±×·¥¸í 	: javascript °øÅë ¸ðµâ
 3. °³¿ä 		: GENERAL VALIDATION  CHECK  RETURN MESSAGE
 
 ------------------------------------------------------------------------------
 ¼öÁ¤ÀÏÀÚ		¼öÁ¤ÀÚ		¼öÁ¤ÀÌÀ¯			¼öÁ¤³»¿ë
 ------------------------------------------------------------------------------
 2002.08.03            		ÃÖÃÊÀÛ¼º
 ------------------------------------------------------------------------------
*******************************************************************************/

/*--------------------------------------------------
  ±â´É   : Check Null RETURN T/F
  INPUT  : check  data
  RETURN : true  -> NULL
           false -> NOT NULL
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckNull( toCheck ) 
{
     var chkstr = toCheck + "";
     var is_Space = true ;	 
	 
     if ( ( chkstr == "") || ( chkstr == null ) ) 
	   return( true );

     for ( j = 0 ; is_Space && ( j < chkstr.length ) ; j++)
     {
	     if( chkstr.substring( j , j+1 ) != " " ) 
         {			
	       is_Space = false ;
         }
     }     
     return ( is_Space );
} 

/*--------------------------------------------------
  ±â´É   : Check Invalid Character RETURN T/F
  INPUT  : check  data
  RETURN : true  -> NO INVALID CHARACTER
           false -> INCLUDE <, >, &, |, `, ", ~ 
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckInvalidChars( toCheck)
{
	var strobj = toCheck
	if (strobj.match(/[<|>|`|~|'|"|\&]/g))			
	{		
		return true;	
	}
	else
	{			
		return false;
	}
}

/*--------------------------------------------------
  ±â´É   : Check Number RETURN T/F
  INPUT  : toCheck  -> check data 
  RETURN : true  -> number
           false -> not number
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckNumber(toCheck) 
{
     var chkstr = toCheck+"" ;
     var isNum = true ;

     //if ( CheckNull(toCheck) ) 
     //   return false;

     for (j = 0 ; isNum && (j < toCheck.length) ; j++) 
     {
          if ((toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9"))
          {
             if ( toCheck.substring(j,j+1) == "-" || toCheck.substring(j,j+1) == "+")
             {
                if ( j != 0 ) 
                {
                   isNum = false;
                }
             }
             else
			   isNum = false;
		   }
     }

     if (chkstr == "+" || chkstr == "-") isNum = false;

     return isNum;
}

/*--------------------------------------------------
  ±â´É   : Check Integer RETURN T/F
  INPUT  : toCheck  -> check data 
  RETURN : true  -> Integer
           false -> not Integer
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckInteger(toCheck)
{
     var chkstr = toCheck+"" ;
     var isNum = true ;

     //if ( CheckNull(toCheck) ) 
     //   return false;

     for (j = 0; j < toCheck.length; j++) 
     {
          if ((toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9"))
          {
			   isNum = false;
			   break;
		  }
     }
     return isNum;
}


/*--------------------------------------------------
  ±â´É   : Check Float RETURN T/F
  INPUT  : toCheck  -> check data 
  RETURN : true  -> number
           false -> not number
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckFloat(toCheck)
{
     var chkstr = toCheck+"" ;
     var isFloat = true;

     var chkPoint = false;
     var chkMinus = false;

     if ( CheckNull(toCheck) )
     {
           return false;
     }

     for (j = 0 ; isFloat && (j < toCheck.length); j++)
     {
         if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9"))
         {

            if ( toCheck.substring(j,j+1) == "." )
            {
               if ( !chkPoint ) chkPoint = true ;
               else  isFloat = false ;
            }
            else if ( toCheck.substring(j,j+1) == "-" || toCheck.substring(j,j+1) == "+")
            {
               if ( ( j == 0 ) && ( !chkMinus ) ) 
					chkMinus = true ; 
               else 
					isFloat = false;
            }
            else 
				isFloat = false;
        }
    }

    return isFloat;
}

/*--------------------------------------------------
  ±â´É   : ÀÚ¸´¼ö check RETURN T/F
  INPUT  : toCheck  -> check data 
  RETURN : true  -> number
           false -> not number
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckPoint( toCheck , Positive , Negative )
{
     var strPos = toCheck + "" ;
     var isPoint = true ;

     if ( CheckFloat ( toCheck ) )
     {

		var inx = strPos.indexOf(".") ;

		if ( inx == -1 )
		{
			if ( strPos.length > parseInt(Positive) )
				isPoint = false ;
			else
				isPoint = true ;
		}
		else
		{
			var pos = strPos.substring( 0, inx ) ;
			var nev = strPos.substring(inx + 1) ;

			if ( pos.length > parseInt(Positive) )
				isPoint = false ;
			else if ( nev.length > parseInt(Negative) )
				isPoint = false ;
			else
				isPoint = true ;
		}
	}
	else if ( CheckNumber (toCheck) ) 
		isPoint = true;
	else 
		isPoint = false ;

	return isPoint ;
}

////////////////////////////////////////////////////////////////n
////////////    DATE  VALIDATION  CHECK    //////////////////////
/////////////////////////////////////////////////////////////////

/*--------------------------------------------------
  ±â´É   : calender¿¡¼­ »ç¿ëÇÒ ¿ùº° ¹è¿­¸¦ ¸¸µç´Ù.
  INPUT  : °¢ ÀÎÀÚÀÇ °ª 
  AUTHOR : e-biz
----------------------------------------------------*/
function MonthArray(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11) 
{
	this[0] = m0;
	this[1] = m1;
	this[2] = m2;
	this[3] = m3;
	this[4] = m4;
	this[5] = m5;
	this[6] = m6;
	this[7] = m7;
	this[8] = m8;
	this[9] = m9;
	this[10] = m10;
	this[11] = m11;
}


/*--------------------------------------------------
  ±â´É   : ³âµµ¸¦ checkÇÑ´Ù.
  INPUT  : toCheck  
  RETURN : NONE
     MSG : 
  AUTHOR : e-biz
----------------------------------------------------*/

function CheckYYYY(toCheck) 
{
	return ( ( toCheck.length == 4) && ( CheckNumber(toCheck)  ) && ( toCheck != "0000") );
}

/*--------------------------------------------------
  ±â´É   : ³â¿ùÀ» checkÇÑ´Ù.
  INPUT  : toCheck  
  RETURN : NONE
     MSG : 
  AUTHOR : H.G.Lim
----------------------------------------------------*/

function CheckYYYYMM(toCheck) 
{
     var isDate  = true ;

     if ( toCheck.length != 6 )
     {
          isDate = false ;
     }
     else
     {

           var yy = toCheck.substring(0,4) +"" ;
           var mm = toCheck.substring(4,6) +"" ;

           if ( !CheckYYYY(yy) )
              isDate = false ;
           else if ( !CheckMM(mm) )
              isDate = false ;
     }

     return isDate ;
}

/*--------------------------------------------------
  ±â´É   : ¿ùÀ» checkÇÑ´Ù.
  INPUT  : toCheck  
  RETURN :
    MSG  : 
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckMM(toCheck)
{
      return ((toCheck.length > 0) && (CheckNumber(toCheck)) && (0< eval(toCheck)) && (eval(toCheck) < 13));
}

/*--------------------------------------------------
  ±â´É   : ÀÏÀ» checkÇÑ´Ù.
  INPUT  : toCheck  
  RETURN : NONE
     MSG : 
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckDD(yyyy,mm,toCheck)
{
      var isYMD  = false;
      var monthDD= new MonthArray(31,28,31,30,31,30,31,31,30,31,30,31);
      var im     = eval(mm) - 1;
      if ( toCheck.length == 0 )  return false;
      if ( !CheckNumber(toCheck)  )  return false;
      var dd     = eval(toCheck);
      if ( ( (yyyy%4 == 0) && (yyyy%100 != 0) ) || (yyyy%400 == 0) )
      {
           monthDD[1] = 29;
      }
      if ( (0 < dd) && (dd <= monthDD[im]) ) isYMD = true;
           return isYMD;
}

/*--------------------------------------------------
  ±â´É   : ³¯Â¥¸¦ checkÇÑ´Ù.
  INPUT  : dateVal  
  RETURN : NONE
     MSG : 
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckDate( dateVal )
{

     var isDate  = true ;

     if ( dateVal.length != 8 )
     {
          isDate = false ;
     }
     else
     {

           var yy = dateVal.substring(0,4) +"" ;
           var mm = dateVal.substring(4,6) +"" ;
           var dd = dateVal.substring(6,8) +"" ;

           if ( !CheckYYYY(yy) )
              isDate = false ;
           else if ( !CheckMM(mm) )
              isDate = false ;
           else if ( !CheckDD (yy,mm,dd) )
              isDate = false ; 
     }

     return isDate ;

}

/*--------------------------------------------------
  ±â´É   : Check Time RETURN T/F
  INPUT  : check  time
  RETURN : true  -> TIME
           false -> NOT TIME
  AUTHOR : Kyung K.W
----------------------------------------------------*/
function CheckTime( toCheck ) 
{
     var chkstr  = toCheck + "";
    
     if ( ( chkstr == "") || ( chkstr == null ) ) 
	   return( false );

     var mm = chkstr.substring( 0 ,2 );
     var ss = chkstr.substring( 3 ,5 );

     if (( mm <= "23" ) && ( mm >= "00" ))
     {
         if (( ss <= "60" ) && ( ss >= "00" ))
         {
             if ( chkstr.substring( 2 ,3 ) == ":")  
             {
	             return( true );
             }
         }
     }
     return( false );
} 

/*--------------------------------------------------
  ±â´É   : Check ÁÖ¹Îµî·Ï¹øÈ£ RETURN T/F
  INPUT  : toCheck
  RETURN : true  -> ¿Ã¹Ù¸¥ ¹øÈ£
           false -> 
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckJumin(toCheck) {
    var isJumin = true;
    if ( CheckNull(toCheck) ) {
          return false;
    } else if ( toCheck.length < 13 || toCheck.length > 13 ) {
          return false;
    } else if ( toCheck.substring(2,3) > "1" || toCheck.substring(6,7) > "2" || toCheck.substring(6,7) == "0" ) {
          return false;
    } else if ( toCheck.substring(2,3) == "1" && toCheck.substring(3,4) > "2" ){
          return false;
    } else if (!(toCheck.substring(4,6) >= "01" && toCheck.substring(4,6) <= "31")){
          return false;
    }
   for (j = 0; isJumin && (j < toCheck.length); j++) {
       if ( ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9")) ) {
           isJumin = false;
       }
   }
   return isJumin;
}

/*--------------------------------------------------
  ±â´É   : Check »ç¾÷ÀÚ µî·Ï¹øÈ£ RETURN T/F
  INPUT  : toCheck
  RETURN : true  -> ¿Ã¹Ù¸¥ ¹øÈ£
           false -> 
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckSaupJa(toCheck) {
    var isSaupJa = true;
    if ( CheckNull(toCheck) ) {
          return false;
    } else if ( toCheck.length < 10 || toCheck.length > 10 ) {
          return false;
    }
    for (j = 0; isSaupJa && (j < toCheck.length); j++) {
       if ( ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9")) ) {
           isSaupJa = false;
       }
    }
    return isSaupJa;
}

/*--------------------------------------------------
  ±â´É   : E-Mail¸¦ checkÇÑ´Ù.
  INPUT  : emailVal  
  RETURN : NONE
     MSG : 
  AUTHOR : e-biz
----------------------------------------------------*/
function CheckEmail( emailVal )
{
     if ( CheckNull(emailVal) ) return true;
    
     var inx1 = emailVal.indexOf("@") ;
     var inx2 = emailVal.indexOf(".") ;

     if ( inx1 <= 0 || inx2 <= 0 || inx1 == emailVal.length - 1 || inx1 > inx2 ) return false;

     return true ;
}

/*--------------------------------------------------
  ±â´É   : °ø¹éÀ» Ã¼Å©ÇÑ´Ù
  INPUT  : strControlName, strMsg
  RETURN : String
     MSG : 
  AUTHOR : h64d5791
----------------------------------------------------*/
function CheckBlank(strControlName, strMsg)
{	
	if (strControlName != "" && strMsg != "")
	{
		if (strControlName = null)
			alert(strMsg);
	}
}

/*-----------------------------------------------------------------------------
 1. ÇÔ¼ö¸í 	: ChangeDate
 2. °³¿ä 	: ³¯Â¥¸¦ º¸¿©ÁÙ¶§ ÇÏÀÌÇÂ(-) ¾ø´Â ³¯Â¥¸¦ ÇÏÀÌÇÂÀ» ³Ö¾î¼­ ³¯Â¥ Çü½ÄÀ¸·Î ¸¸µé¾îÁØ´Ù.
 3. ÀÔ·Â 	: 
	1) Parameters
		A. pstrDate 		: ³¯Â¥
 4. ¸®ÅÏ°ª 	: ÇÏÀÌÇÂÇü½ÄÀÇ ³¯Â¥
-----------------------------------------------------------------------------*/

function ChangeDate(strControlName, strMsg)
{	
	if (strControlName != "" && strMsg != "")
	{
		if (strControlName = null)
			alert(strMsg);
	}
}


function LenUnicode(pstrUnicode)
{
	var intLenCnt = 0;
	var i;
	for (i=0; i<pstrUnicode.length; i++) 
		if (pstrUnicode.charCodeAt(i) < 128) 
			intLenCnt += 1;
		else 
			intLenCnt += 2;
	return intLenCnt
}

/*--------------------------------------------------
 1. ÇÔ¼ö¸í	: setCookie
 2. °³¿ä	: cookie¸¦ ¼³Á¤ÇÑ´Ù.
 3. ÀÔ·Â	:
 4. ¸®ÅÏ°ª	: ¾øÀ½
----------------------------------------------------*/

function setCookie(name, value){
	var argc = setCookie.arguments.length
	var argv = setCookie.arguments
	var expires = (argc > 2) ? argv[2] : null
	var path = (argc > 3) ? argv[3] : null
	var domain = (argc > 4) ? argv[4] : null
	var secure = (argc > 5) ? argv[5] : false

	document.cookie = name + "=" + escape(value) +
			  ((expires==null)? " " : ("; expires=" + expires.toGMTString())) +
			  ((path==null)? " " : ("; path=" + path)) +
			  ((domain==null)? " " : ("; domain=" + domain)) +
			  ((secure==true) ? "; secure" : " ")
}


/*--------------------------------------------------
 1. ÇÔ¼ö¸í	: getCookie
 2. °³¿ä	: cookie °ªÀ» °¡Á®¿Â´Ù. 
 3. ÀÔ·Â	:
 4. ¸®ÅÏ°ª	: ¾øÀ½
----------------------------------------------------*/

function getCookie(name){
	var Found = false
	var start, end
	var i=0

	while(i <= document.cookie.length){
		start = i;
		end = start + name.length
		if(document.cookie.substring(start, end) == name){
			Found=true
			break
		}
		i++
	}

	if(Found == true){
		start = end + 1
		end = document.cookie.indexOf(";", start)
		if(end < start)
			end=document.cookie.length
		return document.cookie.substring(start, end)
	}
	return " "
}

/*--------------------------------------------------
 1. ÇÔ¼ö¸í	: delCookie
 2. °³¿ä	: cookie °ªÀ» Á¦°ÅÇÑ´Ù. 
 3. ÀÔ·Â	:
 4. ¸®ÅÏ°ª	: ¾øÀ½
----------------------------------------------------*/

function delCookie(name){
	var today = new Date()
	today.setTime(today.getTime() - 1)
	var value = getCookie(name)
	if(value != " ")
		document.cookie = name + "=" + value + "; expires=" + today.toGMTString()
}
