﻿var replythreadid = "";
var currentforumid = "";
var currentuserid = "";
var currentparentpostid = "";
var adminuseridworkingon = "";

function jumpForum() {
    var theforumidselected = document.getElementById("jumpforumselection").value;
    showForum(theforumidselected, "0");
}

function showForum(forumid, thepage) {

    showDiv("loadingPnl", "99999");
    currentforumid = forumid;
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=" + forumid + "&thepage=" + thepage + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetForum.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText;
            showDiv("listofthreadspnl", "99999")
            document.getElementById("listofthreadspnl").innerHTML = theBasketStr;
            //closeDiv("listofthreadspnl")
            closeDiv("postcontentpnl")
            closeDiv("forumreplaypnl")
            closeDiv("forumpostpnl")
            closeDiv("postcontentpnl")
            closeDiv("forumcontentpanel")
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            closeDiv("registerpnl")
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            closeDiv("loadingPnl");
            window.location = "#toppage";


        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function getForumList() {

    showDiv("loadingPnl", "99999");
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=all" + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "ForumList.aspx";
    var theBasketStr = ""
    currentforumid = "";
    currentparentpostid = ""
    replythreadid = "";
    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText;
            showDiv("forumcontentpanel", "99999")
            document.getElementById("forumcontentpanel").innerHTML = theBasketStr;
            closeDiv("listofthreadspnl")
            closeDiv("postcontentpnl")
            closeDiv("forumreplaypnl")
            closeDiv("forumpostpnl")
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            closeDiv("registerpnl")
            closeDiv("userprofilepnl");
            closeDiv("adminareapnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            closeDiv("loadingPnl");
            window.location = "#toppage";
            //closeDiv("forumcontent")

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}


function showThread(threadid, thepage) {

    showDiv("loadingPnl", "99999");
    //alert("in method!");
    var xmlHttp
    if (thepage == "") {
        thepage = "0"
    }
    //build product information to be sent to the server
    var params = "threadid=" + threadid + "&rcode=" + getRandomString() + "&thepage=" + thepage;
    //server page for dealing with adding a product
    var url = "GetThread.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText;
            showDiv("postcontentpnl", "99999")
            document.getElementById("postcontentpnl").innerHTML = theBasketStr;
            closeDiv("listofthreadspnl")
            //closeDiv("postcontentpnl")
            closeDiv("forumreplaypnl")
            closeDiv("forumpostpnl")
            closeDiv("forumcontentpanel")
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            closeDiv("registerpnl")
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            closeDiv("loadingPnl");
            window.location = "#toppage";

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function closeDiv(divName) {
    try {
        document.getElementById(divName).style.display = "none";
        document.getElementById(divName).style.zIndex = "1";
    }
    catch (ex) {

    }
}

// show any div ia a z index and display value, default is 99999
function showDiv(divName, zIndex) {
    if (zIndex.length < 1) {
        zIndex = "99999";
    }
    document.getElementById(divName).style.display = "";
    document.getElementById(divName).style.zIndex = zIndex;
}

function replyToThread(threadid, forumid, userid, replyingtostart) {


    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=all" + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "CheckLogin.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); ;

            if (theBasketStr == "true") {

                replythreadid = threadid;
                currentforumid = forumid;
                currentuserid = userid;
                showDiv("forumreplaypnl", "99999");
                closeDiv("listofthreadspnl");
                closeDiv("postcontentpnl");
                closeDiv("forumcontentpanel");
                closeDiv("forumpostpnl");
                closeDiv("forumposteditpnl");
                closeDiv("loginpanel");
                closeDiv("userprofilepnl");
                closeDiv("forumrulespnl");
                closeDiv("sendprivatemessagepnl");
                document.getElementById("replyingtostart").innerHTML = "You are replying to " + replyingtostart;
                window.location = "#toppage";
            }
            else {
                alert("you need to be logged in to post on this forum!");
                replythreadid = threadid;
                currentforumid = forumid;
                currentuserid = userid;
                showLogin()
            }
        }
    }
    //post product data to the server
    xmlHttp.send(params);
    //return false so no page reload takes place
    return false;

}

function newPost(forumid, userid) {

    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=all" + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "CheckLogin.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); ;

            if (theBasketStr == "true") {
                currentforumid = forumid;
                currentuserid = userid;
                showDiv("forumpostpnl", "99999");
                closeDiv("listofthreadspnl");
                closeDiv("postcontentpnl");
                closeDiv("forumcontentpanel");
                closeDiv("forumreplaypnl");
                closeDiv("forumposteditpnl");
                closeDiv("loginpanel");
                closeDiv("userprofilepnl");
                closeDiv("forumrulespnl");
                closeDiv("sendprivatemessagepnl");
                window.location = "#toppage";
            }
            else {
                alert("you need to be logged in to post on this forum!");
                currentforumid = forumid;
                currentuserid = userid;
                showLogin()
            }




            //closeDiv("forumcontent")

        }
    }
    //post product data to the server
    xmlHttp.send(params);
    //return false so no page reload takes place
    return false;


}

