﻿var schoolidclientid = "";
var schoolnamecleintid = "";

var replythreadid = "";
var currentforumid = "";
var currentuserid = "";
var currentparentpostid = "";
var adminuseridworkingon = "";

var controlroomid = "";
var staffroomid = "";
var accountid = "";
var toppanelid = "";

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 = "forumajaxcontrols/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("searchPnl");
            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 = "forumajaxcontrols/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("searchPnl");
            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 = "forumajaxcontrols/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 = addIllegalCharacters(theBasketStr);
            closeDiv("listofthreadspnl")
            //closeDiv("postcontentpnl")
            closeDiv("forumreplaypnl")
            closeDiv("forumpostpnl")
            closeDiv("forumcontentpanel")
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            //closeDiv("registerpnl")
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("searchPnl");
            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 = "forumajaxcontrols/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("searchPnl");
                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 = "forumajaxcontrols/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("searchPnl");
                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");
    closeDiv("searchPnl");
    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 = "forumajaxcontrols/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()
            hideLogInPanels()
        }
    }
    //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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 = "forumajaxcontrols/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("searchPnl");
            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 = "forumajaxcontrols/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 = "forumajaxcontrols/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()
                }
                showLogInPanels()
            }
            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()*/
    document.location.href = "http://www.boffinsquad.co.uk/teachers/index.aspx"


}

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");
    closeDiv("searchPnl");
}

