// JavaScript Document
//funcao para abrir nova janela
function novajanela(url,nome,tamanho){
	window.open(url,nome,tamanho);
}

//FUNÇAO DE LOGIN BASEADA EM AJAX COM
function XHConn(){  
	var xmlhttp, bComplete = false;  
	try { 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	} catch (e) { 
		try { x
		  mlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		} catch (e) { 
			try { 
			  xmlhttp = new XMLHttpRequest(); 
			} catch (e) { 
				xmlhttp = false; 
			}
		}
	}  
 	if (!xmlhttp) return null;  
		this.connect = function(sURL, sMethod, sVars, fnDone)  {    
 	if (!xmlhttp) return false;    
		bComplete = false;    
		sMethod = sMethod.toUpperCase();

try {      

		if (sMethod == "GET"){        
			xmlhttp.open(sMethod, sURL+"?"+sVars, true);        
			sVars = "";      
		} else {        
			xmlhttp.open(sMethod, sURL, true);        
			xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");        
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");      
		}      
	xmlhttp.onreadystatechange = function(){  
	      
		if (xmlhttp.readyState == 4 && !bComplete){
         	 bComplete = true;          
		  	fnDone(xmlhttp);        
		}};      
		  	xmlhttp.send(sVars);    
		  } catch(z) { 
		  	return false; 
		  }    
		  	return true;  
		  };  
		  return this;
		  }


//// FUNÇÃO QUE EXECUTA AS TAREFAS DE LOGIN
function logar(tp,url) {
/*aqui eu chamo a  a class*/
var myConn = new XHConn();
/*pego o id do campo  */

if (tp == "1001") {
	var poststr = "modulo=" + encodeURI( document.getElementById("modulo").value ) + "&bin=" + encodeURI( document.getElementById("bin").value ) +"&codigo=" + encodeURI( document.getElementById("codigo").value ) +"&senha=" + encodeURI( document.getElementById("senha").value );
} else if (tp == "1002") {
	//+ "&bin=" + encodeURI( document.getElementById("bin").value )
	var poststr = "modulo=" + encodeURI(tp) +"&codigo=" + encodeURI( document.getElementById("codigo").value ) +"&senha=" + encodeURI( document.getElementById("senha").value );
} else if (tp == "1003") {
	var poststr = "modulo=" + encodeURI(tp) + "&codigo=" + encodeURI( document.getElementById("codigo").value ) +"&senha=" + encodeURI( document.getElementById("senha").value );
} else if (tp == "1004") {
	var poststr = "modulo=" + encodeURI(tp) + "&bin=" + encodeURI( document.getElementById("bin").value ) +"&codigo=" + encodeURI( document.getElementById("codigo").value ) +"&senha=" + encodeURI( document.getElementById("senha").value );
} else if (tp == "1005") {
	var poststr = "modulo=1005&bin=" + encodeURI( document.getElementById("bin").value ) +"&codigo=" + encodeURI( document.getElementById("codigo").value ) +"&senha=" + encodeURI( document.getElementById("senha").value );
} else if (tp == "1009") {
	var poststr = "modulo=" + encodeURI(tp) + "&codigo=" + encodeURI( document.getElementById("codigo").value ) +"&senha=" + encodeURI( document.getElementById("senha").value );
}


/* Um alerta informando da não inclusão da biblioteca */
if (!myConn) alert("XMLHTTP ERRO AO PROCESSAR TAREFA.");

/*aqui é onde vai mostrar atualizando quando eu for enviar os dados */
document.getElementById('inclusao').innerHTML = "<img src='../imagens/loading.gif' />";

/* o result do post */

var inclusao = function (oXML) { 
	//alert(oXML.reponseText);
	if (oXML.responseText == "OK") {
	   window.location.href='../restrito/default.php';
	} else {
	  document.getElementById('inclusao').innerHTML = oXML.responseText; 
	}
};

/*aqui é enviado mesmo para pagina receber methodo post,+ as variaveis, valorese informar onde vai atualizar     */
myConn.connect(url, "POST", poststr, inclusao);

/*uma coisa legal nesse script se o usuario não tive suporte a JavaScriptpor isso eu coloquei return false no form o php enviar sozinho  */

}


//// FUNÇÃO QUE EXECUTA AS TAREFAS DE LOGIN
function alteracao(tp,url) {
/*aqui eu chamo a  a class*/
var myConn = new XHConn();
/*pego o id do campo  */


if (tp == "1") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&nlimite=" + encodeURI( document.getElementById("nlimite").value ) +"&limiteant=" + encodeURI( document.getElementById("limiteant").value );
} else if (tp == "2") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&limitecdc=" + encodeURI( document.getElementById("limitecdc").value ) +"&limitemcdc=" + encodeURI( document.getElementById("limitemcdc").value) +"&limitemcdcant=" + encodeURI( document.getElementById("limitemcdcant").value)+"&limitecdcant=" + encodeURI( document.getElementById("limitecdcant").value  );
} else if (tp == "3") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&processo=" + encodeURI( document.getElementById("processo").value ) +"&motivoree=" + encodeURI( document.getElementById("motivoree").value );
} else if (tp == "4") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&processo=" + encodeURI( document.getElementById("processo").value );
} else if (tp == "5") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&nomevinc=" + encodeURI( document.getElementById("nomevinc").value ) +"&ncartao=" + encodeURI( document.getElementById("ncartao").value )+"&cpf=" + encodeURI( document.getElementById("cpf").value )+"&dtnasc=" + encodeURI( document.getElementById("dtnasc").value )+"&grauvinc=" + encodeURI( document.getElementById("grauvinc").value )+"&fonecel=" + encodeURI( document.getElementById("fonecel").value )+"&rendacomp=" + encodeURI( document.getElementById("rendacomp").value )+"&rcomp=" + encodeURI( document.getElementById("rcomp").value )+"&empresa=" + encodeURI( document.getElementById("empresa").value )+"&funcao=" + encodeURI( document.getElementById("funcao").value )+"&endcom=" + encodeURI( document.getElementById("endcom").value )+"&baircom=" + encodeURI( document.getElementById("baircom").value )+"&codcidcom=" + encodeURI( document.getElementById("codcidcom").value )+"&ufcom=" + encodeURI( document.getElementById("ufcom").value )+"&cepcom=" + encodeURI( document.getElementById("cepcom").value )+"&fonecom=" + encodeURI( document.getElementById("fonecom").value )+"&ramal=" + encodeURI( document.getElementById("ramal").value );
} else if (tp == "6") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&diaant=" + encodeURI( document.getElementById("diaant").value ) +"&diavenccc=" + encodeURI( document.getElementById("diavenccc").value ) +"&compras=" + encodeURI( document.getElementById("compras").value );
} else if (tp == "7") {
	if (document.getElementById("funcao").value == "contas") {
	  var alt = "usuario_alt="+ encodeURI( document.getElementById("usuario_alt").value ) + "&contas="+ encodeURI( document.getElementById("contas").value )+"&funcao="+ encodeURI( document.getElementById("funcao").value );	
	} else if (document.getElementById("funcao").value == "funcoes") {
	  var alt = "usuario_alt="+ encodeURI( document.getElementById("usuario_alt").value ) + "&contas="+ encodeURI( document.getElementById("contas").value )+"&funcao="+ encodeURI( document.getElementById("funcao").value );	
	} else if (document.getElementById("funcao").value == "relatorios") {
	  var alt = "usuario_alt="+ encodeURI( document.getElementById("usuario_alt").value ) + "&menu="+ encodeURI( document.getElementById("menu").value )+"&funcao="+ encodeURI( document.getElementById("funcao").value ) +"&submenu="+ encodeURI( document.getElementById("submenu").value ) +"&ssubm="+ encodeURI( document.getElementById("ssubm").value );	
	}
} else if (tp == "8") {
	var alt = "senha_atual=" + encodeURI( document.getElementById("senha_atual").value ) +"&senha_nova=" + encodeURI( document.getElementById("senha_nova").value ) +"&conf_nsenha=" + encodeURI( document.getElementById("conf_nsenha").value );
} else if (tp == "9") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&limitecdc=" + encodeURI( document.getElementById("limitecdc").value ) +"&limitemcdc=" + encodeURI( document.getElementById("limitemcdc").value) +"&limconvparc=" + encodeURI( document.getElementById("limconvparc").value)+"&limtotconv=" + encodeURI( document.getElementById("limtotconv").value  );
} else if (tp == "10") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&bloqueio=" + encodeURI( document.getElementById("bloqueio").value ) +"&obs=" + encodeURI( document.getElementById("obs").value);
} else if (tp == "11") {
	var alt = "binusuario=" + encodeURI( document.getElementById("binusuario").value ) +"&convenio=" + encodeURI( document.getElementById("convenio").value ) +"&ativausua=" + encodeURI( document.getElementById("ativausua").value) +"&nomeusua=" + encodeURI( document.getElementById("nomeusua").value)+"&senhausua=" + encodeURI( document.getElementById("senhausua").value)+"&csenhausua=" + encodeURI( document.getElementById("csenhausua").value)+"&valorusua=" + encodeURI( document.getElementById("valorusua").value)+"&proc=" + encodeURI( document.getElementById("proc").value)+"&cpf=" + encodeURI( document.getElementById("cpf").value)+"&codigoAlt=" + encodeURI( document.getElementById("codigoAlt").value);
}else if (tp == "12") {
	var alt = "binNovo=" + encodeURI( document.getElementById("binNovo").value ) +"&conNovo=" + encodeURI( document.getElementById("conNovo").value );
} else if (tp == "13") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&nomeref=" + encodeURI( document.getElementById("nomeref").value ) +"&foneref=" + encodeURI( document.getElementById("foneref").value )+"&referencia=" + encodeURI( document.getElementById("referencia").value ) +"&chaveref=" + encodeURI( document.getElementById("chaveref").value );
} else if (tp == "14") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&pontos=" + encodeURI( document.getElementById("pontos").value ) +"&resgatar=" + encodeURI( document.getElementById("resgatar").value ) +"&premio=" + encodeURI( document.getElementById("premio").value );
} else if (tp == "15") {
	var alt = "prod=" + encodeURI( document.getElementById("prod").value ) +"&qde=" + encodeURI( document.getElementById("qde").value );
	//alert(alt);
}





/* Um alerta informando da não inclusão da biblioteca */
if (!myConn) alert("XMLHTTP ERRO AO PROCESSAR TAREFA.");

/*aqui é onde vai mostrar atualizando quando eu for enviar os dados */
document.getElementById('resp').innerHTML = "<br><span class='certo'>Processando...</span><br><img src='../imagens/loading.gif' />";

/* o result do post */

var resp = function (oXML) { 
	//alert(oXML.reponseText);
	//if (oXML.responseText == "OK") {
	//   window.location.href='../restrito/default.php';
	//} else {
	  document.getElementById('resp').innerHTML = oXML.responseText; 
	//}
};

/*aqui é enviado mesmo para pagina receber methodo post,+ as variaveis, valorese informar onde vai atualizar     */
myConn.connect(url, "POST", alt, resp);

/*uma coisa legal nesse script se o usuario não tive suporte a JavaScriptpor isso eu coloquei return false no form o php enviar sozinho  */

}

//// FUNÇÃO QUE EXECUTA AS TAREFAS DE LOGIN
function relatorio(tp,url) {
/*aqui eu chamo a  a class*/
var myConn = new XHConn();
/*pego o id do campo  */
if (tp == "1") {
	var alt = "codigo_clie=" + encodeURI( document.getElementById("codigo_clie").value ) +"&pini=" + encodeURI( document.getElementById("pini").value ) +"&pfim=" + encodeURI( document.getElementById("pfim").value );
} 


/* Um alerta informando da não inclusão da biblioteca */
if (!myConn) alert("XMLHTTP ERRO AO PROCESSAR TAREFA.");

/*aqui é onde vai mostrar atualizando quando eu for enviar os dados */
document.getElementById('resp').innerHTML = "<br><span class='certo'>Processando...</span><br><img src='../imagens/loading.gif' />";

/* o result do post */

var resp = function (oXML) { 
	//alert(oXML.reponseText);
	//if (oXML.responseText == "OK") {
	//   window.location.href='../restrito/default.php';
	//} else {
	  document.getElementById('resp').innerHTML = oXML.responseText; 
	//}
};

/*aqui é enviado mesmo para pagina receber methodo post,+ as variaveis, valorese informar onde vai atualizar     */
myConn.connect(url, "POST", alt, resp);

/*uma coisa legal nesse script se o usuario não tive suporte a JavaScriptpor isso eu coloquei return false no form o php enviar sozinho  */

}

// JavaScript Document
//NÃO MOSTRA OS ERROS SE HOUVER DE JAVASCRIPTNA PÁGINA...
/*function semerro(){
return true;}
window.onerror=semerro;
*/

function numero(e) {
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	} else { 
		//if(e.which) {
		// netscape
		key = e.which;
	}
	
	if (key != 8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8 || key == 13));{
    	return true;
	}
}

function FormataCampo(Campo,teclapres,mascara){ 
//pegando o tamanho do texto da caixa de texto com delay de -1 no event 
//ou seja o caractere que foi digitado não será contado. 
strtext = Campo.value 
tamtext = strtext.length 
//pegando o tamanho da mascara 
tammask = mascara.length 
//criando um array para guardar cada caractere da máscara 
arrmask = new Array(tammask) 
//jogando os caracteres para o vetor 
for (var i = 0 ; i < tammask; i++){ 
arrmask[i] = mascara.slice(i,i+1) 
} 
//alert (teclapres.keyCode) 
//começando o trabalho sujo 
if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){ 
if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){ 
Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext) 
} 
else{ 
Detona_Event(Campo,strtext) 
} 
} 
else{//Aqui funcionaria a mascara para números mas eu ainda não implementei 
if ((arrmask[tamtext] == "A")) { 
charupper = event.valueOf() 
//charupper = charupper.toUpperCase() 
Detona_Event(Campo,strtext) 
masktext = strtext + charupper 
Campo.value = masktext 
} 
} 
} 
function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){ 
if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){ 
separador = arrpos 
masktext = strtext + separador 
Campo.value = masktext 
} 
} 
function Detona_Event(Campo,strtext){ 
event.returnValue = false 
if (strtext != "") { 
Campo.value = strtext 
} 
} 

function ValidaPeriodo(){
//validar data de nascimento
		co = "ini";
		cm = "fim";
		
		if (document.frm.pini.value == "") {
		  alert("Periodo Inicial em Branco");
		  document.frm.pini.focus();
		  return false;
		}
		if (document.frm.pfim.value == "") {
		  alert("Periodo Final em Branco");
		  document.frm.pfim.focus();
		  return false;
		}
		document.cookie = "ini" + "=" + document.frm.pini.value;
		document.cookie = "fim" + "=" + document.frm.pfim.value;		
		//alert('Cookie Criado');
		//return true;

         hoje = new Date();
         anoActual = hoje.getFullYear();
         barras = document.frm.pini.value.split("/");
         barras1 = document.frm.pfim.value.split("/");		 
         if (barras.length == 3){
                   dia = barras[0];
                   mes = barras[1];
                   ano = barras[2];
                   resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoActual && ano >= 1900));
			 if (!resultado) {
			   alert("Data Inicial Inválida.");
			   document.frm.pini.focus();
			   return false;
			 }
		} else {
			   alert("Data inicial Inválida.");
			   document.frm.pini.focus();
			   return false;
	    }
		 if (barras1.length == 3){
                   dia1 = barras1[0];
                   mes1 = barras1[1];
                   ano1 = barras1[2];
                   resultado1 = (!isNaN(dia1) && (dia1 > 0) && (dia1 < 32)) && (!isNaN(mes1) && (mes1 > 0) && (mes1 < 13)) && (!isNaN(ano1) && (ano1.length == 4) && (ano1 <= anoActual1 && ano1 >= 1900));
			 if (!resultado1) {
			   alert("Data final Inválida.");
			   document.frm.pfim.focus();
			   return false;
			 }
		} else {
			   alert("Data final Inválida.");
			   document.frm.pfim.focus();
			   return false;
	    }
}

function pegacookie(ck) {
		
		cookie = document.cookie.split(";");
		//alert(cookie[0]+cookie[1]);
		if (ck == "ini"){
		  valorfoo = cookie[0].split("=");
		  if (valorfoo[1].length <= 10) {
		  	document.frm.pini.value = valorfoo[1];
		  } else {
			document.frm.pini.value = '';  
		  }
		} else {
		  valorcoo = cookie[1].split("=");
		  if (valorcoo[1].length <= 10) {
		   document.frm.pfim.value = valorcoo[1];
		  } else {
		   document.frm.pfim.value = '';
		  }
		}
}

/* GRAVA COOKIES DAS DATAS E AS FUNÇÕES DE LEITURA E GRAVAÇÃO */
function criacookie() {
	var x = document.frm.pini.value;
	var t = document.frm.pfim.value;
	if (!x) {
		alert('Informe a Data Inicial.');
	}
	else {
		Cookies.create('ini',x,7);
		Cookies.create('fim',t,7);
		//alert('Cookie Criado');
	}
}

// função para a busca no Site
function ver(num){
	var id="conteudo_"+num;
	var obj=document.getElementById(id);
	var status=obj.style.display;
	if(status=="none"){obj.style.display="inline"}
	else{obj.style.display="none";}
}

function doDestacaTexto(Texto, termoBusca){
	
	/*******************************************************************/
	// CASO QUEIRA MODIFICAR O ESTILO DA MARCAÇÃO ALTERE ESSAS VARIÁVEIS
	/*******************************************************************/
	inicioTag = "<font style='color:#000;background-color:#A0FFFF'><b>";
	fimTag = "</b></font>";
	
	var novoTexto = "";
	var i = -1;
	var lcTermoBusca = termoBusca.toLowerCase();
	var lcTexto = Texto.toLowerCase();

	while (Texto.length > 0){
		i = lcTexto.indexOf(lcTermoBusca, i+1);
		if (i < 0){
			novoTexto += Texto;
			Texto = "";
		}
		else{
			if (Texto.lastIndexOf(">", i) >= Texto.lastIndexOf("<", i)){
				if (lcTexto.lastIndexOf("/script>", i) >= lcTexto.lastIndexOf("<script", i)){
					novoTexto += Texto.substring(0, i) + inicioTag + Texto.substr(i, termoBusca.length) + fimTag;
	  				Texto = Texto.substr(i + termoBusca.length);
					lcTexto = Texto.toLowerCase();
	  				i = -1;
				}
			}
		}
	}
	return novoTexto;
}

