function abrir(pagina,largura,altura,scrollbars) {
//pega a resolução do visitante
w = screen.width;
h = screen.height;
//divide a resolução por 2, obtendo o centro do monitor
meio_w = w/2;
meio_h = h/2;
//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
altura2 = altura/2;
largura2 = largura/2;
meio1 = meio_h-altura2;
meio2 = meio_w-largura2;
//abre a nova janela, já com a sua devida posição
window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+', scrollbars='+scrollbars+''); 
}



function Valida_Cliente(theForm) {

if (theForm.itens[0].checked == false && theForm.itens[1].checked == false) {
	alert("Necessário informar o tipo de pessoa (Física/Jurídica)!")
	return false
} 

if (Trim(theForm.nome.value) == "")
 {
  alert("Por favor, digite o Nome do Cliente")
  theForm.nome.focus();
    return (false);
  }

if (theForm.itens[0].checked) {
	var cpf=theForm.cpf.value;
	if (checaCPF(cpf)==false) {
		alert("Necessário informar o número correto do seu CPF")
		theForm.cpf.focus()
		return false
	}
}
 
if (theForm.itens[1].checked) {
	var cnpj=theForm.cnpj.value;
	if (validaCNPJ(cnpj)==false){
		theForm.cnpj.focus()
		return false
	}
}
  
var email=theForm.email.value;
if (email==''){
	alert("Necessário informar seu E-Mail corretamente!")
	theForm.email.focus()
	return false
}


if (theForm.itens[1].checked) {
var razao_social=theForm.razao_social.value;
if (razao_social==""){
	alert("Necessário informar a Razão Social da Empresa!")
	theForm.razao_social.focus()
	return false
}}

if (theForm.itens[1].checked) {
var fantasia=theForm.nome_fantasia.value;
if (fantasia==""){
	alert("Necessário informar o Nome Fantasia da Empresa!")
	theForm.nome_fantasia.focus()
	return false
}}
}

function Valida_Endereco(theForm){

var cep=theForm.cep.value;
if (cep==""){
	alert("Necessário informar o seu CEP!")
	theForm.cep.focus()
	return false
}
var endereco=theForm.endereco.value;
if (endereco==""){
	alert("Necessário informar o seu endereço!")
	theForm.endereco.focus()
	return false
} 
 var numero=theForm.numero.value;
if (numero==""){
	alert("Necessário informar o número!")
	theForm.numero.focus()
	return false
}

var bairro=theForm.bairro.value;
if (bairro==""){
	alert("Necessário informar o seu bairro!")
	theForm.bairro.focus()
	return false
}
  
var cidade=theForm.cidade.value;
if (cidade==""){
	alert("Necessário informar a Cidade!")
	theForm.cidade.focus()
	return false
}

var estado=theForm.estado.value;
if (estado==""){
	alert("Necessário selecionar o Estado!")
	theForm.estado.focus()
	return false
}
  

/*var numero_telefone=theForm.numero_telefone.value;
if (numero_telefone==""){
	alert("Necessário informar o número do telefone!")
	theForm.numero_telefone.focus()
	return false
}
var numero_celular=theForm.numero_celular.value;
if (numero_celular==""){
	alert("Necessário informar o número do telefone celular!")
	theForm.numero_celular.focus()
	return false
}*/

}


