
var actionLinks = [{ "text": "Visita la comunidad", "href": "http://" + window.location.host}];


function PhotoAddComment(ObjectId, IsModerate, docl, nocomm, comcomm)
{
    var Moderation = document.getElementById('Ismoderate').value;
   
    var status = "";
    if (IsModerate == 'true')
        status = "P";
    else
        status = "A";
    
    var Body = document.getElementById('line').value;
	if (Body == docl)
		alert(nocomm);
	else {
		var CommunityId = document.getElementById('CommunityId').value;
		var url = '/Global/Services/Comments.asmx/AddInPhoto';												
		new Ajax.Request(url,
		    {
		        method: 'post',
		        parameters: { ObjectId: ObjectId, Body: Body, CommunityId: CommunityId, Status: status },
		        onSuccess: function(transport)
		        {
                    if (transport.status == 200)
                    {
                        if (transport.responseXML.getElementsByTagName("ut_response")[0].attributes[0].value == 'fail')
                        {
                            var errorCode = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[0].value;
                            var errorMge = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[1].value;
                            alert(errorCode + '-' + errorMge);
                        }
                    }
		        }
		    });
			
        document.getElementById('commentario_Begin').style.display = 'none';
        document.getElementById('commentario_End').style.display = 'block';
        
        if (Moderation == 'True') document.getElementById('comentario_pendiente').style.display = 'block';
        document.getElementById('Body').innerHTML = document.getElementById('line').value;
		
		if(document.getElementById('checkFaceShare'))
		{
		    if(document.getElementById('checkFaceShare').checked)
	        {
	            var title = document.getElementById('PhotoTitle').value;
        	    var attachment = [{'type':'image','src':document.getElementById('srcPhoto').value,'href': window.location.href }];
        	    var title = document.getElementById('communityTitle').value;
	            callPublish('',{'name':comcomm + title,'href':window.location.href,'description':Body, 'media': attachment},actionLinks);
	        }
	    }
	}
}

function DeleteComment(ObjectId,ObjectTypeId,Id)
{
    var url = '/Global/Services/Comments.asmx/CommentDel';												
    new Ajax.Request(url,
    {
        method: 'post', parameters: { ObjectId: ObjectId, ObjectTypeId: ObjectTypeId, Id: Id },												
        onSuccess: function(transport)
        {
            var rsp = transport.responseText.evalJSON().rsp;
            if(rsp.stat != 'fail')
                alert(rsp.err.msg);
        }
    });
}

function DeletePhotoComment(ObjectId, Id, mens,username)
{
    if(confirm(mens))
    {
        var url = '/Global/Services/Comments.asmx/DelInPhoto';												
        new Ajax.Request(url, 
        {
            method: 'post', parameters: { ObjectId: ObjectId, Id: Id, UserName:username },
            onSuccess: function(transport)
            {
                var rsp = transport.responseText.evalJSON().rsp;
                if(rsp.stat != 'fail')
                    alert(rsp.err.msg);
            }
        });
        document.getElementById('comment_' + Id).style.display = 'none';
        document.getElementById('Line_' + Id).style.display = 'none';
    }
}

function PhotoApproval(Id,ObjectId)
{
    var url = '/Comment/Comment.ashx?PhotoApproval&Format=json';												
    new Ajax.Request(url, 
    {
        method: 'post', parameters: { Id: Id, ObjectId: ObjectId},
        onSuccess: function(transport)
        {
            var rsp = transport.responseText.evalJSON().rsp;
            if(rsp.stat != 'fail')
                alert(rsp.err.msg);
        }
    });
}

function PhotoDesapproval(Id,ObjectId)
{
    var url = '/Comment/Comment.ashx?PhotoDesapproval&Format=json';												
    new Ajax.Request(url, 
    {
        method: 'post', parameters: { Id: Id, ObjectId: ObjectId},												
        onSuccess: function(transport)
        {
            var rsp = transport.responseText.evalJSON().rsp;
            if(rsp.stat != 'fail')
                alert(rsp.err.msg);
        }
    });
}

function PhotoBloqUser(Id,ObjectId)
{
    var url = '/Comment/Comment.ashx?PhotoBloqUser&Format=json';												
    new Ajax.Request(url, 
    {
        method: 'post', parameters: { Id: Id, ObjectId: ObjectId},												
        onSuccess: function(transport)
        {
            var rsp = transport.responseText.evalJSON().rsp;
            if(rsp.stat != 'fail')
                alert(rsp.err.msg);
        }
    });
}

function refresh(ClickHereToComment)
{
    if (document.getElementById('line').value == ClickHereToComment)
        document.getElementById('line').value = '';
}

function checkEmpty(ClickHereToComment)
{
    var element = document.getElementById('line').value;
    if(element == '')
    {
        document.getElementById('line').value = ClickHereToComment;
    }
}   

function cambio(e, pre, post)
{
    var element = document.getElementById('line').value
    n = element.length;
    t = 164;
    if (n > t)
    {
        document.getElementById('line').value = document.getElementById('line').value.substring(0, t);
        document.getElementById('cont').innerHTML = post + ' ' + num + ' ' + pre;
    }
    else
    {
        num = t - n;
        document.getElementById('cont').innerHTML = post + ' ' + num + ' ' + pre;
    }
}

function TestAddComment(ObjectId, Body, IsModerate, docl, commt)
{
    var status = "";
    if (Body == docl || Body == '')
    {
        status = "A";
        Body="";
    }
    else
    {
        if (IsModerate == 'true')
            status = "P";
        else
            status = "A";
    }

    var Title = document.getElementById('TitlecUserComment').innerHTML;
	var CommunityId = document.getElementById('CommunityId').value;
	var url = '/Comment/Comment.ashx?AddInTest&Format=json';												
    new Ajax.Request(url, 
    {
        method: 'post', parameters: { ObjectId: ObjectId, Body: Body, CommunityId: CommunityId, Status: status, Title: Title },												
        onSuccess: function(transport)
        {
            var rsp = transport.responseText.evalJSON().rsp;
            if(rsp.stat != 'fail')
                alert(rsp.err.msg);
        }
    });
			
	document.getElementById('commentario_Begin').style.display = 'none';
	document.getElementById('commentario_End').style.display = 'block';
	document.getElementById('Body').innerHTML = document.getElementById('line').value;
	
	if(status == 'P') document.getElementById('comentario_pendiente').style.display = 'block';
	    
	if(document.getElementById('checkFaceShare').checked)
	{
	    var title = document.getElementById('communityTitle').value;
	    callPublish('',{'name': commt+title,'href':window.location.href,'description':Body},actionLinks);
	}
}

function callPublish(msg, attachment, action_link) 
{
    FB.ensureInit(function () {
        FB.Connect.streamPublish('', attachment, action_link);
    });
}