function showLogin() {
    showDiv("loginpanel", "99999");
    closeDiv("listofthreadspnl");
    closeDiv("postcontentpnl");
    closeDiv("forumcontentpanel");
    closeDiv("forumreplaypnl");
    closeDiv("forumposteditpnl");
    closeDiv("forumpostpnl");
    closeDiv("userprofilepnl");
    window.location = "#top";


}

function logoutForum() {

    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=all" + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "LogoutForumUser.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            getForumList()
        }
    }
    //post product data to the server
    xmlHttp.send(params);


}

function replaceIllegalCharacters(theStr) {
    theStr = theStr.replace(/^\s+|\s+$/g, '', "g");
    theStr = theStr.replace("&nbsp;", ' ', "g");
    theStr = theStr.replace(/\u00a0/g, '');
    theStr = theStr.replace(new RegExp("&nbsp;", "g"), " ");
    theStr = theStr.replace(new RegExp("&", "g"), '%amp');
    //theStr = theStr.replace(new RegExp("\?", "g"), '%que');
    //theStr = theStr.replace("?", "%que", "g");
    theStr = theStr.replace(/\?/g, '%que');
    theStr = theStr.replace(new RegExp("@", "g"), '%at');
    theStr = theStr.replace(/\#/g, 'h%h', "g");
    theStr = theStr.replace(new RegExp("!", "g"), '%exp');
    theStr = theStr.replace(/\$/g, '%dollor');
    theStr = theStr.replace(new RegExp("£", "g"), '%pound');
    theStr = theStr.replace(new RegExp("\'", "g"), '%squ');
    theStr = theStr.replace(new RegExp("\"", "g"), '%dqu');
    theStr = theStr.replace(/\+/g, '%2B');
    //theStr = theStr.replace("+", "%2B", "g");
    theStr = theStr.replace(new RegExp("=", "g"), "%eq");
    //theStr = theStr.replace("=", "%eq", "g");
    theStr = theStr.replace(/\n/g, "<br />");
    //alert("removed js spaces! " + theStr)

    return theStr;

}

function replyPost() {

    var thetitle = document.getElementById("titletxt").value;
    var thecontent = document.getElementById("contenttxt").value;

    document.getElementById("titletxt").value = "";
    document.getElementById("contenttxt").value = "";
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + replythreadid + "&title=" + replaceIllegalCharacters(thetitle) + "&content=" + replaceIllegalCharacters(thecontent) + "&userid=" + currentuserid + "&forumid=" + currentforumid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "PostReply.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showThread(replythreadid, "last")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function newPostServer() {

    var thetitle = document.getElementById("newtitletxt").value;
    var thecontent = document.getElementById("newcontenttxt").value;


    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "title=" + replaceIllegalCharacters(thetitle) + "&content=" + replaceIllegalCharacters(thecontent) + "&userid=" + currentuserid + "&forumid=" + currentforumid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "NewPost.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            if (theBasketStr == "true") {
                showForum(currentforumid, "0")
                document.getElementById("newtitletxt").value = "";
                document.getElementById("newcontenttxt").value = "";
            }
            else if (theBasketStr == "false") {
                alert("Error adding your post to our database!")
            }
            else {
                alert("Error posting, message is " + theBasketStr)
            }
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function closePost() {
    showForum(currentforumid, "0")
}

function closeRegisterPnl() {
    if (replythreadid.length > 0) {
        showThread(replythreadid, "0");
    }
    else if (currentforumid.length > 0) {
        showForum(currentforumid, "0")
    }
    else {
        getForumList();
    }

}

function closeLoginPnl() {


    if (replythreadid.length > 0) {
        showThread(replythreadid, "0");
    }
    else if (currentforumid.length > 0) {
    showForum(currentforumid, "0")
    }
    else {
        getForumList();
    }


    
}

function closeReply() {
    if (replythreadid.length > 0) {
        showThread(replythreadid, "0");
    }
    else if (currentforumid.length > 0) {
        showForum(currentforumid, "0")
    }
    else {
        getForumList();
    }

}

function closeEditPost() {
    if (currentparentpostid.length > 0) {
        showThread(currentparentpostid, "0");
    }
    else if (currentforumid.length > 0) {
        showForum(currentforumid, "0")
    }
    else {
        getForumList();
    }
    
}

function closeUserAreaPnl() {
    if (replythreadid.length > 0) {
        showThread(replythreadid, "0");
    }
    else if (currentforumid.length > 0) {
        showForum(currentforumid, "0")
    }
    else {
        getForumList();
    }
}

function deleteThread(threadid, forumid) {
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + threadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "DeletePost.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showForum(forumid, "0");
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function editThread(threadid, forumid, theparentpostid) {
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + threadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetPost.aspx";
    var theBasketStr = ""

    replythreadid = threadid;
    currentforumid = forumid;
    currentparentpostid = theparentpostid;

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //showThread(threadid)
            showDiv("forumposteditpnl", "99999");
            closeDiv("listofthreadspnl");
            closeDiv("postcontentpnl");
            closeDiv("forumcontentpanel");
            closeDiv("forumreplaypnl");
            closeDiv("forumpostpnl");
            closeDiv("loginpanel");
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");

            var returnedXmlDocument = xmlHttp.responseXML.documentElement;

            var threadtitle = getFirstChildOfXmlResponse(returnedXmlDocument, 'threadtitle')
            var threadcontent = getFirstChildOfXmlResponse(returnedXmlDocument, 'threadcontent')

            document.getElementById("edittitletxt").value = addIllegalCharacters(threadtitle);
            document.getElementById("editcontenttxt").value = addIllegalCharacters(threadcontent);


        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function getFirstChildOfXmlResponse(xmlObj, valueid) {
    var returnValue = ""
    if (xmlObj.getElementsByTagName(valueid)[0].firstChild) {
        returnValue = xmlObj.getElementsByTagName(valueid)[0].firstChild.nodeValue;
    }
    return returnValue;
}

function editThreadPost() {

    var thetitle = document.getElementById("edittitletxt").value;
    var thecontent = document.getElementById("editcontenttxt").value;
    document.getElementById("edittitletxt").value = "";
    document.getElementById("editcontenttxt").value = "";

    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "title=" + replaceIllegalCharacters(thetitle) + "&content=" + replaceIllegalCharacters(thecontent) + "&userid=" + currentuserid + "&forumid=" + currentforumid + "&threadid=" + replythreadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "EditPost.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showThread(currentparentpostid, "0")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function getRandomString() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}
function loginPost() {

    var theusername = document.getElementById("usernametxt").value;
    var thepassword = document.getElementById("passwordtxt").value;
    var rememberme = document.getElementById("remebermelogin").value;

    document.getElementById("usernametxt").value = "";
    document.getElementById("passwordtxt").value = "";
    document.getElementById("remebermelogin").checked = false;
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "username=" + replaceIllegalCharacters(theusername) + "&password=" + replaceIllegalCharacters(thepassword) + "&rememberme=" + rememberme + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "LoginToForum.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            if (theBasketStr == "true") {
                if (replythreadid.length > 0) {
                    showThread(replythreadid, "0")
                }
                else if (currentforumid.length > 0) {
                    showForum(currentforumid, "0")
                }
                else {
                    getForumList()
                }
            }
            else {
                alert(theBasketStr);
            }
        }
    }
    //post product data to the server
    xmlHttp.send(params);
    //return false so no page reload takes place
    return false;

}

function registerUser() {
    showDiv("registerpnl", "99999");
    closeDiv("listofthreadspnl");
    closeDiv("postcontentpnl");
    closeDiv("forumcontentpanel");
    closeDiv("forumreplaypnl");
    closeDiv("forumposteditpnl");
    closeDiv("forumpostpnl");
    closeDiv("loginpanel");
    closeDiv("userprofilepnl");
    closeDiv("forumrulespnl");
    closeDiv("sendprivatemessagepnl");
    fillRegisterDateOfBirth()


}

function addOption(selectboxID, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    document.getElementById(selectboxID).options.add(optn);
}

function clearSelectBox(selectbox) {

    /*for (i=document.getElementById(selectbox).options.length-1; i>=0; i--)
    {
    document.getElementById(selectbox).removeChild(document.getElementById(selectbox).options[i]);
    }*/
    document.getElementById(selectbox).options.length = 0;
    //alert("length is " + document.getElementById(selectbox).options.length);

}



function fillRegisterDateOfBirth() {

    clearSelectBox("newuserday")
    clearSelectBox("userareaday")

    clearSelectBox("newusermonth")
    clearSelectBox("userareamonth")

    clearSelectBox("newuseryear")
    clearSelectBox("userareayear")
    
    var i;
    for (i = 1; i <= 31; i++) {
        addOption("newuserday", "" + i, "" + i);
        addOption("userareaday", "" + i, "" + i);
    }
    for (i = 1; i <= 12; i++) {
        addOption("newusermonth", "" + i, "" + i);
        addOption("userareamonth", "" + i, "" + i);
    }
    var thedate = new Date
    var startyear = thedate.getUTCFullYear();
    //alert("start year is " + startyear)
    for (i = startyear; i >= startyear - 100; i--) {
        addOption("newuseryear", "" + i, "" + i);
        addOption("userareayear", "" + i, "" + i);
    }
}

function showUserAreaPanel() {
    showDiv("userprofilepnl", "99999");
    closeDiv("listofthreadspnl");
    closeDiv("postcontentpnl");
    closeDiv("forumcontentpanel");
    closeDiv("forumreplaypnl");
    closeDiv("forumposteditpnl");
    closeDiv("forumpostpnl");
    closeDiv("loginpanel");
    closeDiv("registerpnl");
    closeDiv("forumrulespnl");
    closeDiv("sendprivatemessagepnl");
}

function registerAccount() {

    var theusername = document.getElementById("newuserusername").value;
    var thepassword = document.getElementById("newuserpassword").value;
    var theforename = document.getElementById("newuserforename").value;
    var thesurname = document.getElementById("newusersurname").value;
    var theemail = document.getElementById("newuseremail").value;
    var thepassword = document.getElementById("newuserpassword").value;

    var thedateofbirth = document.getElementById("newuserday").value + "/" + document.getElementById("newusermonth").value + "/" + document.getElementById("newuseryear").value;

    var thelocation = document.getElementById("newuserlocation").value;

    var thetagline = document.getElementById("newusertagline").value;

    var thebiography = document.getElementById("newuserbiography").value;


    if (validEmail(theemail, true)) {



        document.getElementById("newuserusername").value = "";
        document.getElementById("newuserpassword").value = "";

        document.getElementById("newuserforename").value = "";
        document.getElementById("newusersurname").value = "";

        document.getElementById("newuseremail").value = "";
        document.getElementById("newuserpassword").value = "";

        //alert("in method!");
        var xmlHttp
        //build product information to be sent to the server
        var params = "username=" + replaceIllegalCharacters(theusername) + "&password=" + replaceIllegalCharacters(thepassword) + "&forename=" + theforename + "&surname=" + thesurname + "&emailaddr=" + theemail + "&dateofbirth=" + thedateofbirth + "&location=" + thelocation + "&tagline=" + thetagline + "&biography=" + thebiography + "&rcode=" + getRandomString();
        //server page for dealing with adding a product
        var url = "RegisterForumUser.aspx";
        var theBasketStr = ""

        //build a connection
        xmlHttp = newConnection();
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");
        //handle the result
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
                if (theBasketStr == "true") {
                    if (replythreadid.length > 0) {
                        showThread(replythreadid, "0")
                    }
                    else if (currentforumid.length > 0) {
                        showForum(currentforumid, "0")
                    }
                    else {
                        getForumList()
                    }
                    //
                }
                else {
                    alert("Failed to register your details!");
                }
            }
        }
        //post product data to the server
        xmlHttp.send(params);
        //return false so no page reload takes place
    }
    return false;

}


