//<script>

//**************************************************************************************************
//                                                                                                 *
//                             BIBLIOTECA PARA MANIPULAÇÃO DE STRINGS                              *
//                                      VERSÃO 10.03.30.15.00                                      *
//                                                                                                 *
//**************************************************************************************************
//                                                                                                 *
//                                          DEPENDÊNCIAS                                           *
//                                                                                                 *
//=================================================================================================*
//                                                                                                 *
// cltdat.js                                                                                       *
//                                                                                                 *
//**************************************************************************************************

//**************************************************************************************************
String.prototype.addressMask = function() {
    try {
        var value = this;
        value = value.replace(/\bapartamento\b/i, "Ap").replace(/\bapto\b/i, "Ap").replace(/\bapt\b/i, "Ap").replace(/\bap\b/i, "Ap.");
        value = value.replace(/\balameda\b/i, "Al").replace(/\bal\b/i, "Al.");
        value = value.replace(/\baltura\b/i, "Alt").replace(/\balt\b/i, "Alt.");
        value = value.replace(/\bandar\b/i, "And").replace(/\band\b/i, "And.");
        value = value.replace(/\bavenida\b/i, "Av").replace(/\bav\b/i, "Av.");
        value = value.replace(/\bbloco\b/i, "Bl").replace(/\bbl\b/i, "Bl.");
        value = value.replace(/\bcasa\b/i, "Cs").replace(/\bcs\b/i, "Cs.");
        value = value.replace(/\bchacara\b/i, "Ch").replace(/\bch\b/i, "Ch.");
        value = value.replace(/\bcondomínio\b/i, "Cond").replace(/\bcondominio\b/i, "Cond").replace(/\bcond\b/i, "Cond.");
        value = value.replace(/\bconjunto\b/i, "Cj").replace(/\bcj\b/i, "Cj.");
        value = value.replace(/\bedifício\b/i, "Ed").replace(/\bedificio\b/i, "Ed").replace(/\bed\b/i, "Ed.");
        value = value.replace(/\bestrada\b/i, "Est").replace(/\best\b/i, "Est.");
        value = value.replace(/\bgaleria\b/i, "Gal").replace(/\bgal\b/i, "Gal.");
        value = value.replace(/\bjardim\b/i, "Jd").replace(/\bjd\b/i, "Jd.");
        value = value.replace(/\bladeira\b/i, "Ld").replace(/\bld\b/i, "Ld.");
        value = value.replace(/\blargo\b/i, "Lg").replace(/\blg\b/i, "Lg.");
        value = value.replace(/\blote\b/i, "Lt").replace(/\blt\b/i, "Lt.");
        value = value.replace(/\bparalela\b/i, "Par").replace(/\bparalelo\b/i, "Par").replace(/\bpar\b/i, "Par.");
        value = value.replace(/\bpavimento\b/i, "Pav").replace(/\bpav\b/i, "Pav.");
        value = value.replace(/\bpiso\b/i, "Ps").replace(/\bps\b/i, "Ps.");
        value = value.replace(/\bpraça\b/i, "Pr").replace(/\bpraca\b/i, "Pr").replace(/\bpr\b/i, "Pr.");
        value = value.replace(/\bproximo\b/i, "Próx").replace(/\bpróximo\b/i, "Próx").replace(/\bprox\b/i, "Prox").replace(/\bprox\b/i, "Próx.");
        value = value.replace(/\bquadra\b/i, "Q").replace(/\bq\b/i, "Q.");
        value = value.replace(/\brodovia\b/i, "Rod").replace(/\brod\b/i, "Rod.");
        value = value.replace(/\brua\b/i, "R").replace(/\br\b/i, "R.");
        value = value.replace(/\bsala\b/i, "Sl").replace(/\bsl\b/i, "Sl.");
        value = value.replace(/\bsubida\b/i, "Sub").replace(/\bsub\b/i, "Sub.");
        value = value.replace(/\bsubsolo\b/i, "SS").replace(/\bss\b/i, "SS.");
        value = value.replace(/\btelefone\b/i, "Tel").replace(/\btel\b/i, "Tel.");
        value = value.replace(/\btravessa\b/i, "Trav").replace(/\btrav\b/i, "Trav.");
        value = value.replace(/\bvia\b/i, "V").replace(/\bv\b/i, "V.");
        value = value.replace(/\bViaduto\b/i, "Vd").replace(/\bvd\b/i, "Vd.");
        value = value.replace(/\bVila\b/i, "Vl").replace(/\bvl\b/i, "Vl.");
        value = value.replace(/0o\b/gi,"0º").replace(/1o\b/gi,"1º").replace(/2o\b/gi,"2º").replace(/3o\b/gi,"3º").replace(/4o\b/gi,"4º").replace(/5o\b/gi,"5º").replace(/6o\b/gi,"6º").replace(/7o\b/gi,"7º").replace(/8o\b/gi,"8º").replace(/9o\b/gi,"9º");
        value = value.replace(/0a\b/gi,"0ª").replace(/1a\b/gi,"1ª").replace(/2a\b/gi,"2ª").replace(/3a\b/gi,"3ª").replace(/4a\b/gi,"4ª").replace(/5a\b/gi,"5ª").replace(/6a\b/gi,"6ª").replace(/7a\b/gi,"7ª").replace(/8a\b/gi,"8ª").replace(/9a\b/gi,"9ª");
        return value;
    }
    catch(e) {
        throw "cltstr.js: String.prototype.addressMask()__" + (e.message || e);
    }
}

