function topOfElement(elementId)
{
    var obj = document.getElementById(elementId);
    if (!obj)
	{
		return 0;
	}
	var offset =0;
    while (obj.offsetParent)
    {
        offset+= obj.offsetTop;
        obj = obj.offsetParent;
    }

    return (offset);
}

var BlogDisplay = {
    "ScrollToArchives" : function BlogDisplay_ScrollToArchives()
    {
        scrollTo(0, topOfElement('archivesTop') - 10);
        if (window.domain === -1 || window.domain === 5)
        {
            return false;
        }
        else
        {
            return true;
        }
    },
    "toggleArchive" : function toggleArchive(premiumBlogID, year, month)
    {
        var id;
		var imageId;
        if (!!month)
        {
            id = year + '_' + month + '_postList';
			imageId = year+'_' +month+'_imageTag';
        }
        else
        {
            id = year + '_postList';
			imageId = year+'_imageTag';
        }
        var ele = document.getElementById(id);
        if (!!ele)
        {
            if (ele.style.display == 'none')
            {
			    var image = document.getElementById(imageId);
                if (!!month && ele.innerHTML === '')
                {
			        var params = {};
			        params['pblogid'] = premiumBlogID;
			        params['year'] = year;
			        params['month'] = month;
    			    
                    new Ajax.Updater(id, 'ArchiveBlogListHandler.ashx',
                        {
                            "method" : "post",
                            "parameters" : params,
                            "onSuccess" : function(){ele.style.display = 'block'; image.className="icon_arrow_blue_down";}
                        });
                }
                else
                {
                    ele.style.display = 'block';
					if (image)
					{
						image.className="icon_arrow_blue_down";
					}
                }
            }
            else
            {
                ele.style.display = 'none';
				var image = document.getElementById(imageId);
				if (image)
				{
					image.className="icon_arrow_blue_up";
				}
            }
        }
    },
	"scrollToPreview" : function scrollToPreview(element)
	{
		window.scrollTo(0,topOfElement(element));
	},
	"scrollToMogu" : function()
	{
		if (typeof isPOPopped != "undefined" && !!isPOPopped)
		{
			AnimObject.startAnim();
		}
		else
		{
			window.scrollTo(0,topOfElement('PurchasingOpportunity'));
			if (useAnchors)
			{
			    return true;
			}
		}
		return false;
	},
	"GoToSA" : function GoToSA(url)
	{
		window.location = url;
		parent.browser.bringToFocus();
	},
	"CloseBlog" : function BlogDisplay_CloseBlog()
	{
		if(window == window.top)
		{
			window.location = "http://www.fanbox.com/socnet/Desktop.aspx?skipSplash=1&opg=http%3A%2F%2Fprofile.fanbox.com%2FPremiumBlogs%2FAPB_SA.aspx";
		}
		else
		{
			var windowID = BlogDisplay.GetCurrentWindowID();
			if(!(isNaN(windowID)))
			{
		        window.parent.setfocus('',false);
				window.parent.WindowManager.GetWindowByWindowID(windowID).Close();
			}
			else
			{
				var problem = new Error();
				problem.message = "The window cannot be closed because the window ID is absent.";
				throw problem;
			}
		}
	},
	"TryCloseBlog" : function BlogDisplay_TryCloseBlog()
	{
	    if (userHasRated)
	    {
	        return true;
	    }
	    else
	    {
	        BlogDisplay.ShowRatingDiv(true);
	        return false;
	    }
	},
	"GetCurrentWindowID" : function BlogDisplay_GetCurrentWindowID()
	{
		var windowName = window.name;
		var windowIndex = windowName.indexOf("frm");
		if(windowIndex !== -1)
		{
			return parseInt(windowName.substr(windowIndex + 3), 10);
		}
		else
		{
			return NaN;
		}
	},
	"UpdateDesktopWindowTitleBar" : function BlogDisplay_UpdateDesktopWindowTitleBar(title)
	{
		if(window != window.top)
		{
			var windowID = BlogDisplay.GetCurrentWindowID();
			if(!(isNaN(windowID)))
			{
				window.parent.WindowManager.GetWindowByWindowID(windowID).SetTitle(title);
			}
			else
			{
				var problem = new Error();
				problem.message = "The window title cannot be changed because the window ID is absent.";
				throw problem;
			}
		}
	},
	"ShowPosts" : function BlogDisplay_ShowPosts()
	{
		window.document.getElementById("BlogPostsSection").style.display = "block";
		window.document.getElementById("ShopperBlogPreviewShowSection").style.display = "none";
		window.document.getElementById("ShopperBlogPreviewHideSection").style.display = "block";
		window.document.getElementById("showPreview").style.display = "none";
		window.document.getElementById("hidePreview").style.display = "block";
		window.document.getElementById("BlogTagSection").style.display = "block";
		window.document.getElementById("ArchiveContainer").style.display = "block";
		window.document.getElementById("BlogPostsVisibleLandmark").nextSibling.checked = true;
		return false;
	},
	"HidePosts" : function BlogDisplay_HidePosts()
	{
		window.document.getElementById("BlogPostsSection").style.display = "none";
		window.document.getElementById("ShopperBlogPreviewShowSection").style.display = "block";
		window.document.getElementById("ShopperBlogPreviewHideSection").style.display = "none";
		window.document.getElementById("showPreview").style.display = "block";
		window.document.getElementById("hidePreview").style.display = "none";
		window.document.getElementById("BlogTagSection").style.display = "none";
		window.document.getElementById("ArchiveContainer").style.display = "none";
		window.document.getElementById("BlogPostsVisibleLandmark").nextSibling.checked = false;
		return false;
	},
	"ShowRatingDiv" : function BlogDisplay_ShowRatingDiv(closeAfter)
	{
		var currentRating = parseInt(window.document.getElementById("ParticipantBlogPersonalRatingCurrentScore").value, 10);
		if(currentRating === 0)
		{
			window.document.getElementById("ParticipantBlogPersonalRatingNewIntroduction").style.display = "block";
			window.document.getElementById("ParticipantPersonalBlogRatingNewLabel").style.display = "inline";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingIntroduction").style.display = "none";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingInstruction").style.visibility = "hidden";
		}
		else
		{
			window.document.getElementById("ParticipantBlogPersonalRatingNewIntroduction").style.display = "none";
			window.document.getElementById("ParticipantPersonalBlogRatingNewLabel").style.display = "none";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingIntroduction").style.display = "block";
			window.document.getElementById("ParticipantBlogPersonalRatingExistingInstruction").style.visibility = "visible";
		}
		window.document.getElementById("ParticipantBlogPersonalReviewSection").style.display = "none";
		if(window.document.getElementById("ParticipantBlogPersonalRatingReviewAllowed").value === "1")
		{
			window.document.getElementById("ParticipantBlogPersonalReviewInvitationLink").style.display = "block";
			window.document.getElementById("ParticipantBlogPersonalReviewClosedMessage").style.display = "none";
		}
		else
		{
			window.document.getElementById("ParticipantBlogPersonalReviewInvitationLink").style.display = "none";
			window.document.getElementById("ParticipantBlogPersonalReviewClosedMessage").style.display = "block";
		}
		window.document.getElementById("ParticipantBlogPersonalReview").value = "";
		window.document.getElementById("ParticipantBlogPersonalReviewFeedback").firstChild.data = "";
		window.document.getElementById("ParticipantBlogPersonalRatingCurtainBackdrop").style.height = "162px";
		this.ChooseRating(currentRating);
		var dialog = window.document.getElementById("ParticipantBlogPersonalRatingChild").parentNode;
		dialog.style.display = "block";
		this.ShowModalCurtain();
		BlogDisplay.ShowRating = !!closeAfter;
		window.closeAfter = !!closeAfter
		return false;
	},
	"HideRatingDiv" : function BlogDisplay_HideRatingDiv()
	{
		var dialog = window.document.getElementById("ParticipantBlogPersonalRatingChild").parentNode;
		dialog.style.display = "none";
		this.HideModalCurtain();
		if (!!window.closeAfter)
		{
		    BlogDisplay.CloseBlog();
		}
		return false;
	},
	"ShowReadReviewDiv" : function BlogDisplay_ShowReadReviewDiv()
	{
	    var dialog = window.document.getElementById("reviewCollectionDiv");
		dialog.style.display = "block";				
		window.document.getElementById("reviewCollectionIframe").src= "/ReviewCollection.aspx?pbid="+blogId+"&page="+page+"&link="+link+"&src="+src+"&pageno=1";
		this.ShowModalCurtain();
		return false;
	},	
	"HideReadReviewDiv" : function BlogDisplay_HideReadReviewDiv()
	{
		var dialog = window.document.getElementById("reviewCollectionDiv");
		dialog.style.display = "none";
		window.document.getElementById("reviewCollectionIframe").src="about:blank";
		this.HideModalCurtain();
		return false;
	},
	"SetDefaultRating" : function BlogDisplay_SetDefaultRating(rating)
	{
		window.document.getElementById("ParticipantBlogPersonalRatingExistingMeterFilling").style.width = (Math.round(rating * 100 / 5)).toString() + "%";
	},
	"ChooseRating" : function BlogDisplay_ChooseRating(rating)
	{
		window.document.getElementById("ParticipantBlogPersonalRatingNewScore").value = rating.toString();
		this.SetDefaultRating(rating);
		return false;
	},
	"SaveRating" : function BlogDisplay_SaveRating(premiumBlogID, rating, review, formToken, successFunction, failureFunction)
	{
		var ratingProvided = (rating > 0);
		var reviewProvided = (review.length !== 0);
		var transportPlacebo = {"responseText" : ""};
		if(ratingProvided)
		{
			new Ajax.Request("BlogDisplay.ashx",
			{
				"method" : "post",
				"parameters" : "action=rate&pbid=" + encodeURIComponent(premiumBlogID.toString()) + "&rating=" + encodeURIComponent(rating.toString()) + "&review=" + encodeURIComponent(review) + "&token=" + encodeURIComponent(formToken),
				"onSuccess" : successFunction,
				"onFailure" : failureFunction
			});
		}
		else
		{
			if(reviewProvided)
			{
				transportPlacebo.responseText = "You must enter a rating with your review.";
			}
		}
		if(!!failureFunction)
		{
			failureFunction(transportPlacebo);
		}
	},
	"ShowPersonalReviewSection" : function BlogDisplay_ShowPersonalReviewSection()
	{
		window.document.getElementById("ParticipantBlogPersonalRatingCurtainBackdrop").style.height = "278px";
		window.document.getElementById("ParticipantBlogPersonalReviewSection").style.display = "block";
		window.document.getElementById("ParticipantBlogPersonalReviewInvitationLink").style.display = "none";
		window.document.getElementById("ParticipantBlogPersonalReview").focus();
		return false;
	},
	"ShowModalCurtain" : function BlogDisplay_ShowModalCurtain()
	{

		var ele= window.document.getElementById("reviewCollectionDiv");
		if (ele != null)
		{
			window.document.body.appendChild(ele);
		}

	    
		var curtain = window.document.getElementById("ModalCurtain");
		curtain.style.display = "block";
		if(curtain.offsetHeight < 20)
		{
			curtain.style.height = Math.max(window.document.documentElement.scrollHeight, window.document.documentElement.offsetHeight) + "px";
			curtain.style.width = Math.max(window.document.documentElement.scrollWidth, window.document.documentElement.clientWidth) + "px";
		}

		/* Lure the caret away from framed text boxes in Internet Explorer to prevent its blinking from lingering. */
		var frames = window.document.getElementsByName("mogubox");
		if(frames.length !== 0)
		{
			var field = window.document.createElement("INPUT");
			field.className = "offscreen";
			window.document.body.appendChild(field);
			field.focus();
			window.document.body.removeChild(field);
		}
		HideClipboards();
	},
	"HideModalCurtain" : function BlogDisplay_HideModalCurtain()
	{
		window.document.getElementById("ModalCurtain").style.display = "none";
		ShowClipboards();
	},
	"ClickFollow" : function(e)
	{
	    var targ = jQuery('#' + followSection);
	    targ.click(function(){});
	    var params = {}
	    if (targ.hasClass('xmg_new'))
	    {
	        params['action'] = 'follow';
	    }
	    else
	    {
	        params['action'] = 'unfollow';
	    }
	    params['blogid'] = blogId;
	    jQuery.ajax({
	        type: 'post',
	        url: 'followblog.ashx',
	        data: params,
	        dataType: 'json',
	        success: BlogDisplay.ClickFollowCallback
	    });
	},
	"ClickFollowCallback" : function(jsonData)
	{
	    if (jsonData.success)
	    {
	        BlogDisplay.ShowFollowPopUp(jsonData.action);
	        BlogDisplay.ToggleFollowBtn();
	    }
	},
	"ToggleFollowBtn" : function()
	{
	    var newClass, oldClass, newVal, newTitle;
	    var btn = jQuery('#' + followBtn);
	    var container = jQuery('#' + followSection);
	    if (container.hasClass('xmg_new'))
	    {
	        oldClass = 'xmg_new';
	        newClass = 'xag_new';
            newVal = 'Unfollow this blog';
            newTitle = 'No longer receive posts from this blog via email';
	    }
	    else
	    {
	        oldClass = 'xag_new';
	        newClass = 'xmg_new';
	        newVal = 'Follow this blog';
            newTitle = 'New posts from this blog will be sent to you via email';
	    }
	    container.removeClass(oldClass).addClass(newClass).click(BlogDisplay.ClickFollow);
	    btn.attr('title',newTitle).val(newVal);
	},
	"ShowFollowPopUp" : function(action)
	{
	    if (showFollowPopUp)
	    {
	        if(action == 'follow')
	        {
				jQuery('#followPopUpText').text('You will receive new posts from this blog via email.');
	        }
	        else
	        {
				jQuery('#followPopUpText').text('You will no longer receive new posts from this blog via email.');
	        }
	        jQuery('#followPopUp').show();
	        BlogDisplay.PopUpTimer = setTimeout(BlogDisplay.AnimateHideFollowPopUp, 3000);
	    }
	},
	"HideFollowPopUp" : function(checkBox)
	{
	    if (!isNaN(BlogDisplay.PopUpTimer))
	    {
	        clearTimeout(BlogDisplay.PopUpTimer);
	    }
	    if (!!checkBox && jQuery('#followPopUpdonotshowagain').attr('checked'))
	    {
	        var rn=Math.random()*10000000;
            var tempscript = document.createElement("script");
            tempscript.src='http://www.fanbox.com/socnet/handlers/FeatureHandler.ashx?fid=12&stts=0&r='+rn;
            window.document.body.appendChild(tempscript); 
	        showFollowPopUp = false;
	    }
	    jQuery('#followPopUp').fadeTo(0, 100).hide();
	},
	"AnimateHideFollowPopUp" : function()
	{
	    jQuery('#followPopUp').fadeTo(1000, 0, BlogDisplay.HideFollowPopUp)
	}
};

