// 팝업창 띄우기
function PopUpWindow(Url,windowName,Width,Height,scroll){
   if((scroll==null) || (scroll=="")){
	   scroll = "no";
   }
   var win = window.open(Url,windowName,"toolbar=no,location=no,directory=no,status=no,menubar=no,scrollbars="+ scroll +",resizable=no,top=200,left=350,width="+ Width +",height="+ Height);
   win.focus();
}


// 9. 좌측 공백 제거 함수
function Ltrim(strValue){
    while (strValue.length>0){
       if(strValue.charAt(0)==' '){
           strValue=strValue.substring(1,strValue.length);
	   }
       else
          return strValue;
    }
	return strValue;
}


// 10. 우측 공백 제거 함수
function Rtrim(strValue){
    while (strValue.length>0){
       if(strValue.charAt(strValue.length-1)==' '){
           strValue=strValue.substring(0,strValue.length-1);
	   }
       else
           return strValue;
   }
   return strValue;
}


// 11. 양쪽 공백 제거 함수
function Trim(strValue){
   strValue = Ltrim(strValue);
   strValue = Rtrim(strValue);
   return strValue;
}

// 문자열의 갯수
function StringCount(tmpStr,findstr){
	var result = 0;
	var tmp = "";
	tmp = tmpStr;
	while(tmp.indexOf(findstr)>=0){
		result++;
		tmp = tmp.substring(tmp.indexOf(findstr)+1,tmp.length);
	}
	return result;
}


// 8. 소수숫자확인
function chkFloat(Form1)
{
	for( i=0 ; i < Form1.value.length ; i++ )
    {
		if(((Form1.value.charAt(i)<"0") || (Form1.value.charAt(i)>"9")) && Form1.value.charAt(i)!=".")
        {
			alert("숫자만 입력가능합니다.");
			Form1.value=""
			Form1.focus();
	        return false;
		}

    } // end for
	return true;
}

function FindString(aSource,aString){
	return aSource.indexOf(aString);
}


function ReplaceString(sTxt,sFindTxt1,sFindTxt2,sReplaceStr){

	if(sReplaceStr == ""){
		sReplaceStr = " ";
	}
	var iLoc1 = FindString(sTxt,sFindTxt1);

	if(iLoc1 < 0){
		return sTxt;
	}

	var	sTmp1 = sTxt.substring( 0,iLoc1 + sFindTxt1.length)
	var	sTmp2 = sTxt.substring(iLoc1+sFindTxt1.length )
	var	iCnt = FindString(sTmp2,sFindTxt2)

	if(iCnt < 0 ){
		return sTxt;
	}

	var	sTmp3 = sTmp2.substring(iCnt);
	var	sTmp2 = sTmp2.substring(0,iCnt);
	return sTmp1 + sReplaceStr + sTmp3;
}

// 1. 숫자 체크 함수
function chkInteger(Form1)
{
	for( i=0 ; i < Form1.value.length ; i++ )
    {
		if((Form1.value.charAt(i)<"0") || (Form1.value.charAt(i)>"9"))
        {
			alert("숫자만 입력가능합니다.");
			Form1.value=""
			Form1.focus();
	        return false;
		}

    } // end for
	return true;
}

function isNumeric(txtobj){
	if(txtobj.value=="") return;
	if(isNaN(txtobj.value)){
		alert("숫자만 입력가능합니다");
		txtobj.value = "";
		txtobj.focus();
	}
}

function ClearComma(value1){
   newValue='';
   for(i=0;i<value1.length;i++){
      if(value1.charAt(i)!=",")
         newValue = newValue + value1.charAt(i);
   }
   return newValue;
}


