var currentHost = window.location.host;
var CurrentUser = retrieveSSOCookieUserId();
if (CurrentUser !='' && CurrentUser !='undefined') {
	CurrentUser = hex_md5(CurrentUser);
}

/* DANGER:  use of requestPluckUserAvatar() will result in a specific call to
   a batch request, which as a real-world $ cost from Pluck.  If possible, combine
   this with other batch requests using registerPluckPageCallback (found in pageTop.body.php)
*/
function requestPluckUserAvatar() {
	// create a request batch  
	var requestBatch = new RequestBatch();

	// add the userKey to the request
	var userKey = new UserKey(CurrentUser);
	requestBatch.AddToRequest(userKey); 

	// initiate the request.  The response will be passed to the renderUserAvatar() method.  
	requestBatch.BeginRequest(serverUrl, renderUserAvatar);
}

// writes the user avatar into a <img> tag on the page
function renderUserAvatar(responseBatch) {
	// Rip through and find the user reponse
	var response = null;
	for (i=0; i<responseBatch.Responses.length; i++) {
		if (responseBatch.Responses[i].User!=null) {
			response = responseBatch.Responses[i];
			i = responseBatch.Responses.length;		// breaks loop
		}
	}
	if (response==null) {
		// ignore error
		document.getElementById("avatar").src = 'http://appsstage.swiftcom.com/utils/ureg/ui/graphics/notloggedinavatar.gif';
	} else {
		// get the user object out of the response  
		var cookie_date = new Date ( );  // current date & time
		cookie_date.setFullYear(cookie_date.getFullYear() + 2);
		var user = response.User;
		document.getElementById("avatar").src = user.AvatarPhotoUrl;
		document.cookie = "AVATAR" + "=" + user.AvatarPhotoUrl + "; expires=" + cookie_date.toGMTString() + ";domain=" + document.domain + ";path=/";
	}
	//window.location.href=window.location.href;
}

/* Get a request object suitable for use in a Pluck batch operation
   Gets articles:  activity = "Recent", "Commented", "Recommended"
   iNum Arts = max # of arts to return
*/
function getArticlesRequest(activity, iNumArts) {
	var searchSections = new Array();
	searchSections[0] = new Section("All");
	var searchCategories = new Array();
	searchCategories[0] = new Category("All");
	var activityDisco = new Activity(activity);
	var contentType = new ContentType("Article");
	var limitToContributors = new Array();
	var limitToContributors = new Array();
	limitToContributors[0] = new UserTier("Standard");
	limitToContributors[1] = new UserTier("Trusted");
	limitToContributors[2] = new UserTier("Featured");
	limitToContributors[3] = new UserTier("Staff");
	limitToContributors[4] = new UserTier("Editor");
	var age = 15;
	var discoveryAction = new DiscoverContentAction(
			searchSections,
			searchCategories,
			limitToContributors,
			activityDisco,
			contentType,
			age,
			iNumArts);
	return discoveryAction;
}

/* Get a request object suitable for use in a Pluck batch operation
   Gets personas:  activity = "Recent", "Commented", "Recommended"
   iNumPersonas = max # of personas to return
*/
function getPersonasRequest(activity, iNumPersonas) {
	var searchSections = new Array();
	searchSections[0] = new Section("All");
	
	var searchCategories = new Array();
	searchCategories[0] = new Category("All");
	var activityDisco = new Activity(activity);
	var contentType = new ContentType("Persona");
	var limitToContributors = new Array();
	var limitToContributors = new Array();
	limitToContributors[0] = new UserTier("Standard");
	limitToContributors[1] = new UserTier("Trusted");
	limitToContributors[2] = new UserTier("Featured");
	limitToContributors[3] = new UserTier("Staff");
	limitToContributors[4] = new UserTier("Editor");
	var age = 15;
	var discoveryAction = new DiscoverContentAction(
			searchSections,
			searchCategories,
			limitToContributors,
			activityDisco,
			contentType,
			age,
			iNumPersonas);
	return discoveryAction;
}

