﻿/*
* GuideHoraire
*
* Spécifications                : Définition de l'objet qui va gérer l'affichage de la grille horaire.
* Date de création              : Novembre 2010
* Date de dernière modification : 15 février 2012
* Copyright                     : Société de Radio-Canada 
*/

var g_counter = 1;

var GuideHoraireFactory = function () {
    this.id = '';
    this.regionalization = {};
    if (typeof (RadioCanada.Mod.oRegionalization) != 'undefined' && typeof (RadioCanada.Mod.oRegionalization.Profile) != 'undefined') {
        this.regionalization.tvid = RadioCanada.Mod.oRegionalization.Profile.Tele.GuideHoraireId;
        this.regionalization.tvregionname = RadioCanada.Mod.oRegionalization.Profile.Tele.GuideHoraireName;
        this.regionalization.radioid = RadioCanada.Mod.oRegionalization.Profile.Radio.GuideHoraireId;
        this.regionalization.radioregionname = RadioCanada.Mod.oRegionalization.Profile.Radio.GuideHoraireName;
        this.regionalization.emid = RadioCanada.Mod.oRegionalization.Profile.EspaceMusique.GuideHoraireId;
        this.regionalization.emregionname =RadioCanada.Mod.oRegionalization.Profile.EspaceMusique.GuideHoraireName;
    }
    this.channels = {};
    this.broadcasts = {};
    this.currentfeeds = {};
    this.mindate = new Date();
    this.maxdate = new Date();
    this.currentdate = new Date();
    this.baseurl = 'http://' + 'www.radio-canada.ca/Modules/GuideHoraire/v1/';
    this.delta = 3;
    this.step = 1;
    this.selectedregionid = 0;
    this.nbpixelbyminute = 720 / (this.delta * 60);
    this.localCache = new Array();
    this.inputparams = {};
    this.positionCurrent = 0;
    this.lock = true;
    this.url4RegionalizationPopup = 'http://' + 'www.radio-canada.ca/Modules/RegionPopUp/v1/RegionPopUp.aspx?d=domain#tab';
    this.montrealoffset = -5;
    this.currentoffset = -5;
    this.needrefresh = true;
    this.mini = false;
    this.initialized = false;
    this.counterCallee = 0;
};