function moneyShape(Moneytxt){
   money = ClearComma(Moneytxt.value);
   Moneytxt.value = money;
   if (chkInteger(Moneytxt)){
      tmpValue = '';
      header = '';
      if (money.charAt(0)=="-" || money.charAt(0)=="+"){
         header = money.charAt(0);
         money = money.substring(1,money.length);
      }
      if(money.length>3){
         while(money.length>3){
            if (tmpValue!="")
               tmpValue = money.substring(money.length-3,money.length) + "," + tmpValue;
            else
               tmpValue = money.substring(money.length-3,money.length);

            money = money.substring(0,money.length-3);
         }
         if(money.length>0) tmpValue = header + money +','+tmpValue;
         Moneytxt.value = tmpValue;
      }
   }
}



function setCookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}


function getCookie(uName) {
	var flag = document.cookie.indexOf(uName+'=');
	if(flag != -1){
		flag += uName.length + 1
		end = document.cookie.indexOf(';', flag)

		if (end == -1) end = document.cookie.length
		return unescape(document.cookie.substring(flag, end))
	}
	else{
		return ""
	}
}


function replace(str,otxt,rtxt){
	while(str.indexOf(otxt)>=0){
		str = str.replace(otxt,rtxt);
	}
	return str;
}

// html에디터 팝업창 처리
function popEditor(objname){
	PopUpWindow("/admin/common/editor.asp?source=" + objname,"winEditor",600,430,"no");
}


// 문자열의 바이트수를 반환
function countByte (pStr) {
	var nCharCount; 	// 문자수
	var nByteCount; 	// 바이트수
	var sChar;
	var i;

	nCharCount = 0;
	nByteCount = 0;

	// 한문자씩 체크하면서 한글은 2바이트 나머지는 1바이트로 계산
	for (i=0 ; i<pStr.length ; i++) {
		sChar = pStr.substring(i, i+1);
		if (sChar.charCodeAt(0) < 0 || 255 < sChar.charCodeAt(0)) {
			nByteCount += 2;
		} else {
			nByteCount++;
		}
	}

	return nByteCount;		// 계산된 바이트수를 반환한다.
}



// select box의 옵션들 없애기
function clearOption(objname){
	var obj = document.getElementById(objname);
	while (obj.length>=1)
		obj.options[0]=null;
}

// select box에 option 추가
function AddOption(objname,value,strtext){
	var obj = document.getElementById(objname);
	var optobj = new Option(strtext,value,true);
    obj.options[obj.length]=optobj;
}

// select box의 특정 option 선택
function SetSelectOption(objname,selectvalue){
	var obj = document.getElementById(objname);
	var i;

	for(i=0;i<obj.length;i++){
		if(obj.options[i].value==selectvalue){
			obj.options[i].selected = true;
			return;
		}
	}
}

// 일본어 검색
function Search(){
    with(document.search){
        if(str_search.value==""){
            return false;
        }
        return true;
    }
}

function onEnter()
{

  if (event.keyCode==13)
  {
	Search();return;
  }

}

//로그인 상태 체크
function login_check(){
	return "";
	if (getCookie("login_status") == "true"){
		return "<li class=\"first\"><a href=\"javascript:login_out();\">ログアウト</a></li>";
	}else{
		return "<li class=\"first\"><a href=\"javascript:login_in();\">ログイン</a></li> <li><a href=\"/member/membership_join.php\">会員登録</a></li>";
	}
}

//로그인 팝업
function login_in(){
	window.open('/member/login.php','login_pop','width=400,height=250,resize=no,scrollbars=no');
}

//로그인 팝업
function login_out(){
	deleteCookie( 'mem_id', '');
	deleteCookie( 'mem_pw', '');
	deleteCookie( 'login_status', '');
	location.reload();
}

 /** * 쿠키 삭제 * @param cookieName 삭제할 쿠키명 */
 function deleteCookie( cookieName ) {
 	var expireDate = new Date(); //어제 날짜를 쿠키 소멸 날짜로 설정한다.
 	expireDate.setDate( expireDate.getDate() - 1 );
 	document.cookie = cookieName + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";
}



//태그 url 인코딩
function tag_encode(tag){
	var enc_tag = encodeURI(tag);
	document.location = "/search/japanese.php?pageNum=&order=&query=" + enc_tag;
}