function Valida_Boleto(theForm){

if(theForm.banco[0].selected){
  	alert("Por favor, informe o Banco."); 	
	theForm.banco.focus();
  	return (false);
}


if (Trim(theForm.cedente.value) == "") {
  	alert("Por favor, informe o Nome do Cedente."); 	
	theForm.cedente.focus();
  	return (false);
}


if (validaCNPJ(theForm.cnpj.value) == false) {
theForm.cnpj.focus()
return false
}


if(theForm.banco[1].selected || theForm.banco[2].selected || theForm.banco[3].selected || theForm.banco[4].selected || theForm.banco[6].selected || theForm.banco[7].selected){
if (Trim(theForm.nossonumero.value) == "") {
  	alert("Por favor, informe o Nosso Número fornecido pelo banco."); 	
	theForm.nossonumero.focus();
  	return (false);
  }   
}




if(theForm.banco[5].selected){
if (Trim(theForm.num_doc.value) == "") {
  	alert("Por favor, informe o Número do Documento."); 	
	theForm.num_doc.focus();
  	return (false);
}}

if(theForm.banco[5].selected || theForm.banco[7].selected){
if (Trim(theForm.cod_cedente.value) == "") {
  	alert("Por favor, informe o Código do Cedente."); 	
	theForm.cod_cedente.focus();
  	return (false);
}}





if(theForm.banco[4].selected){
if (Trim(theForm.ini_nossonumero.value) == "") {
  	alert("Por favor, informe Início do Nosso Número."); 	
	theForm.ini_nossonumero.focus();
  	return (false);
}}

if (Trim(theForm.carteira.value) == "") {
  	alert("Por favor, informe a Carteira."); 	
	theForm.carteira.focus();
  	return (false);
}

if(theForm.banco[2].selected){
if (Trim(theForm.var_carteira.value) == "") {
  	alert("Por favor, informe a Variação da Carteira."); 	
	theForm.var_carteira.focus();
  	return (false);
}}


if(theForm.banco[1].selected || theForm.banco[2].selected || theForm.banco[3].selected || theForm.banco[4].selected || theForm.banco[6].selected || theForm.banco[7].selected){
if (Trim(theForm.agencia.value) == "") {
  	alert("Por favor, informe o Número da Agência."); 	
	theForm.agencia.focus();
  	return (false);
}
if (Trim(theForm.dig_agencia.value) == "") {
  	alert("Por favor, informe o Dígito da Agência."); 	
	theForm.dig_agencia.focus();
  	return (false);
}
if (Trim(theForm.conta.value) == "") {
  	alert("Por favor, informe o Número da Conta."); 	
	theForm.conta.focus();
  	return (false);
}
if (Trim(theForm.dig_conta.value) == "") {
  	alert("Por favor, informe o Dígito da Conta."); 	
	theForm.dig_conta.focus();
  	return (false);
}}

if(theForm.banco[2].selected){
if (Trim(theForm.convenio.value) == "") {
  	alert("Por favor, informe o Número do Convênio."); 	
	theForm.convenio.focus();
  	return (false);
}}

if(theForm.banco[2].selected){
if (Trim(theForm.contrato.value) == "") {
  	alert("Por favor, informe o Número do Contrato."); 	
	theForm.contrato.focus();
  	return (false);
}}

if(theForm.banco[4].selected){
if (Trim(theForm.conta_ced.value) == "") {
  	alert("Por favor, informe o Número da Conta do Cedente."); 	
	theForm.conta_ced.focus();
  	return (false);
}
if (Trim(theForm.dig_conta_ced.value) == "") {
  	alert("Por favor, informe o Dígito da Conta do Cedente."); 	
	theForm.dig_conta_ced.focus();
  	return (false);
}}
  
  
  if(theForm.tipo[1].selected){
if (Trim(theForm.cod_itaushopline.value) == "") {
  	alert("Por favor, informe o Código Itaú Shopline."); 	
	theForm.cod_itaushopline.focus();
  	return (false);
  }   
if (Trim(theForm.chave_itaushopline.value) == "") {
  	alert("Por favor, informe a Chave Itaú Shopline."); 	
	theForm.chave_itaushopline.focus();
  	return (false);
  }   
}
  
  
  if (Trim(theForm.minimo_parcela.value) == "") {
  	alert("Por favor, informe o valor mínimo para o cliente poder comprar com este cartão"); 	
	theForm.minimo_parcela.focus();
  	return (false);
  }   
if (Trim(theForm.pedidos_acima_de.value) == "") {
  	alert("Por favor, informe valor mínimo para o cliente poder comprar com este cartão"); 	
	theForm.pedidos_acima_de.focus();
  	return (false);
  }   
}




function Valida_Publicidade(theForm){
  
 if (Trim(theForm.nome.value) == "") {
  	alert("Por favor, informe o Nome da Publicidade"); 	
	theForm.nome.focus();
  	return (false);
  }   
if (Trim(theForm.status.value) == "") {
  	alert("Por favor, informe o Status da Publicidade"); 	
	theForm.status.focus();
  	return (false);
  }   
}



function Valida_Cartao(theForm){

if(theForm.tipo[0].selected){
  	alert("Por favor, informe o Tipo da Forma de Pagamento."); 	
	theForm.tipo.focus();
  	return (false);
}


if(theForm.tipo[2].selected || theForm.tipo[3].selected){
if (Trim(theForm.nome.value) == "") {
  	alert("Por favor, informe a Descrição da Forma de Pagamento."); 	
	theForm.nome.focus();
  	return (false);
  }   
}

/*if(theForm.bandeira[4].selected || theForm.bandeira[5].selected){*/
if (Trim(theForm.estab_visa.value) == "") {
  	alert("Por favor, informe o Número do Estabelecimento."); 	
	theForm.estab_visa.focus();
  	return (false);
  /*}*/   
}


if (theForm.tipo[4].selected == false) {
if (Trim(theForm.juros_mes.value) == "") {
  	alert("Por favor, informe o Juros ao Mês (em %)"); 	
	theForm.juros_mes.focus();
  	return (false);
  }  
if (Trim(theForm.juros_apartir_xvezes.value) == "") {
  	alert("Por favor, informe a parcela mínima a qual sera cobrado juros"); 	
	theForm.juros_apartir_xvezes.focus();
  	return (false);
  } 
}

if (Trim(theForm.parcela_ate.value) == "") {
  	alert("Por favor, informe o Número Máximo de Parcelas para esta forma de pagamento"); 	
	theForm.parcela_ate.focus();
  	return (false);
}  

if (Trim(theForm.pedidos_acima_de.value) == "") {
  	alert("Por favor, informe valor mínimo para o cliente poder comprar com esta forma de pagamento"); 	
	theForm.pedidos_acima_de.focus();
  	return (false);
  }   
}





