﻿function live_support(element)
{
    this.link = document.getElementById(element);

    this.show = function()
    {
        this.link.style.visibility = 'visible';
    },
    this.hide = function()
    {
        this.link.style.visibility = 'hidden';
        setTimeout('new live_support("' + element + '");', 1000);
    },
    this.go = function()
    {
        var d = new Date();
        
        if (this.isWeekday(d))
        {
            if (this.isSummer(d))
            {
                /* 
                    8 AM = 13 
                    6 PM = 23
                */
                if (d.getUTCHours() >= 13 && d.getUTCHours() <= 22)
                {
                    this.show();
                }
                else
                {
                    this.hide();
                }
            }
            else
            {
                /*
                    8:30 AM = 13
                    5:30 PM = 22
                */
                if (d.getUTCHours() >= 13 && d.getUTCHours() <= 22)
                {
                    if (d.getUTCHours() == 13)
                    {
                        if (d.getUTCMinutes() >= 30)
                        {
                            this.hide();
                        }
                        else
                        {
                            this.show();
                        }
                    }
                    else if (d.getUTCHours() == 22)
                    {
                        if (d.getUTCMinutes() <= 30)
                        {
                            this.hide();
                        }
                        else
                        {
                            this.show();
                        }
                    }
                    else
                    {
                        this.show();
                    }
                }
            }
        }
        else
        {
            this.hide();
        }
    },
    this.isSummer = function(d)
    {
        var currentMonth = d.getUTCMonth();
        
        if (currentMonth > 4 && currentMonth < 10)
        {
            return true;
        }
        
        return false;
    },
    this.isWeekday = function(d)
    {
        var currentDay = d.getUTCDay();
        
        if (currentDay > 0 && currentDay < 6)
        {
            return true;
        }
        
        return false;
    }
    
    this.go();
}