//¿£ÅÍÅ° Ã¼Å©
function enterKey() {
	if ( event.keyCode==13 ) {
		CheckLogin();
	}

	return;
}

//¿£ÅÍÅ° Ã¼Å©
function enterKey2() {
	if ( event.keyCode==13 ) {
		CheckLogin2();
	}

	return;
}

//Ã¼Å©¹Ú½º ÀüÃ¼ ¼±ÅÃ
function selectAll() {
	checking = 0;
	for ( i = 0; i < document.mainform.elements.length; i++ ) {
		var obj = document.mainform.elements[i];
		if ( obj.type == 'checkbox' ) { 
			if ( obj.name == 'checkall' ) checking = obj.checked;
			else if ( obj.name == "check[]" )
			{
				if ( checking )	obj.checked = true;
				else					obj.checked = false;
			}
		}
	}
}

function comp_val( pmsg, obj ) { 
	if ( obj.value == pmsg ) {
		obj.value = "";
	}
}

//È®´ëÀÌ¹ÌÁö º¸±â.
function imgview( src, title ) {
	window.open( "/cboard/enlargeimage.php?img="+src+"&title="+title, '', 'directories=0,menubar=0,resizable=1,scrollbars=1,left=0,top=0,status=0' );
}

function imgview02( src, title, area, kind, b_id, bid, gubun ) {
	window.open( "/cboard/enlargeimage2.php?img="+src+"&title="+title+"&area="+area+"&kind="+kind+"&b_id="+b_id+"&bid="+bid+"&gubun="+gubun, '', 'directories=0,menubar=0,resizable=1,scrollbars=1,left=0,top=0,status=0' );
}

function trim( str ) {
   /* ¿ÞÂÊ Æ®¸²   */
   len = str.length;
   for(i=0;i<len;i++) {
      if(str.substring(0,1) == " ") {
         str = str.substring(1);
      } else {
         break;
      }
   }

   /* ¿À¸¥ÂÊ Æ®¸²   */
   len = str.length;
   for(i=len;i>0;i--)  {
      if(str.substring(i-1) == " ") {
         str = str.substring(0,i-1);
      } else {
         break;
      }
   }

   return str;
}

function checkSelected() {
	checked = false;
	for ( i = 0; i < document.mainform.elements.length; i++ ) {
		var obj = document.mainform.elements[i];
		if ( obj.type == 'checkbox' ) {
			if ( obj.name != 'checkall' && obj.checked ) checked = true;
		}
	}

	if ( !checked ) {
		alert( "¼±ÅÃµÈ °ªÀÌ ¾ø½À´Ï´Ù." );
		return false;
	}

	return true;
}

//Ã¼Å©¹Ú½º ¼±ÅÃµÈ °ªÀÌ ÀÖ´ÂÁö Ã¼Å©
/*function checkSelected( type ) {
	checked = false;
	obj = document.getElementById( "check[]" );

	if ( !obj ) {
		if ( type == "" ) alert( "¼±ÅÃµÈ °ªÀÌ ¾ø½À´Ï´Ù." );
		return false;
	}
	
	if ( obj.length == null && obj.checked ) checked = true;

	for ( i = 0; i < obj.length; i++ ) {
		if ( obj[i].checked ) {
			checked = true;
			break;
		}
	}
	
	if ( !checked ) {
		if ( type == "" ) alert( "¼±ÅÃµÈ °ªÀÌ ¾ø½À´Ï´Ù." );
		return false;
	}

	return true;
}*/

//pid : ¹°Ç°ÄÚµå, multiple : I/M ´Ù¼öÇ×¸ñ ±¸ºÐ, type : ÀÏ¹Ý/¸ÅÀå
function addCart( pid, multiple, type ) { 
	var action_url = "../product/goods_shoppingbag_process.php?s_mode=" + multiple + "&pid=" + pid + "&type=" + type;
	if ( type == 'H' ) {
		//window.open( '', 'host_shop_bag', 'width=850,height=600,status=1,scrollbars=1,resizable=1' );
		document.mainform.action = action_url;
		//document.mainform.target = "host_shop_bag";
		document.mainform.submit();
	} else { 
		document.mainform.action = action_url;
		document.mainform.submit();	
	}
}

function changeImgSize( obj, size ) { 
	if ( obj.width > size ) obj.width = size;
}

//ÀÌ¹ÌÁö ·Îµù ½ÇÆÐ½Ã ´ëÃ¼ ÀÌ¹ÌÁö 
function imgErrorHandler ( obj, vwidth, vheight  ) { 
	var altSrc = "/cboard/skin_dir/images/noimg.gif"; 
	obj.src = altSrc; 
	obj.width = vwidth;
	if ( vheight != "" ) obj.height = vheight;
}