function desmarcaTexto(){
	document.getElementById('relatorio_texto').innerHTML = document.getElementById('relatorio_textoOld').innerHTML;
}

function doDestacaTextoBusca(textoBusca, textoObj, ehFrase){
	
	if (ehFrase){
		arrayBusca=[textoBusca];
	} else{
		arrayBusca = textoBusca.split(" ");
	}

	//document.getElementById('relatorio_textoOld').innerHTML = document.getElementById(textoObj).innerHTML;
	
	var Texto = document.getElementById(textoObj).innerHTML;
	
	for (var i = 0; i < arrayBusca.length; i++){
		Texto = doDestacaTexto(Texto, arrayBusca[i]);
	}
	document.getElementById(textoObj).innerHTML = Texto;
	return true;
}


function limpaCampo(vl,vl1,vl2){
	if (vl2 == "Digite a Busca") {
	   document.getElementById(vl1).value = '';
	} 
}

/* VÁLIDA O CAMPO DO CONTAS E SERVIÇOS, POIS É O MESMO PARA CRÉDITO E CONVÊNIO */
function ValidaCampo() {
	vr = document.form1.campo.value;
	if (document.form1.campo.value == "") {
		alert('Informe o Algum Dado do Usuário.');
		document.form1.campo.focus();
		return false;
    }
}

function carrega_ocor(vl) {
 if (vl != "") {	
  document.getElementById("ocor").innerHTML = document.getElementById(vl).innerHTML
 } else {
  document.getElementById("ocor").innerHTML = "";
 }
}

// LIMPA RENDA
function LimpaR(vl) {
	if (vl != "") {
	  document.getElementById(vl).value = "";	
	  document.getElementById(vl).focus();	
	} else {
	  document.cadfunc.renda.value = "";	
	}
	
}

// LIMPA RENDA
function LimpaParc(vl) {
 var nameC = 'parcela[]';
 var keywordsC = document.getElementsByName(nameC);
 keywordsC[vl].value = "";	
 keywordsC[vl].focus();	
}

//
// LIMPA Limite
function LimpaL() {
	document.cadfunc.limiteconv.value = "";
}
//
//

function mascaraHellas(valor, id, mascara, evento){
	/*
		Diego Hellas
		diegohellas@gmail.com
		
		Esse script foi desenvolvido com a finalidade de suprir qualquer necessidade
		com máscaras em formulários HTML.
		Para funcionar corretamente o campo tem que ter obrigatóriamente a propriedade
		id no campo input <input name="teste" id="teste" type="text" />, o script so foi
		testado com o evento onkeyup, não sei do comportamento do script com outros eventos
		Uma outra caracteristica dele é a verificação do tipo de dado que entra por posição
		na máscara comforme a tabelinha a seguir:
		***************************
		*       números      *  # *
		***************************
		* qualuqer caratcter *  @ *
		***************************
	*/  
	
	
	/////////////////////////////////////////////////////////////////////////////////
	//                                 MODELO                                      //
	//onkeyup="mascaraHellas(this.value, this.id, '####.##.##.#######-#/#', event)"//
	/////////////////////////////////////////////////////////////////////////////////
	
	
	//inicializa a variavel que vai conter o valor final
	var valorFinal = "";
	
	//verifica o que foi digitada para que seja verificado se é somente números ou não
	var tecla = evento.keyCode;	
	
	//manetem o tamanho original do campo sem retirar a máscara
	var valorOriginal = valor;
	
	//inicializa um array com todos os caracteres que serão retirado
	var arrNaoPermitidos = new Array("-", ".", "/", "\\", "|", "(", ")", ":", " ");
	
	//retira qualquer máscatra que já tenho sido colocada
	for(i1=0;i1<valor.length;i1++)
	{
		for(i2=0;i2<arrNaoPermitidos.length;i2++)
		{
			if(valor.charAt(i1) == arrNaoPermitidos[i2])
			{
				valor = valor.toString().replace( arrNaoPermitidos[i2], "" );
			}	
		}	
	}	
		
	//verifica se foi precionado o backspae
	if(tecla != 8)
	{	
		//verifica se já não ultrapassou o tamanha máximo da máscara
		if(mascara.length >= valorOriginal.length)
		{
			//loop em cima do valor do campo sem a máscara
			jaTemMascara = false;
			for(i=0;i<valor.length;i++)
			{
				//verifica se a string já recebeu alguma máscara ou não
				if(jaTemMascara == false)
				{
					//verifica se o tipo da entrada de dados tem que ser némerica
					if(mascara.charAt(i) == "#")
					{
						//verifica se foi digitado somente números
						if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)))
						{
							//0 = 96 ou 48
							//1 = 97 ou 49
							//2 = 98 ou 50
							//3 = 99 ou 51
							//4 = 100 ou 52
							//5 = 101 ou 53
							//6 = 102 ou 54
							//7 = 103 ou 55
							//8 = 104 ou 56
							//9 = 105 ou 57
							valorFinal = valorFinal  + valor.charAt(i);
						}
						else//se não foi digitado um número é retirado o caracter da string
						{
							valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
						}					
					}
					else if(mascara.charAt(i) == "@")//verifica se o tipo da entrada é qualquer caracter
					{
						valorFinal = valorFinal  + valor.charAt(i);
					}
					else//se não for quelaquer caracter é algum elemento da máscara
					{
						//verifica se o próxima depois da máscara é númerica 
						if(mascara.charAt(i + 1) == "#")
						{
							//verifica se foi digitado somente números
							if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)))
							{
								//0 = 96 ou 48
								//1 = 97 ou 49
								//2 = 98 ou 50
								//3 = 99 ou 51
								//4 = 100 ou 52
								//5 = 101 ou 53
								//6 = 102 ou 54
								//7 = 103 ou 55
								//8 = 104 ou 56
								//9 = 105 ou 57
								valorFinal = valorFinal + mascara.charAt(i + jaTemMascara)  + valor.charAt(i);			
								jaTemMascara = jaTemMascara + 1;	
							}
							else//se não foi digitado um número é retirado o caracter da string
							{
								valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
							}
						}
						else// se não é númerico então pode ser qualuqer caracter
						{
							valorFinal = valorFinal + mascara.charAt(i + jaTemMascara)  + valor.charAt(i);			
							jaTemMascara = jaTemMascara + 1;
						}					
					}
				}
				else//else da verificação da máscara
				{
					//verifica se foi digitado somente números
					if(mascara.charAt(i + jaTemMascara) == "#")
					{
						//verifica se foi digitado somente números
						if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)))
						{
							//0 = 96 ou 48
							//1 = 97 ou 49
							//2 = 98 ou 50
							//3 = 99 ou 51
							//4 = 100 ou 52
							//5 = 101 ou 53
							//6 = 102 ou 54
							//7 = 103 ou 55
							//8 = 104 ou 56
							//9 = 105 ou 57
							valorFinal = valorFinal  + valor.charAt(i);
						}
						else//se não foi digitado um número é retirado o caracter da string
						{
							valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
						}
					}
					else if(mascara.charAt(i + jaTemMascara) == "@")//verifica se o tipo da entrada é qualquer caracter
					{
						valorFinal = valorFinal  + valor.charAt(i);
					}
					else
					{
						//verifica se foi digitado somente números
						if(mascara.charAt(i + jaTemMascara +1) == "#")
						{
							//verifica se foi digitado somente números
							if(((tecla > 95) && (tecla < 106)) || ((tecla > 47) && (tecla < 58)))
							{
								//0 = 96 ou 48
								//1 = 97 ou 49
								//2 = 98 ou 50
								//3 = 99 ou 51
								//4 = 100 ou 52
								//5 = 101 ou 53
								//6 = 102 ou 54
								//7 = 103 ou 55
								//8 = 104 ou 56
								//9 = 105 ou 57
								valorFinal = valorFinal + mascara.charAt(i + jaTemMascara)  + valor.charAt(i);			
								jaTemMascara = jaTemMascara + 1;	
							}
							else//se não foi digitado um número é retirado o caracter da string
							{
								valorFinal = valorOriginal.substring(0, valorOriginal.length -1);
							}
						}
						else// se não é númerico então pode ser qualuqer caracter
						{
							valorFinal = valorFinal + mascara.charAt(i + jaTemMascara)  + valor.charAt(i);			
							jaTemMascara = jaTemMascara + 1;
						}							
					}	
				}//fim da verificação da máscara	
			}	
		}
		else
		{
			valorFinal = valorOriginal.substring(0, mascara.length);	
		}//final da verificação do tamanha máximo da string
	}
	else
	{
		//valorFinal = valorOriginal.substring(0, valorOriginal.length -1)
		valorFinal = valorOriginal.substring(0, valorOriginal.length);		
	}//final da verificação do backspace
	document.getElementById(id).value = valorFinal;
}
// fim das Mascara Forms

// FORMATA CAMPOS 
////////////////////////////////////////////////////////////////////////////////////////
function cleanMask(val) {
	var strCheck = "'[](){}<>=+-*/_|\~`!?@#$%^&:;,.";
	var aux="";
	var i;
	
	for(i=0; i<val.length; i++) {
		if(strCheck.indexOf(val.charAt(i))==-1) {
			aux+=val.charAt(i);
		}
	}
	return aux;
}

function maskCurrency(val, milSep, decSep) {
	var aux="";
	var aux2="";
	
	var i,j;
			
	len = val.length;
	if (len == 0) {
		aux = '';
	} else if (len == 1) {
		aux = '0'+ decSep + '0' + val;
	} else if (len == 2) {
		aux = '0'+ decSep + val;
	} else if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += val.charAt(i);
			j++;
		}
		aux = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--) {
			aux += aux2.charAt(i);
		}
		aux += decSep + val.substr(len - 2, len);
	}	
	return aux;
}

function mask(_mask, val) {
	var i, mki;
	var aux="";
	
	for(i=mki=0; i<val.length; i++, mki++) {
		if(_mask.charAt(mki)=='' || _mask.charAt(mki)=='#' || _mask.charAt(i)==val.charAt(i)) {
			aux+=val.charAt(i);
		} else {
			aux+=_mask.charAt(mki)+val.charAt(i);
			mki++;
		}
	}
	return aux;
}

function maskEvent(field, _mask, event) {
	var key ='';
	var aux='';
	var len=0;
	var i=0;
	var strCheck = '0123456789';
	var rcode = (window.Event) ? event.which : event.keyCode;
	
	if(rcode == 13 || rcode == 0 || field.value.length == _mask.length  ) {
		//Enter
		key=String.fromCharCode(rcode);
				
		if(rcode!=13 && rcode!=0) {
			return false;
		}
		
		return true;
	}
	
	//Get key value from key code
	key=String.fromCharCode(rcode);
	
	if(strCheck.indexOf(key)==-1) {
		//Not a valid key
		return false;
	}
	
	aux=field.value+key;
	//window.alert(aux);
	aux=mask(_mask,aux);
	//window.alert(aux);
	field.value=aux;	
	return false;
}

function browser() {
	var name = navigator.appName ; 
	return name;
	/*if (name == 'Microsoft Internet Explorer') { 
		
	} else { 
	   
	} */

}

function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var br_ = browser();
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		whichCode = e.keyCode;
	} else if(e.which) {
		// netscape
		whichCode = e.which;
	}
	//var whichCode = (window.Event) ? e.which : e.keyCode;

	if (whichCode == 13 || whichCode == 0 || whichCode == 8) {//Enter e BackSpace
		return true;  
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) {
		return false;  // Not a valid key
	}
	len = fld.value.length;
	for(i = 0; i < len; i++) {
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) {
			break;
		}
	}
	aux = '';
	for(; i < len; i++) {
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) {
			aux += fld.value.charAt(i);
		}
	}
	aux += key;
			
	len = aux.length;
	if (len == 0) {
		fld.value = '';
	} else if (len == 1) {
		fld.value = '0'+ decSep + '0' + aux;
	} else if (len == 2) {
		fld.value = '0'+ decSep + aux;
	} else if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--) {
			fld.value += aux2.charAt(i);
		}
		if (br_ == "Microsoft Internet Explorer") {
			fld.value += decSep + aux.substr(len - 2, len);
		} else {
			fld.value += decSep + aux.substr(len - 2, len);
		}
		
	}	
return false;
}


/* VALIDA MOEDA */
function validaMoeda(vl,idCp,vld){
	
	  if (vl != ""){
	   if (vld == "true") {
			if(vl.indexOf(",") != -1){
				alert('Valor Incorreto, Correto: 52.00, somente use o ponto como separador das casas decimais e não virgula.');
				document.getElementById(idCp).focus();
				return false;
			}
	   }
	  }

}
//

/* Deixando apenas numeros em uma variavel */
function somente_numero(numero){
	var validos   = "0123456789";
	var numero_ok = '';
	
	for(i=0;i<numero.length;i++){
		if (numero_ok != "ERRO"){
			if(validos.indexOf(numero.substr(i,1)) != -1){
				numero_ok += numero.substr(i,1);
			} else {
				numero_ok = "ERRO";
			}
		} else {
			numero_ok = "ERRO";
		}
	}
	return numero_ok;
}

function ValidaData(vl,tp){
	  tm_c = document.getElementById(vl).value;

	  var br_ = browser();
	  if ((tp != "false") && (tm_c.length > 0 )){
         //validar data digitada
         hoje = new Date();
         anoActual = hoje.getFullYear();
		 barras = document.getElementById(vl).value.split("/");
         if (barras.length == 3){
                   dia = barras[0];
                   mes = barras[1];
                   ano = barras[2];
                   resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoActual && ano >= 1900));
			 if (!resultado) {
			    alert("Formato de data invalido !!!");
				if (br_ == "Microsoft Internet Explorer"){
			    	document.getElementById(vl).focus();
				} else {
					campo = document.getElementById(vl);
					setTimeout("campo.focus()",250);
				}
			   return false;
			 } 
		} else {
			    alert("Formato de data invalido !!!");
				if (br_ == "Microsoft Internet Explorer"){
			    	document.getElementById(vl).focus();
				} else {
					campo = document.getElementById(vl);
					setTimeout("campo.focus()",250);
				}
			   return false;
	    }
	  }
}


function MontaNome(v){
	str = TrimS(v);
	nome = str.split(" ");
	if (nome.length < 2) {
		alert("O Nome é Inválido");
		document.getElementById('nome').focus();
	}
	
	nnome = nome[0]+" "+nome[nome.length-1];
	
	document.getElementById('ncartao').value = nnome;
}

function TrimS(str){
	 return str.replace(/^\s+|\s+$/g,"");
}

function trim(cpC){

	String = document.getElementById(cpC).value;
	//alert(String);
	Resultado = String;

	//Retira os espaços do inicio
	//Enquanto o primeiro caracter for igual à "Espaço" 
	//1 caracter do inicio é removido

var i;
i = 0;
//alert(Resultado);

if (Resultado.charCodeAt(2-1) == '32'){
}

while (Resultado.charCodeAt(0) == '32'){
   Resultado = String.substring(i,String.length);
   i++;
}

//Pega a string já formatada e agora retira os espaços do final
//mesmo esquema, enquanto o ultimo caracter for um espaço, 
//ele retira 1 caracter do final...

while(Resultado.charCodeAt(Resultado.length-1) == "32"){
   Resultado = Resultado.substring(0,Resultado.length-1);
  }

	return Resultado;
    String = "";

}

/* Função para pegar, mais rapidamente o elemento selecionado, pelo ID*/
function pegaObj(b){	
	return document.getElementById(b);
	
}



function valida_cpf(obj_cpf) {
	var soma;
	var resto;
	var i;
			
	//var cpf = pega(campo).value;
	var cpf = obj_cpf;
	
	/* O RETORNO SERÁ 0 PARA OK E 1 PARA INVÁLIDO*/
	 if ( cpf.length != 11  ||  cpf == "11111111111" ||  cpf == "22222222222" ||  cpf == "33333333333" ||  cpf == "44444444444" ||  cpf == "55555555555" ||  cpf == "66666666666" ||  cpf == "77777777777" ||  cpf == "88888888888" ||  cpf == "99999999999"){
			 //pega(campo).focus();
			  result = "false";
			 //alert('Digite seu CPF corretamente.');
			} else {
				
				soma = 0;			
				for ( i = 1; i <= 9; i++ ) {
				  soma += Math.floor(cpf.charAt(i-1)) * (11 - i);			
				}
				
				resto = 11 - (soma - (Math.floor(soma / 11) * 11));
				if ( (resto == 10) || (resto == 11) ) {			
				 resto = 0;
				}
				
				if ( resto != Math.floor(cpf.charAt(9)) ) {			
				 //pega(campo).focus();
				 result = "false";			 
				 //alert('Verifique o CPF digitado, ele parece estar incorreto.');
				} else {
					
					soma = 0;
					for (i = 1; i<=10; i++) {			
						soma += cpf.charAt(i-1) * (12 - i);
					}
					
					resto = 11 - (soma - (Math.floor(soma / 11) * 11));
					if ( (resto == 10) || (resto == 11) ) {			
						resto = 0;
					}
					
					if (resto != Math.floor(cpf.charAt(10)) ) {			
					  result = "false";		 
					} else {
					  result = "true";
					}
					
				}

			}
			
			return result;
}

function valida_cnpj(obj_cnpj){
	
	var i;
	var s  = obj_cnpj;
	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){
	  result = "false"; 
	} else {
			
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(0) != d1){
			result = "false";
		} else {

			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){
		  	  	result = "false"; 
			} else {
				result = "true";
			}
		}
	}
	return result;
}

