function mascaraVeiculoPlaca(objeto, e){
    
    var key = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
        key = String.fromCharCode(whichCode); // Valor para o código da Chav
    
    if (objeto.value.length < 3) {
        var regx = /[a-z..A-Z]/
        if (regx.test(key)) return true; 
    }
    if (objeto.value.length == 3) objeto.value += "-";
    if (objeto.value.length > 3){
        var regx = /[0-9]/
        if (regx.test(key)) return true;
    }
    if (objeto.value.length == 8) return false;
    
    return false;
    
}

function mascaraTelefone(objeto,e){
    
    var strCheck = '0123456789';
    var key = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
        key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
    if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){ objeto.value = ""; } 
    if (objeto.value.length == 3){
        objeto.value +="-";
    } 
    if (objeto.value.length > 7) { 
        objeto.value = objeto.value.replace("-","");
        objeto.value = objeto.value.substring(0,4) + "-" + objeto.value.substring(4,objeto.value.length); 
    }
    else { 
        if (objeto.value.length == 7) { 
            objeto.value = objeto.value.replace("-","");
            objeto.value = objeto.value.substring(0,3) + "-" + objeto.value.substring(3,objeto.value.length); 
        }
    } 
}

function mascara_cpf(cpf)
     {
       var mycpf = '';
       mycpf = mycpf + cpf.value;
       if (mycpf.length == 3) {
          mycpf = mycpf + '.';
          cpf.value = mycpf;
        }
       if (mycpf.length == 7) {
          mycpf = mycpf + '.';
          cpf.value = mycpf;
        }
       if (mycpf.length == 11) {
          mycpf = mycpf + '-';
          cpf.value = mycpf;
        }
       if (mycpf.length == 14) {
        }
     }

function FormatarRG(campo,xEvent) {
	if(navigator.appNome == "Microsoft Internet Explorer"){
		tecla = window.event.keyCode;
	}else{
		tecla = xEvent.which;
	}
		
	vr = campo.value;
	vr = vr.replace(/([^0-9])/g,'');
	tam = vr.length + 1

	//Formata Mask de RG
	if (tecla != 8 && tecla != 0 && tecla != 127 && tecla != 9 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) {
		if(tam < 9) {
			if ( tam <= 1 ) {
				campo.value = vr;
			} else if ( (tam > 1) && (tam <= 4) ) {
				campo.value = vr.substr( 0, 1 ) + '.' + vr.substr( 1, tam );
			} else if ( (tam > 4) && (tam <= 7) ) {
				campo.value = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, tam );
			} else if ( (tam > 7)  ) {
				campo.value = vr.substr( 0, 1 ) + '.' + vr.substr( 1, 3 ) + '.' + vr.substr( 4, 3 ) + '-' + vr.substr( 7, 1);
			}
		} else if( tam == 9) {
			campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '-' + vr.substr( 8, 1);
		} else {
			campo.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 1) ;
		}
	}
}

function FormatarCPF(campo,xEvent) {
	
	if(navigator.appNome == "Microsoft Internet Explorer"){
		tecla = window.event.keyCode;
		
	}else{
		tecla = xEvent.which;
	}
		
	vr = campo.value;
	vr = vr.replace(/([^0-9])/g,'');
	tam = vr.length + 1

	//Formata Mask de cpf
	if (tecla != 8 && tecla != 0 && tecla != 127 && tecla != 9 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) {
		if ( tam <= 3 ) 
			campo.value = vr ;
		if ( (tam > 3) && (tam <= 6) ) 
			campo.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, tam ) ;
		if ( (tam > 6) && (tam <= 9) ) 
			campo.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, tam ) ;
		if ( (tam > 9)  ) 
			campo.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 1) ;
	}
}

function FormatarCNPJ(campo,xEvent) {
	if (navigator.appNome == "Microsoft Internet Explorer") {
		tecla = window.event.keyCode;
	} else {
		tecla = xEvent.which;
	}
	
	vr = campo.value;
	vr = vr.replace(/([^0-9])/g,'');
	tam = vr.length + 1;

	//Formata Mask de CNPJ
	if ( tecla != 9 && tecla != 0 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 && tecla != 58) {
		if ( tam <= 2 ) 
			campo.value = vr ;
		if ( (tam > 2) && (tam <= 5) ) 
			campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ) ;
		if ( (tam > 5) && (tam <= 8) ) 
			campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, tam ) ;
		if ( (tam > 8) && (tam <= 12) ) 
			campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, tam ) ;
		if ( (tam > 12)  ) 
			campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 1) ;
	}
}


