/* window.open */
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

/*#########################################Front Main###################################*/
/**
 * 이미지 변경
 * @param webZineId 웹진 아이디
 * @param webzineArticleId 아티믈 아이디
 * @param sectionId 섹션아이디
 * @return
 */
function changeBigImg(webZineId, webzineArticleId, sectionId){
    var pwebZineId = webZineId;     
    var pwebzineArticleId = webzineArticleId;    
    var psectionId = sectionId;

    WebZineDWR.getSectionArticleInfo(pwebZineId, pwebzineArticleId, psectionId, { 
        callback:function(data) {

    	var str = "";
            str = "<img src=\"/common/webzine/sectionImage.do?webZineId="+pwebZineId+"&webZineArticleId="+pwebzineArticleId+"&sectionId="+psectionId+"\" width=\"327px\" height=\"190px\" alt=\"\" />";
            str+= "<img src=\""+globalCommonImgServer+"/img/community/webzine/bg_alpha.png\" alt=\"\" width=\"327\" height=\"31\" class=\"alpha forpng\" />";
            str+= "<p class=\"txt\" onclick=\"javascript:location.href='/common/webzine/contents/view.do?articleId="+pwebzineArticleId+"&preUrlType=main'\" style=\"cursor: pointer\">"+data.title+"</p>";
            
            document.getElementById('bigImg').innerHTML=str;
                    
            }
        } 
    );        

    var tagAll = document.body.getElementsByTagName("*");
     
    var mbd = [];
    for (var j=0; j<tagAll.length; j++){
        if(tagAll[j].id == "selectImg") mbd.push(tagAll[j]);
    }    
    
    for(var i=0;i < mbd.length;i++){
        if(mbd[i].title==webzineArticleId)
        {
            mbd[i].className='border';
        }
        else
        {
            mbd[i].className='';
        }
        
    }
    
}
/*#########################################Front Main###################################*/

/*#########################################Front 공통###################################*/
/**
 * 검색 수행(공통)
 */
    function dosearch()
    {
        var frm = document.ListForm;
         frm.searchWord.value = encodeURIComponent(document.getElementById('title').value);
         frm.action = "search.do";
         frm.submit();
    }
/*
 * 칼럼별로 정렬 수행
 */     
    function doSortingColume(colume, direction, editorName, gubun)
    {
        var frm = document.ListForm;
         frm.searchWord.value = encodeURIComponent(document.getElementById('title').value);
         frm.sortingType.value = direction;
         frm.sortingColume.value = colume;
         
         if(editorName!=null && editorName!='')
         {
            frm.editorName.value = encodeURIComponent(editorName);
         }
         if("month"==gubun){
             frm.action = "month.do";
         }else if("category"==gubun){
             frm.action = "category.do";
         }else if("search"==gubun){
             frm.action = "search.do";
         }
         frm.submit();
    }    
/*#########################################Front 공통###################################*/

/*#########################################Front Category###################################*/
/**
 * 정렬 수행
 */    
    function cdoSortingColume(colume, direction, editorName)
    {
        var frm = document.ListForm;
         
         if(frm.searchWord)
         {
            frm.searchWord.value = encodeURIComponent(document.getElementById('title').value);
         }
         frm.sortingType.value = direction;
         frm.sortingColume.value = colume;
         
         if(editorName!=null && editorName!='')
         {
            frm.editorName.value = encodeURIComponent(editorName);
         }
         
         frm.action = "category.do";
         frm.submit();
    }  
/*#########################################Front Category###################################*/
 
/*#########################################Front Month###################################*/
    
    function mdoSortingColume(colume, direction, editorName)
    {
        var frm = document.ListForm;
         if(frm.searchWord){
            frm.searchWord.value = encodeURIComponent(document.getElementById('title').value);
         }
         frm.sortingType.value = direction;
         frm.sortingColume.value = colume;
         
         if(editorName!=null && editorName!='')
         {
            frm.editorName.value = encodeURIComponent(editorName);
         }
         
         frm.action = "month.do";
         frm.submit();
    }    
    function goWebZineOfYear(year)
    {
        location.href="/common/webzine/contents/month.do?nowYear="+year;
    }  