//**************************************************************************************************
String.prototype.isEmail = function() {
    try {
        var auxVal = this.split("@");
        if (auxVal.length != 2) return false;
        if ((auxVal[0].length == 0) || (auxVal[0].match(/[^A-Za-z0-9\_\-\.]/) != null) ||
            (auxVal[0].match(/\.{2}/) != null) || (auxVal[0].match(/^\./) != null) || (auxVal[0].match(/\.$/) != null) ||
            (auxVal[0].match(/\-{2}/) != null) || (auxVal[0].match(/^\-/) != null) || (auxVal[0].match(/\-$/) != null) ||
            (auxVal[0].match(/\_{2}/) != null) || (auxVal[0].match(/^\_/) != null) || (auxVal[0].match(/\_$/) != null)) {
            return false;
        }
        auxVal = auxVal[1].split(".");
        if ((auxVal.length < 2) || (auxVal.length > 4)) return false;
        if ((auxVal[0].length < 2) || (auxVal[0].match(/[^A-Za-z0-9\_\-]/) != null) ||
            (auxVal[0].match(/\-{2}/) != null) || (auxVal[0].match(/^\-/) != null) || (auxVal[0].match(/\-$/) != null) ||
            (auxVal[0].match(/\_{2}/) != null) || (auxVal[0].match(/^\_/) != null) || (auxVal[0].match(/\_$/) != null)) {
            return false;
        }
        for (var loop = 1; loop < auxVal.length; loop++) {
            if ((auxVal[loop].length < 2) || (auxVal[loop].length > 4) || (auxVal[loop].match(/[^A-Za-z0-9]/) != null)) return false;
        }
        return true;
    }
    catch(e) {
        throw "cltstr.js: String.prototype.isEmail()__" + (e.message || e);
    }
}

//**************************************************************************************************
String.prototype.noWrap = function() {
    try {
        return this.replace(/ /g, "&nbsp;");
    }
    catch(e) {
        throw "cltstr.js: String.prototype.noWrap()__" + (e.message || e);
    }
}

//**************************************************************************************************
String.prototype.parameter = function(position, separator) {
    try {
        if (this == "") return "";
        if (!isInteger(position, 1)) return "";
        if ((!isString(separator)) || (separator == "")) return "";
        var split = this.split(separator);
        if ((position < 1) || (position > split.length) || split.length < 1) {
            return "";
        }
        else {
            return split[position - 1];
        }
    }
    catch(e) {
        throw "cltstr.js: parameter()__" + (e.message || e);
    }
}

//**************************************************************************************************
String.prototype.replicate = function(times) {
    try {
        var aux = "";
        times = isInteger(times) ? times : 0;
        for (var loop = 1; loop <= times; loop++) aux += this;
        return aux;
    }
    catch(e) {
        throw "cltstr.js: String.prototype.replicate()__" + (e.message || e);
    }
}

//**************************************************************************************************
String.prototype.trim = function(mode) {
    try {
        mode = ("" + mode).toUpperCase();
        switch (mode) {
        case "L":
            return this.replace(/^\s*/, "");
        case "R":
            return this.replace(/\s*$/, "");
        case "T":
        default:
            var aux = this.trim("L").trim("R");
            while (aux.match(/  /g) != null) aux = aux.replace(/  /g, " ");
            return aux;
        }
        return this;
    }
    catch(e) {
        throw "cltstr.js: String.prototype.trim()__" + (e.message || e);
    }
}

//**************************************************************************************************
String.prototype.wrap = function() {
    try {
        return this.replace(/&nbsp;/g, " ");
    }
    catch(e) {
        throw "cltstr.js: String.prototype.wrap()__" + (e.message || e);
    }
}

//</script>