function Valida_Cupom(theForm){

if (Trim(theForm.titulo.value) == "") {
  	alert("Por favor, informe o Título do Cupom"); 	
	theForm.titulo.focus();
  	return (false);
  }   
if (Trim(theForm.inicio.value) == "") {
  	alert("Por favor, informe o Início da Promoção"); 	
	theForm.inicio.focus();
  	return (false);
  }   
  if (Trim(theForm.fim.value) == "") {
  	alert("Por favor, informe o Término da Promoção"); 	
	theForm.fim.focus();
  	return (false);
  }   
if (Trim(theForm.codigo.value) == "") {
  	alert("Por favor, informe o Código Promocional"); 	
	theForm.codigo.focus();
  	return (false);
  }   
if (Trim(theForm.desconto.value) == "") {
  	alert("Por favor, informe o Desconto Promocional (em %)"); 	
	theForm.desconto.focus();
  	return (false);
  }   
}

function Valida_Taxa(theForm){

if (Trim(theForm.parcela.value) == "") {
  	alert("Por favor, informe o Número da Parcela"); 	
	theForm.parcela.focus();
  	return (false);
  }   
if (Trim(theForm.coeficiente.value) == "") {
  	alert("Por favor, informe o Coeficiente referente a parcela atual"); 	
	theForm.coeficiente.focus();
  	return (false);
  }   
  
}

function Valida_Servico(theForm){

if (Trim(theForm.titulo.value) == "") {
  	alert("Por favor, informe o Título do Serviço"); 	
	theForm.titulo.focus();
  	return (false);
  }   
}

function Valida_Pagina(theForm){

if (Trim(theForm.titulo.value) == "") {
  	alert("Por favor, informe o Título da Página Institucional"); 	
	theForm.titulo.focus();
  	return (false);
  }   
}

function Valida_PayPal(theForm){

if (Trim(theForm.email_paypal.value) == "") {
  	alert("Por favor, informe o Email da Conta PayPal"); 	
	theForm.email_paypal.focus();
  	return (false);
  }   
if (Trim(theForm.dolar_paypal.value) == "") {
  	alert("Por favor, informe o Dólar da Conta PayPal"); 	
	theForm.dolar_paypal.focus();
  	return (false);
  }   
}


function Valida_BRPay(theForm){

if (Trim(theForm.email_brpay.value) == "") {
  	alert("Por favor, informe o Email da Conta BRPay"); 	
	theForm.email_brpay.focus();
  	return (false);
  }   
}

function Valida_Fabricante(theForm){
if (Trim(theForm.nome.value) == "") {
  	alert("Por favor, informe o Nome do Fabricante"); 	
	theForm.nome.focus();
  	return (false);
  }   
}

function Valida_Depto(theForm){
if (Trim(theForm.nome.value) == "") {
  	alert("Por favor, informe o Nome do Departamento"); 	
	theForm.nome.focus();
  	return (false);
  }   
}

function Valida_Categoria(theForm){

if (Trim(theForm.nome.value) == "") {
  	alert("Por favor, informe o Nome da Categoria"); 	
	theForm.nome.focus();
  	return (false);
  }   
}






function Valida_Deposito(theForm){
if (Trim(theForm.num_banco.value) == "")
 {
  alert("Por favor, informe o Número do Banco")
  theForm.num_banco.focus();
    return (false);
  }
if (Trim(theForm.agencia.value) == "")
 {
  alert("Por favor, informe o Número da Agência")
  theForm.agencia.focus();
    return (false);
  }
if (Trim(theForm.conta.value) == "")
 {
  alert("Por favor, informe o Número da Conta")
  theForm.conta.focus();
    return (false);
  }
if (Trim(theForm.dig_conta.value) == "") {
  	alert("Por favor, informe o Dígito da Conta"); 	
	theForm.dig_conta.focus();
  	return (false);
  }   
if (Trim(theForm.titular.value) == "")
 {
  alert("Por favor, informe o Titular da Conta")
  theForm.titular.focus();
    return (false);
  }
if (Trim(theForm.cpf_cnpj.value) == "") {
  	alert("Por favor, informe o CPF/CNPJ do Titular da Conta"); 	
	theForm.cpf_cnpj.focus();
  	return (false);
  }   
}