/* Get a request object suitable for use in a Pluck batch operation
   Gets photos:  activity = "Recent", "Commented", "Recommended"
   iNumPhotos = max # of photos to return
*/
function getPhotosRequest(activity, iNumPhotos) {
	var searchSections = new Array();
	searchSections[0] = new Section("All");
	
	var searchCategories = new Array();
	searchCategories[0] = new Category("All");
	
	var activityDisco = new Activity(activity);
	var contentType = new ContentType("PublicPhoto");
	var limitToContributors = new Array();
	limitToContributors[0] = new UserTier("Standard");
	limitToContributors[1] = new UserTier("Trusted");
	limitToContributors[2] = new UserTier("Featured");
	limitToContributors[3] = new UserTier("Staff");
	limitToContributors[4] = new UserTier("Editor");
	var age = 15;
	var discoveryAction = new DiscoverContentAction(
			searchSections,
			searchCategories,
			limitToContributors,
			activityDisco,
			contentType,
			age,
			iNumPhotos);
	return discoveryAction;
}

/* Get a request object suitable for use in a Pluck batch operation
   Gets blog posts:  activity = "Recent", "Commented", "Recommended"
   iNumBlogs = max # of blogs to return
*/
function getBlogPostsRequest(activity, iNumBlogs) {
	var searchSections = new Array();
	searchSections[0] = new Section("All");
	
	var searchCategories = new Array();
	searchCategories[0] = new Category("All");
	
	var activityDisco = new Activity(activity);
	var contentType = new ContentType("BlogPost");
	var limitToContributors = new Array();
	var limitToContributors = new Array();
	limitToContributors[0] = new UserTier("Standard");
	limitToContributors[1] = new UserTier("Trusted");
	limitToContributors[2] = new UserTier("Featured");
	limitToContributors[3] = new UserTier("Staff");
	limitToContributors[4] = new UserTier("Editor");
	var age = 15;
	var discoveryAction = new DiscoverContentAction(
			searchSections,
			searchCategories,
			limitToContributors,
			activityDisco,
			contentType,
			age,
			iNumBlogs);
			
	return discoveryAction;
}
/*****************************
** Pluck formatting objects **
******************************/

function renderSimpleArticleList(discoveredContent, iMaxNum, iMaxChars, bShowNumRecommends, bShowNumComments) {
	var sHtml = "<div class='Summary_Container'>";
	var iNumAdded = 0;
	for (var i=0; i<discoveredContent.length;i++) {
		var content = discoveredContent[i];
		if ((content.ArticleKey != null)&&(iNumAdded < iMaxNum)) {
			iNumAdded++;
			sHtml += "<div class='Summary_ArticleTitle'>";
			sHtml += "<a href='" + makeURLSafe(content.PageUrl) + "'>";
			sExtra = "";
			if (bShowNumRecommends) sExtra += "(" + content.Recommendations.NumberOfRecommendations + ")";
			if (bShowNumComments) sExtra += "(" + content.Comments.NumberOfComments + ")";
			if (sExtra.length > 0) sExtra = " " + sExtra;
			var iExtraLen = sExtra.length;
			var sText = content.PageTitle;
			if ((sText.length + iExtraLen) > iMaxChars) {
				var iNewLen = iMaxChars - iExtraLen - 4;		// 4 = 1 space and 3 dots
				if (iNewLen < 5) iNewLen = 5;				// Give at least 5 chars!
				sText = sText.substr(0, iNewLen) + "...";
			}
			sText = sText.replace("&#145;", "'");
			sText = sText.replace("&#146;", "'");
			sText = sText.replace("&#147;", "\"");
			sText = sText.replace("&#148;", "\"");
			sText = sText.replace(String(145), "'");
			sText = sText.replace(String(146), "'");
			sText = sText.replace(String(147), "\"");
			sText = sText.replace(String(148), "\"");
			sText += sExtra;
			sHtml += sText;
			sHtml += "</a>";
			sHtml += "</div>";
		}
	}
	sHtml += "</div>";
	return sHtml;
}