/* Função para criar um elemento após o campo que for dado focus  */
function mensagem_erro(txt, cp, obj_Id){
	
		var objSibling = pegaObj(obj_Id);
		texto          = document.createTextNode(txt);
		objElement     = document.createElement(cp);
		objElement.setAttribute('id','erro_'+obj_Id);
		objElement.setAttribute('class','erro');
		objElement.appendChild(texto);
		objSibling.parentNode.insertBefore(objElement, objSibling.nextSibling);	
	
}

function dasabilitarenter() {
 var teclaEnter = event.keyCode;
  if ((teclaEnter == 13)) { 
   	return false;
  }
 return teclaEnter;
}

function ValidaCadastroConv() {
	
	var camposV = new Array();
	//document.getElementById('validaC').innerHTML = "Validando Campos";
	
	/* CAMPO NOME */   
	
 	if (document.getElementById('nomeconv').value == "") {
		camposV[0] = "nomeconv";
		document.getElementById('nomeconv').className = "textoEr";
	} else {
		if ((document.getElementById('nomeconv').value.length > 7) && (document.getElementById('nomeconv').value.length < 41)) { 
			camposV[0] = "S";
			document.getElementById('nomeconv').className = "texto";
			if (document.getElementById('erro_nomeconv')){
			 document.getElementById('erro_nomeconv').innerHTML = "";
			}
		} else {
			camposV[0] = "nomeconv";
			document.getElementById('nomeconv').className = "textoEr";
			if (document.getElementById('erro_nomeconv')){
			 document.getElementById('erro_nomeconv').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Nome Inválido', 'span', 'nomeconv');
		}
	}
	
	if (document.getElementById('razaosocial').value == "") {
		camposV[1] = "razaosocial";
		document.getElementById('razaosocial').className = "textoEr";
	} else {
		if ((document.getElementById('razaosocial').value.length > 7) && (document.getElementById('razaosocial').value.length < 41)) { 
			camposV[1] = "S";
			document.getElementById('razaosocial').className = "texto";
			if (document.getElementById('erro_razaosocial')){
			 document.getElementById('erro_razaosocial').innerHTML = "";
			}
		} else {
			camposV[1] = "razaosocial";
			document.getElementById('razaosocial').className = "textoEr";
			if (document.getElementById('erro_razaosocial')){
			 document.getElementById('erro_razaosocial').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Razão Social Inválido', 'span', 'razaosocial');
		}
	}
	
	if (document.getElementById('endereco').value == "") {
		camposV[2] = "endereco";
		document.getElementById('endereco').className = "textoEr";
	} else {
		if ((document.getElementById('endereco').value.length > 5) && (document.getElementById('endereco').value.length < 40)) { 
			camposV[2] = "S";
			document.getElementById('endereco').className = "texto";
			if (document.getElementById('erro_endereco')){
			 document.getElementById('erro_endereco').innerHTML = "";
			}
		} else {
			camposV[2] = "endereco";
			document.getElementById('endereco').className = "textoEr";
			if (document.getElementById('erro_endereco')){
			 document.getElementById('erro_endereco').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Endereço Inválido', 'span', 'endereco');
		}
	}
	
	if (document.getElementById('codcidade').value == "#") {
		camposV[3] = "codcidade";
		document.getElementById('codcidade').className = "textoEr";
	} else {
		camposV[3] = "S";
		document.getElementById('codcidade').className = "texto";
		if (document.getElementById('erro_codcidade')){
		  document.getElementById('erro_codcidade').innerHTML = "";
		}
		
	}
	
	if (document.getElementById('cep').value == "") {
		camposV[4] = "cep";
		document.getElementById('cep').className = "textoEr";
	} else {
		if (document.getElementById('cep').value.length != "8")  {
			camposV[4] = "cep";
			document.getElementById('cep').className = "textoEr";
			if (document.getElementById('erro_cep')){
			   document.getElementById('erro_cep').innerHTML = "";
			}
			mensagem_erro(' Tamanho do CEP Inválido', 'span', 'cep');
		} else {
			camposV[4] = "S";
			document.getElementById('cep').className = "texto";
			if (document.getElementById('erro_cep')){
			  document.getElementById('erro_cep').innerHTML = "";
			}
		}
		
	}
	
	if (document.getElementById('bairro').value == "") {
		camposV[5] = "bairro";
		document.getElementById('bairro').className = "textoEr";
	} else {
		if ((document.getElementById('bairro').value.length > 4) && (document.getElementById('bairro').value.length < 30)) { 
			camposV[5] = "S";
			document.getElementById('bairro').className = "texto";
			if (document.getElementById('erro_bairro')){
			 document.getElementById('erro_bairro').innerHTML = "";
			}
		} else {
			camposV[5] = "bairro";
			document.getElementById('bairro').className = "textoEr";
			if (document.getElementById('erro_bairro')){
			 document.getElementById('erro_bairro').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Bairro Inválido', 'span', 'bairro');
		}
	}
	
	if (document.getElementById('contato').value == "") {
		camposV[6] = "contato";
		document.getElementById('contato').className = "textoEr";
	} else {
		if ((document.getElementById('contato').value.length > 3) && (document.getElementById('bairro').value.length < 20)) { 
			camposV[6] = "S";
			document.getElementById('contato').className = "texto";
			if (document.getElementById('erro_contato')){
			 document.getElementById('erro_contato').innerHTML = "";
			}
		} else {
			camposV[6] = "contato";
			document.getElementById('contato').className = "textoEr";
			if (document.getElementById('erro_contato')){
			 document.getElementById('erro_contato').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Contato Inválido', 'span', 'contato');
		}
	}
	
	if (document.getElementById('uf').value == "") {
		camposV[7] = "uf";
		document.getElementById('uf').className = "textoEr";
	} else {
		if (document.getElementById('uf').value.length == 2) { 
			camposV[7] = "S";
			document.getElementById('uf').className = "texto";
			if (document.getElementById('erro_uf')){
			 document.getElementById('erro_uf').innerHTML = "";
			}
		} else {
			camposV[7] = "uf";
			document.getElementById('uf').className = "textoEr";
			if (document.getElementById('erro_uf')){
			 document.getElementById('erro_uf').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Estado Inválido', 'span', 'uf');
		}
	}
	
	if (document.getElementById('telefone').value == "") {
		camposV[8] = "telefone";
		document.getElementById('telefone').className = "textoEr";
	} else {
		if (document.getElementById('telefone').value.length == 10) { 
			camposV[8] = "S";
			document.getElementById('telefone').className = "texto";
			if (document.getElementById('erro_telefone')){
			 document.getElementById('erro_telefone').innerHTML = "";
			}
		} else {
			camposV[8] = "telefone";
			document.getElementById('telefone').className = "textoEr";
			if (document.getElementById('erro_telefone')){
			 document.getElementById('erro_telefone').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Telefone Inválido', 'span', 'telefone');
		}
	}
	
	
	
	erro_js = "";
	cont_j = 1;
	for (x = 8; x >= 0; x--){
		//alert(camposV+'='+camposV[x]);
		if (camposV[x] != "S") {
			document.getElementById(camposV[x]).focus();
			document.getElementById('validaC').innerHTML = "Volte e Verifique os campos Marcados, devem possuir erro no preenchimento.<br><input type=\"submit\" name=\"button\" onClick=\"ValidaCadastroConv();\" id=\"button\" value=\"Validar Cadastro\">";
			erro_js = "ERRO"; 
			//return false;
		} 
	}
	
	if (erro_js != "ERRO") {
		//document.getElementById('validaC').innerHTML = "O Cadastro Pode Continuar, Dados Válidados com Sucesso.<br>";
		document.getElementById('validaC').innerHTML = "<input name=\"enviar_btn\" type=\"image\" id=\"enviar_btn\" value=\"Submit\" src=\"../imagens/continuar.png\" />";
		return true;
	} else {
		return false;
	}
	

}


function ValidaCadastroCred() {
	
	var camposV = new Array();
	document.getElementById('validaC').innerHTML = "Validando Campos";
	
	/* CAMPO NOME */   
	
 	if (document.getElementById('nomeconv').value == "") {
		camposV[0] = "nomeconv";
		document.getElementById('nomeconv').className = "textoEr";
	} else {
		if ((document.getElementById('nomeconv').value.length > 7) && (document.getElementById('nomeconv').value.length < 31)) { 
			camposV[0] = "S";
			document.getElementById('nomeconv').className = "texto";
			if (document.getElementById('erro_nomeconv')){
			 document.getElementById('erro_nomeconv').innerHTML = "";
			}
		} else {
			camposV[0] = "nomeconv";
			document.getElementById('nomeconv').className = "textoEr";
			if (document.getElementById('erro_nomeconv')){
			 document.getElementById('erro_nomeconv').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Nome Inválido', 'span', 'nomeconv');
		}
	}
	
	if (document.getElementById('razaosocial').value == "") {
		camposV[1] = "razaosocial";
		document.getElementById('razaosocial').className = "textoEr";
	} else {
		if ((document.getElementById('razaosocial').value.length > 7) && (document.getElementById('razaosocial').value.length < 41)) { 
			camposV[1] = "S";
			document.getElementById('razaosocial').className = "texto";
			if (document.getElementById('erro_razaosocial')){
			 document.getElementById('erro_razaosocial').innerHTML = "";
			}
		} else {
			camposV[1] = "razaosocial";
			document.getElementById('razaosocial').className = "textoEr";
			if (document.getElementById('erro_razaosocial')){
			 document.getElementById('erro_razaosocial').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Razão Social Inválido', 'span', 'razaosocial');
		}
	}
	
	if (document.getElementById('endereco').value == "") {
		camposV[2] = "endereco";
		document.getElementById('endereco').className = "textoEr";
	} else {
		if ((document.getElementById('endereco').value.length > 5) && (document.getElementById('endereco').value.length < 40)) { 
			camposV[2] = "S";
			document.getElementById('endereco').className = "texto";
			if (document.getElementById('erro_endereco')){
			 document.getElementById('erro_endereco').innerHTML = "";
			}
		} else {
			camposV[2] = "endereco";
			document.getElementById('endereco').className = "textoEr";
			if (document.getElementById('erro_endereco')){
			 document.getElementById('erro_endereco').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Endereço Inválido', 'span', 'endereco');
		}
	}
	
	if (document.getElementById('codcidade').value == "#") {
		camposV[3] = "codcidade";
		document.getElementById('codcidade').className = "textoEr";
	} else {
		camposV[3] = "S";
		document.getElementById('codcidade').className = "texto";
		if (document.getElementById('erro_codcidade')){
		  document.getElementById('erro_codcidade').innerHTML = "";
		}
		
	}
	
	if (document.getElementById('cep').value == "") {
		camposV[4] = "cep";
		document.getElementById('cep').className = "textoEr";
	} else {
		if (document.getElementById('cep').value.length != "8")  {
			camposV[4] = "cep";
			document.getElementById('cep').className = "textoEr";
			if (document.getElementById('erro_cep')){
			   document.getElementById('erro_cep').innerHTML = "";
			}
			mensagem_erro(' Tamanho do CEP Inválido', 'span', 'cep');
		} else {
			camposV[4] = "S";
			document.getElementById('cep').className = "texto";
			if (document.getElementById('erro_cep')){
			  document.getElementById('erro_cep').innerHTML = "";
			}
		}
		
	}
	
	if (document.getElementById('bairro').value == "") {
		camposV[5] = "bairro";
		document.getElementById('bairro').className = "textoEr";
	} else {
		if ((document.getElementById('bairro').value.length > 4) && (document.getElementById('bairro').value.length < 30)) { 
			camposV[5] = "S";
			document.getElementById('bairro').className = "texto";
			if (document.getElementById('erro_bairro')){
			 document.getElementById('erro_bairro').innerHTML = "";
			}

		} else {
			camposV[5] = "bairro";
			document.getElementById('bairro').className = "textoEr";
			if (document.getElementById('erro_bairro')){
			 document.getElementById('erro_bairro').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Bairro Inválido', 'span', 'bairro');
		}
	}
	
	if (document.getElementById('contato').value == "") {
		camposV[6] = "contato";
		document.getElementById('contato').className = "textoEr";
	} else {
		if ((document.getElementById('contato').value.length > 3) && (document.getElementById('bairro').value.length < 31)) { 
			camposV[6] = "S";
			document.getElementById('contato').className = "texto";
			if (document.getElementById('erro_contato')){
			 document.getElementById('erro_contato').innerHTML = "";
			}
		} else {
			camposV[6] = "contato";
			document.getElementById('contato').className = "textoEr";
			if (document.getElementById('erro_contato')){
			 document.getElementById('erro_contato').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Contato Inválido', 'span', 'contato');
		}
	}
	
	if (document.getElementById('uf').value == "") {
		camposV[7] = "uf";
		document.getElementById('uf').className = "textoEr";
	} else {
		if (document.getElementById('uf').value.length == 2) { 
			camposV[7] = "S";
			document.getElementById('uf').className = "texto";
			if (document.getElementById('erro_uf')){
			 document.getElementById('erro_uf').innerHTML = "";
			}
		} else {
			camposV[7] = "uf";
			document.getElementById('uf').className = "textoEr";
			if (document.getElementById('erro_uf')){
			 document.getElementById('erro_uf').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Estado Inválido', 'span', 'uf');
		}
	}
	
	if (document.getElementById('telefone').value == "") {
		camposV[8] = "telefone";
		document.getElementById('telefone').className = "textoEr";
	} else {
		if (document.getElementById('telefone').value.length == 10) { 
			camposV[8] = "S";
			document.getElementById('telefone').className = "texto";
			if (document.getElementById('erro_telefone')){
			 document.getElementById('erro_telefone').innerHTML = "";
			}
		} else {
			camposV[8] = "telefone";
			document.getElementById('telefone').className = "textoEr";
			if (document.getElementById('erro_telefone')){
			 document.getElementById('erro_telefone').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Telefone Inválido', 'span', 'telefone');
		}
	}
	
	
	
	erro_js = "";
	cont_j = 1;
	for (x = 8; x >= 0; x--){
		//alert(camposV+'='+camposV[x]);
		if (camposV[x] != "S") {
			document.getElementById(camposV[x]).focus();
			document.getElementById('validaC').innerHTML = "Volte e Verifique os campos Marcados, devem possuir erro no preenchimento.<br><input type=\"submit\" name=\"button\" onClick=\"ValidaCadastroCred();\" id=\"button\" value=\"Validar Cadastro\">";
			erro_js = "ERRO"; 
			//return false;
		} 
	}
	
	if (erro_js != "ERRO") {
		//document.getElementById('validaC').innerHTML = "O Cadastro Pode Continuar, Dados Válidados com Sucesso.<br>";
		document.getElementById('validaC').innerHTML = "<input name=\"enviar_btn\" type=\"image\" id=\"enviar_btn\" value=\"Submit\" src=\"../imagens/continuar.png\" />";
		return true;
	} else {
		return false;
	}
	

}



function ValidaCadastro() {
	
	var camposV = new Array();
	document.getElementById('validaC').innerHTML = "Validando Campos";


	/* CAMPO NOME */   
	
 	if (document.getElementById('nome').value == "") {
		camposV[0] = "nome";
		document.getElementById('nome').className = "textoEr";
	} else {
		if ((document.getElementById('nome').value.length > 7) && (document.getElementById('nome').value.length < 41)) { 
			camposV[0] = "S";
			document.getElementById('nome').className = "texto";
			if (document.getElementById('erro_nome')){
			 document.getElementById('erro_nome').innerHTML = "";
			}
		} else {
			camposV[0] = "nome";
			document.getElementById('nome').className = "textoEr";
			if (document.getElementById('erro_nome')){
			 document.getElementById('erro_nome').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Nome Inválido', 'span', 'nome');
		}
	}
	
	/* CAMPO SEXO */
	if (document.cForm.sexo.value == "#") {
		camposV[1] = "sexo";
		document.cForm.sexo.className = "textoEr";
	} else {
		camposV[1] = "S";
		document.cForm.sexo.className = "texto";
	}
	
	/* CAMPO DATA DE NASCIMENTO */
	if (document.cForm.dtnasc.value == "") {
		camposV[2] = "dtnasc";
		document.cForm.dtnasc.className = "textoEr";
	} else {
		camposV[2] = "S";
		document.cForm.dtnasc.className = "texto";
	}
	
	/* CAMPO NOME CARTÃO */
	if (document.cForm.ncartao.value == "") {
		camposV[3] = "ncartao";
		document.cForm.ncartao.className = "textoEr";
	} else {
		if (document.cForm.ncartao.value.length > 25){
			camposV[3] = "ncartao";
			document.cForm.ncartao.className = "textoEr";
			if (document.getElementById('erro_ncartao')){
			 document.getElementById('erro_ncartao').innerHTML = "";
			}
			mensagem_erro(' Nome Cartão muito extenso, arrume o nome do Cliente ', 'span', 'ncartao');
		} else {
			camposV[3] = "S";
			document.cForm.ncartao.className = "texto";
			if (document.getElementById('erro_ncartao')){
			 document.getElementById('erro_ncartao').innerHTML = "";
			}
		}
	}
	
	/* CAMPO CPF/CGC */
	if (document.cForm.cpfcgc.value.length == 11) {
		res = valida_cpf(document.cForm.cpfcgc.value);
		if (res ==  "true") {
			camposV[4] = "S";
			document.cForm.cpfcgc.className = "texto";
			if (document.getElementById('erro_cpfcgc')){
			 	document.getElementById('erro_cpfcgc').innerHTML = "";
			}
		} else {
			camposV[4] = "cpfcgc";
			document.cForm.cpfcgc.className = "textoEr";
			if (document.getElementById('erro_cpfcgc')){
			 document.getElementById('erro_cpfcgc').innerHTML = "";
			}
			mensagem_erro(' CPF/CNPJ Inválido ', 'span', 'cpfcgc');
		}
	} else if (document.cForm.cpfcgc.value.length == 14) {
		res = valida_cnpj(document.cForm.cpfcgc.value);
		if (res ==  "true") {
			camposV[4] = "S";
			document.cForm.cpfcgc.className = "texto";
			if (document.getElementById('erro_cpfcgc')){
			 	document.getElementById('erro_cpfcgc').innerHTML = "";
			}
		} else {
			camposV[4] = "cpfcgc";
			document.cForm.cpfcgc.className = "textoEr";
			if (document.getElementById('erro_cpfcgc')){
			 document.getElementById('erro_cpfcgc').innerHTML = "";
			}
			mensagem_erro(' CPF/CNPJ Inválido ', 'span', 'cpfcgc');
		}
	} else {	
		camposV[4] = "cpfcgc";
		document.cForm.cpfcgc.className = "textoEr";
		if (document.getElementById('erro_cpfcgc')){
			 document.getElementById('erro_cpfcgc').innerHTML = "";
		}
		mensagem_erro(' CPF/CNPJ Inválido ', 'span', 'cpfcgc');
	}
	
	/* CAMPO RG/INSC */
	if (document.cForm.rginsc.value == "") {
		camposV[5] = "rginsc";
		document.cForm.rginsc.className = "textoEr";
	} else {
		if (document.cForm.rginsc.value.length < 4) {
			camposV[5] = "rginsc";
			document.cForm.rginsc.className = "textoEr";
			if (document.getElementById('erro_rginsc')){
			 document.getElementById('erro_rginsc').innerHTML = "";
			}
			mensagem_erro(' Tamanho do RG Inválido ', 'span', 'rginsc');
		} else {
			camposV[5] = "S";
			document.cForm.rginsc.className = "texto";
			if (document.getElementById('erro_rginsc')){
			 document.getElementById('erro_rginsc').innerHTML = "";
			}
		}
	}
	
	/* ORGÃO EXPEDIDOR*/
	if (document.cForm.orgexp.value == "") {
		camposV[6] = "orgexp";
		document.cForm.orgexp.className = "textoEr";
	} else {
		res = trim('orgexp');
		if (res.length < 3) {
			camposV[6] = "orgexp";
			document.cForm.orgexp.className = "textoEr";
			if (document.getElementById('erro_orgexp')){
			 document.getElementById('erro_orgexp').innerHTML = "";
			}
			mensagem_erro(' Orgão Expedidor Inválido ', 'span', 'orgexp');
		} else {
			camposV[6] = "S";
			document.cForm.orgexp.className = "texto";
			if (document.getElementById('erro_orgexp')){
			 document.getElementById('erro_orgexp').innerHTML = "";
			}			
		}
	}	
	
	/*DATA DE EXPEDIÇÃO*/
	if (document.cForm.dtexpedicao.value == "") {
		camposV[7] = "dtexpedicao";
		document.cForm.dtexpedicao.className = "textoEr";
	} else {
		camposV[7] = "S";
		document.cForm.dtexpedicao.className = "texto";
	}
	
	/*CAMPO NATURALIDADE*/
	if (document.cForm.naturalidade.value != "") {
		res = trim('naturalidade');
		if (res.length < 5) {
			camposV[8] = "naturalidade";
			document.cForm.naturalidade.className = "textoEr";
			if (document.getElementById('erro_naturalidade')){
			 document.getElementById('erro_naturalidade').innerHTML = "";
			}
			mensagem_erro(' Naturalidade Inválida, Muito Curta ', 'span', 'naturalidade');
		} else {
			camposV[8] = "S";
			document.cForm.naturalidade.className = "texto";
			if (document.getElementById('erro_naturalidade')){
			 document.getElementById('erro_naturalidade').innerHTML = "";
			}			
		}
	} else {
		camposV[8] = "S";
		document.cForm.naturalidade.className = "texto";
			
	}
	
	/*CAMPO TELEFONE CELULAR*/
	if (document.cForm.fonecel.value != "") {
		res = trim('fonecel');
		nu = somente_numero(document.cForm.fonecel.value);
		if (nu != "ERRO") {
			if (res.length != 10) {
				camposV[9] = "fonecel";
				document.cForm.fonecel.className = "textoEr";
				if (document.getElementById('erro_fonecel')){
				 document.getElementById('erro_fonecel').innerHTML = "";
				}
				mensagem_erro(' Telefone Inválido ', 'span', 'fonecel');
			} else {
				camposV[9] = "S";
				document.cForm.fonecel.className = "texto";
				if (document.getElementById('erro_fonecel')){
				 document.getElementById('erro_fonecel').innerHTML = "";
				}			
			}
		} else {
			camposV[9] = "fonecel";
			document.cForm.fonecel.className = "textoEr";
			if (document.getElementById('erro_fonecel')){
			 document.getElementById('erro_fonecel').innerHTML = "";
			}
			mensagem_erro(' Caractere(s) inválido(s), somente números ', 'span', 'fonecel');
		}
	} else {
		camposV[9] = "S";
		document.cForm.fonecel.className = "texto";
	}
	
	/*CAMPO EMPREGO*/
	if (document.cForm.emprego.value == "#") {
		camposV[10] = "emprego";
		document.cForm.emprego.className = "textoEr";
	} else {
		camposV[10] = "S";
		document.cForm.emprego.className = "texto";
	}
	
	/* CAMPO NOME DA MÃE*/
	if (document.cForm.mae.value != "") {
		res = trim('mae');
		if (res.length < 7) {
			camposV[11] = "mae";
			document.cForm.mae.className = "textoEr";
			if (document.getElementById('erro_mae')){
			 document.getElementById('erro_mae').innerHTML = "";
			}
			mensagem_erro(' Nome da Mãe Inválido, Muito Curto ', 'span', 'mae');
		} else {
			camposV[11] = "S";
			document.cForm.mae.className = "texto";	
			if (document.getElementById('erro_mae')){
			 document.getElementById('erro_mae').innerHTML = "";
			}			
		}
	} else {
		camposV[11] = "S";
		document.cForm.mae.className = "texto";
	}
	
	/* CAMPO RENDA */
	if (document.cForm.renda.value == "") {
		camposV[12] = "renda";
		document.cForm.renda.className = "textoEr";
	} else {
	  	camposV[12] = "S";
		document.getElementById('renda').className = "texto";	
	}
	
	/* CAMPO DESCRIÇÃO DA RENDA*/
	if (document.cForm.rendan.value != "") {
		res = trim('rendan');
		if (res.length < 6) {
			camposV[13] = "rendan";
			document.cForm.rendan.className = "textoEr";
			if (document.getElementById('erro_rendan')){
			 document.getElementById('erro_rendan').innerHTML = "";
			}
			mensagem_erro(' Descrição Renda Inválido, Muito Curta ', 'span', 'rendan');
		} else {
			camposV[13] = "S";
			document.cForm.rendan.className = "texto";
			if (document.getElementById('erro_rendan')){
			 document.getElementById('erro_rendan').innerHTML = "";
			}
			
		}
	} else {
		camposV[13] = "S";
		document.cForm.rendan.className = "texto";
		//document.getElementById('erro_rendan').innerHTML = "";
	}
	
	/* CAMPO ESCOLARIDADE */
	if (document.cForm.escolaridade.value == "#") {
		camposV[14] = "escolaridade";
		document.cForm.escolaridade.className = "textoEr";
	} else {
		camposV[14] = "S";
		document.cForm.escolaridade.className = "texto";
	}
	
	/* CAMPO ESTADO CIVIL */
	if (document.cForm.estcivil.value == "#") {
		camposV[15] = "estcivil";
		document.cForm.estcivil.className = "textoEr";
	} else {
		camposV[15] = "S";
		document.cForm.estcivil.className = "texto";
	}
	
	/* CAMPO ENDEREÇO RESIDENCIAL */
	if (document.getElementById('endres').value == "") {
		camposV[16] = "endres";
		document.getElementById('endres').className = "textoEr";
	} else {
		res = trim('endres');
		if (res.length < 5) {
			camposV[16] = "endres";
			document.getElementById('endres').className = "textoEr";
			if (document.getElementById('erro_endres')){
			 document.getElementById('erro_endres').innerHTML = "";
			}
			mensagem_erro(' Endereço Inválido, Muito Curto ', 'span', 'endres');
		} else {
			camposV[16] = "S";
			document.getElementById('endres').className = "texto";
			if (document.getElementById('erro_endres')){
			 document.getElementById('erro_endres').innerHTML = "";
			}
		}
	}
	
	/* CAMPO COMPLEMENTO */
	if (document.cForm.complemento.value != "") {
		res = trim('complemento');
		if (res.length < 4) {
			camposV[17] = "complemento";
			document.cForm.complemento.className = "textoEr";
			if (document.getElementById('erro_complemento')){
			 document.getElementById('erro_complemento').innerHTML = "";
			}
			mensagem_erro(' Complemento Inválido, Muito Curto ', 'span', 'complemento');
		} else {
			camposV[17] = "S";
			document.cForm.complemento.className = "texto";
			if (document.getElementById('erro_complemento')){
			 document.getElementById('erro_complemento').innerHTML = "";
			}
		}
	} else {
		camposV[17] = "S";
		document.cForm.complemento.className = "texto";
		if (document.getElementById('erro_complemento')){
			 document.getElementById('erro_complemento').innerHTML = "";
		}
	}
		
	/* CAMPO BAIRRO RESIDENCIAL */
	if (document.cForm.bairres.value == "") {
		camposV[18] = "bairres";
		document.cForm.bairres.className = "textoEr";
	} else {
		res = trim('bairres');
		if (res.length < 5) {
			camposV[18] = "bairres";
			document.cForm.bairres.className = "textoEr";
			if (document.getElementById('erro_bairres')){
			 document.getElementById('erro_bairres').innerHTML = "";
			}
			mensagem_erro(' Bairro Inválido, Muito Curto ', 'span', 'bairres');
		} else {
			camposV[18] = "S";
			document.cForm.bairres.className = "texto";
			if (document.getElementById('erro_bairres')){
			 document.getElementById('erro_bairres').innerHTML = "";
			}
		}
	}
	
	/* CAMPO CIDADE RESIDENCIAL */
	if (document.cForm.codcidres.value == "#") {
		camposV[19] = "codcidres";
		document.cForm.codcidres.className = "textoEr";
	} else {
		camposV[19] = "S";
		document.cForm.codcidres.className = "texto";
	}
	
	/* CAMPO ESTADO */
	if (document.cForm.ufres.value == "") {
		camposV[20] = "ufres";
		document.cForm.ufres.className = "textoEr";
	} else {
		res = trim('ufres');
		if (res.length == 2) {
			camposV[20] = "S";
			document.cForm.ufres.className = "texto";
			if (document.getElementById('erro_ufres')){
			 document.getElementById('erro_ufres').innerHTML = "";
			}
		} else {
			camposV[20] = "ufres";
			document.cForm.ufres.className = "textoEr";
			if (document.getElementById('erro_ufres')){
			 document.getElementById('erro_ufres').innerHTML = "";
			}
			mensagem_erro(' Estado Inválido, ', 'span', 'ufres');
		}
	}
	
	/* CEP RESIDENCIAL */
	if (document.cForm.cepres.value == "") {
		camposV[21] = "cepres";
		document.cForm.cepres.className = "textoEr";
	} else {
		res = trim('cepres');
		nu = somente_numero(document.cForm.cepres.value);
		if (nu != "ERRO") {
			if (res.length == 8) {
				camposV[21] = "S";
				document.cForm.cepres.className = "texto";
				if (document.getElementById('erro_cepres')){
				 document.getElementById('erro_cepres').innerHTML = "";
				}
			} else {
				camposV[21] = "cepres";
				document.cForm.cepres.className = "textoEr";
				if (document.getElementById('erro_cepres')){
				 document.getElementById('erro_cepres').innerHTML = "";
				}
				mensagem_erro(' CEP Inválido, com '+res.length+' dígitos  ', 'span', 'cepres');
			}
		} else {
			camposV[21] = "cepres";
				document.cForm.cepres.className = "textoEr";
				if (document.getElementById('erro_cepres')){
				 document.getElementById('erro_cepres').innerHTML = "";
				}
				mensagem_erro(' Caractere(s) inválido(s), somente números  ', 'span', 'cepres');
		}
	}

        /* CAMPO EMAIL */
	if (document.cForm.email.value != "") {
		res = trim('email');
		if (res.length > 8) {
			if(res.indexOf("@") == -1 || res.indexOf(".") == -1){
				camposV[22] = "email";
				document.cForm.email.className = "textoEr";
				if (document.getElementById('erro_email')){
			 	 document.getElementById('erro_email').innerHTML = "";
				}
				mensagem_erro(' Email Inválido ', 'span', 'email');
			} else {
				camposV[22] = "S";
				document.cForm.email.className = "texto";
				if (document.getElementById('erro_email')){
			 		document.getElementById('erro_email').innerHTML = "";
				}
			}
		} else {
			camposV[22] = "email";
			document.cForm.email.className = "textoEr";
		}
	} else {
		camposV[22] = "S";
		document.cForm.email.className = "texto";
		if (document.getElementById('erro_email')){
			 document.getElementById('erro_email').innerHTML = "";
		}
	}

        /* CAMPO ENDEREÇO DE CORRESPONDENCIA */
	if (document.cForm.endcorr.value == "#") {
		camposV[23] = "endcorr";
		document.cForm.endcorr.className = "textoEr";
	} else {
                if (document.cForm.endcorr.value == "2"){

                    res2 = trim('email');
                    //alert(res2);
                    if (res2.length > 8) {
                        if(res2.indexOf("@") == -1 || res2.indexOf(".") == -1){
                            camposV[22] = "email";
                            document.cForm.email.className = "textoEr";
                            if (document.getElementById('erro_email')){
                             document.getElementById('erro_email').innerHTML = "";
                            }
                            mensagem_erro(' Email Inválido ', 'span', 'email');
                        } else {
                            camposV[22] = "S";
                            camposV[23] = "S";
                            document.cForm.email.className = "texto";
                            document.cForm.endcorr.className = "texto";

                            if (document.getElementById('erro_email')){
                                document.getElementById('erro_email').innerHTML = "";
                            }
                        }
                    } else {
                            camposV[22] = "email";
                            document.cForm.email.className = "textoEr";
                            mensagem_erro(' Email Inválido ', 'span', 'email');
                    }

                } else {
                    camposV[23] = "S";
                    document.cForm.endcorr.className = "texto";
                }
	}
	
	/* CAMPO TIPO DE MORADIA  23 */
	if (document.cForm.tpmoradia.value == "#") {
		camposV[24] = "tpmoradia";
		document.cForm.tpmoradia.className = "textoEr";
	} else {
		camposV[24] = "S";
		document.cForm.tpmoradia.className = "texto";
	}
	
	/* CAMPO RESIDE DESDE*/
	if (document.cForm.resided.value == "") {
		camposV[25] = "resided";
		document.cForm.resided.className = "textoEr";
	} else {
		camposV[25] = "S";
		document.cForm.resided.className = "texto";
	}
	
	/* CAMPO VALOR DO ALUGUEL */
	if (document.cForm.tpmoradia.value == "2") {
		if (document.cForm.valuguel.value == "") {
			camposV[26] = "valuguel";
			document.cForm.valuguel.className = "textoEr";
			if (document.getElementById('erro_valuguel')){
			 document.getElementById('erro_valuguel').innerHTML = "";
			}
			mensagem_erro(' Preencha o Valor do Aluguel ', 'span', 'valuguel');
		} else {
			camposV[26] = "S";
			document.cForm.valuguel.className = "texto";
			if (document.getElementById('erro_valuguel')){
			 document.getElementById('erro_valuguel').innerHTML = "";
			}
		}
	} else {
		  camposV[26] = "S";
		  document.cForm.valuguel.className = "texto";
		  if (document.getElementById('erro_valuguel')){
			 document.getElementById('erro_valuguel').innerHTML = "";
		  }
	}
	
	/* CAMPO EMPRESA */
	if (document.cForm.empresacad.value != "") {
		res = trim('empresacad');
		if (res.length < 5) {
			camposV[27] = "empresacad";
			document.cForm.empresacad.className = "textoEr";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
			mensagem_erro(' Nome Inválido da Empresa, Muito Curto ', 'span', 'empresacad');
		} else {
			camposV[27] = "S";
			document.cForm.empresacad.className = "texto";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
		}
	} else {
		camposV[27] = "S";
		document.cForm.empresacad.className = "texto";
		if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
		}
	}
	
	/* VALIDANDO OS CAMPOS DOS DADOS EMPRESARIAIS SE A EMPRESA ESTIVER CADASTRADA TEM QUE PREENCHER TODOS OS OUTROS DADOS*/
	if ((document.cForm.empresacad.value != "") || (document.cForm.funcaoempr.value != "") || (document.cForm.fonecom.value != "") || (document.cForm.endcom.value != "") || (document.cForm.baircom.value != "") || (document.cForm.codcidcom.value != "#") || (document.cForm.ufcom.value != "") || (document.cForm.cepcom.value != "") || (document.cForm.endcorr.value == "1")) {
		
		/* CAMPO EMPRESA */
	if (document.cForm.empresacad.value != "") {
		res = trim('empresacad');
		if (res.length < 5) {
			camposV[27] = "empresacad";
			document.cForm.empresacad.className = "textoEr";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
			mensagem_erro(' Nome Inválido da Empresa, Muito Curto ', 'span', 'empresacad');
		} else {
			camposV[27] = "S";
			document.cForm.empresacad.className = "texto";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
		}
	} else {
		camposV[27] = "empresacad";
		document.cForm.empresacad.className = "textoEr";
		if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
		}
	}
		
		
		/* CAMPO FUNÇÃO EMPRESA */
		if (document.cForm.funcaoempr.value == "") {
			camposV[28] = "funcaoempr";
			document.cForm.funcaoempr.className = "textoEr";
		} else {
			res = trim('funcaoempr');
			if (res.length < 5){
				camposV[28] = "funcaoempr";
				document.cForm.funcaoempr.className = "textoEr";
				if (document.getElementById('erro_funcaoempr')){
			 		document.getElementById('erro_funcaoempr').innerHTML = "";
				}
				mensagem_erro(' Função Inválida, Muito Curto ', 'span', 'funcaoempr');
			} else {
				camposV[28] = "S";
				document.cForm.funcaoempr.className = "texto";
				if (document.getElementById('erro_funcaoempr')){
			 	 document.getElementById('erro_funcaoempr').innerHTML = "";
				}
			}
		}
		
		camposV[29] = "S";
		/*document.cForm.dtadmissao.className = "texto";*/
		
		/* CAMPO FONE EMPR 30*/
		if (document.cForm.fonecom.value == "") {
			camposV[30] = "fonecom";
			document.cForm.fonecom.className = "textoEr";
		} else {
			res = trim('fonecom');
			nu = somente_numero(document.cForm.fonecom.value);
			if (nu != "ERRO") {
				if (res.length == 10) {
					camposV[30] = "S";
					document.cForm.fonecom.className = "texto";
					if (document.getElementById('erro_fonecom')){
					  document.getElementById('erro_fonecom').innerHTML = "";
					}
				} else {
					camposV[30] = "fonecom";
					document.cForm.fonecom.className = "textoEr";
					if (document.getElementById('erro_fonecom')){
						document.getElementById('erro_fonecom').innerHTML = "";
					}
					mensagem_erro(' Telefone Incorreto, tamanho '+res.length+' dígitos ', 'span', 'fonecom');
				}
			} else {
					camposV[30] = "fonecom";
					document.cForm.fonecom.className = "textoEr";
					if (document.getElementById('erro_fonecom')){
						document.getElementById('erro_fonecom').innerHTML = "";
					}
					mensagem_erro(' Caractere(s) inválido(s), somente números ', 'span', 'fonecom');
			}
		}
		
		/* CAMPO ENDCOM */ 
		if (document.cForm.endcom.value == "") {
			camposV[31] = "endcom";
			document.cForm.endcom.className = "textoEr";
		} else {
			res = trim('endcom');
			if (res.length > 4) {
				camposV[31] = "S";
				document.cForm.endcom.className = "texto";
				if (document.getElementById('erro_endcom')){
				 document.getElementById('erro_endcom').innerHTML = "";
				}
			} else {
				camposV[31] = "endcom";
				document.cForm.endcom.className = "textoEr";
				if (document.getElementById('erro_endcom')){
			 		document.getElementById('erro_endcom').innerHTML = "";
				}
				mensagem_erro(' Endereço inválido, Muito Curto ', 'span', 'endcom');
			}
		}
		
		
	/* CAMPO BAIRRO COMERCIAL*/
	if (document.cForm.baircom.value == "") {
		camposV[32] = "baircom";
		document.cForm.baircom.className = "textoEr";
	} else {
		res = trim('baircom');
		if (res.length < 5) {
			camposV[32] = "baircom";
			document.cForm.baircom.className = "textoEr";
			if (document.getElementById('erro_baircom')){
			 document.getElementById('erro_baircom').innerHTML = "";
			}
			mensagem_erro(' Bairro inválido, Muito Curto ', 'span', 'baircom');
		} else {
			camposV[32] = "S";
			document.cForm.baircom.className = "texto";
			if (document.getElementById('erro_baircom')){
			 document.getElementById('erro_baircom').innerHTML = "";
			}
		}
	}
	
	/* CAMPO CIDADE COMERCIAL */
	if (document.cForm.codcidcom.value == "#") {
		camposV[33] = "codcidcom";
		document.cForm.codcidcom.className = "textoEr";
	} else {
		camposV[33] = "S";
		document.cForm.codcidcom.className = "texto";
	}
	
	/* CAMPO ESTADO COMERCIAL */
	if (document.cForm.ufcom.value == "") {
		camposV[34] = "ufcom";
		document.cForm.ufcom.className = "textoEr";
	} else {
		res = trim('ufres');
		if (res.length == 2) {
			camposV[34] = "S";
			document.cForm.ufcom.className = "texto";
			if (document.getElementById('erro_ufcom')){
			 document.getElementById('erro_ufcom').innerHTML = "";
			}
		} else {
			camposV[34] = "ufcom";
			document.cForm.ufcom.className = "textoEr";
			if (document.getElementById('erro_ufcom')){
			 document.getElementById('erro_ufcom').innerHTML = "";
			}
			mensagem_erro(' Estado inválido, Muito Curto ', 'span', 'ufcom');
		}
	}
	
	/* CEP RESIDENCIAL COMERCIAL */
	if (document.cForm.cepcom.value == "") {
		camposV[35] = "cepcom";
		document.cForm.cepcom.className = "textoEr";
	} else {
		res = trim('cepcom');
		nu = somente_numero(document.cForm.cepcom.value);
		if (nu != "ERRO") {
			if (res.length == 8) {
				camposV[35] = "S";
				document.cForm.cepcom.className = "texto";
				if (document.getElementById('erro_cepcom')){
				 document.getElementById('erro_cepcom').innerHTML = "";
				}
			} else {
				camposV[35] = "cepcom";
				document.cForm.cepcom.className = "textoEr";
				if (document.getElementById('erro_cepcom')){
				 document.getElementById('erro_cepcom').innerHTML = "";
				}
				mensagem_erro(' CEP Inválido, com '+res.length+' dígitos ', 'span', 'cepcom');
			}
		} else {
				camposV[35] = "cepcom";
				document.cForm.cepcom.className = "textoEr";
				if (document.getElementById('erro_cepcom')){
				 document.getElementById('erro_cepcom').innerHTML = "";
				}
				mensagem_erro(' Caractere(s) inválido(s), somente números ', 'span', 'cepcom');
		}
	}
	

	} else {
		camposV[28] = "S";
		document.cForm.funcaoempr.className = "texto";
		if (document.getElementById('erro_funcaoempr')){
			 document.getElementById('erro_funcaoempr').innerHTML = "";
		}
		camposV[29] = "S";
		document.cForm.dtadmissao.className = "texto";
		if (document.getElementById('erro_dtadmissao')){
			 document.getElementById('erro_dtadmissao').innerHTML = "";
		}
		camposV[30] = "S";
		document.cForm.fonecom.className = "texto";
		if (document.getElementById('erro_fonecom')){
			 document.getElementById('erro_fonecom').innerHTML = "";
		}
		camposV[31] = "S";
		document.cForm.endcom.className = "texto";
		if (document.getElementById('erro_endcom')){
			 document.getElementById('erro_encom').innerHTML = "";
		}
		camposV[32] = "S";
		document.cForm.baircom.className = "texto";
		if (document.getElementById('erro_baircom')){
			 document.getElementById('erro_baircom').innerHTML = "";
		}
		camposV[33] = "S";
		document.cForm.codcidcom.className = "texto";
		camposV[34] = "S";
		document.cForm.ufcom.className = "texto";
		if (document.getElementById('erro_ufcom')){
			 document.getElementById('erro_ufcom').innerHTML = "";
		}
		camposV[35] = "S";
		document.cForm.cepcom.className = "texto";
		if (document.getElementById('erro_cepcom')){
			 document.getElementById('erro_cepcom').innerHTML = "";
		}
		
	}/* FIM DA VALIDAÇÃO DOS CAMPOS EMPRESARIAIS */

	
	/* CAMPO DIA DE VENCIMENTO */
	if (document.cForm.diavenccc.value == "#") {
		camposV[36] = "diavenccc";
		document.cForm.diavenccc.className = "textoEr";
	} else {
		camposV[36] = "S";
		document.cForm.diavenccc.className = "texto";
	}
	
	
	
	
	
	/* OUTROS CAMPOS DO VINCULADO A RENDA */
	if ((document.cForm.nomevinc.value != "") || (document.cForm.grauvinc.value != "#") || (document.cForm.cpfvinc.value != "") || (document.cForm.fonevinc.value != "") || (document.cForm.rendasal.value != "") || (document.cForm.nascvinc.value != "") || (document.cForm.emprvinc.value != "") || (document.cForm.funcaovinc.value != "")){
		
			/* NOME DO VINCULADO */
			if (document.cForm.nomevinc.value == "") {
				camposV[37] = "nomevinc";
				document.cForm.nomevinc.className = "textoEr";
				if (document.getElementById('erro_nomevinc')){
					 document.getElementById('erro_nomevinc').innerHTML = "";
				}
			} else {
				res = trim('nomevinc');
				if (res.length < 7) {
					camposV[37] = "nomevinc";
					document.cForm.nomevinc.className = "textoEr";
					if (document.getElementById('erro_nomevinc')){
					 document.getElementById('erro_nomevinc').innerHTML = "";
					}
					mensagem_erro(' Nome do Vinculado Incorreto ', 'span', 'nomevinc');
				} else {
					camposV[37] = "S";
					document.cForm.nomevinc.className = "texto";
					if (document.getElementById('erro_nomevinc')){
					 document.getElementById('erro_nomevinc').innerHTML = "";
					}
				}
			} 
		
		
		/* CAMPO GRAU VINCULADO */ 
		if (document.cForm.grauvinc.value == "#") {
			camposV[38] = "grauvinc";
			document.cForm.grauvinc.className = "textoEr";
		} else {
			camposV[38] = "S";
			document.cForm.grauvinc.className = "texto";
		}
		
		/* CAMPO CPF VINCULADO */
		if (document.cForm.cpfvinc.value == "") {
			camposV[39] = "cpfvinc";
			document.cForm.cpfvinc.className = "textoEr";
		} else {
			res = trim('cpfvinc');
			res = valida_cpf(document.cForm.cpfcgc.value);
			if (res == "true") {
				camposV[39] = "S";
				document.cForm.cpfvinc.className = "texto";
				if (document.getElementById('erro_cpfvinc')){
					document.getElementById('erro_cpfvinc').innerHTML = "";
				}
			} else {
				camposV[39] = "cpfvinc";
				document.cForm.cpfvinc.className = "textoEr";
				if (document.getElementById('erro_cpfvinc')){
					document.getElementById('erro_cpfvinc').innerHTML = "";
				}
				mensagem_erro(' CPF Vinculado Inválido ', 'span', 'cpfvinc');
			}
		}
		
		/* CAMPO DATA DE NASCIMENTO */
		if (document.cForm.nascvinc.value == "") {
			camposV[48] = "nascvinc";
			document.cForm.nascvinc.className = "textoEr";
		} else {
			camposV[48] = "S";
			document.cForm.nascvinc.className = "texto";
		}
		
		/* CAMPO EMPRESA VINCULADO */
		if (document.cForm.emprvinc.value == "") {
			camposV[46] = "emprvinc";
			document.cForm.emprvinc.className = "textoEr";
		} else {
			res = trim('emprvinc');
			//nu = somente_numeros(res);
				if (res.length > 4) {
					camposV[46] = "S";
					document.cForm.emprvinc.className = "texto";
					if (document.getElementById('erro_emprvinc')){
					 document.getElementById('erro_emprvinc').innerHTML = "";
					}
				} else {
					camposV[46] = "emprvinc";
					document.cForm.emprvinc.className = "textoEr";
					if (document.getElementById('erro_emprvinc')){
						document.getElementById('erro_emprvinc').innerHTML = "";
					}
					mensagem_erro(' Empresa com Nome muito Curto ', 'span', 'emprvinc');
				}
		}
		
		/* CAMPO FUNÇÃO VINCULADOS */
		if (document.cForm.funcaovinc.value == "") {
			camposV[47] = "funcaovinc";
			document.cForm.funcaovinc.className = "textoEr";
		} else {
			res = trim('funcaovinc');
			//nu = somente_numeros(res);
				if (res.length > 4) {
					camposV[47] = "S";
					document.cForm.funcaovinc.className = "texto";
					if (document.getElementById('erro_funcaovinc')){
					 document.getElementById('erro_funcaovinc').innerHTML = "";
					}
				} else {
					camposV[47] = "funcaovinc";
					document.cForm.emprvinc.className = "textoEr";
					if (document.getElementById('erro_funcaovinc')){
						document.getElementById('erro_funcaovinc').innerHTML = "";
					}
					mensagem_erro(' Função com descrição muito Curto ', 'span', 'funcaovinc');
				}
		}
		
		/* CAMPO RENDA */
		if (document.cForm.rendasal.value == "") {
			camposV[41] = "rendasal";
			document.cForm.rendasal.className = "textoEr";
		} else {
			camposV[41] = "S";
			document.cForm.rendasal.className = "texto";
		}
		
		
		/* CAMPO FONE VINCULADO */
		if (document.cForm.fonevinc.value == "") {
			camposV[40] = "fonevinc";
			document.cForm.fonevinc.className = "textoEr";
		} else {
			res = trim('fonevinc');
			//nu = somente_numeros(res);
				if (res.length == 10) {
					camposV[40] = "S";
					document.cForm.fonevinc.className = "texto";
					if (document.getElementById('erro_fonevinc')){
					 document.getElementById('erro_fonevinc').innerHTML = "";
					}
				} else {
					camposV[40] = "fonevinc";
					document.cForm.fonevinc.className = "textoEr";
					if (document.getElementById('erro_fonevinc')){
						document.getElementById('erro_fonevinc').innerHTML = "";
					}
					mensagem_erro(' Telefone Incorreto, com '+res.length+' dígitos ', 'span', 'fonevinc');
				}
		}

		
	} else {
		camposV[37] = "S";
		document.cForm.nomevinc.className = "texto";
		camposV[38] = "S";
		document.cForm.grauvinc.className = "texto";
		camposV[39] = "S";
		document.cForm.cpfvinc.className = "texto";
		camposV[40] = "S";
		document.cForm.fonevinc.className = "texto";
		camposV[41] = "S";
		document.cForm.rendasal.className = "texto";
		camposV[46] = "S";
		document.cForm.emprvinc.className = "texto";
		camposV[47] = "S";
		document.cForm.funcaovinc.className = "texto";
		camposV[48] = "S";
		document.cForm.nascvinc.className = "texto";
	}
	
	if (document.cForm.limitemcdc.value != "") {
		
		if (document.cForm.limitecdc.value == "") {
			camposV[43] = "limitecdc";
			document.cForm.limitecdc.className = "textoEr";
		} else {
			camposV[42] = "S";
			document.cForm.limitemcdc.className = "texto";
			camposV[43] = "S";
			document.cForm.limitecdc.className = "texto";
		}
		
	} else {
		camposV[42] = "S";
		document.cForm.limitemcdc.className = "texto";
		camposV[43] = "S";
		document.cForm.limitecdc.className = "texto";
	}
	
	/* CAMPO LIMITE CARTAO */
	if (document.cForm.limitecartao.value == "") {
		camposV[44] = "limitecartao";
		document.cForm.limitecartao.className = "textoEr";
	} else {
		camposV[44] = "S";
		document.cForm.limitecartao.className = "texto";
	}
	
	if (document.cForm.uncad.value == "#") {
	   	camposV[45] = "uncad";
	   	document.cForm.uncad.className = "textoEr";
	} else {
		camposV[45] = "S";
	   	document.cForm.uncad.className = "texto";
	}
	
	if ((document.cForm.nomerefpes.value != "") || (document.cForm.fonerefpes.value != "")) {
		
		if (document.cForm.nomerefpes.value == "") {
			camposV[49] = "nomerefpes";
			document.cForm.nomerefpes.className = "textoEr";
		} else {
			camposV[49] = "S";
			document.cForm.nomerefpes.className = "texto";
		}
		
		
		/* CAMPO FONE REF. PESSOAL */
		if (document.cForm.fonerefpes.value == "") {
			camposV[50] = "fonerefpes";
			document.cForm.fonerefpes.className = "textoEr";
		} else {
			res = trim('fonerefpes');
			//nu = somente_numeros(res);
				if (res.length == 10) {
					camposV[50] = "S";
					document.cForm.fonerefpes.className = "texto";
					if (document.getElementById('erro_fonerefpes')){
					 document.getElementById('erro_fonerefpes').innerHTML = "";
					}
				} else {
					camposV[50] = "fonerefpes";
					document.cForm.fonerefpes.className = "textoEr";
					if (document.getElementById('erro_fonerefpes')){
						document.getElementById('erro_fonerefpes').innerHTML = "";
					}
					mensagem_erro(' Telefone Incorreto, com '+res.length+' dígitos ', 'span', 'fonerefpes');
				}
		}
		
		
	} else {
		camposV[49] = "S";
		document.cForm.nomerefpes.className = "texto";
		camposV[50] = "S";
		document.cForm.fonerefpes.className = "texto";
	}
	
	if ((document.cForm.nomerefcom.value != "") || (document.cForm.fonerefcom.value != "")) {
		
		if (document.cForm.nomerefcom.value == "") {
			camposV[51] = "nomerefcom";
			document.cForm.nomerefcom.className = "textoEr";
		} else {
			camposV[51] = "S";
			document.cForm.nomerefcom.className = "texto";
		}
		
		/* CAMPO FONE REF. COMERCIAL */
		if (document.cForm.fonerefcom.value == "") {
			camposV[52] = "fonerefcom";
			document.cForm.fonerefcom.className = "textoEr";
		} else {
			res = trim('fonerefcom');
			//nu = somente_numeros(res);
				if (res.length == 10) {
					camposV[52] = "S";
					document.cForm.fonerefcom.className = "texto";
					if (document.getElementById('erro_fonerefcom')){
					 document.getElementById('erro_fonerefcom').innerHTML = "";
					}
				} else {
					camposV[52] = "fonerefcom";
					document.cForm.fonerefcom.className = "textoEr";
					if (document.getElementById('erro_fonerefcom')){
						document.getElementById('erro_fonerefcom').innerHTML = "";
					}
					mensagem_erro(' Telefone Incorreto, com '+res.length+' dígitos ', 'span', 'fonerefcom');
				}
		}
		
	} else {
		camposV[51] = "S";
		document.cForm.nomerefcom.className = "texto";
		camposV[52] = "S";
		document.cForm.fonerefcom.className = "texto";
	}
	
	erro_js = "";
	cont_j = 1;
	for (x = 52; x >= 0; x--){
		//alert(camposV+'='+camposV[x]);
		if (camposV[x] != "S") {
			document.getElementById(camposV[x]).focus();
			document.getElementById('validaC').innerHTML = "Volte e Verifique os campos Marcados, devem possuir erro no preenchimento.";
			erro_js = "ERRO"; 
			//return false;
		} 
	}
	
	if (erro_js != "ERRO") {
	    document.getElementById('validarbtn').innerHTML = "";
		document.getElementById('validaC').innerHTML = "<span class='certo'>O Cadastro Pode Continuar, Dados Válidados com Sucesso.</span><br>"+
		"<input name=\"enviar_btn\" type=\"image\" id=\"enviar_btn\" value=\"Submit\" src=\"../imagens/continuar.png\" />";
		return true;
	} else {
		return false;
	}
	//}
	
}

function rendaDiv(cmp_){
   //var  ve = form1.renda.value;
   //alert ("Valor da Renda é "+ve);
   document.cForm.detalhesRenda.value = cmp_;
}

function supervisor() {
	
	if (document.super_.user_super.value == "") {
		alert('Informe o Código do Supervisor');
		document.super_.user_super.focus();
		return false;
	}
	if (document.getElementById('senha_super').value == "") {
		alert('Informe a Senha do Supervisor');
		document.getElementById('senha_super').focus();
		return false;
	}
}

/// ATRIBUI CODIGO AO FORM DE ALTERAÇÃO DE CADASTRO
function AtribuiCodigo(vl){ 
    var i 
    if (vl){
      window.opener.document.getElementById('campo').value = vl;
      self.close();
    } else {
      for (i=0;i<document.BuscaClientes.codigo.length+1;i++){ 
        if (document.BuscaClientes.codigo[i].checked) 
            break; 
      } 
     window.opener.document.getElementById('campo').value = document.BuscaClientes.codigo[i].value;
     self.close(); 
    }
} 

///ABRE UMA PAGINA DENTRO DO LIGHTBOX
function abreOpcao(op,vl){
	if (op == "limite"){
		window.location.href='1001FrmLimites.php?codigo_clie='+vl;
	} else if (op == "limitecv"){
		window.location.href='1002FrmLimites.php?codigo_clie='+vl;
	} else if (op == "limitecvp") {
	   window.location.href='1002FrmLimitesParc.php?codigo_clie='+vl;
	} else if (op == "limitecdc") {
	   window.location.href='1001FrmLimitesCDC.php?codigo_clie='+vl;
	} else if (op == "reimpressao") {
	   window.location.href='FrmReimpressao.php?codigo_clie='+vl;
	} else if (op == "emissao") {
	   window.location.href='FrmEmissao.php?codigo_clie='+vl;
	} else if (op == "fatura") {
	   window.location.href='../procedimentos/faturacliente.php?chave='+vl;
	} else if (op == "faturaConv") {
	   window.location.href='../procedimentos/1002faturaConvenio.php?chave='+vl;
	} else if (op == "faturaConvenio") {
	   window.location.href='../procedimentos/1001faturaConvenio.php?chave='+vl;
	} else if (op == "vinculado") {
	   window.location.href='1001FrmVinculado.php?codigo_clie='+vl;
	} else if (op == "vinculadoconv") {
	   window.location.href='1002FrmVinculado.php?codigo_clie='+vl;
	} else if (op == "doccobranca") {
	   window.location.href='../impressao/impressaoFat.php?codigo_clie='+vl;
	} else if (op == "proposta") {
	   window.location.href='../impressao/meio.php?codigo_clie='+vl;
	} else if (op == "negociacao") {
	   window.location.href='../impressao/descricao.php?codigo_clie='+vl;
	} else if (op == "dadoscadastrais") {
	   window.location.href='../forms/AlteracaoCadastro.php?codigo_clie='+vl;
	} else if (op == "cadastroconv") {
	   window.location.href='../forms/1002frmcadastro.php?codigo_clie='+vl;
	} else if (op == "cancelar") {
	   window.location.href='../procedimentos/1001CancelaNegociacao.php?codigo_clie='+vl;
	} else if (op == "verdados") {
	   window.location.href='../impressao/dadosCadastrais.php?codigo_clie='+vl;
	} else if (op == "referencia") {
	   window.location.href='../forms/1001FrmCadReferencia.php?codigo_clie='+vl;
	} 
	
	
}

function carrega(){
	window.location.reload();
}

function habilitaContinuar(){
	if (document.getElementById('habilita').checked){
		document.getElementById("button").style.visibility = "visible";
	} else {
		document.getElementById("button").style.visibility = "hidden";
	}
}

function printExternal(url) {
	printWindow = new Object();
	printWindow.window.location = url;
	printWindow.window.print();
}

function ValidaVinc(){
	var camposV = new Array();
	var res;
	document.getElementById('cad_dados').innerHTML = "Validando Campos";
	
	
	if (document.getElementById('nomevinc').value == "") {
		camposV[0] = "nomevinc";
		document.getElementById('nomevinc').className = "textoEr";
	} else {
		if ((document.getElementById('nomevinc').value.length > 7) && (document.getElementById('nomevinc').value.length < 41)) { 
			camposV[0] = "S";
			document.getElementById('nomevinc').className = "texto";
			if (document.getElementById('erro_nomevinc')){
			 document.getElementById('erro_nomevinc').innerHTML = "";
			}
		} else {
			camposV[0] = "nomevinc";
			document.getElementById('nomevinc').className = "textoEr";
			if (document.getElementById('erro_nomevinc')){
			 document.getElementById('erro_nomevinc').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Nome Inválido', 'span', 'nomevinc');
		}
	}
	
	if (document.getElementById('ncartao').value == "") {
		camposV[1] = "ncartao";
		document.getElementById('ncartao').className = "textoEr";
	} else {
		if ((document.getElementById('ncartao').value.length > 5) && (document.getElementById('ncartao').value.length < 26)) { 
			camposV[1] = "S";
			document.getElementById('ncartao').className = "texto";
			if (document.getElementById('erro_ncartao')){
			 document.getElementById('erro_ncartao').innerHTML = "";
			}
		} else {
			camposV[1] = "ncartao";
			document.getElementById('ncartao').className = "textoEr";
			if (document.getElementById('erro_ncartao')){
			 document.getElementById('erro_ncartao').innerHTML = "";
			}
			mensagem_erro(' Tamanho do Nome Inválido', 'span', 'ncartao');
		}
	}
	if (document.getElementById('cpf').value == "") {
		camposV[2] = "cpf";
		document.getElementById('cpf').className = "textoEr";
	} else {
		if (document.getElementById('cpf').value.length == 11) { 
			res = valida_cpf(document.getElementById('cpf').value);
			if (res ==  "true") {
				camposV[2] = "S";
				document.getElementById('cpf').className = "texto";
				if (document.getElementById('erro_cpf')){
					document.getElementById('erro_cpf').innerHTML = "";
				}
			} else {
				camposV[2] = "cpf";
				document.getElementById('cpf').className = "textoEr";
				if (document.getElementById('erro_cpf')){
				 document.getElementById('erro_cpf').innerHTML = "";
				}
				mensagem_erro(' CPF/CNPJ Inválido ', 'span', 'cpf');
			}
		} else {
			camposV[2] = "cpf";
			document.getElementById('cpf').className = "textoEr";
			if (document.getElementById('erro_cpf')){
			 document.getElementById('erro_cpf').innerHTML = "";
			}
			mensagem_erro(' CPF Inválido', 'span', 'cpf');
		}
	}
	if (document.getElementById('dtnasc').value == ""){
			camposV[3] = "dtnasc";
			document.getElementById('dtnasc').className = "textoEr";
			if (document.getElementById('erro_dtnasc')){
			 	document.getElementById('erro_dtnasc').innerHTML = "";
			}
			mensagem_erro(' Data de Nascimento Inválida', 'span', 'dtnasc');
	} else {
		camposV[3] = "S";
		document.getElementById('dtnasc').className = "texto";
		if (document.getElementById('erro_dtnasc')){
			document.getElementById('erro_dtnasc').innerHTML = "";
		}
	}
	if (document.getElementById('grauvinc').value == "#"){
			camposV[4] = "grauvinc";
			document.getElementById('grauvinc').className = "textoEr";
			if (document.getElementById('erro_grauvinc')){
			 	document.getElementById('erro_grauvinc').innerHTML = "";
			}
			mensagem_erro(' Informe o Grau de Parentesco', 'span', 'grauvinc');
	} else {
		camposV[4] = "S";
		document.getElementById('grauvinc').className = "texto";
		if (document.getElementById('erro_grauvinc')){
			document.getElementById('erro_grauvinc').innerHTML = "";
		}
	}
	
	erro_js = "";
	cont_j = 1;
	for (x = 4; x >= 0; x--){
		//alert(camposV+'='+camposV[x]);
		if (camposV[x] != "S") {
			document.getElementById(camposV[x]).focus();
			document.getElementById('cad_dados').innerHTML = "<span class='erro'>Volte e Verifique os campos Marcados, devem possuir erro no preenchimento.</span><br><br><input type=\"submit\" name=\"button\" onClick=\"ValidaVinc();\" id=\"button\" value=\"Validar Cadastro\">";
			erro_js = "ERRO"; 
			//return false;
		} 
	}
	
	if (erro_js != "ERRO") {
		//document.getElementById('validaC').innerHTML = "O Cadastro Pode Continuar, Dados Válidados com Sucesso.<br>";
		document.getElementById('cad_dados').innerHTML = "<input name=\"enviar_btn\" type=\"image\" id=\"enviar_btn\" value=\"Submit\" src=\"../imagens/continuar.png\" />";
		return true;
	} else {
		return false;
	}
	
	
	
	
}

function cepVer(cep_,uf_){

    var cep = cep_;
    var cCEP= cep.substring(0,3);
    var erro = "";
    var uf = uf_;

    tm = cep_.substring(6,3);

    if (tm.length < 3) {
        Result = 0; 
    } else if ((uf == 'SP') && (cCEP >= 10 ) && (cCEP <= 199)){ 
        Result = "SP"; 
    } else if ((uf == 'RJ') && (cCEP >= 200) && (cCEP <= 289)){ 
        Result = "RJ"; 
    } else if ((uf == 'ES') && (cCEP >= 290) && (cCEP <= 299)) { 
        Result = "ES"; 
    } else if ((uf == 'MG') && (cCEP >= 300) && (cCEP <= 399)) { 
        Result = "MG"; 
    } else if ((uf == 'BA') && (cCEP >= 400) && (cCEP <= 489)) { 
        Result = "BA"; 
    } else if ((uf == 'SE') && (cCEP >= 490) && (cCEP <= 499)) { 
        Result = "SE"; 
    } else if ((uf == 'PE') && (cCEP >= 500) && (cCEP <= 569)) { 
        Result = "PE"; 
    } else if ((uf == 'AL') && (cCEP >= 570) && (cCEP <= 579)) { 
        Result = "AL"; 
    } else if ((uf == 'PB') && (cCEP >= 580) && (cCEP <= 589)) { 
        Result = "PB"; 
    } else if ((uf == 'RN') && (cCEP >= 590) && (cCEP <= 599)) { 
        Result = "RN"; 
    } else if ((uf == 'CE') && (cCEP >= 600) && (cCEP <= 639)) { 
        Result = "CE"; 
    } else if ((uf == 'PI') && (cCEP >= 640) && (cCEP <= 649)) { 
        Result = "PI"; 
    } else if ((uf == 'MA') && (cCEP >= 650) && (cCEP <= 659)) { 
        Result = "MA"; 
    } else if ((uf == 'PA') && (cCEP >= 660) && (cCEP <= 688)) { 
        Result = "PA"; 
    } else if ((uf == 'AM') && ((cCEP >= 690) && (cCEP <= 692) && (cCEP >= 694) && (cCEP <= 698))) {
        Result = "AM"; 
    } else if ((uf == 'AP') && (cCEP == 689)) { 
        Result = "AP"; 
    } else if ((uf == 'RR') && (cCEP == 693)) { 
        Result = "RR"; 
    } else if ((uf == 'AC') && (cCEP == 699)) { 
        Result = "AC"; 
    } else if (((uf == 'DF') || (uf == 'GO')) && (cCEP >= 000) && (cCEP <= 999)){
        Result = "DF"; 
    } else if ((uf == 'TO') && (cCEP >= 770) && (cCEP <= 779)) { 
        Result = "TO"; 
    } else if ((uf == 'MT') && (cCEP >= 780) && (cCEP <= 788)) { 
        Result = "MT"; 
    } else if ((uf == 'MS') && (cCEP >= 790) && (cCEP <= 799)) { 
        Result = "MS"; 
    } else if ((uf == 'RO') && (cCEP = 789)) { 
        Result = "RO"; 
    } else if ((uf == 'PR') && (cCEP >= 800) && (cCEP <= 879)) { 
        Result = "PR"; 
    } else if ((uf == 'SC') && (cCEP >= 880) && (cCEP <= 899)) { 
        Result = "SC"; 
    } else if ((uf == 'RS') && (cCEP >= 900) && (cCEP <= 999)) { 
        Result = "RS"; 
    } else { 
        Result = 0;
    }
    
    return Result;
}

function capslock(ev) {
    var e = ev || window.event;
    codigo_tecla = e.keyCode?e.keyCode:e.which;
    tecla_shift  = e.shiftKey?e.shiftKey:((codigo_tecla == 16)?true:false);
    //tecla_shift2 = e.shiftKey?e.shiftKey:((codigo_tecla == 16)?true:false);
    //alert(""+tecla_shift);
      if(((codigo_tecla >= 65 && codigo_tecla <= 90) && !tecla_shift) || ((codigo_tecla >= 97 && codigo_tecla <= 122) && tecla_shift)) {
        alert("Por Favor Desative a Tecla \"Caps Lock\", e Digite tudo me minusculo");
      } else {
          if (tecla_shift){
              alert("Por Favor não Utilize a Tecla SHIFT Digite tudo me minusculo");
          }
      }

}

//Valida alteração de cadastro
function ValidaAltCadastro() {
	
	var camposV = new Array();
	document.getElementById('validaC').innerHTML = "Validando Campos";

	/*CAMPO TELEFONE CELULAR*/
	if (document.getElementById('fonecel').value != "") {
		res = trim('fonecel');
		nu = somente_numero(document.getElementById('fonecel').value);
		if (nu != "ERRO") {
			if (res.length != 10) {
				camposV[1] = "fonecel";
				document.getElementById('fonecel').className = "textoEr";
				if (document.getElementById('erro_fonecel')){
				 document.getElementById('erro_fonecel').innerHTML = "";
				}
				mensagem_erro(' Telefone Inválido ', 'span', 'fonecel');
			} else {
				camposV[1] = "S";
				document.getElementById('fonecel').className = "texto";
				if (document.getElementById('erro_fonecel')){
				 document.getElementById('erro_fonecel').innerHTML = "";
				}			
			}
		} else {
			camposV[1] = "fonecel";
			document.getElementById('fonecel').className = "textoEr";
			if (document.getElementById('erro_fonecel')){
			 document.getElementById('erro_fonecel').innerHTML = "";
			 document.getElementById('erro_fonecel').className = "";
			}
			mensagem_erro(' Caractere(s) inválido(s), somente números ', 'span', 'fonecel');
			
		}
	} else {
		camposV[1] = "S";
		document.getElementById('fonecel').className = "texto";
	}
	
	
	/*CAMPO EMPREGO*/
	if (document.getElementById('emprego').value == "#") {
		camposV[2] = "emprego";
		document.getElementById('emprego').className = "textoEr";
	} else {
		camposV[2] = "S";
		document.getElementById('emprego').className = "texto";
	}

	/* CAMPO RENDA */
	if (document.getElementById('renda').value == "") {
		camposV[3] = "renda";
		document.getElementById('renda').className = "textoEr";
	} else {
	  	camposV[3] = "S";
		document.getElementById('renda').className = "texto";	
	}
	
	/* CAMPO DESCRIÇÃO DA RENDA */
	if (document.getElementById('rendancomp').value > 0) {
		res = trim('rendan');
		if (res.length < 6) {
			camposV[4] = "rendan";
			document.getElementById('rendan').className = "textoEr";
			if (document.getElementById('erro_rendan')){
			 document.getElementById('erro_rendan').innerHTML = "";
			}
			mensagem_erro(' Descrição Renda Inválido, Muito Curta ', 'span', 'rendan');
		} else {
			camposV[4] = "S";
			document.getElementById('rendan').className = "texto";
			if (document.getElementById('erro_rendan')){
			 document.getElementById('erro_rendan').innerHTML = "";
			}
			
		}
	} else {
		camposV[4] = "S";
			document.getElementById('rendan').className = "texto";
			if (document.getElementById('erro_rendan')){
			 document.getElementById('erro_rendan').innerHTML = "";
			}
	}
	
	/* CAMPO ESCOLARIDADE */
	if (document.getElementById('escolaridade').value == "#") {
		camposV[5] = "escolaridade";
		document.getElementById('escolaridade').className = "textoEr";
	} else {
		camposV[5] = "S";
		document.getElementById('escolaridade').className = "texto";
	}
	
	/* CAMPO ESTADO CIVIL */
	if (document.getElementById('estcivil').value == "#") {
		camposV[6] = "estcivil";
		document.getElementById('estcivil').className = "textoEr";
	} else {
		camposV[6] = "S";
		document.getElementById('estcivil').className = "texto";
	}
	
	/* CAMPO ENDEREÇO RESIDENCIAL */
	if (document.getElementById('endres').value == "") {
		camposV[7] = "endres";
		document.getElementById('endres').className = "textoEr";
	} else {
		res = trim('endres');
		if (res.length < 5) {
			camposV[7] = "endres";
			document.getElementById('endres').className = "textoEr";
			if (document.getElementById('erro_endres')){
			 document.getElementById('erro_endres').innerHTML = "";
			}
			mensagem_erro(' Endereço Inválido, Muito Curto ', 'span', 'endres');
		} else {
			camposV[7] = "S";
			document.getElementById('endres').className = "texto";
			if (document.getElementById('erro_endres')){
			 document.getElementById('erro_endres').innerHTML = "";
			}
		}
	}
	
	/* CAMPO COMPLEMENTO */
	if (document.getElementById('endrescompl').value != "") {
		res = trim('endrescompl');
		if (res.length < 5) {
			camposV[8] = "endrescompl";
			document.getElementById('endrescompl').className = "textoEr";
			if (document.getElementById('erro_endrescompl')){
			 document.getElementById('erro_endrescompl').innerHTML = "";
			}
			mensagem_erro(' Complemento Inválido, Muito Curto ', 'span', 'endrescompl');
		} else {
			camposV[8] = "S";
			document.getElementById('endrescompl').className = "texto";
			if (document.getElementById('erro_endrescompl')){
			 document.getElementById('erro_endrescompl').innerHTML = "";
			}
		}
	} else {
		camposV[8] = "S";
		document.getElementById('endrescompl').className = "texto";
		if (document.getElementById('erro_endrescompl')){
			 document.getElementById('erro_endrescompl').innerHTML = "";
		}
	}
		
	/* CAMPO BAIRRO RESIDENCIAL */
	if (document.getElementById('bairres').value == "") {
		camposV[9] = "bairres";
		document.getElementById('bairres').className = "textoEr";
	} else {
		res = trim('bairres');
		if (res.length < 5) {
			camposV[9] = "bairres";
			document.getElementById('bairres').className = "textoEr";
			if (document.getElementById('erro_bairres')){
			 document.getElementById('erro_bairres').innerHTML = "";
			}
			mensagem_erro(' Bairro Inválido, Muito Curto ', 'span', 'bairres');
		} else {
			camposV[9] = "S";
			document.getElementById('bairres').className = "texto";
			if (document.getElementById('erro_bairres')){
			 document.getElementById('erro_bairres').innerHTML = "";
			}
		}
	}
	
	/* CAMPO CIDADE RESIDENCIAL */
	if (document.getElementById('codcidres').value == "#") {
		camposV[10] = "codcidres";
		document.getElementById('codcidres').className = "textoEr";
	} else {
		camposV[10] = "S";
		document.getElementById('codcidres').className = "texto";
	}
	
	/* CAMPO ESTADO */
	if (document.getElementById('ufres').value == "") {
		camposV[11] = "ufres";
		document.getElementById('ufres').className = "textoEr";
	} else {
		res = trim('ufres');
		if (res.length == 2) {
			camposV[11] = "S";
			document.getElementById('ufres').className = "texto";
			if (document.getElementById('erro_ufres')){
			 document.getElementById('erro_ufres').innerHTML = "";
			}
		} else {
			camposV[11] = "ufres";
			document.getElementById('ufres').className = "textoEr";
			if (document.getElementById('erro_ufres')){
			 document.getElementById('erro_ufres').innerHTML = "";
			}
			mensagem_erro(' Estado Inválido ', 'span', 'ufres');
		}
	}
	
	
	/* CEP RESIDENCIAL */
	if (document.getElementById('cepres').value == "") {
		camposV[12] = "cepres";
		document.getElementById('cepres').className = "textoEr";
	} else {
		res = trim('cepres');
		nu = somente_numero(document.getElementById('cepres').value);
		if (nu != "ERRO") {
			if (res.length == 8) {
				camposV[12] = "S";
				document.getElementById('cepres').className = "texto";
				if (document.getElementById('erro_cepres')){
				 document.getElementById('erro_cepres').innerHTML = "";
				}
			} else {
				camposV[12] = "cepres";
				document.getElementById('cepres').className = "textoEr";
				if (document.getElementById('erro_cepres')){
				 document.getElementById('erro_cepres').innerHTML = "";
				}
				mensagem_erro(' CEP Inválido, com '+res.length+' dígitos, Correto 8 dígitos.  ', 'span', 'cepres');
			}
		} else {
			camposV[12] = "cepres";
				document.getElementById('cepres').className = "textoEr";
				if (document.getElementById('erro_cepres')){
				 document.getElementById('erro_cepres').innerHTML = "";
				}
				mensagem_erro(' Caractere(s) inválido(s), somente números  ', 'span', 'cepres');
		}
	}
	
	
	/* CAMPO EMAIL */
	if (document.getElementById('email').value != "") {
		res = trim('email');
		if (res.length > 8) {
			if((res.indexOf("@") == -1) || (res.indexOf(".") == -1)){
				camposV[13] = "email";
				document.getElementById('email').className = "textoEr";
				if (document.getElementById('erro_email')){
			 	 document.getElementById('erro_email').innerHTML = "";
				}
				mensagem_erro(' Email Inválido ', 'span', 'email');
			} else {
				camposV[13] = "S";
				document.getElementById('email').className = "texto";
				if (document.getElementById('erro_email')){
			 		document.getElementById('erro_email').innerHTML = "";
				}
			}
		} else {
			camposV[13] = "email";
			document.getElementById('email').className = "textoEr";
			if (document.getElementById('erro_email')){
			 	document.getElementById('erro_email').innerHTML = "";
			}
			mensagem_erro(' Email Inválido ', 'span', 'email');
		}
	} else {
		camposV[13] = "S";
		document.getElementById('email').className = "texto";
		if (document.getElementById('erro_email')){
			 document.getElementById('erro_email').innerHTML = "";
		}
	}
	
	
	/* CAMPO ENDEREÇO DE CORRESPONDENCIA */
	if (document.cForm.endcorr.value == "#") {
		camposV[14] = "endcorr";
		document.cForm.endcorr.className = "textoEr";
	} else {
                if (document.cForm.endcorr.value == "2"){

                    res2 = trim('email');
                    //alert(res2);
                    if (res2.length > 8) {
                        if(res2.indexOf("@") == -1 || res2.indexOf(".") == -1){
                            camposV[13] = "email";
                            document.cForm.email.className = "textoEr";
                            if (document.getElementById('erro_email')){
                             document.getElementById('erro_email').innerHTML = "";
                            }
                            mensagem_erro(' Email Inválido ', 'span', 'email');
                        } else {
                            camposV[13] = "S";
                            camposV[14] = "S";
                            document.cForm.email.className = "texto";
                            document.cForm.endcorr.className = "texto";

                            if (document.getElementById('erro_email')){
                                document.getElementById('erro_email').innerHTML = "";
                            }
                        }
                    } else {
                            camposV[13] = "email";
                            document.cForm.email.className = "textoEr";
                            mensagem_erro(' Email Inválido ', 'span', 'email');
                    }

                } else {
                    camposV[14] = "S";
                    document.cForm.endcorr.className = "texto";
                }
	}
	
	/* CAMPO TIPO DE MORADIA  */
	if (document.getElementById('tpmoradia').value == "#") {
		camposV[15] = "tpmoradia";
		document.getElementById('tpmoradia').className = "textoEr";
	} else {
		camposV[15] = "S";
		document.getElementById('tpmoradia').className = "texto";
	}
	
	/* CAMPO RESIDE DESDE */
	if (document.getElementById('resided').value == "") {
		camposV[16] = "resided";
		document.getElementById('resided').className = "textoEr";
		if (document.getElementById('erro_resided')){
			 document.getElementById('erro_resided').innerHTML = "";
		}
		mensagem_erro(' Data Inválida ', 'span', 'resided');
		
	} else {
		res = trim('resided');
		if (res.length == 10) {
			camposV[16] = "S";
			document.getElementById('resided').className = "texto";
			if (document.getElementById('erro_resided')){
				 document.getElementById('erro_resided').innerHTML = "";
			}
		} else {
			document.getElementById('resided').className = "textoEr";
			if (document.getElementById('erro_resided')){
				 document.getElementById('erro_resided').innerHTML = "";
			}
			mensagem_erro(' Data Inválida ', 'span', 'resided');
		}
	}
	
	
	/* CAMPO VALOR DO ALUGUEL */
	if (document.getElementById('tpmoradia').value == "2") {
		if (document.getElementById('valuguel').value < "1") {
			camposV[17] = "valuguel";
			document.getElementById('valuguel').className = "textoEr";
			if (document.getElementById('erro_valuguel')){
			 document.getElementById('erro_valuguel').innerHTML = "";
			}
			mensagem_erro(' Preencha o Valor do Aluguel ', 'span', 'valuguel');
		} else {
			camposV[17] = "S";
			document.getElementById('valuguel').className = "texto";
			if (document.getElementById('erro_valuguel')){
			 document.getElementById('erro_valuguel').innerHTML = "";
			}
		}
	} else {
		  camposV[17] = "S";
		  document.getElementById('valuguel').className = "texto";
		  if (document.getElementById('erro_valuguel')){
			 document.getElementById('erro_valuguel').innerHTML = "";
		  }
	}
	
	/* CAMPO EMPRESA */
	if (document.getElementById('empresacad').value != "") {
		res = trim('empresacad');
		if (res.length < 5) {
			camposV[18] = "empresacad";
			document.getElementById('empresacad').className = "textoEr";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
			mensagem_erro(' Nome Inválido da Empresa, Muito Curto ', 'span', 'empresacad');
		} else {
			camposV[18] = "S";
			document.getElementById('empresacad').className = "texto";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
		}
	} else {
		camposV[18] = "S";
		document.getElementById('empresacad').className = "texto";
		if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
		}
	}
	
	
	
	/* VALIDANDO OS CAMPOS DOS DADOS EMPRESARIAIS SE A EMPRESA ESTIVER CADASTRADA TEM QUE PREENCHER TODOS OS OUTROS DADOS */
	if ((document.getElementById('empresacad').value != "")||(document.getElementById('funcaoempr').value != "")||(document.getElementById('fonecom').value != "")||(document.getElementById('endcom').value != "")||(document.getElementById('baircom').value != "")||(document.getElementById('ufcom').value != "")||(document.getElementById('cepcom').value != "")||(document.getElementById('codcidcom').value != "#")) {
		
		
	/* CAMPO EMPRESA */
	if (document.getElementById('empresacad').value != "") {
		res = trim('empresacad');
		if (res.length < 5) {
			camposV[18] = "empresacad";
			document.getElementById('empresacad').className = "textoEr";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
			mensagem_erro(' Nome Inválido da Empresa, Muito Curto ', 'span', 'empresacad');
		} else {
			camposV[18] = "S";
			document.getElementById('empresacad').className = "texto";
			if (document.getElementById('erro_empresacad')){
			 document.getElementById('erro_empresacad').innerHTML = "";
			}
		}
	} else {
		camposV[18] = "empresacad";
		document.getElementById('empresacad').className = "textoEr";
		if (document.getElementById('erro_empresacad')){
		 	document.getElementById('erro_empresacad').innerHTML = "";
		}
		mensagem_erro(' Nome da Empresa precisa ser Preenchido. ', 'span', 'empresacad');
	}
		
		
		/* CAMPO FUNÇÃO EMPRESA */
		if (document.getElementById('funcaoempr').value == "") {
			camposV[19] = "funcaoempr";
			document.getElementById('funcaoempr').className = "textoEr";
		} else {
			res = trim('funcaoempr');
			if (res.length < 5){
				camposV[19] = "funcaoempr";
				document.getElementById('funcaoempr').className = "textoEr";
				if (document.getElementById('erro_funcaoempr')){
			 		document.getElementById('erro_funcaoempr').innerHTML = "";
				}
				mensagem_erro(' Função Inválida, Muito Curto ', 'span', 'funcaoempr');
			} else {
				camposV[19] = "S";
				document.getElementById('funcaoempr').className = "texto";
				if (document.getElementById('erro_funcaoempr')){
			 		document.getElementById('erro_funcaoempr').innerHTML = "";
				}
			}
		}
		
		camposV[20] = "S";
		/*document.cForm.dtadmissao.className = "texto";*/
		
		/* CAMPO FONE EMPR */
		if (document.getElementById('fonecom').value == "") {
			camposV[21] = "fonecom";
			document.getElementById('fonecom').className = "textoEr";
		} else {
			res = trim('fonecom');
			nu = somente_numero(document.getElementById('fonecom').value);
			if (nu != "ERRO") {
				if (res.length == 10) {
					camposV[21] = "S";
					document.getElementById('fonecom').className = "texto";
					if (document.getElementById('erro_fonecom')){
					  document.getElementById('erro_fonecom').innerHTML = "";
					}
				} else {
					camposV[21] = "fonecom";
					document.getElementById('fonecom').className = "textoEr";
					if (document.getElementById('erro_fonecom')){
						document.getElementById('erro_fonecom').innerHTML = "";
					}
					mensagem_erro(' Telefone Incorreto, tamanho '+res.length+' dígitos, Correto 10 dígitos. ', 'span', 'fonecom');
				}
			} else {
					camposV[21] = "fonecom";
					document.getElementById('fonecom').className = "textoEr";
					if (document.getElementById('erro_fonecom')){
						document.getElementById('erro_fonecom').innerHTML = "";
					}
					mensagem_erro(' Caractere(s) inválido(s), somente números ', 'span', 'fonecom');
			}
		}
		
		
		/* CAMPO ENDCOM */ 
		if (document.getElementById('endcom').value == "") {
			camposV[22] = "endcom";
			document.getElementById('endcom').className = "textoEr";
		} else {
			res = trim('endcom');
			if (res.length > 4) {
				camposV[22] = "S";
				document.getElementById('endcom').className = "texto";
				if (document.getElementById('erro_endcom')){
				 document.getElementById('erro_endcom').innerHTML = "";
				}
			} else if ((res.length < 5) || (res.length > 0)) {
				camposV[22] = "endcom";
				document.getElementById('endcom').className = "textoEr";
				if (document.getElementById('erro_endcom')){
			 		document.getElementById('erro_endcom').innerHTML = "";
				}
				mensagem_erro(' Endereço inválido, Muito Curto ', 'span', 'endcom');
			} else {
			   camposV[22] = "endcom";
			   document.getElementById('endcom').className = "textoEr";
			}
		}
		
		
	/* CAMPO BAIRRO COMERCIAL */
	if (document.getElementById('baircom').value == "") {
		camposV[23] = "baircom";
		document.getElementById('baircom').className = "textoEr";
		if (document.getElementById('erro_baircom')){
			 document.getElementById('erro_baircom').innerHTML = "";
		}
	} else {
		res = trim('baircom');
		if (res.length < 5) {
			camposV[23] = "baircom";
			document.getElementById('baircom').className = "textoEr";
			if (document.getElementById('erro_baircom')){
			 document.getElementById('erro_baircom').innerHTML = "";
			}
			mensagem_erro(' Bairro inválido, Muito Curto ', 'span', 'baircom');
		} else {
			camposV[23] = "S";
			document.getElementById('baircom').className = "texto";
			if (document.getElementById('erro_baircom')){
			 document.getElementById('erro_baircom').innerHTML = "";
			}
		}
	}
	
	/* CAMPO CIDADE COMERCIAL */
	//if (document.getElementById('codcidcom').value == "#") {
		//camposV[24] = "codcidcom";
		//document.getElementById('codcidcom').className = "textoEr";
	//} else {
		camposV[24] = "S";
		document.getElementById('codcidcom').className = "texto";
	//}
	
	/* CAMPO ESTADO COMERCIAL */
	if (document.getElementById('ufcom').value == "") {
		camposV[25] = "ufcom";
		document.getElementById('ufcom').className = "textoEr";
	} else {
		res = trim('ufres');
		if (res.length == 2) {
			camposV[25] = "S";
			document.getElementById('ufcom').className = "texto";
			if (document.getElementById('erro_ufcom')){
			 document.getElementById('erro_ufcom').innerHTML = "";
			}
		} else {
			camposV[25] = "ufcom";
			document.getElementById('ufcom').className = "textoEr";
			if (document.getElementById('erro_ufcom')){
			 document.getElementById('erro_ufcom').innerHTML = "";
			}
			mensagem_erro(' Estado inválido, Muito Curto ', 'span', 'ufcom');
		}
	}
	
	/* CEP RESIDENCIAL COMERCIAL */
	if (document.getElementById('cepcom').value == "") {
		camposV[26] = "cepcom";
		document.getElementById('cepcom').className = "textoEr";
	} else {
		res = trim('cepcom');
		nu = somente_numero(document.getElementById('cepcom').value);
		if (nu != "ERRO") {
			if (res.length == 8) {
				camposV[26] = "S";
				document.getElementById('cepcom').className = "texto";
				if (document.getElementById('erro_cepcom')){
				 document.getElementById('erro_cepcom').innerHTML = "";
				}
			} else {
				camposV[26] = "cepcom";
				document.getElementById('cepcom').className = "textoEr";
				if (document.getElementById('erro_cepcom')){
				 document.getElementById('erro_cepcom').innerHTML = "";
				}
				mensagem_erro(' CEP Inválido, com '+res.length+' dígitos, Correto 8 dígitos. ', 'span', 'cepcom');
			}
		} else {
				camposV[26] = "cepcom";
				document.getElementById('cepcom').className = "textoEr";
				if (document.getElementById('erro_cepcom')){
				 document.getElementById('erro_cepcom').innerHTML = "";
				}
				mensagem_erro(' Caractere(s) inválido(s), somente números ', 'span', 'cepcom');
		}
	}

	} else {
		camposV[19] = "S";
		document.getElementById('funcaoempr').className = "texto";
		if (document.getElementById('erro_funcaoempr')){
			 document.getElementById('erro_funcaoempr').innerHTML = "";
		}
		camposV[20] = "S";
		document.getElementById('dtadmissao').className = "texto";
		if (document.getElementById('erro_dtadmissao')){
			 document.getElementById('erro_dtadmissao').innerHTML = "";
		}
		camposV[21] = "S";
		document.getElementById('fonecom').className = "texto";
		if (document.getElementById('erro_fonecom')){
			 document.getElementById('erro_fonecom').innerHTML = "";
		}
		camposV[22] = "S";
		document.getElementById('endcom').className = "texto";
		if (document.getElementById('erro_endcom')){
			 document.getElementById('erro_encom').innerHTML = "";
		}
		camposV[23] = "S";
		document.getElementById('baircom').className = "texto";
		if (document.getElementById('erro_baircom')){
			 document.getElementById('erro_baircom').innerHTML = "";
		}
		camposV[24] = "S";
		document.getElementById('codcidcom').className = "texto";
		if (document.getElementById('erro_codcidcom')){
			 document.getElementById('erro_codcidcom').innerHTML = "";
		}
		camposV[25] = "S";
		document.getElementById('ufcom').className = "texto";
		if (document.getElementById('erro_ufcom')){
			 document.getElementById('erro_ufcom').innerHTML = "";
		}
		camposV[26] = "S";
		document.getElementById('cepcom').className = "texto";
		if (document.getElementById('erro_cepcom')){
			 document.getElementById('erro_cepcom').innerHTML = "";
		}
		
	}/* FIM DA VALIDAÇÃO DOS CAMPOS EMPRESARIAIS */

	if (document.getElementById('uncad').value == "#") {
	   	camposV[27] = "uncad";
	   	document.getElementById('uncad').className = "textoEr";
		if (document.getElementById('erro_uncad')){
			document.getElementById('erro_uncad').innerHTML = "";
		}
		mensagem_erro(' Escolha a Unidade de Cadastro ', 'span', 'uncad');
		
	} else {
		camposV[27] = "S";
	   	document.getElementById('uncad').className = "texto";
		if (document.getElementById('erro_uncad')){
			document.getElementById('erro_uncad').innerHTML = "";
		}
	}
	
	erro_js = "";
	cont_j = 1;
	for (x = 27; x >= 1; x--){
		//alert(camposV+'='+camposV[x]);
		if (camposV[x] != "S"){
			document.getElementById(camposV[x]).focus();
			document.getElementById('validaC').innerHTML = "<span class='erro'>Volte e Verifique os campos Marcados, devem possuir erro no preenchimento.</span>";
			erro_js = "ERRO"; 
			//return false;
		} 
	}
	//alert(erro_js);
	if (erro_js != "ERRO") {
		document.getElementById('validarbtn').innerHTML = "";
		document.getElementById('validaC').innerHTML = "<span class='certo'>O Cadastro Pode Continuar, Dados Válidados com Sucesso.</span><br>"+
		"<input name=\"enviar_btn\" type=\"image\" id=\"enviar_btn\" value=\"Submit\" src=\"../imagens/continuar.png\" />";
		return true;
	} else {
		return false;
	}

}

function onChangeCampos(){
    document.getElementById('validaC').innerHTML = "<span class='erro'>Houve Alteração no Cadatro, revalide os campos.</span>";
    document.getElementById('validarbtn').innerHTML = "<input type=\"button\" name=\"validar_btn\" id=\"validar_btn\" onClick=\"ValidaAltCadastro();\" value=\"Validar Dados da Alteração\" />";
    document.getElementById('botaoCad').innerHTML = "";
}

function onChangeCamposCad(){
    document.getElementById('validaC').innerHTML = "<span class='erro'>Houve Alteração no Cadatro, revalide os campos.</span>";
    document.getElementById('validarbtn').innerHTML = "<input type=\"button\" name=\"validar_btn\" id=\"validar_btn\" onClick=\"ValidaCadastro();\" value=\"Validar Dados do Cadastro\" />";
    document.getElementById('botaoCad').innerHTML = "";
}


function onChangeCamposNego(){
	document.getElementById('botaoCad').innerHTML = "";
    document.getElementById('botaoVal').innerHTML = "<input type=\"button\" name=\"validanego\" id=\"validanego\" onclick=\"validaNegociacao();\" value=\"Validar Campos\" />";
	//document.getElementById('botaoCad').innerHTML = "<input type=\"image\" src=\"../imagens/continuar.png\" name=\"button2\" id=\"button2\" value=\"Enviar Dados\" />";
	// 
}


/* 
	BLOQUEIA O USO DO ENTER NOS FORMS QUE DESEJAR 
 	ADICIONAR NO onKeyPress="return entsub(event);"
*/
function entsub(event) {
	//Internet Explorer
	if(window.event && window.event.keyCode == 13) {
	 return false;
	}
	
	//Netscape e Mozilla
	if (event && event.which == 13) {
		return false;
	 }
}


/* FUNCOES DE NEGOCIACAO */

function AtivaParcelas(valor) {
  if (valor == '1') {
      document.getElementById("parcelas").style.visibility = "visible"; 
  } else {
      document.getElementById("parcelas").style.visibility = "hidden"; 
  } 
}

function Verdata() {
  if (document.parcelanego.venc.value == "#") {
    alert("Precisa Selecionar o dia de Vencimento do Cliente!!!");
	document.parcelanego.venc.focus();
	return false;
  }
}

function Limpa(campoLimpa) {
  document.parcela_nego.campoLimpa.value='';
}

function somaT(vl3,vl4) {
	 var Nsoma = (parseFloat(vl3) + parseFloat(vl4));
	 document.getElementById("somaetotal").innerHTML = "<input size='12' readonly='false' size='12' value='"+ Nsoma.toFixed(2) +"' class='FundoCinza' name='totalsom' type='text' maxlength='12' />";
}

function CalculaValoresDes() {
	
	var tot_ = document.getElementById('totalDebito').value.replace(/,/gi, ".");
	var desc = document.getElementById('descontodado').value.replace(/,/gi, ".");
	var entr = document.getElementById('entrada').value.replace(/,/gi, ".");
	
	//alert(tot_ +' '+ desc+' '+ entr);
	
	
	//var tota = document.getElementById('totalsom').value;
	var nvalor = 0;
	var soma_parc = 0;
	
	nvalor = ((tot_ - desc) - entr);

	//alert(nvalor);

	document.getElementById('totalsom').value = (Math.round(nvalor*100)/100).toFixed(2);
	
	if (document.getElementById('ger_parc').checked) {
		
		var name = 'parcela[]';
		var keywords = document.getElementsByName(name);
		for (var i=0; i<keywords.length; i++){
			keywords[i].value = (Math.round((nvalor/keywords.length)*100)/100).toFixed(2);
			//alert(keywords[i].value);
			soma_parc = parseFloat(soma_parc) + parseFloat(keywords[i].value);
		}
		//alert(soma_parc);
		var  vlI = keywords.length-1;
		if (soma_parc < nvalor){
			//alert (vlI);
			soma_parc = (parseFloat(nvalor) - parseFloat(soma_parc))+keywords[vlI].value;
			//alert(soma_parc);
			keywords[vlI].value = (parseFloat(keywords[vlI].value)+parseFloat((Math.round(parseFloat(soma_parc)*100)/100).toFixed(2)));
		}
		
		document.getElementById('totalPar').value = (Math.round(nvalor*100)/100).toFixed(2);
		
	} else {
		
		//alert('Aqui');
		var name = 'parcela[]';
		var keywords = document.getElementsByName(name);
		for (var i=0; i<keywords.length; i++){
			soma_parc = parseFloat(soma_parc) + parseFloat(keywords[i].value);
		}
		document.getElementById('totalPar').value = (Math.round(soma_parc*100)/100).toFixed(2);
	}

}

/*function CalculaValoresDes() {
	
	var tot_ = document.getElementById('totalDebito').value(); //.replace(/,/gi, ".");
	var desc = document.getElementById('descontodado').value(); //.replace(/,/gi, ".");
	var entr = document.getElementById('entrada').value(); //.replace(/,/gi, ".");
	//var tota = document.getElementById('totalsom').value;
	var nvalor = 0;
	var soma_parc = 0;
	
	nvalor = ((tot_ - desc) - entr);
	
	//alert(+""+);
	
	document.getElementById('totalsom').value = nvalor; //(Math.round(nvalor*100)/100).toFixed(2);
	
	if (document.getElementById('ger_parc').checked) {
		
		var name = 'parcela[]';
		var keywords = document.getElementsByName(name);
		for (var i=0; i<keywords.length; i++){
			keywords[i].value = (Math.round((nvalor/keywords.length)*100)/100).toFixed(2);
			soma_parc = parseFloat(soma_parc) + parseFloat(keywords[i].value);
		}
		//alert((Math.round(soma_parc*100)/100).toFixed(2));
		//alert(soma_parc);
		var  vlI = keywords.length-1;
		if (soma_parc < nvalor){
			//alert (vlI);
			soma_parc = (parseFloat(nvalor) - parseFloat(soma_parc))+keywords[vlI].value;
			//alert(soma_parc);
			keywords[vlI].value = (parseFloat(keywords[vlI].value)+parseFloat((Math.round(parseFloat(soma_parc)*100)/100).toFixed(2)));
		}
		
		document.getElementById('totalPar').value = (Math.round(nvalor*100)/100).toFixed(2);
		
	} else {
		
		//alert('Aqui');
		var name = 'parcela[]';
		var keywords = document.getElementsByName(name);
		for (var i=0; i<keywords.length; i++){
			soma_parc = parseFloat(soma_parc) + parseFloat(keywords[i].value);
		}
		document.getElementById('totalPar').value = (Math.round(soma_parc*100)/100).toFixed(2);
	}

}*/



function validaNegociacao(){
	
  if (document.getElementById('tipo').value == "AP") {
	
	var soma_parcV = 0;
	var tot_V = document.getElementById('totalsom').value;
	var nameV = 'parcela[]';
	var keywordsV = document.getElementsByName(nameV);
	
	for (var i=0; i<keywordsV.length; i++){
		soma_parcV = parseFloat(soma_parcV) + parseFloat(keywordsV[i].value);
	}
	
	soma_parcV = (Math.round(soma_parcV*100)/100).toFixed(2);
	
	var soma_parcVS = soma_parcV.split(".");
	var tot_VS	    = tot_V.split(".");
	//alert(parseInt(soma_parcVS[0])+" - "+parseInt(tot_VS[0]));
	if (soma_parcVS[0].length > tot_VS[0].length){
	
	   document.getElementById('botaoVal').innerHTML = "";
	   document.getElementById('botaoCad').innerHTML = "<input type=\"image\" src=\"../imagens/continuar.png\" name=\"button2\" id=\"button2\" value=\"Enviar Dados\" />";	
	
	} else if (soma_parcVS[0] > tot_VS[0]) {
		
	   document.getElementById('botaoVal').innerHTML = "";
	   document.getElementById('botaoCad').innerHTML = "<input type=\"image\" src=\"../imagens/continuar.png\" name=\"button2\" id=\"button2\" value=\"Enviar Dados\" />";	
	   
	} else if (soma_parcVS[0] == tot_VS[0]) {
		
	   if (soma_parcVS[1] >= tot_VS[1]){
			document.getElementById('botaoVal').innerHTML = "";
			document.getElementById('botaoCad').innerHTML = "<input type=\"image\" src=\"../imagens/continuar.png\" name=\"button2\" id=\"button2\" value=\"Enviar Dados\" />";
		} else {
		  	alert('O Valor total das Parcelas não pode ser Menor que o Total de Débito.');
			keywordsV[0].focus();
			return false;	
		}	
		
    }else {
		alert('O Valor total das Parcelas não pode ser Menor que o Total de Débito.');
		keywordsV[0].focus();
		return false;
	}
	
	
	
   /*if ((soma_parcVS[0] >= tot_VS[0]) && (soma_parcVS[1]>=tot_VS[1]) ) {
	document.getElementById('botaoVal').innerHTML = "";
	document.getElementById('botaoCad').innerHTML = "<input type=\"image\" src=\"../imagens/continuar.png\" name=\"button2\" id=\"button2\" value=\"Enviar Dados\" />";
   } else {
	 //if ((soma_parcVS[0] < tot_VS[0]) && (soma_parcVS[1] < tot_VS[1])){
		alert('O Valor total das Parcelas não pode ser Menor que o Total de Débito.');
		keywordsV[0].focus();
		return false;
	 /*} else 
		document.getElementById('botaoVal').innerHTML = "";
		document.getElementById('botaoCad').innerHTML = "<input type=\"image\" src=\"../imagens/continuar.png\" name=\"button2\" id=\"button2\" value=\"Enviar Dados\" />";
	 }*/
   //}
  } else {
	  
	 	var nval = document.getElementById('totalsom').value;
	  	var val = (Math.round(nval*100)/100).toFixed(2);
		
	  	if (document.getElementById('totalsom').value > 0) {
			alert("Adicionar a Entrada R$ "+ val +", Valor Menor que Total Débito.");
			document.getElementById('entrada').focus;
			return false;
		} else {
			document.getElementById('botaoVal').innerHTML = "";
			document.getElementById('botaoCad').innerHTML = "<input type=\"image\" src=\"../imagens/continuar.png\" name=\"button2\" id=\"button2\" value=\"Enviar Dados\" />";
		}
  }

}


function setaPagamento(vl){
  document.parcelanego.marcado.value = vl;
}

function ValidaForm(){

  if (document.parcelanego.marcado.value == "") {
  	alert("Marque o Tipo de Pagamento.");
  	return false;
  } else {
     if (document.parcelanego.marcado.value == "AP") {
	   if (document.parcelanego.parcelas.value == "") {
	      alert("Informe o Numero de Parcelas");
		  document.parcelanego.parcelas.focus();
		  return false;
	   } else {
	   }
	 }
	 if (document.parcelanego.marcado.value == "AV") {
	   if (document.parcelanego.entrada.value == "") {
	      alert("Informe o Valor da Entrada");
		  document.parcelanego.entrada.focus();
		  return false;
	   } else {
	   }
	 }
  }

}

function ValidaSegPasso(){

if (document.getElementById('uncad').value == "#") {
	      alert("Selecione a Loja do Recebimento");
		  document.getElementById('uncad').focus();
		  return false;
	}
	
	if (document.getElementById('documento').value == "") {
	      alert("Informe o Documento");
		  document.getElementById('documento').focus();
		  return false;
	}
}

/* FIM DAS FUNCOES DA NEGOCIACAO*/


// MUDA FUNDO DOS INPUT
function ValidaCad() {
	
	//data = document.cadfunc.dtnasc;
	var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
    var msgErro = 'Formato inválido de data.';
	
	
	if (document.cadfunc.cpfcgc.value == "") {
		alert("Redigite o CPF");
		document.cadfunc.cpfcgc.focus();
		document.cadfunc.cpfcgc.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.passa.value == "1") {
		alert("Você Não Pode Continuar o Cadastro com este CPF");
		document.cadfunc.cpfcgc.focus();
		document.cadfunc.cpfcgc.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.nome.value == "") {
		alert("Nome não Preenchido");
		document.cadfunc.nome.focus();
		document.cadfunc.nome.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.ncartao.value == "") {
		alert("Nome Cartão não Preenchido");
		document.cadfunc.ncartao.focus();
		document.cadfunc.ncartao.className = 'alertfrm';
		return false;
	}
    //function validarData(campo) {
    if (!(document.cadfunc.dtnasc.value.match(expReg))) {
        alert(msgErro);
        document.cadfunc.dtnasc.focus();
		document.cadfunc.dtnasc.className = 'alertfrm';
		return false;
    }
	if (document.cadfunc.estcivil.value == "#") {
		alert("Selecione o Estado Civil");
		document.cadfunc.estcivil.focus();
		document.cadfunc.estcivil.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.sexo.value == "#") {
		alert("Selecione o Sexo");
		document.cadfunc.sexo.focus();
		document.cadfunc.sexo.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.rginsc.value == "") {
		alert("Preencha o RG");
		document.cadfunc.rginsc.focus();
		document.cadfunc.rginsc.className = 'alertfrm';
		return false;
	}
	/*if (document.cadfunc.tipoend.value == "#") {
		alert("Tipo de Endereço");
		document.cadfunc.tipoend.focus();
		document.cadfunc.tipoend.className = 'alertfrm';
		return false;
	}*/
	if (document.cadfunc.endres.value == "") {
		alert("Endereço Residencial Não Preenchido.");
		document.cadfunc.endres.focus();
		document.cadfunc.endres.className = 'alertfrm';
		return false;
	}	
	if (document.cadfunc.bairres.value == "") {
		alert("Bairro Não Preenchido.");
		document.cadfunc.bairres.focus();
		document.cadfunc.bairres.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.renda.value == "") {
		alert("Renda Não Preenchido.");
		document.cadfunc.renda.focus();
		document.cadfunc.renda.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.limiteconv.value == "") {
		alert("Limite Não Preenchido.");
		document.cadfunc.limiteconv.focus();
		document.cadfunc.limiteconv.className = 'alertfrm';
		return false;
	}
	if (document.cadfunc.uncad.value == "#") {
		alert("Escolha a Unidade de Cadastro.");
		document.cadfunc.uncad.focus();
		document.cadfunc.uncad.className = 'alertfrm';
		return false;
	}
}
// FIM DO MUDA FUNDO DOS INPUT

/* MUDA FONTE DOS TEXTOS*/
function MudaFonte(num,id) {
	document.getElementById(id).className = "textoC"+num;
}

function LimparM(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
	for (var i=0; i < valor.length; i++) {
	aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function FormataM(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	
	if (tecla == 8 ){ tam = tam - 1 ; }
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
	
	if ( tam <= dec ) { campo.value = vr ; }
	
	if ( (tam > dec) && (tam <= 5) ){
		campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 6) && (tam <= 8) ){
		campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, 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 - dec, tam ) ; }
	if ( (tam >= 12) && (tam <= 14) ){
		campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 15) && (tam <= 17) ){
		campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	} 

}

function LimparCA(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
	aux = validos.indexOf(valor.substring(i, i+1));
	if (aux>=0) {
	result += aux;
	}
}
return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function Formata(campo,tammax,teclapres,decimal) {
	
	if(window.event) {
		tecla = teclapres.keyCode;
	} else { 
		tecla = teclapres.which;
	}
	
	//var tecla = teclapres.keyCode;
	//var tecla =  (window.Event) ? event.which : event.keyCode;
	vr = LimparCA(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 ) { tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
	if ( tam <= dec ){ campo.value = vr ; }
	if ((tam > dec) && (tam <= 5) ){campo.value = vr.substr( 0, tam - 2 ) + "." + vr.substr( tam - dec, tam ) ; }
	if ((tam >= 6) && (tam <= 8) ){campo.value = vr.substr( 0, tam - 5 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, 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 - dec, tam ); }
	if ((tam >= 12) && (tam <= 14) ){campo.value = vr.substr( 0, tam - 11 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam );}
	if ((tam >= 15) && (tam <= 17) ){campo.value = vr.substr( 0, tam - 14 ) + "" + vr.substr( tam - 14, 3 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - 2, tam );}
} 

}
