// JavaScript Document

function camposVazios(valores)
{
	var arrayCampos = valores.split(',');
	var qtdeCampos = arrayCampos.length;
	var liberar = 0;
	

	for(i=0;i<qtdeCampos;i++)
	{
		var campo = document.getElementById(arrayCampos[i]);
		
		if(campo.value=="")
		{
			alert('Por favor preecha os campos (*)Obrigatorios! ');
			campo.focus();
			campo.className='campoSel';
			liberar = 1;
			break;
		}
	}
	
	if(liberar==1)
	{
		return false;
	}
	else
	{
		return true;
	}
	
}

function validarEmail(email)
{
	//alert(email.value);
	if (email.value.indexOf("@") == -1 || email.value.indexOf(".") == -1) 
	{
		window.alert("E-mail inválido.");
		email.focus();
		return false;
	}
	else
	{
		return true;
	}
}



///mascaras
function BlockKeybord()
{
if((event.keyCode < 48) || (event.keyCode > 57))
{
event.returnValue = false;
}
}

function troca(str,strsai,strentra)
{
while(str.indexOf(strsai)>-1)
{
str = str.replace(strsai,strentra);
}
return str;
}

function FormataMoeda(campo,tammax,teclapres,caracter)
{
if(teclapres == null || teclapres == "undefined")
{
var tecla = -1;
}
else
{
var tecla = teclapres.keyCode;
}

if(caracter == null || caracter == "undefined")
{
caracter = ".";
}

vr = campo.value;
if(caracter != "")
{
vr = troca(vr,caracter,"");
}
vr = troca(vr,"/","");
vr = troca(vr,",","");
vr = troca(vr,".","");

tam = vr.length;
if(tecla > 0)
{
if(tam < tammax && tecla != 8)
{
tam = vr.length + 1;
}

if(tecla == 8)
{
tam = tam - 1;
}
}
if(tecla == -1 || tecla == 8 || 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) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
}
if((tam >= 9) && (tam <= 11))
{
campo.value = vr.substr(0, tam - 8) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
}
if((tam >= 12) && (tam <= 14))
{
campo.value = vr.substr(0, tam - 11) + caracter + vr.substr(tam - 11, 3) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
}
if((tam >= 15) && (tam <= 17))
{
campo.value = vr.substr(0, tam - 14) + caracter + vr.substr(tam - 14, 3) + caracter + vr.substr(tam - 11, 3) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
}
}
}

function maskKeyPress(objEvent) 
{
var iKeyCode; 
iKeyCode = objEvent.keyCode; 
if(iKeyCode>=48 && iKeyCode<=57) return true;
return false;
}






function cnpj(cnpj)
{ 
            
	return formataCampo(cnpj, '00.000.000/0000-00', event);
}

function cep(cep)
{              
	           
	return formataCampo(cep, '00.000-000', event);
}

function data(data){ 
	
	return formataCampo(data, '00/00/0000', event);
}

function tel(tel)
{         
	
	return formataCampo(tel, '0000-0000', event);
}


function cpf(cpf)
{
	
	return formataCampo(cpf, '000.000.000-00', event);
}

function formataCampo(campo, Mascara, evento) 
{        
var boleanoMascara; 
var Digitato = evento.keyCode; 
$exp = /\-|\.|\/|\(|\)| /g
campoSoNumeros = campo.value.toString().replace( $exp, "" );
var posicaoCampo = 0;
var NovoValorCampo="";
var TamanhoMascara = campoSoNumeros.length;;
	if (Digitato != 8) 
	{ 
		for(i=0; i<= TamanhoMascara; i++) 
		{                      
		boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".") || (Mascara.charAt(i) == "/"))
		boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))
			if (boleanoMascara)
			{                              
			NovoValorCampo += Mascara.charAt(i); 
			TamanhoMascara++;       
			}
			else
			{       
			NovoValorCampo += campoSoNumeros.charAt(posicaoCampo); 
			posicaoCampo++;  
			}      
		}      
	campo.value = NovoValorCampo; 
	return true;    
	}
	else 
	{ 
		return true;  
	}
}

