 function GetPostCommentString(fBlogViewPage, strEntryId, strPPLogo)
 {
 var strDisable = "";
 var strPost = "";
 if (BlogJS_IsPassportAuthenticated == "false")
 {
 strPost += "<table width=100% cellspacing=0 class='bvSectionContentY'>";
 strPost += "<tr><td height=4 colspan=2></td></tr>";
 strPost += "<tr>";
 strPost += "<td class='bold'>" + BlogJS_blogview_passportsignin + "</td>";
 strPost += "<td>" + strPPLogo + "</td>";
 strPost += "</tr>";
 strPost += "<tr><td height=4 colspan=2></td></tr>";
 strPost += "<tr><td colspan=2>" + BlogJS_blogview_getonetoday + "</td></tr>";
 strPost += "<tr><td height=4 colspan=2></td></tr>";
 strPost += "</table>";
 strDisable = "disabled='true'";
 }
 var bvClass = (strDisable.length > 0) ? "bvSectionContentG" : "bvSectionContentPC";
 strPost += "<table width=100% cellspacing=0 class='" + bvClass + "'>";
 strPost += "<tr><td id='Err" + strEntryId + "' class='Err' style='width:100%;padding:0 3 0 3;margin:0;'></td></tr>";
 if (BlogJS_IsPassportAuthenticated == "false")
 {
 strPost += "<tr><td height=12></td></tr>";
 }
 else
 {
 strPost += "<tr><td height=4></td></tr>";
 }
 strPost += "<tr><td>" + BlogJS_blogview_commentname + "</td></tr>";
 strPost += "<tr><td><input type='text' class='text' id='txtName" + strEntryId + "' name='txtName" + strEntryId + "' " + strDisable + " style='width:70%' value='" + strNickName + "' maxlength=" + c_Name + "></td></tr>";
 strPost += "<tr><td height=5></td></tr>";
 strPost += "<tr><td>" + BlogJS_blogview_commentemail + "</td></tr>";
 strPost += "<tr><td><input type='text' " + strDisable + " class='text' id='txtEmail" + strEntryId + "' name='txtEmail" + strEntryId + "' style='width:100%' value='' maxlength=" + c_Email + "></td></tr>";
 strPost += "<tr><td height=5></td></tr>"
 strPost += "<tr><td>" + BlogJS_blogview_commentblogurl + "</td></tr>";
 strPost += "<tr><td><input type='text' " + strDisable + " class='text' id='txtURL" + strEntryId + "' name='txtURL" + strEntryId + "' style='width:100%' value='" + strVisitorUrl + "' maxlength=" + c_Url + "></td></tr>";
 strPost += "<tr><td height=5></td></tr>";
 strPost += "<tr><td>" + BlogJS_blogview_commentstext + "</td></tr>";
 strPost += "<tr><td> <textarea id='txtComment" + strEntryId + "' name='txtComment" + strEntryId + "' rows='12' " + strDisable + " style='width:100%; padding:0 2 0 2;' value='' onkeypress='return(this.value.length< c_Comment)'></textarea></td></tr>";
 strPost += "<tr><td class='bvh8'></td></tr>";
 strPost += "<tr><td>";
 strPost += "<table width=100% cellspacing=0 class='bvPostCommentBtn' border=0 >";;
 strPost += "<tr>";
 strPost += "<td><input type='button' " + strDisable + " onclick=\"PostComment('" + strEntryId + "')\" value='" + BlogJS_blogview_publishcomment + "'></td>";
 if (fBlogViewPage)
 {
 strPost += "<td><img src='images/c.gif' width=4 height=1 border=0></td>";
 strPost += "<td><input type='button' " + strDisable + " onclick=\"CloseComment('comment', '" + strEntryId + "')\" value='" + BlogJS_blogview_cancel + "'></td>";
 }
 strPost += "<td width=100%></td>";
 strPost += "</tr>";
 strPost += "</table>";
 strPost += "</td></tr>";
 strPost += "<tr><td class='bvh8'></td></tr>";
 strPost += "</table>";
 return strPost;
 }
