﻿<!--
    function liveBlogEntryCommentComponent(liveBlogEntryId, applicationSubPath) {    
        this.liveBlogEntryId = liveBlogEntryId;
        this.applicationSubPath = applicationSubPath;
        function show() {
            openDiv('divLiveBlogEntryCommentEditor' + liveBlogEntryId);
            //focus
            document.getElementById('taLiveBlogEntryCommentBody' + liveBlogEntryId).focus();
        }
        
        function hide() {
            closeDiv('divLiveBlogEntryCommentEditor' + liveBlogEntryId);
        }
        
        function add() {  
            var eleLiveBlogEntryCommentBody = document.getElementById('taLiveBlogEntryCommentBody' + liveBlogEntryId);

            if (eleLiveBlogEntryCommentBody.value.length == 0 || eleLiveBlogEntryCommentBody.value == null) {                
                alert('Proszę wprowadzić komentarz.');
                eleLiveBlogEntryCommentBody.focus();
                return;
            }  
        
            if (eleLiveBlogEntryCommentBody.value.length > 140) {                
                alert('Komentarz nie może być dłuższy niż 140 znaków.');
                eleLiveBlogEntryCommentBody.focus();
                return;
            }  

            document.getElementById('btnLiveBlogEntryCommentAdd' + liveBlogEntryId).disabled = 'true';
            wsComponent.sendRequest(applicationSubPath + '/Portal/WebServices/LiveBlogEntryCommentService.asmx', 'Add', '<liveBlogEntryId>' + liveBlogEntryId + '</liveBlogEntryId><body>' + encodeURIComponent(eleLiveBlogEntryCommentBody.value) + '</body>', true, wsComponent.execOnSuccess(addCallback));
        }
        
        function addCallback(xmlHttpReq) {
            document.getElementById('btnLiveBlogEntryCommentAdd' + liveBlogEntryId).disabled = '';
            if (wsComponent.getNodeValue(xmlHttpReq, 'AddResult') == 'true') {
                hide();
                document.getElementById('taLiveBlogEntryCommentBody' + liveBlogEntryId).value = '';
                retrieve();
            } else {
                alert('Wystąpił błąd.');
            }        
        }
        
        function retrieve() {  
            wsComponent.sendRequest(applicationSubPath + '/Portal/WebServices/LiveBlogEntryCommentService.asmx', 'Get', '<liveBlogEntryId>' + liveBlogEntryId + '</liveBlogEntryId>', true, wsComponent.execOnSuccess(retrieveCallback));
        }
        
        function retrieveCallback(xmlHttpReq) {
            nodeValue = wsComponent.getNodeValue(xmlHttpReq, 'GetResult').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
            if (nodeValue != null && nodeValue != '') {
                document.getElementById('divLiveBlogEntryCommentViewer' + liveBlogEntryId).innerHTML = nodeValue;                
            }            
        }
    
        this.show = show;
        this.hide = hide;
        this.add = add;
        this.retrieve = retrieve;
    }   
//-->

