
function CC_Content_IsFan(contentId, isFan) {
    $.ajax({
        type: "POST",
        url: "/WebServices/Content.asmx/IsFan",
        contentType: "application/json; charset=utf-8",
        data: "{'contentId': " + contentId + ", 'isFan': " + isFan + "}",
        dataType: "json",
        cache: false,
        success: function(msg) {                
            var r = eval('(' + msg + ')');                                       
             
            if(r.Success == -1) {
                CC_Login_Open();
            }
            else {       
                $('#fanQuestion').hide();
                $('#fanQuestionPanel').hide();
                $('#fanStatement').html(isFan ? 'You are a fan' : 'You are not a fan');
                $('#fanStatement').fadeIn('fast');                
            }
        }
    });   
}

function CC_Content_IsTopless(obj, contentId, isTopless) {
    var o = $(obj);
    $.ajax({
        type: "POST",
        url: "/WebServices/Content.asmx/UpdateTopless",
        contentType: "application/json; charset=utf-8",
        data: "{'contentId': " + contentId + ", 'isTopless': " + (isTopless ? 'true' : 'false') + "}",
        dataType: "json",
        cache: false,
        success: function(msg) {                            
        }
    });   
}

function CC_Content_IsVIP(obj, contentId, isVIP) {
    var o = $(obj);
    $.ajax({
        type: "POST",
        url: "/WebServices/Content.asmx/UpdateVIP",
        contentType: "application/json; charset=utf-8",
        data: "{'contentId': " + contentId + ", 'isVIP': " + (isVIP ? 'true' : 'false') + "}",
        dataType: "json",
        cache: false,
        success: function(msg) {                            
        }
    });   
}

function CC_Content_ReportAbuse(contentId) {    
    $.ajax({
        type: "POST",
        url: "/WebServices/Content.asmx/ReportOffensive",
        contentType: "application/json; charset=utf-8",
        data: "{'contentId': " + contentId + "}",
        dataType: "json",
        cache: false,
        success: function(msg) {     
            $('#reportAbuse').fadeOut(100);                       
            $('#reportAbuse').text('Thank you');
            $('#reportAbuse').unbind('click');
            $('#reportAbuse').removeClass('item-not-selected');
            $('#reportAbuse').fadeIn(200);
        }
    });   
}

function CC_Content_GetUserContentPaged(mediaType, pageIndex) {
    $.ajax({
        type: "POST",
        url: "/WebServices/Content.asmx/GetUserContentPaged",
        contentType: "application/json; charset=utf-8",
        data: "{'mediaType': " + mediaType + ", 'pageIndex': " + pageIndex + "}",
        dataType: "json",
        cache: false,
        success: function(msg) {                
            var r = eval('(' + msg + ')');                                       
        }
    });   
}

function CC_Content_Update(contentId, name, description, tags, isTopless, isVIP, result, item) {
    $.ajax({
        type: "POST",
        url: "/WebServices/Content.asmx/UpdateContent",
        contentType: "application/json; charset=utf-8",
        data: "{'contentId': " + contentId + ", 'name': '" + name + "', 'description': '" + description + "', 'tags': '" + tags + "', 'isTopless': '" + isTopless + "', 'isVIP': '" + isVIP + "'}",
        dataType: "json",
        cache: false,
        success: function(msg) {                
            var r = eval('(' + msg + ')');      
                        
            if(r.Success == 1) {
                $(item).fadeOut();
            } else {
                $(result).showError(r.Message);
            }
        }
    });   
}

function CC_Content_Delete(contentId, result, item) {
    var success1 = -1;
    $.ajax({
        type: "POST",
        url: "/WebServices/Content.asmx/DeleteContent",
        contentType: "application/json; charset=utf-8",
        data: "{'contentId': " + contentId + "}",
        dataType: "json",
        cache: false,
        success: function(msg) {                
            var r = eval('(' + msg + ')');      
                        
            if(r.Success == 1) {
                $(item).fadeOut();
                success1 = 1;
            } else {
                $(result).showError(r.Message);
            }
        }
    });       
    return success1;
}

function get_title() {
    var title = document.title;
    if($('#featuredTitle').html() != null) {
        title = $('#featuredTitle').html();
    } else if($('#blogTitle').html() != null) {
        title = $('#blogTitle').html();
    } else if($('#profileName').html() != null) {
        title = $('#profileName').html();
    }
    return title;
}

function fbs_click() 
{
    u=location.href;t=get_title();window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
}


function bebo_click() 
{
    var u=location.href;
    var title = encodeURIComponent(get_title());    
    u=location.href;t=get_title();window.open('http://www.bebo.com/c/share?Url='+encodeURIComponent(u)+'&Title='+ title);return false;
}

function twitter_click() 
{
    var u=location.href;
    var title = encodeURIComponent(get_title());    
    u=location.href;t=get_title();window.open('http://twitter.com/home?status='+title+':+'+encodeURIComponent(u));return false;
}




function del_click() 
{
    var u=location.href;
    var title = encodeURIComponent(get_title());    
    window.location.href = 'http://del.icio.us/post?url='+encodeURIComponent(u)+'&title='+title; return false;
}

function digg_click() 
{
    var u=location.href;
    var title = encodeURIComponent(get_title());    
    window.location.href = 'http://digg.com/submit?phase2&url='+encodeURIComponent(u)+'&title='+title; return false;
}