function FormatarCPFeCNPJ(campo,xEvent) {

	if(navigator.appName == "Microsoft Internet Explorer"){
		tecla = window.event.keyCode;
	}else{
		tecla = xEvent.which;
	}
	if (tecla > 57 || tecla < 48){
		return
    }
	
	vr = campo.value;
	vr = vr.replace(/([^0-9])/g,'');
	tam = vr.length + 1;

	if (tam <= 11) {
		//Formata Mask de cpf
		if ( tecla != 9 && tecla != 0 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) {
			if ( tam <= 3 ) 
				campo.value = vr ;
			if ( (tam > 3) && (tam <= 6) ) 
				campo.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, tam ) ;
			if ( (tam > 6) && (tam <= 9) ) 
				campo.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, tam ) ;
			if ( (tam > 9) && (tam <= 10) ) 
				campo.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 1) ;
		}
	} else {
		//Formata Mask de CNPJ
		if ( tecla != 9 && tecla != 0 && tecla != 8 && tecla != 13 && tecla != 37 && tecla != 39 && tecla != 46 ) {
			if ( tam <= 2 ) 
				campo.value = vr ;
			if ( (tam > 2) && (tam <= 5) ) 
				campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ) ;
			if ( (tam > 5) && (tam <= 8) ) 
				campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, tam ) ;
			if ( (tam > 8) && (tam <= 12) ) 
				campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, tam ) ;
			if ( (tam > 12)  ) 
				campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 1) ;
		}
	}
}

function mascaraCEP(campo,xEvent) 
{
    var strCheck = '0123456789';
    var key = '';
    var whichCode = (window.Event) ? xEvent.which : xEvent.keyCode;
    if (whichCode == undefined) whichCode = xEvent.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
	
	vr = campo.value;
	if (vr.length == 9) return false;
	if (vr.length == 5) campo.value = vr + "-"
}

//Apagar FormatarCEP
function FormatarCEP(campo,xEvent) 
{
    var strCheck = '0123456789';
    var key = '';
    var whichCode = (window.Event) ? xEvent.which : xEvent.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
	
	vr = campo.value;
	if (vr.length == 9) return false;
	if (vr.length == 5) campo.value = vr + "-"
}
1
function FormatarDATA(campo, vEvent) {
// Formata a data "DD/MM/YYYY"
// Chamada:  onKeyUp="DateFormat(this,event)" 

    var strCheck = '0123456789';
    var key = '';
    var whichCode = (window.Event) ? vEvent.which : vEvent.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
    
    var  vDate = campo;

    isNav4 = navigator.appName == "Netscape" && navigator.appVersion < "5";
    strSeperator = '/';

    if (!isNav4) {
        if (vDate.value.length == 2 || vDate.value.length == 5)
        if (vEvent.keyCode != 46)    // Del 
            if (vEvent.keyCode != 8)   // Back Space
            vDate.value = vDate.value + strSeperator;   
            else
            vDate.value = vDate.value.substr(0,vDate.value.length-1);   
    }
    else 
        if (vDate.value.length == 8) 
            vDate.value = vDate.value.substr(0,2) + strSeperator + 
                            vDate.value.substr(2,2) + strSeperator + 
                            vDate.value.substr(4,4);
}

