// JavaScript Document

// --- lista toda a parte de editoria do Portal ---
function PopUpEditoria(codedit)
{
  window.open("/editoria/editoria.php?codigo="+codedit,'Brinde','width=500,height=400 status=no,scrollbars=yes,resizable=0,toolbar=no,menubar=no');
}

// --- lista a parte de taxas e cotacoes
function PopUpTaxa()
{
  window.open("/cotacoes/taxa.php",'','width=270,height=130 status=no,scrollbars=no,resizable=0,toolbar=no,menubar=no');
}

// --- chama a tela de ajuda esqueci minha senha ---
function PopUpAjuda()
{
  window.open("/ajuda/ajuda.php",'Ajuda','width=350,height=150 status=no,scrollbars=no,resizable=0,toolbar=no,menubar=no');
}

// --- chama a tela de ajuda esqueci minha senha ---
function PopUpTreinamento()
{
  window.open("treinamento.html",'Ajuda','width=250,height=200 status=no,scrollbars=no,resizable=0,toolbar=no,menubar=no');
}

// --- chama a tela de assinatura da revista Bremen Magazine ---
function PopUpAssinatura()
{
  window.open("/assinatura.php",'Revista','width=493,height=350 status=no,scrollbars=yes,resizable=0,toolbar=no,menubar=no');
}

// --- chama a tela de assinatura do portal ---
function PopUpAssinaturaPortal()
{
  //posiciona a popup no centro da tela
  var posw = (screen.width - 350) / 2;
  var posl = (screen.height - 250) / 2;
  window.open("/assinaturas/assinatura_portal.html",'Assinatura','width=350,height=250,top='+posw+',left='+posl+' status=no,scrollbars=no,resizable=0,toolbar=no,menubar=no');
}

// redireciona para as opcoes do portal
function MM_jumpMenu(targ,selObj,restore)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

// --- valida os campos que sao numericos ---
function FormatarNumero(field)
{
  numero=String(field.value);
  if (numero==0){ field.value=numero; }
  else { field.value=numero; }
}

function String(S)
{
 // Deixa so' os digitos no numero
 var Digitos = "0123456789.";
 var temp = "";
 var digito = "";
 var cont=0;
 for (var i=0; i<S.length; i++)
 {
  digito = S.charAt(i);
  if (Digitos.indexOf(digito)>=0)
  {
    if (Digitos.indexOf(digito)==10){ cont++; }
	if (cont<=1){ temp=temp+digito; }
	else{ temp=temp+""; }
  }
 }
  return temp  
}

// --- valida o estado pesquiso da rede licenciada ---
function RedeLicEstado()
{
  var estado = document.FormEstado.estado.value;
  if (estado=="0")
  {
     alert("\n Favor selecionar um estado para que o sistema localize o posto ! \n");
     document.FormEstado.estado.focus();
	return false; 
  }  
}

// valida a cidade pesquisada da rede licenciada
function RedeLicCidade()
{
  var cidade = document.FormCidade.cidade.value;  
  if (cidade=="0")
  {
     alert("\n Favor selecionar uma cidade para que o sistema localize o posto ! \n");
     document.FormCidade.cidade.focus();
	return false; 
  }  
}

// valida o nome do posto pesquisado da rede licenciada
function RedeLicPosto()
{
  var posto = document.FormPosto.posto.value;   
  if (posto=="")
  {
     alert("\n Favor preencher o campo nome do posto para que o sistema localize o posto ! \n");
     document.FormPosto.posto.focus();
	return false; 
  }  
}

// valida o email do fale conosco do Portal
function FaleConosco()
{
  var nomeuser = document.FormFaleConosco.nomeuser.value;  
  var mensagem = document.FormFaleConosco.msguser.value; 
  if (nomeuser=="")
  {
     alert("\n Favor preencher o campo nome ! \n");
     document.FormFaleConosco.nomeuser.focus();
	return false; 
  }  
  
  if (mensagem=="")
  {
     alert("\n Favor preencher o campo mensagem ! \n");
     document.FormFaleConosco.msguser.focus();
	return false; 
  }  
}

//troca imagem do carrinho
function MudaCarrinho(comp)
{
  comp.innerHTML = '<img src="../images/carcompra.gif"  width="28" height="14" border="0" alt="Compra efetuada">';		
}

//redirecionamento do fundo de comercio
function load1(form) 
{
     var url = form.codcidade.options[form.codcidade.selectedIndex].value;
     if (url != '0') location.href = url;
     return false;
}