var GetQS = GetQS || function()
{
    if (!!window.document)
    {
        return window.document.location.search;
    }
    else
    {
        return window.location.search;
    }
};

//check qs to see what domain we are in
if (!window.domain)
{
    var loc = GetQS().indexOf('domain=');
    if (loc !== -1)
    {
        var value = GetQS().substring(loc +7);
        if (value.indexOf('&') !== -1)
        {
            value = value.substring(0,value.indexOf('&'));
        }
        window.domain = parseInt(value,10);
    }
	else
	{
		window.domain = -1;
	}
}
/* Imitates the actual PBlogs object for the desktop (PBlogs.js).  Please synchronize. */
var PBlogs = {
	"ShowShareDiv" : function PBlogs_ShowShareDiv()
	{
	    if (window.domain !== -1 && window.domain !== 5)
	    {
	        document.getElementById('divShare').style.display='block';
	        ShowModalCurtain();
	    }
	    else
	    {
		    BlogDisplay.ShowModalCurtain();
		    try
		    {
			    if(window != window.top)
			    {
				    window.top.coverPageWithDarkness();
			    }
		    }
		    catch(problem)
		    {
		    }

		    if (!PBlogs._shareDiv)
		    {
			    var ifr = document.createElement('script');
			    ifr.type = 'text/javascript';
			    ifr.src = 'http://files.fbstatic.com/' + $('MasterVersion').value + '/socnet/ajaxdivs/pblog_ShareDiv.js';
			    document.getElementsByTagName('head')[0].appendChild(ifr);
		    }
		    if (!!PBlogs._shareDiv)
		    {
			    PBlogs._finishShareDiv();
		    }
		}
	},
	"_finishShareDiv" : function PBlogs_FinishShareDiv()
	{
	    if (window.domain === -1 || window.domain === 5)
		{
		    PBlogs._uniqueURLInput.value = $("BlogDisplayURL").value;
		    PBlogs._shareDiv.style.visibility = 'visible';
		    PBlogs._shareDiv.style.zIndex = 100000;
		}
		else
		{
		    return;
		}
	},
	"HideShareDiv" : function()
	{
	    if (window.domain !== -1 && window.domain !== 5)
	    {
	        HideModalCurtain();
	        document.getElementById('divShare').style.display='none';
	    }
	    else
	    {
		    BlogDisplay.HideModalCurtain();
		    try
		    {
			    if(window != window.top)
			    {
				    if(!!window.top.uncoverPageFromDarkness)
				    {
					    window.top.uncoverPageFromDarkness()
				    }
			    }
		    }
		    catch(problem)
		    {
		    }

		    PBlogs._shareDiv.style.visibility = 'hidden';
	    }
	},	
	"ShowLearnMoreDiv" : function PBlogs_ShowLearnMoreDiv(state, pblogid)
	{
		if (state != 'import' && state != 'promote')
		{
			return;
		}
		PBlogs.LearnMoreDivState = state;
		PBlogs.PBlogId = pblogid;
		PBlogs.ShareURL = $("BlogDisplayURL").value;
		
		BlogDisplay.ShowModalCurtain();
		try
		{
			if(window != window.top)
			{
				window.top.coverPageWithDarkness();
			}
		}
		catch(problem)
		{
		}

		if (!PBlogs._learnMoreDiv)
		{
			var ifr = document.createElement('script');
			ifr.type = 'text/javascript';
			ifr.src = 'http://files.fbstatic.com/' + $('MasterVersion').value + '/socnet/ajaxdivs/pblog_LearnMoreDiv.js';

			document.getElementsByTagName('head')[0].appendChild(ifr);
		}
		if (!!PBlogs._learnMoreDiv)
		{
			PBlogs._finishLearnMoreDiv();
		}
	},
	"_finishLearnMoreDiv" : function PBlogs_FinishLearnMoreDiv()
	{
		if (PBlogs.LearnMoreDivState == 'import')
		{
			Blogs._learnMoreShadow.style.height = '430px';
			PBlogs._learnMoreTitle.innerHTML = 'Import your blog';
			PBlogs._learnMoreImportContent.style.display = 'block';
			PBlogs._learnMorePromoteContent.style.display = 'none';
		}
		else
		{
			PBlogs._learnMoreShadow.style.height = '450px';
			PBlogs._learnMoreTitle.innerHTML = 'Promote your blog!';
			PBlogs._learnMoreURL.innerHTML = PBlogs.ShareURL;
			PBlogs._learnMoreImportContent.style.display = 'none';
			PBlogs._learnMorePromoteContent.style.display = 'block';
		}
		PBlogs._learnMoreDiv.style.visibility = 'visible';
		PBlogs._learnMoreDiv.style.zIndex = 100000;
	},
	"HideLearnMoreDiv" : function()
	{
		BlogDisplay.HideModalCurtain();
		try
		{
			if(window != window.top)
			{
				if(!!window.top.uncoverPageFromDarkness)
				{
					window.top.uncoverPageFromDarkness()
				}
			}
		}
		catch(problem)
		{
		}

		PBlogs._learnMoreDiv.style.visibility = 'hidden';
	},
	"ShowSettingsDiv" : function(PBlogId, link, source, pageid)
    {
        if (window.location.pathname.toLowerCase().indexOf('editor') >= 0 || PBlogId > 0)
        {
	        try
	        {
		        PBlogs.PBlogId = PBlogId;
		        PBlogs.SettingsLink = link;
		        PBlogs.SettingsSrc = source;
		        PBlogs.SettingsPgid = pageid;
        		
		        if (!PBlogs._SettingsDiv)
		        {
			        var ifr = document.createElement('script');
		            ifr.type = 'text/javascript';
				    var source = 'http://files.fbstatic.com/';
				    if (window.domain == -1 || window.domain == 5)
				    {
					    source += top.$('MasterVersion').value;
				    }
			        else
			        {
                        recordActionStatistic(1, 19);
					    source += document.getElementById('MasterVersion').value;
			        }
			        source += '/socnet/ajaxdivs/pblog_SettingsDiv.js'
			        ifr.src = source;	    
    		        
		            document.getElementsByTagName('head')[0].appendChild(ifr);
		        }
		        else
		        {
		            PBlogs._finishSettingsDiv();
		        }
	        }
	        catch(e)
	        {
		        HideModalCurtain();
	        }
        }
        else
        {
            window.open('http://blogs.fanbox.com/Editor.aspx?mode=LW&domain=' + window.domain, '_blank');
        }
    },
    "_finishSettingsDiv" : function()
    {
        if (!PBlogs._SettingsDiv)
        {
            return;
        }
	    var ifr = document.getElementById('SettingsDivIFrame');
	    var ifrsrc = "http://profile.fanbox.com/PremiumBlogs/SettingsDiv.aspx?currStep=0&nextStep=1&PBlogId=" + PBlogs.PBlogId + "&lkid=" + PBlogs.SettingsLink + "&src=" + PBlogs.SettingsSrc + "&pageid=" + PBlogs.SettingsPgid;
		if (window.domain > -1)
		{
			var qString = window.location.search;
			ifrsrc +="&domain=" + window.domain;
			if (window.domain === 2 && !!window.getViewerID) //myspace
			{
			    var errorDiv = document.getElementById('tooManyBlogsDiv');
			    ifrsrc += '&euserid=' + getViewerID();
                if (!!errorDiv)
                {
                    errorDiv.style.visibility = 'hidden';
                }
			    PBlogs._SettingsDiv.style.top = '200px';
			    PBlogs._SettingsDiv.style.marginTop = '0px';
			    if (!!viewerInfo)
			    {
				    ifrsrc += '&viewername=' + viewerInfo.name;
				}
			}
			else if (window.domain === 3 && !!window.FB_RequireFeatures) // facebook
			{
	            FB_RequireFeatures(["Api"], function() {
		            var api = new FB.ApiClient(api_key, 'channel.htm', null);
			        ifrsrc += '&euserid=' + api.get_session().uid;
			        var errorDiv = document.getElementById('tooManyBlogsDiv');
                    if (!!errorDiv)
                    {
                        errorDiv.style.visibility = 'hidden';
                    }
			        PBlogs._SettingsDiv.style.top = '200px';
			        PBlogs._SettingsDiv.style.marginTop = '0px';
				    ifrsrc += '&viewername=' + window.senderName;
				});
			}
		}
	    ifr.src = ifrsrc;
        PBlogs._SettingsDiv.style.visibility = 'visible';
	    ShowModalCurtain();
    },
    "HideSettingsDiv" : function()
    {
        PBlogs._SettingsDiv.style.visibility = 'hidden';
	    var ifr = document.getElementById('SettingsDivIFrame');
	    ifr.src = "";
	    HideModalCurtain();
    },
    "RemoveSettingsSrc" : function()
    {
	    var ifr = document.getElementById('SettingsDivIFrame');
	    ifr.src = "about:blank";
    },
    "ShowTooManyBlogsError" : function()
    {
        CanvasHeaderCall(null, true);
    },
    "DeletePrompt_BlogId" : -1,
	"DeletePrompt_Ticket" : '',
	"Show_DeletePrompt_Initial" : function( title, blogId )
	{
		title = title || '';
		PBlogs.DeletePrompt_BlogId = blogId;
		
		if (!PBlogs._DeletePrompt_Initial)
		{
			PBlogs._DeletePrompt_Initial = document.createElement('div');
			PBlogs._DeletePrompt_Initial.id = 'pblogs_DeletePrompt_Initial';
			PBlogs._DeletePrompt_Initial.style.visibility = 'hidden';
			PBlogs._DeletePrompt_Initial.style.zIndex = '11003';
			PBlogs._DeletePrompt_Initial.style.position = 'absolute';
			PBlogs._DeletePrompt_Initial.style.left = '50%';
			PBlogs._DeletePrompt_Initial.style.marginLeft = '-200px';
			PBlogs._DeletePrompt_Initial.style.width = '394px';
			PBlogs._DeletePrompt_Initial.style.height = '199px';
			if (window.domain === 2 || window.domain === 3)
			{
			    PBlogs._DeletePrompt_Initial.style.top = '200px';
			    PBlogs._DeletePrompt_Initial.style.marginTop = '0px';
				document.getElementById('content_wrapper').appendChild(PBlogs._DeletePrompt_Initial);
			}
			else
			{
				$('MasterDiv').appendChild(PBlogs._DeletePrompt_Initial);
			}
		}
	
		PBlogs._DeletePrompt_Initial.innerHTML = '<div style="position: absolute; top: 0; left: 0; width: 394px; z-index: 0; filter: alpha(opacity=50); -moz-opacity: 0.5; opacity: 0.5; zoom: 100%;"><div style=""><b class="dwtop"><b class="dw1"></b><b class="dw2"></b><b class="dw3"></b><b class="dw4"></b><b class="dw5"></b></b></div><div style="background-color: #434343; height: 196px;"></div><div style=""><b class="dwbottom"><b class="dw5"></b><b class="dw4"></b><b class="dw3"></b><b class="dw2"></b><b class="dw1"></b></b></div></div><div style="position: absolute; top: 10px; left: 0; width: 394px; z-index: 1;"><div class="border_blk" style="width:372px; margin: 0 auto; border-width:0px 1px 1px 1px; background-color: #fff;"><div align="left" class="widget_header" style="border-width: 1px 0;"><div class="text_12_drk_bold" style="float: left;">Are You Sure?</div><div class="btn btn_close"><a href="#" onclick="PBlogs.Hide_DeletePrompt_Initial();"><img src="http://profile.fanbox.com/themes/_images/tpxl.gif" border="0" /></a></div><div class="div_clear"></div></div><div style="padding: 14px 14px; zoom: 100%; height: 130px; text-align: left;"><div class="text_18_drk" style="font-weight:bold;color:#333;font-size:18px;text-align: center; margin-bottom: 14px;overflow:hidden;height:42px;width:344px;">You are about to delete<br />##TITLE##.</div><div class="text_18_drk" style="font-weight:bold;color:#333;font-size:18px;text-align: center;">Are you sure?</div><div style="width: 234px; margin: 20px auto 0;"><div class="btnsq" style="width: 112px; margin-right: 10px;"><input type="button" onclick="PBlogs.DeletePrompt_Initial_YesClick();" class="btn_grn_sq_m" value="YES (Delete)" style="width: 112px;" /></div><div class="btnsq" style="width: 112px;"><input type="button" class="btn_gry_sq_m" value="NO (Do not delete)" style="width: 112px;" onclick="PBlogs.Hide_DeletePrompt_Initial();" /></div><div class="div_clear"></div></div></div></div></div>'.replace( '##TITLE##', title );
		PBlogs._finish_DeletePrompt_Initial();
	},
	"_finish_DeletePrompt_Initial" : function()
	{
		ShowModalCurtain();
        PBlogs._DeletePrompt_Initial.style.visibility = 'visible';
	},
	"Hide_DeletePrompt_Initial" : function()
	{
		PBlogs._DeletePrompt_Initial.style.visibility = 'hidden';
		PBlogs._finishSettingsDiv();
	},
	"DeletePrompt_Initial_YesClick" : function()
	{
		PBlogs._DeletePrompt_Initial.style.visibility = 'hidden';
		ajaxGo('/PBLogHandler.ashx?cmd=AttemptDeleteBlog&pbid=' + PBlogs.DeletePrompt_BlogId, PBlogs.DeletePrompt_Detailed_Show);
	},
	"DeletePrompt_Detailed_Show" : function( response )
	{
        if (response.readyState !== 4)
        {
            return;
        }
		
		var data;
		
		if (window.domain === 2)
		{
		    data = gadgets.json.parse(response.responseText);
		}
		else
		{
		    eval("data = " + response.responseText);
		}
		var args = {},
		subscribers = ( ( +data.subscriberCount ) || 0 ),
		shoutouts = ( ( +data.shoutoutCount ) || 0 ),
		ticket = ( ( data.ticket ) || '' );

		if( shoutouts === 0 && subscribers === 0 )
		{
			if (window.domain === 2 || window.domain === 3)
			{
		        HideModalCurtain();
		        CanvasHeaderCall();
			/*	var manage = document.getElementById('iframe_wrapper');
				manage.firstChild.src =
					'http://blogs.fanbox.com/Manage.aspx?delete=true&domain=' + window.domain +
					'&euserid=' + encodeURIComponent(getViewerID()) +'&viewername=' + getViewerName();*/
			}
			else
			{
				top.browser.changeSrc( 'http://profile.fanbox.com/PremiumBlogs/Manage.aspx?delete=true' );
			}
			return;
		}
		else
		{
			args.truncatedTitle = data.truncatedTitle;
			PBlogs.DeletePrompt_Ticket = ticket;

			if( shoutouts > 0 )
			{
				var som = '<span>&bull; <span>##COUNT##</span>&nbsp;Shout-Out##PLURAL##</span>';
				args.shoutoutsMarkup = som.replace( '##COUNT##', shoutouts ).replace( '##PLURAL##', ( shoutouts === 1 ? '' : 's' ) );
			}
			var sm;
			if( subscribers > 0 && subscribers < 6 )
			{
				sm = '<span>&bull; <span>##COUNT##</span>&nbsp;Subscriber##PLURAL##</span>';
				args.subscribersMarkup = sm.replace( '##COUNT##', subscribers ).replace( '##PLURAL##', ( subscribers === 1 ? '' : 's' ) );
			}
			else if(subscribers >= 6)
			{
				args.subscribersMarkup = '<span>&bull; More than 5 </span> <span>Subscribers</span>';
			}
			else
			{
				args.subscribersMarkup = '';
			}
			if( subscribers > 0 && shoutouts > 0 )
			{
				args.separator = '<br />';
			}
		}

		if (!PBlogs._DeletePrompt_Detailed)
		{
			PBlogs._DeletePrompt_Detailed = document.createElement('div');
			PBlogs._DeletePrompt_Detailed.id = 'pblogs_DeletePrompt_Detailed';
			PBlogs._DeletePrompt_Detailed.style.visibility = 'hidden';
			PBlogs._DeletePrompt_Detailed.style.zIndex = '11003';
			PBlogs._DeletePrompt_Detailed.style.position = 'absolute';
			PBlogs._DeletePrompt_Detailed.style.top = '50%';
			PBlogs._DeletePrompt_Detailed.style.left = '50%';
			PBlogs._DeletePrompt_Detailed.style.marginTop = '-120px';
			PBlogs._DeletePrompt_Detailed.style.marginLeft = '-205px';
			PBlogs._DeletePrompt_Detailed.style.width = '394px';
			PBlogs._DeletePrompt_Detailed.style.height = '199px';
			if (window.domain === 2 || window.domain === 3)
			{
			    PBlogs._DeletePrompt_Detailed.style.top = '200px';
			    PBlogs._DeletePrompt_Detailed.style.marginTop = '0px';
				document.getElementById('content_wrapper').appendChild(PBlogs._DeletePrompt_Detailed);
			}
			else
			{
				$('MasterDiv').appendChild(PBlogs._DeletePrompt_Detailed);
			}
		}

		var markup = '<div style="position:absolute;top:0;margin-top:0;left:0;margin-left:0;width: 394px;"><div style="position: absolute; top: 0; left: 0; width: 394px; height: 230px; z-index: 0; filter: alpha(opacity=50); -moz-opacity: 0.5; opacity: 0.5; zoom: 100%;"><div style=""><b class="dwtop"><b class="dw1"></b><b class="dw2"></b><b class="dw3"></b><b class="dw4"></b><b class="dw5"></b></b></div><div style="background-color: #434343; height: 220px;"></div><div style=""><b class="dwbottom"><b class="dw5"></b><b class="dw4"></b><b class="dw3"></b><b class="dw2"></b><b class="dw1"></b></b></div></div><div style="position: absolute; top: 10px; left: 0; width: 394px; height: 210px; z-index: 1;"><div class="border_blk" style="width:372px; margin: 0 auto; border-width:0px 1px 1px 1px; background-color: #fff;"><div align="left" class="widget_header" style="border-width: 1px 0;"><div class="text_12_drk_bold" style="float: left;">Are You Sure?</div><div class="btn btn_close"><a href="#" onclick="PBlogs.DeletePrompt_Detailed_Hide();"><img src="http://files.fbstatic.com/themes/_images/tpxl.gif" border="0" /></a></div><div class="div_clear"></div></div><div style="padding: 14px 14px; zoom: 100%; height: 157px; text-align: left;"><div class="text_18_drk" style="font-weight:bold;color:#333;font-size:18px;text-align: center; margin-bottom: 14px;"><div id="detailed_title" style="overflow:hidden;width:344px;">##TITLE##</div> currently has:</div><div class="text_18_drk" style="font-weight:bold;color:#333;font-size:18px;text-align: left; margin: 0 0 14px 100px;">##SHOUTOUTS####SEPARATOR####SUBSCRIBERS##</div><div class="text_18_drk" style="font-weight:bold;color:#333;font-size:18px;text-align: center;">Are you sure you want to delete?</div><div style="width: 234px; margin: 5px auto 0;"><div class="btnsq" style="width: 112px; margin-right: 10px;"><input onclick="PBlogs.DeletePrompt_Detailed_YesClick();" type="button" class="btn_grn_sq_m" value="YES (Delete)" style="width: 112px;" /></div><div class="btnsq" style="width: 112px;"><input onclick="PBlogs.DeletePrompt_Detailed_Hide();" type="button" class="btn_gry_sq_m" value="NO (Do not delete)" style="width: 112px;" /></div><div class="div_clear"></div></div></div></div></div></div>';

		PBlogs._DeletePrompt_Detailed.innerHTML = markup.replace( '##TITLE##', args.truncatedTitle || '' ).replace( '##SHOUTOUTS##', args.shoutoutsMarkup || '' ).replace( '##SEPARATOR##', args.separator || '' ).replace( '##SUBSCRIBERS##', args.subscribersMarkup || '' );

		PBlogs.DeletePrompt_Detailed_Finish();
	},
	"DeletePrompt_Detailed_Finish" : function()
	{
	    if (window.domain === 2 || window.domain === 3)
	    {
		    ShowModalCurtain();
		}
		else
		{
		    PBlogs.ShowModalCurtain();
		}
		PBlogs._DeletePrompt_Detailed.style.visibility = 'visible';

		var titleDiv = document.getElementById('detailed_title');
		if (parseInt(titleDiv.parentElement.offsetHeight,10) > 42)
		{
			titleDiv.style.height='21px';
		}	
	},
	"DeletePrompt_Detailed_Hide" : function()
	{
		PBlogs._DeletePrompt_Detailed.style.visibility = 'hidden';
		PBlogs._finishSettingsDiv();
	},
	"DeletePrompt_Detailed_YesClick" : function()
	{
		PBlogs._DeletePrompt_Detailed.style.visibility = 'hidden';
	
		var params =
		{
			cmd : 'ConfirmDeleteBlog',
			pbid : PBlogs.DeletePrompt_BlogId,
			'ticket' : PBlogs.DeletePrompt_Ticket
		};
	
	
		if (window.domain === 2)
		{
	        HideModalCurtain();
	        CanvasHeaderCall();
	        ajaxGo('/PBLogHandler.ashx?cmd=ConfirmDeleteBlog&pbid=' + PBlogs.DeletePrompt_BlogId + '&ticket=' + PBlogs.DeletePrompt_Ticket);
			/*var manage = document.getElementById('iframe_wrapper');
			manage.firstChild.src =
				'http://blogs.fanbox.com/Manage.aspx?delete=true&domain=' + window.domain +
				'&euserid=' + encodeURIComponent(getViewerID()) +'&viewername=' + getViewerName();
			manage.firstChild.onload = new function()
			{
				DisplayMSTabs('top_earners_wrapper');
			};*/
		}
		else if (window.domain === 3)
		{
	        HideModalCurtain();
	        CanvasHeaderCall();
	        ajaxGo('/PBLogHandler.ashx?cmd=ConfirmDeleteBlog&pbid=' + PBlogs.DeletePrompt_BlogId + '&ticket=' + PBlogs.DeletePrompt_Ticket);
		}
		else
		{
		    new Ajax.Request( 'http://www.fanbox.com/socnet/handlers/PBLogHandler.ashx',
		    {
			    method : 'post',
			    parameters : params
		    });
			top.browser.changeSrc( 'http://profile.fanbox.com/PremiumBlogs/Manage.aspx?delete=true' );
		}
	}
};

