﻿/*********************************************
Por: Felippe Medeiros - felippem.wordpress.com
Data de criação: 17/10/2011
Versão: 1.0.0
*********************************************/
var GeosigaSiteUtil = function () {
    var aberto = false;
    return {
        AbrirBarraLogin: function (idObjeto, idBotao, posicaoAberto, posicaoFechado, classeBullet, idObjetoConteudo, focus) {
            $(idObjeto).animate({ top: (aberto == false ? posicaoAberto : posicaoFechado) }, 400, function () {
                if (!aberto) {
                    $(idBotao).addClass(classeBullet);
                    $(idObjetoConteudo).fadeIn("slow");

                    if (focus != null || focus != "")
                        $(focus).focus();

                    aberto = true;
                }
                else {
                    $(idBotao).removeClass(classeBullet);
                    $(idObjetoConteudo).fadeOut("slow");
                    aberto = false;
                }
            });
        },

        ExecutaBanner: function (objBanner, objDescricao, urlAjaxLoad) {
            $(objBanner).slides({
                preload: true,
                preloadImage: urlAjaxLoad,
                play: 15000,
                pause: 2000,
                hoverPause: true,
                animationStart: function (current) {
                    $(objDescricao).animate({
                        bottom: -200
                    }, 200);
                },
                animationComplete: function (current) {
                    $(objDescricao).animate({
                        bottom: 0
                    }, 200);
                },
                slidesLoaded: function () {
                    $(objDescricao).animate({
                        bottom: 0
                    }, 200);
                }
            });
        },

        RealizarLoginGeoTracker: function (usuario, senha, objMsg) {
            if (!GeosigaSiteUtil.ValidarTamanho(usuario, 3, 16, objMsg) || !GeosigaSiteUtil.ValidarTamanho(senha, 3, 16, objMsg))
                return;

            Geosiga.Geotracker.Authentication.login(usuario.val(), senha.val(),
                   function (result) {
                       if (result)
                           window.location.href = 'http://geotracker.geosiga.com.br/AppGateway.aspx';
                       else
                           $(objMsg).html("Usuário ou senha inválido. Por favor, tente novamente.");
                   }
               );
        },

        ValidarTamanho: function (obj, minimo, maximo, objMsg) {
            if (obj.val().length > maximo || obj.val().length < minimo) {
                $(obj).focus();
                $(objMsg).html("<b>" + $(obj).attr("d") + "</b> deve conter entre " + minimo + " e " + maximo + " caracteres.");
                return false;
            } else {
                return true;
            }
        },

        SelecionarTodosChecks: function (spanChk) {
            var oItem = spanChk.children;
            var theBox = (spanChk.type == "checkbox") ? spanChk : spanChk.children.item[0];
            xState = theBox.checked;
            elm = theBox.form.elements;
            for (i = 0; i < elm.length; i++) {
                if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {
                    if (elm[i].checked != xState)
                        elm[i].click();
                }
            }
        }
    };
} ();