// valida o cadastro do Portal
function ValCadPortal()
{
function rString(S)
{
  // Deixa so' os digitos no numero
  var Digitos = "0123456789";
  var temp = "";
  var digito = "";
 
  for (var i=0; i<S.length; i++)
  {
     digito = S.charAt(i);
     if (Digitos.indexOf(digito)>=0){temp=temp+digito}
  }
 return temp
}

function ValidaCnpj()
{
  var i;
  s = rString(s);
  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) return false;
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (dv.charAt(0) != d1) { return false; }
  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){ return false; }
 return true;
}
  
  var razao = document.FormCadastro.razaosocial.value;  
  var logradouro = document.FormCadastro.logradouro.value; 
  var bairro = document.FormCadastro.bairro.value;  
  var cidade = document.FormCadastro.cidade.value; 
  var estado = document.FormCadastro.estado.value;  
  var telefone = document.FormCadastro.telefone.value;
  var observacao = document.FormCadastro.observacao.value;  
  var tipo = document.FormCadastro.tipo.value;  
  
// --- valida o cnpj do cliente ---
  var cnpj = document.FormCadastro.cnpj.value;
  if (cnpj=="")
  {
     alert("\n Favor preencher o campo cnpj ! \n");
     document.FormCadastro.cnpj.focus();
	return false; 
  }
  else
  { 
    s = rString(cnpj);
    if (ValidaCnpj(cnpj) == false)
    {
      alert("O formato do cnpj para este cliente é inválido !");
      document.FormCadastro.cnpj.focus();
     return false;
    }
  }  
   
  if (razao=="")
  {
     alert("\n Favor preencher o campo nome ou razão social ! \n");
     document.FormCadastro.razaosocial.focus();
	return false; 
  } 
  
  if (logradouro=="")
  {
     alert("\n Favor preencher o campo logradouro ! \n");
     document.FormCadastro.logradouro.focus();
	return false; 
  } 
  
  if (bairro=="")
  {
     alert("\n Favor preencher o campo bairro ! \n");
     document.FormCadastro.bairro.focus();
	return false; 
  }     
  
  if (cidade=="")
  {
     alert("\n Favor preencher o campo cidade ! \n");
     document.FormCadastro.cidade.focus();
	return false; 
  }       
  
  if (estado=="0")
  {
     alert("\n Favor preencher o campo estado ! \n");
     document.FormCadastro.estado.focus();
	return false; 
  } 
  
  if (telefone=="")
  {
     alert("\n Favor preencher o campo telefone ! \n");
     document.FormCadastro.telefone.focus();
	return false; 
  } 
  
  if (observacao=="")
  {
     alert("\n Favor preencher o campo observação ! \n");
     document.FormCadastro.observacao.focus();
	return false; 
  }  
  
  if (tipo=="0")
  {
     alert("\n Favor preencher o campo tipo de cliente ! \n");
     document.FormCadastro.tipo.focus();
	return false; 
  }   
}

// --- valida o cadastro de cliente ---
function ValCadRevPortal()
{

function rString(S)
{
  // Deixa so' os digitos no numero
  var Digitos = "0123456789";
  var temp = "";
  var digito = "";
 
  for (var i=0; i<S.length; i++)
  {
     digito = S.charAt(i);
     if (Digitos.indexOf(digito)>=0){temp=temp+digito}
  }
 return temp
}

function ValidaCnpj()
{
  var i;
  s = rString(s);
  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) return false;
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (dv.charAt(0) != d1) { return false; }
  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){ return false; }
 return true;
}