function Valida_SubCategoria(theForm){
if (Trim(theForm.depto_categ.value) == "")
 {
  alert("Por favor, selecione o Departamento/Categoria")
  theForm.depto_categ.focus();
    return (false);
  }
if (Trim(theForm.nome.value) == "") {
  	alert("Por favor, informe o Nome da Categoria"); 	
	theForm.nome.focus();
  	return (false);
  }   
}

function Valida_Noticia(theForm){
if (Trim(theForm.titulo.value) == "")
 {
  alert("Por favor, informe o Título da Notícia")
  theForm.titulo.focus();
    return (false);
  }
if (Trim(theForm.fonte.value) == "") {
  	alert("Por favor, informe a origem/fonte desta notícia"); 	
	theForm.fonte.focus();
  	return (false);
  }
  if (Trim(theForm.subt.value) == "") {
  	alert("Por favor, informe o Sub-Título desta notícia"); 	
	theForm.subt.focus();
  	return (false);
  }
  //////////////////////////////////////////////////////////////
  if (theForm.foto1.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.foto1.value.substr( theForm.foto1.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.foto1.focus();
       return (false);
     }
   }
//////////////////////////////////////////////////////////////
}

function Valida_PG_basica(theForm){
if (Trim(theForm.tipo.value) == "")
 {
  alert("Por favor, selecione o tipo da página")
  theForm.tipo.focus();
    return (false);
  }
  if (Trim(theForm.titulo.value) == "") {
  	alert("Por favor, digite o titulo da página"); 	
	theForm.titulo.focus();
  	return (false);
  }
  //////////////////////////////////////////////////////////////
  if (theForm.foto1.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.foto1.value.substr( theForm.foto1.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.foto1.focus();
       return (false);
     }
   }
//////////////////////////////////////////////////////////////
}


function Valida_Config(theForm){
if (Trim(theForm.nome_site.value) == "")
 {
  alert("Por favor, informe o Nome do Site")
  theForm.nome_site.focus();
    return (false);
  }
if (Trim(theForm.url_site.value) == "") {
  	alert("Por favor, informe a URL do Site. Ex: http://www.seudominio.com.br"); 	
	theForm.url_site.focus();
  	return (false);
  }
  if (Trim(theForm.contato_site.value) == "") {
  	alert("Por favor, informe a Pessoa de Contato"); 	
	theForm.contato_site.focus();
  	return (false);
  }
    if (Trim(theForm.email_contato_site.value) == "") {
  	alert("Por favor, informe o Email de Contato"); 	
	theForm.email_contato_site.focus();
  	return (false);
  }
    if (Trim(theForm.end_contato_site.value) == "") {
  	alert("Por favor, informe o Endereço de Contato"); 	
	theForm.end_contato_site.focus();
  	return (false);
  }
   if (Trim(theForm.tel_contato_site.value) == "") {
  	alert("Por favor, informe o Telefone de Contato"); 	
	theForm.tel_contato_site.focus();
  	return (false);
  }
  //////////////////////////////////////////////////////////////
  if (theForm.logo_email.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.logo_email.value.substr( theForm.logo_email.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.logo_email.focus();
       return (false);
     }
   }
//////////////////////////////////////////////////////////////
}




function Valida_Email(theForm){
if (Trim(theForm.cod_depto.value) == "")
 {
  alert("Por favor, selecione um Departamento")
  theForm.cod_depto.focus();
    return (false);
  }
if (Trim(theForm.status.value) == "") {
  	alert("Por favor, informe o Status do Email"); 	
	theForm.status.focus();
  	return (false);
  }   
if (Trim(theForm.nome.value) == "") {
  	alert("Por favor, informe o Nome da Categoria"); 	
	theForm.nome.focus();
  	return (false);
  }   
}


function Valida_Login(theForm){
if (Trim(theForm.login.value) == "")
 {
  alert("Por favor, informe o Nome de Usuário")
  theForm.login.focus();
    return (false);
  }
if (Trim(theForm.sen.value) == "") {
  	alert("Por favor, informe a Senha de Acesso"); 	
	theForm.sen.focus();
  	return (false);
  }   
}

function Valida_Usuario(theForm){
if (Trim(theForm.nome.value) == "")
 {
  alert("Por favor, informe o Nome do Usuário")
  theForm.nome.focus();
    return (false);
 }
if (Trim(theForm.email.value) == "") {
  	alert("Por favor, informe o Email do Usuário"); 	
	theForm.email.focus();
  	return (false);
  }   
if (Trim(theForm.cargo.value) == "") {
  	alert("Por favor, informe o Cargo do Usuário"); 	
	theForm.cargo.focus();
  	return (false);
  }   
if (Trim(theForm.login.value) == "") {
  	alert("Por favor, informe o Login de Acesso"); 	
	theForm.login.focus();
  	return (false);
  }   
if (Trim(theForm.senha.value) == "") {
  	alert("Por favor, informe a Senha de Acesso"); 	
	theForm.senha.focus();
  	return (false);
  }   
if (Trim(theForm.data_exp.value) == "") {
  	alert("Por favor, informe a Data de Expiração deste Usuário"); 	
	theForm.data_exp.focus();
  	return (false);
  }   
}