function tagClicked(tagName, tagId, blogId)
{
    var params = {};
    params['blogid'] = blogId;
    params['tagid'] = tagId;
    params['source'] = 'BlogCanvas';
    new Ajax.Request('PBlogTagStatHandler.ashx', 
        {
            'method' : 'post',
            'parameters' : params
        }
    );
    if (window.domain === 2)
    {
        parent.tagName = tagName;
        parent.DisplayMSTabs('apb_wrapper');
    }
    else if (window.domain === 3)
    {
        parent.tagName = tagName;
        parent.DisplayTabs('apb_wrapper');
    }
    else
    {
        var url = 'http://profile.fanbox.com/PremiumBlogs/APB_SA.aspx?TagName=' + encodeURIComponent(tagName) + '&jump=1';
        ProfileLink_Click(url);
    }
}

function hideAboutDiv()
{
	var show = document.getElementById('blogDescriptionTrunc');
	var hide = document.getElementById('blogDescriptionFull');
	if (!!hide && !!show)
	{
		hide.style.display='none';
		show.style.display='block';
	}
}
function showAboutDiv()
{
	var hide = document.getElementById('blogDescriptionTrunc');
	var show = document.getElementById('blogDescriptionFull');
	if (!!hide && !!show)
	{
		show.style.display='block';
		hide.style.display='none';
	}
}

