﻿//var addthis_localize = { share_caption: "Partager cette vidéo", more: "Plus..." };
var addthis_pub = "filigranes";
//var addthis_language = "fr";

function VideoDetail(divID) {
    this.DivID = divID;
    this.RootUrl = 'http://www.filigranes.be/';
    this.wymEditor;

    var header = document.getElementsByTagName("head")[0];
    if (header) {
        var scripts = header.getElementsByTagName("script");
        var links = header.getElementsByTagName("link");
        var isScriptAlreadyExists = false;
        var isCommonAlreadyExist = false;
        for (var i = 0; i < scripts.length; i++) {
            var script = scripts[i];
            if (script.src.indexOf('date.js') > 0) {
                isScriptAlreadyExists = true;
            }
            if (script.src.indexOf('common.js') > 0) {
                isCommonAlreadyExist = true;
            }

            if (isCommonAlreadyExist == true && isScriptAlreadyExists == true) {
                break;
            }
        }
        if (isScriptAlreadyExists == false) {
            var newScript = document.createElement('script');
            newScript.type = 'text/javascript';
            newScript.src = this.RootUrl + "js/methods/date.js";
            header.appendChild(newScript);
        }
        if (isCommonAlreadyExist == false) {
            var newScript = document.createElement('script');
            newScript.type = 'text/javascript';
            newScript.src = this.RootUrl + "js/methods/common.js";
            header.appendChild(newScript);
        }
    }
    this.VideoID = GetParam('clip');    
}

GetVideoDetail = function(videoDetail) {
    if (videoDetail.VideoID && videoDetail.VideoID != '') {
        if (videoDetail.DivID && document.getElementById(videoDetail.DivID)) {
            imgLoad = document.createElement('div');
            imgLoad.id = 'loading_' + videoDetail.DivID;
            imgLoad.className = 'ImageLoading';
            document.getElementById(videoDetail.DivID).appendChild(imgLoad);
        }

        var header = document.getElementsByTagName("head")[0];
        if (header) {
            var scripts = header.getElementsByTagName("script");
            var isScriptAlreadyExists = false;
            for (var i = 0; i < scripts.length; i++) {
                var script = scripts[i];
                //
                //if (script.src == 'http://w.sharethis.com/button/sharethis.js#publisher=4d0663f5-00f7-414e-9bfa-d3d2381d905d&amp;type=website&amp;buttonText=Partager cet événement&amp;embeds=true&amp;style=rotate&amp;post_services=facebook%2Cdigg%2Cdelicious%2Cybuzz%2Ctwitter%2Cstumbleupon%2Creddit%2Ctechnorati%2Cmixx%2Cblogger%2Ctypepad%2Cwordpress%2Cgoogle_bmarks%2Cwindows_live%2Cmyspace%2Cfark%2Cbus_exchange%2Cpropeller%2Cnewsvine%2Clinkedin') {
                if (script.src == 'http://s7.addthis.com/js/200/addthis_widget.js') {
                    isScriptAlreadyExists = true;
                    break;
                }
            }

            if (isScriptAlreadyExists == false) {
                var newScript = document.createElement('script');
                newScript.type = 'text/javascript';
                newScript.src = 'http://s7.addthis.com/js/200/addthis_widget.js';
                header.appendChild(newScript);
            }
            var scripts = header.getElementsByTagName("script");
            var links = header.getElementsByTagName("link");
            var isScriptAlreadyExists = false;
            var isCSSAlreadyExists = false;
            for (var i = 0; i < scripts.length; i++) {
                var script = scripts[i];
                if (script.src.indexOf('rating.js') > 0) {
                    isScriptAlreadyExists = true;
                    break;
                }
            }
            for (var i = 0; i < links.length; i++) {
                var link = links[i];
                if (link.href.indexOf('rating.css') > 0) {
                    isCSSAlreadyExists = true;
                    break;
                }
            }
            if (isScriptAlreadyExists == false) {
                var newScript = document.createElement('script');
                newScript.type = 'text/javascript';
                newScript.src = videoDetail.RootUrl + "js/rating.js";
                header.appendChild(newScript);
            }
            if (isCSSAlreadyExists == false) {
                var newLink = document.createElement('link');
                newLink.type = 'text/css';
                newLink.href = videoDetail.RootUrl + 'css/rating.css';
                newLink.rel = 'stylesheet';
                header.appendChild(newLink);
            }
        }

        new Ajax.Request(videoDetail.RootUrl + 'VimeoWidget.ashx',
         {
             method: 'get',
             onSuccess: function(transport) { videoDetail.OnGetVideoDetailData(transport); },
             onFailure: function() {
                 videoDetail.OnGetVideoDetailData();
             },
             parameters:
            {
                'ms': new Date().getTime(),
                'ID': videoDetail.VideoID,
                'type': 'detail'
            }
         });
    }
}