function Valida(theForm)
{

if (Trim(theForm.nome.value) == "")
 {
  alert("Por favor, digite o nome do produto")
  theForm.nome.focus();
    return (false);
  }

if (Trim(theForm.categoria.value) == "") {
  	alert("Por favor, Selecione uma categoria"); 	
	theForm.categoria.focus();
  	return (false);
  }   

if (Trim(theForm.preco.value) == "") {
  	alert("Por favor, digite o preço do produto"); 	
	theForm.preco.focus();
  	return (false);
  }  

if (Trim(theForm.peso.value) == "")
 {
  alert("Por favor,  digite o peso do produto")
  theForm.peso.focus();
    return (false);
  } 
   

//////////////////////////////////////////////////////////////
  if (theForm.foto1.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.foto1.value.substr( theForm.foto1.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.foto1.focus();
       return (false);
     }
   }
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
  if (theForm.foto2.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.foto2.value.substr( theForm.foto2.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.foto2.focus();
       return (false);
     }
   }
//////////////////////////////////////////////////////////////     
//////////////////////////////////////////////////////////////
  if (theForm.foto3.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.foto3.value.substr( theForm.foto3.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.foto3.focus();
       return (false);
     }
   }
//////////////////////////////////////////////////////////////     

//////////////////////////////////////////////////////////////
  if (theForm.foto4.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.foto4.value.substr( theForm.foto4.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.foto4.focus();
       return (false);
     }
   }
////////////////////////////////////////////////////////////// 

//////////////////////////////////////////////////////////////
  if (theForm.foto5.value != ""){
   var extensoesOk = ",.jpg,jpeg,";
   var extensao    = "," + theForm.foto5.value.substr( theForm.foto5.value.length - 4 ).toLowerCase() + ",";
   if( extensoesOk.indexOf( extensao ) == -1 ){
       alert( "Só é permitido uso de imagens JPEG ou JPG" );
	   theForm.foto5.focus();
       return (false);
     }
   }
//////////////////////////////////////////////////////////////     
  
  return (true);
}

