﻿//<script type="text/javascript" src="../include/java.js"></script>

//------------Limpa a mascara-----------
function Limpa(IdNome,Mascara){
    if (document.getElementById(IdNome).value == Mascara) {
        document.getElementById(IdNome).value = "";
    }
}

//----------------Maximo de caracteres no imput text (nome,maximo)-----------------------
//onkeyup="MaximoStr('nome',10)"
function MaximoStr(IdNome,maximo) {  
    Valor='';  
    for(i=0;i<maximo;i++) {  
        Valor += document.getElementById(IdNome).value.substr(i,1);  
    }  
    document.getElementById(IdNome).value  =   Valor;
}



//----------------E-MAIL:----------------
//onblur="ValidaEmail('nome');"

function ValidaEmail(IdNome){
    if ((document.getElementById(IdNome).value) != "" ) {
        Valor = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
        if (!Valor.test(document.getElementById(IdNome).value)) 
        {
        alert('Informe um e-mail valido!');
        document.getElementById(IdNome).value = '';
        document.getElementById(IdNome).focus();
        }
    }
}

//----------------onKeyPress="Mascara('TEL',tbtel,FormCad.tbtel.value);"
function Mascara(tipo, campo) {
	 
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
 
 
    if ( campo.value != '' ) {
		switch (tipo)
		{
		    

        case 'TEL': //(00) 0000-0000   14
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;
 
		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
        break;

        
	        }
	}
}