/*#########################################Front Month###################################*/

/*#########################################Front Search###################################*/
/*
 * 검색결과 페이지에서 검색 수행
 */    
    function sdosearch()
    {
        var frm = document.ListForm;
         frm.searchWord.value = encodeURIComponent(document.getElementById('title').value);
         frm.categoryId.value = '';
         frm.editorName.value = '';
         frm.action = "search.do";
         frm.submit();
    }
/*
 * 검색 결과네에서 카테고리별 검색
 */    
    function goSearchCategory(categoryId)
    {
        var frm = document.ListForm;
         frm.searchWord.value = encodeURIComponent(document.getElementById('title').value);
         frm.categoryId.value = categoryId;
         frm.editorName.value = '';
         frm.action = "search.do";
         frm.submit();
    }

/*#########################################Front Search###################################*/

/*#########################################Front View###################################*/
function copyUrlPop(){
    var url = document.URL;
    //url = url.substring(0,((url.length)-1));
    var html = "";
                                                 
    html += "    <div class=\"corner lt\"></div>";
    html += "    <div class=\"corner rt \"></div>";
    html += "        <a href=\"#.\" onclick=\"closePop('copyURL');\"><img src=\"" +globalCommonImgServer+"/img/common/mygallery/btn_x.gif\" alt=\"close\" class=\"close_x\" /></a>";
    html += "        <div class=\"content2 clearfix\">";
    html += "            <h2><img src=\"" +globalCommonImgServer+"/img/community/learn/academe/h2_copyURL.gif\" alt=\"URL 복사\" /></h2>";
    html += "            <p class=\"mgt10\"><img src=\"" +globalCommonImgServer+"/img/community/learn/academe/txt_copyURL.gif\" alt=\"이 게시판의 주소가 복사되었습니다. 메모장이나 메신저 창에서 ctrl+v를 눌러주세요.\" /></p>";
    html += "            <input type=\"text\" value="+url+" class=\"mgt15 copyURL\" />";
    html += "            <div class=\"btnC\"><a href=\"#.\" onClick=\"javascript:copyTheUrl()\"><img src=\"" +globalCommonImgServer+"/img/community/learn/academe/btn_copy.gif\" alt=\"복사하기\" /></a></div>";
    html += "        </div>";
    html += "    <div class=\"corner lb\"></div>";
    html += "    <div class=\"corner rb\"></div>";
    
    var urlLayer = nv.$('copyUrlLayer');
    var urlShowDiv = nv.$("copyURL");
    if(urlShowDiv) {
        urlLayer.removeChild(urlShowDiv);
    }    
        
    urlShowDiv = document.createElement('div');
    urlShowDiv.id = 'copyURL';
    urlShowDiv.className = 'rbox_pks';
    urlShowDiv.style.top = '40px';    
    urlShowDiv.style.width = '925px';
    urlShowDiv.innerHTML = html;
    urlLayer.appendChild(urlShowDiv);
}

function copyTheUrl() {
    if (nv.BrowserDetector.isIE) {
        window.clipboardData.setData("Text", document.URL);
    }else {
        globalCommon.alertNotice('Only IE');
    }
}
function webZineArticlePrint(webZineArticleId){
    var height = "700";
    var width = "800";
    var winType = "fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no, scrollbars=no, resizable=yes,location=no, width=" + width + ",height="+height;

    var top = (screen.availheight - height)/2;
    var left =(screen.availwidth - width)/2;
    var action = "/common/webzine/webZineArticlePrint.do?articleId="+webZineArticleId;
    window.open(action,"",winType+",top="+top+",left="+left);
}
/*#########################################Front View###################################*/