function reddit_click() 
{
    var u=location.href;
    var title = encodeURIComponent(get_title());    
    window.location.href = 'http://reddit.com/submit?url='+encodeURIComponent(u); return false;
}

function google_click() 
{
    var u=location.href;
    var title = encodeURIComponent(get_title());    
    window.location.href = 'http://google.com/bookmarks/mark?op=edit&bkmk='+encodeURIComponent(u)+'&title='+title; return false;
}

function GetThis1(T, C, U, L)
{
	var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T)
	+ '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
	window.open(targetUrl);
}

function myspace_click() 
{
    var u=location.href;
    var title = get_title();    
    GetThis1(title, '<a href="' + u + '" title="' + title + '">' + u + '</a>', 'http://myspace.com/', 1);
}

function CC_VIP_GiveStar(star, contentId, platinum, fromAvatar, toAvatar, toName) 
{
    var star1 = $('#' + star);
    star1.attr('onclick', '');
    star1.animate({ 'width': 0, 'height': 0 }, 200, 'swing',
        function(e) {
            star1.parent().remove();
            
            if(platinum == 0) {
                $('#awardHeader').attr('src', '/Images/gold_star_award.jpg');
                $('#awardType').attr('src', '/Images/gold_star_award_diag.jpg');
            } else {
                $('#awardHeader').attr('src', '/Images/platinum_star_award.jpg');
                $('#awardType').attr('src', '/Images/platinum_star_award_diag.jpg');
            }
            
            $('#awardFrom').attr('src' ,fromAvatar);
            $('#awardTo').attr('src', toAvatar);
            
            
            if(platinum == 1) {
                var count = parseInt($('#platinumCount').html());
                count--;
                $('#platinumCount').html(count);
                if(count == 0) {
                    $('#platinumStarsPanel').hide();
                }         
            } else {
                var count = parseInt($('#goldCount').html());
                count--;
                $('#goldCount').html(count);   
                if(count == 0) {
                    $('#goldStarsPanel').hide();
                }         
            }
            
            CC_UpdateStarPanels();
            
            $.modal($('#awardGiven'), {
            containerCss: { 'width': '400px' },
            onOpen: function (dialog) {
                dialog.overlay.fadeIn('fast', function () {
                dialog.container.slideDown('fast', function () {
                    dialog.data.fadeIn('fast');
                        $.ajax({
                        type: "POST",
                        url: "/WebServices/Content.asmx/GiveAStar",
                        contentType: "application/json; charset=utf-8",
                        data: "{'starTransactionId': '" + star + "', 'contentId': " + contentId + "}",
                        dataType: "json",
                        cache: false,
                        success: function(msg) {                
                            var r = eval('(' + msg + ')');      
                                        
                            if(r.Success == 1) {                                
                            
                                if(platinum == 1) {
                                    $('#awardInfo').html('Congratulations! You have awarded 1 Platinum Star worth &pound;1 to ' + toName + '. An alert has been sent.');                                
                                }
                                else {
                                    $('#awardInfo').html('Congratulations! You have awarded 1 Gold Star worth 70p to ' + toName + '. An alert has been sent.');                                
                                }
                                
                            } else {
                                $('#awardInfo').showError(r.Message);
                            }
                        }
                    });
                });                                                
                });
            }
            }); 
        }
    );
    
    //star.remove();
}

function CC_FixImages() {
	var posts = $('.cP');
	var imgs = $(posts).find('img');
	for(var i=0; i<imgs.length; i++) {
		var img = $(imgs[i]);

		img.bind('load', function(e) {
				var i = $(this);
				if(i.attr('width') > 600) {
				i.removeAttr('style');
				i.attr('width', 600);
				}
		});

	}
}

function CC_Blog_DeleteComment(td, id) 
{       
    $.ajax({
    type: "POST",
    url: "/WebServices/Content.asmx/DeleteBlogComment",
    contentType: "application/json; charset=utf-8",
    data: "{'spaceBlogCommentId': " + id + "}",
    dataType: "json",
    cache: false,
    success: function(msg) {                
        var r = eval('(' + msg + ')');      
                    
        if(r.Success == 1) {                                    
            $(td).parent().parent().parent().parent().hide(200); 
            $(td).parent().parent().parent().parent().next().hide(200);            
        } else {
        }
    }       
       
    });
    //$(td).parent().parent().parent().hide(200);    
}
function CC_Status_DeleteComment(id) 
{       
    $.ajax({
    type: "POST",
    url: "/WebServices/Content.asmx/DeleteStatusComment",
    contentType: "application/json; charset=utf-8",
    data: "{'spaceStatusCommentId': " + id + "}",
    dataType: "json",
    cache: false,
    success: function(msg) {                
        var r = eval('(' + msg + ')');      
                    
        LoadUserFeed(currentFilter);                    
     
    }       
       
    });
    //$(td).parent().parent().parent().hide(200);    
}

function CC_Content_DeleteComment(td, id) 
{       
    $.ajax({
    type: "POST",
    url: "/WebServices/Content.asmx/DeleteContentComment",
    contentType: "application/json; charset=utf-8",
    data: "{'contentCommentId': " + id + "}",
    dataType: "json",
    cache: false,
    success: function(msg) {                
        var r = eval('(' + msg + ')');      
                    
        if(r.Success == 1) {                                    
            $(td).parent().parent().parent().parent().hide(200); 
        } else {
        }
    }       
       
    });    
}