function registerAccount() {

    var theusername = document.getElementById("newuserusername").value;
    var thepassword = document.getElementById("newuserpassword").value;
    var thetitle = document.getElementById("newusertitle").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 thecountry = document.getElementById("newusercountry").value;
    var thelevel = document.getElementById("newuserlevel").value;

    var thetagline = document.getElementById("newusertagline").value;
    var theavatar = document.getElementById("newuseravatar").value;
    var theschoolname = document.getElementById("newuserfindschoolid").value;

    var thebiography = document.getElementById("newuserbiography").value;

    var theemailsend = document.getElementById("newuseremailsend").value;
    var thesubject = document.getElementById("newusersubjects").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 = "";

        document.getElementById("newuserfindschoolid").value = "";
        document.getElementById("newuserschoolname").value = "";

        //alert("in method!");
        var xmlHttp
        //build product information to be sent to the server
        var params = "username=" + replaceIllegalCharacters(theusername) + "&password=" + replaceIllegalCharacters(thepassword) + "&thetitle=" + thetitle + "&forename=" + theforename + "&surname=" + thesurname + "&emailaddr=" + theemail + "&schoolnameid=" + theschoolname + "&country=" + thecountry + "&tagline=" + thetagline + "&biography=" + thebiography + "&emailsend=" + theemailsend + "&thelevel=" + thelevel + "&avatar=" + theavatar + "&thesubject=" + thesubject + "&rcode=" + getRandomString();
        //server page for dealing with adding a product
        var url = "forumajaxcontrols/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 thetitle = document.getElementById("userareatitle").value;
    var theforename = document.getElementById("userareaforenametxt").value;
    var theschoolid = document.getElementById("userareaschoolid").value;
    var thesurname = document.getElementById("userareasurnametxt").value;
    var theemail = document.getElementById("userareaemailtxt").value;
    var thepassword = document.getElementById("userareapasswordtxt").value;
    var thelevel = document.getElementById("userarealevel").value;
    var thesubject = document.getElementById("userareasubject").value;
    var thecountry = document.getElementById("userareacountryddl").value;
    var theavatar = document.getElementById("userareaavatar").value;

    

    var thetagline = document.getElementById("userareatagline").value;

    var thebiography = document.getElementById("userareabiography").value;

    var emailsend = ""
    if (document.getElementById("userareaemailsend").checked) {
        emailsend = "y"
    }
    else {
        emailsend = "n"
     }


    if (validEmail(theemail, true)) {

        //alert("in method!");
        var xmlHttp
        //build product information to be sent to the server
        var params = "password=" + replaceIllegalCharacters(thepassword) + "&forename=" + replaceIllegalCharacters(theforename) + "&surname=" + replaceIllegalCharacters(thesurname) + "&emailaddr=" + replaceIllegalCharacters(theemail) + "&tagline=" + replaceIllegalCharacters(thetagline) + "&biography=" + thebiography + "&title=" + replaceIllegalCharacters(thetitle) + "&schoolid=" + theschoolid + "&level=" + thelevel + "&subject=" + thesubject + "&country=" + thecountry + "&avatar=" + replaceIllegalCharacters(theavatar) + "&emailsend=" + emailsend + "&rcode=" + getRandomString();
        //server page for dealing with adding a product
        var url = "forumajaxcontrols/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 selectCurrentIndexString(objectClientID, theValue) {
    var comparestr = "";
    for (i = 0; i < parseInt(document.getElementById(objectClientID).options.length); i++) {
        comparestr = comparestr + theValue + "-" + document.getElementById(objectClientID).options[i].value;
        comparestr = comparestr + " : "  
        if (theValue == document.getElementById(objectClientID).options[i].value) {
            document.getElementById(objectClientID).selectedIndex = i;
            break;
        }
    }

    alert(comparestr);
}

function showUserArea(userid) {

    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 = "forumajaxcontrols/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("searchPnl");
            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("userareaschoolname").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userschoolname')
            document.getElementById("userareaschoolid").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userschoolid')
            document.getElementById("userareaavatar").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'useravatar')

            if (getFirstChildOfXmlResponse(returnedXmlDocument, 'usersendmail')) {
                document.getElementById("userareaemailsend").checked = true;
            }
            else {
                document.getElementById("userareaemailsend").checked = false;
            }


            try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
                selectCurrentIndexString("userareatitle", getFirstChildOfXmlResponse(returnedXmlDocument, 'usertitle'));
            }
            catch (ex) {

            }
            try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
                selectCurrentIndexString("userarealevel", getFirstChildOfXmlResponse(returnedXmlDocument, 'userlevel'));
            }
            catch (ex) {

            }
            try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
                selectCurrentIndexString("userareasubject", getFirstChildOfXmlResponse(returnedXmlDocument, 'usersubjectid'));
            }
            catch (ex) {

            }
            try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
                selectCurrentIndexString("userareacountryddl", getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry'));
            }
            catch (ex) {

            }
            try {
                document.getElementById("userareatagline").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usertagline')
            }
            catch (ex) {

            }
            try {
                document.getElementById("userareabiography").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'userbiography')
            }
            catch (ex) {

            }*/


            document.getElementById("userareatotalposts").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usertotalposts')

            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 = "forumajaxcontrols/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 = "forumajaxcontrols/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("searchPnl");
            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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 showAllForumsAdmin(thepage, titlesearchstr, contentsearchstr) {
    //alert("in method!");
    var xmlHttp;
        //build product information to be sent to the server
    var params = "rcode=" + getRandomString() + "&thepage=" + thepage;
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/ShowAllForums.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("adminEditForumPnl");

        }
    }
    //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 = "forumajaxcontrols/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) {
            showDiv("edituserpnl", "99999");
            document.getElementById("editpnlforename").value = "";
            document.getElementById("editpnlsurname").value = "";
            document.getElementById("editpnlemail").value = "";
            document.getElementById("editpnlusername").value = "";
            document.getElementById("editpnlpassword").value = "";
            document.getElementById("editpnlschoolname").value = "";
            document.getElementById("editpnlfindschoolid").value = "";
            document.getElementById("editpnlavatar").value = "";
            document.getElementById("editpnlbiography").value = "";

            document.getElementById("editpnltagline").value = "";
            document.getElementById("editpnladmintagline").value = "";

            var returnedXmlDocument = xmlHttp.responseXML.documentElement;

            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')
            document.getElementById("editpnlschoolname").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userschoolname')
            document.getElementById("editpnlfindschoolid").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userschoolid')
            document.getElementById("editpnlavatar").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'useravatar')
            document.getElementById("editpnladmintagline").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'useradmintagline')

            if (getFirstChildOfXmlResponse(returnedXmlDocument, 'usersendmail')) {
                document.getElementById("editpnlemailsend").checked = true;
            }
            else {
                document.getElementById("editpnlemailsend").checked = false;
            }


            try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
                selectCurrentIndexString("editpnltitle", getFirstChildOfXmlResponse(returnedXmlDocument, 'usertitle'));
            }
            catch (ex) {

            }
            try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
                selectCurrentIndexString("editpnllevel", getFirstChildOfXmlResponse(returnedXmlDocument, 'userlevel'));
            }
            catch (ex) {

            }
            try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
                selectCurrentIndexString("editpnlsubjects", getFirstChildOfXmlResponse(returnedXmlDocument, 'usersubjectid'));
            }
            catch (ex) {

            }
            //try {
                // document.getElementById("userareacountrytxt").innerHTML = getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountry')
            selectCurrentIndexString("editpnlcountry", getFirstChildOfXmlResponse(returnedXmlDocument, 'usercountrycode'));
            /*}
            catch (ex) {

            }*/
            try {
                document.getElementById("editpnltagline").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'usertagline')
            }
            catch (ex) {

            }
            try {
                document.getElementById("editpnlbiography").value = getFirstChildOfXmlResponse(returnedXmlDocument, 'userbiography')
            }
            catch (ex) {

            }
            
            
            

           
        }
    }
    //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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 thetitle = document.getElementById("editpnltitle").value;
    var theforename = document.getElementById("editpnlforename").value;
    var thesurname = document.getElementById("editpnlsurname").value;
    var theemail = document.getElementById("editpnlemail").value;
    var theschoolid = document.getElementById("editpnlfindschoolid").value;
    var thelevel = document.getElementById("editpnllevel").value;
    var thesubject = document.getElementById("editpnlsubjects").value;
    var theusername = document.getElementById("editpnlusername").value;
    var thepassword = document.getElementById("editpnlpassword").value;
    var thecountry = document.getElementById("editpnlcountry").value;
    var thetagline = document.getElementById("editpnltagline").value;
    var theadmintagline = document.getElementById("editpnladmintagline").value;
    var thebiography = document.getElementById("editpnlbiography").value;
    var theavatar = document.getElementById("editpnlavatar").value;
    


    var theemailsend = ""
    if (document.getElementById("editpnlemailsend").checked) {
        theemailsend = "y"
    }
    else {
        theemailsend = "n"
    }




    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "password=" + replaceIllegalCharacters(thepassword) + "&admintagline=" + replaceIllegalCharacters(theadmintagline) + "&forename=" + replaceIllegalCharacters(theforename) + "&surname=" + replaceIllegalCharacters(thesurname) + "&emailaddr=" + replaceIllegalCharacters(theemail) + "&tagline=" + replaceIllegalCharacters(thetagline) + "&biography=" + replaceIllegalCharacters(thebiography) + "&title=" + replaceIllegalCharacters(thetitle) + "&schoolid=" + replaceIllegalCharacters(theschoolid) + "&level=" + replaceIllegalCharacters(thelevel) + "&subject=" + replaceIllegalCharacters(thesubject) + "&country=" + thecountry + "&avatar=" + replaceIllegalCharacters(theavatar) + "&emailsend=" + theemailsend + "&useridtoedit=" + adminuseridworkingon + "&rcode=" + getRandomString(); //server page for dealing with adding a product

    //alert("params is " + params);
    var url = "forumajaxcontrols/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 = "forumajaxcontrols/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 addNewForum() {

    var forumname = document.getElementById("newforumtxt").value;
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumname=" + forumname + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/AddForum.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) {
            showAllForumsAdmin("0", "", "")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

//forum
function adminDeleteForum(forumidpi) {
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=" + forumidpi + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/DeleteForum.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) {
            showAllForumsAdmin("0", "", "")
        }
    }
    //post product data to the server
    xmlHttp.send(params);


    //return false so no page reload takes place
    return false;

}

