﻿/*------------------------------------------------------------------------------------*/
// 주민등록번호 체크
/*------------------------------------------------------------------------------------*/
function IsSSN(ssn1, ssn2) {
    var chk = 0;

    if (ssn1.length == 6) {
        if (ssn2.length == 7) {
            if (ssn2.substring(0, 1) == 5 || ssn2.substring(0, 1) == 6) {
                return true;
            }
            for (var i = 0; i <= 5; i++) { chk = chk + ((i % 8 + 2) * parseInt(ssn1.substring(i, i + 1))) }
            for (var i = 6; i <= 11; i++) { chk = chk + ((i % 8 + 2) * parseInt(ssn2.substring(i - 6, i - 5))) }
            chk = 11 - (chk % 11);
            chk = chk % 10;
            if (chk != ssn2.substring(6, 7)) {
                return false;
            } else return true;
        } else return false;
    } else return false;
}


//check email address format
function IsEmail(str) {    
    
    if (str.length == 0)
        return false;

    if (str.length >= 50)
        return false;

    var emailExpression = /[a-z0-9]{2,}@[a-z0-9-]{2,}\.[a-z0-9]{2,}/i;
    if (!emailExpression.test(str))
        return false;

    return true;
}

// 이메일 아이디 체크
function IsValidEmailId(str) {
    if (str.length == 0)
        return false;

    var emailExpression = /[a-z0-9]{2,}/i;
    if (!emailExpression.test(str))
        return false;

    return true;
}

//check if the string is a valid phone number
function IsPhoneNumber(str) {
    if (str.length < 9)
        return false;

    for (var i = 0; i < str.length; i++) {
        if (!('0' <= str.charAt(i) && str.charAt(i) <= '9') && !(str.charAt(i) == " ") && !(str.charAt(i) == "-"))
            return false;
    }
    return true;
}

// 아이디 문자열 체크
function IsAccount(data) {
    var str = data;

    str = str.toUpperCase();
    if (!('A' <= str.charAt(0) && str.charAt(0) <= 'Z')) {
        return false;
    }

    for (var i = 1; i < str.length; i++) {
        if (!('A' <= str.charAt(i) && str.charAt(i) <= 'Z') && !('0' <= str.charAt(i) && str.charAt(i) <= '9')) {
            return false;
        }
    }
    return true;
}

//		좌우공백 제거
function trim(sTmp) {
    return ltrim(rtrim(sTmp));
}


//		왼쪽공백 제거
function ltrim(sTmp) {
    var sRet = new String(sTmp);
    if (sRet.substr(0, 1) == " ") {
        return ltrim(sRet.substr(1));
    }
    else {
        return sRet;
    }
}

//		오른쪽공백 제거
function rtrim(sTmp) {
    var sRet = new String(sTmp);
    if (sRet.substr(sRet.length - 1, 1) == " ") {
        return rtrim(sRet.substring(0, sRet.length - 1))
    }
    else {
        return sRet;
    }
}

//check input string is correct name
function IsCorrectName(inputStr) {
    for (var i = 0; i < inputStr.length; i++) {
        var nCode = inputStr.charCodeAt(i);

        if (!(nCode >= 44032 && nCode <= 55203) && !('A' <= inputStr.charAt(i) && inputStr.charAt(i) <= 'Z') && !('a' <= inputStr.charAt(i) && inputStr.charAt(i) <= 'z') && !(inputStr.charAt(i) <= ' '))
            return false;
    }
    if (trim(inputStr).length == 0)
        return false;
    return true;
}


// 한글 글자수 체크
function getLength(checkStr) {
    var strLength = 0;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        if (ch >= "가" && ch <= "힣")
            strLength += 2;
        else
            strLength += 1;
    }
    return (strLength);
}

function IsNickName(data) {

    if (data=="") {
        return false;
    }

    var str = data;
    if (str.length == 0) {
        return false;
    }

    if (str.length < 2)
        return false;
    if (str.length > 12)
        return false;

    /* 한글/영문/숫자 체크 */
    /*
    str = str.toUpperCase();
    for (var i = 0; i < str.length; i++) {
        var nCode = str.charCodeAt(i);

        if (!(nCode >= 44032 && nCode <= 55203) && !('A' <= str.charAt(i) && str.charAt(i) <= 'Z') && !('0' <= str.charAt(i) && str.charAt(i) <= '9')) {
            return false;
        }
    }
    */
    return true;
}

// check if str includes a numeric character or special character
function IsNumOrSpecialIncluded(str) {
    var flag = false;
    for (var i = 0; i < str.length; i++) {
        if (!(('A' <= str.charAt(i) && str.charAt(i) <= 'Z') || ('a' <= str.charAt(i) && str.charAt(i) <= 'z')))
            flag = true;
    }
    return flag;
}



// 영문자,숫자 허용
function IsAlphaNumeric(obj) {
    var str = obj;
    if (str.length == 0) {
        return false;
    }

    str = str.toUpperCase();
    for (var i = 0; i < str.length; i++) {
        if (!(('A' <= str.charAt(i) && str.charAt(i) <= 'Z') ||
			('0' <= str.charAt(i) && str.charAt(i) <= '9'))) {
            return false;
        }
    }
    return true;
}

//핸드폰 번호 체크
function IsPhoneNumber(str) {
    if (str.length < 9)
        return false;

    for (var i = 0; i < str.length; i++) {
        if (!('0' <= str.charAt(i) && str.charAt(i) <= '9') && !(str.charAt(i) == " ") && !(str.charAt(i) == "-"))
            return false;
    }
    return true;
}

//숫자체크
function IsNumber(str) {
    if (str.length == 0)
        return false;

    for (var i = 0; i < str.length; i++) {
        if (!('0' <= str.charAt(i) && str.charAt(i) <= '9'))
            return false;
    }
    return true;
}

// os 버젼 리턴함.
function getOSInfoStr() {
    var ua = navigator.userAgent;

    if (ua.indexOf("NT 6.0") != -1) return "Windows Vista/Server 2008";
    else if (ua.indexOf("NT 5.2") != -1) return "Windows Server 2003";
    else if (ua.indexOf("NT 5.1") != -1) return "Windows XP";
    else if (ua.indexOf("NT 5.0") != -1) return "Windows 2000";
    else if (ua.indexOf("NT") != -1) return "Windows NT";
    else if (ua.indexOf("9x 4.90") != -1) return "Windows Me";
    else if (ua.indexOf("98") != -1) return "Windows 98";
    else if (ua.indexOf("95") != -1) return "Windows 95";
    else if (ua.indexOf("Win16") != -1) return "Windows 3.x";
    else if (ua.indexOf("Windows") != -1) return "Windows";
    else if (ua.indexOf("Linux") != -1) return "Linux";
    else if (ua.indexOf("Macintosh") != -1) return "Macintosh";
    else return "";
}