//ÆäÀÌÁö ÀÌµ¿
function movePage( page_obj, pageNum ) {
	var obj = eval( "document.mainform."+page_obj );
	obj.value = pageNum;
	document.mainform.submit();
}

//Æ¯Á¤ ÀÌ¹ÌÁö ¿ä¼Ò src º¯°æ½ÃÅ°±â.
function changeImg( img_name, img_src ) { 
	document.getElementById( img_name ).src = img_src;
}

//Æ¯Á¤ div º¸¿©ÁÖ±â 
function ShowDiv( div_id, showhide ) {
	var obj = eval( document.getElementById( div_id ) );

	if ( showhide ) {
		obj.style.top  = event.y + document.body.scrollTop - 5;
		obj.style.left = event.x - 150;
		obj.style.display = "";
	} else { 
		obj.style.display = "none";
	}
}

//when printing
function showhideDIV( obj_name, act ) {
	var a = eval( document.getElementById.item( obj_name ) );

	if ( act == 1 ) act_str = "";
	else			act_str = "none";

	if ( a != null ) {
		if ( a.length != null ) {
			for ( i=0; i< a.length; i++ ) 
				a(i).style.display = act_str;			
		}
	}
}

//Ãâ·ÂÇÒ ³»¿ë
//msg : Ãâ·Â ³»¿ë, type : 1 - ´Ü¼ø ¸Þ¼¼Áö, 2 - htmlÇü½Ä
function showMSG( msg, type ){
	if ( msg == "" ) return;

	var _tmpx,_tmpy, marginx, marginy;
	_tmpx = event.clientX;
	_tmpy = event.clientY;
	_marginx = document.body.clientWidth - _tmpx;
	_marginy = document.body.clientHeight - _tmpy ;
	if(_marginx < 0)
		_tmpx = event.clientX + document.body.scrollLeft + _marginx ;
	else
		_tmpx = event.clientX + document.body.scrollLeft ;
	if(_marginy < 0)
		_tmpy = event.clientY + document.body.scrollTop + _marginy +20;
	else
		_tmpy = event.clientY + document.body.scrollTop ;
	objMsg.style.posLeft=_tmpx + 0;
	objMsg.style.posTop=_tmpy + 5;
	
	//ÀÏ¹Ý °£´Ü ¸Þ¼¼Áö Ãâ·Â½Ã
	if ( type == 1 ) {
		var strHTML = "";
		//strHTML =  "<table width='200' border='1' cellspacing='3' cellpadding='2' bordercolor='#4A4A8E'>";
		//strHTML += " <tr> ";
		//strHTML += "	<td height='22' bgcolor='#FB91D9' class=text><b>"+msg+"</b></td>";	
		//strHTML += " </tr>";
		//strHTML += "</table>";

		strHTML =  "<table width='200' border='0' cellpadding='3' cellspacing='1' bgcolor='0FB657'>";
		strHTML +=	"<tr> ";
		strHTML +=		"<td valign='top' bgcolor='F0F0F0'>";
		strHTML +=			"<table width='100%' border='0' cellpadding='0' cellspacing='10' bgcolor='#FFFFFF'>";
		strHTML +=				"<tr> ";
		strHTML +=					"<td valign='top'>";
		strHTML +=						"<table width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='EAE6E6'>";
		strHTML +=							"<tr bgcolor='F6F6F6'> ";
		strHTML +=								"<td><div align='center'>"+msg+"</div></td>";
		strHTML +=							"</tr>";
		strHTML +=						"</table>";
		strHTML +=					"</td></tr></table></td></tr></table>";
		

	//»ó¼¼ µðÀÚÀÎ Ãâ·Â½Ã
	} else {
		strHTML = msg;
	}
	objMsg.innerHTML = strHTML;
	objMsg.style.visibility = '';
}

function hideMSG() {
	objMsg.style.visibility = 'hidden';
}

function newWin( url, name, width, height, param ) {
	window.open( url, name, "width="+width+",height="+height+",resizable=0,status=0"+param );
}

//ÇØ´ç ¿ÀºêÁ§Æ®ÀÇ ¼ø¼­ °ª ¸®ÅÏ
function indexOfObj( tobj ) {
	var checking = true;
	var arryObj  = document.getElementById( tobj.name );
	for ( i = 0; i < arryObj.length; i++ )
		if ( arryObj[i] == tobj ) return i;
}

//Æ¯Á¤ °´Ã¼ÀÇ value °ªÀ¸·Î ÀÎµ¦½º Ã£±â
function indexOfObjByVal( value, objName ) {
	var checking = true;
	var arryObj = objName;

	for ( i = 0; i < arryObj.length; i++ ) {
		var obj = arryObj[i];
		if ( obj.value == value ) { 
			return i;
		}
	}
}

