﻿function gsPoster()
{
    this.oAttachLinkReq = null;
}

gsPoster.prototype =
{
    init: function () 
    {
        var oMe = this;
    },

    addPost: function (tp) 
    {
        var type = (typeof (tp) != undefined && tp != null && isNaN(tp) == false) ? tp : 0;

        if (document.getElementById("addPostForm") == undefined) {
            var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body

            var dsocleft = document.all ? iebody.scrollLeft : pageXOffset
            var dsoctop = document.all ? iebody.scrollTop : pageYOffset

            var oForm = document.createElement("div");
            oForm.id = "addPostForm";
            oForm.className = "popupform";
            oForm.style.width = "506px";
            //oForm.style.height = "406px";
            oForm.style.left = ((oInfo.clientWidth / 4) + (506 / 4)) - 250;
            oForm.style.top = (((dsoctop > 150) ? dsoctop : 150) + 50) + "px";

            var oInnerForm = document.createElement("div");
            oInnerForm.id = "addPostForm_inner";
            oInnerForm.className = "innerform";
            oInnerForm.style.width = "480px";
            //oInnerForm.style.height = "380px";

            var sFormHTML = "";
            sFormHTML += "<table style = \"width:100%;\" border = \"0\" cellpadding = \"0\" cellspacing = \"3\">";

            sFormHTML += "<tr>";
            sFormHTML += "<td valign = \"middle\">";
            sFormHTML += "<div id = \"poster_attachment_options\" style = \"padding:5px 0px 5px 0px;\">";
            sFormHTML += "<span id = \"poster_attachment_options_0\" onclick = \"oPoster.SelectAttachment(0);\" class = \"selected\"><img src = \"assets/images/icons/status.png\" alt = \"Status Update\" /> Status</span> &nbsp; &nbsp; ";
            sFormHTML += "<span id = \"poster_attachment_options_1\" onclick = \"oPoster.SelectAttachment(1);\"><img src = \"assets/images/icons/link.png\" alt = \"Attach a Link\" /> Link</span> &nbsp; &nbsp; ";
            sFormHTML += "<span id = \"poster_attachment_options_2\" onclick = \"oPoster.SelectAttachment(2);\"><img src = \"assets/images/icons/picture.png\" alt = \"Attach a Picture\" /> Picture</span> &nbsp; &nbsp; ";
            sFormHTML += "<span id = \"poster_attachment_options_3\" onclick = \"oPoster.SelectAttachment(3);\"><img src = \"assets/images/icons/recipe.png\" alt = \"Attach a Recipe\" /> Recipe</span> &nbsp; &nbsp; ";
            sFormHTML += "<span id = \"poster_attachment_options_4\" onclick = \"oPoster.SelectAttachment(4);\"><img src = \"assets/images/icons/review.png\" alt = \"Attach a Review\" /> Review</span> &nbsp; &nbsp; ";
            sFormHTML += "<span id = \"poster_attachment_options_5\" onclick = \"oPoster.SelectAttachment(5);\"><img src = \"assets/images/icons/article.png\" alt = \"Attach a Article\" /> Article</span>";
            sFormHTML += "</div>";
            sFormHTML += "</td>";
            sFormHTML += "</tr>";

            sFormHTML += "<tr>";
            sFormHTML += "<td valign = \"middle\">";
            sFormHTML += "<div><textarea id = \"post_text\" style = \"width:99%;height:60px;\"></textarea></div>";
            sFormHTML += "</td>";
            sFormHTML += "</tr>";

            sFormHTML += "<tr>";
            sFormHTML += "<td valign = \"middle\">";

            sFormHTML += "<div class = \"attachments\">";

            // Link
            sFormHTML += "<div id = \"addpost_linkattachment\" class = \"attachlink\">";

            sFormHTML += "<div class = \"title\">";
            sFormHTML += "<span class = \"heading\">Link</span>";
            sFormHTML += "<span class = \"close\" onclick = \"oPoster.CancelAttachment();\"></span>";
            sFormHTML += "</div>";

            sFormHTML += "<div id = \"addpost_linkattachment_selector\" class = \"selectorbox\">";
            sFormHTML += "<div class = \"linkattachment_addurl\">";
            sFormHTML += "<input type = \"text\" id = \"addpost_linkattachment_url\" value = \"http://\" class = \"focusoff\" onfocus = \"if(this.className == 'focusoff'){this.value = '';};this.className = 'focuson';\" />";
            sFormHTML += "<input type = \"button\" id = \"AttachLinkButton\" value = \"Attach\" onclick = \"oPoster.attachLinkToPost();\" />";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div id = \"addpost_linkattachment_previewbox\" class = \"previewbox\">";

            sFormHTML += "<div class = \"previewimage\">";
            sFormHTML += "<img id = \"addpost_linkattachment_previewimage\" src = \"assets/images/transpx.png\" alt = \"\" align = \"left\" />";
            sFormHTML += "<div id = \"addpost_linkattachment_previewbox_imagelist\"></div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"previewcontent\">";
            sFormHTML += "<span id = \"linkPreviewTitle\"></span>";
            sFormHTML += "<input type = \"text\" id = \"linkPreviewTitle_Editable\" style = \"width:70%;font-size:11px;display:none;\" />";

            sFormHTML += "<div id = \"linkPreviewAddr\" class = \"linkaddr\"></div>";

            sFormHTML += "<span id = \"linkPreviewDescrip\"></span>";
            sFormHTML += "<textarea id = \"linkPreviewDescrip_Editable\" style = \"width:70%;font-size:11px;display:none;\"></textarea>";

            sFormHTML += "<div class = \"imageselector\">";
            sFormHTML += "<div id = \"addpost_linkattachment_previewbox_imagelist_selector_cntrls\" class = \"pnctrls\">";
            sFormHTML += "<a href = \"javascript:void(0);\" class = \"prevdisabled\" onclick = \"oPoster.selectPostLinkImage(-1);\" unselectable = \"on\">&nbsp;</a>";
            sFormHTML += "<a href = \"javascript:void(0);\" class = \"nextdisabled\" onclick = \"oPoster.selectPostLinkImage(1);\" unselectable = \"on\">&nbsp;</a>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"info\">";
            sFormHTML += "<span><span id = \"addpost_linkattachment_previewbox_imagelist_selectorselected\">0</span> of <span id = \"addpost_linkattachment_previewbox_imagelist_selectorcountertotal\">0</span></span>";
            sFormHTML += "<span class = \"message\">Choose a Thumbnail</span>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "</div>";
            sFormHTML += "</div>";

            // Image
            sFormHTML += "<div id = \"addpost_imageattachment\" class = \"attachimage\">";
            sFormHTML += "<div class = \"title\">";
            sFormHTML += "<span class = \"heading\">Image</span>";
            sFormHTML += "<span class = \"close\" onclick = \"oPoster.CancelAttachment();\"></span>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"GSPostImage\">";
            sFormHTML += "<form id=\"addForm_piff\" action=\"ajax/postimage.aspx\" target=\"addForm_pif\" method=\"post\" enctype=\"multipart/form-data\"><input type = \"file\" id = \"GSPostImageUploader\" name = \"GSPostImageUploader\" /></form>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"previewbox\"></div>";
            sFormHTML += "<iframe id = \"addForm_pif\" name = \"addForm_pif\" style = \"width:400px;height:150px;display:none;\" src = \"about:blank\" onload = \"oPoster.onImagePostUploadComplete();\" frameborder = \"0\" scrolling = \"on\"></iframe>";
            sFormHTML += "</div>";

            // Recipe
            sFormHTML += "<div id = \"addpost_recipeattachment\" class = \"attachrecipe\">";
            sFormHTML += "<div class = \"title\">";
            sFormHTML += "<span class = \"heading\">Recipe</span>";
            sFormHTML += "<span class = \"close\" onclick = \"oPoster.CancelAttachment();\"></span>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<p class = \"red small\" style = \"margin-top:0px;\">";
            sFormHTML += "Fields marked with an asterisk (*) are required.";
            sFormHTML += "</p>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"recipetitle\">";
            sFormHTML += "<label>* Name:</label>";
            sFormHTML += "<div><input type = \"text\" id = \"addpost_recipeattachment_title\" style = \"width:425px;\" /></div>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"recipeingredientslist\">";
            sFormHTML += "<table border = \"0\" cellspacing = \"0\" cellpadding = \"0\" style = \"width:430px;text-align:center;\">";
            sFormHTML += "<tr>";
            sFormHTML += "<td valign = \"top\" style = \"width:33.3%;\">";
            sFormHTML += "<div style = \"padding-top:5px;padding-bottom:5px;\"><label>* Serves:</label></div>";
            sFormHTML += " <input type = \"text\" id = \"addpost_recipeattachment_serves\" style = \"width:100px;\" />";
            sFormHTML += "<div>";
            sFormHTML += "</td>";
            sFormHTML += "<td valign = \"top\" style = \"width:33.3%;\">";
            sFormHTML += "<div style = \"padding-bottom:5px;\"><label>Prep Time:</label></div>";
            sFormHTML += " <input type = \"text\" id = \"addpost_recipeattachment_preptime\" style = \"width:100px;\" />";
            sFormHTML += "<div>";
            sFormHTML += "</td>";
            sFormHTML += "<td valign = \"top\" style = \"width:33.3%;\">";
            sFormHTML += "<div style = \"padding-top:5px;padding-bottom:5px;\"><label>Cooking Time:</label></div>";
            sFormHTML += " <input type = \"text\" id = \"addpost_recipeattachment_cookingtime\" style = \"width:100px;\" />";
            sFormHTML += "<div>";
            sFormHTML += "</td>";
            sFormHTML += "</tr>";
            sFormHTML += "</table>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"recipemethod\">";
            sFormHTML += "<div><label>* Ingredients:</label></div>";
            sFormHTML += "<textarea id = \"addpost_recipeattachment_ingredients\" style = \"width:427px;height:80px;\">";
            sFormHTML += "</textarea>";
            sFormHTML += "<div class = \"red small\">NB: List each ingredient on a new line.</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"recipemethod\">";
            sFormHTML += "<div><label>* Method:</label></div>";
            sFormHTML += "<textarea id = \"addpost_recipeattachment_method\" style = \"width:427px;height:80px;\">";
            sFormHTML += "</textarea>";
            sFormHTML += "<div class = \"red small\">NB: Leave a new line between each step.</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"recipeadditionalinformation\">";
            sFormHTML += "<div><label>Additional Information:</label></div>";
            sFormHTML += "<textarea id = \"addpost_recipeattachment_additionalinformation\" style = \"width:427px;height:50px;\">";
            sFormHTML += "</textarea>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"pics\">Pictures:</div>";
            sFormHTML += "<form id=\"addForm_prff\" action=\"ajax/postrecipeimage.aspx\" target=\"addForm_prf\" method=\"post\" enctype=\"multipart/form-data\">";
            sFormHTML += "<div class = \"GSPostRecipeImage\">";
            sFormHTML += "<input type = \"file\" id = \"GSPostRecipeImageUploader\" name = \"GSPostRecipeImageUploader\" />";
            sFormHTML += "<input type = \"hidden\" id = \"rid\" name = \"rid\" />";
            sFormHTML += "</div>";
            sFormHTML += "</form>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"previewbox\"></div>";
            sFormHTML += "<iframe id = \"addForm_prf\" name = \"addForm_prf\" style = \"width:300px;height:150px;display:none;\" src = \"about:blank\" onload = \"oPoster.onRecipeImagePostUploadComplete();\" frameborder = \"0\" scrolling = \"on\"></iframe>";
            sFormHTML += "</div>";

            // Review
            sFormHTML += "<div id = \"addpost_reviewattachment\" class = \"attachreview\">";
            sFormHTML += "<div class = \"title\">";
            sFormHTML += "<span class = \"heading\">Review</span>";
            sFormHTML += "<span class = \"close\" onclick = \"oPoster.CancelAttachment();\"></span>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"reviewtitle\">";
            sFormHTML += "<label>Name:</label>";
            sFormHTML += "<div><input type = \"text\" id = \"addpost_reviewattachment_title\" style = \"width:625px;\" /></div>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"reviewcategory\">";
            sFormHTML += "<div style = \"padding-top:5px;\"><label>Category:</label></div>";
            sFormHTML += "<div>";
            sFormHTML += "<select id = \"addpost_reviewattachment_category\" style = \"width:300px;\">";
            sFormHTML += "<option value = \"\">- select -</option>";
            sFormHTML += "<option value = \"1\">Desitination</option>";
            sFormHTML += "<option value = \"2\">Restaurant</option>";
            sFormHTML += "<option value = \"3\">Product</option>";
            sFormHTML += "<option value = \"4\">Service</option>";
            sFormHTML += "</select>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"reviewtext\">";
            sFormHTML += "<div><label>Review Text:</label></div>";
            sFormHTML += "<textarea id = \"addpost_reviewattachment_review\" style = \"width:625px;height:200px;\">";
            sFormHTML += "</textarea>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"pics\">Pictures:</div>";
            sFormHTML += "<form id=\"addForm_prvff\" action=\"ajax/postreviewimage.aspx\" target=\"addForm_prvf\" method=\"post\" enctype=\"multipart/form-data\">";
            sFormHTML += "<div class = \"GSPostReviewImage\">";
            sFormHTML += "<input type = \"file\" id = \"GSPostReviewImageUploader\" name = \"GSPostReviewImageUploader\" />";
            sFormHTML += "<input type = \"hidden\" id = \"rvid\" name = \"rvid\" />";
            sFormHTML += "</div>";
            sFormHTML += "</form>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"previewbox\"></div>";
            sFormHTML += "<iframe id = \"addForm_prvf\" name = \"addForm_prvf\" style = \"width:150px;height:120px;display:none;\" src = \"about:blank\" onload = \"oPoster.onReviewImagePostUploadComplete();\" frameborder = \"0\" scrolling = \"on\"></iframe>";
            sFormHTML += "</div>";

            // Article
            sFormHTML += "<div id = \"addpost_articleattachment\" class = \"attacharticle\">";
            sFormHTML += "<div class = \"title\">";
            sFormHTML += "<span class = \"heading\">Article</span>";
            sFormHTML += "<span class = \"close\" onclick = \"oPoster.CancelAttachment();\"></span>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"articletitle\">";
            sFormHTML += "<label>Title:</label>";
            sFormHTML += "<div><input type = \"text\" id = \"addpost_articleattachment_title\" style = \"width:650px;\" /></div>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"reviewtext\">";
            sFormHTML += "<div><label>Body:</label></div>";
            sFormHTML += "<textarea id = \"addpost_articleattachment_article\" style = \"width:645px;height:300px;\">";
            sFormHTML += "</textarea>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"selectorbox\">";
            sFormHTML += "<div class = \"pics\">Pictures:</div>";
            sFormHTML += "<form id=\"addForm_paff\" action=\"ajax/postarticleimage.aspx\" target=\"addForm_paf\" method=\"post\" enctype=\"multipart/form-data\">";
            sFormHTML += "<div class = \"GSPostArticleImage\">";
            sFormHTML += "<input type = \"file\" id = \"GSPostArticleImageUploader\" name = \"GSPostArticleImageUploader\" />";
            sFormHTML += "<input type = \"hidden\" id = \"artclid\" name = \"artclid\" />";
            sFormHTML += "</div>";
            sFormHTML += "</form>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"previewbox\"></div>";
            sFormHTML += "<iframe id = \"addForm_paf\" name = \"addForm_paf\" style = \"width:150px;height:120px;display:none;\" src = \"about:blank\" onload = \"oPoster.onArticleImagePostUploadComplete();\" frameborder = \"0\" scrolling = \"on\"></iframe>";
            sFormHTML += "</div>";

            sFormHTML += "<div style = \"display:none;\">";
            sFormHTML += "<div class = \"promotepost\"><input type = \"checkbox\" id = \"promotepost\" /> <span>FEATURE THIS POST?</span> &nbsp; &nbsp; <a href = \"javascript:void(0);\">[ learn more ]</a></div>";
            sFormHTML += "</div>";

            sFormHTML += "<div class = \"servebuttons\" style = \"padding-top:10px;\">";
            sFormHTML += "<input type = \"button\" id = \"GSPosterSubmitButton\" value = \"Serve\" onclick = \"oPoster.servePost();\" />";
            sFormHTML += "<input type = \"button\" id = \"GSPosterCancelButton\" value = \"Cancel\" onclick = \"oPoster.cancelPost();\" style = \"margin-left:5px;\" />";
            sFormHTML += "<img id = \"addPost_BPIndicator\" src = \"assets/images/transpx.png\" alt = \"Bust Serving...\" />";
            sFormHTML += "</div>";
            sFormHTML += "</div>";
            sFormHTML += "</div>";

            sFormHTML += "</td>";
            sFormHTML += "</tr>";


            sFormHTML += "</table>";
            sFormHTML += "<input type = \"hidden\" id = \"post_title\" />";
            sFormHTML += "<input type = \"hidden\" id = \"post_descrip\" />";
            sFormHTML += "<input type = \"hidden\" id = \"post_url\" />";
            sFormHTML += "<input type = \"hidden\" id = \"post_image\" />";
            sFormHTML += "<input type = \"hidden\" id = \"post_recipe\" />";
            sFormHTML += "<input type = \"hidden\" id = \"post_review\" />";
            sFormHTML += "<input type = \"hidden\" id = \"post_article\" />";
            sFormHTML += "<input type = \"hidden\" id = \"post_type\" value = \"0\" />";

            oInnerForm.innerHTML = "<div class = \"margin\">" + sFormHTML + "</div>";

            oForm.appendChild(oInnerForm);

            var oBody = document.getElementsByTagName("body")[0];

            oBody.appendChild(oForm);

            // Add the WYSIWYG Editors
            tinyMCE.init({
                mode: "none",
                theme: "advanced",
                plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

                theme_advanced_buttons1: "cut,copy,pastetext,pasteword,|,search,replace,|,undo,redo,|,cleanup,visualaid,fullscreen",
                theme_advanced_buttons2: "ltr,rtl,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,tablecontrols,|,hr",
                theme_advanced_buttons3: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,styleprops,removeformat,|,sub,sup",

                theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align: "left",
                theme_advanced_statusbar_location: "bottom"
            });

            //tinyMCE.execCommand("mceAddControl", true, "addpost_articleattachment_article");

            this.SelectAttachment(((type != null) ? type : 0));
        }
    },

    removePost: function (postid) {
        var oMe = oPoster;

        if (postid != null && postid != "" && isNaN(postid) == false && parseInt(postid) > 0) {
            if (confirm("Are you sure you want to remove this post?") == true) {
                var params = new Array();
                params[0] = "pid=" + parseInt(postid);

                var func = function () {
                    if (arguments[0] != null) {
                        if (arguments[0].readyState == 4) {
                            if (arguments[0].status == 200) {
                                if (arguments[0].responseText == "True") {
                                    setTimeout(function () {
                                        document.getElementById("_post_" + postid).style.display = "none";
                                        //alert("Post Removed");                          

                                    }, 0);
                                }
                                else {
                                    setTimeout(function () {
                                        alert("This post could not be removed at this time. Please try again a little bit later.");
                                    }, 0);
                                }
                            }
                        }
                        else {
                        }
                    }
                };

                var oRemovePostReq = oAjaxTools.getData(13, params, true, func);
            }
        }
    },

    getPostUI: function (postid) {
        var oMe = oPoster;
        var UIHTML = "";

        if (postid != null && isNaN(postid) == false) {
            var params = new Array();
            params[0] = "pid=" + parseInt(postid);

            var func = function () {
                if (arguments[0] != null) {
                    if (arguments[0].readyState == 4) {
                        if (arguments[0].status == 200) {
                            UIHTML = arguments[0].responseText;

                            alert(UIHTML)
                        }
                    }
                }
            };

            var UIHTML = oAjaxTools.getData(17, params, false, null);
        }

        return UIHTML;
    },

    servePost: function () {
        var oMe = oPoster;

        document.getElementById("addPost_BPIndicator").style.visibility = "visible";

        var text = oMe.encodeDataForPost((typeof (document.getElementById("post_text")) != undefined) ? document.getElementById("post_text").value : "");
        var title = oMe.encodeDataForPost((typeof (document.getElementById("post_title")) != undefined) ? document.getElementById("post_title").value : "");
        var descrip = oMe.encodeDataForPost((typeof (document.getElementById("post_descrip")) != undefined) ? document.getElementById("post_descrip").value : "");
        var url = oMe.encodeDataForPost((typeof (document.getElementById("post_url")) != undefined) ? document.getElementById("post_url").value : "");
        var image = oMe.encodeDataForPost((typeof (document.getElementById("post_image")) != undefined) ? document.getElementById("post_image").value : "");
        var recipe = oMe.encodeDataForPost((typeof (document.getElementById("post_recipe")) != undefined) ? document.getElementById("post_recipe").value : "");
        var review = oMe.encodeDataForPost((typeof (document.getElementById("post_review")) != undefined) ? document.getElementById("post_review").value : "");
        var article = oMe.encodeDataForPost((typeof (document.getElementById("post_article")) != undefined) ? document.getElementById("post_article").value : "");

        var type = oMe.encodeDataForPost((typeof (document.getElementById("post_type")) != undefined) ? document.getElementById("post_type").value : "0");

        var fv = true;

        // if the post does not have an attachment and has no post text
        if (parseInt(type) == 0 && text == "") {
            fv = false;
        }

        // if the post has a link attachment and has no title
        if (parseInt(type) == 1 && title == "") {
            fv = false;
        }

        // if the post has a image attachment and has no image
        if (parseInt(type) == 2 && image == "") {
            fv = false;
        }

        if ((fv == true) && ((text != "" && parseInt(type) == 0) || (text == "" && parseInt(type) > 0) || (text != "" && parseInt(type) > 0))) {
            document.body.scrollTop = 0;

            document.getElementById("post_text").disabled = true;
            document.getElementById("GSPosterSubmitButton").disabled = true;

            var params = new Array();
            params[0] = "pid=" + parseInt(document.getElementById("pid").value);
            params[1] = "type=" + parseInt(type);
            params[2] = "text=" + text.replace(new RegExp("\'", "ig"), "''");
            params[3] = "title=" + title.replace(new RegExp("\'", "ig"), "''");
            params[4] = "descrip=" + descrip.replace(new RegExp("\'", "ig"), "''")
            params[5] = "url=" + url;
            params[6] = "img=" + image;
            params[7] = "recipe=" + recipe;
            params[8] = "review=" + review;
            params[9] = "article=" + article;

            var func = function () {
                if (arguments[0] != null) {
                    if (arguments[0].readyState == 4) {
                        if (arguments[0].status == 200) {
                            var reply = arguments[0].responseText;

                            if (reply.indexOf("[gs-nrid:") > -1) {
                                var postid = parseInt(reply.substring(reply.indexOf(":") + 1, reply.lastIndexOf("]")));

                                setTimeout(function () {
                                    document.getElementById("addPost_BPIndicator").style.visibility = "hidden";

                                    // Add new post to page
                                    document.getElementById("post_text").value = "";
                                    document.getElementById("post_text").disabled = false;
                                    document.getElementById("GSPosterSubmitButton").disabled = false;

                                    oMe.ClearAttachments();
                                    oMe.SelectAttachment(0);

                                    // Close the poster
                                    oMe.closeAddPost();

                                    // Insert the Post
                                    if (isNaN(postid) == false) {
                                        var uiHTML = oMe.getPostUI(postid);
                                        document.getElementById("PostsList").innerHTML = uiHTML + document.getElementById("PostsList").innerHTML;
                                    }

                                }, 750);
                            }
                            else {
                                document.getElementById("addPost_BPIndicator").style.visibility = "hidden";

                                setTimeout(function () {
                                    // alert error
                                    document.getElementById("post_text").disabled = false;
                                    document.getElementById("GSPosterSubmitButton").disabled = false;
                                }, 750);
                            }
                        }
                    }
                    else {
                        document.getElementById("post_text").disabled = true;
                        document.getElementById("GSPosterSubmitButton").disabled = true;
                    }
                }
            };

            var oNewPostReq = oAjaxTools.getData(12, params, true, func);
        }
        else {
            document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
            alert("There are outstanding fields!");
        }
    },

    serveImagePost: function () {
        document.getElementById("addPost_BPIndicator").style.visibility = "visible";

        var type = oPoster.encodeDataForPost((typeof (document.getElementById("post_type")) != undefined) ? document.getElementById("post_type").value : "0");

        if (parseInt(type) == 2) {
            if (typeof (document.getElementById("GSPostImageUploader")) != undefined) {
                if (document.getElementById("GSPostImageUploader").value != "") {
                    if (typeof (document.getElementById("addForm_piff")) != undefined) {
                        document.getElementById("addForm_piff").submit();
                    }
                    else {
                        document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
                    }
                }
            }
        }
    },

    serveRecipePost: function () {
        var oMe = oPoster;

        document.getElementById("addPost_BPIndicator").style.visibility = "visible";

        var name = oMe.encodeDataForPost((typeof (document.getElementById("addpost_recipeattachment_title")) != undefined) ? document.getElementById("addpost_recipeattachment_title").value : "");
        var preptime = oMe.encodeDataForPost((typeof (document.getElementById("addpost_recipeattachment_preptime")) != undefined) ? document.getElementById("addpost_recipeattachment_preptime").value : "");
        var cookingtime = oMe.encodeDataForPost((typeof (document.getElementById("addpost_recipeattachment_cookingtime")) != undefined) ? document.getElementById("addpost_recipeattachment_cookingtime").value : "");
        var serves = oMe.encodeDataForPost((typeof (document.getElementById("addpost_recipeattachment_serves")) != undefined) ? document.getElementById("addpost_recipeattachment_serves").value : "");
        var ingredients = oMe.encodeDataForPost((typeof (document.getElementById("addpost_recipeattachment_ingredients")) != undefined) ? document.getElementById("addpost_recipeattachment_ingredients").value : "");
        var method = oMe.encodeDataForPost((typeof (document.getElementById("addpost_recipeattachment_method")) != undefined) ? document.getElementById("addpost_recipeattachment_method").value : "");
        var additionalinformation = oMe.encodeDataForPost((typeof (document.getElementById("addpost_recipeattachment_additionalinformation")) != undefined) ? document.getElementById("addpost_recipeattachment_additionalinformation").value : "");
        var comment = oMe.encodeDataForPost((typeof (document.getElementById("post_text")) != undefined) ? document.getElementById("post_text").value : "");

        var fv = true;

        // if the recipe has no name
        if (name == "") {
            fv = false;
        }

        // if the ingredients field is blank
        if (serves == "") {
            fv = false;
        }

        // if the ingredients field is blank
        if (ingredients == "") {
            fv = false;
        }

        // if the method field is blank
        if (method == "") {
            fv = false;
        }

        if (fv == true) {
            document.body.scrollTop = 0;

            document.getElementById("post_text").disabled = true;
            document.getElementById("GSPosterSubmitButton").disabled = true;

            var params = new Array();
            params[0] = "pid=" + parseInt(document.getElementById("pid").value);
            params[1] = "name=" + name;
            params[2] = "preptime=" + preptime.replace(new RegExp("\'", "ig"), "''");
            params[3] = "cookingtime=" + cookingtime.replace(new RegExp("\'", "ig"), "''");
            params[4] = "serves=" + serves;
            params[5] = "ingredients=" + ingredients;
            params[6] = "method=" + method;
            params[7] = "additionalinformation=" + additionalinformation;
            params[8] = "comment=" + comment;

            // Set the Post Title
            document.getElementById("post_title").value = name;

            var func = function () {
                if (arguments[0] != null) {
                    if (arguments[0].readyState == 4) {
                        if (arguments[0].status == 200) {
                            if (arguments[0].responseText.indexOf("True[gs-nrid:") > -1) {
                                document.getElementById("addForm_prff").action = "ajax/postrecipeimage.aspx";

                                var rid = arguments[0].responseText;
                                rid = rid.substring(rid.indexOf("[gs-nrid:") + 9, rid.lastIndexOf("]"));

                                if (typeof (document.getElementById("rid")) != undefined) {
                                    document.getElementById("rid").value = rid;
                                }

                                document.getElementById("post_recipe").value = rid;

                                if (document.getElementById("GSPostRecipeImageUploader").value != "") {
                                    setTimeout(function () {
                                        if (typeof (document.getElementById("GSPostRecipeImageUploader")) != undefined) {
                                            if (document.getElementById("GSPostRecipeImageUploader").value != "") {
                                                if (typeof (document.getElementById("addForm_prff")) != undefined) {
                                                    document.getElementById("addForm_prff").action = "ajax/postrecipeimage.aspx?r=" + rid;
                                                    document.getElementById("addForm_prff").submit();
                                                }
                                                else {
                                                    document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
                                                }
                                            }
                                        }
                                    }, 750);
                                }
                                else {
                                    oMe.servePost();
                                }
                            }
                            else {
                                document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
                                document.getElementById("addForm_prff").action = "ajax/postrecipeimage.aspx";

                                setTimeout(function () {
                                    // alert error
                                    document.getElementById("post_text").disabled = false;
                                    document.getElementById("GSPosterSubmitButton").disabled = false;
                                }, 750);
                            }
                        }
                    }
                    else {
                        document.getElementById("post_text").disabled = true;
                        document.getElementById("GSPosterSubmitButton").disabled = true;
                    }
                }
            };

            var oNewPostReq = oAjaxTools.getData(16, params, true, func);
        }
        else {
            document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
            alert("There are outstanding fields!");
        }
    },

    serveReviewPost: function () {
        var oMe = oPoster;

        document.getElementById("addPost_BPIndicator").style.visibility = "visible";

        var name = oMe.encodeDataForPost((typeof (document.getElementById("addpost_reviewattachment_title")) != undefined) ? document.getElementById("addpost_reviewattachment_title").value : "");
        var reviewtext = oMe.encodeDataForPost((typeof (document.getElementById("addpost_reviewattachment_review")) != undefined) ? document.getElementById("addpost_reviewattachment_review").value : "");
        var category = oMe.encodeDataForPost((typeof (document.getElementById("addpost_reviewattachment_category")) != undefined) ? document.getElementById("addpost_reviewattachment_category").value : "");
        var comment = oMe.encodeDataForPost((typeof (document.getElementById("post_text")) != undefined) ? document.getElementById("post_text").value : "");

        var fv = true;

        // if the review has no name
        if (name == "") {
            fv = false;
        }

        // if the review text field is blank
        if (reviewtext == "") {
            fv = false;
        }

        if (fv == true) {
            document.body.scrollTop = 0;

            document.getElementById("post_text").disabled = true;
            document.getElementById("GSPosterSubmitButton").disabled = true;

            var params = new Array();
            params[0] = "pid=" + parseInt(document.getElementById("pid").value);
            params[1] = "name=" + name;
            params[2] = "reviewtext=" + reviewtext.replace(new RegExp("\'", "ig"), "''");
            params[3] = "category=" + category.replace(new RegExp("\'", "ig"), "''");
            params[4] = "comment=" + comment;

            // Set the Post Title
            document.getElementById("post_title").value = name;

            var func = function () {
                if (arguments[0] != null) {
                    if (arguments[0].readyState == 4) {
                        if (arguments[0].status == 200) {
                            //alert(arguments[0].responseText)

                            if (arguments[0].responseText.indexOf("True[gs-nrid:") > -1) {
                                document.getElementById("addForm_prvff").action = "ajax/postreviewimage.aspx";

                                var rvid = arguments[0].responseText;
                                rvid = rvid.substring(rvid.indexOf("[gs-nrid:") + 9, rvid.lastIndexOf("]"));

                                if (typeof (document.getElementById("rvid")) != undefined) {
                                    document.getElementById("rvid").value = rvid;
                                }

                                document.getElementById("post_review").value = rvid;

                                if (document.getElementById("GSPostReviewImageUploader").value != "") {
                                    setTimeout(function () {
                                        if (typeof (document.getElementById("GSPostReviewImageUploader")) != undefined) {
                                            if (document.getElementById("GSPostReviewImageUploader").value != "") {
                                                if (typeof (document.getElementById("addForm_prvff")) != undefined) {
                                                    document.getElementById("addForm_prvff").action = "ajax/postreviewimage.aspx?r=" + rvid;
                                                    document.getElementById("addForm_prvff").submit();
                                                }
                                                else {
                                                    document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
                                                }
                                            }
                                        }
                                    }, 750);
                                }
                                else {
                                    oMe.servePost();
                                }
                            }
                            else {
                                document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
                                document.getElementById("addForm_prvff").action = "ajax/postreviewimage.aspx";

                                setTimeout(function () {
                                    // alert error
                                    document.getElementById("post_text").disabled = false;
                                    document.getElementById("GSPosterSubmitButton").disabled = false;
                                }, 750);
                            }
                        }
                    }
                    else {
                        document.getElementById("post_text").disabled = true;
                        document.getElementById("GSPosterSubmitButton").disabled = true;
                    }
                }
            };

            var oNewPostReq = oAjaxTools.getData(18, params, true, func);
        }
        else {
            document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
            alert("There are outstanding fields!");
        }
    },

    serveArticlePost: function () {
        var oMe = oPoster;

        document.getElementById("addPost_BPIndicator").style.visibility = "visible";

        var title = oMe.encodeDataForPost((typeof (document.getElementById("addpost_articleattachment_title")) != undefined) ? document.getElementById("addpost_articleattachment_title").value : "");
        var articlebody = oMe.encodeDataForPost((typeof (document.getElementById("addpost_articleattachment_article")) != undefined) ? document.getElementById("addpost_articleattachment_article").value : "");

        if (typeof (tinyMCE) != 'undefined') {
            if (tinyMCE.get('addpost_articleattachment_article') != null) {
                articlebody = tinyMCE.get('addpost_articleattachment_article').getContent();
            }
        }

        var comment = oMe.encodeDataForPost((typeof (document.getElementById("post_text")) != undefined) ? document.getElementById("post_text").value : "");

        var fv = true;

        // if the article has no title
        if (title == "") {
            fv = false;
        }

        // if the article body field is blank
        if (articlebody == "") {
            fv = false;
        }

        if (fv == true) {
            document.body.scrollTop = 0;

            document.getElementById("post_text").disabled = true;
            document.getElementById("GSPosterSubmitButton").disabled = true;

            var params = new Array();
            params[0] = "pid=" + parseInt(document.getElementById("pid").value);
            params[1] = "title=" + title;
            params[2] = "articlebody=" + articlebody.replace(new RegExp("\'", "ig"), "''");
            params[4] = "comment=" + comment;

            // Set the Post Title
            document.getElementById("post_title").value = title;

            var func = function () {
                if (arguments[0] != null) {
                    if (arguments[0].readyState == 4) {
                        if (arguments[0].status == 200) {
                            //alert(arguments[0].responseText)

                            if (arguments[0].responseText.indexOf("True[gs-nrid:") > -1) {
                                document.getElementById("addForm_paff").action = "ajax/postarticleimage.aspx";

                                var artclid = arguments[0].responseText;
                                artclid = artclid.substring(artclid.indexOf("[gs-nrid:") + 9, artclid.lastIndexOf("]"));

                                if (typeof (document.getElementById("artclid")) != undefined) {
                                    document.getElementById("artclid").value = artclid;
                                }

                                document.getElementById("post_article").value = artclid;

                                if (document.getElementById("GSPostArticleImageUploader").value != "") {
                                    setTimeout(function () {
                                        if (typeof (document.getElementById("GSPostArticleImageUploader")) != undefined) {
                                            if (document.getElementById("GSPostArticleImageUploader").value != "") {
                                                if (typeof (document.getElementById("addForm_paff")) != undefined) {
                                                    document.getElementById("addForm_paff").action = "ajax/postarticleimage.aspx?r=" + artclid;
                                                    document.getElementById("addForm_paff").submit();
                                                }
                                                else {
                                                    document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
                                                }
                                            }
                                        }
                                    }, 750);
                                }
                                else {
                                    oMe.servePost();
                                }
                            }
                            else {
                                document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
                                document.getElementById("addForm_paff").action = "ajax/postarticleimage.aspx";

                                setTimeout(function () {
                                    // alert error
                                    document.getElementById("post_text").disabled = false;
                                    document.getElementById("GSPosterSubmitButton").disabled = false;
                                }, 750);
                            }
                        }
                    }
                    else {
                        document.getElementById("post_text").disabled = true;
                        document.getElementById("GSPosterSubmitButton").disabled = true;
                    }
                }
            };

            var oNewPostReq = oAjaxTools.getData(19, params, true, func);
        }
        else {
            document.getElementById("addPost_BPIndicator").style.visibility = "hidden";
            alert("There are outstanding fields!");
        }
    },

    onImagePostUploadComplete: function () {
        var f = document.getElementById("addForm_pif");

        if (f != null && typeof (f) != undefined) {
            var w = f.contentWindow;

            if (w != null && typeof (w) != undefined) {
                var o = w.document;
                if (o != null && typeof (o) != undefined) {
                    var idf = o.getElementById("ImageID");

                    if (idf != null && typeof (idf) != undefined) {
                        if (idf.innerHTML != "") {
                            document.getElementById("post_image").value = "" + idf.innerHTML;

                            if (document.getElementById("post_image").value != "") {
                                this.servePost();
                            }
                        }
                    }
                }
            }
        }
    },

    onRecipeImagePostUploadComplete: function () {
        var oMe = this;
        var f = document.getElementById("addForm_prf");

        if (f != null && typeof (f) != undefined) {
            var w = f.contentWindow;

            if (w != null && typeof (w) != undefined) {
                var o = w.document;
                if (o != null && typeof (o) != undefined) {
                    var rdf = o.getElementById("RecipeID");

                    if (rdf != null && typeof (rdf) != undefined) {
                        //alert(rdf.innerHTML)
                        if (rdf.innerHTML != "") {
                            oMe.servePost();
                        }
                    }
                }
            }
        }
    },

    onReviewImagePostUploadComplete: function () {
        var oMe = this;
        var f = document.getElementById("addForm_prvf");

        if (f != null && typeof (f) != undefined) {
            var w = f.contentWindow;

            if (w != null && typeof (w) != undefined) {
                var o = w.document;
                if (o != null && typeof (o) != undefined) {
                    var rdf = o.getElementById("ReviewID");

                    if (rdf != null && typeof (rdf) != undefined) {
                        //alert(rdf.innerHTML)
                        if (rdf.innerHTML != "") {
                            oMe.servePost();
                        }
                    }
                }
            }
        }
    },

    onArticleImagePostUploadComplete: function () {
        var oMe = this;
        var f = document.getElementById("addForm_paf");

        if (f != null && typeof (f) != undefined) {
            var w = f.contentWindow;

            if (w != null && typeof (w) != undefined) {
                var o = w.document;
                if (o != null && typeof (o) != undefined) {
                    var rdf = o.getElementById("ArticleID");

                    if (rdf != null && typeof (rdf) != undefined) {
                        //alert(rdf.innerHTML)
                        if (rdf.innerHTML != "") {
                            oMe.servePost();
                        }
                    }
                }
            }
        }
    },

    cancelPost: function () {
        this.closeAddPost();
    },

    closeAddPost: function () {
        var o = document.getElementById("addPostForm");

        if (o != undefined) {
            o.parentNode.removeChild(o);
        }
    },

    switchServePostButton: function (b) {
        oBtn = document.getElementById("GSPosterSubmitButton");

        switch (b) {
            case 2: oBtn.onclick = oPoster.serveImagePost; break;
            case 3: oBtn.onclick = oPoster.serveRecipePost; break;
            case 4: oBtn.onclick = oPoster.serveReviewPost; break;
            case 5: oBtn.onclick = oPoster.serveArticlePost; break;
            default: oBtn.onclick = oPoster.servePost; break;
        }
    },

    SelectAttachment: function (type)
    {
        // Reset Dimenstions

        document.getElementById("addPostForm").style.width = "506px";
        document.getElementById("addPostForm_inner").style.width = "480px";

        // Clear Link Preview Fields
        document.getElementById("linkPreviewTitle").innerHTML = "";
        document.getElementById("linkPreviewTitle_Editable").value = "";
        document.getElementById("linkPreviewDescrip").innerHTML = "";
        document.getElementById("linkPreviewDescrip_Editable").value = "";
        document.getElementById("linkPreviewAddr").innerHTML = "";

        // Disable attach link button    
        document.getElementById("AttachLinkButton").disabled = false;

        document.getElementById("addpost_linkattachment_selector").style.display = "block";
        document.getElementById("addpost_linkattachment_previewbox").style.display = "none";

        document.getElementById("addpost_linkattachment").style.display = "none";
        document.getElementById("addpost_imageattachment").style.display = "none";
        document.getElementById("addpost_recipeattachment").style.display = "none";
        document.getElementById("addpost_reviewattachment").style.display = "none";
        document.getElementById("addpost_articleattachment").style.display = "none";

        document.getElementById("post_type").value = "0";
        document.getElementById("post_title").value = "";
        document.getElementById("post_descrip").value = "";
        document.getElementById("post_url").value = "";
        document.getElementById("post_image").value = "";
        document.getElementById("post_recipe").value = "";
        document.getElementById("post_review").value = "";
        document.getElementById("post_article").value = "";

        var oPosterAttachmentOptions = document.getElementById("poster_attachment_options");

        for (var i = 0; i < oPosterAttachmentOptions.childNodes.length; i++) 
        {
            if (oPosterAttachmentOptions.childNodes[i].nodeType != 3)
            {
                oPosterAttachmentOptions.childNodes[i].className = "";
            }
        }

        this.switchServePostButton(0);

        if (type == 0)
        {
            oPosterAttachmentOptions.childNodes[0].className = "selected";
        }

        if (type == 1)  // Link Attachment
        {
            document.getElementById("addpost_linkattachment").style.display = "block";

            document.getElementById("addpost_linkattachment_url").value = "http://";
            document.getElementById("addpost_linkattachment_url").className = "focusoff";

            document.getElementById("post_type").value = "1";
            document.getElementById("poster_attachment_options_1").className = "selected";
        }

        if (type == 2) // Image Attachment
        {
            document.getElementById("addpost_imageattachment").style.display = "block";
            document.getElementById("post_type").value = "2";
            document.getElementById("poster_attachment_options_2").className = "selected";

            this.switchServePostButton(2);
        }

        if (type == 3) // Recipe Attachment
        {
            document.getElementById("addpost_recipeattachment").style.display = "block";
            document.getElementById("post_type").value = "3";
            document.getElementById("poster_attachment_options_3").className = "selected";

            this.switchServePostButton(3);
        }

        if (type == 4) // Review Attachment
        {
            document.getElementById("addPostForm").style.width = "706px";
            document.getElementById("addPostForm_inner").style.width = "680px";

            document.getElementById("addpost_reviewattachment").style.display = "block";
            document.getElementById("post_type").value = "4";
            document.getElementById("poster_attachment_options_4").className = "selected";

            this.switchServePostButton(4);
        }

        if (type == 5) // Article Attachment
        {
            document.getElementById("addPostForm").style.width = "726px";
            document.getElementById("addPostForm_inner").style.width = "700px";

            document.getElementById("addpost_articleattachment").style.display = "block";
            document.getElementById("post_type").value = "5";
            document.getElementById("poster_attachment_options_5").className = "selected";

            this.switchServePostButton(5);
        }
    },

    CancelAttachment: function () {
        this.ClearAttachments();
    },

    ClearAttachments: function () {
        // Clear Link Preview Fields
        document.getElementById("linkPreviewTitle").innerHTML = "";
        document.getElementById("linkPreviewTitle_Editable").value = "";
        document.getElementById("linkPreviewDescrip").innerHTML = "";
        document.getElementById("linkPreviewDescrip_Editable").value = "";
        document.getElementById("linkPreviewAddr").innerHTML = "";

        // Disable attach link button    
        document.getElementById("AttachLinkButton").disabled = false;

        document.getElementById("addpost_linkattachment_selector").style.display = "block";
        document.getElementById("addpost_linkattachment_previewbox").style.display = "none";

        document.getElementById("addpost_linkattachment").style.display = "none";
        document.getElementById("addpost_imageattachment").style.display = "none";
        document.getElementById("addpost_recipeattachment").style.display = "none";
        document.getElementById("addpost_reviewattachment").style.display = "none";
        document.getElementById("addpost_articleattachment").style.display = "none";

        document.getElementById("post_type").value = "0";
        document.getElementById("post_text").value = "";
        document.getElementById("post_title").value = "";
        document.getElementById("post_descrip").value = "";
        document.getElementById("post_url").value = "";
        document.getElementById("post_image").value = "";
        document.getElementById("post_recipe").value = "";
        document.getElementById("post_review").value = "";
        document.getElementById("post_article").value = "";

        document.getElementById("addpost_linkattachment_previewbox_imagelist").innerHTML = "";

        document.getElementById("addPostForm").style.width = "506px";
        document.getElementById("addPostForm_inner").style.width = "480px";

        this.switchServePostButton(0);
    },

    selectPostLinkImage: function (d)
    {
        var dir = (d == 1) ? 1 : -1;

        var oImgList = document.getElementById("addpost_linkattachment_previewbox_imagelist");
        var oImgListSelectorCntrls = document.getElementById("addpost_linkattachment_previewbox_imagelist_selector_cntrls");

        var oPreviewImg = document.getElementById("addpost_linkattachment_previewimage");

        var nCurrentImg = parseInt(document.getElementById("addpost_linkattachment_previewbox_imagelist_selectorselected").innerHTML);
        var nNextCurrentImg = nCurrentImg + (dir);
        var nImgCount = oImgList.childNodes.length;

        var oPrevButton = oImgListSelectorCntrls.childNodes[0];
        var oNextButton = oImgListSelectorCntrls.childNodes[1];

        if (nNextCurrentImg >= 1 && nNextCurrentImg <= nImgCount) 
        {
            if (nNextCurrentImg > 1) 
            {
                oPrevButton.className = "prev";
            }
            else 
            {
                oPrevButton.className = "prevdisabled";
            }

            if (nNextCurrentImg < nImgCount) {
                oNextButton.className = "next";
            }
            else {
                oNextButton.className = "nextdisabled";
            }

            // Show the image preview
            oPreviewImg.src = oImgList.childNodes[nNextCurrentImg - 1].src;
            document.getElementById("post_image").value = oImgList.childNodes[nNextCurrentImg - 1].src;

            // Show the number of the selected image
            document.getElementById("addpost_linkattachment_previewbox_imagelist_selectorselected").innerHTML = nNextCurrentImg;
        }
    },

    htmlEncode: function (h) {
        var html = "" + ((h != null) ? h : "");

        html = html.replace(new RegExp("<", "g"), "&lt;");
        html = html.replace(new RegExp(">", "g"), "&gt;");

        return html;
    },

    encodeDataForPost: function (d) {
        var data = "" + ((d != null) ? d : "");

        data = data.replace(new RegExp("<", "g"), "&lt;");
        data = data.replace(new RegExp(">", "g"), "&gt;");
        data = data.replace(new RegExp("&", "gi"), "[--fs--ampersand--placeholder--]");

        return data;
    },

    sanitizeURL: function (u) {
        var url = "" + ((u != null) ? u : "");

        url = url.replace(new RegExp("'", "g"), "''");
        url = url.replace(new RegExp("<", "g"), "");
        url = url.replace(new RegExp(">", "g"), "");

        return url;
    },

    attachLinkToPost: function () 
    {
        var oMe = this;

        // Disable the skewer controls
        document.getElementById("AttachLinkButton").disabled = true;
        document.getElementById("addpost_linkattachment_url").style.background = "url(assets/images/loading.gif) center right no-repeat";

        // Show the loading/processing animation
        //document.getElementById("loadingmsg").style.display = "block";

        var oRecordSet = null;

        var func = function () 
        {
            if (arguments[0] != null) 
            {
                if (arguments[0].readyState == 4) 
                {
                    if (arguments[0].status == 200) 
                    {
                        oRecordSet = (arguments[0].responseText).split("[--gs-pxy-spliter--]");

                        if (oRecordSet != null) {
                            document.getElementById("linkPreviewTitle").innerHTML = oMe.htmlEncode(oRecordSet[0]);
                            document.getElementById("linkPreviewTitle_Editable").value = oRecordSet[0];
                            document.getElementById("post_title").value = oRecordSet[0];

                            document.getElementById("linkPreviewDescrip").innerHTML = oMe.htmlEncode(((oRecordSet[1].length <= 255) ? oRecordSet[1] : oRecordSet[1].substr(0, 255) + " ..."));
                            document.getElementById("linkPreviewDescrip_Editable").value = ((oRecordSet[1].length <= 255) ? oRecordSet[1] : oRecordSet[1].substr(0, 255) + " ...");
                            document.getElementById("post_descrip").value = oRecordSet[1];

                            document.getElementById("linkPreviewAddr").innerHTML = oMe.htmlEncode(((oRecordSet[3].length <= 50) ? oRecordSet[3] : oRecordSet[3].substr(0, 50) + " ..."));
                            document.getElementById("post_url").value = oRecordSet[3];

                            // Images
                            var arrImages = new Array();

                            if (oRecordSet[2].indexOf("\n") > 0) {
                                arrImages = oRecordSet[2].split("\n");
                            }

                            var oPreviewImg = document.getElementById("addpost_linkattachment_previewimage");
                            var oPreviewImgSelectorControls = document.getElementById("addpost_linkattachment_previewbox_imagelist_selector_cntrls");

                            var imgCount = 0;
                            for (var i = 0; i < arrImages.length; i++) {
                                if (arrImages[i] != null && arrImages[i] != "") {
                                    var oImg = document.createElement("img");
                                    oImg.src = "" + arrImages[i];
                                    oImg.alt = "";

                                    document.getElementById("addpost_linkattachment_previewbox_imagelist").appendChild(oImg);

                                    if (i == 0) {
                                        if (arrImages[0] != "") {
                                            oPreviewImg.src = arrImages[0];
                                            document.getElementById("post_image").value = arrImages[0];
                                        }
                                        else {
                                            oPreviewImg.src = "assets/images/transpx.png";
                                        }
                                    }

                                    imgCount++;
                                }
                            }

                            document.getElementById("addpost_linkattachment_previewbox_imagelist_selectorselected").innerHTML = "0";

                            if (imgCount >= 1) 
                            {
                                document.getElementById("addpost_linkattachment_previewbox_imagelist_selectorselected").innerHTML = "1";

                                oPreviewImg.parentNode.style.display = "block";
                                oPreviewImgSelectorControls.parentNode.style.display = "block";
                                document.getElementById("addpost_linkattachment_previewbox").childNodes[1].style.width = "330px";
                            }
                            else 
                            {
                                document.getElementById("addpost_linkattachment_previewbox_imagelist_selectorselected").innerHTML = "0";

                                oPreviewImg.parentNode.style.display = "none";
                                oPreviewImgSelectorControls.parentNode.style.display = "none";
                                document.getElementById("addpost_linkattachment_previewbox").childNodes[1].style.width = "430px";
                                oPreviewImg.src = "assets/images/transpx.png";

                            }

                            document.getElementById("addpost_linkattachment_previewbox_imagelist_selectorcountertotal").innerHTML = imgCount;

                            if (imgCount <= 1) {
                                document.getElementById("addpost_linkattachment_previewbox_imagelist_selector_cntrls").childNodes[0].className = "prevdisabled";
                                document.getElementById("addpost_linkattachment_previewbox_imagelist_selector_cntrls").childNodes[1].className = "nextdisabled";
                            }
                            else {
                                document.getElementById("addpost_linkattachment_previewbox_imagelist_selector_cntrls").childNodes[1].className = "next";
                            }

                            // Enable the poster controls
                            document.getElementById("addpost_linkattachment_url").disabled = false;
                            document.getElementById("AttachLinkButton").disabled = false;

                            document.getElementById("addpost_linkattachment_selector").style.display = "none";
                            document.getElementById("addpost_linkattachment_previewbox").style.display = "block";

                        }
                        else {
                            // Enable the poster controls
                            document.getElementById("addpost_linkattachment_url").disabled = false;
                            document.getElementById("AttachLinkButton").disabled = false;

                            document.getElementById("addpost_linkattachment_selector").style.display = "block";
                            document.getElementById("addpost_linkattachment_previewbox").style.display = "none";

                            alert("An error occured!");
                        }

                        document.getElementById("addpost_linkattachment_url").style.background = "";
                    }
                    else {
                        // Enable the poster controls
                        document.getElementById("addpost_linkattachment_url").disabled = false;
                        document.getElementById("AttachLinkButton").disabled = false;

                        document.getElementById("addpost_linkattachment_selector").style.display = "block";
                        document.getElementById("addpost_linkattachment_previewbox").style.display = "none";

                        alert("An error occured " + arguments[0].status);
                    }
                }
                else {
                    // Disable the poster controls
                    document.getElementById("addpost_linkattachment_url").disabled = true;
                    document.getElementById("AttachLinkButton").disabled = true;

                    document.getElementById("addpost_linkattachment_selector").style.display = "block";
                    document.getElementById("addpost_linkattachment_previewbox").style.display = "none";
                }
            }
        }

        if (typeof (document.getElementById("addpost_linkattachment_url")) != undefined) {
            var url = this.htmlEncode(document.getElementById("addpost_linkattachment_url").value);

            if (url != "" && url != "http://" && url.indexOf(".") > -1) {
                var arr = new Array();
                arr[0] = "url=" + url;

                this.oAttachLinkReq = oAjaxTools.getData(14, arr, true, func);
            }
            else {
                alert("Please enter a valid website address.");
                document.getElementById("AttachLinkButton").disabled = false;
            }
        }
    }
}

var oPoster = new gsPoster();
    oPoster.init();

