var contextPath="";

function openMenu(menuId){
    if(menuId == "ROOT"){
        document.location = contextPath+"/";
    }else{
        document.location = contextPath+"/content.jsp?menuId="+menuId;
    }
}
function openUrl(url, target){
    if(url == null || url.length < 3) return false;
    if(target != null && target == '_blank'){
        window.open(url, '', '');
    }else{
        location.href = url;
    }
}
function selectMenu(menuId){
    location.href = contextPath+"/content.jsp?menuId="+menuId;
}
function openMenuWin(value){
    window.open(contextPath+"/content.jsp?menuId="+value,"","");
}
function openMenuSite(value, target){
    if(target == "self"){
        openMenu(value);
    }else{
        window.open(value,"","");
    }
}

function moveLogin(menuId){
    if(menuId!=null){
        location.href = "content.jsp?menuId=login&moveMenu="+menuId;
    }else{
        location.href = "content.jsp?menuId=login";
    }
}
function moveJoin(){
    openMenu("memberJoin");
}
function logout(){
    document.location = contextPath+"/session/logout.jsp";
}
function modifyMember(){
    openMenu("myInformation");
}

function downloadFile(contentId, idx){
    var frame = document.createElement("IFRAME");
    frame.width = 0;
    frame.height = 0;
    document.body.insertBefore(frame);
    frame.src = contextPath+"/include/download.jsp?contentId="+contentId+"&idx="+idx;
}

function openPopup(name, url, width, height, isCenterAlign, positionX, positionY, option){
    // ¾Æ·¡ÀÇ ¶óÀÎÀº ÆË¾÷µÇ´Â À§Ä¡¸¦ ÁöÁ¤ÇÑ À§Ä¡·Î ¿Å°ÜÁÜ
    if(!isCenterAlign){
    }else{
        positionX = (screen.height - eval(height)+30)/2;
        positionY = (screen.width - eval(width))/2;
    }
    var popup;
    if(option.length>0){
        // ÆË¾÷ WindowÀÇ ¿É¼Ç³»¿ëÀÌ ÀÖÀ»¶§
        popup = window.open(url,name,option+", width="+width+", height="+(eval(height)+30) + ", left="+positionX+", top="+positionY);
    }else{
        popup = window.open(url,name,"width="+width+", height="+(eval(height)+30) + ", left="+positionX+", top="+positionY);
    }   
    popup.focus()
}

function findPasswd(){
    window.open(contextPath+"/session/findPasswd.jsp","findAddress","width=350, height=340");
}

function printContent(){
    window.open(contextPath+"/print.jsp"+(location.href.substring(location.href.indexOf("?"))),"print","width=700, height=600, scrollbars=yes");
}
function emailContent(){
    //window.open(contextPath+"/email.jsp?script=ContentDiv","email","width=700, height=600");
    window.open(contextPath+"/email.jsp"+(location.href.substring(location.href.indexOf("?"))),"email","");
}
function getContent(name){
    return document.getElementById(name).innerHTML;
}

function attachInvalidCheck(name){
    var target = null;
    if(document.getElementById(name)!=null){
        target = document.getElementById(name);
    }else if(eval("document."+name)!=null){
        target = eval("document."+name);
    }else if(document.all[name]!=null){
        target = document.all[name];
    }
    if(target!=null){
        if(target.value!=null && target.value.length>0){
            var invalid = new Array("ZIP","HWP","TXT","TEXT","PDF","DOC","RTF","PPT","XLS","AVI","WMV","WAV","WMA","ASF","MPG","MPEG","JPG","JPEG","GIF","BMP","PNG");
            var isValid = false;
            for(var k=0 ; k < invalid.length ; k++) {
                if (target!=null && endsWith(target.value, invalid[k])) {
                    isValid = true;
                }
            }
            return isValid;
        }else{
            return true;
        }
    }else{
        return true;
    }
}