/* Publicus has a few issues with some chars in the URLs; fix them up here */
function makeURLSafe(url) {
	// Get rid of %3A first
	var r = url.replace(/%3A/i, "-");
	var i = r.indexOf(":");
	var r1 = r.substr(0, i+1);
	var r2 = r.substr(i+1);
	r2 = r2.replace(/:/, "-");
	return r1 + r2;
}
function renderPersonaList(discoveredContent, iMaxNum, appsPath) {
	var sHtml = "<div class='Summary_Container'>";
	sHtml += "<table class='Summary_ProfileTable' cellpadding='0' cellspacing='0'>";
	var iNumAdded = 0;
	for (var i=0; i<discoveredContent.length;i++) {
		var persona = discoveredContent[i];
		if ((persona.UserKey != null)&&(iNumAdded < iMaxNum)) {
			iNumAdded++;
			sHtml += "<tr>";
			sHtml += "<td class='Summary_ProfileTableLeft'>";
			sHtml += "<a href='" + appsPath + "/utils/persona/ui/index.php?userId=" + persona.UserKey.Key + "&plckUserId=" + persona.UserKey.Key + "'>";
			sHtml += "<img src='" + persona.AvatarPhotoUrl + "' alt='" + persona.DisplayName + "'>";
			sHtml += "</a>";
			sHtml += "</td>";
			sHtml += "<td class='Summary_ProfileTableRight'>";
			sHtml += "<div class='Summary_ProfileName'>";
			sHtml += "<a href='" + appsPath + "/utils/persona/ui/index.php?userId=" + persona.UserKey.Key + "&plckUserId=" + persona.UserKey.Key + "'>";
			sHtml += persona.DisplayName;
			sHtml += "</a>";
			sHtml += "</div>";
			sHtml += "<div class='Summary_ProfileTime'>";
			sHtml += persona.LastUpdated;
			sHtml += "</div>";
			sHtml += "</td>";
			sHtml += "</tr>";
		}
	}
	sHtml += "</table>";
	sHtml += "</div>";
	return sHtml;
}
function renderPhotoList(discoveredContent, iMaxNum, appsPath) {
	var sHtml = "<div class='Summary_Container'>";
	sHtml += "<table class='Summary_PhotoTable' cellpadding='0' cellspacing='0'>";
	var iNumAdded = 0;
	for (var i=0; i<discoveredContent.length;i++) {
		var photo = discoveredContent[i];
		if (photo.PhotoKey != null) sHtml += "\n<!-- photo: " + photo.Title + " -->\n";
		if ((photo.PhotoKey != null)&&(iNumAdded < iMaxNum)) {
			iNumAdded++;
			sHtml += "<tr>";
			sHtml += "<td class='Summary_PhotoTableLeft'>";
			sHtml += "<a href='" + photo.PhotoUrl + "'>";
			sHtml += "<img src='" + photo.Image.Small + "' alt='" + photo.Title + "'>";
			sHtml += "</a>";
			sHtml += "</td>";
			sHtml += "<td class='Summary_PhotoTableRight'>";
			sHtml += "<div class='Summary_PhotoTitle'>";
			sHtml += "<a href='" + photo.PhotoUrl + "'>";
			sHtml += photo.Title;
			sHtml += "</a>";
			sHtml += "</div>";
			sHtml += "<div class='Summary_PhotoDescription'>";
			sHtml += photo.Description;
			sHtml += "</div>";
			sHtml += "<div class='Summary_PhotoBy'>";
			sHtml += "By: ";
			sHtml += "<a href='" + appsPath + "/utils/persona/ui/index.php?userId=" + photo.Author.UserKey.Key + "&plckUserId=" + photo.Author.UserKey.Key + "'>";
			sHtml += photo.Author.DisplayName;
			sHtml += "</a>";
			sHtml += "</div>";
			sHtml += "</td>";
			sHtml += "</tr>";
		}
	}
	sHtml += "</table>";
	sHtml += "</div>";
	return sHtml;
}
function renderBlogPostList(discoveredContent, iMaxNum, appsPath, responseBatch) {
	var sHtml = "<div class='Summary_Container'>";
	sHtml += "<table class='Summary_PhotoTable' cellpadding='0' cellspacing='0'>";
	var iNumAdded = 0;
	for (var i=0; i<discoveredContent.length;i++) {
		var blogpost = discoveredContent[i];
		// Get the site of origin
		var idx = serverUrl.search(/sid=/i);
		if (idx==-1) return "error retrieving blog posts";
		var thisSite = serverUrl.substr(idx+4);
		if ((blogpost.BlogPostKey != null)&&(iNumAdded < iMaxNum)&&(thisSite == blogpost.SiteOfOrigin)) {
			iNumAdded++;
			sHtml += ((iNumAdded % 2) == 0)?"<tr>":"<tr class='Summary_BlogAltTRColor'>";
			sHtml += "<tr>";
			sHtml += "<td class='Summary_BlogTableLeft'>";
			sHtml += "<a href='" + appsPath + "/utils/persona/ui/index.php?userId=" + blogpost.PostAuthor.UserKey.Key + "&plckUserId=" + blogpost.PostAuthor.UserKey.Key + "'>";
			sHtml += "<img src='" + blogpost.PostAuthor.AvatarPhotoUrl + "' alt='" + blogpost.PostAuthor.DisplayName + "'>";
			sHtml += "</a>";
			sHtml += "</td>";
			sHtml += "<td class='Summary_BlogTableRight'>";
			sHtml += "<div class='Summary_BlogTitle'>";
			sHtml += "<a href='" + blogpost.Url + "'>";
			sHtml += blogpost.PostTitle;
			sHtml += "</a>";
			sHtml += "</div>";
			sHtml += "<div class='Summary_BlogBy'>";
			sHtml += "By ";
			sHtml += "<a href='" + appsPath + "/utils/persona/ui/index.php?userId=" + blogpost.PostAuthor.UserKey.Key + "&plckUserId=" + blogpost.PostAuthor.UserKey.Key + "'>";
			sHtml += blogpost.PostAuthor.DisplayName;
			sHtml += "</a>";
			sHtml += "</div>";
			sHtml += "<div class='Summary_BlogTime'>";
			sHtml += blogpost.PostDate;
			sHtml += "</a>";
			sHtml += "</div>";
			sHtml += "</td>";
			sHtml += "</tr>";
		}
	}
	sHtml += "</table>";
	sHtml += "</div>";
	return sHtml;
}
function getBlogFromResponseBatch(blogKey, responseBatch) {
	for (var i=0; i < responseBatch.Responses.length; i++) {
		var response = responseBatch.Responses[i];
		if ((response.Blog!=null)&&(response.Blog.BlogKey.Key == blogKey)) {
			return response;
		}
	}
	return null;
}

