String.prototype.isid = function(){
    if (this.search(/[^A-Za-z0-9_-]/) == -1) 
        return true;
    else 
        return false;
}

String.prototype.istel = function(){
    if (this.search(/[^0-9_-]/) == -1) 
        return true;
    else 
        return false;
}

String.prototype.isalpha = function(){
    if (this.search(/[^A-Za-z]/) == -1) 
        return true;
    else 
        return false;
}

String.prototype.isnumber = function(){
    if (this.search(/[^0-9]/) == -1) 
        return true;
    else 
        return false;
}

String.prototype.isfloat = function(){
    if (this.search(/[^0-9_.]/) == -1) 
        return true;
    else 
        return false;
}

String.prototype.isemail = function(){
    if (this.search(/(.+)@.+\..+/) == -1) 
        return false;
    else {
        for (var i = 0; i < this.length; i++) 
            if (this.charCodeAt(i) > 256) 
                return false;
        return true;
    }
}

String.prototype.isdate = function(){
    if (this.search(/\d{4}\-\d{2}\-\d{2}/) == -1) 
        return false;
    else {
        return true;
    }
}

String.prototype.strLen = function(){
    var temp;
    var set = 0;
    var mycount = 0;
    
    for (k = 0; k < this.length; k++) {
        temp = this.charAt(k);
        
        if (escape(temp).length > 4) {
            mycount += 2
        }
        else 
            mycount++;
    }
    
    return mycount;
}

String.prototype.ltrim = function(){
    var i, j = 0;
    var objstr
    
    for (i = 0; i < this.length; i++) {
        if (this.charAt(i) == ' ') {
            j = j + 1;
        }
        else {
            break;
        }
    }
    return this.substr(j, this.length - j + 1)
}

String.prototype.rtrim = function(){
    var i, j = 0;
    
    for (i = this.length - 1; i >= 0; i--) {
        if (this.charAt(i) == ' ') {
            j = j + 1
        }
        else {
            break;
        }
    }
    return this.substr(0, this.length - j);
}

String.prototype.trim = function(){
    return this.replace(/\s/g, "");
}

// Automatic input test data
function setTestData(){
    var form = document.form;
    var cnt = 0;
    for (i = 0; i < form.length; i++) {
        if (form.elements[i].type == 'text' && form.elements[i].value == '') {
            form.elements[i].value = cnt++;
        }
    }
}


// Setting default value - [select], [radio]
function setSelect(elName, targetValue){
    var el;
    el = document.getElementById(elName);
    
    switch (el.type) {
        case 'select-one':
            for (var i = 0; i < el.length; i++) {
                if (el.options[i].value == targetValue) {
                    el.options[i].selected = true;
                }
            }
            break;
            
        case 'radio':
            var radioEl = document.getElementsByName(elName);
            ;
            for (var i = 0; i < radioEl.length; i++) {
                if (radioEl[i].value == targetValue) {
                    radioEl[i].checked = true;
                    break;
                }
            }
            break;
    }
}

function getByte(str){
    var sum = 0;
    var len = str.length;
    for (var i = 0; i < len; i++) {
        var ch = str.substring(i, i + 1);
        var en = escape(ch);
        if (en.length <= 4) {
            sum++;
        }
        else {
            sum += 2;
        }
    }
    return sum;
}

document.getElementsByClassName = function(className){
    var children = document.getElementsByTagName('*') || document.all;
    var elements = new Array();
    
    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        var classNames = child.className.split(' ');
        for (var j = 0; j < classNames.length; j++) {
            if (classNames[j] == className) {
                elements.push(child);
                break;
            }
        }
    }
    
    return elements;
}

// add css class
function addClass(target, className){
    target.className += (target.className ? " " : "") + className;
}

// validation check 
function validate(target, isMsg){
    for (i = 0; i < target.length; i++) {
        if (target.elements[i].getAttribute("required") != null) {
            if (target.elements[i].value.trim() == "") {
                if (isMsg) {
                    if (target.elements[i].alt) {
                        alert(target.elements[i].alt + " Àº(´Â) ÇÊ¼ö Ç×¸ñÀÔ´Ï´Ù");
                    }
                    else {
                        alert("ÇÊ¼ö Ç×¸ñÀÔ´Ï´Ù");
                    }
                }
                
                addClass(target.elements[i], "error");
                target.elements[i].focus();
                
                return false;
            }
        }
    }
    
    return true;
}

function onlyNum(obj){
    var key = event.keyCode;
    if (!(key == 8 || key == 9 || key == 13 || key == 46 || key == 144 || (key >= 48 && key <= 57) || key == 110 || key == 190 || 97 <= key <= 105)) {
        alert('¼ýÀÚ¸¸ ÀÔ·Â °¡´ÉÇÕ´Ï´Ù');
        obj.value = '';
        event.returnValue = false;
    }
}

