//LTrim
String.prototype.ltrim = function()
{
	var re = /\s*((\S+\s*)*)/;
    return this.replace(re, "$1");
}

//RTrim
String.prototype.rtrim = function()
{
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}

//Trim
String.prototype.trim = function() 
{
	return this.ltrim().rtrim();
}

//ReplaceAll
String.prototype.replaceAll = function(str1, str2)
{
	var temp = this;

	while (1)
	{
		if( temp.indexOf(str1) != -1 )
			temp = temp.replace(str1, str2);
		else
			break;
	}

	return temp;
}

//3ÀÚ¸®¸¶´Ù ÄÞ¸¶Âï±â
function addCommas(strValue)
{ 
	var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
	
	while(objRegExp.test(strValue)) 
	{ 
		strValue = strValue.replace(objRegExp, '$1,$2'); 
	} 
	
	return strValue; 
}

//ºó¹®ÀÚ¿­ÀÎÁö¸¦ Ã¼Å©ÇÏ¿© ºó¹®ÀÚ¿­ÀÌ¸é true¸¦ ¹ÝÈ¯ÇÑ´Ù
function jsIsBlankValue(userValue1)
{
	userValue1 = userValue1.trim();
	userValue2 = userValue1.replaceAll("¡¡", "");
	
	if (userValue2.search(/\S/) == -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//¹®ÀÚ°¡ ÀÖ´ÂÁö¸¦ Ã¼Å©ÇÏ¿© ¹®ÀÚ°¡ ¾ø°í ¼ýÀÚ¸¸À¸·Î µÇ¾ú´Ù¸é true¸¦ ¹ÝÈ¯ÇÑ´Ù
function jsIsNumberValue(userValue1)
{
	if (userValue1.search(/\D/) == -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//³¯Â¥Ã¼Å©
function jsChkDate(user_date)
{
	var input_date, input_year, input_month, input_day, input_time;
	var comp_date, comp_year, comp_month, comp_day;
	var today_date, today_time;
	
	if (user_date.length==10)
	{
		if (user_date.search(/\d{4}-\d{2}-\d{2}/)==0)
		{
			input_year=parseFloat(user_date.substr(0,4));
			input_month=parseFloat(user_date.substr(5,2))-1;
			input_day=parseFloat(user_date.substr(8,2));
			
			input_date=new Date(input_year, input_month, input_day);
			
			comp_year=parseFloat(input_date.getFullYear());
			comp_month=parseFloat(input_date.getMonth()+1);
			comp_day=parseFloat(input_date.getDate());
			
			if ((input_year==comp_year) && ((input_month+1)==comp_month) && (input_day==comp_day))
			{
				today_date=new Date();
				
				today_time=Math.round(today_date.getTime()/(((1000*60)*60)*24));
				input_time=Math.round(input_date.getTime()/(((1000*60)*60)*24));
				
				if (input_time >= today_time)
				{
					return 1;
				}
				else
				{
					//¿À´Ã³¯Â¥º¸´Ù ÀÌÀü³¯Â¥
					return -1;
				}			
			}
			else
			{
				//¾ø´Â³¯Â¥
				return -2;
			}
		}
		else
		{
			//Àß¸øµÈ ³¯Â¥Çü½Ä
			return -3;
		}
	}
	else
	{
		//Àß¸øµÈ ³¯Â¥Çü½Ä
		return -3;
	}	
}

//ÀüÈ­¹øÈ£ ¼ýÀÚ, - Ã¼Å©
function jsChkTelNum(str)
{
	var num = '0123456789-~';

	for(i=0;i<str.length;i++)
	{
		chr = str.charAt(i);
		if (num.indexOf(chr) < 0)
		{
			return false;
		}
	}
	return true;
}

//¼ýÀÚ, - Ã¼Å©
function jsChkNum(str)
{
	var num = '0123456789';

	for(i=0;i<str.length;i++)
	{
		chr = str.charAt(i);
		if (num.indexOf(chr) < 0)
		{
			return false;
		}
	}
	return true;
}

//½Ã°£ ¼ýÀÚ, : Ã¼Å©
function jsChkTimeNum(str)
{
	var num = '0123456789:';

	for(i=0;i<str.length;i++)
	{
		chr = str.charAt(i);
		if (num.indexOf(chr) < 0)
		{
			return false;
		}
	}
	return true;
}

//¾ÆÀÌµð¿¡ ¿µ¹® ¹× ¼ýÀÚ, ÇÏÀÌÇÂ, ¾ð´õ¹Ù ¸¸ ÀÔ·Â
function jsChkId(str)
{
	var flag = 0, isnum = 0;

    for(var i = 0; i < str.length; i++)
    {
        if (str.charCodeAt(i) >= 45 && str.charCodeAt(i) <= 57 && str.charCodeAt(i) != 46 && str.charCodeAt(i) != 47)
        {
        	flag = 0;
        }
        else if ((str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 95 && str.charCodeAt(i) <= 122 && str.charCodeAt(i) != 96))
        {
        	flag = 0;
        	isnum = 1;
        }
        else
        {
            flag = 1;
            break;
    	}
    }

    if (flag == 1) return false;
    else if ((isnum == 0) && (1<str.length<8)) return false;
    else return true;
}	

//ÁÖ¹Î¹øÈ£ Ã¼Å©
function jsCheckRegNum(jumin)
{
	var  i = 0;
	var Sum = 0;
	var Mod = 0;
	var YearIn = 0;
	var MonthIn = 0;
	var DateIn = 0;
	var ID = "";

	ID = jumin;

	curDate = new Date();         //ÇöÀçÀÇ ³¯Â¥¸¦ »ý¼º
	curYear = curDate.getYear();  //»ý¼ºµÈ °´Ã¼·ÎºÎÅÍ ¿¬µµ(µÚÀÇ µÎÀÚ¸®)¸¦ ¾òÀ½
	curMonth = curDate.getMonth() + 1;  //ÇöÀçÀÇ ´ÞÀ» ¾òÀ½


		//ÁÖ¹Î¹øÈ£ 14ÀÚ¸®¸¦ ÇÑÀÚ¸®¾¿ Ã¼Å©
	 for( i=0 ; i < 13 ; i++ )
    	 {

	 	if( (ID.charAt(i) < "0") || (ID.charAt(i) > "9") )
   		{
			//alert("ºñÁ¤»óÀûÀÎ ÁÖ¹Îµî·Ï¹øÈ£ÀÔ´Ï´Ù!");
			            return false;
		 }

	 } // end for

	for( i = 0 ; i < 12 ; i++ )
	{
		if( i == 0)
 			YearIn+=parseInt(ID.charAt(i))*10;
		if( i == 1)
			 YearIn+=parseInt(ID.charAt(i));
		if( i == 2)
		              MonthIn+=parseInt(ID.charAt(i))*10;
	              if( i == 3)
		              MonthIn+=parseInt(ID.charAt(i));
		if( i == 4)
		              DateIn+=parseInt(ID.charAt(i))*10;
		if( i == 5)
		              DateIn+=parseInt(ID.charAt(i));
		if( i < 6) {
			  Sum+=parseInt(ID.charAt(i))*(i+2);
		}
		if( i > 5 && i < 8 ) {
		              Sum+=parseInt(ID.charAt(i))*(i+2);
		 }
		if( i > 7) {
		              Sum+=parseInt(ID.charAt(i))*(i-6);
		}
	  } //end for

	 Mod=11-(Sum%11);

	 if((11-(Sum%11))>=10) Mod-=10;

	 if( Mod!=parseInt(ID.charAt(12)) )
	 {
		 //alert("¿Ã¹Ù¸£Áö ¾ÊÀº ÁÖ¹Îµî·Ï¹øÈ£ ¹øÈ£ÀÔ´Ï´Ù! ");
		 return false;
	 }

	 if( MonthIn < 1 || MonthIn > 12 || DateIn < 1 || DateIn > 31 )
	 {
		//alert("¿Ã¹Ù¸£Áö ¾ÊÀº ÁÖ¹Îµî·Ï¹øÈ£  ¹øÈ£ÀÔ´Ï´Ù! ");
		return false;
	 }

	 if( (MonthIn ==4 || MonthIn == 6 || MonthIn == 9 || MonthIn == 11 ) && DateIn > 30 )
	 {
		 //alert("¿Ã¹Ù¸£Áö ¾ÊÀº ÁÖ¹Îµî·Ï¹øÈ£ ¹øÈ£ÀÔ´Ï´Ù! ");
		 return false;
	 }

	 if( MonthIn ==2 && DateIn > 29 )
	 {
		 //alert("¿Ã¹Ù¸£Áö ¾ÊÀº ÁÖ¹Îµî·Ï¹øÈ£ ¹øÈ£ÀÔ´Ï´Ù! ");
	     return false;
	 }

	return true;


} // end function checkNum

//ÀüÀÚ¿ìÆíÁÖ¼Ò Çü½ÄÃ¼Å©
function checkFormat(str,format) {
    if (str.search(format) == -1) {
        return true;
    }
	else if (str.charAt(str.indexOf('@')+1)=='.')
		return true;
    return false;
}

//ÀüÀÚ¿ìÆíÁÖ¼Ò Çü½ÄÃ¼Å©
function jsCheckMailForm(str) {
    var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
    return checkFormat(str,format);
}


//±ÛÀÚ¼ö
function jsGetLen(str) {
    var len;
    var temp;

    len = str.length;
    var tot_cnt = 0;

    for(k=0;k < len;k++){
        temp = str.charAt(k);
        if(escape(temp).length > 4)
            tot_cnt += 2;
        else
            tot_cnt++;
    }
    return tot_cnt;
}

function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie(name, value) 
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	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" : "");
}

function jsOverMenu(paraId)
{
	jsHiddenMenu();
	
	if (window.document.getElementById(paraId) != null)
	{
		window.document.getElementById(paraId).style.display = "inline";
	}
}

function jsHiddenMenu()
{
	window.document.getElementById("id_submenu1").style.display = "none";
	window.document.getElementById("id_submenu2").style.display = "none";
	window.document.getElementById("id_submenu3").style.display = "none";
	window.document.getElementById("id_submenu4").style.display = "none";
	window.document.getElementById("id_submenu5").style.display = "none";
	window.document.getElementById("id_submenu6").style.display = "none";
	window.document.getElementById("id_submenu7").style.display = "none";
}