/*#########################################Front Write###################################*/
var REG_CNT = 0;
function checkSubmit() {
    var WriteForm = nv.$("WriteForm");
    var validator = new nv.Validator(WriteForm, globalCommon.alertMsg);

    // 제목
    var name = nv.$("name");
    var email1 = nv.$("email1");
    var email2 = nv.$("email2");
    var phone1 = nv.$("phone1");
    var phone2 = nv.$("phone2");
    var phone3 = nv.$("phone3");
    var title = nv.$("title");

    if(name){
        validator.checkRequired("name", "이름을 입력해 주세요", true);       
        validator.checkSpecialChar('name', "특수문자를 사용할수 없습니다.", true);
        validator.checkMaxLength('name', 10, "제목은 10자 이하여야 합니다.", true);
    }
    
    if(email1){
        validator.checkRequired("email1", "메일을 입력해 주세요", true);     
        validator.checkSpecialChar('email1', "특수문자를 사용할수 없습니다.", true);          
    }
    
    if(email2){
        validator.checkRequired("email2", "메일을입력해 주세요", true);    
        validator.checkRegex('email2', /^((\w|[\-\.])+)\.([A-Za-z]+)$/, true, "이메일 형식이 바르지 않습니다.", true);
        validator.checkSpecialChar('email1', "특수문자를 사용할수 없습니다.", true);                   
    }
    
    if(phone1){
        validator.checkRequired('phone1', '휴대폰 번호를 입력해 주세요', true);
        validator.checkOnlyNumber('phone1', '숫자만 입력이 가능합니다.', true);
        validator.checkMaxLength('phone1', 3, "3자 이하여야 합니다.", true);        
    }
    if(phone2){
        validator.checkRequired('phone2', '휴대폰 번호를 입력해 주세요', true);
        validator.checkOnlyNumber('phone2', '숫자만 입력이 가능합니다.', true);  
        validator.checkMaxLength('phone2', 4, "4자 이하여야 합니다.", true);           
             
    }
    if(phone3){
        validator.checkRequired('phone3', '휴대폰 번호를 입력해 주세요', true);
        validator.checkOnlyNumber('phone3', '숫자만 입력이 가능합니다.', true);
        validator.checkMaxLength('phone3', 4, "4자 이하여야 합니다.", true);                  
    }
    
    if(title){
        validator.checkRequired('title', '제목을 입력해 주세요', true);
    }

    if(!validator.validate()) return false;
    // 에디터 검사.
    var contents = "";
    var fck = FCKeditorAPI.GetInstance('contentsOrg');
    contents= fck.GetHTML() ;
    
    var removedHTMLTagsContents = contents;
    removedHTMLTagsContents = removedHTMLTagsContents.replace(/&nbsp;/g, "");
    if(removedHTMLTagsContents.length <=0 || nv.Str.trim(removedHTMLTagsContents).length <=0) {
        alert("기사를 입력해 주세요");
        return false;
    }

    WriteForm.contents.value = xssFunction(contents);

    return true;
}
/*
 * 등록 수행
 */
function submitMessage(){

    if(REG_CNT > 0) {
        alert("저장 중 입니다.")
        return;
    } else {
        REG_CNT = REG_CNT + 1;
        var WriteForm = nv.$("WriteForm");
        if(checkSubmit()) {
            WriteForm.action="write.do";
            WriteForm.submit();
        }else{
            REG_CNT = 0;
        }

    }
}
/*
 * 메일 선택
 */
function selectEmail(){
   var WriteForm = nv.$("WriteForm");   
   WriteForm.email2.value=WriteForm.email3.value; 
}
/*
 * 최기화
 */
function newClear(){
   var WriteForm = nv.$("WriteForm");
   WriteForm.reset();
   WriteForm.contents.value="";
    var fck = FCKeditorAPI.GetInstance('contentsOrg');
    fck.SetHTML('');
}
/*#########################################Front Write###################################*/