function ProfileLink_Click(url)
{
    var link = false;
    if (!url)
    {
        url = this.href;
        link = true;
    }
	var browser;
	try
	{
		browser = window.top.browser;
	}
	catch(problem)
	{
	}

	if(!!browser)
	{
		browser.openBrowser(url);
		browser.bringToFocus();
		return false;
	}
	else if (link && (window.domain === -1 || window.domain === 5))
	{
		this.href = "http://www.fanbox.com/socnet/Desktop.aspx?skipSplash=1&opg=" + encodeURIComponent(url);
		this.target = "_top";
		return true;
	}
	else if (!link && (window.domain === -1 || window.domain === 5))
	{
	    top.window.location = "http://www.fanbox.com/socnet/Desktop.aspx?skipSplash=1&opg=" + encodeURIComponent(url);
	}
	else if (window.domain !== -1 && window.domain !== 5)
	{
        url += '&domain='+window.domain;
        var qs = GetQS();
        var start = qs.indexOf('euserid=');
        var end = qs.indexOf('&',start);
        if (end === -1)
        {
            end = qs.length;
        }
        url += '&euserid=' + qs.slice(start,end);
 
	    if (link)
	    {
	        window.open(url, VL2GoController.NewWindowId || top.VL2GoController.NewWindowId);
	        return false;
	    }
	    else
	    {
	        this.href = url;
	        this.target = "_top";
	        return true;
	    }
	}
}