function FormatarDATA_MY(campo, vEvent) {
// Formata a data "MM/YYYY"
// Chamada:  onKeyUp="DateFormat(this,event)" 

    var strCheck = '0123456789';
    var key = '';
    var whichCode = (window.Event) ? vEvent.which : vEvent.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
    
    var  vDate = campo;

    isNav4 = navigator.appName == "Netscape" && navigator.appVersion < "5";
    strSeperator = '/';

    if (!isNav4) {
        if (vDate.value.length == 2)
        if (vEvent.keyCode != 46)    // Del 
            if (vEvent.keyCode != 8)   // Back Space
            vDate.value = vDate.value + strSeperator;   
            else
            vDate.value = vDate.value.substr(0,vDate.value.length-1);   
    }
    else 
        if (vDate.value.length == 8) 
            vDate.value = vDate.value.substr(0,2) + strSeperator + 
                            vDate.value.substr(2,4);
}
  
  function FormatarHORA(campo, xEvent){
  	
	if(navigator.appNome == "Microsoft Internet Explorer"){
		tecla = window.event.keyCode;
	}else{
		tecla = xEvent.which;
	}
		
	vr = campo.value;
	vr = vr.replace(/([^0-9])/g,'');
	vr = vr.replace(/(^\s+)(\S)(\s+$)/,/^[1]$/);
	tam = vr.length + 1;

	//Formata Mask de cpf
	if ( tecla != 9 && tecla != 8 && tecla != 37 && tecla != 13 && tecla != 39 && tecla != 46 ) {
		if ( tam <= 2 ) 
			campo.value = vr ;
		//if ( (tam > 2) && (tam <= 5) ) 
		//	campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3) ;
		if ( (tam > 2) && (tam > 2) )
			//campo.value = vr.substr(0, 2 ) +  vr.substr( 2, 3 ) + '-' + vr.substr( 5, 3 ) ; // Sergio Rinaldi - ultimo substr alterado de 5,2 para 5,3
			campo.value = vr.substr(0, 2 ) +  ':' + vr.substr(2,4) ; // Sergio Rinaldi - ultimo substr alterado de 5,2 para 5,3
	}
}
  
  function ValidarCNPJ(source, arguments) {
	var cgc = source.value;
	var n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14
	var d1,d2
	var digitado, calculado
	cgc = extrai_numeros(cgc)
	
	if(cgc.length < 14) {
		arguments.IsValid = false 
		return
	}
	
	n1 = cgc.substring(0,1)
	n2 = cgc.substring(1,2)
	n3 = cgc.substring(2,3)
	n4 = cgc.substring(3,4)
	n5 = cgc.substring(4,5)
	n6 = cgc.substring(5,6)
	n7 = cgc.substring(6,7)
	n8 = cgc.substring(7,8)
	n9 = cgc.substring(8,9)
	n10 = cgc.substring(9,10)
	n11 = cgc.substring(10,11)
	n12 = cgc.substring(11,12)
	n13 = cgc.substring(12,13)
	n14 = cgc.substring(13,14)
	d1 = n12*2+n11*3+n10*4+n9*5+n8*6+n7*7+n6*8+n5*9+n4*2+n3*3+n2*4+n1*5
	d1= 11-(d1 % 11)
	if (d1 >= 10) d1=0
	d2 = d1*2+n12*3+n11*4+n10*5+n9*6+n8*7+n7*8+n6*9+n5*2+n4*3+n3*4+n2*5+n1*6
	d2 = 11-(d2 % 11)
	if (d2 >= 10) d2=0
	calculado = d1 + d2
	digitado = n13*1 + n14*1
	if (calculado == digitado)
		arguments.IsValid = true
	else
		arguments.IsValid = false
}

function valida_CPFCNPJ(cmp){
    if (cmp.value.length == 14){
        valida_CPF(cmp);
    }else if(cmp.value.length == 18){
        valida_CNPJ(cmp);
    }else{
        return cmp.IsValid = false;
    }
}

function valida_CPF(cmp){
    var s = cmp.value;
    s = s.replace(/[.]/g,'');
    s = s.replace('-','');
    //args.isValid = (s >= 3);
    //document.write(oSrc.value + ',' + args.value);
    if (isNaN(s)) {
        return cmp.IsValid = false;
    }
   
    var result = true
    
    for (i=1; i<s.length; i++) {
		result = result && (s.charAt(i-1) == s.charAt(i));
	}   
   
    var i;
    var c = s.substr(0,9);
    var dv = s.substr(9,2);
    var d1 = 0;
    
    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i)*(10-i);
    }
    if (d1 == 0){
        return cmp.IsValid = false;
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1) {
        return cmp.IsValid = false;
    }
    d1 *= 2;
    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i)*(11-i);
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1) {
        return cmp.IsValid = false;
    }
    return cmp.IsValid = (!result);
}

//Validação de CNPJ
function valida_CNPJ(cmp){
    
    var s = cmp.value;
    
    s = s.replace(/[.]/g,'');
    s = s.replace(/-/,'');
    s = s.replace('/','');
    
    if (isNaN(s)) {
        return cmp.IsValid = false;
    }
    
    var i;
    var c = s.substr(0,12);
    var dv = s.substr(12,2);
    var d1 = 0;
    
    for (i = 0; i <12; i++){
        d1 += c.charAt(11-i)*(2+(i % 8));

    }
    if (d1 == 0)
        return cmp.IsValid = false;

    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1){
        return cmp.IsValid = false;
    }
    d1 *= 2;
    for (i = 0; i < 12; i++){
        d1 += c.charAt(11-i)*(2+((i+1) % 8));
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9)
        d1 = 0;
    if (dv.charAt(1) != d1){
        return cmp.IsValid = false;
    }
    return cmp.IsValid = true;
} 

	function ValidarHORA(source, arguments) {
			var hora = arguments.value;
			var formato = "[0-2][0-9]:[0-5][0-9]";
			var reg = new RegExp(formato);
			var formato_ok = reg.test(hora);
			var h = hora.substring(0,2);
			var m = hora.substring(3,5);
			var nova_hora = new Date(2000, 1, 1, h, m);
			var h_ok = (nova_hora.getHours() == h);
			var m_ok = (nova_hora.getMinutes() == m);
			arguments.IsValid = (formato_ok && h_ok && m_ok)
	}