function Trim(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function VerImagemParc() { 
if (document.cadastro.foto.value == "") {
	document.imagem1.src="imagens/semfoto/semfoto.jpg"
} else {
	document.imagem1.src=document.cadastro.foto.value
}}

function VerImagemCfg() { 
if (document.cadastro.logo_email.value == "") {
	document.imagem1.src="imagens/semfoto/semfoto.jpg"
} else {
	document.imagem1.src=document.cadastro.logo_email.value
}}

function VerImagem1() { 
if (document.cadastro.foto1.value == "") {
	document.imagem1.src="imagens/semfoto/semfoto.jpg"
} else {
	document.imagem1.src=document.cadastro.foto1.value
}}

function VerImagem2() { 
if (document.cadastro.foto2.value == "") {
	document.imagem2.src="imagens/semfoto/semfoto.jpg"
} else {
	document.imagem2.src=document.cadastro.foto2.value
}}


function VerImagem3() { 
if (document.cadastro.foto3.value == "") {
	document.imagem3.src="imagens/semfoto/semfoto.jpg"
} else {
	document.imagem3.src=document.cadastro.foto3.value
}}


function VerImagem4() { 
if (document.cadastro.foto4.value == "") {
	document.imagem4.src="imagens/semfoto/semfoto.jpg"
} else {
	document.imagem4.src=document.cadastro.foto4.value
}}


function VerImagem5() { 
if (document.cadastro.foto5.value == "") {
	document.imagem5.src="imagens/semfoto/semfoto.jpg"
} else {
	document.imagem5.src=document.cadastro.foto5.value
}}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function sohnumero(event,local)
{
Tecla = event.which;
if(Tecla == null)
Tecla = event.keyCode;
if((Tecla<48 || Tecla>57) && local=='num') 
return false;
    if((Tecla==34 || Tecla==39) && local=="texto") 
        return false;
return true;
}

// função que intercala entre dois um mais objetos ocultos à serem exibidos //
function make(obj){
if(document.cadastro.itens[0].checked){
//pessoa juridica
cam2.style.display="none";
cam3.style.display="none";
cam4.style.display="none";
cam5.style.display="none";
cam6.style.display="none";
//pessoa fisica
cam1.style.display="block";
cam7.style.display="block";

document.cadastro.nome.focus()
}
else{
if(document.cadastro.itens[1].checked){
//pessoa juridica
cam2.style.display="block";
cam3.style.display="block";
cam4.style.display="block";
cam5.style.display="block";
cam6.style.display="block";
//pessoa fisica
cam1.style.display="none";
cam7.style.display="none";

document.cadastro.nome.focus()
}
}
}


function mudabanco(obj){
	if(document.cadastro.banco[1].selected){ //banestes
		shopline.style.display="none";
		nosso_numero.style.display="block";

		agencias.style.display="block";
		contas.style.display="block";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="block";
		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="none";
		
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";

		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";

} else if(document.cadastro.banco[2].selected){ //bb
		shopline.style.display="none";
		nosso_numero.style.display="block";

		agencias.style.display="block";
		contas.style.display="block";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="none";
		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="none";
		
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";

		convenios.style.display="block";
		contratos.style.display="block";		
		vcart_bb.style.display="block";
		fmt_conv_bb.style.display="block";
		fmt_nn_bb.style.display="block";

} else if(document.cadastro.banco[3].selected){ //bradesco
		shopline.style.display="none";
		nosso_numero.style.display="block";

		agencias.style.display="block";
		contas.style.display="block";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="none";
		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="none";
		
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";

		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";
		
} else if(document.cadastro.banco[4].selected){ //cef
		shopline.style.display="none";
		nosso_numero.style.display="block";

		agencias.style.display="block";
		contas.style.display="block";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="none";
		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="none";
		
		nn_cef.style.display="block";		
		cta_ced_cef.style.display="block";

		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";
		
} else if(document.cadastro.banco[5].selected){ //hsbc
		shopline.style.display="none";
		nosso_numero.style.display="none";

		agencias.style.display="none";
		contas.style.display="none";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="none";
		
		ndoc_hsbc.style.display="block";
		cod_hsbc_uni.style.display="block";
		
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";

		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";

} else if(document.cadastro.banco[6].selected){ //itau
		shopline.style.display="block";
		nosso_numero.style.display="block";

		agencias.style.display="block";
		contas.style.display="block";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="none";
		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="none";
		
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";

		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";

} else if(document.cadastro.banco[7].selected){ //unibanco
		shopline.style.display="none";
		nosso_numero.style.display="block";

		agencias.style.display="block";
		contas.style.display="block";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="none";
		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="block";
		
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";

		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";
}else{
		shopline.style.display="none";
		nosso_numero.style.display="none";
		agencias.style.display="none";
		contas.style.display="none";		
		carteiras.style.display="none";		
		tipo_cob_bnsts.style.display="none";		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="none";	
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";
		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";
}
}


function mudashopline(obj){

if(document.cadastro.tipo[1].selected){
	cod_shopline.style.display="block";
	chave_shopline.style.display="block";
		nosso_numero.style.display="none";
		agencias.style.display="none";
		contas.style.display="none";		
		carteiras.style.display="none";		
		tipo_cob_bnsts.style.display="none";		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="none";	
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";
		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";
}else{
	cod_shopline.style.display="none";
	chave_shopline.style.display="none";

		nosso_numero.style.display="block";

		agencias.style.display="block";
		contas.style.display="block";
		
		carteiras.style.display="block";
		
		tipo_cob_bnsts.style.display="none";
		
		ndoc_hsbc.style.display="none";
		cod_hsbc_uni.style.display="block";
		
		nn_cef.style.display="none";		
		cta_ced_cef.style.display="none";

		convenios.style.display="none";
		contratos.style.display="none";		
		vcart_bb.style.display="none";
		fmt_conv_bb.style.display="none";
		fmt_nn_bb.style.display="none";
}
}



function muda(obj){

if(document.cadastro.tipo[1].selected){
	nomes.style.display="none";
	cartao.style.display="block";
	juros.style.display="block";
	jurosapartirde.style.display="block";
}else if(document.cadastro.tipo[4].selected){
	nomes.style.display="block";
	cartao.style.display="none";
	juros.style.display="none";
	jurosapartirde.style.display="none";
}else{
	nomes.style.display="block";
	cartao.style.display="none";
	juros.style.display="block";
	jurosapartirde.style.display="block";
}
}



function trava(obj){
if(document.form_anuncio.debito[1].checked){
document.form_anuncio.documentacao.disabled = "disabled";
document.form_anuncio.parcela.disabled = "disabled";
document.form_anuncio.financiamento.disabled = "disabled";
document.form_anuncio.financiadora.disabled = "disabled";

} else if(document.form_anuncio.debito[0].checked){
	
document.form_anuncio.documentacao.disabled = document.form_anuncio.debito[1].unchecked;
document.form_anuncio.parcela.disabled = document.form_anuncio.debito[1].unchecked;
document.form_anuncio.financiamento.disabled = document.form_anuncio.debito[1].unchecked;
document.form_anuncio.financiadora.disabled = document.form_anuncio.debito[1].unchecked;

}}


// formata o numero do cpf em 111.111.111-00 no campo cpf //
// USO: onKeyPress="FormataCPF(this,event); no campo desejado //
function FormataCPF(Campo, teclapres){ 
var tecla = teclapres.keyCode; 
var vr = new String(Campo.value); 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace("-", ""); 
tam = vr.length + 1; 
if(tecla != 9 && tecla !=8){ 
if(tam > 3 && tam < 7) 
Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam); 
if(tam >= 7 && tam <10) 
Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6); 
if(tam >= 10 && tam < 12) 
Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9); 
} 
} 

