﻿//var masterPageID = "ctl00$ContentPlaceHolder1$";
var masterPageID = "ctl00$ContentPlaceHolder1$ctl00$";
var arrDelFileList = new Array();
var arrDelImgList = new Array();
var blnUploading = false;
var blnDeleting = false;
var readFontSize = 12;



/* ###############################################################################################

    공용함수
    
############################################################################################### */


// 경로 중 파일이름만 반환
function getFileName(path)
{
    return path.substr(path.lastIndexOf("/")+1);
}


// 팝업
function goPop(url) {
    var pop = window.open(url, 'pop');
    pop.focus();
}
function goPopNude(url, width, height, left) {
    var pop = window.open(url, 'pop', 'width=' + width + 'px, height=' + height + 'px, left=' + left + 'px');
    pop.focus();
}


// 문자열 길이 반환
function len(s) {
	var s1 = trim(s);
	return s1.length;
}


// 우편번호 찾기
function openPost(FieldsName) {
    var post = window.open('/include/page/searchPost.aspx?form_name=aspnetForm&fields_name=' + FieldsName, 'post', 'scrollbars=yes,left=' + (screen.width - 440) / 2 + ',top=' + (screen.height - 320) / 2 + ',width=440,height=320');
    post.focus();
    return;
}


// 폰트 확대/축소
function setFont(type) {
	if (type == "plus") {		
		switch (readFontSize) {
			case 12 :
				$get("readContentArea").style.fontSize = "14px";
				readFontSize = 14;
				break;
			case 14 :
				$get("readContentArea").style.fontSize = "16px";
				readFontSize = 16;
				break;
			case 16 :
				$get("readContentArea").style.fontSize = "18px";
				readFontSize = 18;
				break;
			case 18 :
				$get("readContentArea").style.fontSize = "20px";
				readFontSize = 20;
				break;
		}
	} else if (type == "minus") {
		switch (readFontSize) {
			case 14 :
				$get("readContentArea").style.fontSize = "12px";
				readFontSize = 12;
				break;
			case 16 :
				$get("readContentArea").style.fontSize = "14px";
				readFontSize = 14;
				break;
			case 18 :
				$get("readContentArea").style.fontSize = "16px";
				readFontSize = 16;
				break;
			case 20 :
				$get("readContentArea").style.fontSize = "18px";
				readFontSize = 18;
				break;
		}
	} else {
		$get("readContentArea").style.fontSize = "12px";
		readFontSize = 12;
	}
}


// 공백제거
function trim(s) {
  s += ''; // 숫자라도 문자열로 변환
  return s.replace(/^\s*|\s*$/g, '');
}











/* ###############################################################################################

    사이트 종속적인 함수
    
############################################################################################### */

function DeleteFile(type) {
    var FileList = document.getElementById(masterPageID + type + "_list");
    
	if (blnUploading) {
		alert('파일을 첨부 중입니다.\n\n파일 첨부 완료 후 삭제하여 주십시요.');
		return;
	}
	if (blnDeleting) {
		alert('파일 삭제중입니다.');
		return;
	}
	
	if (FileList.length == 0) {
		alert('삭제할 파일이 없습니다.');
		return;
	}
	
	if (FileList.selectedIndex < 0 || FileList.selectedIndex == null) {
		alert('삭제할 파일을 선택하여 주십시요.');
		return;
	}
	
	blnDeleting = true;

	FileList.options[FileList.selectedIndex].text = FileList.options[FileList.selectedIndex].text + ' <== File remove...';

	var nIndex, strFilePath, strFileName;

	strFilePath = FileList.options[FileList.selectedIndex].value;
	nIndex = strFilePath.lastIndexOf('/');
	strFileName = strFilePath.substr(nIndex + 1);
	strFilePath = strFilePath.substr(0, nIndex);
    /* 임시로...
	if (strFilePath.toLowerCase( ).indexOf('/pds/board/temp') >= 0) {
		document.frm_delete_file.delete_file_index.value = FileList.selectedIndex;
		document.frm_delete_file.delete_file_path.value = FileList.options[FileList.selectedIndex].value;
		
		document.frm_delete_file.submit();
	} else {
		if (Len(document.getElementById("delete_file_list").value) > 0) document.getElementById("delete_file_list").value = document.getElementById("delete_file_list").value + ',';
		document.getElementById("delete_file_list").value = document.getElementById("delete_file_list").value + FileList.options[FileList.selectedIndex].value;
		
		DeleteComplete(FileList.selectedIndex);
	}
	*/
	arrDelFileList.push(FileList.options[FileList.selectedIndex].value);
	//DeleteComplete(type, FileList.selectedIndex);
	updateFileList("del", type, "", "");
	syncFileList(type);
}



function fileSearch(type)
{
    var fileUp = document.getElementById("ifrm_area_" + type).contentWindow.document.getElementById("file1");

    fileUp.click();
    
    var fileName = fileUp.value;
    $get("tmpText_" + type).value = fileName;
}


function fileUpload(type)
{
    if(blnUploading == true) {
        alert('업로드 중입니다.\n 잠시 기다려주세요.');
    } else {
        var fileForm = document.getElementById("ifrm_area_" + type).contentWindow.document.getElementById("write_form");
        if(fileForm.file1.value != "") {
            blnUploading= true;
            fileForm.submit();
        } else {
            alert('업로드할 파일을 선택해주세요!');
        }
    }
}


