//==================================================================
//	ÇÔ ¼ö ¸í : countBytes()
//	ÀÛ ¼º ÀÚ : ±èÁ¾À±
//	±â	  ´É : ÀÔ·ÂµÈ text byte	count
//	Æä·¯¹ÌÅÍ : e ->	ÀÔ·Â»óÀÚ °³Ã¼
//			   maxs	-> ÃÖ´ë	ÀÔ·Â °¡´ÉÇÑ	byte
//			   tg -> Ç¥½Ã ´ë»ó
//==================================================================
function countBytes(e, maxs, tg)
{
	var	bytesLength	= 0;
	var	validMsgLength = 0;
	var	validBytesLength = 0;

	var	ByteView = document.getElementById(tg);

	for	(i = 0 ; i < e.value.length	; i++)
	{
		var	oneChar	= e.value.charAt(i);

		if ( escape(oneChar).length	> 4	)
		{
			bytesLength	+= 2;
		}
		else if	( oneChar != '\r' )
		{
			bytesLength++;
		}

		if ( bytesLength <=	maxs )
		{
			validMsgLength = i + 1;
			validBytesLength = bytesLength;
		}
	}

	if ( bytesLength > maxs	)
	{
		alert(maxs +"byteÀÌ»ó ÀÔ·Â ÇÏ½Ç¼ö ¾ø½À´Ï´Ù");
		var	returnVal =	e.value.substr(0, validMsgLength);
		e.value	= returnVal;
		bytesLength	= maxs;
	}

	bytesVal = bytesLength;
	ByteView.innerHTML = bytesVal;
}

//===================================================================================
//	ÇÔ ¼ö ¸í : openBW()
//	ÀÛ ¼º ÀÚ : ±èÁ¾À±
//	±â	  ´É : ÆË¾÷À» ¶ç¿öÁÜ
//	Æä·¯¹ÌÅÍ : theURL -> ÆË¾÷ ¶ç¿ï ÆäÀÌÁö °æ·Î
//			   winName -> ÆË¾÷ ¸í¸í
//			   w ->	ÆË¾÷ Ã¢	³ÐÀÌ
//			   h ->	ÆË¾÷ Ã¢	³ôÀÌ
//			   scroll -> scroll	À¯¹«
//			   resize -> resize	À¯¹«
//			   l ->	ÆË¾÷ À§Ä¡ left (±âº» Áß¾Ó)
//			   t ->	ÆË¾÷ À§Ä¡ top (±âº»	Áß¾Ó)
//===================================================================================
function openBW(theURL,	winName, w,	h, scroll, resize, l, t) {
	var	winl = (screen.width-w)/2;
	var	wint = (screen.height-h)/2;
	if ( l ) winl =	l;
	if ( t ) wint =	t

	var	setting	= 'height='+h+','+
				  'width='+w+','+
				  'top='+wint+','+
				  'left='+winl+','+
				  'scrollbars='+scroll+','+
				  'resizable='+resize;

	win	= window.open(theURL, winName, setting);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}


//===================================================================================
//	ÇÔ ¼ö ¸í : valueNumSize()
//	ÀÛ ¼º ÀÚ : ±èÁ¾À±
//	±â	  ´É : frm¿¡ ÀÔ·ÂµÈ	°ªÀ» num°ú ºñ±³ÇÏ¿©	¼öÄ¡ ±×	ÀÌ»óÀÌ µÇ´ÂÁö, È¤Àº	¼ýÀÚÀÎÁö¸¦ °Ë¼ö
//	Æä·¯¹ÌÅÍ : frm -> Æû °´Ã¼
//			   num -> ¼ýÀÚ
//===================================================================================
function valueNumSize(frm, num, msg)
{
	if ( !frm.value	)
	{
		alert(msg + " °ªÀ» ÀÔ·ÂÇÏ¿© ÁÖ½Ê½Ã¿À");
		frm.focus();
		return true;
	}

	if ( num )
	{
		if ( parseInt(frm.value) <=	num	)
		{
			alert(num +"ÀÌ»óÀÇ ¼ö¸¦	ÀÔ·ÂÇÏ¿© ÁÖ½Ê½Ã¿À");
			frm.focus();
			return true;
		}
	}

	if ( isNaN(frm.value) )
	{
		alert("¼ýÀÚ¸¸ ÀÔ·Â °¡´ÉÇÕ´Ï´Ù");
		frm.value =	"";
		frm.focus();
		return true;
	}
}