function adminLockPost(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 = "forumajaxcontrols/LockPost.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 adminUnLockPost(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 = "forumajaxcontrols/UnLockPost.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 = "forumajaxcontrols/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 adminEditForumToServer() {

    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) + "&forumid=" + replythreadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/EditForum.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")
            showAllForumsAdmin("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 = "forumajaxcontrols/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 adminEditForum(threadid) {
    //alert("in method!");
    var xmlHttp
    //build product information to be sent to the server
    var params = "forumid=" + threadid + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/AdminGetForum.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("adminEditForumPnl", "99999");
            var returnedXmlDocument = xmlHttp.responseXML.documentElement;
            var threadtitle = getFirstChildOfXmlResponse(returnedXmlDocument, 'forumtitle')
            var threadcontent = getFirstChildOfXmlResponse(returnedXmlDocument, 'forumdescription')

            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 errorString = ""
    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("The email " + email + " has the following errors: " + 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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 = "forumajaxcontrols/AddBadWords.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 = "forumajaxcontrols/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("searchPnl");
    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 = "forumajaxcontrols/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 = "forumajaxcontrols/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("searchPnl");
            closeDiv("forumreplaypnl")
            closeDiv("forumpostpnl")
            closeDiv("forumcontentpanel")
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            //closeDiv("registerpnl")
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");




            closeDiv("listofthreadspnl")
            closeDiv("forumposteditpnl");
              
            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 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 = "forumajaxcontrols/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("searchPnl");
                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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 style='background-color:#cccc66;'>" + 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 = "forumajaxcontrols/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");
                closeDiv("searchPnl");
                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 = "forumajaxcontrols/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 = "forumajaxcontrols/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 = "forumajaxcontrols/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");
            closeDiv("searchPnl");
            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();
    }

}

