//------------------------------------------------------------------------------
//~ Common Functions -----------------------------------------------------------
//------------------------------------------------------------------------------

//~ File -----------------------------------------------------------------------
function uploadFile() {
    var limitCount = (document.fileListForm.fileList.length)-1;
    var uploadFileMaxSize = 10*1024*1024;
    if (limitCount > 0) {
        
        var uploadCount = 0;
        for (var i = 1; i < document.fileListForm.fileList.length; i++) {
            if (document.fileListForm.fileList.options[i].value.length > 0) uploadCount++;
        }


        if(isBlank(document.uploadForm.filename,"파일명을 입력하십시오.")) return;

        if(limitCount <= uploadCount) {
			alert('파일 업로드 제한 갯수는 '+limitCount+'개입니다');
			return;
		}
        if(document.fileListForm.totalsize.value > uploadFileMaxSize){
			alert('최대 파일 업로드 SIZE는 10MB 입니다.');
			return;
        }
        document.uploadForm.submit();
    }
}



function deleteFile() {
    var isSelected = false;
    var directDelList = '';
    for (var i = 1; i < document.fileListForm.fileList.length; i++) {
        if (document.fileListForm.fileList.options[i].value.length > 0 &&
            document.fileListForm.fileList.options[i].selected) {
            directDelList = document.fileListForm.fileList.options[i].value;
            isSelected = true;
            break;
        }
    }
    
    if (isSelected) {
        if (confirm('삭제하시겠습니까?')) {
            document.fileListForm.deleteList.value = directDelList;  
            document.fileListForm.submit();
        }
    } else{
        alert('삭제할 파일을 선택하십시오.');
    }
}



//~ Security -------------------------------------------------------------------
function checkAndSubmit(){
    var objFrm = document.frmJCO;
    
    if (objFrm.email.value == null || objFrm.email.value == ""){
        alert("로그인 이메일을 입력하세요.");
        objFrm.email.focus();
        return false;
    }
    if (objFrm.pw.value == null || objFrm.pw.value == ""){
        alert("로그인 비밀번호를 입력하세요.");
        objFrm.pw.focus();
        return false;
    }
    
    return true;
}

function init(){
    var objFrm = document.loginForm;
    var saveEmail = getCookie("loginId");
    if(saveEmail!=null && saveEmail!=''){
        objFrm.email.value=saveEmail;
    }
    
}

function checkEnter(varMain, varSub) {
    if (event.keyCode == 13) {
        loginProcess(varMain, varSub);
    }
}



//~ Competition ----------------------------------------------------------------
//~ Conference -----------------------------------------------------------------
//~ Member ---------------------------------------------------------------------
function findAddressAction(){
    if(document.frmAddress.dong.value.length<1) {
        alert("'동이름'을 입력해주십시오.");
        document.frmAddress.dong.focus();
        return false;
    }
    else{
        goPage(document.frmAddress,"addressOfMember","address","POST","/PopupControl.do","","");
        return true;
    } 
}


function putAddress(varZipcode1,varZipcode2,varAddress){
    opener.document.frmJCO.zipcode1.value = varZipcode1;
    opener.document.frmJCO.zipcode2.value = varZipcode2;
    opener.document.frmJCO.address.value = varAddress;
    self.close();
    opener.document.frmJCO.address1.focus();
}


//~ Common ---------------------------------------------------------------------
function isBlank(obj,msg){
    var str = obj.value;
    if(str.replace(/(^\s*)|(\s*$)/g, "") == ''){
        alert(msg);
        obj.focus();
        return true;
    }else{
        return false;
    }
}

function isMatch(obj1, obj2, msg){
    if(obj1.value != obj2.value){
        alert(msg);
        obj1.focus();
        return false;
    }else{
        return true;
    }
}

function isKorean(obj,msg){
    var str = obj.value;
    if(str.search(/[ㄱ-ㅎ|ㅏ-ㅣ|가-힝]/) != -1){
        alert(msg);
        obj.focus();
        return true;
    }else{
        return false;
    }
}

function isEnglish(obj,msg){

    var str = obj.value;
    alert(str);
    if(str.search(/[^a-z|^A-Z]/) != -1){
    alert("true");
        return true;
    }else{
    alert("false");
        alert(msg);
        obj.focus();
        return false;
    }
}

function isEnglishNumber(obj,msg){
    var str = obj.value;
    if(str.search(/([^a-z|^A-Z][^0-9])/) != -1 || str.search(/([^0-9][^a-z|^A-Z])/) != -1){
        return true;
    }else{
        alert(msg);
        obj.focus();
        return false;
    }
}

function isNumber(obj,msg){
    var str = obj.value;
    if(str.search(/[^0-9]/) != -1){
        alert(msg);
        obj.focus();
        return false;
    }else{
        return true;
    }
}

function isEmail(obj){
    var email = obj.value;
    var regExp=/^[0-9a-z]([-_\.]?[0-9a-z])*@[0-9a-z]([-_\.]?[0-9a-z])*\.[a-z]{2,3}$/i; 
    if(regExp.test(obj.value)) { 
        return true; 
    }else{ 
        alert("Email주소가 올바르지 않습니다."); 
        obj.focus();
        return false; 
    } 
}

function isMoreLength(obj,num){
    var value = obj.value;

    if(value.length >= num) { 
        return true; 
    }else{ 
        alert(obj.value+"은(는) "+num+"자 이상이어야 합니다."); 
        obj.focus();
        return false; 
    } 
}

function replaceBlank(obj,msg){
    var str = obj.value;
    if(str.replace(/(^\s*)|(\s*$)/g, "") == ''){
        obj.value = msg;
    }
}

//-------------------------------------------------------------------
// 지정된 객체의 문자열의 길이를 계산하는 부분
//-------------------------------------------------------------------
function checkByte(str) {
    var i;
    var strLen;
    var strByte;
    strLen = str.length;
    for(i=0, strByte=0;i<strLen;i++) {
        if(str.charAt(i) >= ' ' && str.charAt(i) <= '~' )
            strByte++;
        else
            strByte += 2;
    }
    return strByte;
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure){

    var today = new Date();
    var expires=new Date();
    expires.setTime(today.getTime()+ 1000*60*60*24*365);
    document.cookie = name + "=" + escape(value)+ " ; expires=" + expires.toGMTString();

}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name){
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1){
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }else{
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1){
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain){
    if (getCookie(name)){
        document.cookie = name + "="
                        + ((path) ? "; path=" + path : "")
                        + ((domain) ? "; domain=" + domain : "")
                        + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function goPage(obj,varNextCommand,varTarget,varMethod,varAction,varMainMenu,varSubMenu){
    obj.cmd.value = varNextCommand;
    obj.mainMenu.value = varMainMenu;
    obj.subMenu.value = varSubMenu;
    obj.target = varTarget;
    obj.method = varMethod;
    obj.action = varAction;
    obj.submit();
}

function goConferencePage(obj,varNextCommand,varSlaveMenu){
    obj.cmd.value = varNextCommand;
    obj.mainMenu.value = "2";
    obj.subMenu.value = "1";
    obj.slaveMenu.value = varSlaveMenu;
    obj.target = "_self";
    obj.method = "POST";
    obj.action = "/ConferenceControl.do";
    obj.submit();
}

// Open a popup page
function popup(obj,varLoginPage,varTarget,varMethod,varAction,varStyle){
    pop = window.open('',varTarget,varStyle);
    obj.cmd.value = varLoginPage;
    obj.target = varTarget;
    obj.method = varMethod;
    obj.action = varAction;
    obj.submit();
    pop.focus();
}