//===================================================================================
//	ÇÔ ¼ö ¸í : checkValue()
//	ÀÛ ¼º ÀÚ : ±èÁ¾À±
//	±â	  ´É : ÀÔ·Â	Æû ¹«°á¼º °Ë¼ö
//	Æä·¯¹ÌÅÍ : frm -> Æû °´Ã¼
//			   msg -> alert¸Þ½ÃÁö
//===================================================================================
function checkValue(frm, msg)
{
	switch ( frm.type )
	{
		case "select-one"	: msg =	msg	+ " ¼±ÅÃÇÏ¿© ÁÖ½Ê½Ã¿À";	break;
		case "hidden"		: msg =	msg	+ "ÇÏ¿© ÁÖ½Ê½Ã¿À"; break;
		case "file"			: msg =	msg	+ " ¼±ÅÃÇÏ¿© ÁÖ½Ê½Ã¿À";	break;
		default				: msg =	msg	+ " ÀÔ·ÂÇÏ¿© ÁÖ½Ê½Ã¿À";	break;
	}

	if ( !strim(frm.value) )
	{
		alert(msg);
		if ( frm.type != "hidden" && !frm.readOnly )	frm.focus();
		return true;
	}
}

//===================================================================================
//	ÇÔ ¼ö ¸í : DateDiffCheck()
//	ÀÛ ¼º ÀÚ : ±èÁ¾À±
//	±â	  ´É : ³¯Â¥	ÀÔ·Â Æû	°Ë¼ö
//	Æä·¯¹ÌÅÍ : svalue -> ½ÃÀÛ ÀÏ
//			   evalue -> Á¾·áÀÏ
//			   msg -> alert	¸Þ½ÃÁö
//			   frm -> Æû °´Ã¼
//===================================================================================
function DateDiffCheck(svalue, evalue, msg,	frm)
{
	var	sdate =	svalue.split("-");
	var	edate =	evalue.split("-");

	var	getDateS = new Date(sdate[0], sdate[1], sdate[2]);
	var	getDateE = new Date(edate[0], edate[1], edate[2]);

	if ( getDateS > getDateE )
	{
		alert(msg + " ½ÃÀÛÀÏÀÌ Á¾·áÀÏº¸´Ù ´ÊÀ» ¼ö ¾ø½À´Ï´Ù");
		if ( frm.type != "hidden" && !frm.readOnly )	frm.focus();
		return true;
	}
}

//=========================================================================
//	ÇÔ¼ö ¸í		: set_comma()
//	ÇÔ¼ö ¼³¸í	: °ª¿¡ ´ëÇÑ	Ãµ´ÜÀ§ , ¸¦	Âï¾îÁØ´Ù.
//	Æä·¯¹ÌÅÍ	: val =	intÇü °ª
//=========================================================================
function set_comma(val)	{

	str	= ""+str+"";
	var	retValue = "";
	for	( i	= 0	; i	< str.length ; i++ )
	{
		if ( i > 0 && (	i %	3 )	== 0 ) {
			retValue = str.charAt(str.length - i -1) + "," + retValue;
		} else {
			retValue = str.charAt(str.length - i -1) + retValue;
		}
	}
	return retValue;
}

//=========================================================================
//	ÇÔ¼ö ¸í		: number_format()
//	ÇÔ¼ö ¼³¸í	: ¹®ÀÚ¿­(intÇü)¿¡ Ãµ´ÜÀ§·Î ,¸¦ Âï¾î	¸®ÅÏ
//	Æä·¯¹ÌÅÍ	: str -> ¹®ÀÚ¿­(¼ýÀÚ)
//=========================================================================
function number_set_comma(num) {
	//num =	num.replace(/,/g , "");
	var	num_str	= num.toString();
	var	result = "";

	if ( isNaN(num)	) {
		alert("¼ýÀÚ¸¦ ÀÔ·ÂÇÏ¼¼¿ä");
	} else {
		for( i = 0 ; i < num_str.length	; i++ )	{
			var	tmp	= num_str.length - (i +	1);
			if ( i % 3 == 0	&& i !=	0) result =	','	+ result;
			result = num_str.charAt(tmp) + result;
		}
	}

	return result;
}

