/** 
    validation 체크
**/
//빈값 체크
$.fn.emptyCheck = function() {
	var value = $.trim(this.val() + '');
	
    if (undefined == value || ! value) {
        alert($(this).attr('alt') + '는(은) 반드시 입력해 주세요.');
        $(this).select();
        return false;
    }
    return true;
}

//빈값 체크
$.fn.radioEmptyCheck = function(radio) {
	var value = $.trim(this.val() + '');
	
    if (undefined == value || 'undefined' == value) {
        alert($(radio).attr('alt') + '는(은) 반드시 입력해 주세요.');
        $.scrollTo($('#h' + $(radio).attr('name')));
        return false;
    }
    
    return true;
}

$.fn.emptyCheckForSmartEditor = function() {
	var value = $.trim(this.val() + '');
	
	value = $.replaceAll(value, /&nbsp;/gi, '');
	value = $.replaceAll(value, /<br>/gi, '');
	value = $.replaceAll(value, /<p>/gi, '');
	value = $.replaceAll(value, /<\/p>/gi, '');
	value = $.trim(value);
	
    if (!value) {
        alert($(this).attr('alt') + '는(은) 반드시 입력해 주세요.');
        $(this).select();
        return false;
    }
    return true;
}

//숫자 체크
$.fn.isNumberCheck = function() {
    if (! $(this).emptyCheck()) return false;
    if (isNaN($.trim(this.val() + ''))) {
        alert($(this).attr('alt') + '은(는) 숫자만 입력 가능합니다.');
        $(this).select();
        return false;
    }
    return true;
}

//숫자 범위 체크
$.fn.betweenCheck = function(min, max) {
    if (! $(this).emptyCheck()) return false;
    if (! $(this).isNumberCheck()) return false;
     
    var value = Number($(this).val());

    if (min > value) {
        alert($(this).attr('alt') + '은(는) ' + min + '이상 ' + max + '이하의 값만 입력 가능합니다.');
        $(this).select();
        return false;
    }

    if (max < value) {
        alert($(this).attr('alt') + '은(는) ' + min + ' 이상 ' + max + ' 이하의 값만 입력 가능합니다.');
        $(this).select();
        return false;
    }
    
    return true;
}

//문자 길이 체크
$.fn.lengthCheck = function(max) {
    if (! $(this).emptyCheck()) return false;
    
    if (max < $.trim(this.val() + '').length) {
        alert($(this).attr('alt') + '은(는) ' + max + ' 글자를 초과할 수 없습니다.');
        $(this).select();
        return false;
    }
    return true;
}