/*****************************
** Logon Code               **
*****************************/
function openLogonPopUp() {
	document.getElementById('logonPopUp').style.visibility="visible";
	document.getElementById('logon_email').focus();
}
function closeLogonPopUp() {
	document.getElementById('logonPopUp').style.visibility="hidden";
}
function setCookie(ssokey, emailaddress, screenname, rememberme, cookieDomain) {
	var cookie_value = ssokey + "|" + screenname + "||" + emailaddress;
	if (rememberme == "YES") {
		// set cookie expires out a year
		var cookie_date = new Date ( );  // current date & time
		cookie_date.setFullYear(cookie_date.getFullYear() + 2);
		document.cookie = "HD" + "=" + cookie_value + "; expires=" + cookie_date.toGMTString() + ";domain=" + cookieDomain + ";path=/";
	} else {
		// session cookie
		document.cookie = "HD" + "=" + cookie_value + "; domain=" + cookieDomain + ";path=/";
	}
}

// COOKIE VALUE RETRIEVAL - and SSO COOKIE HANDLING
function getCookie(c_name) {
	if (document.cookie.length>0) {
		var c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			var c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function retrieveSSOCookieUserId() {
	var cookieValue = getCookie("HD");
	if (cookieValue.length > 0)	{
		var aryCookieValues = cookieValue.split("|");
		return aryCookieValues[0].toLowerCase();
	} else {
		return "";
	}
}
function RetrieveSSOCookieDisplayName() {
	var cookieValue = getCookie("HD");
	if (cookieValue.length > 0) {
		var aryCookieValues = cookieValue.split("|");
		return aryCookieValues[1];
	} else {
		return "";
	}
}
function logout(cookieDomain, redirectOnLogout) {
	// remove HD cookie
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setFullYear ( cookie_date.getFullYear() - 1 );
	document.cookie = "HD" + "=; expires=" + cookie_date.toGMTString() + ";domain=" + cookieDomain + ";path=/";
	document.cookie = "AVATAR" + "=; expires=" + cookie_date.toGMTString() + ";domain=" + cookieDomain + ";path=/";
	// refresh the current document; if we need to redirect away from the caller, go to the update page
	if (redirectOnLogout)
		window.location.href=appsPath + "/utils/ureg/ui/updateaccount.php?showLogoutSuccessful=true";
	else
		window.location.href=window.location.href;
}
function NewWindow(width,height,url) {
	window.open(url,"PopUp","menubar=0,scrollbars=1,resizable=1,height="+height+",width="+width);
}

/* Used to activate a tab and its content for any of the right column widgets */
function activateWidgetTab(widgetPrefix,tabToActivate) {
	var cnt = 0;
	if (eleft = document.getElementById(widgetPrefix+cnt+".l"))
		if (tabToActivate==0)
			eleft.className = eleft.className.replace(/left_off/, "left_on");
		else
			eleft.className = eleft.className.replace(/left_on/, "left_off");
	while ((emid = document.getElementById(widgetPrefix+cnt+".m")) && (eright = document.getElementById(widgetPrefix+cnt+".r"))) {
		erightnext = document.getElementById(widgetPrefix+(cnt+1)+".r");
		if (tabToActivate == cnt) {
			emid.className = emid.className.replace(/off/, "on");
			if (erightnext)
				eright.className = eright.className.replace(new RegExp("_offon|_offoff", "g" ), "_onoff");
			else
				eright.className = eright.className.replace(/right_off/, "right_on");
			if (econtent = document.getElementById(widgetPrefix+(cnt)+".c")) econtent.style.display = "block";
		} else {
			emid.className = emid.className.replace(/on/, "off");
			if (erightnext)
				eright.className = eright.className.replace(new RegExp("_offon|_onoff|_offoff", "g"), tabToActivate==(cnt+1)?"_offon":"_offoff");
			else
				eright.className = eright.className.replace(/right_on/, "right_off");
			if (econtent = document.getElementById(widgetPrefix+(cnt)+".c")) econtent.style.display = "none";
		}
		cnt++;
	}
	return false;
}

/* Great function for debugging: returns output for an object tree
   Call like this:
   		alert(dumpObj(myObject, "myobjectname", "", 0));
*/
var MAX_DUMP_DEPTH = 10;
function dumpObj(obj, name, indent, depth) {
	if (depth > MAX_DUMP_DEPTH) {
		return indent + name + ": <Maximum Depth Reached>\n";
	}

	if (typeof obj == "object") {
		var child = null;
		var output = indent + name + "\n";
		indent += "\t";
		for (var item in obj) {
			try {
				child = obj[item];
			} catch (e) {
				child = "<Unable to Evaluate>";
			}
			if (typeof child == "object") {
				output += dumpObj(child, item, indent, depth + 1);
			} else {
				output += indent + item + ": " + child + "\n";
			}
		}
		return output;
	} else {
		return obj;
	}
}

function getCommentPageRequest(sUniqueId, iNumItemsPerPage, iCurrentPage, sSortOrder) {
	var oCommentPage = new CommentPage(new ArticleKey(sUniqueId), 
		iNumItemsPerPage, iCurrentPage, sSortOrder);
		
	return oCommentPage;
	
} // getCommentPageRequest

function renderCommentPage(oCommentPage, oMemberSites) {
	var sHtml = '';
	if (oCommentPage.Comments.length > 0) {
		sHtml = '<table class="Comments_Table" cellpadding="0" cellspacing="0"><tbody>';
		for (var i=0; i<oCommentPage.Comments.length;i++) {
			var oComment = oCommentPage.Comments[i];
			if (oComment.Author.IsBlocked!="False" && CurrentUser!=oComment.Author.UserKey.Key) {}
			else if (oComment.ContentBlockingState!="Unblocked" || oComment.AbuseReportCount > 2) {
				sHtml += '<tr class="Comments_TableRowColorBlocked"><td class="Comments_UserImage"><a href="'+appsPath+'/utils/persona/ui/index.php?userId='+oComment.Author.UserKey.Key+'&amp;plckUserId='+oComment.Author.UserKey.Key+'" onclick=""><img id="" src="'+oComment.Author.AvatarPhotoUrl+'" alt="User Image" class="PluckUserAvatar"></a></td>';
				sHtml += '<td class="Comments_TableRight"><div class="Comments_From"><a id="" href="'+appsPath+'/utils/persona/ui/index.php?userId='+oComment.Author.UserKey.Key+'&amp;plckUserId='+oComment.Author.UserKey.Key+'" target="_parent">'+oComment.Author.DisplayName+'</a> wrote:</div>';
				sHtml += '<div id="CommentBody['+i+']" class="Comments_CommentText">Comment blocked. Please read the Community Guidelines above or the Terms of Use at the bottom of the page.</div>';
				sHtml += '<div class="Comments_NestedDate">'+oComment.PostedAtTime+'<span id="SiteAttributionActivity" class="Comments_SiteAttribution"> on '+oMemberSites[0].MemberSiteName+'</span></div>';
				sHtml += '</td></tr>';
			} else {
				sHtml += '<tr class="Comments_TableRowColor"><td class="Comments_UserImage"><a href="'+appsPath+'/utils/persona/ui/index.php?userId='+oComment.Author.UserKey.Key+'&amp;plckUserId='+oComment.Author.UserKey.Key+'" onclick=""><img id="" src="'+oComment.Author.AvatarPhotoUrl+'" alt="User Image" class="PluckUserAvatar"></a></td>';
				sHtml += '<td class="Comments_TableRight"><div class="Comments_From"><a id="" href="'+appsPath+'/utils/persona/ui/index.php?userId='+oComment.Author.UserKey.Key+'&amp;plckUserId='+oComment.Author.UserKey.Key+'" target="_parent">'+oComment.Author.DisplayName+'</a> wrote:</div>';
				sHtml += '<div id="CommentBody['+i+']" class="Comments_CommentText">'+oComment.CommentBody+'</div>';
				sHtml += '<div class="Comments_NestedDate">'+oComment.PostedAtTime+'<span id="SiteAttributionActivity" class="Comments_SiteAttribution"> on '+oMemberSites[0].MemberSiteName+'</span></div>';
				sHtml += '<table class="Comments_NestedTable" cellpadding="0" cellspacing="0"><tbody><tr>';
				sRecommended = '';
				if (oComment.NumberOfRecommendations > 0) {
					sRecommended = ' ('+oComment.NumberOfRecommendations+')';
				}
				sReported = '';
				if (oComment.AbuseReportCount > 0) {
					sReported = ' ('+oComment.AbuseReportCount+')';
				}
				sHtml += '<td class="Comments_NestedRecommend"><div id="recommend:'+oComment.CommentKey.Key+'"><a href="#none" class="SiteLife_Recommend" onclick="return gSiteLife.PostRecommendation(\'Comment\',\''+oComment.CommentKey.Key+'\',\'recommend:'+oComment.CommentKey.Key+'\', document.title);">Recommend'+sRecommended+'</a></div></td>';
				sHtml += '<td class="Comments_NestedReport"><div id="rpt_'+oComment.CommentKey.Key+'"><span><a id="'+oComment.CommentKey.Key+'_RptAbuse" href="#none" class="SiteLife_ReportAbuse" onclick="ShowReportAbuse(event, document.URL, gSiteLife.__baseUrl + \'/AbuseReport/ReportAbuse?plckElementId=rpt_'+oComment.CommentKey.Key+'&amp;plckTargetKey='+oComment.CommentKey.Key+'&amp;plckTargetKeyType=Comment\'); return false;">Report abuse'+sReported+'</a></span></div></td></tr></tbody></table></td></tr>';
			}
		}
		sHtml += '</tbody></table>';
				
		// Add pagination links
		if (oCommentPage.NumberOfComments > oCommentPage.NumberPerPage) {
			var iCurrentPageNum = Number(oCommentPage.OnPage);
			var iTotalPageCount = Math.ceil(oCommentPage.NumberOfComments / oCommentPage.NumberPerPage);
			var iPaginatorPagesDisplayed = 10; // Number of page links to show
			var iPaginatorPagesAdjacent = 1; // Number of page links to left of current page
			var iPaginatorStart, iPaginatorEnd;
			var iPaginatorAdjustment = 1;
			
			if (iTotalPageCount <= iPaginatorPagesDisplayed) {
				iPaginatorStart = 1;
				iPaginatorEnd = iTotalPageCount;
			} else {
				// Set the low end
				if ((iCurrentPageNum - iPaginatorPagesAdjacent) > 0) {
					iPaginatorStart = iCurrentPageNum - iPaginatorPagesAdjacent;
				} else {
					iPaginatorStart = 1;
					iPaginatorAdjustment = 0;
				}
				// Set the high-end
				if ((iCurrentPageNum + (iPaginatorPagesDisplayed - iPaginatorPagesAdjacent) - iPaginatorAdjustment) <= iTotalPageCount) {
					iPaginatorEnd = iCurrentPageNum + (iPaginatorPagesDisplayed - iPaginatorPagesAdjacent) - iPaginatorAdjustment;
				} else {
					iPaginatorEnd = iTotalPageCount;
				}
				// Adjust low-end when approaching the high-end
				if ((iTotalPageCount - iCurrentPageNum + iPaginatorPagesAdjacent + iPaginatorAdjustment) < iPaginatorPagesDisplayed) {
					iPaginatorStart = iPaginatorStart - (iPaginatorPagesDisplayed - (iTotalPageCount - iCurrentPageNum + iPaginatorPagesAdjacent + iPaginatorAdjustment));
					if (iPaginatorStart < 1) {
						iPaginatorStart = 1;
					}
				}
			}
			
			if (iTotalPageCount > 1) {
				sHtml += '<div id="Paginator" class="Comments_Page"> ';
				
				var sOrigUrl = location.href.substring(0, location.href.indexOf('plckCurrentPage')-1);
				if (sOrigUrl == '' || sOrigUrl == null) {
					sOrigUrl = location.href;
				}
				sOrigUrl = sOrigUrl.replace('&_ic=true','');
				sOrigUrl += '&';
				
				if ((iCurrentPageNum-1) >= 1) {
					sHtml += '<a href="'+sOrigUrl+'plckCurrentPage=1&amp;sid='+pluckEnvPath+'">First</a>&nbsp;';
					sHtml += '<a href="'+sOrigUrl+'plckCurrentPage='+(iCurrentPageNum-1)+'&amp;sid='+pluckEnvPath+'">&lt;&lt;</a>&nbsp;&nbsp;';
				}
				for (var iPageNum=iPaginatorStart; iPageNum<=iPaginatorEnd; iPageNum++) {
					if (iPageNum == iCurrentPageNum) {
						sHtml += '<b>'+iPageNum+'</b>&nbsp;&nbsp;';
					} else {
						sHtml += '<a href="'+sOrigUrl+'plckCurrentPage='+iPageNum+'&amp;sid='+pluckEnvPath+'">'+iPageNum+'</a>&nbsp;&nbsp;';
					}
				}
				if ((iCurrentPageNum+1) <= iTotalPageCount) {
					sHtml += '<a href="'+sOrigUrl+'plckCurrentPage='+(iCurrentPageNum+1)+'&amp;sid='+pluckEnvPath+'">&gt;&gt;</a>&nbsp;';
					sHtml += '<a href="'+sOrigUrl+'plckCurrentPage='+iTotalPageCount+'&amp;sid='+pluckEnvPath+'">Last</a>';
				}
				
				sHtml += '</div>';
			}
		}
	}
	
	return sHtml;
	
} // renderCommentPage
function multipleFormSubmit(formSubmitButton) {
	document.getElementById(formSubmitButton).disabled=true;
	var d = new Date();
	var tempValue = hex_md5(document.getElementById("formId").value);
	tempValue = tempValue.concat(d.getTime());
	if (document.getElementById("formMultipleIdSubmit").value == "") {
		document.getElementById("formMultipleIdSubmit").value = tempValue;
		return true;
	} else {
		return false;
	}
}