//=========================================================================
//	ÇÔ¼ö ¼³¸í	: ¿ìÆí¹øÈ£ Ã£±â ÇÔ¼ö(zipcode_search, zipcode_input ¼ÂÆ®)
/*
	1. ¾Æ·¡ ¿Í °°ÀÌ ¼³Á¤ (Style Sheet´Â »ç¿ëÀÚ ÀÓÀÇ ¼³Á¤)
		<style type="text/css">
			li {float:left}
			ul {margin-left:0; margin-bottom:5; margin-top:6}
		</style>

	2. li·Î ÁÖ¼Ò ÀÔ·Â ºÎºÐÀ» °¨½ÎÁÖ°í ID¸¦ ¼³Á¤ ÇÏ¿© ÁØ´Ù
		<li id="¼³Á¤ ¾ÆÀÌµð">
			<ul>
				<input name="¿ìÆí¹øÈ£1" type="text" style="cursor:hand" onclick="zipcode_search()" readonly> -
				<input name="¿ìÆí¹øÈ£2" type="text" style="cursor:hand" onclick="zipcode_search()" readonly>
				<img src="ÀÌ¹ÌÁö ÁÖ¼Ò" style="cursor:hand" onclick="zipcode_search()">
			</ul>
			<ul><input name="ÁÖ¼Ò" type="text" readonly></ul>
			<ul><input name="±âÅ¸ »ç¿ëÀÚ ÀÔ·Â ÁÖ¼Ò" size="50"></ul>
		</li>
	3. ¿ìÆí¹øÈ£¸¦ °Ë»öÇÒ ÆäÀÌÁö¸¦ ¼³Á¤ÇÑ´Ù
	4. popup ¼³Á¤ ÇÔ¼ö´Â »ç¿ëÀÚ¿¡ ÀÇÇØ Á¤ÇÑ´Ù
	5. zipcode_search(¼³Á¤¾ÆÀÌµð)
	6. zipcode_input(¿ìÆí¹øÈ£, ÁÖ¼Ò, ¼³Á¤¾ÆÀÌµð)
	7. ÁÖ¼Ò °Ë»ö½Ã ename°ªÀ» ÀÒÁö ¾Êµµ·Ï hiddenÇÊµå»ç¿ë ÇÏ¿© ename°ª À¯Áö
*/
//=========================================================================
function zipcode_search(ename)
{
	var sURL = "/common/zipcode_search.asp?EleName="+ ename;
	openBW(sURL, "_zip", 400, 250, 'yes', 'no');
}

function zipcode_input(zipcode, addr, ename)
{
	var getEle = opener.document.getElementById(ename);
	var getIpt = getEle.getElementsByTagName("INPUT");
	spZip = zipcode.split("-");

	getIpt[0].value = spZip[0];
	getIpt[1].value = spZip[1];
	getIpt[2].value = addr;
	getIpt[3].focus();

	self.close();
}

//=========================================================================
//	ÇÔ¼ö ¸í		: js_replace()
//	ÇÔ¼ö ¼³¸í	: ´ë»ó ¹®ÀÚ¿­À» ¿øÇÏ´Â ¹®ÀÚ¿­·Î º¯°æÇÏ¿© ¸®ÅÏ
//	Æä·¯¹ÌÅÍ	: str -> ¹®ÀÚ¿­
//				  t -> ´ë»ó ¹®ÀÚ
//				  c -> º¯°æ ¹®ÀÚ
//=========================================================================
function js_replace(str, t, c)
{
	var Target = str.split(t);
	var returnVal = "";

	for ( var i = 0 ; i < Target.length ; i++ )
	{
		returnVal += Target[i].toString() + c;
	}

	return returnVal;
}

function strim(str) {//trimÇÔ¼ö
	var index, len;

	while(true) {
		index = str.indexOf(" ");
		if(index == -1) {
			break;
		}
		len = str.length;

		str = str.substring(0, index) + str.substring((index + 1), len);
	}

	return str;
}

function LoginChk()
{
	var frm = document.loginForm;

	if ( checkValue(frm.ComID, "¾ÆÀÌµð¸¦") ) return false;
	if ( checkValue(frm.ComPw, "ºñ¹Ð¹øÈ£¸¦") ) return false;

	frm.submit();
}