function saveTags() {
	if( $F('str_tags') == "" ) {
		alert('태그를 입력하세요.\n\n여러개 입력시에는 ,로 구분하세요.');
		$('str_tags').focus();
		return false;
	}
	$('mode').value = "NEW";
	return true;
}

// isPublicDoc : 현재 문서가 공개 문서인지를 나타냄 'T'이면 공개 문서이고 'F'이면 비공개이다.
function copyBlog(selElement, seq) {
	var browserName = navigator.appName;
	if ( browserName.search("Explorer") > 0 ) {
		var range = selElement.createTextRange();
		range.execCommand('Copy');
	} else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = ''; 
		var copyData = $F(selElement);
		var divinfo = '<embed src="/js/clipboard/clipboard.swf" FlashVars="clipboard='
									+encodeURIComponent(copyData)
									+'" width="0" height="0" type="application/x-shockwave-flash" allowScriptAccess="always"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
}

// SWF 태그 복사하기
function copySwfTag(selElement, seq) {
	var browserName = navigator.appName;
	if ( browserName.search("Explorer") > 0 ) {
		var range = $(selElement).createTextRange();
		range.execCommand('Copy');
	} else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var copyData = $F(selElement);
		var divinfo = '<embed src="/js/clipboard/clipboard.swf" FlashVars="clipboard='
									+encodeURIComponent(copyData)
									+'" width="0" height="0" type="application/x-shockwave-flash" allowScriptAccess="always"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}	
}