function CheckType( obj, type ) {
	var pos = obj.value.lastIndexOf( "." );
	var value = obj.value.substring( pos + 1, obj.value.length );
	
	value = value.toLowerCase();
	var matched = false;
	if ( type == 'I' ) { 	
		//if((/(.jpg|.jpeg|.gif|.png)$/i).test(fname))
		//allowed_img_ext = new Array( 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'ico', 'png' );		
		allowed_img_ext = new Array( 'jpg', 'gif' );		
		for ( i = 0; i < allowed_img_ext.length; i++ ) {
			if ( allowed_img_ext[i] == value ) {
				matched = true;
				break;
			}
		}
		
		if ( !matched ) {
			alert( 'Çã¿ë°¡´ÉÇÑ ÀÌ¹ÌÁö ÆÄÀÏÀÌ ¾Æ´Õ´Ï´Ù.\n\n´ÙÀ½°ú °°Àº È®ÀåÀÚÀÇ ÆÄÀÏÀ» ¿Ã·ÁÁÖ½Ê½Ã¿ä.\n' + allowed_img_ext.toString() );			
		}
	} else {
		banned_file_ext = new Array( 'php', 'php3', 'inc', 'html', 'htm', 'asp', 'jsp' );
		for ( i = 0; i < banned_file_ext.length; i++ ) {
			if ( banned_file_ext[i] == value ) {
				alert( 'Çã¿ë°¡´ÉÇÑ ÆÄÀÏÀÌ ¾Æ´Õ´Ï´Ù.\n\n´ÙÀ½°ú °°Àº È®ÀåÀÚÀÇ ÆÄÀÏÀº ¿Ã¸±¼ö ¾ø½À´Ï´Ù.\n' + banned_file_ext.toString() );				
				matched = false;
				break;
			}
		}
	}

	if ( !matched ) {		
		obj.value = "";
	}
}

// 0 Áý¾î ³Ö±â
function padZero(num) {
	return (num < 10)? '0' + num : num;
}

// Å×½ºÆ® ÇØ º¸±â!
function CkImageVal() {
	var oInput = event.srcElement;
	var fname = oInput.value;
	if((/(.jpg|.jpeg|.gif|.png)$/i).test(fname))
		oInput.parentElement.children[0].src = fname;
	else
		alert('ÀÌ¹ÌÁö´Â gif, jpg, png ÆÄÀÏ¸¸ °¡´ÉÇÕ´Ï´Ù.');

	//<input type=file name=AttFile[] size=40 onChange="CkImageVal()" class=textidpass>
}

// ------------------------------------------------------------------
// Function    : check_len(aro_name)
// Description : ÀÔ·ÂÇÑ ±ÛÀÚ¼ö¸¦ Ã¼Å© (°³Çà¹®ÀÚ Æ÷ÇÔ)
// Argument    : aro_name - Ã¼Å©ÇÒ Obj, ari_max - Á¦ÇÑ ±ÛÀÚ¼ö byte
// Return      : 
// ------------------------------------------------------------------
function check_len( aro_name,ari_max ) {
   var ls_str     = aro_name.value;
   var li_str_len = ls_str.length;

   var li_max      = ari_max;
   var i           = 0;  // for¹®¿¡ »ç¿ë
   var li_byte     = 0;  // ÇÑ±ÛÀÏ°æ¿ì´Â 2 ±×¹Ü¿¡´Â 1À» ´õÇÔ
   var li_len      = 0;  // substringÇÏ±â À§ÇØ¼­ »ç¿ë
   var ls_one_char = ""; // ÇÑ±ÛÀÚ¾¿ °Ë»çÇÑ´Ù
   var ls_str2     = ""; // ±ÛÀÚ¼ö¸¦ ÃÊ°úÇÏ¸é Á¦ÇÑÇÒ¼ö ±ÛÀÚÀü±îÁö¸¸ º¸¿©ÁØ´Ù.

   for(i=0; i< li_str_len; i++) {
      ls_one_char = ls_str.charAt(i);
      if (escape(ls_one_char).length > 4) {
         li_byte += 2;
      } else {
         li_byte++;
      }

      // ÀüÃ¼ Å©±â°¡ li_max¸¦ ³ÑÁö¾ÊÀ¸¸é
      if(li_byte <= li_max) {
         li_len = i + 1;
      }
   }
   
   // ÀüÃ¼±æÀÌ¸¦ ÃÊ°úÇÏ¸é
   if(li_byte > li_max) {
      alert( "¿µ¹® " + li_max + "ÀÚ, ÇÑ±Û " + li_max / 2 + "ÀÚ¸¦ ÃÊ°ú ÀÔ·ÂÇÒ¼ö ¾ø½À´Ï´Ù. \n ÃÊ°úµÈ ³»¿ëÀº ÀÚµ¿À¸·Î »èÁ¦ µË´Ï´Ù. ");
      ls_str2 = ls_str.substr(0, li_len);
      aro_name.value = ls_str2;
   }
   aro_name.focus();   
}