VideoDetail.prototype.OnGetVideoDetailData = function(transport) {

    var videoDetailTmp = this;
    if (transport && transport.responseXML) {

        var clipNodes = transport.responseXML.getElementsByTagName('video');
        if (clipNodes && clipNodes.length) {
            var clipNode = clipNodes[0];
            var clipID = "";
            if (clipNode.getElementsByTagName("id") &&
                                                        clipNode.getElementsByTagName("id").length > 0 &&
                                                        clipNode.getElementsByTagName("id")[0].firstChild) {
                clipID = clipNode.getElementsByTagName("id")[0].firstChild.nodeValue;
            }

            var titleVideo = "";
            if (clipNode.getElementsByTagName("title") &&
                                                        clipNode.getElementsByTagName("title").length > 0 &&
                                                        clipNode.getElementsByTagName("title")[0].firstChild) {
                titleVideo = clipNode.getElementsByTagName("title")[0].firstChild.nodeValue;
            }

            var url = "";
            if (clipNode.getElementsByTagName("url") &&
                                                        clipNode.getElementsByTagName("url").length > 0 &&
                                                        clipNode.getElementsByTagName("url")[0].firstChild) {
                url = clipNode.getElementsByTagName("url")[0].firstChild.nodeValue;
            }

            var description = '';
            if (clipNode.getElementsByTagName("description") &&
                                                        clipNode.getElementsByTagName("description").length > 0 &&
                                                        clipNode.getElementsByTagName("description")[0].firstChild) {
                description = clipNode.getElementsByTagName("description")[0].firstChild.nodeValue;
            }

            var width = '650';
            if (clipNode.getElementsByTagName("width") &&
                                                        clipNode.getElementsByTagName("width").length > 0 &&
                                                        clipNode.getElementsByTagName("width")[0].firstChild) {
                var newWidth = clipNode.getElementsByTagName("width")[0].firstChild.nodeValue;
                if ( parseInt(newWidth) < parseInt(width))
                	width = newWidth;
            }
            var tags = '';
            if (clipNode.getElementsByTagName("tags") &&
                                                        clipNode.getElementsByTagName("tags").length > 0 &&
                                                        clipNode.getElementsByTagName("tags")[0].firstChild) {
                tags = clipNode.getElementsByTagName("tags")[0].firstChild.nodeValue;
            }

            var arEans = new Array();

            var arTags = tags.toLowerCase().split(',');
            for (var i = 0; i < arTags.length; i++) {
                if (arTags[i].indexOf('ean=') >= 0) {
                    arEans.push(arTags[i].substr(5, arTags[i].length - 5));
                }
                else if (arTags[i].indexOf('ean:') >= 0) {
                    arEans.push(arTags[i].substr(5, arTags[i].length - 5));
                }
                else if (arTags[i].indexOf('ean : ') >= 0) {
                    arEans.push(arTags[i].substr(7, arTags[i].length - 5));
                }
                else if (arTags[i].indexOf('ean = ') >= 0) {
                    arEans.push(arTags[i].substr(7, arTags[i].length - 5));
                }
            }

            document.title = titleVideo.replace(/filiGranes.tv,/i, '');
            if (document.getElementById(this.DivID)) {
                var videoDetailDiv = document.getElementById(this.DivID);

                divDetail = document.createElement('div');

                divBooks = document.createElement('div');
                divBooks.id = 'DivBooks';
                booksTitle = document.createElement('h1');
                booksTitle.innerHTML = 'Les livres liés à cette vidéo !';
                divBooks.appendChild(booksTitle);
                imgLoadBooks = document.createElement('div');
                imgLoadBooks.id = 'loading_' + videoDetailTmp.DivID + '_Books';
                imgLoadBooks.className = 'ImageLoading';
                divBooks.appendChild(imgLoadBooks);


                divFiligranautesComment = document.createElement('div');
                divFiligranautesComment.id = 'DivFiligranaute';
                filigranautesCommentTitle = document.createElement('h1');
                filigranautesCommentTitle.appendChild(document.createTextNode('Les avis des filigranautes !'));
                divFiligranautesComment.appendChild(filigranautesCommentTitle);
                imgLoadFiligranaute = document.createElement('div');
                imgLoadFiligranaute.id = 'loading_' + videoDetailTmp.DivID + '_Filigranaute';
                imgLoadFiligranaute.className = 'ImageLoading';
                divFiligranautesComment.appendChild(imgLoadFiligranaute);

                divYourComment = document.createElement('div');
                divYourComment.id = 'DivYourComment';
                var divYourCommentArea = document.createElement('div');
                divYourCommentArea.id = 'DivYourCommentArea';
                yourCommentTitle = document.createElement('h1');
                yourCommentTitle.appendChild(document.createTextNode('Votre avis nous intéresse !'));
                divYourComment.appendChild(yourCommentTitle);
                divYourComment.appendChild(divYourCommentArea);

                var isLogged = false;
                if (GetCookie("Mail")) {
                    isLogged = true;
                    //<textarea id="txtShortDesc" rows="1"></textarea>
                    textArea = document.createElement('textarea');
                    textArea.id = "txtYourComment";
                    textArea.setAttribute('rows', '1');
                    divYourCommentArea.appendChild(textArea);
                    setTimeout(function() {
                        jQuery(function() {
                            jQuery('#txtYourComment').wymeditor({
                                toolsItems: [
                                { 'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong' },
                                { 'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis' },
                                { 'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list' },
                                { 'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list' },
                                { 'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent' },
                                { 'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent' },
                                { 'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link' },
                                { 'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink' }
                                ],

                                //we customize the XHTML structure of WYMeditor by overwriting 
                                //the value of boxHtml. In this example, "CONTAINERS" and 
                                //"CLASSES" have been moved from "wym_area_right" to "wym_area_top":
                                boxHtml: "<div class='wym_box'>"
                                  + "<div class='wym_area_top'>"
                                  + WYMeditor.TOOLS
                                  + "</div>"
                                  + "<div class='wym_area_left'></div>"
                                  + "<div class='wym_area_right'>"
                                  + "</div>"
                                  + "<div class='wym_area_main'>"
                                  + WYMeditor.HTML
                                  + WYMeditor.IFRAME
                                  + WYMeditor.STATUS
                                  + "</div>"
                                  + "<div class='wym_area_bottom'>"
                                  + "</div>"
                                  + "</div>",

                                postInit: function(wym) {
                                    videoDetailTmp.wymEditor = wym;
                                    //construct the button's html
                                    var html = "<li class='wym_tools_newbutton'>"
                                + "<a name='Save' href='#' alt='Envoyer'"
                                + " style='background-image:"
                                + " url(http://www.filigranes.be/Images/WymEditor/envoyer.gif);width:78px;'>"
                                 + "Sauvegarder votre commentaire"
                                + "</a></li>";

                                    //add the button to the tools box
                                    jQuery(wym._box)
                                .find(wym._options.toolsSelector + wym._options.toolsListSelector)
                                .append(html);

                                    //handle click event
                                    jQuery(wym._box)
                                .find('li.wym_tools_newbutton a').click(function() {
                                    videoDetailTmp.SaveComment();
                                    return (false);
                                });
                                }
                            });
                        });
                    }, 500);
                }
                else {
                    divYourCommentArea.appendChild(document.createTextNode('Veuillez vous connecter afin de saisir votre commentaire'));
                }

                var divHeader = document.createElement('div');
                divHeader.id = 'HeaderDetailTitle';
                var divHeaderText = document.createElement('div');
                divHeaderText.className = 'DivHeader';
                divHeaderText.appendChild(document.createTextNode(titleVideo.replace(/filiGranes.tv,/i, '')));
                divHeader.appendChild(divHeaderText);

                divDetail.appendChild(divHeader);

                divActions = document.createElement('div');
                divActions.id = 'Actions';
                divHeader.appendChild(divActions);

                aFavorite = document.createElement('a');
                aFavorite.setAttribute('href', '#VideoFavorite');
                imgFavorite = document.createElement('img');
                aFavorite.id = 'BookMark';
                imgFavorite.src = this.RootUrl + "Images/BookDetail/bookmark.png";
                imgFavorite.style.border = 'none';
                aFavorite.appendChild(imgFavorite);
                divActions.appendChild(aFavorite);

                var aAddThis = document.createElement('a');
                aAddThis.href = "";
                aAddThis.onmouseover = function() { return addthis_open(this, '', document.url, document.title); };
                aAddThis.onmouseout = function() { addthis_close(); };
                aAddThis.onclick = function() { return addthis_sendto(); };
                imgAddThis = document.createElement("img");
                imgAddThis.id = "imgAddthis";
                imgAddThis.src = "http://files.honet.be/wymstyle/sites/www-filigranes-be/partager.gif";
                imgAddThis.style.border = '0';
                aAddThis.appendChild(imgAddThis);
                divActions.appendChild(aAddThis);

                var divVideoClip = document.createElement('div');
                divVideoClip.id = 'clip_' + clipID;
                divVideoClip.className = 'DivVideo';
                var imgVideoLoad = document.createElement('div');
                imgVideoLoad.id = 'loading_' + videoDetail.DivID + '_clip';
                imgVideoLoad.className = 'ImageLoading';
                divVideoClip.appendChild(imgVideoLoad);
                divDetail.appendChild(divVideoClip);


                var spanRating = document.createElement('span');
                spanRating.appendChild(document.createTextNode('Vos votes : '));
                divDetail.appendChild(spanRating);

                divRating = document.createElement('div');
                divRating.id = 'ratingDetail' + clipID;
                divDetail.appendChild(divRating);
                var rating = new Rating('ratingDetail' + clipID, clipID, 'Video', 5, true, false);
                rating.Init();


                var divDescriptionClip = document.createElement('div');
                divDescriptionClip.innerHTML = description;
                //divDescriptionClip.appendChild(divDescriptionClip);
                divDetail.appendChild(divDescriptionClip);
                videoDetailDiv.appendChild(divDetail);
                if (arEans.length > 0) {
                    videoDetailDiv.appendChild(divBooks);
                }
                videoDetailDiv.appendChild(divFiligranautesComment);
                videoDetailDiv.appendChild(divYourComment);
                addBookmarkObj.convert('BookMark');

                videoDetailTmp.GetVideoVimeoData(clipID, width);

                videoDetailTmp.GetBookFiligranautesComment();
                videoDetailTmp.GetBooksTitle(arEans);
                if (isLogged == false) {
                    var divLogin = document.createElement('div');
                    divLogin.id = 'login_videodetail';
                    document.getElementById('DivYourCommentArea').appendChild(divLogin);
                    var loginModule = new Login('login_videodetail');
                    loginModule.Init();
                    loginModule.OnLoginSucceedEvent = OnLoginSucceedVideo;
                    loginModule.LoginParentModule = videoDetailTmp;
                }
            }

        }
    }

    if (this.DivID) {
        if (document.getElementById('loading_' + this.DivID)) {
            document.getElementById('loading_' + this.DivID).style.display = 'none';
        }
    }
}