function editUserDetails() {

    var theforename = document.getElementById("userareaforenametxt").value;
    var thesurname = document.getElementById("userareasurnametxt").value;
    var theemail = document.getElementById("userareaemailtxt").value;
    var thepassword = document.getElementById("userareapasswordtxt").value;

    var thedateofbirth = document.getElementById("userareaday").value + "/" + document.getElementById("userareamonth").value + "/" + document.getElementById("userareayear").value;

    var thelocation = document.getElementById("userarealocationtxt").value;

    var thetagline = document.getElementById("userareatagline").value;

    var thebiography = document.getElementById("userareabiography").value;


    if (validEmail(theemail, true)) {

        //alert("in method!");
        var xmlHttp
        //build product information to be sent to the server
        var params = "password=" + replaceIllegalCharacters(thepassword) + "&forename=" + theforename + "&surname=" + thesurname + "&emailaddr=" + theemail + "&dateofbirth=" + thedateofbirth + "&location=" + thelocation + "&tagline=" + thetagline + "&biography=" + thebiography + "&rcode=" + getRandomString();
        //server page for dealing with adding a product
        var url = "EditUserProfile.aspx";
        var theBasketStr = ""

        //build a connection
        xmlHttp = newConnection();
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");
        //handle the result
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
                if (theBasketStr == "true") {
                    alert("Your details have been updated!")
                }
                else {
                    alert("Failed to Update your details!");
                }
            }
        }
        //post product data to the server
        xmlHttp.send(params);
        //return false so no page reload takes place

    }
    return false;

}

