
/* - popup.js - */
jQuery(document).ready(function(){
    
    var popupTimer;

    window.onload = function() {
        jQuery("#portal-column-content").append('<div id="popup"></div>');
        jQuery("#popup").css('visibility:hidden');
        var hasCookie = readCookie();
        var popupAllow = "True";
        if ((hasCookie == 'new' || hasCookie == null) && popupAllow.toLowerCase() == 'true') {
            popupTimer = setTimeout(function(){
                jQuery("#popup").html('<div style="padding-left: 1em !important; "><h3 class="p1" style="text-align: center; ">Need help?</h3><p><span>Aktion Associates is happy to help you find the products and services your business needs to grow and profit. Choose "OK" to initiate a real time chat now.</span></p></div>');
                jQuery("#popup").append('<div id="chat_logo">&nbsp;</div><p>&nbsp;</p>');
                jQuery("#popup").append('<a id="chat_no" class="chat_button">No Thanks</a><a id="chat_yes" class="chat_button">Ok</a>')
                jQuery("#popup").hide();
                jQuery("#popup").toggle('slide');
                jQuery("#chat_yes").click(function() {
                    jQuery("#popup").toggle('slide');
                    jQuery('<iframe src="http://chat.aktion.com/webim/client.php?locale=en" align="center" style="padding=0;"></iframe>').dialog({width: 670, height: 500, zIndex: 1001, resizable: false});
                });
                jQuery("#chat_no").click(function() {
                    jQuery("#popup").toggle('slide');
                });
                createCookie('old');
            }, (20 * 1000));
        }

        function readCookie() {
            var visitor = "visitor=";
            var cookies = document.cookie.split(';');

            for(var i=0; i < cookies.length; i++) {
                var cookie = cookies[i];
                while (cookie.charAt(0) == ' ') {
                    cookie = cookie.substring(1, cookie.length);
                }
                if (cookie.indexOf(visitor) == 0) {
                    return cookie.substring(visitor.length, cookie.length);
                }
            }
            return null;
        }

        function createCookie(value) {
            document.cookie="visitor="+value;
        }

        //This code will launch the chat dialog box when either the chat portlet or
        //chat viewlet anchors are clicked

        jQuery(".chat").click(function() {
            clearTimeout(popupTimer);
            createCookie('old');
            jQuery(".ui-dialog-titlebar").show();
            jQuery('<iframe src="http://chat.aktion.com/webim/client.php?locale=en" align="center" style="padding=0;"></iframe>').dialog({
                width: 670,
                height: 500,
                zIndex: 1001,
                resizable: false
            });
        });
    }
    
});