OnLoginSucceedVideo = function(videoDetailTmp) {
    if (document.getElementById('DivYourCommentArea')) {
        //var videoDetailTmp = this;
        var divYourCommentArea = document.getElementById('DivYourCommentArea');
        if (GetCookie("Mail")) {


            while (divYourCommentArea.childNodes.length >= 1) {
                divYourCommentArea.removeChild(divYourCommentArea.firstChild);
            }


            isLogged = true;
            //<textarea id="txtShortDesc" rows="1"></textarea>
            textArea = document.createElement('textarea');
            textArea.id = "txtYourComment";
            textArea.setAttribute('rows', '1');
            divYourCommentArea.appendChild(textArea);
            setTimeout(function() {
                jQuery(function() {
                    jQuery('#txtYourComment').wymeditor({
                        toolsItems: [
                                { 'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong' },
                                { 'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis' },
                                { 'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list' },
                                { 'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list' },
                                { 'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent' },
                                { 'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent' },
                                { 'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link' },
                                { 'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink' }
                                ],

                        //we customize the XHTML structure of WYMeditor by overwriting 
                        //the value of boxHtml. In this example, "CONTAINERS" and 
                        //"CLASSES" have been moved from "wym_area_right" to "wym_area_top":
                        boxHtml: "<div class='wym_box'>"
                                  + "<div class='wym_area_top'>"
                                  + WYMeditor.TOOLS
                                  + "</div>"
                                  + "<div class='wym_area_left'></div>"
                                  + "<div class='wym_area_right'>"
                                  + "</div>"
                                  + "<div class='wym_area_main'>"
                                  + WYMeditor.HTML
                                  + WYMeditor.IFRAME
                                  + WYMeditor.STATUS
                                  + "</div>"
                                  + "<div class='wym_area_bottom'>"
                                  + "</div>"
                                  + "</div>",

                        postInit: function(wym) {
                            videoDetailTmp.wymEditor = wym;
                            //construct the button's html
                            var html = "<li class='wym_tools_newbutton'>"
                                + "<a name='Save' href='#' alt='Envoyer'"
                                + " style='background-image:"
                                + " url(http://www.filigranes.be/Images/WymEditor/envoyer.gif);width:78px'>"
                                 + "Sauvegarder votre commentaire"
                                + "</a></li>";

                            //add the button to the tools box
                            jQuery(wym._box)
                                .find(wym._options.toolsSelector + wym._options.toolsListSelector)
                                .append(html);

                            //handle click event
                            jQuery(wym._box)
                                .find('li.wym_tools_newbutton a').click(function() {
                                    videoDetailTmp.SaveComment();
                                    return (false);
                                });
                        }
                    });
                });
            }, 500);
        }
    }

}

