// VARIAVEIS GLOBAIS //
var const_WhiteChars = ' \t\n\r';
// isEmpty() //
String.prototype.isEmpty = function(){
	var iCount, sChar;
	if(this==null || this.length<=0)
		return true;
	for(iCount=0; iCount<this.length; iCount++){
		sChar = this.charAt(iCount);
		if(const_WhiteChars.indexOf(sChar)==-1) return false;
	}
	return true;
}
// Trim() //
String.prototype.Trim = function(){
	var iCount, iPos, sChar, sValor1=this;
	if(sValor1==null || sValor1.length<=0)
		return;

	for(iCount=0; iCount<const_WhiteChars.length; iCount++){
		sChar = const_WhiteChars.substr(iCount,1);
		while(sValor1.indexOf(sChar)>=0){
			sValor1 = sValor1.replace(sChar,'');
		}
	}
	return sValor1;
}
// Left(iQtde) //
String.prototype.Left = function(iQtde){
	return this.slice(0, iQtde);
}
// Right(iQtde) //
String.prototype.Right = function(iQtde){
	return this.slice(iQtde, this.length);
}

String.prototype.isValidEmail = function(){
	pattern = new RegExp("^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([a-z,A-Z]){2,3}([0-9,a-z,A-Z])?$");
	if(this.search(pattern) == -1)
		return false;
	else
		return true;
}

String.prototype.isNumeric = function(){            
    return !isNaN(this);
}

String.prototype.isValidCNPJ = function(){
    var b = [6,5,4,3,2,9,8,7,6,5,4,3,2], c = this;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 14) return false;
    for(var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
    if(c[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
    if(c[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
};

String.prototype.isValidCPF = function(){
    var CPF = this; // Recebe o valor digitado no campo

    // Verifica se o campo é nulo
    if (CPF.length < 11)
        return false;    

    // Aqui começa a checagem do CPF
    var POSICAO, I, SOMA, DV, DV_INFORMADO;
    var DIGITO = new Array(10);
    DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

    // Desemembra o número do CPF na array DIGITO
    for (I=0; I<=8; I++) {
        DIGITO[I] = CPF.substr( I, 1);
    }

    // Calcula o valor do 10º dígito da verificação
    POSICAO = 10;
    SOMA = 0;
    for (I=0; I<=8; I++) {
        SOMA = SOMA + DIGITO[I] * POSICAO;
        POSICAO = POSICAO - 1;
    }
    DIGITO[9] = SOMA % 11;
    if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
    }
    else{
        DIGITO[9] = 11 - DIGITO[9];
    }

    // Calcula o valor do 11º dígito da verificação
    POSICAO = 11;
    SOMA = 0;
    for (I=0; I<=9; I++) {
        SOMA = SOMA + DIGITO[I] * POSICAO;
        POSICAO = POSICAO - 1;
    }
    DIGITO[10] = SOMA % 11;
    if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
    }
    else {
        DIGITO[10] = 11 - DIGITO[10];
    }

    // Verifica se os valores dos dígitos verificadores conferem
    DV = DIGITO[9] * 10 + DIGITO[10];
    if (DV != DV_INFORMADO)
        return false;
    else    
        return true;
}

fctVerifica_OnBlur = function(obj, text)
{    
    if(obj.value == "")
        obj.value = text;
}

fctVerifica_OnFocus = function(obj, text)
{
    if(obj.value == text)
        obj.value = "";
}


