/**
 * @author gsandrigo
 */
 
	function retrievesubscribers()
    {
        json1.sendBegin("http://profile-websvc.break.com/Membership/Handlers/Profile/Subscription/SubscriptionHandler.ashx?invoke=subscribersbynickname&syndicatorNickname=" + nickname + "&subscriptionTypeId=2&pageNumber=1&pageSize=6&siteId=1", "updatesubscribers");
    }

    function retrievesubscriptions()
    {
        json1.sendBegin("http://profile-websvc.break.com/Membership/Handlers/Profile/Subscription/SubscriptionHandler.ashx?invoke=contentsubscriptions&subscriberId=" + encMemberID + "&pageNumber=1&pageSize=6&siteId=1", "updatesubscription");
    }
    
    function retrieveComments()
    {
        json2.sendBegin("http://profile-websvc.break.com/Membership/Handlers/Profile/Comments/CommentsHandler.ashx?invoke=viewallcomments&memberId=" + encMemberID + "&pageNumber=1&pageSize=5&siteId=1", "updatecomments");
    }
    
    function banuser()
    {
        json.sendBegin("http://profile-websvc.break.com/Membership/Handlers/Profile/Member/MemberHandler.ashx?invoke=banmember&memberId=" + viewerId + "&banMemberId=" + encMemberID + "&siteId=1", "removeSubscriberCallback");
    }
    
	function markInappropriate()
	{
		markInappropriateJson.sendBegin("http://profile-websvc.break.com/Membership/Handlers/MemberFeedback/MemberFeedbackHandler.ashx?invoke=markinappropriate&aboutMemberId=" +  encMemberID + "&fromMemberId=" + viewerId + "&ip=" + viewerIpAddy + "&feedbackType=1&feedbackValue=1", "markedInappropriate");
	}
	
    function deletecomment()
    {
        var contentCommentIds = "";
		var memberCommentIds = "";
		var indices = "";
        var element;
        if(global_comments != undefined && global_comments != null){
		if(global_comments.length)
		{
		    for(var i=0; i<global_comments.length; i++){
		      element = document.getElementById('cid' + i);
		      if(element.checked){
			if(global_comments[i].IsMemberComment == "True"){
				memberCommentIds += global_comments[i].CommentId + ",";
					}
				else{
				contentCommentIds += global_comments[i].CommentId + ",";
					}
		      }
		    }
		}
		else
		{
		    element = document.getElementById('cid0');
		      if(element.checked){
			 if(global_comments.IsMemberComment == "True"){
				memberCommentIds += global_comments.CommentId + ",";
					}
				else{
				contentCommentIds += global_comments.CommentId + ",";
					}
		    }
		}
        }
        if(contentCommentIds.length == 0 && memberCommentIds.length == 0){
      		dialogObj.Message = "Please select a comment to delete";
		dialogObj.Display();
		return;
   		}
   
	   if(contentCommentIds.length > 0){
	      indices = indices.substr(0, indices.length-1);
	      contentCommentIds = contentCommentIds.substr(0, contentCommentIds.length-1);
	   }
	   
	   if(memberCommentIds.length > 0){
	      indices = indices.substr(0, indices.length-1);
	      memberCommentIds = memberCommentIds.substr(0, memberCommentIds.length-1);
	   }
       json.sendBegin("http://profile-websvc.break.com/Membership/Handlers/Profile/Comments/CommentsHandler.ashx?invoke=deletecomments&contentCommentIds=" + contentCommentIds + "&memberCommentIds=" + memberCommentIds + "&memberId=" + encMemberID + "&siteId=1", "retrieveComments");
    }
    
    function deleteandban()
    {
        var ids = "";
	var indices = "";
        var element;
        var selfBan = false;
        if(global_comments != undefined && global_comments != null){
		if(global_comments.length)
		{
		    for(var i=0; i<global_comments.length; i++){
		      element = document.getElementById('cid' + i);
		      if(element.checked){
			 if(nickname != global_comments[i].ByNickName){
			    if(ids.indexOf(global_comments[i].EncryptedByMemberId) == -1){
			       indices += i + ",";
			       ids += global_comments[i].EncryptedByMemberId + ",";
			    }
			 }
			 else{
			    selfBan = true;
			    element.checked = false;
			 }
		      }
		    }
		}
		else
		{
		      element = document.getElementById('cid0');
		      if(element.checked){
				if(nickname != global_comments.ByNickName){
					ids += global_comments.EncryptedByMemberId + ",";
				}
		      }
		}
        }
        if(ids.length > 0){
          ids = ids.substr(0, ids.length-1);
        }
        else{
		if(selfBan){
			dialogObj.Message = "You cannot ban yourself.";
		}
		else {
			dialogObj.Message = "Please select a comment to delete";
		}
	  dialogObj.Display();
        }
    json.sendBegin("http://profile-websvc.break.com/Membership/Handlers/Profile/Comments/CommentsHandler.ashx?invoke=bananddelete&banMemberIds=" + ids + "&memberId=" + encMemberID + "&siteId=1", "retrieveComments");
  }
    
    function removeSubscriberCallback(jsonData)
    {
        if(jsonData.Response.Code == 0)
	    {
	        dialogObj.Message = "You have succesfully blocked this user.";
			dialogObj.Display();
	    }
	    else if(jsonData.Response.Code == -1)
	    {
			dialogObj.Message = "The operation failed.";
			dialogObj.Display();
	    }
	     
    }
    
	function markedInappropriate(jsonData)
    {
		markInappropriateJson.sendEnd();
        if(jsonData.Response.Code == 0)
	    {
	        dialogObj.Message = "Profile has been marked inappropriate.";
			dialogObj.Display();
	    }
	    else if(jsonData.Response.Code == -1)
	    {
			dialogObj.Message = "The operation failed.";
			dialogObj.Display();
	    }
	     
    }
	
	
    function updatesettings(jsonData)
    {
        div = document.getElementById("settings_body_content");
        
        if(jsonData.contentType == "HTML")
        {
            div.innerHTML = jsonData.moduleContent;
            checkRemoveMyAccountLink();
            
        }
        else
        {
            div.innerHTML = "Unknown response type";
        }

    }
    
    function checkRemoveMyAccountLink() {
       if (ThirdPartyMember.IsLoggedIntoBreak()){
            div = document.getElementById("settings_body_content");
            if (div.childNodes.length > 0) {
                var listItems = div.childNodes[0].getElementsByTagName("li");
                /* alert(listItems.length + " div id: " + div.childNodes[0].id); */
                var ulParent = listItems[0].parentNode;
                ulParent.removeChild(listItems[0]);
                /* alert(ulParent.nodeName); */
                
            }
        }
    }
    
    function updateaboutme(jsonData)
    {
        div = document.getElementById("aboutme_body");
        
        if(jsonData.contentType == "HTML")
        {
            div.innerHTML = jsonData.moduleContent;
        }
        else if(jsonData.contentType == "JSON")
        {
            renderAboutMeModule(div, jsonData.moduleContent);
        }
        else
        {
            div.innerHTML = "Unknown response type";
        }
         
    }
    
    function updateprofile(jsonData)
    {
        div = document.getElementById("profile_body_content");
        
        if(jsonData.contentType == "JSON")
        {
            renderProfileModule(div, jsonData.moduleContent);
        }
        else
        {
            div.innerHTML = "Unknown response type";
        }
         
    }
    
    function updatesubscription(jsonData)
    {
        div = document.getElementById("subscriptions_body_content");
        
        renderSubscriptionModule(div, jsonData.Response.ContentSubscription);
         
    }
    
    function updatesubscribers(jsonData)
    {
        div = document.getElementById("subscribers_list_body_content");
        renderSubscribersModule(div, jsonData.Response.Subscriber);
         
    }
	
	function updaterating(jsonData)
    {
        div = document.getElementById("ratings_list_body_content");
		if(jsonData.Response.Contents.RatingHistory){
			renderRatingModule(div, jsonData.Response.Contents.RatingHistory.RatingRecord);
		}
		else
		{
			renderRatingModule(div, jsonData.Response.Contents.RatingHistory);
		}
    }
    
    function updatebulletins(jsonData)
    {
        div = document.getElementById("mybulletins_body_content");
        renderMyBulletinsModule(div, jsonData.Response.BulletinSubscription);
    }
    
    function updatecomments(jsonData)
    {
        div = document.getElementById("comments_body_content");
        
        renderCommentsModule(div, jsonData.Response.Comment);
         
    }
	
	function updatebreakmoney (jsonData)
	{
		div = document.getElementById ("breakmoney_body_content");
		renderBreakMoneyModule (div, jsonData.moduleContent);
	
	}
    
    function updatefeaturedvideo(jsonData)
    {
        div = document.getElementById("featured_body_content");
        
        if(jsonData.contentType == "JSON")
        {
            renderFeaturedVideoModule(div, jsonData.moduleContent);
        }
        else
        {
            div.innerHTML = "Unknown response type";
        }
         
    }
    
    
    
    function ratingCallBack(jsonData){
		dialogObj.Message = "Thank you for rating!";
		dialogObj.Display();
    }
    
    
    
    function updateleft(jsonData){
        if(jsonData.contentType == "HTML")
        {
            document.getElementById("pane1").innerHTML = jsonData.paneContent;
        }
        else
        {
            document.getElementById("pane1").innerHTML = "Unknown response type";
        }

        jQuery(document).ready(function() {
            for (i = 0; i < jsonData.calls.length; i++) {
                if (jsonData.calls[i] != "null") {
                    /* don't let 3rd party members see the about me section */
                    if (ThirdPartyMember.IsLoggedIntoBreak() && (jsonData.calls[i].toString().toLowerCase().indexOf("aboutmehandler.ashx") !== -1)) {
                        /*alert("ignoring " + jsonData.calls[i].toString());*/
                        var div = document.getElementById("aboutme_body");
                        var parentDiv = div.parentNode;
                        document.getElementById(parentDiv.id).style.display = "none";
                        continue;
                    }
                    eval(jsonData.calls[i]);
                }
            }
        });
        
    }
    
    function updateright(jsonData){
        if(jsonData.contentType == "HTML")
        {
            document.getElementById("pane2").innerHTML = jsonData.paneContent;
        }
        else
        {
            document.getElementById("pane2").innerHTML = "Unknown response type";
        }
        
        for(i=0; i < jsonData.calls.length; i++)
        {
            if(jsonData.calls[i] != "null"){
				//alert(i);
				eval(jsonData.calls[i]);
			}
        }
    }

	function subscribeCallback(jsonData)
	{
	    if(jsonData.Response.Code == 0){
	        retrievesubscribers();
	        toggleBox("subscribers_list_none", 0);
	        toggleBox("subscribers_list_body_content", 1);
			dialogObj.Message = "You have been suscribed to this user";
			dialogObj.Display();
	    }
	    else {
	        dialogObj.Message = jsonData.Response.Message;
			dialogObj.Display();
	    }
	     
	}