function RatingFormSaveButton_Click()
{
	var blogID = parseInt(window.document.getElementById("ParticipantBlogPersonalRatingBlogID").value, 10);
	var rating = parseInt(window.document.getElementById("ParticipantBlogPersonalRatingNewScore").value, 10);
	var review = window.document.getElementById("ParticipantBlogPersonalReview").value;
	var token = window.document.getElementById("ParticipantBlogPersonalRatingFormToken").value;
	this.disabled = true;
	var feedbackTextNode = window.document.getElementById("ParticipantBlogPersonalReviewFeedback").firstChild;
	feedbackTextNode.data = "";
	BlogDisplay.SaveRating(blogID, rating, review, token, RatingFormSave_Succeeded, RatingFormSave_Failed);
}

function RatingFormSave_Succeeded(transport)
{
	window.document.getElementById("ParticipantBlogPersonalRatingCurrentScore").value = transport.responseText;
	var review = window.document.getElementById("ParticipantBlogPersonalReview").value;
    userHasRated = true;
	BlogDisplay.HideRatingDiv();
	EnableRatingForm();

	if (review != "")
	{
		window.document.getElementById("ParticipantBlogPersonalRatingReviewAllowed").value = "0";
	    BlogDisplay.ShowReadReviewDiv();
	}
}

function RatingFormSave_Failed(transport)
{
	var feedbackTextNode = window.document.getElementById("ParticipantBlogPersonalReviewFeedback").firstChild;
	feedbackTextNode.data = transport.responseText;
	EnableRatingForm();
}

function EnableRatingForm()
{
	window.document.getElementById("ParticipantBlogPersonalReviewSaveButton").disabled = false;
}

function RepaintBlogRatingIE6()
{
	this.style.display = "none";
	this.style.display = "inline-block";
}

function ConfigureBlogRatingRepaintingIE6()
{
	if((window.navigator.appName === "Microsoft Internet Explorer") && (window.navigator.appVersion.indexOf("MSIE 6.") !== -1))
	{
		var links = window.document.links;
		for(var index = 0;  index < links.length;  index++)
		{
			var link = links[index];
			if(link.className.indexOf("BlogRating") !== -1)
			{
				link.onmouseout = link.onblur = RepaintBlogRatingIE6;
			}
		}
	}
}

var Clipboards = [];
function ConfigureExportToClipboardButtons()
{
	var exportLandmarks = window.document.getElementsByName("BlogPostExportLandmark");
	if(exportLandmarks.length !== 0)
	{
		if(!!window.addEventListener)
		{
			window.addEventListener("resize", ResizeClipboards, false);
		}
		else if(!!window.attachEvent)
		{
			window.attachEvent("onresize", ResizeClipboards);
		}

		for(var buttonIndex = 0;  buttonIndex < exportLandmarks.length;  buttonIndex++)
		{
			var exportLandmark = exportLandmarks[buttonIndex];
			var exportButton = exportLandmark.nextSibling;
			var exportTextHolder = exportButton.nextSibling;

			var clipboard = new ZeroClipboard.Client();
			Clipboards.push(clipboard);
			clipboard.BlogDiplayTargetID = exportButton.id;
			clipboard.setText(exportTextHolder.value);
			clipboard.addEventListener("onLoad", Clipboard_Loaded);
			clipboard.addEventListener("onComplete", Clipboard_Copied);
			clipboard.glue(BuildDecoyElementForClipboard(exportButton));
		}
	}
}