function ShowPostComment(strPPLogo, strEntryId)
 {
 var strComment = "comment";
 var strPost = "";
 strPost = GetPostCommentString(true, strEntryId, strPPLogo)
 strPost = strPost.replace("spacesbeid", strEntryId);
 return strPost;
 }
 function Close(section, entryid)
 {
 CleanUpFields(entryid);
 document.getElementById(section + entryid).style.display = "none";
 entrysectionObj = document.getElementById("entry"+entryid);
 if (entrysectionObj != null)
 {
 entrysectionObj.scrollIntoView(true);
 }
 }
 function OpenSection(section, entryid, bTriedPassportRefresh)
 {
 var strText;
 var fError = false;
 var sectionTitleObj = document.getElementById(section+entryid);
 if (sectionTitleObj.style.display == 'none' || sectionTitleObj.style.display == '')
 {
 sectionTitleObj.style.display = "block";
 }
 if (section == "trackback")
 {
 if(document.getElementById("trackback" + entryid).innerHTML =="" || bTriedPassportRefresh)
 {
 strText = GetBlogActivity(entryid, "trackback", "", bTriedPassportRefresh);
 if (strText.toLowerCase() != "error" && strText.length > 0)
 {
 document.getElementById("trackback" + entryid).innerHTML = strText;
 }
 else
 {
 fError = true;
 }
 }
 }
 else if (section == "comment")
 {
 if(document.getElementById("commentsec" + entryid).innerHTML == "" || bTriedPassportRefresh)
 {
 strText = GetBlogActivity(entryid, "comment", "", bTriedPassportRefresh);
 if (strText.toLowerCase() != "error" && strText.length > 0)
 {
 document.getElementById("commentsec" + entryid).innerHTML = strText;
 }
 else
 {
 fError = true;
 }
 }
 var strLogo = BlogJS_PPLogo;
 strLogo = strLogo.replace("spacesbeid", entryid);
 strLogo = strLogo.replace("tpf", "tpfbak");
 strPost = ShowPostComment(strLogo, entryid);
 if (document.getElementById("postcommentsec"+entryid) != null)
 {
 document.getElementById("postcommentsec"+entryid).innerHTML = strPost;
 }
 if (document.getElementById("txtName"+entryid) != null &&
 document.getElementById("txtName"+entryid).disabled == false)
 {
 document.getElementById("txtName"+entryid).focus();
 }
 }
 if (fError)
 {
 if(bTriedPassportRefresh){
 if(section == "comment"){
 document.getElementById("commentsec" + entryid).innerHTML = "";
 }else if(section == "trackback"){
 sectionTitleObj.innerHTML = "";
 }
 }
 sectionTitleObj.style.display = "none";
 alert(BlogJS_blogjs_errorretrievingcontent);
 }
 else
 {
 sectionTitleObj.scrollIntoView(true);
 }
 }
 function OpenCommentSection(entryid, otherFormFields, bTriedPassportRefresh)
 {
 var section = "comment";
 var fError = false;
 strText = GetBlogActivity(entryid, section, otherFormFields, bTriedPassportRefresh);
 if (strText.toLowerCase() != "error" && strText.length > 0)
 {
 document.getElementById("commentsec" + entryid).innerHTML = strText;
 }
 else
 {
 fError = true;
 }
 var sectionTitleObj = document.getElementById(section+entryid);
 if (fError)
 {
 if(bTriedPassportRefresh){
 document.getElementById("commentsec" + entryid).innerHTML = "";
 }
 sectionTitleObj.style.display = "none";
 alert(BlogJS_blogjs_errorretrievingcontent);
 }
 else
 {
 sectionTitleObj.scrollIntoView(true);
 }
 }
 function GetBlogActivity(entryid, item, otherformfields, bTriedRefresh)
 {
 var response = "";
 var fException = false;
 eval ('try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {xmlhttp = null;}');
 if (xmlhttp != null)
 {
 try{
 xmlhttp.Open("POST", BlogJSPostUrl, false);
 var strA = "handle="+ entryid;
 strA += "&blogitem=" + item;
 strA += "&" + BlogJSBlogPartParam;
 strA += otherformfields;
 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 xmlhttp.Send(strA);
 }catch(e){
 fException = true;
 }
 if(fException){
 if(bTriedRefresh){
 //exception after trying passport refresh, stop here to avoid infinite loop
 response = "error";
 }else{
 //build the response - an iframe that will load up and refresh passport credentials
 var timer = setTimeout(DisplayContentLoadError(item, entryid), 10000); //fail in 10s if not cleared
 var iframeString = "<iframe src=\"/PassportRefresh.aspx?id=" + entryid + "&function=get&timer=" + timer + "&item=" + item + "&formfields=" + otherformfields.replace(/&/g, "%26") + "\" />";
 var divID = "ppRefresh" + item + entryid;
 if(document.getElementById(divID)){
 response = iframeString;
 document.getElementById(divID).style.display = "none";
 }else{
 response = "<div style=\"display:none\" id=\"" + divID + "\">" + iframeString + "</div>";
 }
 }
 }else{
 if(xmlhttp.status != 200){
 response = "error";
 }else{
 response = xmlhttp.responseText;
 }
 }
 }
 return response;
 }
 function DisplayContentLoadError(section, strEntryId){
 return function(){
 //so OpenSection knows to try again and not just re-display the iframe content
 var sectionObj = false;
 if(section == "comment"){
 sectionObj = document.getElementById("commentsec"+strEntryId);
 }else if(section == "trackback"){
 sectionObj = document.getElementById(section+strEntryId);
 }
 if(sectionObj){
 sectionObj.innerHTML = "";
 sectionObj.style.display = "none";
 }
 alert(BlogJS_blogjs_errorretrievingcontent);
 }
 }
 function ReturnFromPassportRefreshGet(entryid, status, timer, item, otherformfields){
 var err = false;
 if(entryid && status){
 //good response, clear fail timer
 if(timer){
 clearTimeout(timer);
 }
 //try to open section again.
 if(item == "comment" && otherformfields && otherformfields.length > 0){
 OpenCommentSection(entryid, otherformfields, true);
 }else{
 OpenSection(item, entryid, true);
 }
 }
 }
 function PostComment(strEntryId, bTriedPassportRefresh)
 {
 var strName = document.getElementById("txtName"+strEntryId);
 var strEmail = document.getElementById("txtEmail"+strEntryId);
 var strUrl = document.getElementById("txtUrl"+strEntryId);
 var strComment = document.getElementById("txtComment"+strEntryId);
 var strError = "";
 var fnServerError = DisplayPostCommentError(strEntryId);
 fName = ValidateName(strName.value);
 if (!fName || strName.value.length > c_Name)
 {
 if (strError.length == 0)
 {
 strName.focus();
 }
 }
 if (!fName)
 {
 strError += "<tr><td width=15><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogjs_namerequired + "</td></tr>";
 }
 else if (strName.value.length > c_Name)
 {
 strError += "<tr><td width=15><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogjs_nametoolong + "</td></tr>";
 }
 fEmail = ValidateEmail(strEmail.value);
 if ( (strEmail.value.length > 0 && !fEmail) ||
 strEmail.value.length > c_Email)
 {
 if (strError.length == 0)
 {
 strEmail.focus();
 }
 }
 if (strEmail.value.length > 0 && !fEmail)
 {
 strError += "<tr><td width=15><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogjs_invalidemail + "</td></tr>";
 }
 else if (strEmail.value.length > c_Email)
 {
 strError += "<tr><td width=15><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogjs_emailtoolong + "</td></tr>";
 }
 if (strUrl.value.length > c_Url)
 {
 if (strError.length == 0)
 {
 strUrl.focus();
 }
 strError += "<tr><td width=15><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogjs_urltoolong + "</td></tr>";
 }
 nCommentLength = strComment.value.trim().length;
 if (nCommentLength == 0 ||
 nCommentLength > c_Comment )
 {
 if (strError.length == 0)
 {
 strComment.focus();
 }
 }
 if (nCommentLength == 0)
 {
 strError += "<tr><td width=15><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogjs_invalidcomment + "</td></tr>";
 }
 else if (nCommentLength > c_Comment)
 {
 strError += "<tr><td width=15><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogjs_commenttoolong + "</td></tr>";
 }
 if (strError.length > 0)
 {
 document.getElementById("Err" + strEntryId).innerHTML = "<table cellspacing=0 border=0 class='bvError'>" + strError + "</table>";
 return;
 }
 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 xmlhttp.Open("POST", BlogJSPostUrl, false);
 var stringReExp = new RegExp ('[&]', 'gi') ;
 var strA = "handle="+strEntryId;
 strA += "&txtname="+ strName.value.replace(/\%/g,"%25").replace(stringReExp, '%26');
 strA += "&txturl="+ strUrl.value.replace(stringReExp, '%26');
 strA += "&txtemail="+ strEmail.value.replace(stringReExp, '%26');
 strA += "&txtcomment="+ strComment.value.replace(/\%/g,"%25").replace(stringReExp, '%26');
 strA += "&" + BlogJSBlogPartBlogView;
 strA += "&" + BlogJSBlogPartParam;
 strA += "&blogitem=addcomment"
 var re = new RegExp ('[+]', 'gi') ;
 strA = strA.replace(re, '%2b') ;
 if (document.getElementById("LastMDate"+strEntryId) != null)
 {
 strA += "&lastmdate=true"
 }
 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 var fException = false;
 try{
 xmlhttp.Send(strA);
 }catch(e){
 fException = true;
 }
 if(fException){
 if(bTriedPassportRefresh){
 //stop to avoid infinite loop
 fnServerError();
 }else{
 //exceptions occur when passport refresh fails
 //build the response - an iframe that will load up and refresh passport credentials
 var timer = setTimeout(fnServerError, 10000); //fail in 10s if not cleared
 var divID = "ppPostRefresh" + strEntryId;
 var iframeString = "<iframe style=\"display:none\" src=\"/PassportRefresh.aspx?id=" + strEntryId + "&function=post&timer=" + timer + "\" />";
 var div = document.getElementById(divID)
 if(!div){
 div = document.createElement("div");
 div.style.display = "none";
 div.id = divID;
 document.getElementById("entry"+strEntryId).appendChild(div);
 }
 div.innerHTML = iframeString;
 }
 }
 else if (xmlhttp.responseText.toLowerCase() == "error")
 {
 fnServerError();
 }
 else if (xmlhttp.responseText.toLowerCase() == "itemcontainsprofanity")
 {
 document.getElementById("Err"+strEntryId).innerHTML = "<table cellspacing=3 class='bvError'><tr><td width=15 valign=top><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogview_containsprofanity + "</td></tr></table>";
 }
 else
 {
 document.getElementById("entry"+strEntryId).innerHTML = xmlhttp.responseText;
 OpenSection("comment", strEntryId);
 document.getElementById("txtName"+strEntryId).value = strNickName;
 }
 }
 function DisplayPostCommentError(strEntryId){
 return function(){
 document.getElementById("Err"+strEntryId).innerHTML = "<table cellspacing=3 class='bvError'><tr><td width=15 valign=top><img src='images/error_icon.gif' width=15 height=16 border=0></td><td height=20 width=100%>" + BlogJS_blogview_servererror + "</td></tr></table>";
 }
 }
 function ReturnFromPassportRefreshPost(entryid, status, timer){
 if(entryid && status){
 //good response, clear fail timer
 if(timer){
 clearTimeout(timer);
 }
 //Post comment again.
 PostComment(entryid, true);
 }
 }
 function CloseComment(strComment, strEntryId)
 {
 CleanUpFields(strEntryId);
 Close(strComment, strEntryId);
 }
 function CleanUpFields(strEntryId)
 {
 if (document.getElementById("err"+strEntryId) != null)
 {
 document.getElementById("Err"+strEntryId).innerHTML = "";
 document.getElementById("txtName"+strEntryId).value = "";
 document.getElementById("txtEmail"+strEntryId).value = "";
 document.getElementById("txtUrl"+strEntryId).value = "";
 document.getElementById("txtComment"+strEntryId).value = "";
 }
 }
