﻿$(function () {
    $('.subMenus').mouseover(function () {
        var file = $(this).attr('src').split('/');
        var fileName = file[file.length - 1];
        var path = '';
        for (i = 0; i < file.length - 1; i++) {
            path = (i == 0) ? path + file[i] : path + '/' + file[i];
        }
        $(this).attr('src', path + '/' + fileName.replace('_off.gif', '_on.gif'));
    }).mouseout(function () {
        var file = $(this).attr('src').split('/');
        var fileName = file[file.length - 1];
        var path = '';
        for (i = 0; i < file.length - 1; i++) {
            path = (i == 0) ? path + file[i] : path + '/' + file[i];
        }
        $(this).attr('src', path + '/' + fileName.replace('_on.gif', '_off.gif'));
    });
});


function UserChkPwd(obj) {
    var url = "Prog_RegistEdit_Chk.aspx?userChk=" + obj
    return xmlRequestSend(url);
}

function UserChangePwd(obj) {
    var url = "Prog_RegistPw_Change.aspx?userChk=" + obj
    return xmlRequestSend(url);
}

function QnaDelete(obj) {
    var url = "Prog_QnaDelete.aspx?idx=" + obj
    return xmlRequestSend(url);
}

function xmlRequestSend(url) {
    var xmlRequest;
    if (window.ActiveXObject) {
        xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        xmlRequest = new XMLHttpRequest();
    }

    xmlRequest.open("POST", url, false);
    xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlRequest.send(null);

    return xmlRequest.ResponseText;
}

//문자 체크
function chkText(obj, type) {
    var source;
    switch (type) {
        case 1: //아이디 체크(첫글자 숫자안됨, 영문 + 숫자만 입력가능)
            source = /^[a-zA-Z]{1}[0-9a-z\_]+$/;
            break;
        case 2: //메일주소 체크
            source = /^[\w\-]+@(?:(?:[\w\-]{2,}\.)+[a-zA-Z]{2,})$/;
            break;
        case 3: //한글체크(이름)
            source = /^[가-힣]+$/;
            break;
        case 4: //한글 및 영문, 숫자 체크(닉네임)
            source = /^[가-힣a-zA-Z0-9]+$/;
            break;
        case 5:
            source = /^([a-z]+):\/\/((?:[a-z\d\-]{2,}\.)+[a-z]{2,})(:\d{1,5})?(\/[^\?]*)?(\?.+)?$/i;
            break;
        case 6: //비밀번호체크
            source = /^[A-Za-z0-9]+$/;
            break;
        case 7: //주민등록번호(숫자만입력 체크)
            source = /^[0-9]+$/;
            break;
        case 8: //한글 및 영문, 숫자, _
            source = /^[가-힣a-zA-Z0-9_]+$/;
            break;
        case 9: //한글 및 영문, 숫자, _
            source = /^[가-힣a-zA-Z0-9Ⅰ-Ⅹ()_\.\-,\/]+$/;
            break;
        case 10: //한글 및 영문, 숫자, -
            source = /^[0-9\-]+$/;
            break;
    }
    var checked = source.test(obj);
    return checked;
}


function WRITE_OK_SELF(obj, mainURL) {
    alert(obj);
    document.location.href = mainURL;
}

function addfavorites() {
    var urlHostStr = "http://www.keducenter.com";
    var favoriteurl = urlHostStr.value;
    var favoritetitle = "한국사이버교육원"
    if (document.all) {
        if (confirm("즐겨찾기에 추가 하시겠습니까?")) {
            window.external.AddFavorite(favoriteurl, favoritetitle)
        }
    }
}

function WinPopup_quickTel() {
    src = "/Pop_QuickTel.aspx";
    etc = 'toolbar=no,location=no,status=no,scrollbars=no,width=400' + ',height=358' + ',resizable=no'
    window.open(src, 'Pop_QuickTel', etc);
}

function WinPopup(URL, Width, Height, ScrollBar, Resizable, PopName) {
    src = URL;
    if (!ScrollBar) ScrollBar = "no";
    if (!Resizable) Resizable = "no";
    etc = 'toolbar=no,location=no,status=no,scrollbars=' + ScrollBar + ',width=' + Width + ',height=' + Height + ',resizable=' + Resizable
    window.open(src, PopName, etc);
}

function LoginChk() {
    location.href = "/Regist/Regist_Login.aspx";
}

function LoginFailed() {
    alert("아이디 또는 비밀번호가 맞지 않습니다.");
    location.href = "/Regist/RegistLogin.aspx";
}

function isEng(str) {
    for (var i = 0; i < str.length; i++) {
        achar = str.charCodeAt(i);
        if (achar > 255) {
            return false;
        }
    }
    return true;
}

function CheckID(inText) {
    var ret;

    for (var i = 0; i < inText.length; i++) {
        ret = inText.charCodeAt(i);
        if ((ret > 122) || (ret < 48) || (ret > 57 && ret < 65) || (ret > 90 && ret < 97)) {
            return false;
        }
    }
    return true;
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function WRITE_ALERT(msg, mainURL, returnURL, popType) {
    if (popType == "answer") {
        var answer = msg;
        if (confirm(answer) == false) {
            opener.location.href = mainURL;
            self.close();
        } else {
            opener.location.href = mainURL;
            location.href = returnURL;
        }
    } else {
        if (msg != "") {
            alert(msg);
        }

        if (mainURL == "") {
            location.href = returnURL;
        } else if (returnURL == "") {
            opener.location.href = mainURL;
            self.close();
        } else {
            opener.location.href = mainURL;
            location.href = returnURL;
        }
    }
}
