/* 이웃 추가 팝업 (단 login한 경우에만 실행해야함 
 * descript parmeter
 * targetBlogSrnb : 신청하려는 북로그 일련번호
 * */
function openNeigPopup(targetBlogSrnb){
    window.open('/blog/addNeighbor.do?neigBlogSrnb='+targetBlogSrnb,'new','scrollbars=no,resizable=no,width=380,height=390,top=200,left=400');
}

/* 이웃 추가 팝업 (단 login한 경우에만 실행해야함 
* descript parmeter
* targetBlogSrnb : 신청하려는 북로그 일련번호
* */
function openNeigPopupForId(memid){
   window.open('/blog/addNeighbor.do?neigMmbrId='+memid,'new','scrollbars=no,resizable=no,width=380,height=390,top=200,left=400');
}


/*
 * 프로파일 보러가기
 */
function gotoProfile(targetId){
    window.open('/blog/blogController.do?memid='+targetId+"&menuDvcd=PRP&blogWrinSrnb=0&blogMenuSrnb=0&subMenuSrnb=0");
}

/**
 * dynamic 한 ajax select options 를 만들어 준다.(계층구조임)
 * @return
 */
function ufSelectOptions(selectDiv, clstCode, ctgrPrntCode) {
	//히든 div 존재 여부
	if($('#hidden' + selectDiv).size() == 0) {
		$('#' + selectDiv).after('<div id="hidden' + selectDiv + '"></div>');
		$('#hidden' + selectDiv).hide();
	}

	//현재 select 의 변한 코드값으로 하위코드들을 조회하는 조건이 된다.
	var selectCtgrCodeArray = ufSelectOptions.arguments.length > 3 ? ufSelectOptions.arguments[3] : new Array(); //현재 select 의 값
	var selectOptionDepth = ufSelectOptions.arguments.length > 4 ? ufSelectOptions.arguments[4] : 0; //현재 select 의 깊이
	var selectCtgrCode = '';
	try {
		selectCtgrCode = selectCtgrCodeArray[selectOptionDepth]['ctgrCode'];
	} catch(e) {
		//처리없음
	}
	//임시 히든 div 에 select option 결과값을 세팅한다.
	$('#hidden' + selectDiv).load('/blog/comm/appendSelectOptionSubCategory.do?clstCode='+ clstCode +'&ctgrPrntCode=' + ctgrPrntCode
		,function(responseText, textStatus, XMLHttpRequest) {
			$('#hidden' + selectDiv).html('');

			if($.trim(responseText) == '') {
				//현재 시퀀스 보다 큰것(하위카테고리 select 번호)이 있으면, 하위select 모두 삭제
				$('[id^='+ selectDiv +'_selRltdCtgrCode_]').each(function() { //기존의 select 가 있으면 삭제
					var idIndex = parseInt($(this).attr('id').substring((selectDiv +'_selRltdCtgrCode_').length));
					if(selectOptionDepth < idIndex) {
						$(this).remove();
						$('#span' + $(this).attr('id')).remove();
					}
				});
				return; //조회된 값이 없으면 하위없음
			}
			//현재 시퀀스 보다 큰것(하위카테고리 select 번호)이 있으면, 하위select 모두 삭제
			$('[id^='+ selectDiv +'_selRltdCtgrCode_]').each(function() { //기존의 select 가 있으면 삭제
				var idIndex = parseInt($(this).attr('id').substring((selectDiv +'_selRltdCtgrCode_').length));
				if(selectOptionDepth < idIndex) {
					$(this).remove();
					$('#span' + $(this).attr('id')).remove();
				}
			});

			var childSelOptionId = '_selRltdCtgrCode_' + (selectOptionDepth+1); //다음 하위로 생성할 select id 생성
			$('#' + selectDiv).append($.trim(responseText) + '<span id="span'+selectDiv + childSelOptionId+'">&nbsp;</span>');
			$('#dynamicSelectOption').attr('id', selectDiv + childSelOptionId); //하위 select 의 아이디 변경

			$('#' + selectDiv + childSelOptionId).change(function(){ //하위 select  의 이벤트
				ufSelectOptions(selectDiv, clstCode, $(this).val(), selectCtgrCodeArray, (selectOptionDepth+1));
			});

			$('#' + selectDiv + childSelOptionId).val(selectCtgrCode).change();

		}
	);
}

/**
 * ufSelectOptions 로 생성한 select option 의 가장 하위의 select option 의 선택값을 리턴한다.
 * @param selectDiv
 * @return
 */
function ufLastSelectOptionsValue(selectDiv) {
	var retValue = '';
	var size = $('[id^='+ selectDiv +'_selRltdCtgrCode_]').size();
	if(size > 0) {
		retValue = $('#'+selectDiv+'_selRltdCtgrCode_' + size).val();
	}
	return retValue;
}

/**
 * 가장 하위의 카테고리 코드를 넘기면 최상위까지의 select option 를 만들어 준다.
 * @param selectDiv
 * @param clstCode
 * @param ctgrCode
 * @return
 */
function ufShowSelectOptionsForValues(selectDiv, clstCode, ctgrCode) {
	$.getJSON('/blog/comm/findSelectOptionParentCategoryList.do'
    	,{clstCode:clstCode, ctgrCode:ctgrCode}
        ,function(data) {
        	$.each(data.items, function(i,item){
        		if(i == 0) { //첫번째만 수행하고 나머지는 클릭이벤트로 처리
            		ufSelectOptions('divRltdCtgrCode', item.clstCode, item.ctgrPrntCode, data.items);
        		}
			});
		}
	);
}

/**
 * 공통 - 북로그 타이틀 제목
 * @return
 */
function gfSetBooklogGlobalTitle() {
    if (!document.all&&!document.getElementById)
        return;
    document.title = "인터넷교보문고 북로그 - 책에 대한 모든 이야기";
    var t = setTimeout("gfSetBooklogGlobalTitle()", 200);
}
$(document).ready(function() { gfSetBooklogGlobalTitle(); });

function setPng24(obj) {
    obj.width=obj.height=1;
    obj.className=obj.className.replace(/\bpng24\b/i,'');
    obj.style.filter =
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
    obj.src=''; 
    return '';
}

// 이벤트 끝 팝업
function fnEvent(){
    window.open('/jsp/blog/blogView/popup/fnEvent.jsp','','width=500,height=550,top=0,left=0'); // 팝업윈도우의 경로와 크기
}
