/**
*   Identifica browser do usuário
*/

var netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

/**
*   Imprime animação do topo
*/

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-7041276-4");
pageTracker._trackPageview();
} catch(err) {}

function exibirTopo()
{
  var id = (arguments[0]) ? arguments[0] : "";
  if (!netscape)
  {
    document.write(
    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  '+
    '       codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,24" '+
    '       width="780" height="124"> '+
    '<param name="movie" value="flash/header_fv8.swf?button=' + id + '"  />  '+
    '<param name="quality" value="high"  /> '+
    '<param name="menu" value="false"  /> '+
    '<param name="wmode" value="transparent"  />  '+
    '</object>'
    );
  }
  else
  {
    document.write(
    '<object data="flash/header_fv8.swf?button=' + id + '" '+
    '        width="780" height="124" type="application/x-shockwave-flash"> '+
    '<param name="quality" value="high"  /> '+
    '<param name="menu" value="false"  /> '+
    '<param name="wmode" value="transparent"  /> '+
    '<param name="pluginurl" value="https://www.macromedia.com/go/getflashplayer"  /> '+
    'FAIL (the browser should render some flash content, not this). '+
    '</object>'
    );
  }
}

function ChecaEmail(campo) {
	var email = campo.value;
	var arroba = email.indexOf("@");
	var ponto = email.lastIndexOf(".");
	var espaco = email.indexOf(" ");
	var mail = ((arroba != -1) && (arroba != 0) && (ponto != -1) && (ponto > arroba + 1) && (ponto < email.length - 1) && (espaco == -1));
	if (!mail)
		return true;
	else
		return false;
}

function validaCPF(cpf) {
  cpf = cpf.replace(".","").replace(".","").replace(".","").replace("-","");
  erro = new String;
  if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
  var nonNumbers = /\D/;
  if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
  if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
    erro += "Numero de CPF invalido!"
  }
  var a = [];
  var b = new Number;
  var c = 11;
  for (i=0; i<11; i++){
    a[i] = cpf.charAt(i);
    if (i < 9) b += (a[i] * --c);
  }
  if ((x = b % 11) < 2) { a[9] = 0 }
  else { a[9] = 11-x }
  b = 0;
  c = 11;
  for (y=0; y<10; y++) 
    b += (a[y] * c--); 
  if ((x = b % 11) < 2) { a[10] = 0; } 
  else { a[10] = 11-x; }
  if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
    erro +="Digito verificador com problema!";
  }
  if (erro.length > 0) {
    return false;
  }
  return true;
}

function $(id)
{
  return document.getElementById(id);  
}

function submeterLogin(e)
{
  var campo = (document.all) ? event.srcElement : e.target;
  var tecla = (document.all) ? event.keyCode : e.which;
  if (tecla == 13)
  {
    if (campo.name == "usuario")
      campo.form.elements['senha'].focus();
    else if (campo.name == "senha")
      campo.parentNode.getElementsByTagName("A")[0].onclick();
  }
}

function enviarLogin()
{
  //alert('Devido a problemas em nosso servidor, as atualizações notificadas por email não foram realizadas.\nEm breve as atualizações serão incluídas em nosso sistema.');
  $('autenticacao').elements["acao"].value = 'logar';
  $('autenticacao').submit();
}

function enviarEsqueci()
{
  $('autenticacao').elements["acao"].value = 'esqueci';
  $('autenticacao').submit();
}

var divDinamica = false;
function esqueciMinhaSenha()
{
  while ($('dinamico').firstChild)
    $('dinamico').removeChild($('dinamico').firstChild);
 
  if (divDinamica == false)
  {
    var label = document.createElement("label");
    var input = document.createElement("input");
    var img = document.createElement("img");
    label.appendChild(document.createTextNode("Email:"));
    input.setAttribute("name", "email");
    input.maxLength = 50;
    img.setAttribute("alt", "OK")
    img.setAttribute("src", "images/button_p1.gif");
    img.onclick = function() { enviarEsqueci() };

    $('dinamico').appendChild(label);
    $('dinamico').appendChild(input);
    $('dinamico').appendChild(img);
    
    divDinamica = true;
  }
  else
    divDinamica = false;
}

function Numeros(e) {
	tecla = (netscape) ? e.which : event.keyCode;
	if (tecla == 17)
	return false;

	if (tecla > 47 && tecla < 58)
	return true;
	else {
		if (tecla == 8 || tecla == 9 || tecla == 0)
		return true;
		else
		return false;
	}
}

window.onload = function()
{
  // Inserir aviso no HCL para usuários FireFox 3.0.6
  var links = document.links;
  for (var i=0; i<links.length; i++)
  {
    if (links[i].href.indexOf('Live') > -1)
    {
        links[i].onclick = function()
        {
            if (navigator.userAgent.indexOf('3.0.6') > -1)
            {
                alert('Nosso sistema de suporte não é compátivel com a versão do seu navegador (FireFox 3.0.6), por favor utilize outro navegador para acessar este suporte.');
                return false;
            }
        }
    }
  }
}

