var Header = {
	init: function() {
		Portal.init();
        $(".textHelp").each(function(){
            if(!$(this).attr("alt") || $(this).attr("alt") == '') {
                $(this).attr("alt",$(this).attr("value"));
            }
        });

        this.asignarEventos();
        this.cargarEncuesta();
	},

    asignarEventos: function() {
        $("#imagen_boton_chat").click(function(){
            Header.chatear();
            Portal.ga_virtualTracking('/chat/activo');
        });

        $(".textHelp").focus(function(){
        if ($(this).val()==$(this).attr("alt")){
            $(this).val("");
        }
        });

        $(".textHelp").blur(function(){
            if($(this).val()==''){
                $(this).val($(this).attr("alt"));
            }
        });

        $('#BusquedaProductosFormCabecera').submit(function(e){
            var txtBusqueda = $('#BusquedaProductosFormCabecera #busquedaCabecera').val();
            var txtAlt = $('#BusquedaProductosFormCabecera #busquedaCabecera').attr('alt');
            if(txtBusqueda == txtAlt || $.trim(txtBusqueda) == '') {
                e.preventDefault();
                return false;
            } else {
                var words = txtBusqueda.split(' ');
                var filtro = $('#BusquedaProductosFormCabecera #filtro');
                filtro.val('');
                for(var i = 0; i < (words.length -1); i++) {
                    filtro.val(filtro.val() + words[i] + "+");
                }
                filtro.val(filtro.val() + words[words.length-1]);
            }
        });
    },
    
    cargarEncuesta: function () {        
        //Portal.loadScript("https://ips-invite.iperceptions.com/webValidator.aspx?sdfc=6b48b102-103890-13d97eab-39cf-4e7a-a669-f40615441db4&lID=16&loc=STUDY&cD=90&rF=False&iType=1&domainname=0", function () {});
    },

    inicializarChat: function() {
        //Inicialización del Chat
        var div = window.frames["chaty"].document.body;
        var imagen = div.getElementsByTagName('img');
        if(!imagen[0].src || (imagen[0].src+'').indexOf('off')==-1) {
            document.getElementById('ntr-chat-button2').style.display = 'block';
        }
    },

    chatear: function () {
        var iframe = window.frames["chaty"];
        iframe.chateando();
    }
}

$(function(){
    Header.init();
});