function showUserArea(userid) {

    fillRegisterDateOfBirth()
    var xmlHttp
    //build product information to be sent to the server
    var params = "userid=" + userid + "&admin=false&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetUserDetails.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //showThread(threadid)
            showDiv("userprofilepnl", "99999");
            closeDiv("listofthreadspnl");
            closeDiv("postcontentpnl");
            closeDiv("forumcontentpanel");
            closeDiv("forumreplaypnl");
            closeDiv("forumpostpnl");
            closeDiv("loginpanel");
            closeDiv("forumposteditpnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");

            document.getElementById("userareaforenametxt").value = "";
            document.getElementById("userareasurnametxt").value = "";
            document.getElementById("userareaemailtxt").value = "";
            document.getElementById("userareausername").innerHTML = "";
            document.getElementById("userareapasswordtxt").value = "";
            document.getElementById("userareatotalposts").innerHTML = "";
            document.getElementById("userarealocationtxt").innerHTML = "";
            document.getElementById("userareatagline").innerHTML = "";
            document.getElementById("userareabiography").innerHTML = "";



            var returnedXmlDocument = xmlHttp.responseXML.documentElement;

            document.getElementById("userareaforenametxt").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userforename')
            document.getElementById("userareasurnametxt").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'usersurname')
            document.getElementById("userareaemailtxt").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'useremail')
            document.getElementById("userareausername").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'userusername')
            document.getElementById("userareapasswordtxt").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userpassword')
            document.getElementById("userareatotalposts").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usertotalposts')


            try {
                document.getElementById("userarealocationtxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'userlocation')
            }
            catch (ex) {

            }
            try {
                document.getElementById("userareatagline").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usertagline')
            }
            catch (ex) {

            }
            try {
                document.getElementById("userareabiography").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'userbiography')
            }
            catch (ex) {

            }
            try {
                selectCurrentIndexString("userareaday", getFirstChildOfXmlResponse(returnedXmlDocument, 'userday'))
                selectCurrentIndexString("userareamonth", getFirstChildOfXmlResponse(returnedXmlDocument, 'usermonth'))
                selectCurrentIndexString("userareayear", getFirstChildOfXmlResponse(returnedXmlDocument, 'useryear'))
            }
            catch (ex) {

            }

            getPrivatePosts()








        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function getPrivatePosts() {

    var xmlHttp
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetPrivatePosts.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
    
        theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
        document.getElementById("privatePostsPnl").innerHTML = theBasketStr   
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function selectCurrentIndexString(objectClientID, theValue) {
    for (i = 0; i < parseInt(document.getElementById(objectClientID).options.length); i++) {
        if (theValue == document.getElementById(objectClientID).options[i].value) {
            document.getElementById(objectClientID).selectedIndex = i;
            break;
        }
    }
}

function displayAdminPanel() {
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetAdminPanel.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);
            showDiv("adminareapnl", "99999");
            closeDiv("listofthreadspnl");
            closeDiv("postcontentpnl");
            closeDiv("forumcontentpanel");
            closeDiv("forumreplaypnl");
            closeDiv("forumpostpnl");
            closeDiv("loginpanel");
            closeDiv("forumposteditpnl");
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            document.getElementById("adminareapnl").innerHTML = theBasketStr;

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function showAllUsersAdmin(thepage, usernamestr, emailstr) {
    //alert("in method!");
    var xmlHttp;
    if (usernamestr.length > 0) {
        usernamestr = document.getElementById("searchusernametxt").value
    }
    if (emailstr.length > 0) {
        emailstr = document.getElementById("searchemailtxt").value
    }
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&thepage=" + thepage + "&usernamestr=" + usernamestr + "&emailstr=" + emailstr;
    //server page for dealing with adding a product
    var url = "ShowAllUsers.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);

            document.getElementById("adminareapnl").innerHTML = theBasketStr;

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;
}

function showAllPostsAdmin(thepage, titlesearchstr, contentsearchstr) {
    //alert("in method!");
    var xmlHttp;
    if (titlesearchstr.length > 0) {
        titlesearchstr = document.getElementById("searchtitletxt").value
    }
    if (contentsearchstr.length > 0) {
        contentsearchstr = document.getElementById("searchcontenttxt").value
    }
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&thepage=" + thepage + "&titlesearchstr=" + titlesearchstr + "&contentsearchstr=" + contentsearchstr;
    //server page for dealing with adding a product
    var url = "ShowAllPosts.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);

            document.getElementById("adminareapnl").innerHTML = theBasketStr;
            closeDiv("adminEditPnl");

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;
}

function editUser(theuserid) {

    adminuseridworkingon = theuserid
    var xmlHttp
    //build product information to be sent to the server
    var params = "userid=" + theuserid + "&admin=true&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetUserDetails.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            var returnedXmlDocument = xmlHttp.responseXML.documentElement;

            try {
                document.getElementById("editpnlforename").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userforename')
                document.getElementById("editpnlsurname").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'usersurname')
                document.getElementById("editpnlemail").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'useremail')
                document.getElementById("editpnlusername").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userusername')
                document.getElementById("editpnlpassword").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userpassword')
            }
            catch (ex) {
                alert("Error 1");
            }
            try {
                document.getElementById("editpnllocation").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userlocation')
            }
            catch (ex) {
                alert("Error 2");
            }
            try {
                document.getElementById("editpnltagline").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'usertagline')
            }
            catch (ex) {
                alert("Error 3");
            }
            try {
                document.getElementById("editpnladmintagline").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'useradmintagline')
            }
            catch (ex) {
                alert("Error 4");
            }
            /* try {
                
            }*/
            /*catch (ex) {
            //alert("Error 5");
            }*/

            document.getElementById("editpnlbiography").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userbiography');





            showDiv("edituserpnl", "99999");
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;




}