GuideHoraireFactory.prototype = {

    getChannelsIds: function () {
        var list = '';
        var counter = 0;
        for (var channel in this.channels) {
            if (counter > 0) {
                list += ',';
            }
            list += this.channels[channel].Id;
            counter++;
        }
        return list;
    },

    increaseCounter: function () {
        this.counterCallee++;

        return this.counterCallee;
    },

    initialize: function (regionalization, params, hoursdelta, baseurl, url4RegionalizationPopup, pMini, pIsTvRadio, pIsLegacy) {
        this.initialized = true;
        var l_oScheduleTableWrapperI = this;

        if (typeof (baseurl) != 'undefined' && baseurl != "") {
            l_oScheduleTableWrapperI.baseurl = baseurl;
        }

        if (typeof (hoursdelta) != 'undefined') {
            l_oScheduleTableWrapperI.delta = hoursdelta;
        }

        if (typeof (regionalization) != 'undefined') {
            l_oScheduleTableWrapperI.regionalization = regionalization;
        }

        if (typeof (params) != 'undefined') {
            l_oScheduleTableWrapperI.inputparams = params;
        }

        if (typeof (url4RegionalizationPopup) != 'undefined' && url4RegionalizationPopup != "") {
            l_oScheduleTableWrapperI.url4RegionalizationPopup = url4RegionalizationPopup;
        }

        if (this.currentdate == null) {
            this.currendate = new Date();
        }

        var l_time = l_oScheduleTableWrapperI.delta / 2;
        var l_hours = this.currentdate.getHours();
        if (this.currentdate.getMinutes() > 30) {
            l_hours = l_hours + 1;
        }

        var l_temporary = new Date(this.currentdate.getFullYear(), this.currentdate.getMonth(), this.currentdate.getDate(), l_hours, 0, 0, 0);
        l_oScheduleTableWrapperI.mindate.setTime(l_temporary.getTime() - (l_time * 60 * 60 * 1000));
        l_oScheduleTableWrapperI.maxdate.setTime(l_temporary.getTime() + (l_time * 60 * 60 * 1000));
        l_oScheduleTableWrapperI.nbpixelbyminute = 720 / (l_oScheduleTableWrapperI.delta * 60);
        l_oScheduleTableWrapperI.lock = true;
        l_oScheduleTableWrapperI.synchronize(false, true, pMini, pIsTvRadio, pIsLegacy, false);
    },

    synchronize: function (pDisplay, pRefresh, pMini, pIsTvRadio, pIsLegacy, pCallFromRefresh) {
        var l_oScheduleTableWrapperS = this;
        var l_key4Cache = l_oScheduleTableWrapperS.regionalization.tvid + '_' + l_oScheduleTableWrapperS.regionalization.radioid + '_' + l_oScheduleTableWrapperS.regionalization.emid + '_' + l_oScheduleTableWrapperS._formatDate("yyyyMMddHHmm", l_oScheduleTableWrapperS.mindate) + '_' + l_oScheduleTableWrapperS._formatDate("yyyyMMddHHmm", l_oScheduleTableWrapperS.maxdate);
        var today = new Date();

        if (l_oScheduleTableWrapperS.localCache[l_key4Cache] == null) {
            RadioCanada.Lib.jQuery.ajax({
                url: l_oScheduleTableWrapperS.baseurl + "/GuideHoraireDataHandler.ashx",
                dataType: 'jsonp',
                jsonpCallback: 'synchronizeall_' + l_oScheduleTableWrapperS.increaseCounter(),
                cache: true,
                data: { action: "get", tvregionid: l_oScheduleTableWrapperS.regionalization.tvid, radioregionid: l_oScheduleTableWrapperS.regionalization.radioid, emregionid: l_oScheduleTableWrapperS.regionalization.emid, datemin: this._formatDate("yyyy-MM-ddTHH:mm", l_oScheduleTableWrapperS.mindate), datemax: this._formatDate("yyyy-MM-ddTHH:mm", l_oScheduleTableWrapperS.maxdate) },
                success: function (data) {
                    l_oScheduleTableWrapperS.channels = data['channels'];
                    l_oScheduleTableWrapperS.currentfeeds = data['currentfeeds'];
                    l_oScheduleTableWrapperS.broadcasts = data['broadcasts'];
                    l_oScheduleTableWrapperS.localCache[l_key4Cache] = data;
                    l_oScheduleTableWrapperS.lock = false;

                    if (pMini) {
                        if (pDisplay) {
                            l_oScheduleTableWrapperS.displaymini(pIsTvRadio, pIsLegacy);
                        }
                    }
                    else {
                        l_oScheduleTableWrapperS.display(pDisplay, pRefresh);
                        RadioCanada.Lib.jQuery('div#loading-guide').hide();
                        RadioCanada.Lib.jQuery("div#scheduletable").show();
                    }
                }
            });
        }
        else {

            RadioCanada.Lib.jQuery.ajax({
                url: l_oScheduleTableWrapperS.baseurl + "/GuideHoraireDataHandler.ashx",
                dataType: 'jsonp',
                jsonpCallback: 'synchronizefeeds_' + l_oScheduleTableWrapperS.increaseCounter(),
                cache: true,
                data: { action: "getcurrentfeeds", tvregionid: l_oScheduleTableWrapperS.regionalization.tvid, radioregionid: l_oScheduleTableWrapperS.regionalization.radioid, emregionid: l_oScheduleTableWrapperS.regionalization.emid },
                success: function (data) {
                    l_oScheduleTableWrapperS.currentfeeds = data;
                    l_oScheduleTableWrapperS.localCache[l_key4Cache]['currentfeeds'] = data;
                    l_oScheduleTableWrapperS.channels = l_oScheduleTableWrapperS.localCache[l_key4Cache]['channels'];
                    l_oScheduleTableWrapperS.broadcasts = l_oScheduleTableWrapperS.localCache[l_key4Cache]['broadcasts'];
                    l_oScheduleTableWrapperS.lock = false;

                    if (pMini) {
                        if (pDisplay) {
                            l_oScheduleTableWrapperS.displaymini(pIsTvRadio, pIsLegacy);
                        }
                    }
                    else {
                        l_oScheduleTableWrapperS.display(pDisplay, pRefresh);
                        RadioCanada.Lib.jQuery('div#loading-guide').hide();
                        RadioCanada.Lib.jQuery("div#scheduletable").show();
                    }
                }
            });
        }
    },

    previous: function () {
        this.needrefresh = false;

        RadioCanada.Lib.jQuery("div#scheduletable").hide();
        RadioCanada.Lib.jQuery('div#loading-guide').show();

        this.mindate.setTime(this.mindate.getTime() - this.step * 180 * 60 * 1000);
        this.maxdate.setTime(this.maxdate.getTime() - this.step * 180 * 60 * 1000);
        this.synchronize(true, false, false, false, false, false);
    },

    next: function () {
        this.needrefresh = false;

        RadioCanada.Lib.jQuery("div#scheduletable").hide();
        RadioCanada.Lib.jQuery('div#loading-guide').show();

        this.mindate.setTime(this.mindate.getTime() + this.step * 180 * 60 * 1000);
        this.maxdate.setTime(this.maxdate.getTime() + this.step * 180 * 60 * 1000);
        this.synchronize(true, false, false, false, false, false);
    },

    refresh: function (pDisplay) {
        var now = new Date();

        if (this.needrefresh) {
            if (this.currentdate.getMinutes() != now.getMinutes()) {
                if (this.currentdate.getMinutes() > now.getMinutes()) {
                    this.currentdate.setMinutes(now.getMinutes() + 60);
                }
                else {
                    this.currentdate.setMinutes(now.getMinutes());
                }
                var l_hours = this.currentdate.getHours();
                if (this.currentdate.getMinutes() > 30) {
                    l_hours = (l_hours + 1);
                }

                RadioCanada.Lib.jQuery("div#scheduletable").hide();
                RadioCanada.Lib.jQuery('div#loading-guide').show();
                var l_time = this.delta / 2;
                var l_temporary = new Date(this.currentdate.getFullYear(), this.currentdate.getMonth(), this.currentdate.getDate(), l_hours, 0, 0, 0);

                if ((l_temporary.getTime() - this.maxdate.getTime()) < (30 * 60 * 1000)) {
                    this.mindate.setTime(l_temporary.getTime() - (l_time * 60 * 60 * 1000));
                    this.maxdate.setTime(l_temporary.getTime() + (l_time * 60 * 60 * 1000));
                }

                this.lock = true;
                this.synchronize(pDisplay, false, false, false, false, true);
            }

            setTimeout("RadioCanada.Mod.oGuideHoraire.refresh(true)", 1000);
        }
    },

    refreshmini: function (pIsTvRadio, pIsLegacy) {
        var now = new Date();

        if (this.currentdate.getMinutes() != now.getMinutes() || !this.initialized) {
            if (!this.initialized && typeof (RadioCanada.Mod.oRegionalization) != 'undefined' && typeof (RadioCanada.Mod.oRegionalization.Profile) != 'undefined') {
                this.regionalization.tvid = RadioCanada.Mod.oRegionalization.Profile.Tele.GuideHoraireId;
                this.regionalization.tvregionname = RadioCanada.Mod.oRegionalization.Profile.Tele.GuideHoraireName;
                this.regionalization.radioid = RadioCanada.Mod.oRegionalization.Profile.Radio.GuideHoraireId;
                this.regionalization.radioregionname = RadioCanada.Mod.oRegionalization.Profile.Radio.GuideHoraireName;
                this.regionalization.emid = RadioCanada.Mod.oRegionalization.Profile.EspaceMusique.GuideHoraireId;
                this.regionalization.emregionname =RadioCanada.Mod.oRegionalization.Profile.EspaceMusique.GuideHoraireName;
            }
            
            if (this.currentdate.getMinutes() > now.getMinutes()) {
                this.currentdate.setMinutes(now.getMinutes() + 60);
            }
            else {
                this.currentdate.setMinutes(now.getMinutes());
            }
            var l_hours = this.currentdate.getHours();
            if (this.currentdate.getMinutes() > 30) {
                l_hours = (l_hours + 1);
            }
            var l_time = this.delta / 2;
            var l_temporary = new Date(this.currentdate.getFullYear(), this.currentdate.getMonth(), this.currentdate.getDate(), l_hours, 0, 0, 0);

            if ((l_temporary.getTime() - this.maxdate.getTime()) < (30 * 60 * 1000)) {
                this.mindate.setTime(l_temporary.getTime() - (l_time * 60 * 60 * 1000));
                this.maxdate.setTime(l_temporary.getTime() + (l_time * 60 * 60 * 1000));
            }

            this.synchronize(true, false, true, pIsTvRadio, pIsLegacy, true);
        }
        else {
            this.displaymini(pIsTvRadio, pIsLegacy);
        }
    },

    display: function (pDisplay, pRefresh) {
        if (!pDisplay) {
            RadioCanada.Lib.jQuery("div#guide-bloc").css('visibility', 'hidden');
        }

        this._display_left_channels();
        this._display_navigation();
        this._display_broadcasts(this.currentdate);
        this._display_right_channels();

        if (!pDisplay) {
            setTimeout(function () { RadioCanada.Lib.jQuery("div#guide-bloc").css('visibility', 'visible'); }, 1000);

            if (pRefresh) {
                setTimeout("RadioCanada.Mod.oGuideHoraire.refresh(true)", 1000);
            }
        }

        this.lock = false;
    },

    displaymini: function (pIsTvRadio, pIsLegacy) {
        RadioCanada.Lib.jQuery("div#miniguide-bloc").hide();
        RadioCanada.Lib.jQuery("div#miniguide-bloc").css('visibility', 'hidden');
        RadioCanada.Lib.jQuery('div#loading-guide').show();

        this._displaymini_broadcasts(this.currentdate, pIsTvRadio, pIsLegacy);

        RadioCanada.Lib.jQuery('div#loading-guide').hide();
        RadioCanada.Lib.jQuery("div#miniguide-bloc").show();
        RadioCanada.Lib.jQuery("div#miniguide-bloc").css('visibility', 'visible');

        this.lock = false;
    },

    _getLabel4Stats: function (pChannel, pMini) {

        if (pMini == null)
            pMini = false;

        var l_label_stats = 'GH';
        if (pMini) {
            if (pChannel.IsRadio) {
                l_label_stats = 'Mini_GH_Radio';
            } else {
                l_label_stats = 'Mini_GH_Tele';
            }
        }

        if (pChannel.IsTV) {
            if (pChannel.Key == 'premierechaine') {
                l_label_stats += ' TV';
            }
            else {
                if (pChannel.Key == 'rdi') {
                    l_label_stats += '_RDI';
                }
                else {
                    l_label_stats += ' ' + pChannel.Name;
                }
            }
        }
        if (pChannel.IsRadio) {
            if (pChannel.Key == 'premierechaine') {
                l_label_stats += '_Radio1';
            }
            else {
                if (pChannel.Name == 'espacemusique') {
                    l_label_stats += '_RadioEM';
                }
                else {
                    l_label_stats += ' ' + pChannel.Name;
                }
            }
        }

        return l_label_stats;
    },

    _display_left_channels: function () {
        RadioCanada.Lib.jQuery('#left-channels').empty();
        var l_counter = 1;
        for (var channelkey in this.channels) {
            RadioCanada.Lib.jQuery('#left-channels').append(this._display_column_left_onechannel(this.channels[channelkey], channelkey, l_counter, false, false));
            l_counter++;
        }
    },

    _display_navigation: function () {
        var l_initialtine = this.mindate.getTime();
        var l_currentdatetodisplay = new Date(this.mindate.getFullYear(), this.mindate.getMonth(), this.mindate.getDate(), this.mindate.getHours(), this.mindate.getMinutes(), this.mindate.getSeconds(), 0);
        var l_previousdatetodisplay = new Date(this.mindate.getFullYear(), this.mindate.getMonth(), this.mindate.getDate(), this.mindate.getHours(), this.mindate.getMinutes(), this.mindate.getSeconds(), 0);
        RadioCanada.Lib.jQuery('#hours').empty();

        for (l_counterdemiheure = 0; l_counterdemiheure <= this.delta * 2; l_counterdemiheure++) {
            l_currentdatetodisplay.setTime(l_initialtine + l_counterdemiheure * 30 * 60 * 1000);

            if (l_counterdemiheure > 0) {
                l_last = (l_counterdemiheure > (this.delta * 2) - 1);

                RadioCanada.Lib.jQuery('#hours').append(this._display_label_onehour(l_previousdatetodisplay, l_currentdatetodisplay, this.currentdate, this.positionCurrent, l_last));
            }

            l_previousdatetodisplay = new Date(l_currentdatetodisplay.getFullYear(), l_currentdatetodisplay.getMonth(), l_currentdatetodisplay.getDate(), l_currentdatetodisplay.getHours(), l_currentdatetodisplay.getMinutes(), l_currentdatetodisplay.getSeconds(), 0);
        }
    },

    _display_broadcasts: function (pCurrentDate) {
        RadioCanada.Lib.jQuery('#scheduletable').empty();

        for (var onechannelinbroadcasts in this.channels) {
            counterKey = 0;
            for (var onebroadcastkey in this.broadcasts) {
                if (onebroadcastkey != 'ID') {
                    counterKey++;
                }
            }
            if (counterKey > 0) {
                RadioCanada.Lib.jQuery('#scheduletable').append(this._display_broadcast_onechannel(this.broadcasts[onechannelinbroadcasts], pCurrentDate, this.channels[onechannelinbroadcasts]));
            }
            else {
                RadioCanada.Lib.jQuery('#scheduletable').append(this._display_broadcast_onechannel_empty(this.channels[onechannelinbroadcasts]));
            }
        }
    },

    _displaymini_broadcasts: function (pCurrentDate, pIsTvRadio, pIsLegacy) {
        RadioCanada.Lib.jQuery('#miniguide-bloc').empty();
        var l_counter = 1;
        var l_class = '';
        var l_html = '';

        //RadioCanada.Lib.jQuery('#miniguide-bloc').append(RadioCanada.Lib.jQuery('<a></a>').attr('name', ((pIsTvRadio) ? 'zonetele' : 'zoneradio')));

        for (var onechannelinbroadcasts in this.channels) {
            l_html = '';

            if (l_counter % 2 == 0) {
                l_class = 'sousMenuZone even';
            }
            else {
                l_class = 'sousMenuZone odd';
            }

            if ((pIsTvRadio && this.channels[onechannelinbroadcasts].IsTV) || (!pIsTvRadio && this.channels[onechannelinbroadcasts].IsRadio)) {
                l_html += '<div class="' + l_class + '"><ul>';
                l_html += this._display_column_left_onechannel(this.channels[onechannelinbroadcasts], onechannelinbroadcasts, l_counter, true, pIsLegacy);
                l_html += this._display_column_right_onechannel(this.channels[onechannelinbroadcasts], l_counter, true);
                l_html += this._display_currentbroadcast(this.broadcasts[onechannelinbroadcasts], pCurrentDate, this.channels[onechannelinbroadcasts], true);
                l_html += '</ul></div>';

                RadioCanada.Lib.jQuery('#miniguide-bloc').append(l_html);

                l_counter++;
            }
        }

        if (!pIsTvRadio) {
            var l_channel = { Name: 'RCI', Id: 0, IsTV: false, IsRadio: true, City: 'Montréal', Indicatif: '', Region: { Id: 1, Name: 'Montréal', HourDelay: 0, Ids4Syndication: new Array()} };
            if (l_counter % 2 == 0) {
                l_class = 'sousMenuZone even';
            }
            else {
                l_class = 'sousMenuZone odd';
            }

            l_html = '<div class="' + l_class + '"><ul>';
            l_html += this._display_column_left_onechannel(l_channel, '', l_counter, true);
            l_html += this._display_column_right_onechannel(l_channel, l_counter, true);
            l_html += '<li class="emission">';
            l_html += '<a class="link-news" href="' + RadioCanada.buildLink('http://www.rcinet.ca/radio/index.php?language=fr&type=&media=radio&id=cbc') + '" onclick="' + this._statstags(this._getLabel4Stats(l_channel, true) + ' Play', 'RCI En Direct', false) + this._popRciConsole('fr', '', 'radio', 'cbc') + 'return false;" title="Écouter RCI en direct"><span class="play xx-small"></span></a>';
            l_html += '<span>RCI en direct</span>';
            l_html += '</li>';
            l_html += '</ul></div>';

            RadioCanada.Lib.jQuery('#miniguide-bloc').append(l_html);
        }
    },

    _display_right_channels: function () {
        RadioCanada.Lib.jQuery('#right-channels').empty();
        var l_counter = 1;
        for (var channelkey in this.channels) {
            RadioCanada.Lib.jQuery('#right-channels').append(this._display_column_right_onechannel(this.channels[channelkey], l_counter, false));
            l_counter++;
        }
    },

    _display_column_left_onechannel: function (pChannel, pKeyChannel, pCounter, pIsMini, pIsLegacy) {
        var l_leftonechannel = '';
        var l_classname = 'onechannel';
        var l_tab = '';
        var l_regionname = '';
        var l_href = '';
        var l_title = '';
        var l_statsclicklogo = '';
        var l_statsclick = '';

        if (pChannel.Key == 'premierechaine' && pChannel.IsTV) {
            l_classname = 'channel-tele';
            l_tab = '#tv';
            l_regionname = this.regionalization.tvregionname;
            l_href = RadioCanada.buildLink(RadioCanada.getBaseUrl() + "/tele/");
            l_title = pChannel.Name + ' Télévision';

            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Tele_TVG_Logo';
                l_statsclick = 'Mini_GH_Tele_TVG_ChangerBloc';
            } else {
                l_statsclicklogo = 'GH_Tele_TVG_Logo';
                l_statsclick = 'GH_Tele_TVG_ChangerBloc';
            }
        }

        if (pChannel.Key == 'rdi') {
            l_classname = 'channel-rdi';
            l_href = RadioCanada.buildLink("http://www.radio-canada.ca/rdi");
            l_title = pChannel.Name;

            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Tele_RDI_Logo';
            } else {
                l_statsclicklogo = 'GH_Tele_RDI_Logo';
            }
        }

        if (pChannel.Key == 'premierechaine' && pChannel.IsRadio) {
            l_classname = 'channel-radio';
            l_tab = '#radio';
            l_regionname = this.regionalization.radioregionname;
            l_href = RadioCanada.buildLink("http://www.radio-canada.ca/radio");
            l_title = pChannel.Name + ' Radio';


            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Radio_PC_Logo';
                l_statsclick = 'Mini_GH_Radio_PC_ChangerBloc';
            } else {
                l_statsclicklogo = 'GH_Radio_PC_Logo';
                l_statsclick = 'GH_Radio_PC_ChangerBloc';
            }
        }

        if (pChannel.Key == 'espacemusique') {
            l_classname = 'channel-espace';
            l_tab = '#radio';
            l_regionname = this.regionalization.emregionname;
            l_href = RadioCanada.buildLink("http://www.radio-canada.ca/espace_musique");
            l_title = pChannel.Name;

            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Radio_EM_Logo';
                l_statsclick = 'Mini_GH_Radio_EM_ChangerBloc';
            } else {
                l_statsclicklogo = 'GH_Radio_EM_Logo';
                l_statsclick = 'GH_Radio_EM_ChangerBloc';
            }
        }

        if (pChannel.Key == 'artv') {
            l_classname = 'channel-artv';
            l_href = RadioCanada.buildLink("http://artv.ca");
            l_title = 'artv';

            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Tele_ARTV_Logo';
            } else {
                l_statsclicklogo = 'GH_Tele_ARTV_Logo';
            }

        }

        if (pChannel.Name == 'RCI') {
            l_classname = 'channel-rci';
            l_href = RadioCanada.buildLink("http://www.rcinet.ca/francais/");
            l_title = 'RCI';

            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Radio_RCI_Logo';
            } else {
                l_statsclicklogo = 'GH_Radio_RCI_Logo';
            }
        }

        var l_displaytitle = this._ellipsis(l_regionname, 21, ' ');

        if (pIsMini) {
            l_leftonechannel += '<li class="' + l_classname + '">';
        }
        else {
            l_leftonechannel += '<li class="' + l_classname + ((pCounter % 2 == 0) ? ' even' : ' odd') + '">';
        }

        this._ellipsis(l_regionname, null, ' ')
        l_leftonechannel += '<a href="' + l_href + '" title="' + l_title + '" class="channel-name" onclick="' + this._statstags(l_statsclicklogo, l_statsclicklogo, true) + '">' + pChannel.Name + '</a>';

        if (pChannel.Key != "rdi" && pChannel.Name != "ARTV" && pChannel.Name != "RCI") {
            l_leftonechannel += '<div class="change-region"' + ((l_displaytitle.ellipsize) ? ' title="' + l_regionname + '"' : '') + '>' + l_displaytitle.title + ' ';

            if (pIsLegacy) {
                l_leftonechannel += '<a href="' + this.url4RegionalizationPopup.replace("?d=domain", "?d=radio-canada.ca").replace("#tab", l_tab) + '" id="channel_' + pChannel.Id + '_chooseregion"';
                l_leftonechannel += ' title="Choisir une nouvelle région" onclick="' + this._statstags(l_statsclick, l_statsclick, true) + ' if (typeof( RadioCanada.Lib.jQuery.colorbox) != \'undefined\') {  RadioCanada.Lib.jQuery(this).colorbox({className: \'regionalisation\', fixed: true, width: \'720px\', height: \'398px\', iframe: true, title: false, close: \'Fermer\', fastIframe: false}); return false; }">[Changer]</a>';
            }
            else {
                l_leftonechannel += '<a href="' + this.url4RegionalizationPopup.replace("?d=domain", "").replace("#tab", l_tab) + '" id="channel_' + pChannel.Id + '_chooseregion"';
                l_leftonechannel += ' title="Choisir une nouvelle région" onclick="' + this._statstags(l_statsclick, l_statsclick, true) + ' if (typeof( RadioCanada.Lib.jQuery.colorbox) != \'undefined\') {  RadioCanada.Lib.jQuery(this).colorbox({className: \'regionalisation\', fixed: true, width: \'720px\', height: \'398px\', iframe: true, title: false, close: \'Fermer\', fastIframe: false}); return false; }">[Changer]</a>';
            }

            l_leftonechannel += '</div>';
        }
        else {
            l_leftonechannel += '<span class="edition-nationale">Édition nationale seulement</span>';
        }

        l_leftonechannel += '</li>';

        return l_leftonechannel;
    },

    _display_label_onehour: function (pPreviousDate, pLabelDate, pCurrentDate, pPositionCurrent, pLast) {
        var l_onehour = '';

        if (!pLast) {
            l_onehour += '<li class="hour">';
            l_onehour += pLabelDate.getHours() + ' h ' + this._formatNumber(pLabelDate.getMinutes());
            l_onehour += '</li>';
        }

        return l_onehour;
    },

    _display_broadcast_onechannel: function (pChannelInBroadcast, pCurrentDate, pChannel) {
        var l_html = '';
        var l_counter = 1;
        l_html += '<ul id="broadcasts4channel_' + pChannelInBroadcast["ID"] + '" class="emissions channel-' + pChannelInBroadcast["ID"] + '">';

        var onebroadcast = "";
        for (var onebroadcastkey in pChannelInBroadcast) {
            if (onebroadcastkey != "ID") {
                onebroadcast += this._display_broadcast_onebroadcast(pChannelInBroadcast[onebroadcastkey], pCurrentDate, pChannel, l_counter);
                l_counter++;
            }
        }

        // Falloff si il n'y a pas de données onebroadcastkey dans le broadcast 
        if (onebroadcast == "") {
            if (g_counter % 2 == 0) {
                onebroadcast = "<li class=\"length-90\" style=\"width:720px; line-height:30px;\"><span class=\"left\"><span class=\"right\">Ce guide horaire n'est pas disponible pour le moment</span></span></li>";
            } else {
                onebroadcast = "<li class=\"length-90\" style=\"width:720px; line-height:30px;\"><span class=\"left\"><span class=\"right\">Ce guide horaire n'est pas disponible pour le moment</span></span></li>";
            }
            g_counter++;
        }

        l_html += onebroadcast

        l_html += '</ul>';

        return l_html;
    },

    _display_broadcast_onechannel_empty: function (pChannel) {
        var l_html = '';

        l_html += '<ul id="broadcasts4channel_' + pChannel.Id + '" class="emissions channel-' + pChannel.Id + '">';
        l_html += '<li class="signoff length-180">&nbsp;</li>';
        l_html += '</ul>';

        return l_html;
    },

    _display_currentbroadcast: function (pChannelInBroadcast, pCurrentDate, pChannel, pMini) {
        var l_html = '';
        var l_currentfeed = '';

        if (pMini == null)
            pMini = false;

        var l_label_stats = this._getLabel4Stats(pChannel, pMini);
        var l_HasPlayButton = false;
        var l_displayTitle = '';

        if (pMini == null)
            pMini = false;

        for (var onebroadcastkey in pChannelInBroadcast) {
            if (onebroadcastkey != "ID") {
                var pBroadcast = pChannelInBroadcast[onebroadcastkey];
                var l_pageUrl = pBroadcast.PageUrl;

                var l_tempDate = pBroadcast.StartDateStr.split("-");
                var l_tempTime = pBroadcast.StartHours.split(":");
                var l_broadcastStart = new Date(parseInt(l_tempDate[0], 10), parseInt(l_tempDate[1], 10) - 1, parseInt(l_tempDate[2], 10), parseInt(l_tempTime[0], 10), parseInt(l_tempTime[1], 10), 0);

                l_tempDate = pBroadcast.EndDateStr.split("-");
                l_tempTime = pBroadcast.EndHours.split(":");
                var l_broadcastEnd = new Date(parseInt(l_tempDate[0], 10), parseInt(l_tempDate[1], 10) - 1, parseInt(l_tempDate[2], 10), parseInt(l_tempTime[0], 10), parseInt(l_tempTime[1], 10), 0);

                var l_localCurrent = new Date(this.currentdate.getFullYear(), this.currentdate.getMonth(), this.currentdate.getDate(), this.currentdate.getHours(), this.currentdate.getMinutes(), this.currentdate.getSeconds());

                var timezoneInMinutes = this.currentoffset * 60;
                var channeltimezoneInMinutes = (pChannel.Region.HoursDelay + this.montrealoffset) * 60;
                if (timezoneInMinutes != channeltimezoneInMinutes) {
                    delta = channeltimezoneInMinutes - timezoneInMinutes;
                    l_localCurrent.setTime(pCurrentDate.getTime() + delta * 60 * 1000);
                }

                if (l_broadcastStart <= l_localCurrent && l_localCurrent <= l_broadcastEnd) {
                    var l_key = (pChannel.IsTV) ? "tv_" + pBroadcast.BroadcastID : (pChannel.Name == "Espace musique") ? "em_" + pBroadcast.BroadcastID : "radio_" + pBroadcast.BroadcastID;

                    if (typeof (this.currentfeeds[l_key]) != "undefined") {
                        var l_action = ''
                        if (pChannel.IsTV) {
                            l_action = "Regarder en ligne ";
                        }
                        if (pChannel.IsRadio) {
                            l_action = "Écouter en ligne ";
                        }

                        // Pour le lancement du nouveau mag télé
                        // seul le live pour la région Montréal est disponible pour l'instant
                        // A modifier lorsque le live sera disponible dans d'autres régions
                        if (pChannel.Key == 'premierechaine' && pChannel.IsTV && pChannel.Id == 1 && RadioCanada._loadLiveInMagTele) {
                            l_currentfeed = '<a class="link-news" href="' + RadioCanada.getBaseUrl() + '/tele/?autoPlay=1" onclick="' + this._statstags(l_label_stats + ' Play', pBroadcast.Title, false) + ';" title="' + l_action + pBroadcast.Title + '"><span class="play xx-small"></span></a>';
                        }
                        else {
                            l_currentfeed = '<a class="link-news" href="http://' + 'www.radio-canada.ca/audio-video/pop.shtml#urlMedia=' + this.currentfeeds[l_key] + '"  onclick="' + this._statstags(l_label_stats + ' Play', pBroadcast.Title, false) + this._consolePopup(this.currentfeeds[l_key]) + 'return false;" title="' + l_action + pBroadcast.Title + '"><span class="play xx-small"></span></a>';
                        }
                        l_HasPlayButton = true;
                    }

                    l_displayTitle = this._ellipsis(pBroadcast.Title, 50, ' ');

                    l_html = '<li class="emission">';
                    l_html += l_currentfeed;
                    var l_onclick = "";

                    if (l_pageUrl != undefined && l_pageUrl != null && l_pageUrl != "" && pBroadcast.Title != 'Fin des émissions') {
                        var extensionRegex = /.+\.([^?]+)(\?|$)/;
                        var extension = l_pageUrl.match(extensionRegex);
                        if (extension && extension.length > 1 && extension[1] == 'asx') {
                            l_onclick = this._consolePopup(l_pageUrl) + "return false";
                            l_pageUrl = "http://" + "www.radio-canada.ca/audio-video/pop.shtml#urlMedia=" + l_pageUrl;
                        }
                    }

                    if (l_pageUrl != undefined && l_pageUrl != null && l_pageUrl != "" && pBroadcast.Title != 'Fin des émissions') {
                        l_html += '<a href="' + RadioCanada.buildLink(l_pageUrl) + '" onclick="' + this._statstags(l_label_stats, pBroadcast.Title, false) + l_onclick + '" title="' + pBroadcast.Title + ' : ' + pBroadcast.Description + ' [ ' + pBroadcast.StartHours.replace(":", " h ") + ' - ' + pBroadcast.EndHours.replace(":", " h ") + ' ] ' + '"' +
                                  ((l_displayTitle.ellipsize) ? ' desc="' + pBroadcast.Title + '"' : '') +
                                  '>' +
                                  l_displayTitle.title +
                                  '</a>';
                    }
                    else {
                        l_html += '<span title="' + pBroadcast.Title + ' : ' + pBroadcast.Description + ' [ ' + pBroadcast.StartHours.replace(":", " h ") + ' - ' + pBroadcast.EndHours.replace(":", " h ") + ' ] ' + '">' +
                                  l_displayTitle.title +
                                  '</span>';
                    }

                    l_html += '</li>';
                }
            }
        }

        return l_html;
    },

    _display_broadcast_onebroadcast: function (pBroadcast, pCurrentDate, pChannel, pCounter) {
        var l_html4broadcast = '';
        var l_currentclass = '';
        var l_currentfeed = '';
        var l_onclick = '';
        var l_label_stats = this._getLabel4Stats(pChannel, false);
        var l_playUrl = null;
        var HasPlayButton = false;
        var l_pageUrl = pBroadcast.PageUrl;

        var l_tempDate = pBroadcast.StartDateStr.split("-");
        var l_tempTime = pBroadcast.StartHours.split(":");
        var l_broadcastStart = new Date(parseInt(l_tempDate[0], 10), parseInt(l_tempDate[1], 10) - 1, parseInt(l_tempDate[2], 10), parseInt(l_tempTime[0], 10), parseInt(l_tempTime[1], 10), 0);

        l_tempDate = pBroadcast.EndDateStr.split("-");
        l_tempTime = pBroadcast.EndHours.split(":");
        var l_broadcastEnd = new Date(parseInt(l_tempDate[0], 10), parseInt(l_tempDate[1], 10) - 1, parseInt(l_tempDate[2], 10), parseInt(l_tempTime[0], 10), parseInt(l_tempTime[1], 10), 0);

        var l_localCurrent = new Date(this.currentdate.getFullYear(), this.currentdate.getMonth(), this.currentdate.getDate(), this.currentdate.getHours(), this.currentdate.getMinutes(), this.currentdate.getSeconds());

        var timezoneInMinutes = this.currentoffset * 60;
        var channeltimezoneInMinutes = (pChannel.Region.HoursDelay + this.montrealoffset) * 60;
        if (timezoneInMinutes != channeltimezoneInMinutes) {
            var delta = channeltimezoneInMinutes - timezoneInMinutes;
            l_localCurrent.setTime(pCurrentDate.getTime() + delta * 60 * 1000);
        }

        if (l_broadcastStart <= l_localCurrent && l_localCurrent <= l_broadcastEnd) {
            l_currentclass = 'current';
            var l_key = (pChannel.IsTV) ? "tv_" + pBroadcast.BroadcastID : (pChannel.Name == "Espace musique") ? "em_" + pBroadcast.BroadcastID : "radio_" + pBroadcast.BroadcastID;

            l_playUrl = this.currentfeeds[l_key];
        }

        if (l_pageUrl != undefined && l_pageUrl != null && l_pageUrl != "" && pBroadcast.Title != 'Fin des émissions') {
            var extensionRegex = /.+\.([^?]+)(\?|$)/;
            var extension = l_pageUrl.match(extensionRegex);
            if (extension && extension.length > 1 && extension[1] == 'asx') {
                l_onclick = this._consolePopup(l_pageUrl) + "return false";
                l_pageUrl = "http://" + "www.radio-canada.ca/audio-video/pop.shtml#urlMedia=" + l_pageUrl;
            }
        }

        if (typeof (l_playUrl) != 'undefined' && l_playUrl != null && l_playUrl != "") {
            var l_action = ''
            if (pChannel.IsTV) {
                l_action = "Regarder en ligne ";
            }
            if (pChannel.IsRadio) {
                l_action = "Écouter en ligne ";
            }
            if (pChannel.Key == 'premierechaine' && pChannel.IsTV && pChannel.Id == 1 && RadioCanada._loadLiveInMagTele) {
                l_currentfeed = '<a class="link-news" href="' + RadioCanada.getBaseUrl() + '/tele/?autoPlay=1" onclick="' + this._statstags(l_label_stats + ' Play', pBroadcast.Title, false) + ';" title="' + l_action + pBroadcast.Title + '"><span class="play xx-small"></span></a>';
            }
            else {
                l_currentfeed = '<a class="link-news" href="http://' + 'www.radio-canada.ca/audio-video/pop.shtml#urlMedia=' + this.currentfeeds[l_key] + '"  onclick="' + this._statstags(l_label_stats + ' Play', pBroadcast.Title, false) + this._consolePopup(this.currentfeeds[l_key]) + 'return false;" title="' + l_action + pBroadcast.Title + '"><span class="play xx-small"></span></a>';
            }
            HasPlayButton = true;
        }

        var l_displayTitle = this._ellipsis(pBroadcast.Title, this._getNbMaxCharacters(pBroadcast.RemainingTimeInMinutes, HasPlayButton), ' ');

        if (pBroadcast.Title == 'Fin des émissions') {
            l_html4broadcast += '<li class="signoff ' + l_currentclass + '" style="width: ' + (pBroadcast.RemainingTimeInMinutes * 4) + 'px" title="' + pBroadcast.Title + ' [' + pBroadcast.StartHours.replace(":", " h ") + ' - ' + pBroadcast.EndHours.replace(":", " h ") + ']">';
        }
        else {
            l_html4broadcast += '<li class="length-' + pBroadcast.RemainingTimeInMinutes + ' ' + l_currentclass + '" title="' + pBroadcast.StartHours.replace(":", " h ") + ' - ' + pBroadcast.EndHours.replace(":", " h ") + '">';
        }

        if (l_pageUrl != undefined && l_pageUrl != null && l_pageUrl != "" && pBroadcast.Title != 'Fin des émissions') {
            l_html4broadcast += '<span class="left"><span class="right">' +
                                l_currentfeed +
                                '<a href="' + l_pageUrl + '" onclick="' + this._statstags(l_label_stats + ' ' + pCounter, pBroadcast.Title, false) + l_onclick + '" title="' + pBroadcast.Title + ' : ' + pBroadcast.Description + ' [ ' + pBroadcast.StartHours.replace(":", " h ") + ' - ' + pBroadcast.EndHours.replace(":", " h ") + ' ] ' + '"' +
                                ((l_displayTitle.ellipsize) ? ' desc="' + pBroadcast.Title + '"' : '') +
                                '>' +
                                l_displayTitle.title +
                                '</a></span></span>';
        }
        else {
            l_html4broadcast += '<span class="left"><span title="' + pBroadcast.Title + ' : ' + pBroadcast.Description + ' [ ' + pBroadcast.StartHours.replace(":", " h ") + ' - ' + pBroadcast.EndHours.replace(":", " h ") + ' ] ' + '"' +
                                ((l_displayTitle.ellipsize) ? ' class="right" desc="' + pBroadcast.Title + '"' : ' class="right"') +
                                '>' +
                                l_currentfeed +
                                l_displayTitle.title +
                                '</span></span>';
        }

        return l_html4broadcast;
    },

    _display_column_right_onechannel: function (pChannel, pCounter, pIsMini) {
        var l_rightonechannel = '';
        var l_classname = 'onechannel';
        var l_urlemissions = '';
        var l_urlgrillehoraire = '';
        var l_label4Stats = this._getLabel4Stats(pChannel, pIsMini);
        var l_href = '';
        var l_title = '';
        var l_statsclicklogo = '';
        var l_statsclick = '';
        var l_tooltipEmissions = '';
        var l_labelEmission = '';
        var l_label4Stats = '';
        var l_tooltipGuideHoraire = '';

        if (pChannel.Key == 'premierechaine' && pChannel.IsTV) {
            l_classname = 'channel-tele';

            l_urlemissions = RadioCanada.buildLink(RadioCanada.getBaseUrl() + "/tele/emissions/");
            l_urlgrillehoraire = RadioCanada.buildLink(RadioCanada.getBaseUrl() + "/tele/guide-horaire/");
            l_href = RadioCanada.buildLink(RadioCanada.getBaseUrl() + "/tele/");

            l_title = pChannel.Name + ' Télévision';

            if (pIsMini) {
                l_statsclick = 'Mini_GH_Tele_TVG_ChangerBloc';
                l_statsclicklogo = 'Mini_GH_Tele_TVG_Logo';
                l_label4Stats = 'Mini_GH_Tele_TVG_page_';
            } else {
                l_statsclick = 'GH_Tele_TVG_ChangerBloc';
                l_statsclicklogo = 'GH_Tele_TVG_Logo';
                l_label4Stats = 'GH_Tele_TVG_page_';
            }

            l_tooltipEmissions = 'Consulter les émissions de la ' + l_title;
            l_labelEmission = 'Emissions';

            l_tooltipGuideHoraire = 'Consulter le guide horaire de la ' + l_title;
        }
        if (pChannel.Key == 'rdi') {
            l_classname = 'channel-rdi';
            l_urlemissions = RadioCanada.buildLink("http://www.radio-canada.ca/rdi/emissions.shtml");
            l_urlgrillehoraire = RadioCanada.buildLink("http://www.radio-canada.ca/rdi/ghHoraires.asp");
            l_href = RadioCanada.buildLink("http://www.radio-canada.ca/rdi");
            l_title = pChannel.Name;

            l_tooltipEmissions = 'Consulter les émissions de ' + l_title;
            l_labelEmission = 'Emissions';

            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Tele_RDI_Logo';
                l_label4Stats = 'Mini_GH_Tele_RDI_page_';
            } else {
                l_statsclicklogo = 'GH_Tele_RDI_Logo';
                l_label4Stats = 'GH_Tele_RDI_page_';
            }

            l_tooltipGuideHoraire = 'Consulter le guide horaire de ' + l_title;
        }
        if (pChannel.Key == 'artv') {
            l_classname = 'channel-artv';
            l_urlemissions = RadioCanada.buildLink("http://artv.ca/emissions/");
            l_urlgrillehoraire = RadioCanada.buildLink("http://artv.ca/horaire/");
            l_href = RadioCanada.buildLink("http://artv.ca");
            l_title = 'ARTV';

            l_tooltipEmissions = 'Consulter les émissions d\'' + l_title;
            l_labelEmission = 'Emissions';

            if (pIsMini) {
                l_statsclicklogo = 'Mini_GH_Tele_ARTV_Logo';
                l_label4Stats = 'Mini_GH_Tele_ARTV_page_';
            } else {
                l_statsclicklogo = 'GH_Tele_ARTV_Logo';
                l_label4Stats = 'GH_Tele_ARTV_page_';
            }

            l_tooltipGuideHoraire = 'Consulter le guide horaire d\'' + l_title;
        }
        if (pChannel.Key == 'premierechaine' && pChannel.IsRadio) {
            l_classname = 'channel-radio';
            l_urlemissions = RadioCanada.buildLink("http://www.radio-canada.ca/radio/emissions/index.asp");
            l_urlgrillehoraire = RadioCanada.buildLink("http://www.radio-canada.ca/radio/horaire/ghHoraires.asp?ghRegions=" + pChannel.Region.Id);
            l_href = RadioCanada.buildLink("http://www.radio-canada.ca/radio");
            l_title = pChannel.Name + '_Radio';

            l_tooltipEmissions = 'Consulter les émissions de la ' + l_title;
            l_labelEmission = 'Emissions';

            if (pIsMini) {
                l_label4Stats = 'Mini_GH_Radio_PC_page_';
                l_statsclicklogo = 'Mini_GH_Radio_PC_Logo';
                l_statsclick = 'Mini_GH_Radio_PC_ChangerBloc';
            } else {
                l_label4Stats = 'GH_Radio_PC_page_';
                l_statsclicklogo = 'GH_Radio_PC_Logo';
                l_statsclick = 'GH_Radio_PC_ChangerBloc';
            }

            l_tooltipGuideHoraire = 'Consulter le guide horaire de la ' + l_title;
        }
        if (pChannel.Key == 'espacemusique') {
            l_classname = 'channel-espace';
            l_urlemissions = RadioCanada.buildLink("http://www.radio-canada.ca/espace_musique/listeAnimateurs.asp");
            l_urlgrillehoraire = RadioCanada.buildLink("http://www.radio-canada.ca/espace_musique/ghHoraires.asp?r=" + this._selectRegion4EM(pChannel.Region.Id));
            l_href = RadioCanada.buildLink("http://www.radio-canada.ca/espace_musique");
            l_title = pChannel.Name;

            l_tooltipEmissions = 'Consulter les animateurs d\'' + l_title;
            l_labelEmission = 'Animateurs';

            if (pIsMini) {
                l_label4Stats = 'Mini_GH_Radio_EM_page_';
                l_statsclicklogo = 'Mini_GH_Radio_EM_Logo';
                l_statsclick = 'Mini_GH_Radio_EM_ChangerBloc';
            } else {
                l_label4Stats = 'GH_Radio_EM_page_';
                l_statsclicklogo = 'GH_Radio_EM_Logo';
                l_statsclick = 'GH_Radio_EM_ChangerBloc';
            }

            l_tooltipGuideHoraire = 'Consulter le guide horaire d\'' + l_title;
        }
        if (pChannel.Name == 'RCI' && pChannel.IsRadio) {
            l_classname = 'channel-rci';
            l_urlemissions = RadioCanada.buildLink("http://www.rcinet.ca/francais/emission/tam-tam-canada/accueil/");
            l_urlgrillehoraire = RadioCanada.buildLink("http://www.rcinet.ca/francais/horaire/");
            l_href = RadioCanada.buildLink("http://www.rcinet.ca/francais");
            l_title = 'RCI';
            l_tooltipEmissions = 'Consulter les émissions de ' + l_title;
            l_labelEmission = 'Emissions';

            if (pIsMini) {
                l_label4Stats = 'Mini_GH_Radio_RCI_page_';
                l_statsclick = 'Mini_GH_Radio_RCI_ChangerBloc';
                l_statsclicklogo = 'Mini_GH_Radio_RCI_Logo';
            } else {
                l_label4Stats = 'GH_Radio_RCI_page_';
                l_statsclick = 'GH_Radio_RCI_ChangerBloc';
                l_statsclicklogo = 'GH_Radio_RCI_Logo';
            }

            l_tooltipGuideHoraire = 'Consulter le guide horaire de ' + l_title;
        }

        if (pIsMini) {
            l_rightonechannel += '<li>';
            l_rightonechannel += '<a href="' + l_href + '" title="' + l_title + '" onclick="' + this._statstags(l_statsclicklogo, l_statsclicklogo, true) + '">Accueil</a>';
            l_rightonechannel += '</li>';
            l_rightonechannel += '<li>';
            l_rightonechannel += '<a href="' + l_urlemissions + '" title="' + l_tooltipEmissions + '" onclick="' + this._statstags(l_label4Stats + l_labelEmission, l_label4Stats + l_labelEmission, true) + '">' + l_labelEmission + '</a>';
            l_rightonechannel += '</li>';
            l_rightonechannel += '<li>';
            l_rightonechannel += '<a href="' + l_urlgrillehoraire + '" title="' + l_tooltipGuideHoraire + '" onclick="' + this._statstags(l_label4Stats + '_Guide_horaire', l_label4Stats + '_Guide_horaire', true) + '">Guide horaire</a>';
            l_rightonechannel += '</li>';
        }
        else {
            l_rightonechannel += '<li class="' + l_classname + ((pCounter % 2 == 0) ? ' even' : ' odd') + '">';
            l_rightonechannel += '</li>';
        }

        return l_rightonechannel;
    },

    _getNbMaxCharacters: function (pRemainingTimeInMinute, HasPlayButton) {
        if (pRemainingTimeInMinute <= 6) {
            return 1;
        }
        else {
            if (HasPlayButton) {
                return (Math.floor(13 * pRemainingTimeInMinute / 15) - 19);
            }
            else {
                return Math.floor(13 * pRemainingTimeInMinute / 15);
            }
        }
    },

    _ellipsis: function (pStr, nbcharmax, separator) {
        var maxAllowedLetterIndex = 0;
        if (nbcharmax != null) {
            maxAllowedLetterIndex = pStr.length - nbcharmax;
        }
        else {
            nbcharmax = pStr.split(separator)[0].length;
            maxAllowedLetterIndex = pStr.length - nbcharmax;
        }

        var l_out = { title: '', ellipsize: false };

        if (maxAllowedLetterIndex > 0) {
            var words = pStr.split(separator);
            var l_counterword = 0;
            var l_stop = false;
            l_out.ellipsize = true;

            while (l_counterword < words.length && l_out.title.length < nbcharmax && !l_stop) {
                if (words[l_counterword].length + l_out.title.length + 1 < nbcharmax) {
                    if (l_out.title.length > 0)
                        l_out.title += ' ';

                    l_out.title += words[l_counterword];

                    l_counterword++;
                }
                else {
                    l_stop = true;
                }
            }
            l_out.title += "&hellip;";
        }
        else {
            l_out.title = pStr;
            l_out.ellipsize = false;
        }

        return l_out;
    },

    _formatDate: function (strformat, pDate) {
        var l_year = pDate.getFullYear();
        var l_month = this._formatNumber(eval(pDate.getMonth() + ' + 1'));
        var l_day = this._formatNumber(pDate.getDate());
        var l_hours = this._formatNumber(pDate.getHours());
        var l_minutes = this._formatNumber(pDate.getMinutes());
        var l_seconds = this._formatNumber(pDate.getSeconds());

        strformat = strformat.replace("yyyy", l_year);
        strformat = strformat.replace("MM", l_month);
        strformat = strformat.replace("dd", l_day);
        strformat = strformat.replace("HH", l_hours);
        strformat = strformat.replace("mm", l_minutes);
        strformat = strformat.replace("ss", l_seconds);

        return strformat;
    },

    _formatNumber: function (pNumber) {
        if (pNumber < 10)
            return '0' + pNumber;
        else
            return pNumber;
    },

    _selectRegion4EM: function (pRegionId) {
        switch (pRegionId) {
            case 32:
                return 1;
                break;
            case 33:
                return 12;
                break;
            case 22:
                return 10;
                break;
            case 21:
                return 11;
                break;
            case 24:
                return 2;
                break;
            case 11:
                return 14;
                break;
            case 17:
                return 9;
                break;
            case 12:
                return 15;
                break;
            case 1:
                return 5;
                break;
            case 16:
                return 6;
                break;
            case 10:
                return 4;
                break;
            case 9:
                return 3;
                break;
            case 18:
                return 16;
                break;
            case 13:
                return 8;
                break;
            case 34:
                return 17;
                break;
            case 14:
                return 7;
                break;
            case 15:
                return 18;
                break;
            default:
                return 5;
                break;
        }
    },

    _afficherToolTip: function (obj, desc) {
        var curleft = 0;
        var curtop = 0;
        RadioCanada.Lib.jQuery("div#tooltip-guide").empty().append(desc);
        curleft = RadioCanada.Lib.jQuery(obj).closest("li").position().left + 180;
        curtop = RadioCanada.Lib.jQuery(obj).closest("li").position().top;
        RadioCanada.Lib.jQuery("div#tooltip-guide").css("left", curleft);
        RadioCanada.Lib.jQuery("div#tooltip-guide").css("top", curtop);
        RadioCanada.Lib.jQuery("div#tooltip-guide").fadeIn();
    },

    _cacherToolTip: function (obj) {
        RadioCanada.Lib.jQuery("div#tooltip-guide").fadeOut();
    },

    _consolePopup: function (pUrl) {
        return "window.open('http://www.radio-canada.ca/audio-video/pop.shtml#urlMedia=" + pUrl + "', 'audioVideo', 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');";
    },

    _statstags: function (pClicAction, pClicContenu, pSimple) {
        return "statsToClics('clic_action', '" + this._replaceQuote(pClicAction) + "', 'clic_contenu', '" + this._replaceQuote(pClicContenu) + "', 'WT.ti', '" + ((pSimple) ? this._replaceQuote(pClicAction) : this._replaceQuote(pClicAction) + " _ " + this._replaceQuote(pClicContenu)) + "');";
    },

    _replaceQuote: function (pStr) {
        return pStr.replace("'", "\\'");
    },

    _popRciConsole: function (lang, type, media, episode_id) {
        var rciconsole_left = (screen.availWidth - 800) / 2;
        var rciconsole_top = (screen.availHeight - 490) / 2;

        if (media == "video") {
            return "window.open('http://www.rcinet.ca/radio/video.php?language=" + lang + "&type=" + type + "&media=" + media + "&id=" + episode_id + "', 'rci_console', 'resizable=no,location=no,status=no,scrollbars=no,width=800,height=490,top=" + rciconsole_top + ",left=" + rciconsole_left + "');";
        } else {
            return "window.open('http://www.rcinet.ca/radio/index.php?language=" + lang + "&type=" + type + "&media=" + media + "&id=" + episode_id + "', 'rci_console', 'resizable=no,location=no,status=no,scrollbars=no,width=800,height=490,top=" + rciconsole_top + ",left=" + rciconsole_left + "');";
        }
    }
};

if (typeof (RadioCanada.Mod.oGuideHoraire) == 'undefined') {
    RadioCanada.Mod.oGuideHoraire = new GuideHoraireFactory();
}

