﻿function AcceptFriend(ParentId, ChildId, Rel) {
    var url = '/Friends/Services/Friends.asmx/Accept';  // Friend/Friend.ashx?Accept&Format=json';
    new Ajax.Request(url, { method: 'post', parameters: { ParentId: ParentId, ChildId: ChildId , Relation : Rel},
        onSuccess: function (transport) {
            var rsp = transport.responseText.evalJSON().rsp;
            if (rsp.stat != 'fail')
                alert(rsp.err.msg);


        } 
    });
                        
        document.getElementById('Aceptar_' + ChildId).style.display = "none";
        document.getElementById('Ignorar_' + ChildId).style.display = "none";
        document.getElementById('FeedBack_True_' + ChildId).style.display = "block";
        try {
            document.getElementById('AceptarAdmin_' + ChildId).style.display = "none";
         } catch(e){}
}
function Ignore(ParentId, ChildId, UserName, LastName, FirstPartQuestionIgnore, LastPartQuestionIgnore) {
    if (!confirm(FirstPartQuestionIgnore + ' ' + UserName + ' ' + LastName + ' ' + LastPartQuestionIgnore)) {

    }
    else {
        var url = '/Friends/Services/Friends.asmx/Ignore';
        new Ajax.Request(url, { method: 'post', parameters: { ParentId: ParentId, ChildId: ChildId},
            onSuccess: function (transport) {
                var rsp = transport.responseText.evalJSON().rsp;
                if (rsp.stat != 'fail')
                    alert(rsp.err.msg);
            } 
        });
        document.getElementById('LabelName' + ChildId).style.textDecoration = "line-through";
        document.getElementById('LabelBody' + ChildId).style.textDecoration = "line-through";
        document.getElementById('LabelVisitas' + ChildId).style.textDecoration = "line-through";

        document.getElementById('LabelAmigos' + ChildId).style.textDecoration = "line-through";
        document.getElementById('LabelFotos' + ChildId).style.textDecoration = "line-through";
        document.getElementById('LabelVideos' + ChildId).style.textDecoration = "line-through";
        document.getElementById('LabelNotas' + ChildId).style.textDecoration = "line-through";
        document.getElementById('LabelNotas' + ChildId).style.textDecoration = "line-through";
        document.getElementById('Img' + ChildId).src = "../images/usuario_eliminado.gif";
    }
}

function IgnoreFriend(ParentId,ChildId, UserName, LastName, FirstPartQuestionIgnore, LastPartQuestionIgnore) {
    if (!confirm(FirstPartQuestionIgnore + ' ' + UserName + ' ' + LastName + ' ' + LastPartQuestionIgnore)) {

    }
    else {
        var url = '/Friends/Services/Friends.asmx/Ignore';
        new Ajax.Request(url, { method: 'post', parameters: { ParentId: ParentId, ChildId: ChildId},
            onSuccess: function (transport) {
                var rsp = transport.responseText.evalJSON().rsp;
                if (rsp.stat != 'fail')
                    alert(rsp.err.msg);
            } 
        });
        document.getElementById('Aceptar_' + ChildId).style.display = "none";
        document.getElementById('Ignorar_' + ChildId).style.display = "none";
        document.getElementById('FeedBack_False_' + ChildId).style.display = "block";
        try {
            document.getElementById('AceptarAdmin_' + ChildId).style.display = "none";
        } catch (e) { }
    }
}

 function DeleteFriend(ParentContactId, ChildContactId, CommunityId, Question) {
     if (!confirm(Question))
	{

	}
	else
	{
	    var url = '/Global/Services/Delete.asmx/DeleteFriend';
        new Ajax.Request(url, 
        {
		    method: 'post', 
		    parameters: 
		    { 
			    ParentContactId: ParentContactId,
			    ChildContactId: ChildContactId,
                CommunityId : CommunityId
		    },
		    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);
				    }
				    else
				    {
				        document.getElementById('Content_' + ChildContactId).style.display = 'none';
				        document.getElementById('Line_' + ChildContactId).style.display = 'none';
				    }
			    }
		    }
	    });
	}
}

 function DeleteMember(ParentContactId, ChildContactId, CommunityId, Question) {
     if (!confirm(Question))
	{

	}
	else
	{
	    
	    var url = '/Global/Services/Delete.asmx/DeleteMember';
        new Ajax.Request(url, 
        {
		    method: 'post', 
		    parameters: 
		    { 
			    ParentContactId: ParentContactId,
			    ChildContactId: ChildContactId,
                CommunityId : CommunityId
		    },
		    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);
				    }
				    else
				    {
				        document.getElementById('gallery_' + ChildContactId).style.display = 'none';
				    }
			    }
		    }
	    });
	}
}


function deladmin(parent, childid) {
    var url = '/Friends/Services/Friends.asmx/ChangeRelationshipType'; 
    new Ajax.Request(url, { method: 'post', parameters: {ParentId:parent, ChildId:childid, Type:2},
        onSuccess: function (transport) {
            var rsp = transport.responseText.evalJSON().rsp;
            if (rsp.stat != 'fail')
                alert(rsp.err.msg);


        } 
    });

    document.getElementById('add_' + childid).style.display = "block";
    document.getElementById('del_' + childid).style.display = "none";
}



function addadmin(parent, childid) {
    var url = '/Friends/Services/Friends.asmx/ChangeRelationshipType';
    new Ajax.Request(url, { method: 'post', parameters: { ParentId: parent, ChildId: childid, Type:3 },
        onSuccess: function (transport) {
            var rsp = transport.responseText.evalJSON().rsp;
            if (rsp.stat != 'fail')
                alert(rsp.err.msg);


        }
    });

    document.getElementById('add_' + childid).style.display = "none";
    document.getElementById('del_' + childid).style.display = "block";
}

function checkEnterSearchFans(e, text) {
	if (e && e.which) {
		e = e;
		characterCode = e.which;
	}
	else {
		e = event;
		characterCode = e.keyCode;
	}

	if (characterCode == 13) {
		window.location = '/Search/Search.aspx?Type=Club_De_Fans&Search=' + text;
	}
	else {
		return true;
	}
}