// formata o numero do cnpj em 00.000.000/0000-00 no campo cnpj //
// USO: onKeyPress="FormataCNPJ(this,event); no campo desejado //
function FormataCNPJ(Campo, teclapres){ 
var tecla = teclapres.keyCode; 
var vr = new String(Campo.value); 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace("/", ""); 
vr = vr.replace("-", ""); 
tam = vr.length + 1 ; 
if(tecla != 9 && tecla !=8){ 
if(tam > 2 && tam < 6)
Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam); 
if(tam >= 6 && tam < 9) 
Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5); 
if(tam >= 9 && tam < 13) 
Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8); 
if(tam >= 13 && tam < 15)
Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12); 
}
}

// verifica se o numero do CPF é valido //
// USO: no submit return checaCPF(campo) //
function checaCPF(CPF)
{
dig_1 = 0;
dig_2 = 0;
controle_1 = 10;
controle_2 = 11;
lsucesso = 1;

if ((CPF.length != 14) || (CPF.substring(11, 12) != "-"))
return false
else
{
CPF = CPF.substring(0,3) + CPF.substring(4,7) + CPF.substring(8,14);
for (i=0 ; i < 9 ; i++)
{
dig_1 = dig_1 + parseInt(CPF.substring(i, i+1) * controle_1);
controle_1 = controle_1 - 1;
}
resto = dig_1 % 11;
dig_1 = 11 - resto;
if ((resto == 0) || (resto == 1)) dig_1 = 0;
for ( i=0 ; i < 9 ; i++)
{
dig_2 = dig_2 + parseInt(CPF.substring(i, i + 1) * controle_2);
controle_2 = controle_2 - 1;
}
dig_2 = dig_2 + 2 * dig_1;
resto = dig_2 % 11;
dig_2 = 11 - resto;
if ((resto == 0) || (resto == 1)) dig_2 = 0;
dig_ver = (dig_1 * 10) + dig_2;
if (dig_ver != parseFloat(CPF.substring(CPF.length-2,CPF.length))) return false;
}
return true;
} 

// verifica se o numero do CNPJ é valido //
function validaCNPJ() {
CNPJ = document.cadastro.cnpj.value;
erro = new String;
if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ!"; 
if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ!";
}
//substituir os caracteres que não são números
if(document.layers && parseInt(navigator.appVersion) == 4){
	x = CNPJ.substring(0,2);
	x += CNPJ. substring (3,6);
	x += CNPJ. substring (7,10);
	x += CNPJ. substring (11,15);
	x += CNPJ. substring (16,18);
	CNPJ = x; 
} else {
	CNPJ = CNPJ. replace (".","");
	CNPJ = CNPJ. replace (".","");
	CNPJ = CNPJ. replace ("-","");
	CNPJ = CNPJ. replace ("/","");
}
var nonNumbers = /\D/;
if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n"; 
var a = [];
var b = new Number;
var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
for (i=0; i<12; i++){
	a[i] = CNPJ.charAt(i);
	b += a[i] * c[i+1];
}
if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	b = 0;
for (y=0; y<13; y++) {
	b += (a[y] * c[y]); 
}
if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
	erro +="É necessário preencher corretamente o número do CNPJ!";
}
if (erro.length > 0){
alert(erro);
return false;
} //else {
//alert("CNPJ valido!");
//}
return true;
}

// USO se for CEP: onKeyPress="return txtBoxFormat(document.formulario, 'campo_cep', '9999-999', event);"//
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
  var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
  if(document.all) { // Internet Explorer
	nTecla = evtKeyPress.keyCode; }
  else if(document.layers) { // Nestcape
	nTecla = evtKeyPress.which;
  }
  sValue = objForm[strField].value;
  // Limpa todos os caracteres de formatação que
  // já estiverem no campo.
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( " ", "" );
  sValue = sValue.toString().replace( " ", "" );
  fldLen = sValue.length;
  mskLen = sMask.length;
  i = 0;
  nCount = 0;
  sCod = "";
  mskLen = fldLen;
  while (i <= mskLen) {
	bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
	bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
	if (bolMask) {
	  sCod += sMask.charAt(i);
	  mskLen++; }
	else {
	  sCod += sValue.charAt(nCount);
	  nCount++;
	}
	i++;
  }
  objForm[strField].value = sCod;
  if (nTecla != 8) { // backspace
	if (sMask.charAt(i-1) == "9") { // apenas números...
	  return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
	else { // qualquer caracter...
	  return true;
	} }
  else {
	return true;
  }
}