function deleteUser(theuserid) {
    var xmlHttp
    //build product information to be sent to the server
    var params = "useridtodelete=" + theuserid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "DeleteUser.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showAllUsersAdmin("0", "", "")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function banUser(theuserid) {
    var xmlHttp
    //build product information to be sent to the server
    var params = "useridtoban=" + theuserid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "BanUser.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showAllUsersAdmin("0", "", "")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;
}

function unBanUser(theuserid) {
    var xmlHttp
    //build product information to be sent to the server
    var params = "useridtoban=" + theuserid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "UnBanUser.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showAllUsersAdmin("0", "", "")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;
}

function adminEditUsersDetails() {

    var theforename = document.getElementById("editpnlforename").value;
    var thesurname = document.getElementById("editpnlsurname").value;
    var theemail = document.getElementById("editpnlemail").value;
    var theusername = document.getElementById("editpnlusername").value;
    var thepassword = document.getElementById("editpnlpassword").value;
    var thelocation = document.getElementById("editpnllocation").value;
    var thetagline = document.getElementById("editpnltagline").value;
    var theadmintagline = document.getElementById("editpnladmintagline").value;
    var thebiography = document.getElementById("editpnlbiography").value;


    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "password=" + replaceIllegalCharacters(thepassword) + "&forename=" + theforename + "&surname=" + thesurname + "&emailaddr=" + theemail + "&username=" + theusername + "&useridtoedit=" + adminuseridworkingon + "&location=" + thelocation + "&tagline=" + thetagline + "&admintagline=" + theadmintagline + "&biography=" + thebiography + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "EditUserProfileAdmin.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            if (theBasketStr == "true") {
                showAllUsersAdmin("0", "", "")
                alert("Your details have been updated!");

            }
            else {
                alert("Failed to Update your details!");
            }
        }
    }
    //post product data to the server
    xmlHttp.send(params);
    //return false so no page reload takes place
    return false;


}

