function textCounter(field, maxlimit, destino)
{
  if (field.value.length > maxlimit)
  {
    field.value = field.value.substring(0, maxlimit);
  }
  else
  {
    document.getElementById(destino).innerHTML = maxlimit - field.value.length + " caracteres restantes";
  }
}

$(document).ready(function () {

  $('#painel_home').jScrollPane({
    showArrows: true,
    scrollbarWidth: 14,
    dragMaxHeight: 14,
    animateTo: true,
    animateInterval: 50,
    animateStep: 5
  });

  $('#painel_obras').jScrollPane({
    showArrows: true,
    scrollbarWidth: 14,
    dragMaxHeight: 14,
    animateTo: true,
    animateInterval: 50,
    animateStep: 5
  });

  $("#form_login").submit(function () {
  
    if (document.form_login.login.value == "") {
      alert("Preencha o campo Login.");
      document.form_login.login.focus();
      return false;
    }

    if (document.form_login.passwd.value == "") {
      alert("Preencha o campo Senha.");
      document.form_login.passwd.focus();
      return false;
    }

    /*
    if (document.form_login.cmbTipo.value == "") {
      alert("Preencha o campo Tipo.");
      document.form_login.cmbTipo.focus();
      return false;
    }
    */

    $.post('verificacao.php', {
      login: $('input[name=login]').val(),
      passwd: $('input[name=passwd]').val()
    }, function (resposta) {
      if (resposta == "OK") {
        document.form_login.action = "http://projetos.niskier.com/gpweb3/port/index.php";
        document.form_login.submit();
        return false;
      } else {
        alert("Login incorreto!");
        return false;
      }
    });

    return false;

  });

  $("#form_fale_conosco").submit(function () {

    if (document.form_fale_conosco.txtNome.value == "") {
      alert("Preencha o campo Nome.");
      document.form_fale_conosco.txtNome.focus();
      return false;
    }

    if ( (document.form_fale_conosco.txtEmail.value == "") || (document.form_fale_conosco.txtEmail.value == "E-mail") ) {
      alert("Preencha o campo E-mail.");
      document.form_fale_conosco.txtEmail.value = "";
      document.form_fale_conosco.txtEmail.focus();
      return false;
    } else {
      if (document.form_fale_conosco.txtEmail.value.indexOf('@') <= -1) {
        alert("E-mail inválido.");
        document.form_fale_conosco.txtEmail.focus();
        return false;
      }
    }

    if (document.form_fale_conosco.txtProfissao.value == "") {
      alert("Preencha o campo Profissão.");
      document.form_fale_conosco.txtProfissao.focus();
      return false;
    }

    if (document.form_fale_conosco.txtCidade.value == "") {
      alert("Preencha o campo Cidade.");
      document.form_fale_conosco.txtCidade.focus();
      return false;
    }

    if (document.form_fale_conosco.txtEstado.value == "") {
      alert("Preencha o campo Estado.");
      document.form_fale_conosco.txtEstado.focus();
      return false;
    }
    
    if (document.form_fale_conosco.txtComentario.value == "") {
      alert("Preencha o campo Comentário.");
      document.form_fale_conosco.txtComentario.focus();
      return false;
    }

    /*
    if (document.form_fale_conosco.chkNewsletter.checked == false)
    {
      alert("Você deve aceitar o recebimento da Newsletter.");
      return false;
    }
    */

    return false;

  });

});

function exibir_floater_galeria(posicao)
{
  posicao = parseInt(posicao) - 1;

  $("#galeria").overlay({
    top: '10%',
    expose: {
      color: '#000000',
      loadSpeed: 200,
      opacity: 0.6
    },
    closeOnClick: true,
    api: true
  }).load();

  $('#galeria_imagem_container_imagens').cycle({
    fx: 'fade',
    speed: 1000,
    before: alterar_legenda_galeria,
    startingSlide: posicao,
    timeout: 0,
    next: '#proximo',
    prev: '#anterior'
  });
}

function fechar_floater_galeria()
{
  $("#galeria_legenda_inicio").html("");
  $("#galeria").overlay().close();
}

function alterar_legenda_galeria(curr,next,opts)
{
  slide = parseInt(opts.nextSlide) + 1;

  if ($("#galeria_legenda_inicio").html() == "")
  {
    $("#galeria_topo_legenda").html($("#galeria_legenda_" + opts.nextSlide).html());

    $("#galeria_legenda_inicio").html("1");
  }
  else
  {
    $("#galeria_topo_legenda").html($("#galeria_legenda_" + slide).html());
  }
}