//  ##################### FUNÇÕES DE FORMATAR VALOR EM REAIS ##################//
//  USO: onBlur="javascript:formataValorDigitado(this);" onKeyUp="javascript:formataValorDigitado(this);" //
// create the prototype on the String object
String.prototype.trim = function() {
 // skip leading and trailing whitespace
 // and return everything in between
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}
// create the prototype on the String object
String.prototype.trimLeadingZeros = function(todos) { //true, false
    if (""+todos=="undefined") todos=false;
    //tirando os zeros do começo
    var i=0;
    while ((i < this.length- (todos?0:1) ) && (this.substring(i,i+1)=='0')) i++;
    valor = this.substring(i);
	return valor;
}

function stripCharsNotInBag(bag, campo) { //campo só deve ser passado se for para alterar seu valor
	//bag = "0123456789";
	var temp="";
	if (campo==null) temp=this;
	if (campo!=null) temp=campo.value;
	var result = "";
	for (i=0; i<temp.length; i++){
		character = temp.charAt(i);
		if (bag.indexOf(character) != -1)
			result += character;
	}
	if (campo!=null && campo.value!=result) {
		campo.value=result;
	}
	return result;
}

// create the prototype on the String object
String.prototype.stripCharsNotInBag = stripCharsNotInBag;

function stripNotNumber(num) {
	return num.stripCharsNotInBag("0123456789");
}

function FormataNumero(num,decimalNum,bolLeadingZero,bolParens,bolCommas){
if (isNaN(parseInt(num))) return "NaN";
	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);
	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
	tmpNumStr = tmpNumStr.replace(/\./g,",");
	// Complete all decimal places
	if (decimalNum>0) {
		var iStart = tmpNumStr.indexOf(",");
		if (iStart < 0) {
			tmpNumStr+=",";
			iStart = tmpNumStr.indexOf(",");
		}
		for (i=(decimalNum-(tmpNumStr.length-iStart)); i>=0 ; i--) {
			tmpNumStr+="0";
		}
	}
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(",");
		if (iStart < 0)
			iStart = tmpNumStr.length;
		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "." + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}
	}
	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";
	return tmpNumStr;		// Return our formatted string!
}

// USO: onBlur="javascript:formataValorDigitado(this);" onKeyUp="javascript:formataValorDigitado(this);" //
function formataValorDigitado(campo, decimal) {
	var decimalNum=2;
	if (decimal!=null)
		decimalNum=decimal;
	var temp = FormataNumero(campo.value.stripCharsNotInBag("0123456789").trimLeadingZeros() / Math.pow(10,decimalNum), decimalNum, true, false, true);
    if (campo.value!=temp) {
        campo.value=temp;
    }
}	



/*var BASE_DATE = new Date("1997","09","07")  // 1999-out-07
var MAX_DATE = new Date("2025","01","21")   // 2025-jan-21

function ValidaData (data) {
	dt = data.value;

	if (dt.length<10) {
		alert("Tamanho inválido, digitar no formato dd/mm/aaaa.");
		data.select();
		return false;
	}

	dia = dt.substring(0,2);
	mes = dt.substring(3,5);
	ano = dt.substring(6,10);

	// month argument must be in the range 1 - 12
	// javascript month range : 0- 11
	var tempDate = new Date(ano,mes-1,dia);
		
	if ( (ano == tempDate.getFullYear()) &&
	     (mes == (tempDate.getMonth()+1)) &&
	     (dia == tempDate.getDate()) ) {
		var tmp = new Date();
		var todayDate = new Date(tmp.getFullYear(), tmp.getMonth(), tmp.getDate());

	     	//return (tempDate >= BASE_DATE && tempDate<=MAX_DATE && tempDate>=todayDate)
	     	return (tempDate >= BASE_DATE && tempDate<=MAX_DATE)
	} else {
		alert("Data inválida, digitar no formato dd/mm/aaaa.");
		data.select();
		return false;
	}
}*/

// USO: onBlur="javascript:formataDataDigitada(this);" onKeyUp="javascript:formataDataDigitada(this);" //
function formataDataDigitada(campo) {
    // retira tudo que nao eh numerico
    var temp=campo.value;
    var valor="";

    valor=stripNotNumber(temp);

    if (valor.length>8) { valor=valor.substring(0,8); }

    var j=0;
    temp="";
    for (var tam=0;tam<valor.length;tam++) {
        if (j==0) {
            temp+=valor.substring(tam,tam+1);
            if ( (tam==1) && (valor.length>2) ) { j++; temp+="/"; }
        } else if (j==1) {
            temp+=valor.substring(tam,tam+1);
            if ( (tam==3) && (valor.length>4) ) { j++; temp+="/"; }
        } else if (j==2) {
            temp+=valor.substring(tam,tam+1);
        }
    }

    if (campo.value!=temp) {
        campo.value=temp;
    }
}
