String.prototype.trim = function(){
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
};
function formValidator(form) {
    this.docForm = form;
    this.mappingCnt=0;
    this.isPassForm=true;
    this.fieldObj=new Object();
    this.errorMessage="";
    this.focus=true;
}
formValidator.prototype.oneMapping = function(isPassForm, fieldObj, errorMessage, focus) {
    if(this.mappingCnt==0){
        this.isPassForm=isPassForm;
        this.fieldObj=fieldObj;
        this.errorMessage=errorMessage;
        this.focus=focus;
    }
    this.mappingCnt++;
};
formValidator.prototype.isPass = function() {
        if(!this.isPassForm){
            alert(this.errorMessage);
            if(this.focus){
                this.fieldObj.focus();
            }
            return false;
        }
        return true;
};
formValidator.prototype.checkNVL = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    if(fieldObj.value.trim()==""){
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkMinLen = function(fieldName, minLength, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    if(fieldObj.value.trim().length<minLength){
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkMaxLen = function(fieldName, maxLength, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    if(fieldObj.value.trim().length>maxLength){
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkSpecialChar = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    var strPattern = /[~!@\#$%^&*\()\-=+_']/gi;
    if (strPattern.test(fieldObj.value)) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkAlphaNum = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    var strPattern = /^[a-zA-Z0-9]+$/;
    if (!strPattern.test(fieldObj.value)) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkUpperAlphaNum = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    var strPattern = /^[A-Z0-9]+$/;
    if (!strPattern.test(fieldObj.value)) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkLowerAlphaNum = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    var strPattern = /^[a-z0-9]+$/;
    if (!strPattern.test(fieldObj.value)) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkNum = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    var strPattern = /^[0-9]+$/;
    if (!strPattern.test(fieldObj.value)) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkSelect = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    var idx = fieldObj.selectedIndex;
    if(fieldObj.options[idx].value==""){
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkMixAlphaNum = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    chk2 = /[a-zA-Z]/i;  //적어도 한개의 a-z 확인
    chk3 = /\d/;  //적어도 한개의 0-9 확인
    if (!(chk2.test(fieldObj.value)&&chk3.test(fieldObj.value))) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkDecimal = function(fieldName, errorMessage, focus) {
    fieldObj = this.docForm[fieldName];
    var strPattern = /^(\-)?[0-9]*(\.[0-9]*)?$/;
    if (!strPattern.test(fieldObj.value)) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkEmail = function(fieldName, errorMessage, focus, isNull) {
    fieldObj = this.docForm[fieldName];
    var strPattern = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
    if (fieldObj.value == ""){ return; }
    if (!strPattern.test(fieldObj.value)) {
        this.oneMapping(false, fieldObj, errorMessage, focus);
    }
};
formValidator.prototype.checkCompareTo = function(fieldName1, fieldName2, errorMessage, focus) {
    fieldObj1 = this.docForm[fieldName1];
    fieldObj2 = this.docForm[fieldName2];
    if ( fieldObj1.value != fieldObj2.value ) {
        fieldObj2.value="";
        this.oneMapping(false, fieldObj2, errorMessage, focus);
    }
};