function BuildDecoyElementForClipboard(element)
{
	return {
		"id" : element.id,
		"className" : element.className,
		"style" : {
		"zIndex" : element.zIndex
		},
		"width" : element.offsetWidth,
		"height" : element.offsetHeight,
		"offsetLeft" : element.offsetLeft,
		"offsetTop" : element.offsetTop,
		"offsetParent" : element.offsetParent
	};
}

function Clipboard_Loaded(clipboard)
{
	var exportButton = window.document.getElementById(clipboard.BlogDiplayTargetID);
	exportButton.disabled = false;
	exportButton.title = "";
}

function Clipboard_Copied(clipboard)
{
	window.document.getElementById(clipboard.BlogDiplayTargetID).click();
}

function ResizeClipboards()
{
	for(var clipboardIndex = 0;  clipboardIndex < Clipboards.length;  clipboardIndex++)
	{
		var clipboard = Clipboards[clipboardIndex];
		var exportButton = window.document.getElementById(clipboard.BlogDiplayTargetID);
		clipboard.reposition(BuildDecoyElementForClipboard(exportButton));
	}
}

function HideClipboards()
{
	for(var clipboardIndex = 0;  clipboardIndex < Clipboards.length;  clipboardIndex++)
	{
		var clipboard = Clipboards[clipboardIndex];
		clipboard.hide();
	}
}

function ShowClipboards()
{
	for(var clipboardIndex = 0;  clipboardIndex < Clipboards.length;  clipboardIndex++)
	{
		var clipboard = Clipboards[clipboardIndex];
		clipboard.show();
	}
}

function ConfigureDesktopWindowFocus()
{
	if(window != window.top)
	{
		if(!!window.addEventListener)
		{
			window.document.documentElement.addEventListener("mousedown", FocusDesktopWindow, false);
		}
		else if(!!window.attachEvent)
		{
			window.document.documentElement.attachEvent("onmousedown", FocusDesktopWindow);
		}
	}
}

function FocusDesktopWindow()
{
	var windowID = BlogDisplay.GetCurrentWindowID();
	if(!(isNaN(windowID)))
	{
		window.parent.WindowManager.GetWindowByWindowID(windowID).BringToFront();
	}
}

function BlogDisplayPageLoad()
{
	ConfigureExportToClipboardButtons();
	var ratingMeter = window.document.getElementById("BlogRatingMeter");
	if(ratingMeter !== null)
	{
		ConnectInlineHTMLTooltipTargetEvents(ratingMeter);
	}
	ratingMeter = window.document.getElementById("PurchasingBlogRatingMeter");
	if(ratingMeter !== null)
	{
		ConnectInlineHTMLTooltipTargetEvents(ratingMeter);
	}
	ConfigureDesktopWindowFocus();
	WrapComments();
	if(!!window.ScrollToComments && typeof(ScrollToComments) === 'function')
	{
		window.ScrollToComments();
	}
	var qstring = GetQS();
	if (qstring.indexOf('&comment=') > -1)
	{
		qstring = qstring.substring(qstring.indexOf('&comment=')+9);
		if (qstring.indexOf('new') == 0)
		{
			BlogDisplay.scrollToPreview('pb_blogcomment_textarea');
		}
		else if (qstring.indexOf('view') == 0)
		{
			BlogDisplay.scrollToPreview('pb_blogcomments_header');
		}
	}
	ConfigureBlogRatingRepaintingIE6();
	if (typeof isPOPopped != "undefined" && !!isPOPopped)
	{
		window.AnimObject = new OptDivAnimator();
		window.setTimeout(function() { AnimObject.startAnim(); },1000);
		
		document.getElementById('optinboxWin').onclick = function() { window.optinDivClicked=true; };
		
		if(!!window.document.addEventListener)
		{
			window.document.addEventListener("click",
				function() 
				{
					if (AnimObject.optinShowFlag && typeof(window.optinDivClicked) != 'undefined' && !window.optinDivClicked) 
					{
						AnimObject.startAnim(); 
					}
					window.optinDivClicked = false;
				}, 
				false
				);
			window.addEventListener("scroll",
				function()
				{
					if (AnimObject.optinShowFlag)
					{
						AnimObject.scrollWithWindow();
					}
				},
				false
				);
		}
		else if(!!window.document.attachEvent)
		{
			window.document.attachEvent("onclick",
				function() 
				{
					if (AnimObject.optinShowFlag && (typeof window.optinDivClicked == 'undefined' || (typeof window.optinDivClicked != 'undefined' && !window.optinDivClicked)))
					{
						AnimObject.startAnim(); 
					}
					window.optinDivClicked = false;
				}
				);
			window.attachEvent("onscroll",
				function()
				{
					if (AnimObject.optinShowFlag)
					{
						AnimObject.scrollWithWindow();
					}
				}
				);
		}
	}
    window.aboutText = jQuery('.aboutTextArea').autogrow().focus(aboutTextFocus).blur(aboutTextBlur).keyup(aboutTextKeyUp);
    jQuery('#submitDesc input').click(submitAboutText);
    if (window.aboutText.length > 0)
    {
        aboutTextKeyUp();
        aboutTextBlur();
    }
}

function aboutTextFocus()
{
    if (window.aboutText.val() == 'Enter a description of your blog...')
    {
        window.aboutText.val('');
    }
    jQuery('#submitDesc').show();
}

function aboutTextBlur()
{
    if (window.aboutText.val() == '')
    {
        window.aboutText.val('Enter a description of your blog...');
        jQuery('#submitDesc').hide();
        jQuery('#aboutTextChars').text(250);
    }
}

function aboutTextKeyUp()
{
    var len = window.aboutText.val().length;
    if (len > 250)
    {
        window.aboutText.val(window.aboutText.val().substr(0,250));
    }
    if (len == 249)
    {
        jQuery('#aboutTextChars').text('1 character');
    }
    else
    {
        jQuery('#aboutTextChars').text((250 - window.aboutText.val().length) + ' characters');
    }
}

function submitAboutText()
{
    var len = window.aboutText.val().length;
    if (len > 250)
    {
        window.aboutText.val(window.aboutText.val().substr(0,250));
    }
    var params = {};
    var ajaxSettings = {};
    params['blogId'] = blogId;
    params['text'] = window.aboutText.val();
    ajaxSettings['data'] = params;
    ajaxSettings['url'] = 'DescUpdate.ashx';
    ajaxSettings['type'] = 'post';
    ajaxSettings['dataType'] = 'json';
    ajaxSettings['success'] = submitAboutTextCallback;
    jQuery.ajax(ajaxSettings)
    jQuery('#aboutTextError').hide();
    jQuery('#submitDesc input').attr('disabled', 'disabled');
}

function submitAboutTextCallback(data)
{
    if (data.success)
    {
        jQuery('#submitDesc').hide();
    }
    else
    {
        jQuery('#aboutTextError').text(data.error).show();
    }
    jQuery('#submitDesc input').removeAttr('disabled');
}

if(!!window.addEventListener)
{
	window.addEventListener("load", BlogDisplayPageLoad, false);
}
else if(!!window.attachEvent)
{
	window.attachEvent("onload", BlogDisplayPageLoad);
}

function ResizeModalCurtain()
{
	var curtain = window.document.getElementById("curtain");
	var curtainBacking = window.document.getElementById("curtainBacking");
	
	var fullWidth = 0;
	var fullHeight = 0;

	if (!window.domain || window.domain == -1 || window.domain == 5)
	{
		fullWidth = window.document.documentElement.scrollWidth;
		fullHeight = window.document.documentElement.scrollHeight;
	}
	else if (window.domain == 3)
	{
	    return;
	}
	else
	{
		var top_earners_wrapper = window.document.getElementById('iframe_wrapper');
		fullWidth = top_earners_wrapper.scrollWidth;
		fullHeight = top_earners_wrapper.scrollHeight;
	}

	curtain.style.width = fullWidth + "px";
	curtain.style.height = fullHeight + "px";
	curtainBacking.style.width = fullWidth + "px";
	curtainBacking.style.height = fullHeight + "px";
}

var FeatureManager={
updateFeature:function(featureId,isEnabled){
    if (window.document.getElementById('donotshowagain').checked)
    {
        var isEnabledParam=isEnabled?1:0;
        var rn=Math.random()*10000000;        
        var tempscript = document.createElement("script");
        tempscript.src='http://www.fanbox.com/socnet/handlers/FeatureHandler.ashx?fid='+featureId+'&stts='+isEnabledParam+'&r='+rn;
        window.document.body.appendChild(tempscript);
    }
    }
}