VideoDetail.prototype.GetBooksTitle = function(arEans) {
    var videoDetailTmp = this;
    for (var i = 0; i < arEans.length; i++) {
        var ean = arEans[i];
        new Ajax.Request(videoDetailTmp.RootUrl + 'BookDetail.ashx',
             {
                 method: 'get',
                 onSuccess: function(transport) { videoDetailTmp.GetBooksTitleSucceed(transport); },
                 onFailure: function() {
                     videoDetailTmp.GetBooksTitleFailed();
                 },
                 parameters:
                {
                    'ms': new Date().getTime(),
                    'ean': ean,
                    'type': 'detail'
                }
             });
    }
}

VideoDetail.prototype.GetBooksTitleSucceed = function(transport) {
    if (transport && transport.responseXML) {
        if (document.getElementById('DivBooks')) {
            var title = '';
            var subtitle = '';
            var id = '';

            if (transport.responseXML.getElementsByTagName("recordreference") &&
                        transport.responseXML.getElementsByTagName("recordreference").length > 0 &&
                        transport.responseXML.getElementsByTagName("recordreference")[0].firstChild) {
                id = transport.responseXML.getElementsByTagName("recordreference")[0].firstChild.nodeValue;
            }
            if (transport.responseXML.getElementsByTagName("title") &&
                        transport.responseXML.getElementsByTagName("title").length > 0) {
                var titleNode = transport.responseXML.getElementsByTagName("title")[0];
                if (titleNode.getElementsByTagName("titletext") &&
                        titleNode.getElementsByTagName("titletext").length > 0 &&
                            titleNode.getElementsByTagName("titletext")[0].firstChild) {
                    title = titleNode.getElementsByTagName("titletext")[0].firstChild.nodeValue;
                }

                if (titleNode.getElementsByTagName("subtitle") &&
                            titleNode.getElementsByTagName("subtitle").length > 0 &&
                            titleNode.getElementsByTagName("subtitle")[0].firstChild) {
                    subtitle = titleNode.getElementsByTagName("subtitle")[0].firstChild.nodeValue;
                }
            }
            if (subtitle && subtitle != '') {
                title = title + ' (' + subtitle + ')';
            }

            var divBook = document.createElement('div');
            divBook.className = 'BookUrl';

            var aBookLink = document.createElement('a');
            aBookLink.href = this.RootUrl + 'fr/details-livre/index.aspx?book=' + id;
            aBookLink.target = '_self';
            aBookLink.appendChild(document.createTextNode(title));

            divBook.appendChild(aBookLink);
            document.getElementById('DivBooks').appendChild(divBook);
        }
    }
    if (document.getElementById('loading_' + this.DivID + '_Books')) {
        document.getElementById('loading_' + this.DivID + '_Books').style.display = 'none';
    }
}