function updateHiddenSchoolField(theid, schoolname) {
    document.getElementById(schoolidclientid).value = theid;
    document.getElementById(schoolnamecleintid).value = schoolname;
}

function addNewSchool(schoolpnlid) {
    document.getElementById("addnewschoolpnl").style.display = "";
}

function showFindSchool(thepageno, schoolnameid, schoolidid, resultspnlid) {
    showDiv("loadingPnl", "99999");
    schoolidclientid = schoolidid;
    schoolnamecleintid = schoolnameid;


    if (document.getElementById(schoolnameid).value.length > 0) {

        //schoolnameid
        var thesearchterm = document.getElementById(schoolnameid).value;
        //alert("in method!");
        var xmlHttp
        //build product information to be sent to the server
        var params = "rcode=" + getRandomString() + "&searchterm=" + thesearchterm + "&thepage=" + thepageno + "&schoolidclientid=" + schoolidid + "&schoolnameclientid=" + schoolnameid + "&resultspnlid=" + resultspnlid;
        //server page for dealing with adding a product
        var url = "forumajaxcontrols/GetSchool.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(resultspnlid, "99999")
                document.getElementById(resultspnlid).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("memberlistpnl")
                closeDiv("loadingPnl");
                closeDiv("searchPnl");
                window.location = "#toppage";

            }
        }
        //post product data to the server
        xmlHttp.send(params);
    }
    else {
        alert("You need to a search term to enable us to find the school!")
    }

    //return false so no page reload takes place
    return false;

}


function showAddSchool(pnlid) {

    showDiv(pnlid, "99999");
}


function addSchool(txtAddSchoolNameid, txtAddSchoolAdd1id, txtAddSchoolAdd2id, txtAddSchoolAdd3id, txtAddSchoolTownid, txtAddSchoolCountyid, txtAddSchoolPostCodeid, txtAddSchoolCountryid, chkSecondryid, containerpnl, schoolnameid, schoolidid) {

    var schoolname = document.getElementById(txtAddSchoolNameid).value;
    var schooladdress1 = document.getElementById(txtAddSchoolAdd1id).value;
    var schooladdress2 = document.getElementById(txtAddSchoolAdd2id).value;
    var schooladdress3 = document.getElementById(txtAddSchoolAdd3id).value;
    var schooltown = document.getElementById(txtAddSchoolTownid).value;
    var schoolcounty = document.getElementById(txtAddSchoolCountyid).value;
    var schoolpostcode = document.getElementById(txtAddSchoolPostCodeid).value;
    var schoolcountry = document.getElementById(txtAddSchoolCountryid).value;
    var schoolsecondary = document.getElementById(chkSecondryid).value;
    //build product information to be sent to the server
    var params = "schoolname=" + replaceIllegalCharacters(schoolname) + "&schooladdress1=" + replaceIllegalCharacters(schooladdress1) + "&schooladdress2=" + replaceIllegalCharacters(schooladdress2) +  "&schooladdress3=" + replaceIllegalCharacters(schooladdress3) + "&schooltown=" + replaceIllegalCharacters(schooltown) + "&schoolcounty=" + replaceIllegalCharacters(schoolcounty) + "&schoolpostcode=" + schoolpostcode + "&schoolsecondary=" + schoolsecondary + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/AddSchool.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;
            document.getElementById(schoolidid).value = theBasketStr;
            document.getElementById(schoolnameid).value = txtAddSchoolNameid;
            closeDiv(containerpnl)
            window.location = "#toppage";

        }
    }
    //post product data to the server
    xmlHttp.send(params);
    
    


    //return false so no page reload takes place
    return false;
}