function ShowModalCurtain()
{
	var curtain = window.document.getElementById("curtain");
	curtain.style.display = "block";
	var curtainBacking = window.document.getElementById("curtainBacking");
	if (!!curtainBacking)
	{
	    curtainBacking.style.display = "block";
	    ResizeModalCurtain();
	}
}

function HideModalCurtain()
{
	var curtain = window.document.getElementById("curtain");
	curtain.style.display = "none";
	curtain.style.width = "100%";
	curtain.style.height = "100%";
	var curtainBacking = window.document.getElementById("curtainBacking");
	if (!!curtainBacking)
	{
	    curtainBacking.style.display = "none";
	    curtainBacking.style.width = "100%";
	    curtainBacking.style.height = "100%";
	}
}

function showNewBlogDiv()
{
	var createdDivShow = document.getElementById("newBlogDiv");
	createdDivShow.style.display = "";
}

function hideNewBlogDiv()
{
	var createdDivShow = document.getElementById("newBlogDiv");
	createdDivShow.style.display = "none";
}

function hideReminder()
{
	FeatureManager.updateFeature(10, 0);
	var shoutoutreminder = document.getElementById("ShoutoutReminder");
	shoutoutreminder.style.display = "none";	
	HideModalCurtain();
}

function hideReminderShout(prodId)
{
    var rn=Math.random()*10000000;        
    var tempscript = document.createElement("script");
    tempscript.src='http://www.fanbox.com/socnet/handlers/FeatureHandler.ashx?fid=10&stts=0&r='+rn;
    window.document.body.appendChild(tempscript);
	window.open('http://developer.fanbox.com/WidgetWizard/Shoutout/Manage.aspx?appid=' + prodId + '', '_blank');
	var shoutoutreminder = document.getElementById("ShoutoutReminder");
	shoutoutreminder.style.display = "none";
	DeveloperAction.RecordStat(2, 37, -1);
    HideModalCurtain();	
}

var LastTextArea = null;
var LastTextAreaLimit = NaN;
var TextAreaTimer = NaN;
function LimitedTextArea_KeyPress()
{
	var checkNow;
	if(isNaN(TextAreaTimer))
	{
		checkNow = true;
	}
	else if(LastTextArea !== this)
	{
		window.clearTimeout(TextAreaTimer);
		TextAreaTimer = NaN;
		TrimLastLimitedTextAreaToLength();
		checkNow = true;
	}
	else
	{
		checkNow = false;
	}
	if(checkNow)
	{
		LastTextAreaLimit = parseInt(this.attributes["maxlength"].value, 10);
		LastTextArea = this;
		if(this.value.length < LastTextAreaLimit)
		{
			TextAreaTimer = window.setTimeout(TrimLastLimitedTextAreaToLength, 250);
		}
		else
		{
			TextAreaTimer = window.setTimeout(TrimLastLimitedTextAreaToLength, 0);
		}
	}
}

function LimitedTextArea_Change()
{
	LastTextAreaLimit = parseInt(this.attributes["maxlength"].value, 10);
	LastTextArea = this;
	TrimLastLimitedTextAreaToLength();
}

function TrimLastLimitedTextAreaToLength()
{
	var currentValue = LastTextArea.value;
	if(currentValue.length > LastTextAreaLimit)
	{
		LastTextArea.value = currentValue.substr(0, LastTextAreaLimit);
	}
	TextAreaTimer = NaN;
}

function ResizePhotos()
{
	var images = [window.document.getElementById("ParticipantBlogAuthorPhoto")];
	for(var imageIndex = 0;  imageIndex < images.length;  imageIndex++)
	{
		var image = images[imageIndex];
		if(image !== null)
		{
			ResizePhoto(image, parseInt(image.maxWidth, 10), parseInt(image.maxHeight, 10));
		}
	}
}

function ResizePhoto(imgRef, maxWidth, maxHeight)
{
	if(imgRef)
	{
		if(imgRef.width)
		{
			if(imgRef.width > maxWidth || imgRef.height > maxHeight)
			{
				var maxRatio = maxWidth / maxHeight;
				var imgRatio = imgRef.width / imgRef.height;

				if(maxRatio < imgRatio)
				{
					var temph = Math.round(((maxWidth)/imgRef.width) * imgRef.height);
					if(temph > 2)
					{
						imgRef.height = temph;
						imgRef.width = maxWidth;
					}
				}
				else
				{
					var tempw = Math.round(((maxHeight)/imgRef.height) * imgRef.width);
					if(tempw > 2)
					{
						imgRef.width = tempw;
						imgRef.height = maxHeight;
					}
				}
			}
		}
		else
		{
			imgRef.height = maxHeight;
		}
	}
	imgRef.style.visibility = "visible";
}

function WrapComments()
{
	var elementIDs = window.commentBodyClientIDs;
	if(!!elementIDs)
	{
		for(i = 0; i < elementIDs.length; i++)
		{
			var elementID = elementIDs[i];
			var commentContainer = window.document.getElementById(elementID);
			if(commentContainer.offsetWidth > 518)
			{
				var textNodes = [];
				for(var cursor = commentContainer.firstChild;  cursor !== null;  cursor = cursor.nextSibling)
				{
					if(cursor.nodeType === 3)
					{
						textNodes.push(cursor);
					}
				}
				for(var textNodeIndex = 0;  textNodeIndex < textNodes.length;  textNodeIndex++)
				{
					WordBreakDisplayTextWidth(commentContainer, 450, textNodes[textNodeIndex]);
				}
			}
		}
	}
}
var DeveloperAction = DeveloperAction || {};

DeveloperAction.RecordStat = function(action, eventLocationId, assocIntData)
{
    var args = {
        vlsid : -1,
        ac : action,
        elid : eventLocationId,
        aid : assocIntData};
    new Ajax.Request
	('DeveloperActionStat.ashx',
    {
        method: 'post',
		parameters: args
	});
}

function GetScrollTop()
{
	if (typeof document.documentElement.scrollTop !== 'undefined')
	{
		return document.documentElement.scrollTop;
	}
	if (typeof window.pageYOffset !== 'undefined')
	{
		return window.pageYOffset;
	}
	else
	{
		return document.body.scrollTop;
	}
}