VideoDetail.prototype.GetBooksTitleFailed = function() {
    if (document.getElementById('loading_' + this.DivID + '_Books')) {
        document.getElementById('loading_' + this.DivID + '_Books').style.display = 'none';
    }
}

VideoDetail.prototype.GetVideoVimeoData = function(clipId, width) {
    var videoDetailTmp = this;
    new Ajax.Request(this.RootUrl + 'VimeoWidget.ashx',
         {
             method: 'get',
             onSuccess: function(transport) { videoDetailTmp.OnGetVideoData(transport, clipId); },
             onFailure: function() {
                 videoDetail.OnGetVideoDetailData();
             },
             parameters:
            {
                ms: new Date().getTime(),
                id: clipId,
                width: width
            }
         });
}

VideoDetail.prototype.OnGetVideoData = function(transport, clipId) {
    if (transport && transport.responseXML) {
        var videoXml = transport.responseXML;
        var oembedNode = transport.responseXML.getElementsByTagName("oembed");

        if (oembedNode && oembedNode.length > 0) {
            var htmlNode = oembedNode[0].getElementsByTagName("html");
            if (htmlNode && htmlNode.length > 0) {
                try {
                    if (document.getElementById("clip_" + clipId)) {
                        var strObject = htmlNode[0].firstChild.nodeValue;
                        if (strObject.indexOf('</object>') > 0) {
                            strObject = strObject.substr(0, strObject.indexOf('</object>')) + '<param name="wmode" value="transparent" />' + strObject.substr(strObject.indexOf('</object>'))
                        }
                        document.getElementById("clip_" + clipId).innerHTML = strObject;

                        if (document.getElementById('loading_' + videoDetail.DivID + '_clip')) {
                            document.getElementById('loading_' + videoDetail.DivID + '_clip').style.display = 'none';
                        }
                    }
                }
                catch (e) {
                    alert(e);
                }
            }
        }
    }
    else {

    }
}