function FormatarTELEFONE(campo,vEvent)
{
	var separador;
	var Result = "";
	var abre = "";
	var fecha = "";
	var conjunto2;
	var conjunto1;
	var telefone = campo;
	

	separador = '-'; 
	abre = '(';
	fecha = ')';
	conjunto2 = 2;
	conjunto1 = 8;
	
	if (telefone.value.length == conjunto2)
	{
		telefone.value = abre + telefone.value + fecha;
	}
	
	if (telefone.value.length == conjunto1)
	{
		telefone.value = telefone.value + separador;
	}
}

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e) {
    
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
	
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    if (len > 12) return false; 
     
    var num = objTextBox.value.replace(/\./g, "");
    num = num.replace(/\,/g, "");
    num += key;
      
    for (i = num.length -1 ; i >= 0; i--){
        j++
        aux += num.charAt(i);
        if (j == 3){ 
            
            aux += SeparadorMilesimo;
            j = 0;
        }
        
    }
    
    if (aux.charAt(aux.length - 1) == ".") aux = aux.substring(0, aux.length -1);
    
    for(i = aux.length; i >= 0; i--){
        aux2 += aux.charAt(i - 1); 
    }
    
    objTextBox.value = aux2;
    
    /* 
    if (event.stopPropagation) {
        event.stopPropagation();
    }        
    event.cancelBubble = true; */ //para resolver o problema de duplicar o valor do campo, qdo tiver o atributo default button definido.
    
    return false;
}

function MascaraMixMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){

    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    if (len >= 12) return false;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function MascaraNumero(objTextBox,e){
    var strCheck = '0123456789';
    var key = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13 || whichCode == 8 || whichCode == 0) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida 
}


