// 팝업창 띄우기
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.frmSearch){
        if(str_search.value==""){
            return false;    
        }
        action = "/etc/search/search.php";
        return true;
    }    
}

function onEnter() 
{

  if (event.keyCode==13) 
  {	
	Search();return;
  } 

}

//로그인 상태 체크
function login_check(){
	if (getCookie("login_status") == "true"){
		document.write("<p class=\"login\"><a href=\"javascript:login_out();\">ログアウト</a></p>");
	}else{
		document.write("<p class=\"login\"><a href=\"javascript:login_in();\">ログイン</a> <span class=\"bar\">|</span> <a href=\"/member/membership_join.php\">会員登録</a></p>");
	}
}

//로그인 팝업
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=/"; 
}



// 폴 중복 체크용
function p_chk(p_no) {
	var radioObj = document.all('ps_seq');
	var isChecked;
	
	if(radioObj.length == null){ // 라디오버튼이 같은 name 으로 하나밖에 없다면
		isChecked = radioObj.checked;
	}else{ // 라디오 버튼이 같은 name 으로 여러개 있다면
		for(i=0; i<radioObj.length; i++){
			if(radioObj[i].checked){
				isChecked = true;
				break;
			}
		}
	}

	if(isChecked) {
		if (getCookie("japanese_" + p_no) == "") {			
			setCookie("japanese_" + p_no,p_no,0,"/","","");
			return;
		} else {
			alert ("重複投票です");
			return false;
		}
	} else {
		alert ("項目を選んでください");
		return false;
	}
}

//나도한마디 보여주기 
function goHidden(v1) {
	
	try {
		if (v1=="Y") {
			setCookie("Hcomments","Y",0,"/","",""); //(Y:hidden)		
			document.getElementById("HiddenDiv1").style.display='none';
			document.getElementById("HiddenDiv2").style.display='';
			document.getElementById("HiddenDiv3").style.display='none'; 		
		} else {
			setCookie("Hcomments","N",0,"/","","");		
			document.getElementById("HiddenDiv1").style.display='';
			document.getElementById("HiddenDiv2").style.display='none';
			document.getElementById("HiddenDiv3").style.display=''; 		
		}
	} catch(e) {}
}

//우측 영역 연예뉴스 top10
function ent10(){
	document.getElementById("ent10").style.display = "block";
	document.getElementById("news10").style.display = "none";

	document.getElementById("btn_ent10").src = "http://images.joins.com/ui_joins/japan07/btn_toplist01_on.gif";
	document.getElementById("btn_news10").src = "http://images.joins.com/ui_joins/japan07/btn_toplist02_off.gif";
}

//우측 영역 뉴스 top10
function news10(){
	document.getElementById("comment10").style.display = "none";
	document.getElementById("news10").style.display = "block";
	
	document.getElementById("btn_comment10").src = "http://images.joins.com/ui_joins/japan09/tab_toplist_comment_off.gif";
	document.getElementById("btn_news10").src = "http://images.joins.com/ui_joins/japan09/tab_toplist_news_on.gif";
}	

//우측 영역 연예뉴스 top10
function comment10(){
	document.getElementById("comment10").style.display = "block";
	document.getElementById("news10").style.display = "none";

	document.getElementById("btn_comment10").src = "http://images.joins.com/ui_joins/japan09/tab_toplist_comment_on.gif";
	document.getElementById("btn_news10").src = "http://images.joins.com/ui_joins/japan09/tab_toplist_news_off.gif";
}

//우측 영역 카테고리 별로 순위 바꾸기
function best_view(hidden_div, view_div){
	
	document.getElementById(view_div).style.display = "block";
	document.getElementById(hidden_div).style.display = "none";
	
}


pmnews_no = 1;
//포토 뉴스 뒤로 가기
function next_pmnews(max_page_pmnews){

	pmnews_no = pmnews_no + 1;

	if (pmnews_no == max_page_pmnews+1){
		pmnews_no = 1;
	}

	document.getElementById("pmnews_1").style.display = "none";
	document.getElementById("pmnews_2").style.display = "none";
	document.getElementById("pmnews_3").style.display = "none";
	document.getElementById("pmnews_" + pmnews_no).style.display = "block";		
}		

//포토 뉴스 리스트 앞로 가기
function pre_pmnews(max_page_pmnews){

	pmnews_no = pmnews_no - 1;
	
	if (pmnews_no == 0){
		pmnews_no = max_page_pmnews;
	}		
	
	document.getElementById("pmnews_1").style.display = "none";
	document.getElementById("pmnews_2").style.display = "none";
	document.getElementById("pmnews_3").style.display = "none";
	document.getElementById("pmnews_" + pmnews_no).style.display = "block";		
}

//태그 url 인코딩
function tag_encode(tag){
	var enc_tag = encodeURI(tag);
	document.location = "/search/japanese.php?pageNum=&order=&query=" + enc_tag;
}

//선택된 메뉴 강조
function highlight_menu_name(mid){
	try {
		document.getElementById(mid).style.fontWeight = "bold";
		document.getElementById(mid).className = "on";
	}
	catch(e) { }
}

function ax_print(s)
{
	document.write(s);
}

var _navi_timer = 0;
function clearNaviTimeout()
{
	clearTimeout(_navi_timer);
}

function setNaviTimeout()
{
	_navi_timer = setTimeout('ChangeLayer(nowtab)',150);
}