// --- valida o cnpj do cliente ---
  var cnpj = document.FormCliente.cnpj.value;
  if (cnpj=="")
  {
     alert("\n Favor preencher o campo cnpj ! \n");
     document.FormCliente.cnpj.focus();
	return false; 
  }
  else
  { 
    s = rString(cnpj);
    if (ValidaCnpj(cnpj) == false)
    {
      alert("O formato do cnpj para este cliente é inválido !");
      document.FormCliente.cnpj.focus();
     return false;
    }
  }
  
  // --- valida a razão social do cliente ---
  var razao = document.FormCliente.razaosocial.value;
  if (razao=="")
  {
     alert("\n Favor preencher o campo razão social ! \n");
     document.FormCliente.razaosocial.focus();
	return false; 
  }
  
  // --- valida a isncricao estadual do cliente ---
  var ie = document.FormCliente.ie.value;
  if (ie=="")
  {
     alert("\n Favor preencher o campo inscrição estadual ! \n");
     document.FormCliente.ie.focus();
	return false; 
  } 
 
  // --- valida o logradouro do cliente ---
  var logradouro = document.FormCliente.logradouro.value;
  if (logradouro=="")
  {
     alert("\n Favor preencher o campo logradouro ! \n");
     document.FormCliente.logradouro.focus();
	return false; 
  }   
  
  // --- valida o bairro do cliente ---
  var bairro = document.FormCliente.bairro.value;
  if (bairro=="")
  {
     alert("\n Favor preencher o campo bairro ! \n");
     document.FormCliente.bairro.focus();
	return false; 
  }
 
  // --- valida a cidade do cliente ---
  var cidade = document.FormCliente.cidade.value;
  if (cidade=="")
  {
     alert("\n Favor preencher o campo cidade ! \n");
     document.FormCliente.cidade.focus();
	return false; 
  }     
  
  // --- valida o estado do cliente ---
  var estado = document.FormCliente.estado.value;
  if (estado=="0")
  {
     alert("\n Favor preencher o campo estado ! \n");
     document.FormCliente.estado.focus();
	return false; 
  }   
 
  // --- valida o telefone do cliente ---
  var telefone = document.FormCliente.telefone.value;
  if (telefone=="")
  {
     alert("\n Favor preencher o campo telefone ! \n");
     document.FormCliente.telefone.focus();
	return false; 
  }  
 
  // --- valida os serviços do cliente ---
  var servicos = document.FormCliente.servicos.value;
  if (servicos=="")
  {
     alert("\n Favor preencher o campo serviços ! \n");
     document.FormCliente.servicos.focus();
	return false; 
  }     
  
  // --- valida as formas de pagamento dos serviços ---
  var pagamento = document.FormCliente.formapgto.value;
  if (pagamento=="")
  {
     alert("\n Favor preencher o campo forma de pagamento ! \n");
     document.FormCliente.formapgto.focus();
	return false; 
  }    
 
 
}

// --- valida a ajuda esqueci minha senha ---
function ValAjuda()
{

function rString(S)
{
  // Deixa so' os digitos no numero
  var Digitos = "0123456789";
  var temp = "";
  var digito = "";
 
  for (var i=0; i<S.length; i++)
  {
     digito = S.charAt(i);
     if (Digitos.indexOf(digito)>=0){temp=temp+digito}
  }
 return temp
}

function ValidaCnpj()
{
  var i;
  s = rString(s);
  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) return false;
  d1 = 11 - (d1 % 11);
  if (d1 > 9) d1 = 0;
  if (dv.charAt(0) != d1) { return false; }
  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){ return false; }
 return true;
}

// --- valida o cnpj do usuario ---
  var cnpj = document.FormAjuda.cnpj.value;
  if (cnpj=="")
  {
     alert("\n Favor preencher o campo cnpj ! \n");
     document.FormAjuda.cnpj.focus();
	return false; 
  }
  else
  { 
    s = rString(cnpj);
    if (ValidaCnpj(cnpj) == false)
    {
      alert("O formato do cnpj para este cliente é inválido !");
      document.FormAjuda.cnpj.focus();
     return false;
    }
  }
}

// valida o formulario de autenticacao do usuario
function AutenticaUser()
{
  var login = document.FormAutentica.login.value;
  var senha = document.FormAutentica.senha.value;    
  if (login=="")
  {
     alert("\n Favor preencher o campo login ! \n");
     document.FormAutentica.login.focus();
	return false; 
  } 
  
  if (senha=="")
  {
     alert("\n Favor preencher o campo senha ! \n");
     document.FormAutentica.senha.focus();
	return false; 
  }     
}

// valida o erro de autenticacao do usuario
function AutenticaErro(num)
{
  if (num==1){ alert("\nLogin e/ou Senha inválidos !\n"); }
  //if (num==2){ alert("\nVocê não está conectado ao sistema ou seu tempo de conexão expirou por motivos de segurança.\n Entre novamente com seu login e senha, se o problema continuar entre em contato com o Telemarketing.\n"); }  
  else
  {
     //posiciona a popup no centro da tela
     var posw = (screen.width - 370) / 2;
     var posl = (screen.height - 150) / 2;  
     window.open("http://www.b2bremen.com.br/validar/AutenticaUser.php?Login=0&Senha=0&Erro="+num,'Autenticar','width=370,height=150,top='+posw+',left='+posl+' status=no,scrollbars=no,resizable=0,toolbar=no,menubar=no');
  }
}

// valida o usuário querendo acessar pelo mapa do site
function AutMapUser( regiao )
{
     //posiciona a popup no centro da tela
     var posw = (screen.width - 390) / 2;
     var posl = (screen.height - 150) / 2;  
     window.open("http://www.b2bremen.com.br/mapa/AutMapUser.php?Regiao="+regiao,'Autenticar','width=390,height=150,top='+posw+',left='+posl+' status=no,scrollbars=no,resizable=0,toolbar=no,menubar=no');
}