function ValidaTexto(sender,args)
{
    var ret = false
    
    //Telefone
    var x = /([(]?[0-9]?[0-9]{2}[)]?)?[ ]?[0-9]?[0-9]{3}[ -]?[0-9]{4}/
    //Email
    var y = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/
    //URL
    var z = /((http(s)?:\/\/)|(www(2)?.))+([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/

    var txt = args.value
    
    ret1 = x.test(txt) || y.test(txt) || z.test(txt)
  
    args.IsValid = !ret1
}

function MudaFoco(obj,objDestino,qtdChar)
{
    if (obj.value.length == qtdChar)
    {
       document.getElementById(objDestino).focus();
    }
}

function ValidaTelefone(sender, args){

    var Tel = /^[0-9]{3,4}[-]?[0-9]{4}$/
    args.IsValid = Tel.test(args.value);

}

function Trim(_svalue){

    return _svalue.replace(/^\s*/, "").replace(/\s*$/, "");

}

function ValidaData(sender,args){
    
        args.IsValid = VerificaData(args.value)
}

function VerificaData(Data) {
	        if (Data.length != 10) {
		        return false
	        }
	        dia = ''
	        for (i=0;i<=1; i++) {
		        val = Data.charAt(i)
		        dia = dia + Data.charAt(i)
		        if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
					        (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {
			        return false
		        }			   
	        }
	        if (Data.charAt(2) != "/") {
		        return false
	        }
	        mes = ''
	        for (i=3;i<=4; i++) {
		        val = Data.charAt(i)
		        mes = mes + Data.charAt(i)
		        if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
					        (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {
			        return false
		        }			   
	        }
	        if (Data.charAt(5) != "/") {
		        return false
	        }
	        ano = ''
	        for (i=6;i<=9; i++) {		
		        val = Data.charAt(i)
		        ano = ano + Data.charAt(i)
		        if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
					        (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {
			        return false
		        }			   
	        }
	        if (mes <= 12) {
		        if (mes == 2) {
		            if (AnoBissexto(ano)) {
		                if (dia > 29) {
				            return false
			            }
			            else {
				            return true
			            }
		            }	
		            else {
		               if (dia > 28) {
				            return false
			            }
			            else {
				            return true
			            }
		            }		        
		        }
		        else {
			        if (mes == 4 || mes == 6 || mes == 9 || mes == 11) {
				        if (dia > 30) {
					        return false
				        }
				        else {
					        return true
				        }
			        }
			        else {
				        if (dia > 31) {
					        return false
				        }
				        else {
					        return true
				        }
			        }
		        }
	        }
	        else {
		        return false
	        }	
        }
       
        function AnoBissexto (Ano) {
            if (((Ano % 4)==0) && ((Ano % 100)!=0) || ((Ano % 400)==0))
                return true;
            else
                return false;
        }
        
function max(txarea, max, font) {  
    var total = max;     
    tam = txarea.value.length; 
    str=""; 
    str=str+tam;      
    if ((total - str) < 0){
        document.getElementById(font).innerHTML = 0;       
    } else {
        document.getElementById(font).innerHTML = total - str;       
    }
    if (tam > total){         
       aux = txarea.value;         
       if (total < 0){
            txarea.value = aux.substring(0,max);                    
       } else {
            txarea.value = aux.substring(0,total);                    
       }
       if ((total - str) < 0){
            document.getElementById(font).innerHTML = 0;       
       }else{
            document.getElementById(font).innerHTML = total - str;     
       }
    }
} 

function MaxControls(controle, maximo, idFont, de, para) {
    max(controle, maximo, idFont.replace(de,para))
}

function PassaDominio(StrDado, Dominio)
	{
	var i, j, c;
	var Result;

	Result = "";
	for (i=0; i<StrDado.length; i++)
	{
		c = StrDado.substr(i,1);
		for (j=0; j<Dominio.length; j++)
		{
			if (c == Dominio.substr(j,1)) break;
		}
			
	    if (j < Dominio.length)
		{
		    Result = Result + c;
		}
	}
	return Result;
}
function FormatarCEPBusca(campo,xEvent) 
{
	if(navigator.appName == "Microsoft Internet Explorer"){
		tecla = window.event.keyCode;
	}else{
		tecla = xEvent.which;
	}
	vr = campo.value;
	vr = vr.replace(/([^0-9])/g,'');
	vr = vr.replace(/([a-z][A-Z])/g,'');
	vr = vr.replace(/(^\s+)(\S)(\s+$)/,/^[1]$/);
	tam = vr.length;
	//Formata Mask de cpf
	if ( tecla != 9 && tecla != 8 && tecla != 37 && tecla != 13 && tecla != 39 && tecla != 46 ) {
		if ( tam <= 2 ) 
			campo.value = vr ;
		//if ( (tam > 2) && (tam <= 5) ) 
		//	campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3) ;
		if ( (tam > 5) && (tam > 5) )
			campo.value = vr.substr(0, 2 ) +  vr.substr( 2, 3 ) + '-' + vr.substr( 5, 3 ); // Sergio Rinaldi - ultimo substr alterado de 5,2 para 5,3
	}
	else
	{
	    iTamanho = campo.value.length;
	    if (iTamanho > 0)
	    {
	        iTamanho = iTamanho + 1;
	    }
	    campo.value = vr.substr(0,iTamanho);
	}
}

function formatMoeda(objValue, SeparadorMilesimo, SeparadorDecimal) {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux  = aux2 = '';
	
	objValue = String(objValue);
	len      = objValue.length;
	var num  = objValue.replace(/\./g, "");
    num      = num.replace(/\,/g, "");
    num      += key;

    for (i = num.length -1 ; i >= 0; i--){
        j++
        aux += num.charAt(i);
        if (j == 3){ 
            
            aux += SeparadorMilesimo;
            j = 0;
        }
        
    }

    if (aux.charAt(aux.length - 1) == ".") aux = aux.substring(0, aux.length -1);
    
    for(i = aux.length; i >= 0; i--){
        aux2 += aux.charAt(i - 1); 
    }

    return aux2;
}

function onlyTxt(key){     
	var key = key.keyCode ? key.keyCode : key.which;    

	if (key == 8 || key == 32 || key == 46 || key == 64 || key == 95) {
		return true;
	}        
	  
	if ((key > 64 && key < 91) || (key > 96 && key < 123)) { /* Teclas a-z e A-Z */  
		return true;
	}        
	if ((key > 191 && key < 221) || (key > 223 && key < 253)) {  /* Teclas acentuadas e cidilha */ 
		return true;
	}   
	return false;
}
