

oldObj = "";
oldValor = "";
inteiro = new RegExp("[0-9]");
decimal = new RegExp("[\,]");
arroba = new RegExp("[@]");
ponto = new RegExp("[\.]");
hexa = new RegExp("[0-9a-fA-F]");
minutos = new RegExp("\:");
semCaracterEspeciais = new RegExp("[\"!@#$%&*{}^~´`?/><()=+;?,.\\|]");

function tiraEspacos(s) {

    var temp = '';
    
    splitstring = s.split(' ');

    for (i = 0; i < splitstring.length; i++)
    {
        temp += splitstring[i];
    }
    
    return temp;
    
} /* tiraEspacos */

desselecionaCampo = function(field){
	for(i=0;i<field.length;i++){
			field[i].style.background="#FFFFFF";
	}
}

verificaPreenchimentoForm = function(){

	var status=true;
	var verInput = document.getElementsByTagName("INPUT");
	var verSelect = document.getElementsByTagName("SELECT");

	desselecionaCampo(verInput);
	desselecionaCampo(verSelect);

	// Inputs
	for(i=0;i<verInput.length;i++){
		if(verInput[i].value==""){
			if(verInput[i].required){
				verInput[i].focus();
				status = false;
				verInput[i].style.background="#FF0000";
				break;
			}
		}
	}

	if(status==true){
		// selects 
		for(i=0;i<verSelect.length;i++){
			if(verSelect[i].value==""){
				if(verInput[i].required){
					verSelect[i].focus();
					status = false;
					verSelect[i].style.background="#FF0000";
					break;
				}
			}
		}
	}
	
/*	if (status==true){
		if(verificaSenha()){
			enviaForm();
	//		formObj.submit();
			//return true;
		}else{
			return false;
		}
	}else{
		return status;
	}
*/	
}

function verificaSenha(){

			if(document.getElementById('frm_senha').value != document.getElementById('frm_resenha').value){
				alert("Por favor, verifique a senha digitada!!!");
				document.getElementById('frm_senha').style.background="FF0000";
				document.getElementById('frm_senha').focus();
				return false;
			}else{
				return true;
			}
	
}

function autofocus(field, limit, next, evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
	((evt.which) ? evt.which : 0));
	if (charCode > 31 && field.value.length == limit) {
		field.form.elements[next].focus( );
	}
}