// ------------------------------------------------------------------
// Function    : fc_chk_byte(aro_name)
// Description : ÀÔ·ÂÇÑ ±ÛÀÚ¼ö¸¦ Ã¼Å© (°³Çà¹®ÀÚ Æ÷ÇÔ)
// Argument    : aro_name - Ã¼Å©ÇÒ Obj, ari_max - Á¦ÇÑ ±ÛÀÚ¼ö byte
// Return      : 
// ------------------------------------------------------------------
function fc_chk_byte(aro_name,ari_max) {
	check_len( aro_name, ari_max );
}


/**
* ÀÔ·ÂÅØ½ºÆ®¿¡ ½ºÆäÀÌ½º ÀÔ·ÂÀ» ¸·±âÀ§ÇÏ¿© »ç¿ëÇÏ´Â ¸Þ¼Òµå.
* @param strOriginal  Ã¼Å©ÇÒ ¹®ÀÚ¿­
* @param strFind Ã¼Å©ÇÒ ¹®ÀÚ¿­¿¡¼­ °Ë»öÇÒ ¹®ÀÚ
* @param strChange °Ë»öÇÒ ¹®ÀÚ¸¦ Ä¡È¯ÇÒ ¹®ÀÚ
* @return strOri_Length Ã¼Å©ÇÒ ¹®ÀÚ¿­ÀÇ ±æÀÌ¸¦ ¸®ÅÏÇÑ´Ù.
*/
function checkStr(strOriginal, strFind, strChange) {
 var position, strOri_Length;
 position = strOriginal.indexOf(strFind);

 while(position != -1) {
  strOriginal = strOriginal.replace(strFind, strChange);
  position = strOriginal.indexOf(strFind);
 }

 strOri_Length = strOriginal.length;
 return strOri_Length;
}

function idWin( utype ) {
	if ( utype == "_admin" )	window.open( "/config/search_form/admin_search.php", "id", "width=360,height=350" );
	
	else						window.open( "/config/search_form/id_search.htm", "id", "width=360,height=350" );
}

function postWin(value) {
	window.open( "/config/search_form/address_search.htm?mode="+value, "addr", "width=360,height=350" );
}

function bookmark(url, name) {
  window.external.AddFavorite(url, name);
}

function setstartpage(url) {
  startpage.style.behavior='url(#default#homepage)';
  startpage.setHomePage(url);
}

function dateAdd( date, gap ) {
	date_arr = date.split("-");

	rdate = new Date( date_arr[0], date_arr[1], date_arr[2], 0, 0, 0 );
	rdate.setDate( date_arr[2] );
	rdate.setMonth( date_arr[1] - 1 );
	rdate.setYear( date_arr[0] );

	rdate.setDate( rdate.getDate() + gap );

	return rdate.getFullYear() + "-" + padZero( rdate.getMonth() + 1 ) + "-" + padZero( rdate.getDate() );
}

// »ç¾÷ÀÚ ¹øÈ£ Ã¼Å©
function reg_no_check()
{
	var chkRule = "137137135";
	var ThisVal1 = document.form1.corp_reg_number1.value;
	var ThisVal2 = document.form1.corp_reg_number2.value;
	var ThisVal3 = document.form1.corp_reg_number3.value;

	var strCorpNum = ThisVal1 + ThisVal2 + ThisVal3; // »ç¾÷ÀÚ¹øÈ£ 10ÀÚ¸®
	var step1, step2, step3, step4, step5, step6, step7;

	step1 = 0; // ÃÊ±âÈ­

	for (i=0; i<7; i++)
	{
		step1 = step1 + (strCorpNum.substring(i, i+1) *chkRule.substring(i, i+1));
	}

	step2 = step1 % 10;
	step3 = (strCorpNum.substring(7, 8) * chkRule.substring(7, 8))% 10;
	step4 = strCorpNum.substring(8, 9) * chkRule.substring(8, 9);
	step5 = Math.round(step4 / 10 - 0.5);
	step6 = step4 - (step5 * 10);
	step7 = (10 - ((step2 + step3 + step5 + step6) % 10)) % 10;

	if (strCorpNum.substring(9, 10) != step7)   // °á°ú ºñ±³ ÆÇ´Ü
	{
		return false;
	}
	return true;
}