VideoDetail.prototype.GetBookFiligranautesComment = function() {
    var videoDetailTmp = this;

    new Ajax.Request(this.RootUrl + 'FiligranauteComment.ashx',
         {
             method: 'get',
             onSuccess: function(transport) { videoDetailTmp.OnGetBookFiligranautesComment(transport); },
             onFailure: function() {
                 videoDetailTmp.OnGetBookFiligranautesCommentFailed(transport);
             },
             parameters:
            {
                'ms': new Date().getTime(),
                'Reference': videoDetailTmp.VideoID,
                'MediaType': 'Video',
                'Validated': 'true'
            }
         });
}

VideoDetail.prototype.OnGetBookFiligranautesComment = function(transport) {

    if (document.getElementById('DivFiligranaute')) {
        var filigranauteComment = document.getElementById('DivFiligranaute');

        if (transport && transport.responseXML) {
            var xml = transport.responseXML;

            var commentNodes = xml.getElementsByTagName('Comment');
            for (var i = 0; i < commentNodes.length; i++) {
                var commentNode = commentNodes[i];

                var comment = '';
                var date = new Date();
                var user = '';
                var avatar = '';

                if (commentNode.attributes.getNamedItem("Date")) {
                    var dateStr = commentNode.attributes.getNamedItem("Date").nodeValue;
                    year = dateStr.substr(0, 4);
                    month = dateStr.substr(5, 2);
                    if (month.indexOf('0') == '0')
                        month = month.substr(1, 1);
                    day = dateStr.substr(8, 2);
                    if (day.indexOf('0') == '0')
                        day = day.substr(1, 1);
                    hour = dateStr.substr(11, 2);
                    if (hour.indexOf('0') == '0')
                        hour = hour.substr(1, 1);
                    minute = dateStr.substr(14, 2);
                    if (minute.indexOf('0') == '0')
                        minute = minute.substr(1, 1);

                    date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day), parseInt(hour), parseInt(minute), 0, 0);
                }
                if (commentNode.attributes.getNamedItem("Comment")) {
                    comment = commentNode.attributes.getNamedItem("Comment").nodeValue;
                }

                var userNodes = commentNode.getElementsByTagName('User');
                if (userNodes.length > 0) {
                    if (userNodes[0].attributes.getNamedItem('Avatar')) {
                        avatar = userNodes[0].attributes.getNamedItem('Avatar').nodeValue;
                    }
                    if (userNodes[0].attributes.getNamedItem('Pseudo')) {
                        user = userNodes[0].attributes.getNamedItem('Pseudo').nodeValue;
                    }
                }

                if (user != '') {
                    divCommentContent = document.createElement('div');
                    divCommentContent.className = 'CommentContainer';

                    divUser = document.createElement('div');
                    divComment = document.createElement('div');
                    if (avatar != '') {
                        imgAvatar = document.createElement('img');
                        imgAvatar.src = avatar;
                        divUser.appendChild(imgAvatar);
                    }
                    date.format('');
                    divUser.appendChild(document.createTextNode('Posté par ' + htmlToAccent(user) + ', le ' + date.format('dd/mm/yyyy') + ' à ' + date.format('HH:MM')));
                    divComment.innerHTML = comment;

                    divCommentContent.appendChild(divUser);
                    divCommentContent.appendChild(divComment);
                    filigranauteComment.appendChild(divCommentContent);


                }
            }
        }
    }

    if (document.getElementById('loading_' + this.DivID + '_Filigranaute')) {
        document.getElementById('loading_' + this.DivID + '_Filigranaute').style.display = 'none';
    }

}