function copy(inElement) {
  var browserName = navigator.appName;
  if ( browserName.search("Explorer") > 0 ) {
    var range = inElement.createTextRange();   
    range.execCommand('Copy');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="clipboard3.swf" FlashVars="_clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
  alert ("다음 소스가 복사되었습니다.\n" + inElement.value );
} 





function goScrap(islogin) {

	if( islogin != '1' ){
		var goLogin = confirm('로그인 후 사용 가능합니다. 로그인 하시겠습니까?');
		if(goLogin){
			location.href = '/user/login.php';
		}
		return false;
	}

	if( confirm('스크랩 하시겠습니까?') ) {
		return true;
	}
	return false;
}

// 메일로 문서 추천하기
function goRecommend(seq, islogin, isauth, isPublicDoc) {
	if(islogin != '1'){
		var goLogin = confirm('로그인 후 사용 가능합니다. 로그인 하시겠습니까?');
		if(goLogin){
			if(isauth == '0') {
				location.href = '/user/login.php?re_url=/swfview/swf_view.php?seq='+seq;		
			}else{
				location.href = '/user/login.php?re_url=/preview/view.php?seq='+seq;		
			}			
		}
		return false;
	}
	
	if (isPublicDoc != 'T')
	{
		if ( confirm('우선 문서를 공개하셔야 합니다. 문서를 공개 하시겠습니까?') )
		{
			if (isauth == '0') {
				document.location.href = '/mybox/index.php?cmd=agreement&seq=' + seq.substr(1) + '&swfView=S';
			}else{
				document.location.href = '/mybox/index.php?cmd=agreement&seq=' + seq.substr(1) + '&swfView=N';
			}
		}
		return false;
	}
	
	/*
	if(isauth != '1') {
		alert('추천은 인증된 회원만 사용가능합니다.\n가입시 신청하신 이메일로 발송된 인증메일을 확인해 주십시오.')
		return false;
	}
	*/
	$('recomment_seq').value = seq;
	window.open("", 'recom_mail', "width=660, height=330");
	$('frmRecomment').submit();
	
}

function download(seq, flag, cd_org) {		
	var url = "/preview/downProc.php";
	new Ajax.Request(url, {
  	method:'get',
  	asynchronous: false,
  	parameters:{'flag':flag, 'seq':seq, 'cd_org':cd_org},
  	onSuccess:function(xmlHttp) {
  		var result = xmlHttp.responseText;	  			
  		if( result != '' ) {
  			alert(result);
  		}		  		
  	},
  	onFailure:function(xmlHttp) {
  	} 
 	});  		  	 	
}

function checkValidUrl(seq) {		
	var url = "/preview/urlValidProc.php";
	new Ajax.Request(url, {
  	method:'get',
  	asynchronous: true,
  	parameters:{'seq':seq},
  	onSuccess:function(xmlHttp) {
  		/*var result = xmlHttp.responseText;	  			
  		if( result != '' ) {
  			alert(result);
  		}*/		  		
  	},
  	onFailure:function(xmlHttp) {
  	} 
 	});  		  	 	
}
/**
 * 사용자 파일 다운로드 
 */
function userFileDownload(seq) {
	var frm = $('downForm');
	$('fileSumSeq_down').value = seq;
	frm.method = "post";
	frm.action = "/regist/file_download.php";
	frm.submit();
	
}

function searchInDoc(kwd, seq) {
	if ($('docSearchFlag').value == '' || kwd == '')
	{
		alert('검색어를 입력해 주세요');	
	}
	else
	{
		window.open('/search/searchInDoc.php?kwd=' + encodeURI(kwd) + '&seq=' + encodeURI(seq),'','width=690,height=500,scrollbars=yes' );
	}
}


/**
 * 연관 문서 와 등록자의 다른 문서간의 탭이동
 */
function docuTabOver(docuName) {
	
	if('sameDocumentArea' == docuName){
		$('sameDocumentArea').style.display='block';
		$('sameDocumentArea_tab').className = 'docu_tab_over';
		$('otherDocumentArea').style.display='none';
		$('otherDocumentArea_tab').className = 'docu_tab';
	}else{
		$('sameDocumentArea').style.display='none';
		$('sameDocumentArea_tab').className='docu_tab';
		$('otherDocumentArea').style.display='block';	
		$('otherDocumentArea_tab').className='docu_tab02_over';	
	}	
}


/**
 * 추천 이슈 탭 클릭에 따른 모양 변경
 * 
 * @param serialNum 선택된 탭의 번호 (오른쪽으로 부터 있기 때문에 오른쪽에서 부터 0으로 시작된다.)
 * @param tabNum 탭의 수
 * @author goodoi
 * @since 08.12.11
 * @requires sub.css 가 필요함
 */
function issueTabOver(serialNum, tabNum) {
	
	for (var i=0; i<tabNum; i++) {
		if (serialNum == i) {
			$('issue_tab_' + i).className = 'issue_tab_over';
			$('issue_content_' + i).show();
		} else {
			
			if (i == 0) { // 세 번째 탭 선택시
				$('issue_tab_' + i).className = 'issue_tab';
			} else if (i == 1) { // 두 번째 탭 선택시
				
				if (serialNum == 0) {
					$('issue_tab_' + i).className = 'issue_tab02'; // border left, top, bottom 1px
				} else if (serialNum == 2) {
					$('issue_tab_' + i).className = 'issue_tab'; // border right, top, bottom 1px
				}
				
			} else if ( i == 2 ) { // 첫 번째 탭 선택시
					$('issue_tab_' + i).className = 'issue_tab02';
			}
			$('issue_content_' + i).hide();
		}
	}
}

function doMetaSearch(){
	var kwd = document.frmMain.kwd.value;
	
	if('' == kwd){
		alert('검색어가 올바르지 않습니다.');
		document.frmMain.focus();
	}else{
		document.location.href = '/search/search.php?w=meta&kwd='+encodeURI(kwd);
	}
}



/**
 * 템플릿, 서식, 표지 상세보기 썸네일이미지 에러 발생시 안 보이기
  *
 * @param obj 썸네일 이미지 src 태그 오브젝트
 * @author lauree
 * @since 09.01.05
 */
function template_small_thumbnail_error(obj)
{	
	//obj.src="/image/icon/dot.jpg";
	//obj.style.border = "0px";
	//obj.width="0";
	divName = obj.id+'_div';
	if ($(divName)){
		$(divName).style.display = 'none';
	}
	
}


/**
 * 일반상세 보기  썸네일이미지 에러 발생시 다른 이미지로 대체
 * - 이미지 클릭이 안되도록 수정 -
 *
 * by mobidic 09.01.28 stack overflow 처리
 * @param obj 썸네일 이미지 src 태그 오브젝트
 * @author goodoi
 * @since 09.01.05
 * @see search.js의 happy_thumbnail_error와 이미지만 다름 
 */
function thumbnail_error_view(obj) {
	obj.src = '/image/com/empty_thumbnail_doc.gif';
	obj.parentNode.removeNode(false);
	var nextArrow = $('nextArrow');
	var nextArrowBlank = $('nextArrowBlank');
	if ( nextArrow && nextArrowBlank) {
		nextArrow.hide();
		nextArrowBlank.show();
	}
	
}


/**
 * 추천문서 썸네일이미지 에러 발생시 다른 이미지로 대체하고 우선은 클릭시에도 아무런 동작이 없도록 한다.
 *
 * @param obj 썸네일 이미지 src 태그 오브젝트
 * @author goodoi
 * @since 09.01.06
 */
function thumbnail_error_best(obj, seq) {
	obj.src = '/image/com/empty_thumbnail_doc.gif';
	obj.parentNode.href = '#';
	obj.parentNode.rel = "";
}

/**
 * 서식의 썸네일 이미지 에러 발생시 이미지 대체
 * 
 * @param {Object} obj 썸네일 이미지 src 태그 오브젝트
 * @author goodoi
 * @since 09.07.20
 */
function thumbnail_error_form(obj) {
	obj.src = '/image/com/empty_thumbnail_doc.gif';
}


/**
 * 썸네일이미지 초기화
 * 
 */
var nowThumbnailPage = 1;
var totalThumbnailPage = 0;

/**
 * 다음 썸네일이미지 
 * 
 */
function nextThumbnail() {
	if(nowThumbnailPage+1>totalThumbnailPage) {
		return;
	}
	nowThumbnailPage+=1;
	nowThumbnailIndex = nowThumbnailPage - 2;
	nextThumbnailIndex = nowThumbnailPage - 1;
	$("thumnail_"+nowThumbnailIndex).style.display = "none";
	$("thumnail_"+nextThumbnailIndex).style.display = "inline";
	
	
	$("thumnail_img_"+nextThumbnailIndex).src ="/image/lightbox/loading.gif";
	$("thumnail_img_"+nextThumbnailIndex).width=32;
	$("thumnail_img_"+nextThumbnailIndex).height=32;
	$("thumnail_img_"+nextThumbnailIndex).setStyle({border:'0px', padding:'80px 0px'});
				
	setTimeout ( "loaddingThumbnail(nextThumbnailIndex)" , 300 );									
	
	showArrawThumbnail(nowThumbnailPage);
}	

/**
 * 썸네일이미지 로딩
 * 
 *  @param nextThumbnailIndex 다음 이미지 index
 */
function loaddingThumbnail(nextThumbnailIndex) {
	$("thumnail_"+nextThumbnailIndex).style.display = "none";
	$("thumnail_img_"+nextThumbnailIndex).src = $("thumnail_src_"+nextThumbnailIndex).href;
	setTimeout ( "showThumbnail(nextThumbnailIndex)" , 300 );		
}

/**
 * 현재 썸네일이미지 보여주기
 * 
 *  @param nextThumbnailIndex 다음 이미지 index
 */
function showThumbnail(nextThumbnailIndex) {		
	$("thumnail_"+nextThumbnailIndex).style.display = "inline";			
	$("thumnail_img_"+nextThumbnailIndex).width=140;
	$("thumnail_img_"+nextThumbnailIndex).height=170;		
	$("thumnail_img_"+nextThumbnailIndex).setStyle({border:'1px solid #CFD0D6', padding:'10px'});
}

/**
 * 썸네일이미지 방향(화살표) 보여주기
 * 
 *  @param page 현재 이미지 index
 */
function showArrawThumbnail(page) {
	if(page+1>totalThumbnailPage) {
		$('nextArrow').style.display = "none";
		$('nextArrowBlank').style.display = "inline";
	} else {
		$('nextArrowBlank').style.display = "none";
		$('nextArrow').style.display = "inline";
	}

	if(page-1<=0) {
		$('prevArrow').style.display = "none";
		$('prevArrowBlank').style.display = "inline";
	} else {
		$('prevArrowBlank').style.display = "none";
		$('prevArrow').style.display = "inline";
	}
}

/**
 * 이전 썸네일이미지 
 * 
 * 
 */
function prevThumbnail() {
	if(nowThumbnailPage-1<1 || nowThumbnailPage-1>totalThumbnailPage) {
		return;
	}
	nowThumbnailPage-=1;
	nowThumbnailIndex = nowThumbnailPage;
	nextThumbnailIndex = nowThumbnailPage - 1;
	$("thumnail_"+nowThumbnailIndex).style.display = "none";
	$("thumnail_"+nextThumbnailIndex).style.display = "inline";
	showArrawThumbnail(nowThumbnailPage);
}	

/**
 * 장바구니 담은 후 이동
 * 
 * 
 */
function basket(seq) {		
	var url = "/pay/basketProc.php";
	new Ajax.Request(url, {
  	method:'get',
  	asynchronous: false,
  	parameters:{'flag':'add', 'seq':seq},
  	onSuccess:function(xmlHttp) {
  		document.location.href='/pay/index.php?cmd=basket';
  	},
  	onFailure:function(xmlHttp) {
  		document.location.href='/pay/index.php?cmd=basket';
  	} 
 	});  		  	 	
	
	
}