function adminDeletePost(thethreadid) {
    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + thethreadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "DeletePost.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showAllPostsAdmin("0", "", "")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}


function adminEditPostToServer() {

    var thetitle = document.getElementById("admintitletxt").value;
    var thecontent = document.getElementById("admincontenttxt").value;
    document.getElementById("admintitletxt").value = "";
    document.getElementById("admincontenttxt").value = "";

    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "title=" + replaceIllegalCharacters(thetitle) + "&content=" + replaceIllegalCharacters(thecontent) + "&threadid=" + replythreadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "EditPost.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //showThread(currentparentpostid, "0")
            showAllPostsAdmin("0", "", "");
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function adminEditPost(threadid) {
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + threadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetPost.aspx";
    var theBasketStr = ""

    replythreadid = threadid;

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //showThread(threadid)
            showDiv("adminEditPnl", "99999");
            var returnedXmlDocument = xmlHttp.responseXML.documentElement;
            var threadtitle = getFirstChildOfXmlResponse(returnedXmlDocument, 'threadtitle')
            var threadcontent = getFirstChildOfXmlResponse(returnedXmlDocument, 'threadcontent')

            document.getElementById("admintitletxt").value = threadtitle;
            document.getElementById("admincontenttxt").value = threadcontent;


        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}


function validEmail(emailAddrID, byvalue)	//---------validEmail()------------checks email validity---------------
{
    var error = false;
    var email = ""
    if (byvalue) {
        email = emailAddrID;
    }
    else {
        email = document.getElementById(emailAddrID).value;
    }

    invalidChars = "/:,; ";
    if (email == "")//email not entered
    {
        errorString = "You have not entered any email address.\n";
        error = true;
    }

    for (i = 0; i < invalidChars.length; i++)//checks for the invalid characters
    {
        badChar = invalidChars.charAt(i)
        if (email.indexOf(badChar, 0) > -1) {
            if (badChar == ' ') {

                errorString = errorString + "Error: Email must not contain spaces.\n";
                error = true;
            }
            else
                errorString = errorString + "Error: Email must not contain the character: ' " + badChar + " '.\n";
            error = true;
        }
    }

    atPos = email.indexOf("@", 1); //checks position
    if (atPos == -1) {
        errorString = errorString + "Email Error: Misplaced ' @ ' symbol.\n";
        error = true;
    }
    if (email.indexOf("@", atPos + 1) != -1)//checks pos
    {
        errorString = errorString + "Email Error: Misplaced ' @ ' symbol.\n";
        error = true;
    }
    periodPos = email.indexOf(".", atPos)//checks point for .provider
    if (periodPos == -1) {
        errorString = errorString + "Email Error: Misplaced ' . ' symbol.\n";
        error = true;
    }
    if (periodPos + 3 > email.length)//checks length of provider atleast 3 as standard
    {
        errorString = errorString + "Email Error: Error with right hand side of address.\n";
        error = true;
    }
    if (error) {
        alert(errorString + "Please correct.");
        return false;
    }
    for (i = 0; i < email.length; i++)//checks for 'www' in email address
        if (email.charAt(i) == 'w' && email.charAt(i + 1) == 'w' && email.charAt(i + 2) == 'w' && wwwCheck == true) {
        if (confirm("Caution: WWW is for surfing the web, it is not usually part of an email address.\nClick OK to confirm or cancel to correct address.") == false) {
            return false;
        }
        else
            wwwCheck = false;
    }

    return true;
}


function newAdminUserType(theuserid) {
    var xmlHttp
    //build product information to be sent to the server
    var params = "roleidpassedin=" + document.getElementById("usertypeinput-" + theuserid).value + "&useridpassedin=" + theuserid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "ChangeAdminUserType.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            showAllUsersAdmin("0", "", "")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;
}

function manageBadWords() {

    var xmlHttp;
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "ManageBadWords.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);

            document.getElementById("adminareapnl").innerHTML = theBasketStr;
            //closeDiv("adminEditPnl");

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}


function addBadWord() {

    var xmlHttp;
    var theword = replaceIllegalCharacters(document.getElementById("thebadwordtxt").value)
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&theword=" + theword;
    //server page for dealing with adding a product
    var url = "AddBadWord.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);
            manageBadWords();


        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function deleteBadWord(wordid) {

    var xmlHttp;
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&thewordid=" + wordid;
    //server page for dealing with adding a product
    var url = "DeleteBadWord.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);

            manageBadWords();

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function showForumRules() {

    closeDiv("postcontentpnl")
    closeDiv("forumreplaypnl")
    closeDiv("forumpostpnl")
    closeDiv("postcontentpnl")
    closeDiv("forumcontentpanel")
    closeDiv("forumposteditpnl");
    closeDiv("loginpanel");
    closeDiv("registerpnl")
    closeDiv("userprofilepnl");
    closeDiv("listofthreadspnl");
    closeDiv("sendprivatemessagepnl");
    showDiv("forumrulespnl", "99999")
    
    window.location = "#toppage";


}

function closeForumRulesAdmin() {
    displayAdminPanel();
}

function closeForumRules() {
   getForumList()
}

function authoriseUser(theuserid) {

    var xmlHttp;
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&accountid=" + theuserid;
    //server page for dealing with adding a product
    var url = "AuthoriseForumAccount.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);

            showAllUsersAdmin("0", "", "")

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function viewProfile(theuserid, theforumid, thethreadid) {

    var xmlHttp;
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&forumuserid=" + theuserid + "&theforumid=" + theforumid + "&thethreadid=" + thethreadid;
    //server page for dealing with adding a product
    var url = "ViewProfile.aspx";
    var theBasketStr = "";

    replythreadid = thethreadid;
    currentforumid = theforumid;

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            //alert(theBasketStr);
            document.getElementById("postcontentpnl").innerHTML = theBasketStr;
            showDiv("postcontentpnl", "99999");
            closeDiv("forumreplaypnl")
            closeDiv("forumpostpnl")
            closeDiv("forumcontentpanel")
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            closeDiv("registerpnl")
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            window.location = "#toppage";

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function sendPrivateMessage(theuserid, thethreadid) {



    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=all" + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "CheckLogin.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); ;

            if (theBasketStr == "true") {

                closeDiv("forumreplaypnl")
                closeDiv("forumpostpnl")
                closeDiv("forumcontentpanel")
                closeDiv("forumposteditpnl");
                closeDiv("loginpanel");
                closeDiv("registerpnl");
                closeDiv("userprofilepnl");
                closeDiv("forumrulespnl");
                closeDiv("postcontentpnl");
                showDiv("sendprivatemessagepnl", "99999");
                document.getElementById("privatemessageuserid").value = theuserid;
                document.getElementById("privatemessagethreadid").value = thethreadid;
                window.location = "#toppage";
                

            }
            else {
                alert("you need to be logged in to post on this forum!");
                replythreadid = threadid;
                showLogin()
            }
        }
    }
    //post product data to the server
    xmlHttp.send(params);
    //return false so no page reload takes place
    return false;




   

}

function closePrivateMessage() {
    showThread(document.getElementById("privatemessagethreadid").value, "0")
}

function savePrivateMessage() {
    var thetitle = document.getElementById("privatemessagetitletxt").value;
    var thecontent = document.getElementById("privatemessagecontenttxt").value;
    var foruserid = document.getElementById("privatemessageuserid").value
    var xmlHttp;
    //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&title=" + thetitle + "&content=" + thecontent + "&useridto=" + foruserid;
    //server page for dealing with adding a product
    var url = "SavePrivateMessage.aspx";
    var theBasketStr = "";
  
    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            document.getElementById("privatemessagecontenttxt").value = "";
            document.getElementById("privatemessagetitletxt").value = "";
            alert("Your message has been sent!");
            //sendPrivateMessage(document.getElementById("privatemessageuserid").value, document.getElementById("privatemessagethreadid").value)
            closePrivateMessage();
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function deletePrivatePost(thethreadid) {

    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + thethreadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "DeletePost.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
             getPrivatePosts()
            alert("Your post has been deleted!");
            
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function showFullPrivateMessage(threadid) {

    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + threadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetFullPrivateMessage.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, '');
            document.getElementById("fullPrivateMessagePnl").innerHTML = theBasketStr;
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function quotePostOther(threadidpi, forumidpi) {

    var xmlHttp
    //build product information to be sent to the server
    var params = "threadid=" + threadidpi + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetPost.aspx";
    var theBasketStr = ""

    

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //showThread(threadid)
            var returnedXmlDocument = xmlHttp.responseXML.documentElement;
            var threadcontent = getFirstChildOfXmlResponse(returnedXmlDocument, 'threadcontent')
            document.getElementById("contenttxt").value = "<blockquote>" + addIllegalCharacters(threadcontent) + "</blockquote>";


        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;
}

function quotePost(threadid, forumid, replyidpi) {

    
//comment here
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=all" + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "CheckLogin.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); ;

            if (theBasketStr == "true") {


                replythreadid = replyidpi;
                currentforumid = forumid;
                showDiv("forumreplaypnl", "99999");
                //changed
                quotePostOther(threadid, forumid)
                closeDiv("listofthreadspnl");
                closeDiv("postcontentpnl");
                closeDiv("forumcontentpanel");
                closeDiv("forumpostpnl");
                closeDiv("forumposteditpnl");
                closeDiv("loginpanel");
                closeDiv("userprofilepnl");
                closeDiv("forumrulespnl");
                closeDiv("sendprivatemessagepnl");
                window.location = "#toppage";
            }
            else 
            {
                alert("you need to be logged in to post on this forum!");
                replythreadid = replyidpi;
                currentforumid = forumid;
                //currentuserid = userid;
                showLogin()
            }
        }
    }
    //post product data to the server
    xmlHttp.send(params);
    //return false so no page reload takes place
    return false;

}

function addIllegalCharacters(theStr) {
    theStr = theStr.replace(/^\s+|\s+$/g, '', "g");
    theStr = theStr.replace(new RegExp("%amp", "g"), "&");
    theStr = theStr.replace(new RegExp("%que", "g"), "?");
    theStr = theStr.replace(new RegExp("%at", "g"), "@");
    theStr = theStr.replace(new RegExp("h%h", "g"), '#');
    theStr = theStr.replace(new RegExp("%exp", "g"), "!");
    theStr = theStr.replace(new RegExp("%dollor", "g"), "$");
    theStr = theStr.replace(new RegExp("%pound", "g"), "£");
    theStr = theStr.replace(new RegExp("%squ", "g"), "\'");
    theStr = theStr.replace(new RegExp("&#34;", "g"), "\"");
    theStr = theStr.replace(new RegExp("&#39;", "g"), "\'");
    theStr = theStr.replace(new RegExp("&amp;#34;", "g"), "\"");
    theStr = theStr.replace(new RegExp("&amp;#39;", "g"), "\'");
    theStr = theStr.replace(new RegExp("%dqu", "g"), "\"");
    theStr = theStr.replace(new RegExp("%2B", "g"), "+");

    return theStr;

}

function changeForumRules() {


    var xmlHttp
    //build product information to be sent to the server
    var params = "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetForumRules.aspx";
    var theBasketStr = ""

        //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //showThread(threadid)
            theBasketStr = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); ;
            document.getElementById("adminareapnl").innerHTML = theBasketStr;
            


        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}



function updateRules() {

    var xmlHttp
    //build product information to be sent to the server
    var params = "ruletxt=" + replaceIllegalCharacters(document.getElementById("rulestxt").value) + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "UpdateRules.aspx";
    var theBasketStr = ""

      //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //showThread(threadid)
            document.getElementById("existingforumrules").innerHTML = document.getElementById("rulestxt").value;
            displayAdminPanel()
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function addIcon(theicon, thetextboxid) {
    document.getElementById(thetextboxid).value = document.getElementById(thetextboxid).value + " " + theicon;
}

function showMemberList(thenewpage) {

    showDiv("loadingPnl", "99999");
    //alert("in method!");
    var xmlHttp
    if (thenewpage == "") {
        thenewpage = "0"
    }
    //build product information to be sent to the server
    var params = "thepage=" + thenewpage + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "GetMemberList.aspx";
    var theBasketStr = ""

    //build a connection
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //handle the result
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {

            //new basket returned from the server
            theBasketStr = xmlHttp.responseText;
            showDiv("memberlistpnl", "99999")
            document.getElementById("memberlistpnl").innerHTML = theBasketStr;

            

            closeDiv("postcontentpnl")
            closeDiv("listofthreadspnl")
            //closeDiv("postcontentpnl")
            closeDiv("forumreplaypnl")
            closeDiv("forumpostpnl")
            closeDiv("forumcontentpanel")
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            closeDiv("registerpnl")
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            closeDiv("loadingPnl");
            window.location = "#toppage";

        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;


}

function closeMemberList() {

    closeDiv("memberlistpnl")
    if (replythreadid.length > 0) {
        showThread(replythreadid, "0");
    }
    else if (currentforumid.length > 0) {
        showForum(currentforumid, "0")
    }
    else {
        getForumList();
    }

}