// iframe 으로 만들어진 하부페이지들의 순서를 반환하는 함수
function getSubLinkOrder(tURL)
{
    var tOrder, subOrd, subOrdSrc;
    
    if(tURL.lastIndexOf("board_seq=") > 0)
    {
        tURL = tURL.substr(tURL.lastIndexOf("board_seq=")+10);
        if(tURL.lastIndexOf("&") > 0)
        {
            tOrder = tURL.split("&");
            subOrd = tOrder[0];
        } else {
            subOrd = tURL;
        }
        
        if(subOrd == "20")  // 종무자료실이라면...
        {
            if(tURL.lastIndexOf("temp_fld1=") > 0)
            {
                tURL = tURL.substr(tURL.lastIndexOf("temp_fld1=")+10);
                if(tURL.lastIndexOf("&") > 0)
                {
                    tOrder = tURL.split("&");
                    subOrd = tOrder[0];
                } else {
                    subOrd = tURL;
                }
            } else {
                subOrd = "000";
            }
        }
        
    } else {
        tOrder = tURL.substr(tURL.lastIndexOf("_")+1).split(".");
        subOrd = tOrder[0];
    }
    
    if($get("subLinkImg"+subOrd) == null)
    {
        subOrd = "000";
    }
    
    subOrdSrc = $get("subLinkImg"+subOrd).src;
    $get("subLinkImg"+subOrd).src = subOrdSrc.substr(0,subOrdSrc.lastIndexOf(".")) + '_on.gif';
}


function goPopUrlWithUpdateHit(boardSeq, no, url) {
    if(len(url) > 0) {
        if(boardSeq == "298") url = 'http://well.hani.co.kr' + url;
        
        var boardPop = window.open(url, 'boardPop');
        boardPop.focus();
        dm2uWebService.updateReadCnt(boardSeq, no);
    }
}


function goScrap() {
}


function goMail() {
    var board_path = 'news';
	content_mail = window.open('http://www.buddhism.or.kr/common/lib/mail.asp?board_seq=' + boardSeq + '&article_seq=' + $get("article_seq").value + '&board_path=' + escape(board_path), 'content_mail', 'scrollbars=0,left=0,top=0,width=580,height=330');
	content_mail.focus();
}


//스크랩, 프린팅, 메일보내기 관련
function goPrint() {
    var board_path = 'news';
	content_print = window.open('http://www.buddhism.or.kr/common/lib/print.asp?board_seq=' + boardSeq + '&article_seq=' + $get("article_seq").value + '&board_path=' + escape(board_path), 'content_print', 'scrollbars=1,left=0,top=0,width=750,height=600');
	content_print.focus();
}


function openTemple(FieldsName) {
    temple = window.open('/include/page/searchTemple.aspx?form_name=aspnetForm&fields_name=' + FieldsName, 'temple', 'scrollbars=yes,left=' + (screen.width - 440) / 2 + ',top=' + (screen.height - 320) / 2 + ',width=440,height=320');
    temple.focus();
    return;
}


function searchBoard()
{
    var item = searchBoardCol.getSelectedItem();
    if(item != null) {
        var searchCol = item.get_value();
        var searchVal = trim($get("searchBoardVal").value);
        
        if(searchVal.length > 0)
        {
            var url = "";
            var tmp = location.href;
            
            if(tmp.indexOf("&") >= 0)
            {
                var arrTmp = tmp.split("&");
                url = arrTmp[0];
            } else {
                url = tmp;
            }
            location.href = url + "&search_key=" + searchCol + "&search_value=" + encodeURIComponent(searchVal);
            
        } else {
            window.alert('검색어를 입력하세요!');
        }
    }
}


function searchBoardKeyCheck()
{
    if (event.keyCode == 13)
    {
        searchBoard();
        return false;
    }
}

function openMediaFile() {
	var serverName = 'www.buddhism.or.kr';
	open_vod = window.open('http://media.koreatemple.net/rvod_list_buddhism.asp?host_url='+serverName+'&folder_path=/BuddhismK_root/', 'open_vod', 'width=930px, height=450px, scrollbars=yes, top=0, left=0');
}

function selectSubjectPhoto(prefix, boardSeq, articleSeq, page)
{
    if(len(boardSeq) > 0 && len(articleSeq) > 0) {
        var url = prefix + "read.aspx?board_seq=" + boardSeq + "&article_seq=" + articleSeq + "&page=" + page;
        location.href = url;
    }
}

function syncFileList(type)
{
    $get(masterPageID + type + "List").value = "";
    opts = $get(masterPageID + type + "_list").options;
    
    for(var i=0; i<opts.length; i++) {
        $get(masterPageID + type + "List").value += opts[i].value + ",";
    }
}


function UploadComplete(type, act, filePath, fileName)
{    
    if(type == "image") {
        ifrm_area_image.location.href = "/include/board/boardUpload.aspx?type=" + type;
    } else {
        ifrm_area_file.location.href = "/include/board/boardUpload.aspx?type=" + type;
    }
    
    updateFileList(act, type, filePath, fileName);
    $get("tmpText_" + type).value = "";
}


// 반환된 업로드URL을 배열에 저장
function updateFileList(act, type, filePath, fileName)
{
    var opts;
    
    if(act == "add") {
        // 업로드 ListBox 에 추가
        opts = $get(masterPageID + type + "_list").options;
	    opts[opts.length] = new Option(fileName, filePath);
        blnUploading = false;
	      
    } else {
        // 삭제 ListBox 에 추가
        $get(masterPageID + act + type + "List").value += $get(masterPageID + type + "_list").options[$get(masterPageID + type + "_list").selectedIndex].value + ",";
    
        // 업로드 ListBox 에서 삭제
	    $get(masterPageID + type + "_list").options[$get(masterPageID + type + "_list").selectedIndex] = null;
	    blnDeleting = false;
    }
    
    syncFileList(type);
}


   