'use strict';

var _gaq = _gaq || [];

jQuery(document).ready(function($) {
    _gaq.push(['_setAccount', 'UA-16219573-1']);
    _gaq.push(['_setCustomVar', 1, 'product', getValueFor('input[name=sessionProdName]'), 3]);
    _gaq.push(['_setCustomVar', 2, 'role', getValueFor('input[name=sessionCurrentRoleType]'), 3]);
    _gaq.push(['_setDomainName', ".lpionline.com"]);
    _gaq.push(['_trackPageview']);

    $("a[href^='http:']").click(function() {
        if (this.host.indexOf('lpionline.com') < 0) {
            _gaq.push(['_trackEvent', 'link', 'outgoing', this.href]);
        }
    });

    var ga = DomUtils.createElement('script', {
        type: 'text/javascript',
        async: true,
        src: (document.location.protocol == 'https:' ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'
    });
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);

    function getValueFor(selector) {
        var value = $(selector).val();
        return value === undefined ? '(none)' : value;
    }
});

var FooterUtils = {
    showCopyrights: function() {
        FooterUtils._dialog('copyrights.body', 'Copyrights');
    },
    showPrivacy: function() {
        FooterUtils._dialog('tos.body', 'tos.title');
    },
    showTOS: function() {
        FooterUtils._dialog('licagree.body', 'licagree.title');
    },
    _dialog: function(msgI18NCode, titleI18NCode) {
        var displayedMessage = "<div style='width: 100%; height: 300px; overflow: auto;'>" + i18n.value(msgI18NCode) + "</div>";
        Boxy.alert(displayedMessage, null, { title: i18n.value(titleI18NCode) });
    }
};