function formatarData(campo, teclapres)
{

    var tecla = teclapres.keyCode;
    
	if (tecla == 8 || tecla == 46)
	{
        return; /* Quando BackSpace ou Delete for pressionado, deixa o usuario fazer o que quiser */
	}
    valorSemFormato = campo.value;
	valorSemFormato = valorSemFormato.replace("-", "");
    valorSemFormato = valorSemFormato.replace("-", "");
    
	tamanho = valorSemFormato.length;

	if (tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{

        if ((tamanho >= 2) && (tamanho <= 3))
		{
            campo.value = valorSemFormato.substr(0, 2) + "-" + valorSemFormato.substr(2, tamanho);
        }
		else if ((tamanho >= 4) && (tamanho <= 9))
        {
            campo.value = valorSemFormato.substr(0, 2) + "-" + valorSemFormato.substr(2, 2) + "-" + valorSemFormato.substr(4, 4);
        }
		else
        {
            campo.value = valorSemFormato;
        }

    }
    //if(!isDataEnter(valorSemFormato)){
     //   campo.value = campo.value.substr(0,(campo.value.length -1));
   // }

} /* formatarData */

/*
function formatarCPF(campo, teclaPres)
{
	
	var tecla = teclaPres.keyCode;

	vr = "";
	
	for (i = 0 ; i < campo.value.length ; i++)
	{
		if (campo.value.charAt(i) != "." && campo.value.charAt(i) != "-" && campo.value.charAt(i) != "/")
		{
			vr=vr + campo.value.charAt(i);
		}
	}

	tam = vr.length ;
	campo.maxLength=14;

	if (tam < 15 && tecla != 8)
	{
		tam = vr.length + 1;
	}

	if (tecla == 8)
	{
		tam = tam - 1;
	}

	if (tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)
	{
		if (tam <= 2) { campo.value = vr ;}
		if ((tam > 2) && (tam <= 5) ){ campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
		if ((tam >= 6) && (tam <= 8) ){ campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
		if ((tam >= 9) && (tam <= 11) ){campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}else{
		campo.value = campo.value.substr(0,campo.value.length-1);
	}

}
*/
/* formatarCPF */


function validarNumero(campo,teclaPres){
	var tecla = teclaPres.keyCode;
	if (tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)
	{
		
	}else{
		campo.value = campo.value.substr(0,campo.value.length-1);
	}
}


function checaCEP(obj)
{
  valor = obj.value;
  if(valor != oldValor || oldObj != obj){
	for(i=0;i<valor.length;i++){
	  if(!inteiro.test(valor.charAt(i))){
		valor = valor.substring(0,i) + valor.substring(i+1,valor.length);
		if(valor.length == 1){
		  !inteiro.test(valor)?valor = "":0;
		}
		i = -1;
	  }
	}
	if(valor.length < 1){
	  valor = "";
	}else if(valor.length > 5 && valor.length < 9){
	  valor = valor.substring(0,5) + "-" +  valor.substring(5,valor.length);
	}else if(valor.length > 8){
	  valor = valor.substring(0,5) + "-" +  valor.substring(5,8);
	}
	obj.value = valor;
	oldValor = valor;
	oldObj = obj;
  }
}




function isNum( caractere ) 
  
{ 
  
var strValidos = "0123456789" 
  
if ( strValidos.indexOf( caractere ) == -1 ) 
  
return false; 
  
return true; 
  
} 
  
function validaTecla(campo, event) 
  
{ 
  
var BACKSPACE= 8; 
  
var key; 
  
var tecla; 
  
  
CheckTAB=true; 
  
if(navigator.appName.indexOf("Netscape")!= -1) 
  
tecla= event.which; 
  
else 
  
tecla= event.keyCode; 
  
  
key = String.fromCharCode( tecla); 
  
//alert( 'key: ' + tecla + ' -> campo: ' + campo.value); 
  
  
if ( tecla == 13 ) 
  
return false; 
  
if ( tecla == BACKSPACE ) 
  
return true; 
  
return ( isNum(key)); 
  
} 
  
/*  
function FormataCNPJ( el ) 
  
{ 
  
vr = el.value; 
  
tam = vr.length; 
  
  
if ( vr.indexOf(".") == -1 ) 
  
{ 
  
if ( tam <= 2 ) 
  
el.value = vr; 
  
if ( (tam > 2) && (tam <= 6) ) 
  
el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
  
if ( (tam >= 7) && (tam <= 10) ) 
  
el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/'; 
  
if ( (tam >= 11) && (tam <= 18) ) 
  
el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
  
} 
  
return true; 
  
} 
*/
/* validação de email */

var invalidaddress=new Array()
invalidaddress[0]=""

var testresults
function checkemail(campo){
var invalidcheck=0;
var str=campo.value
var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)){
var tempstring=str.split("@")
tempstring=tempstring[1].split(".")
for (i=0;i<invalidaddress.length;i++){
if (tempstring[0]==invalidaddress[i])
invalidcheck=1
}
if (invalidcheck!=1){
	testresults=true
	campo.style.background="#FFFFFF";
}else{
		alert("Por favor, insira um endereço de email válido!")
		campo.style.background="#FF0000";
		campo.focus();
		testresults=false
}
}
else{
alert("Por favor, insira um endereço de email válido!")
campo.style.background="#FF0000";
campo.focus();
testresults=false
}
return (testresults)
}

// verifica se o cnpj é válidos e formata
function FormataCNPJ(pField)
{
	var val = pField.value;
	var base = val.substring(0, val.length-2);

	pField.value=formatCpfCnpj(val, true);
	dvCpfCnpj(base, false);
	if(isCnpj(val)==false){
		alert('O CNPJ digitado não é válido.');
		pField.style.background="#FF0000";
		pField.focus();
		return false;
	}else{
		pField.style.background="#FFFFFF";
		return true;
	}
} // verifica e formata cnpj


// verifica se o cpf é válidos e formata
function FormataCPF(pField)
{
	var val = pField.value;
	var base = val.substring(0, val.length-2);

	pField.value=formatCpfCnpj(val, true);
	dvCpfCnpj(base, false);
	if(isCpf(val)==false){
		alert('O CPF digitado não é válido.');
		pField.style.background="#FF0000";
		pField.focus();
		return false;
	}else{
		pField.style.background="#FFFFFF";
		return true;
	}
} // verifica e formata cpf

	/*
	else{
		alert("CPF:"
			+ "\nDesformatado = " + unformatNumber(val)
			+ "\nFormatado = " + formatCpfCnpj(val, true)
			+ "\nDVs = " + dvCpfCnpj(base, false)
			+ "\nVálido = " + isCpf(val));
	}
*/
	//return false;

//} //doSubmit
