﻿function validateForm(bObj, e) {
    var scTxt = "하이픈(-) 이외 특수 기호는 입력할 수 없습니다.";
    if (txtLastName) {
        if (txtLastName.value.length == 0) { halert("성을 입력하십시오.", txtLastName); return false; }
        else if (!inputValidator.LastName.test(txtLastName.value)) { halert("영문으로 입력하십시오." + scTxt, txtLastName); return false; }
        else if (txtLastName.value.length > 35) { halert("성은 35자 이내로 입력하십시오.", txtLastName); return false; }
    }
    if (txtFirstName) {
        if (txtFirstName.value.length == 0) { halert("이름을 입력하십시오.", txtFirstName); return false; }
        else if (!inputValidator.FirstName.test(txtFirstName.value)) { halert("영문으로 입력하십시오." + scTxt, txtFirstName); return false; }
        else if (txtFirstName.value.length > 35) { halert("이름은 35자 이내로 입력하십시오.", txtFirstName); return false; }
    }
    if (txtPhone) {
        if (txtPhone.value.length == 0) { halert("전화번호를 입력하십시오.", txtPhone); return false; }
        else if (!inputValidator.KORPhone.test(txtPhone.value)) { halert("정확한 전화번호를 입력하십시오.", txtPhone); return false; }
    }   
    if (txtEmail) {
        if (txtEmail.value.length == 0) { halert("이메일 주소를 입력하십시오. ", txtEmail); return false; }
        else if (!inputValidator.Email.test(txtEmail.value)) { halert("정확한 이메일 주소를 입력하십시오.", txtEmail); return false; }
    }
    if (txtEmailConfirm) {
        if (txtEmailConfirm.value.length == 0) { halert("확인을 위해 이메일 주소를 다시 한 번 입력하십시오.", txtEmailConfirm); return false; }
        else if (txtEmail.value != txtEmailConfirm.value) { halert("이메일 주소와 확인용 이메일 주소가 일치하지 않습니다. 확인 후 다시 입력하십시오.", txtEmailConfirm); return false; }
    }
    
   return true;

}


function input_onKeyPress(sender, e) {
    var iKey = e.keyCode;
    if (e.preventDefault) { if ({ 8: 1, 9: 1, 33: 1, 34: 1, 35: 1, 36: 1, 37: 1, 38: 1, 39: 1, 40: 1, 46: 1}[iKey]) { return; } else { iKey = e.which; } } //needed for FireFox.
    var chr = String.fromCharCode(iKey); var re = /^.*$/;

    switch (sender) {
        case txtFirstName: re = inputValidator.FirstName; break;
        case txtLastName: re = inputValidator.LastName; break;
        case txtAreaCode: re = inputValidator.Numbers; break;
        case txtPhone: re = inputValidator.PhoneEnter; break;
        case txtEmail: re = inputValidator.EmailChar; break;
        case txtEmailConfirm: re = inputValidator.EmailChar; break;
    }
    if (!re.test(chr)) { e.preventDefault ? e.preventDefault() : e.returnValue = false; }
}
function input_onBlur(sender, e) {
    var oVal = sender.value;
    sender.value = Trim(oVal);
    switch (sender) {
        case txtZipCode: sender.value = oVal.toUpperCase(); break;
        case txtPhone: sender.value = oVal.replace(/\-/g, ""); break;
    }
}
function Trim(str) {
    if (str.charAt(0) == " ") { str = Trim(str.substring(1)); }
    if (str.charAt(str.length - 1) == " ") { str = Trim(str.substring(0, str.length - 1)); }
    return str;
}

var inputValidator = new Object();
inputValidator.FirstName = /^[a-zA-Z\s\-]+$/;
inputValidator.LastName = /^[a-zA-Z\s\-]+$/;
inputValidator.Zip = /^((\d{5}\d{4})|(\d{5}-\d{4})|\d{5})$/;
inputValidator.JAPZip = /^((\d{7})|(\d{3}-\d{4}))$/;
inputValidator.ZipInput = /^[\w\-]$/
inputValidator.Phone = /^[0-9\-]{10}|[0-9\-]{11}$/;
inputValidator.KORPhone = /^((\d{9})|(\d{10})|(\d{11})|(\d{12}))$/;
inputValidator.PhoneEnter = /^[0-9\-]$/;
inputValidator.EmailChar = /^[\w\d\-\.\@\[\]]+$/;
inputValidator.Email = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
inputValidator.Numbers = /^[\d]+$/;
inputValidator.Alpha = /^[a-zA-Z]$/;