var AnimObject;
function OptDivAnimator()
{	
	//Variables used across the different functions
	this.optinwinmaxwid = 560;
	this.optinwinmaxhgt = 320;
	this.optinwincontentmaxhgt = 320;
	this.optinShowFlag = false;
	this.optinwin = document.getElementById('optinboxWin');
	this.optinwincontent = document.getElementById('optinboxWinContent');
	this.optincon = document.getElementById('optinContent');

	//Determine window size values
	this.windowmaxwid = window.document.body.clientWidth;
	this.windowmaxhgt = window.document.body.clientHeight;
	this.offsetleftmax = (this.windowmaxwid/2) - 280;
	this.offsettopmax = (this.windowmaxhgt/2) - 160;
	this.intervalhgt = this.optinwinmaxhgt / 6;
	this.intervalwid = this.optinwinmaxwid / 6;
	this.intervalcontenthgt = this.optinwincontentmaxhgt / 6;
	
	this.regularStepIncrement = 75;
	this.lastStepTime = null;
	
	this.alreadyOpted = false;
	this.stepSliddinAway = false;
	
	//Initializes animation sequences
	this.startAnim = function()
	{
		if (this.alreadyOpted === true && this.optinShowFlag === false)
		{
			return;
		}
		
		if (this.optinShowFlag)
		{
			this.stepDown();
		}
		else if (!this.stepSliddinAway)
		{
			this.stepSliddinAway = true;
			this.stepSlide();
		}
	};
	
	this.scrollWithWindow = function()
	{
		this.optinwin.style.marginTop = (-1*(parseInt(this.optinwin.style.height) / 2) + GetScrollTop()) + "px";
	};
	
	//Maximizes the Profile window
	this.stepSlide = function()
	{
		if(this.optinShowFlag === false)
		{
			this.lastStepTime = null;
		}
		
		var stepIncrement = this.setStep();
		if(parseInt(this.optinwin.style.bottom) >= 40) 
		{
			this.optinwin.style.marginBottom = '';
			this.optinwin.style.bottom = "";
			this.optinwin.style.top = "50%";
			this.optinwin.style.left = "50%";
			this.optinwin.style.height = "384px";
			this.optinwincontent.style.height = "364px";
			this.optinwin.style.width = "560px";
			this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
			this.optinwin.style.marginTop = (-1*(parseInt(this.optinwin.style.height) / 2) + GetScrollTop()) + "px";
			if (this.optinShowFlag === false)
			{
				this.showOptin();
			}
		}
		else 
		{
			this.optinwin.style.top = "";
			this.optinwin.style.marginTop = "";
			this.optinwin.style.width = (parseInt(this.optinwin.style.width) + (stepIncrement * this.intervalwid)) + "px";
			this.optinwin.style.height = (parseInt(this.optinwin.style.height) + (stepIncrement * this.intervalhgt)) + "px";
			this.optinwincontent.style.height = ((parseInt(this.optinwincontent.style.height) + (stepIncrement * this.intervalcontenthgt)) - 10) + "px";
			this.optinwin.style.bottom = (parseInt(this.optinwin.style.bottom) + (stepIncrement * 10)) + "%";
			this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
			this.optinwin.style.marginBottom = "-" + ((parseInt(this.optinwin.style.height) / 2) + GetScrollTop() ) + "px";
			window.setTimeout(function() { AnimObject.stepSlide(); }, 75);
		}
	};
	
	//Minimizes the profile window
	this.stepDown = function() 
	{
		if(this.optinShowFlag === true)
		{
			this.showOptin();
		}
	
		var stepIncrement = this.setStep();
		if(parseInt(this.optinwin.style.bottom) <= 10) {
			this.optinwin.style.top = "";
			this.optinwin.style.marginTop = "";
			this.optinwin.style.bottom = "-10%";
			this.optinwin.style.left = "50%";
			this.optinwin.style.height = "0";
			this.optinwincontent.style.height = "0";
			this.optinwin.style.width = "0";
			this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
			this.optinwin.style.marginBottom = "-" + ((parseInt(this.optinwin.style.height) / 2) + GetScrollTop() ) + "px";
		}
		else 
		{
			//just catch every error and completely hide, I dont want to check if each operation is going to go negative
			try
			{
				this.optinwin.style.top = "";
				this.optinwin.style.marginTop = "";
				this.optinwin.style.width = (parseInt(this.optinwin.style.width) - (stepIncrement * this.intervalwid)) + "px";
				this.optinwin.style.height = (parseInt(this.optinwin.style.height) - (stepIncrement * this.intervalhgt)) + "px";
				this.optinwincontent.style.height = ((parseInt(this.optinwincontent.style.height) - (stepIncrement * this.intervalcontenthgt)) - 10) + "px";
				if(isNaN(parseInt(this.optinwin.style.bottom,10)))
				{
					this.optinwin.style.bottom = '50%';
				}
				this.optinwin.style.bottom = (parseInt(this.optinwin.style.bottom) - (stepIncrement * 10)) + "%";
				this.optinwin.style.marginLeft = "-" + (parseInt(this.optinwin.style.width) / 2) + "px";
				this.optinwin.style.marginBottom = "-" + ((parseInt(this.optinwin.style.height) / 2) + GetScrollTop() ) + "px";
			}
			catch(e)
			{
				//make it less than 10px so next time this method gets called it is completely hidden
				this.optinwin.style.bottom = "9px";
			}
			window.setTimeout(function() { AnimObject.stepDown(); }, 75);
		}
	};
	
	//Fades out the profile window content
	this.showOptin = function() 
	{
		this.lastStepTime = null;
		if(this.optincon.style.visibility == "hidden") 
		{
			this.optincon.style.visibility = "visible";
			this.optinShowFlag = true;
			this.stepSliddinAway = false;
		}
		else 
		{
			this.optincon.style.visibility = "hidden";
			this.optinShowFlag = false;
		}
	};
	
	//Sets the last step time and returns the ratio of regular step time over real step time
	this.setStep = function()
	{
		if(!this.lastStepTime)
		{
			//keep normal increment, nothing has happened yet
			this.lastStepTime = new Date();
			return 1;
		}
		else
		{
			//set new increment depending on how long it's been
			var tempTime = new Date();
			//get total milliseconds
			var ms = (tempTime.getTime() - this.lastStepTime.getTime());
			
			this.lastStepTime = tempTime;
			return ms/this.regularStepIncrement;
		}
	}
}

function addPageTimer(obj)
{
    var atr;
    var toAdd = 'PageTimer_Request=' + (new Date()).getTime();
    if (obj.nodeName === "a" || obj.nodeName === "A")
    {
        atr = "href";
    }
    else if (obj.nodeName === "form" || obj.nodeName === "FORM")
    {
        atr = "action";
    }
    else
    {
        return;
    }
    var reg = obj[atr].replace(/([?&])PageTimer_Request=[^&#]+/g, ('$1' + toAdd))
    if (reg !== obj[atr])
    {
        obj[atr] = reg;
        return;
    }
    var hashStart = obj[atr].indexOf("#");
    var queryStringStart = obj[atr].indexOf("?");
    if (queryStringStart < 0)
    {
        toAdd = '?' + toAdd;
    }
    else
    {
        toAdd = '&' + toAdd;
    }
    if (hashStart < 0)
    {
        obj[atr] += toAdd;
    }
    else
    {
        obj[atr] = obj[atr].substring(0,hashStart) + toAdd + obj[atr].substring(hashStart);
    }
}
function tagInputStartup()
{
    var inputContainer = document.getElementById('tagInputContainer');
    var tagInput = inputContainer.firstChild;
    var counter = 0;
    while(!!tagInput)
    {
        AutoComplete.AddControl(tagInput.id, 'AutoCompleteHandler.ashx', null, tagInputValidator);
        counter++;
        tagInput = tagInput.nextSibling;
    }
    ConnectInlineHTMLTooltipTargetEvents(document.getElementById('tagInputHelp'));
}
function tagInputValidator(e)
{
	var
		e = e || window.event,
		keyCode = e.which || e.keyCode,
		evSource = e.target || e.srcElement;
	
	if ( keyCode === 23 && !!evSource && evSource.value.match(/^\s*$/gm))
	{
		return false;
	}
	return true;
}
function tagInputFocus(input)
{
    if (input.className == 'tagsInput')
    {
        input.value = '';
    }
    input.className = 'tagsInput tagsInputFilled';
}
function tagInputBlur(input)
{
    if (input.value == '')
    {
        input.value = 'One tag per box';
        input.className = 'tagsInput';
    }
}
function tagInputSubmit(input)
{
    var inputContainer = document.getElementById('tagInputContainer');
    var tagInput = inputContainer.firstChild;
    var counter = 0;
    var params = {};
    params['postId'] = document.getElementById('PostTagInsertId').value;
    while(!!tagInput)
    {
        if (tagInput.className == 'tagsInput tagsInputFilled')
        {
            params['tag_' + counter] = tagInput.value;
        }
        counter++;
        tagInput = tagInput.nextSibling;
    }
    new Ajax.Request('PostTag.ashx',
        {
            'method' : 'post',
            'parameters' : params,
            'onSuccess' : function(response){input.disabled = false;tagInputSubmitCallback(response)},
            'onFailure' : function(){input.disabled = false;}
        });
    input.disabled = true;
    return false;
}
function tagInputSubmitCallback(response)
{
    var data = response.responseText.evalJSON(false);
    if (!!data.success)
    {
        document.getElementById('PostTagInsert').style.visibility = 'hidden';
        if (!!data.tagHtml)
        {
            var tagContainer = document.getElementById('pblogTagList');
            tagContainer.innerHTML = data.tagHtml;
            tagContainer.parentNode.parentNode.style.display = 'block';
        }
        return;
    }
    var textField = document.getElementById('tagInputMessage');
    textField.firstChild.data = data.error;
    textField.className = 'inlineBlockElement text_sm_red';
    textField.style.marginTop = '16px';
    var inputContainer = document.getElementById('tagInputContainer');
    var tagInput = inputContainer.firstChild;
    var counter = 0;
    while(!!tagInput)
    {
        if (!!data['tag_' + counter])
        {
            tagInput.className = 'tagsInput tagsInputFilled tagsInputError';
        }
        counter++;
        tagInput = tagInput.nextSibling;
    }
}
function hideTagInput()
{
    document.getElementById('PostTagInsert').style.visibility = 'hidden';
    return false;
}
var PBlogCreate = PBlogCreate || {};
PBlogCreate._finishEduDiv = function()
{
	PBlogCreate._eduDiv.style.visibility = 'visible';
	PBlogCreate._eduDiv.style.display = 'block';
    PBlogs._SettingsDiv.style.visibility = 'hidden';
};
PBlogCreate.OpenEditor = function()
{
	PBlogCreate._eduDiv.style.visibility = 'hidden';
	PBlogCreate._eduDiv.style.display = 'none';
	if (!PBlogs || !PBlogs.HideModalCurtain)
    {
        SelectedBlogController.LaunchEditor(PBlogCreate.NewBlogId);
    }
    else
    {
        PBlogs.HideModalCurtain();
	    LaunchEditor(PBlogCreate.NewBlogId,PBlogCreate.NewBlogId,6,10,1,'&bts=8',2);
    }
};