﻿var selectedArticleImageId;

function SelectedImage(id, articleImageId)
{
    $("#MainImage").attr("src","../Handlers/ImageHandler.ashx?imageId=" + id);
    $.post('Handlers/GetImageComments.ashx',
    {
        imageId : id
    },
    function(data)
    {    
        var numberOfComment;
        $('#ImageComments').html(data);
        selectedArticleImageId = articleImageId;
        $('.SelectedImage').removeClass("SelectedImage");
        $('#Image_'+id).addClass("SelectedImage");
        $('.ViewGalleryResponses').show();
        $('#ImageComments .ImageComment').each(
        function(i)
        {
            numberOfComment = i;
        });
        if(numberOfComment != null)
            $("#NumberOfComments").html(parseInt(numberOfComment)+1);
        else
            $("#NumberOfComments").html("0")
    });
}
function changeVodSource (VodID)
{
	document.getElementById('theIFrame').src='http://players.mediazone.co.il/media/authors/38/playlists/' + 
	VodID + 
	'/players/11/';
	
	return false;
}
function showCommentDiv()
{
    $('#divAddNewComment').toggle('slow');
}
function ShowImageInMainGallery(id)
{
    $('.SelectedImage').removeClass("SelectedImage");
    $('#MainMoreArticlesImage_'+id).addClass("SelectedImage");
    $('#MainGalleryImage').attr("src","../Handlers/ImageHandler.ashx?imageId=" + id);
}
function saveComment(dexUserId)
{
    var num = $("#NumberOfComments").html();
    username = $('#CommentUserName').val();
    if(username == null || username=="")
    {
        alert("חובה להכניס שם משתמש");
        return;
    }
    title = $('#CommentTitle').val();
    if(title == null || title=="")
    {
        alert("חובה להכניס כותרת");
        return;
    }
    content = $('#CommentText').val();
    $.post("Handlers/SaveComment.ashx",
        {
            articleImageId : selectedArticleImageId,
            userName : username,
            content : content,
            title : title,
            dexUserId : dexUserId
        },
        function(data)
        {
            $("#ImageComments").append(data);
            $("#divAddNewComment").hide();
            $("#NumberOfComments").html(parseInt(num)+1);
        });
}
function saveArticleComment(articleId, dexUserId)
{
    var num = $("#NumberOfComments").html();
    username = $('#CommentUserName').val();
    if(username == null || username=="")
    {
        alert("חובה להכניס שם משתמש");
        return;
    }
    title = $('#CommentTitle').val();
    if(title == null || title=="")
    {
        alert("חובה להכניס כותרת");
        return;
    }
    content = $('#CommentText').val();
    $.post("Handlers/SaveArticleComment.ashx",
        {
            articleId : articleId,
            userName : username,
            content : content,
            title : title,
            dexUserId : dexUserId
        },
        function(data)
        {
            $("#ImageComments").append(data);
            $("#divAddNewComment").hide();
            $("#NumberOfComments").html(parseInt(num)+1);
        });
}


function OpenSendForm(uri)
{
        //alert(location.href);
        var url = "SendToFriend.aspx?url=" + location.href;
        var win = window.open('','','left=100px, top=100px, width=600px, height=550px, scrollbars=no, status =no, resizable=no');
        win.location.href = url;
        win=null;
       // return false;
   
 
}
