﻿Master = function () {
    this._metodoCidade = null;
    this._handlerEnterKey = null;
    this._objIAjax = null;
    this._fontMax = 22;
    this._fontMin = 8;
}

Master.Load = function () {
    var _dados = new Master();
    _dados.initialize();
    return _dados;
}

Master.prototype = {

    initialize: function () {
        this._objIAjax = new AjaxInterface();
        var dtBusca = 'tbxSearch|busca';
        //this._loadBG();
        $('#tbxSearch').focus(dtBusca, $.methodDelegate(this._objIAjax, this._objIAjax._limpaTextoCampoBusca));
        $('#tbxSearch').blur(dtBusca, $.methodDelegate(this._objIAjax, this._objIAjax._addTextoCampoBusca));
        $('#btnSearch').click($.methodDelegate(this, this._executaBusca));
        var dtAssine = 'tbxNews|assine o nosso boletim';
        $('#tbxNews').focus(dtAssine, $.methodDelegate(this._objIAjax, this._objIAjax._limpaTextoCampoBusca));
        $('#tbxNews').blur(dtAssine, $.methodDelegate(this._objIAjax, this._objIAjax._addTextoCampoBusca));
        $('#btnNews').click($.methodDelegate(this, this._cadastraNews));
        $('#lnkaumfont').click($.methodDelegate(this, this._aumentafonte));
        $('#lnkdimfont').click($.methodDelegate(this, this._diminuifonte));
        $('#lnkescbck').click($.methodDelegate(this, this._escurecebg));
        $('#lnkclabck').click($.methodDelegate(this, this._clareiabg));
    },

    //    _handlerEscKeyPress: function (e) {
    //        if (e.keyCode == 27) {
    //            this._handlerEnterKey();
    //        }
    //    },

    _loadBG: function () {
        $('body').css("background", "url(../Upload/Pics/af/af14ebd0-3899-4ae8-a6a4-3f69dcf7e4c7.gif) no-repeat fixed center 0 transparent");
    },

    _executaBusca: function () {
        window.location.pathname = '/Busca/' + $('#tbxSearch').val();
    },

    _cadastraNews: function () {
        var m = $('#tbxNews').val();
        if (this._validaEmail(m)) {
            var str = { email: m };
            this._objIAjax.executeBind('/Home/cadastraNews', str, 'POST', $.methodDelegate(this, this._cadastraNews_Success), null, $.methodDelegate(this, this._cadastraNews_Begin));
        }
    },

    _cadastraNews_Begin: function () {
        this._objIAjax._carregando('btnLoad', 'btnNews');
    },

    _cadastraNews_Success: function (data, context, method) {
        alert(data.Msg);
        this._objIAjax._carregando('btnNews', 'btnLoad');
        $('#tbxNews').val('assine o nosso boletim');
    },

    _validaEmail: function (email) {
        var status = false;
        var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
        if (email.search(emailRegEx) == -1) {
            alert("Por favor, insira um e-mail válido");
        } else {
            status = true;
        }
        return status;
    },

    _aumentafonte: function () {
        
        var size = $('.lineSpace').css('font-size').substring(0, 2);
        size = parseInt(size);
        size += 1;
        if (size != this._fontMax) {
            $('.lineSpace').css('font-size', size + 'px');
            $('.lineSpace p').css('font-size', size + 'px');
            $('.lineSpace span').css('font-size', size + 'px');
        }
    },

    _diminuifonte: function () {
        
        var size = $('.lineSpace').css('font-size').substring(0, 2);
        size = parseInt(size);
        size -= 1;
        if (size != this._fontMin) {
            $('.lineSpace').css('font-size', size + 'px');
            $('.lineSpace p').css('font-size', size + 'px');
            $('.lineSpace span').css('font-size', size + 'px');
        }
    },

    _escurecebg: function () {
        $('.contentData').css('background-color', '#DDD');
        $('#topNews').css('background-color', '#DDD');
    },

    _clareiabg: function () {
        $('.contentData').css('background-color', '#FFF');
        $('#topNews').css('background-color', '#FFF');
    }
}


$(document).ready(function () {
    Master.Load();
});

/*
('#lkbCriarSecao').bind('click', '', $.methodDelegate(this, this._addSecaoRedirect));
var ed = '{ edicao: "' + $.query.get('eid') + '" }';
this.executeBind('editionContent.aspx/carregaListaSecoes', ed, 'POST', $.methodDelegate(this, this._carregaDropDown_Success), $.methodDelegate(this, this._carregaDropDown_Error), null);
_carregaDropDown_Success: function (data, context, method) {},
_carregaDropDown_Error: function (data, context, erro) {},

_carregando: function () {
$('#loading').show();
},

_carregandoEnd: function () {
$('#loading').hide();
},

_statusLogin: function () {
        var _obj = this;
        this._carregando('ldn_login');
        FB.getLoginStatus(function (response) {
            if (response.session) {
                $('#fbLogin').hide();
                $('#lblLogged').show();

                var query = FB.Data.query('select name, uid from user where uid={0}', response.session.uid);
                query.wait(function (rows) {
                    _obj._carregandoEnd('ldn_login');
                    $('#lblLogged').html('<img src="https://graph.facebook.com/' + rows[0].uid + '/picture" alt="" width="36" height="36" />\
                                            Seja bem vindo ' + rows[0].name);
                    _obj._carregaCidadeUsuario();
                });
            } else {
                _obj._carregandoEnd('ldn_login');
                $('#fbLogin').show();
                $('#lblLogged').hide();
            }
        });
    },

*/