function setServerClientIds(controlroomidpi, staffroomidpi, accountidpi, toppanelidpi, uid) {
    controlroomid = controlroomidpi;
    staffroomid = staffroomidpi;
    accountid = accountidpi;
    toppanelid = toppanelidpi;
    
    if (uid.length < 1) {
        hideLogInPanels()   
    }
    else {
        showLogInPanels()   
    }
}

function hideLogInPanels() {
//    document.getElementById(controlroomid).style.display = "none";
//    document.getElementById(staffroomid).style.display = "none";
//    document.getElementById(accountid).style.display = "none";
    document.getElementById(toppanelid).style.display = "none";
}

function showLogInPanels() {
//    document.getElementById(controlroomid).style.display = "";
//    document.getElementById(staffroomid).style.display = "";
//    document.getElementById(accountid).style.display = "";
    document.getElementById(toppanelid).style.display = "";
}
function searchForThreadPages(thepagepi, searchstr) {

    if (searchstr.length > 0) {
        var params = "searchvalue=" + replaceIllegalCharacters(searchstr) + "&thepage=" + thepagepi + "&rcode=" + getRandomString();
        //server page for dealing with adding a product
        var url = "forumajaxcontrols/GetSearchResults.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;
                document.getElementById("searchPnl").innerHTML = theBasketStr;
                document.getElementById("searchtxt").value = "";


                closeDiv("forumreplaypnl");
                closeDiv("listofthreadspnl");
                closeDiv("postcontentpnl");
                closeDiv("forumcontentpanel");
                closeDiv("forumpostpnl");
                closeDiv("forumposteditpnl");
                closeDiv("loginpanel");
                closeDiv("userprofilepnl");
                closeDiv("forumrulespnl");
                closeDiv("sendprivatemessagepnl");
                closeDiv("memberlistpnl")
                window.location = "#toppage";

            }
        }
        //post product data to the server
        xmlHttp.send(params);


    }
    else {
        alert("You need to enter a search term!")
    }

    //return false so no page reload takes place
    return false;


}

function searchForThread(thepagepi) {

    document.getElementById("searchPnl").style.display = "";
    var searchstr = document.getElementById("searchtxt").value;
    if (searchstr.length > 0) {
    var params = "searchvalue=" + replaceIllegalCharacters(searchstr) + "&thepage=" + thepagepi + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/GetSearchResults.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;
            document.getElementById("searchPnl").innerHTML = theBasketStr;
            document.getElementById("searchtxt").value = "";


            closeDiv("forumreplaypnl");
            closeDiv("listofthreadspnl");
            closeDiv("postcontentpnl");
            closeDiv("forumcontentpanel");
            closeDiv("forumpostpnl");
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            closeDiv("memberlistpnl")
            window.location = "#toppage";

        }
    }
    //post product data to the server
    xmlHttp.send(params);


 }
    else {
        alert("You need to enter a search term!")
    }

    //return false so no page reload takes place
    return false;

}


function searchForThreadOther(thepagepi, searchidbox) {

    document.getElementById("searchPnl").style.display = "";
    var searchstr = document.getElementById(searchidbox).value;
if (searchstr.length > 0) {
    var params = "searchvalue=" + replaceIllegalCharacters(searchstr) + "&thepage=" + thepagepi + "&rcode=" + getRandomString();
    //server page for dealing with adding a product
    var url = "forumajaxcontrols/GetSearchResults.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;
            document.getElementById("searchPnl").innerHTML = theBasketStr;

            document.getElementById(searchidbox).value = "";

            closeDiv("forumreplaypnl");
            closeDiv("listofthreadspnl");
            closeDiv("postcontentpnl");
            closeDiv("forumcontentpanel");
            closeDiv("forumpostpnl");
            closeDiv("forumposteditpnl");
            closeDiv("loginpanel");
            closeDiv("userprofilepnl");
            closeDiv("forumrulespnl");
            closeDiv("sendprivatemessagepnl");
            closeDiv("memberlistpnl")
            window.location = "#toppage";

        }
    }
    //post product data to the server
    xmlHttp.send(params);


}
else {
    alert("You need to enter a search term!")
}

    //return false so no page reload takes place
    return false;

}