VideoDetail.prototype.OnGetBookFiligranautesCommentFailed = function(transport) {
    if (document.getElementById('loading_' + this.DivID + '_Filigranaute')) {
        document.getElementById('loading_' + this.DivID + '_Filigranaute').style.display = 'none';
    }
}

VideoDetail.prototype.SaveComment = function() {
    var videoDetailTmp = this;
    if (GetCookie("Mail")) {
        var htmlText = removeHTMLTags(this.wymEditor.html());
        htmlText = htmlText.split(' ').join('').split('&nbsp;').join('').split('\r\n').join('');
        if (htmlText.length > 0) {
            var params = '<CommentParam>';
            params += '<Reference>' + this.VideoID + '</Reference>';
            params += '<MediaType>Video</MediaType>';
            params += '<Mail>' + GetCookie("Mail") + '</Mail>';
            var test = this.wymEditor.xhtml();
            params += '<Comment>' + Base64.encode(accentToHTML(this.wymEditor.html())) + '</Comment>';
            params += '</CommentParam>';
            params = Base64.encode(params);

            var test = accentToHTML(this.wymEditor.html());
            new Ajax.Request(this.RootUrl + 'SaveComment.ashx',
                 {
                     method: 'POST',
                     onSuccess: function(transport) { videoDetailTmp.OnSaveCommentSucceed(transport); },
                     onFailure: function(transport) {
                         videoDetailTmp.OnSaveCommentError(transport);
                     },
                     postBody: params
                 });
        }
        else {
            this.wymEditor.status('Veuillez saisir votre commentaire !');
        }
    }
    else {

        var divYourCommentArea = document.getElementById('DivYourCommentArea');

        if (divYourCommentArea.hasChildNodes()) {
            while (divYourCommentArea.childNodes.length >= 1) {
                divYourCommentArea.removeChild(divYourCommentArea.firstChild);
            }
        }
        var divLogin = document.createElement('div');
        divLogin.id = 'login_videodetail';
        document.getElementById('DivYourCommentArea').appendChild(divLogin);

        var loginModule = new Login('login_videodetail');
        loginModule.Init();
        loginModule.OnLoginSucceedEvent = videoDetailTmp.OnLoginSucceed;
        //            yourCommentTitle = document.createElement('h1');
        //            yourCommentTitle.appendChild(document.createTextNode('Votre avis nous interesse !'));
        //            divYourComment.appendChild(yourCommentTitle);
        //            divYourComment.appendChild(document.createElement('Veuillez vous connecter afin de saisir votre commentaire'));
    }
}

VideoDetail.prototype.OnSaveCommentSucceed = function(transport) {
    this.wymEditor.html("");
    this.wymEditor.status('Votre commentaire a été enregistré et doit être validé par un modérateur');
}

VideoDetail.prototype.OnSaveCommentError = function(transport) {
    this.wymEditor.status(transport.responseText);
}

