﻿var plugin = null;
var allowNotRegisteredUser = true;

function sldebug(pos) {
    window.status = pos + "|";
}
function showProgramInformation(programID) {
    var w = window.open('../show/' + programID, '_blank');
}
function openMyShowroom() {
    var w = window.open('http://myshowroom.tv/', '_blank');
}
//obsolote
function dataCompleted() {
    if (plugin != null) {
        m_CurrentMedia = plugin.Content.slGateway.Current;
        m_Comments = plugin.Content.slGateway.Comments;
        setTimeout('updateData()', 500);
    }
}
function programCompleted() {
    if (plugin != null) {
        m_CurrentMedia = plugin.Content.slGateway.Program;
        try {
            try {
                drawProgramDetails2();
            } catch (e) { //alert('1' + e.message);  
            }
            drawComment(null, false);
            if (m_RatedProgramID != null) m_RatedProgramID.value = m_CurrentMedia.ID;
            //if (m_CurrentMedia.Vote != 0) {
            if (m_Rate != null) m_Rate.innerHTML = drawStars(m_CurrentMedia.Vote, true);
            //} else {
            //    if (m_Rate != null) m_Rate.innerHTML = drawStars(m_CurrentMedia.Vote, true);
            //}
            var numOfComments = document.getElementById('numberOfComments');
            if (numOfComments != null) numOfComments.innerHTML = m_CurrentMedia.NumberOfComments;
        } catch (e) {
            //alert(e.message);  
        }
    }
}
function addChatMessage(msg) {
    drawComment(msg,true);
}
function plugInCompleted(sender) {
    plugin = sender.getHost();
    if (plugin != null) {
        postPlugInCompleted();
    }
}
function playRecordedVideo(id) {
    if (plugin != null) {
        plugin.Content.slApplication.PlayRecordedProgram(id);
        var fb = document.getElementById('facebookFrame');
	directUrl = masterUrl + id;
        if (fb != null){
            facebookLikeUrl = facebookLikeUrl.replace('@@URL@@', encodeURIComponent(directUrl));
            fb.setAttribute('src', facebookLikeUrl);
        }
    }
}
function pauseRecordedVideo(id) {
    if (plugin != null) {
        plugin.Content.slApplication.PauseRecordedProgram(id);
    }
}
function closeChatWindow() {
    var chatWin = document.getElementById('chatTable');
    if ((chatWin != null) && (chatWin.style.display == 'inline')) {
        chatWin.style.display = 'none';
    }
    plugin.Content.slApplication.ShowInlineChat();
}
function showChatWindow() {
    if (m_PlayerMode.toLowerCase() == 'full') {
        var chatWin = document.getElementById('chatTable');
        if ((chatWin != null) && (chatWin.style.display == 'inline')) {
            closeChatWindow();
        }
        else {
            switchTab('COM');
        }
    } else {
        if ((m_CurrentMedia != null) && (m_CurrentMedia.Program != null) && (m_CurrentMedia.Program.CustomerNickName != "")) {
            window.open('../profiles/' + m_CurrentMedia.Program.CustomerNickName, '_top');
        } else {
            window.open('../pages/default.aspx', '_top');
        }
    }
}
function postComment() {
    if (!allowNotRegisteredUser) {
        var d = document.getElementById('ExternalUserName');
        if (d != null) {
            if (d.value.replace(/(^\s*)|(\s*$)/g, "") == '') {
                d = document.getElementById('AuthenticationError');
                if (d != null) {
                    alert(d.value);
                } else {
                    alert('Please sign in first!');
                }
                return;
            }
        }
    }
    var c = document.getElementById('comment').value;
    if (c != null) {
        if (c.length > 30) {
            var s = c.split(' ');
            if (s.length > 1) {
                for (var i = 0; i < s.length; i++) {
                    if (s[i].length > 30) {
                        c = c.substring(0, 30) + '...';
                        document.getElementById('comment').value = c;
                        break;
                    }
                }
            } else {
                c = c.substring(0, 30) + '...';
                document.getElementById('comment').value = c;
            }
        }
    }
    
    sendDataRequest('formComment', '../services/addcomment.aspx', true);
    document.getElementById('comment').value = '';
}
function checkEnter(event) {
    if (event.keyCode == 13) {
        postComment();
        return false;
    }
}
function checkScroll() {
    m_PreviousScroll = m_CommentContainer.scrollTop;
}
function setUserName(nick) {
    var d = document.getElementById('nickName');
    if (d != null) {
        d.value = nick;
    }
    d = document.getElementById('currentNickName');
    if (d != null) {
        d.innerHTML = nick;
    }
    openUrl('../services/setusername.aspx?n=' + nick);
}
function changeChannelId(cid) {
    var d = document.getElementById('channelId');
    if (d != null) {
        d.value = cid;
    }
}