// valida o formulario de busca do lado externo do Portal
function ValidarBusca()
{
  var busca = document.FormBusca.busca.value;
  if ( busca == "" )
  {
     alert("\n Favor preencher o campo busca com um critério ! \n");
     document.FormBusca.busca.focus();
	return false; 
  } 
}

//scroll das promoções
function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 
bw=new verifyCompatibleBrowser() 
 
 
var speed=100 
 
var loop, timer 
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 
function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 
var initialised; 
function InitialiseScrollableArea(){ 
    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 
    initialised=true; 
} 
//scroll das promoções

//---- envia a compra do usuario feita pela promoção da parte aberta para o mundo
function EnviarCarrinho(Form, CodFornec, CodPrazo, CodGrupo, CodBase, CodProduto, Produto, DetProduto, Qtde, Valor, Prazo, Motorista, Placa)
{
  //envia os dados para a url do carrinho  
  Arquivo = '/promocao/promcarrinho.php?CodFornec='+CodFornec+'&CodPrazo='+CodPrazo+'&CodGrupo='+CodGrupo+'&CodBase='+CodBase+'&CodProduto='+CodProduto+'&Produto='+Produto+'&DetProduto='+DetProduto+'&Qtde='+Qtde+'&Valor='+Valor+'&Prazo='+Prazo+'&Motorista='+Motorista+'&Placa='+Placa+'&ADD=1';
  Form.action = Arquivo;
  Form.target = 'FrmCarExt';
  Form.method = 'post';
  Form.submit();	
}

// valida o formulario de treinamento
function FichaTreinamento()
{
  var Treinamento = document.FormTreinamento.treinamento.value;
  var Cliente     = document.FormTreinamento.codcliente.value;
  var Nome        = document.FormTreinamento.nome.value;
  var Dono        = document.FormTreinamento.qtdedono.value;  
  var Gerente     = document.FormTreinamento.qtdeger.value;
  var Funcionario = document.FormTreinamento.qtdefunc.value;      
  
  if ( Treinamento == "0" )
  {
     alert("\n Favor selecionar um treinamento ! \n");
     document.FormTreinamento.treinamento.focus();
	return false; 
  } 
  
  if ( Cliente == "0" )
  {
     alert("\n Favor selecionar um cliente ! \n");
     document.FormTreinamento.codcliente.focus();
	return false; 
  }   
  
  if ( Nome == "" )
  {
     alert("\n Favor preencher o campo nome ! \n");
     document.FormTreinamento.nome.focus();
	return false; 
  }   
  
  if ( ( Dono == "" ) && ( Gerente == "" ) && ( Funcionario == "" ) )
  {
     alert("\n Favor informar o número de pessoas que vão participar do treinamento ! \n");
     document.FormTreinamento.qtdedono.focus();
	return false; 
  }    
  
}


// valida o formulario de incrição da revista
function FichaAssinatura()
{
  var Cnpj        = document.FormAssinatura.cnpj.value;  
  var Nome        = document.FormAssinatura.nome.value;
  var Endereco    = document.FormAssinatura.endereco.value;  
  var Bairro      = document.FormAssinatura.bairro.value;  
  var Cidade      = document.FormAssinatura.cidade.value; 
  var Telefone    = document.FormAssinatura.cidade.value;   
  var Estado      = document.FormAssinatura.estado.value;           
  
  if ( Cnpj == "" )
  {
     alert("\n Favor preencher corretamente o campo Cpf / Cnpj ! \n");
     document.FormAssinatura.cnpj.focus();
	return false; 
  }    
  
  if ( Nome == "" )
  {
     alert("\n Favor preencher corretamente o campo nome ! \n");
     document.FormAssinatura.nome.focus();
	return false; 
  } 
  
  if ( Endereco == "" )
  {
     alert("\n Favor preencher corretamente o campo endereço ! \n");
     document.FormAssinatura.endereco.focus();
	return false; 
  }   
  
  if ( Bairro == "" )
  {
     alert("\n Favor preencher corretamente o campo bairro ! \n");
     document.FormAssinatura.bairro.focus();
	return false; 
  }    
  
  if ( Cidade == "" )
  {
     alert("\n Favor preencher corretamente o campo cidade ! \n");
     document.FormAssinatura.cidade.focus();
	return false; 
  }   
  
  if ( Estado == "0" )
  {
     alert("\n Favor selecionar um estado ! \n");
     document.FormAssinatura.estado.focus();
	return false; 
  }  
  
  if ( Telefone == "" )
  {
     alert("\n Favor preencher corretamente o campo telefone ! \n");
     document.FormAssinatura.telefone.focus();
	return false; 
  }   
  
}