isIE = window.Event ? false : true;
downX = 0;
downY = 0;
dragObject = null;
modifierObject = null;
mouseIsDown = false;
g_DirectoryPrefix = "";
gPreviousChatContainerName = "view";
gChatCallingFunction = "";
lastGroupRequested = "";

xModImage = 0;
yModImage = 0;

if (!isIE)
{ document.captureEvents(Event.MOUSEDOWN); }
document.onmousedown = downXY;


/********* Chat *********************/
chatExistsTimeout = 100000;
chatModifiedTimeout = 10000;
gRefreshChatIds = false;
gRefreshChatMessages = false;
function checkChatEnter(e) {
    ev = isIE ? event : e;
    if (ev && ev.which)
    { charCode = ev.which }
    else
    { charCode = ev.keyCode }

    if (charCode == 13) {
        g_DirectoryPrefix = '../';
        sendChatMessage();
        return false;
    }
    else { return true; }
}

function clearChat() {
    gChatId = "";
    document.getElementById("removeChatLink").style.display = "none";
    document.getElementById("spnChatParticipantCount").innerHTML = "0"
    document.getElementById("divChats").innerHTML = "";
    document.getElementById("chatArea").innerHTML = "";
    document.getElementById("chatParticipants").innerHTML = "";
    getChatExists();
}
function createChat() {
    gChatId = "";
    document.getElementById("spnChatParticipantCount").innerHTML = "0";
    document.getElementById("chatParticipants").innerHTML = "";
    getChatFriendsDropDown();
}

function createChatParticipant(userId) {
    gCallingFunction = "getChatParticipants";
    postData = "action=create&dataElement=participant&chatId=" + gChatId + "&userId=" + userId;
    getData("/servers/chatserver.aspx", postData);
}
function deleteChat() {
    gCallingFunction = "deleteChat";
    postData = "action=delete&dataElement=chat&chatId=" + gChatId;
    getData("/servers/chatserver.aspx", postData);
}
function deleteChatParticipant(userId) {
    gCallingFunction = "getChatParticipants";
    postData = "action=delete&dataElement=participant&chatId=" + gChatId + "&userId=" + userId;
    getData("/servers/chatserver.aspx", postData);
}
function getChatData(verb, url, parameters) {
    gChatServerRequest = false;
    if (window.XMLHttpRequest)
    { gChatServerRequest = new XMLHttpRequest(); }
    else if (window.ActiveXObject) {
        try
        { gChatServerRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { gChatServerRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { }
        }
    }
    if (!gChatServerRequest)
    { return false; }
    else {
        gChatServerRequest.open(verb, url, true);
        gChatServerRequest.onreadystatechange = function() {
            if (gChatServerRequest.readyState == 4) {
                switch (gChatCallingFunction) {
                    case "getChatExists":
                        if (gChatServerRequest.responseText != "false") {
                            clearTimeout(time_chatExists);
                            arrChatIds = gChatServerRequest.responseText.split(':');
                            gRefreshChatMessages = true;
                            if (document.getElementById("menuChat").style.display == "none")
                            { showHideMenu("Chat"); }
                            populateChats(arrChatIds);
                            time_getChatModified = setTimeout("getChatModified()", chatModifiedTimeout);
                        }
                        else {
                            time_chatExists = setTimeout("getChatExists()", chatExistsTimeout);
                        }
                        break;
                    case "getChatIds":
                        arrChatIds = gChatServerRequest.responseText.split(':');
                        if (gRefreshChatIds == true) {
                            gRefreshChatIds = false;
                            gRefreshChatMessages = false;
                            if (time_getChatModified == "reset")
                            { getChatModified(); }
                        }
                        else
                        { gRefreshChatMessages = true; }

                        if (gChatServerRequest.responseText == "")
                        { clearChat(); }
                        else
                        { populateChats(arrChatIds); }
                        break;
                    case "getChatMessages":
                        showChatMenu();
                        document.getElementById("chatArea").innerHTML = gChatServerRequest.responseText;
                        document.getElementById("spnChatParticipantCount").innerHTML = document.getElementById("hdnChatParticipantCount").value;
                        showHideChat("view");
                        if (gRefreshChatIds)
                        { getChatIds(); }
                        if (time_getChatModified == "reset")
                        { getChatModified(); }
                        break;
                    case "getChatModified":
                        headerLastModified = new Date(gChatServerRequest.getResponseHeader("Last-Modified"));

                        if (time_getChatModified == "reset")
                        { gChatLastModified = headerLastModified; }

                        if (gChatLastModified == "") {
                            gChatLastModified = headerLastModified;
                            time_getChatModified = setTimeout("getChatModified()", chatModifiedTimeout);
                        }
                        else if (new Date(headerLastModified) > new Date(gChatLastModified))
                        { repopulateChat(); }
                        else
                        { time_getChatModified = setTimeout("getChatModified()", chatModifiedTimeout); }
                        break;
                    case "refreshChatIds":
                        arrChatIds = gChatServerRequest.responseText.split(':');
                        gRefreshChatMessages = false;
                        populateChats(arrChatIds);
                        break;
                }
            }
        }
        if (parameters == "")
        { gChatServerRequest.send(null); }
        else
        { gChatServerRequest.send(parameters); }
    }
}
function getChatExists() {
    randomNumber = Math.floor(Math.random() * 1000000);
    gChatCallingFunction = "getChatExists";
    getChatData("GET", "/servers/chatserverasync.aspx?action=getChatExists&userId=" + gUserId + "&randomNumber=" + randomNumber, "");
}
function getChatFriendsDropDown() {
    gCallingFunction = "getChatFriendsDropDown";
    postData = "action=get&dataElement=friendsdropdown";
    getData("/servers/chatserver.aspx", postData);
}
function getChatIds() {
    randomNumber = Math.floor(Math.random() * 1000000);
    gChatCallingFunction = "getChatIds";
    getChatData("GET", "/servers/chatserver.aspx?action=get&dataElement=chatIds&randomNumber=" + randomNumber, "");
}
function getChatMessages(chatId) {
    if (chatId != "") {
        randomNumber = Math.floor(Math.random() * 1000000);
        gChatId = chatId;
        gChatCallingFunction = "getChatMessages";
        getChatData("GET", "/servers/chatserverasync.aspx?action=getChatMessages&userId=" + gUserId + "&chatId=" + gChatId + "&randomNumber=" + randomNumber, "");
    }
}
function getChatModified() {
    gChatCallingFunction = "getChatModified";
    verb = "HEAD";
    if (!isIE)
    { verb = "GET"; }
    randomNumber = Math.floor(Math.random() * 1000000);
    getChatData(verb, "/" + gUserDirectory + "chatnotifications.xml?" + randomNumber, "");
}
function getChatParticipants() {
    gCallingFunction = "getChatParticipants";
    postData = "action=get&dataElement=participants&chatId=" + gChatId + "&userId=" + gUserId;
    getData("/servers/chatserver.aspx", postData);
}
function populateChats(arrChatIds) {
    if (gChatId == "") {
        arrChatId = arrChatIds[0].split('*');
        gChatId = arrChatId[0];
    }
    if (gChatId != "") {
        writeHtml = "";
        for (i = 0; i < arrChatIds.length; i++) {
            arrChatId = arrChatIds[i].split('*');
            writeIcon = "icon_chatinactive.gif";
            if (gChatId == arrChatId[0])
            { writeIcon = "icon_chatactive.gif"; }
            else if (arrChatId[1] == "pending")
            { writeIcon = "icon_chatpending.gif"; }
            writeHtml = writeHtml + "<a href=\"#\" onclick=\"gChatId = '" + arrChatId[0] + "'; repopulateChat(); return false;\">" +
				"<img src=\"/Images/" + writeIcon + "\" border=\"0\" alt=\"" + arrChatId[2] + "\" /></a>&nbsp;&nbsp;";
        }

        document.getElementById("removeChatLink").style.display = "block";
        document.getElementById("divChats").innerHTML = writeHtml;
        if (gRefreshChatMessages) {
            gRefreshChatMessages = false;
            getChatMessages(gChatId);
        }
    }
}
function refreshChatIds() {
    gChatCallingFunction = "refreshChatIds";
    getChatData("GET", "/servers/chatserver.aspx?action=get&dataElement=chatIds", "");
}
function repopulateChat() {
    clearTimeout(time_getChatModified);
    time_getChatModified = "reset";
    gRefreshChatIds = false;
    getChatIds();
}
function sendChatMessage() {
    if (document.getElementById("spnChatParticipantCount").innerHTML == "0") {
        showHideChat("participants");
        document.getElementById("displayChatParticipants").style.display = "block";
        document.getElementById("chatParticipants").innerHTML = "<strong>Please add an online neighbor.</strong>";
        getChatFriendsDropDown();
    }
    else if (document.getElementById("chatMessageText").value != "") {
        gRefreshChatIds = true;
        gCallingFunction = "sendChatMessage";
        postData = "action=send&dataElement=message&chatId=" + gChatId + "&messageText=" + document.getElementById("chatMessageText").value;
        getData("/servers/chatserver.aspx", postData);
        document.getElementById("chatMessageText").value = "";
    }
}
function showChatMenu() {
    if (document.getElementById("leftNavControl_menuChat")) {
        if (document.getElementById("leftNavControl_menuChat").style.display != "block")
        { document.getElementById("leftNavControl_menuChat").style.display = "block"; }
    }
}
function showHideChat(containerName) {
    switch (containerName) {
        case "view":
            document.getElementById("participantsChat").style.display = "none";
            document.getElementById("viewChat").style.display = "block";
            document.getElementById("chatArea").style.display = "block";
            break;
        case "participants":
            document.getElementById("participantsChat").style.display = "block";
            document.getElementById("viewChat").style.display = "none";
            document.getElementById("chatArea").style.display = "none";
            break;
    }
    gPreviousChatContainerName = containerName;
}
function updateChatAvailability(availability) {
    gCallingFunction = "updateChatAvailability";
    postData = "action=update&dataElement=availability&userId=" + gUserId + "&availability=" + availability;
    getData("/servers/chatserver.aspx", postData);
}
/******************************/

function downXY(e) {
    ev = isIE ? event : e;

    downX = ev.clientX + document.body.scrollLeft;
    downY = ev.clientY + document.body.scrollTop;

    if (dragObject) {
        moveX = downX;
        moveY = downY;
        if (modifierObject) {
            xModifier = moveX - xOffset;
            yModifier = moveY - yOffset;
        }
        else {
            xModifier = 0;
            yModifier = 0;
        }
        dragObject.style.position = "absolute";
        dragObject.style.display = "block";
        dragObject.style.left = moveX - xModifier - xModImage;
        dragObject.style.top = moveY - yModifier - yModImage;
        return false;
    }

    mouseIsDown = true;
}

function popupContainer(containerId, topModifier, leftModifier) {
    oContainer = document.getElementById(containerId);
    oContainer.style.display = "block";
    oContainer.style.top = downY + topModifier;
    oContainer.style.left = downX + leftModifier;
}

function showHelp(containerId) {
    popupContainer(containerId, 0, 0);
}

function forgotPassword() {
    if (document.getElementById("loginUsername").value == "" || document.getElementById("loginUsername").value == "Username")
    { setStatus("Please enter your username to find your password."); }
    else {
        gCallingFunction = "forgotPassword";
        postData = "action=send&dataElement=password&username=" + document.getElementById("loginUsername").value;
        getData("/servers/profileserver.aspx", postData);
    }
}

var gServerRequest = false;
var gCallingFunction = "";
function getData(url, parameters) {
    gServerRequest = false;
    if (window.XMLHttpRequest)
    { gServerRequest = new XMLHttpRequest(); }
    else if (window.ActiveXObject) {
        try
        { gServerRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {
            try { gServerRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { }
        }
    }
    if (!gServerRequest)
    { return false; }

    gServerRequest.onreadystatechange = stateListener;
    gServerRequest.open('POST', url, true);
    gServerRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    gServerRequest.setRequestHeader("Content-length", parameters.length);
    gServerRequest.setRequestHeader("Connection", "close");
    gServerRequest.send(parameters);
}

function buildFormData(formName) {
    formObject = document.getElementById(formName);
    postData = "";
    for (i = 0; i < formObject.elements.length; i++) {
        formElement = formObject.elements[i];
        if (formElement.type == "checkbox") {
            if (formElement.checked) {
                formValue = encodeURI(formElement.value);
                formValue = formValue.replace("&", "%26");
                postData = postData + "&" + encodeURI(formElement.name) + "=" + formValue;
            }
        }
        else if (formElement.type != "button" && formElement.type != "submit" && formElement.type != "image") {
            formValue = encodeURI(formElement.value);
            formValue = formValue.replace("&", "%26");
            postData = postData + "&" + encodeURI(formElement.name) + "=" + formValue;
        }
    }

    return postData;
}

function buildUriString(stringValue) {
    return encodeURI(stringValue.replace(/&quot;/g, '"').replace(/&amp;/g, "&")).replace(/&/g, "%26");
}

function stateListener() {
    if (gServerRequest.readyState == 4) {
        if (gServerRequest.status == 200) {
            switch (gCallingFunction) {

                case "createTinyURL":
                    rText = gServerRequest.responseText;
                    if (rText == "ERR") 
                        {
                            document.getElementById("txtShortenURL").value = "ERROR - cannot shrink URL - check and try again";
                            document.getElementById("txtShortenURL").style.color = "red";
                        }
                    else 
                        {
                            document.getElementById("microblogInput2").value = document.getElementById("microblogInput2").value + ' ' + rText;
                            document.getElementById("txtShortenURL").style.color = "black";
                        }
                    updateCharacterCount();
                    break;

                case "createTinyURL_LN":
                    rText = gServerRequest.responseText;
                    if (rText == "ERR") {
                        document.getElementById("txtShortenURL_LN").value = "ERROR - cannot shrink URL - check and try again";
                        document.getElementById("txtShortenURL_LN").style.color = "red";
                    }
                    else {
                        document.getElementById("microblogInput1").value = document.getElementById("microblogInput1").value + ' ' + rText;
                        document.getElementById("txtShortenURL_LN").style.color = "black";
                    }
                    updateCharacterCount();
                    break;

                case "addModerator":
                    splitResponse = gServerRequest.responseText.split("|^");
                    splitItem = splitResponse[0].split("|@");
                    document.getElementById("allMembersDIV").innerHTML = splitItem[0];
                    gAllMembersCount = splitItem[1];
                    splitItem = splitResponse[1].split("|@");
                    document.getElementById("moderatorsDIV").innerHTML = splitItem[0];
                    gModeratorsCount = splitItem[1];
                    splitItem = splitResponse[2].split("|@");
                    document.getElementById("ignoreListDIV").innerHTML = splitItem[0];
                    gIgnoreListCount = splitItem[1];
                    document.getElementById("hiddenScriptAll").innerHTML = splitResponse[3];
                    document.getElementById("hiddenScriptMod").innerHTML = splitResponse[4];
                    document.getElementById("hiddenScriptIgn").innerHTML = splitResponse[5];
                    setStatus("Selected user(s) are now Moderators of this group");
                    break;
                case "removeFromGroup":
                    splitResponse = gServerRequest.responseText.split("|^");
                    splitItem = splitResponse[0].split("|@");
                    document.getElementById("allMembersDIV").innerHTML = splitItem[0];
                    gAllMembersCount = splitItem[1];
                    splitItem = splitResponse[1].split("|@");
                    document.getElementById("moderatorsDIV").innerHTML = splitItem[0];
                    gModeratorsCount = splitItem[1];
                    splitItem = splitResponse[2].split("|@");
                    document.getElementById("ignoreListDIV").innerHTML = splitItem[0];
                    gIgnoreListCount = splitItem[1];
                    document.getElementById("hiddenScriptAll").innerHTML = splitResponse[3];
                    document.getElementById("hiddenScriptMod").innerHTML = splitResponse[4];
                    document.getElementById("hiddenScriptIgn").innerHTML = splitResponse[5];
                    setStatus("Selected user(s) are no longer part of this group");
                    break;
                case "ignoreMember":
                    splitResponse = gServerRequest.responseText.split("|^");
                    splitItem = splitResponse[0].split("|@");
                    document.getElementById("allMembersDIV").innerHTML = splitItem[0];
                    gAllMembersCount = splitItem[1];
                    splitItem = splitResponse[1].split("|@");
                    document.getElementById("moderatorsDIV").innerHTML = splitItem[0];
                    gModeratorsCount = splitItem[1];
                    splitItem = splitResponse[2].split("|@");
                    document.getElementById("ignoreListDIV").innerHTML = splitItem[0];
                    gIgnoreListCount = splitItem[1];
                    document.getElementById("hiddenScriptAll").innerHTML = splitResponse[3];
                    document.getElementById("hiddenScriptMod").innerHTML = splitResponse[4];
                    document.getElementById("hiddenScriptIgn").innerHTML = splitResponse[5];
                    setStatus("Selected user(s) are now blocked from this group");
                    break;
                case "removeModerator":
                    splitResponse = gServerRequest.responseText.split("|^");
                    splitItem = splitResponse[0].split("|@");
                    document.getElementById("allMembersDIV").innerHTML = splitItem[0];
                    gAllMembersCount = splitItem[1];
                    splitItem = splitResponse[1].split("|@");
                    document.getElementById("moderatorsDIV").innerHTML = splitItem[0];
                    gModeratorsCount = splitItem[1];
                    splitItem = splitResponse[2].split("|@");
                    document.getElementById("ignoreListDIV").innerHTML = splitItem[0];
                    gIgnoreListCount = splitItem[1];
                    document.getElementById("hiddenScriptAll").innerHTML = splitResponse[3];
                    document.getElementById("hiddenScriptMod").innerHTML = splitResponse[4];
                    document.getElementById("hiddenScriptIgn").innerHTML = splitResponse[5];
                    setStatus("Selected user(s) are no longer Moderators of this group");
                    break;
                case "reactivateIgnoredUser":
                    splitResponse = gServerRequest.responseText.split("|^");
                    splitItem = splitResponse[0].split("|@");
                    document.getElementById("allMembersDIV").innerHTML = splitItem[0];
                    gAllMembersCount = splitItem[1];
                    splitItem = splitResponse[1].split("|@");
                    document.getElementById("moderatorsDIV").innerHTML = splitItem[0];
                    gModeratorsCount = splitItem[1];
                    splitItem = splitResponse[2].split("|@");
                    document.getElementById("ignoreListDIV").innerHTML = splitItem[0];
                    gIgnoreListCount = splitItem[1];
                    document.getElementById("hiddenScriptAll").innerHTML = splitResponse[3];
                    document.getElementById("hiddenScriptMod").innerHTML = splitResponse[4];
                    document.getElementById("hiddenScriptIgn").innerHTML = splitResponse[5];
                    setStatus("Selected user(s) are no longer blocked from this group");
                    break;

                case "acceptRequest":
                    splitResponse = gServerRequest.responseText.split("|^");
                    document.getElementById("spnIncomingMemberRequests").innerHTML = splitResponse[0];
                    document.getElementById("spnPendingInvitations").innerHTML = splitResponse[1];
                    splitItem = splitResponse[2].split("|@");
                    document.getElementById("allMembersDIV").innerHTML = splitItem[0];
                    gAllMembersCount = splitItem[1];
                    splitItem = splitResponse[3].split("|@");
                    document.getElementById("moderatorsDIV").innerHTML = splitItem[0];
                    gModeratorsCount = splitItem[1];
                    splitItem = splitResponse[4].split("|@");
                    document.getElementById("ignoreListDIV").innerHTML = splitItem[0];
                    gIgnoreListCount = splitItem[1];
                    document.getElementById("hiddenScriptAll").innerHTML = splitResponse[5];
                    document.getElementById("hiddenScriptMod").innerHTML = splitResponse[6];
                    document.getElementById("hiddenScriptIgn").innerHTML = splitResponse[7];
                    setStatus("Accepted Member Request");
                    break;

                case "denyRequest":
                    splitResponse = gServerRequest.responseText.split("|^");
                    document.getElementById("spnIncomingMemberRequests").innerHTML = splitResponse[0];
                    document.getElementById("spnPendingInvitations").innerHTML = splitResponse[1];
                    setStatus("Denied Member Request");
                    break;

                case "cancelInvitation":
                    splitResponse = gServerRequest.responseText.split("|^");
                    document.getElementById("spnIncomingMemberRequests").innerHTML = splitResponse[0];
                    document.getElementById("spnPendingInvitations").innerHTML = splitResponse[1];
                    setStatus("Cancelled Member Invitation");
                    break;

                case "cancelInvitationNoRefresh":
                    document.getElementById("spnPendingInvitations").innerHTML = gServerRequest.responseText;
                    setStatus("Cancelled Member Invitation");
                    break;

                case "createChannelSubscriber":
                    gChannelSubscriberId = gServerRequest.responseText;
                    if (document.getElementById("subscribe" + gChannelId)) {
                        document.getElementById("subscribe" + gChannelId).style.display = "none";
                        document.getElementById("unsubscribe" + gChannelId).style.display = "block";
                    }
                    else
                    { setStatus("You are now subscribed to the channel."); }
                    break;
                case "createUserFriend":
                    returnId = gServerRequest.responseText;
                    //view user is under 18
                    if (returnId == -100)
                    { setStatus("You cannot add neighbors that are under 18."); }
                    //user is under 18
                    else if (returnId == -200)
                    { setStatus("You cannot add neighbors that are over 18."); }
                    //both are under 18 or both are over 18
                    else
                    { setStatus("Neighbor request sent."); }
                    break;
                case "createGroupMemberFF":
                    returnId = gServerRequest.responseText;
                    //view user is under 18
                    if (returnId == -100)
                    { setStatus("Group/member is in restriction (-100)"); }
                    //user is under 18
                    else if (returnId == -200)
                    { setStatus("Group/member is in restriction (-200)"); }
                    //both are under 18 or both are over 18
                    else {
                        var obj1 = document.getElementById("FGroupsHolder");
                        if (obj1) obj1.innerHTML = gServerRequest.responseText;
                        setStatus("Group membership request sent.");
                        getMyGroupsFM();
                    }
                    break;
                case "getMyGroupsFM":
                    var ptext = gServerRequest.responseText;
                    var obj1 = document.getElementById("MyGroupsHolder");
                    if (obj1) obj1.innerHTML = ptext;
                    if (ptext.indexOf(lastGroupRequested) > -1) {
                        setStatus("Your request has been approved.");
                    }
                    break;
                case "createGroupMemberFS":
                    returnId = gServerRequest.responseText;
                    //view user is under 18
                    if (returnId == -100)
                    { setStatus("Group/member is in restriction (-100)"); }
                    //user is under 18
                    else if (returnId == -200)
                    { setStatus("Group/member is in restriction (-200)"); }
                    //both are under 18 or both are over 18
                    else {
                        var obj1 = document.getElementById("SearchGroupsHolder");
                        if (obj1) obj1.innerHTML = gServerRequest.responseText;
                        setStatus("Group membership request sent.");
                        getMyGroupsFM();
                    }
                    break;
                case "createUserIgnore":
                    document.getElementById("spnIgnore").style.display = "none";
                    document.getElementById("spnUnIgnore").style.display = "block";
                    document.getElementById('imgIgnoreIcon').src = '/Images/icon_check.gif';
                    setStatus("Neighbor will be ignored.");
                    break;
                case "createGroupIgnoreFM":
                    splitResponse = gServerRequest.responseText.split("|^");
                    document.getElementById("spnIgnoredGroups").innerHTML = splitResponse[0];
                    var obj1 = document.getElementById("MyGroupsHolder");
                    if (obj1) obj1.innerHTML = splitResponse[1];
                    setStatus("The Group will be ignored.");
                    break;
                case "createGroupIgnoreFF":
                    splitResponse = gServerRequest.responseText.split("|^");
                    document.getElementById("spnIgnoredGroups").innerHTML = splitResponse[0];
                    var obj1 = document.getElementById("FGroupsHolder");
                    if (obj1) obj1.innerHTML = splitResponse[1];
                    setStatus("The Group will be ignored.");
                    break;
                case "createGroupIgnoreFS":
                    splitResponse = gServerRequest.responseText.split("|^");
                    document.getElementById("spnIgnoredGroups").innerHTML = splitResponse[0];
                    var obj1 = document.getElementById("SearchGroupsHolder");
                    if (obj1) obj1.innerHTML = splitResponse[1];
                    setStatus("The Group will be ignored.");
                    break;
                case "deleteGroupMember":
                    var obj1 = document.getElementById("MyGroupsHolder");
                    if (obj1) obj1.innerHTML = gServerRequest.responseText;
                    var obj2 = document.getElementById("spnLeaveGroup");
                    var obj3 = document.getElementById("spnJoinGroup");
                    if (obj2 && obj3) { obj2.style.display = 'none'; obj3.style.display = 'block'; }
                    setStatus("You have left a group.");
                    break;
                case "requestGroupMember":
                    setStatus("You have requested to join the group.");
                    var obj2 = document.getElementById("spnLeaveGroup");
                    var obj3 = document.getElementById("spnJoinGroup");
                    if (obj2 && obj3) { obj3.style.display = 'none'; obj2.style.display = 'block'; }
                    break;
                case "getSearchGroup":
                    var obj1 = document.getElementById("SearchGroupsHolder");
                    if (obj1) obj1.innerHTML = gServerRequest.responseText;
                    obj1 = document.getElementById("SearchAnimHolder");
                    if (obj1) obj1.innerHTML = "";
                    break;
                case "deleteChat":
                    gChatId = "";
                    repopulateChat();
                    break;
                case "getChatMessages":
                    document.getElementById("chatMessageText").value = "";
                    document.getElementById("chatArea").innerHTML = gServerRequest.responseText;
                    showHideChat("view");
                    break;
                case "getChatParticipants":
                    arrReturnData = gServerRequest.responseText.split(':*:');
                    gChatId = arrReturnData[0];
                    document.getElementById("chatParticipants").innerHTML = arrReturnData[1];
                    document.getElementById("spnChatParticipantCount").innerHTML = document.getElementById("participantCount" + gChatId).value;
                    break;
                case "deleteUserIgnore":
                    document.getElementById("spnUnIgnore").style.display = "none";
                    document.getElementById("spnIgnore").style.display = "block";
                    document.getElementById('imgIgnoreIcon').src = '/Images/icon_minus.gif';
                    setStatus("Neighbor will not be ignored.");
                    break;
                case "forgotPassword":
                    if (gServerRequest.responseText == "")
                    { setStatus("Your password has been sent to your email address."); }
                    else
                    { setStatus(gServerRequest.responseText); }
                    break;
                case "getChatFriendsDropDown":
                    if (gServerRequest.responseText == "false") {
                        document.getElementById("displayChatParticipants").style.display = "none";
                        document.getElementById("displayChatNoParticipants").style.display = "block";
                    }
                    else {
                        document.getElementById("displayChatParticipants").style.display = "block";
                        document.getElementById("displayChatNoParticipants").style.display = "none";
                        document.getElementById("spnChatParticipants").innerHTML = gServerRequest.responseText;
                    }
                    if (gChatId != "")
                    { getChatParticipants(); }
                    break;
                case "getForgotPasswordLink":
                    document.location.href = gServerRequest.responseText;
                    break;
                case "getNavWhiteboards":
                    populateNavWhiteboards(gServerRequest.responseText);
                    break;
                case "requestInvite":
                    document.getElementById("txtInviteEmail").value = "";
                    //document.getElementById("getAnInvite").style.display = "none";
                    setStatus("Please check your email to accept your invite.  Your verification code is " + gServerRequest.responseText + ".");
                    break;
                case "sendInvite":
                    setStatus("Invite sent to " + document.getElementById("txtInviteEmail").value + ".");
                    document.getElementById("txtInviteEmail").value = "";
                    //document.getElementById("getAnInvite").style.display = "none";
                    break;
                case "logout":
                    document.location.href = "/home.aspx";
                    break;
                case "removeChannelSubscriber":
                    gChannelSubscriberId = "";
                    if (document.getElementById("subscribe" + gChannelId)) {
                        document.getElementById("subscribe" + gChannelId).style.display = "block";
                        document.getElementById("unsubscribe" + gChannelId).style.display = "none";
                    }
                    else
                    { setStatus("You have unsubscribed from the channel."); }
                    break;
                case "sendChatMessage":
                    repopulateChat();
                    break;
                case "sendRoomMediaPlayer":
                    setStatus("Media Player sent to " + document.getElementById("txtRoomMediaPlayerEmail").value + ".");
                    document.getElementById("txtRoomMediaPlayerEmail").value = "";
                    document.getElementById("viewSendRoomMediaPlayer").style.display = "none";
                    break;
                case "sendSurveyInvite":
                    document.getElementById("lstMobileProvider").value = "";
                    document.getElementById("txtMobileNumber").value = "";
                    document.getElementById("txtEmail").value = "";
                    setStatus("Thank you for your response.");
                    break;
                case "submitSurveyResponse":
                    sendSurveyInvite();
                    break;
                case "createMicroBlog":
                    microblogUpdate(gServerRequest.responseText);
                    break;
                case "createGroupMicroBlog":
                    groupMicroblogUpdate(gServerRequest.responseText);
                    break;
                case "removeGroupIgnore":
                    splitResponse = gServerRequest.responseText.split("|^");
                    document.getElementById("spnIgnoredGroups").innerHTML = splitResponse[0];
                    document.getElementById("spnFeaturedGroups").innerHTML = splitResponse[1];
                    document.getElementById("spnMyGroups").innerHTML = splitResponse[2];
                    setStatus("Group removed from Ignored List");
                    break;

                default:
                    if (gCallingFunction != "launchPlayer")
                    { callExecuted(gCallingFunction, gServerRequest.responseText); }
                    break;
            }
        }
    }
}

function selectValue(dropDownList, selectedValue) {
    for (i = 0; i < dropDownList.options.length; i++) {
        if (dropDownList.options[i].value == selectedValue) {
            dropDownList.options[i].selected = true;
            break;
        }
    }
}

var playerwin = '';
gMediaOwnerId = "";
gMediaArtistId = "";
gMediaTransactionKeyId = "";
function launchPlayer(Id) {
    playerwin = window.open("/MediaPlayer/player.aspx?id=" + Id, "MediaPlayer", "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no,left=100,top=25,width=600,height=400");

    gCallingFunction = "launchPlayer";
    postData = "action=create&dataElement=playBankTransaction&mediaOwnerId=" + gMediaOwnerId + "&mediaArtistId=" + gMediaArtistId + "&transactionKey=" + gMediaTransactionKeyId;
    gMediaOwnerId = "";
    gMediaArtistId = "";
    gMediaTransactionKeyId = "";
    getData("/servers/webmediaserver.aspx", postData);
}

function addOption(selectList, value, text) {
    var newOption = document.createElement("OPTION");
    newOption.value = value;
    newOption.text = text;
    if (navigator.appName == "Netscape")
    { selectList.appendChild(newOption) }
    else
    { selectList.options.add(newOption); }
}

function createChannelSubscriber() {
    if (gUserId == "")
    { setStatus("Please login to subscribe to this channel"); }
    else if (gChannelSubscriberId != "")
    { setStatus("You are already subscribed to this channel."); }
    else {
        postData = "action=create&dataElement=channelsubscriber&channelId=" + gChannelId;
        gCallingFunction = "createChannelSubscriber";
        getData("/servers/channelserver.aspx", postData);
    }
}

function createUserFriend(userId, friendId) {
    gCallingFunction = "createUserFriend";
    postData = "action=create&dataElement=UserFriend&userId=" + encodeURI(userId) + "&friendId=" + encodeURI(friendId);
    getData("/servers/friendserver.aspx", postData);
}


function createUserIgnore(ignoreUserId) {
    gCallingFunction = "createUserIgnore";
    postData = "action=create&dataElement=UserIgnore&ignoreUserId=" + encodeURI(ignoreUserId);
    getData("/servers/profileserver.aspx", postData);
}

// create group ignore FF (From Featured Groups box)
function createGroupIgnoreFF(ignoreUserId, excludeIds, includeIds) {
    gCallingFunction = "createGroupIgnoreFF";
    postData = "action=create&dataElement=GroupIgnoreFF&excludeIds=" + excludeIds + "&includeIds=" + includeIds + "&ignoreUserId=" + encodeURI(ignoreUserId);
    getData("/servers/profileserver.aspx", postData);
}

// create group ignore FM (From My Groups box)
function createGroupIgnoreFM(ignoreUserId) {
    gCallingFunction = "createGroupIgnoreFM";
    postData = "action=create&dataElement=GroupIgnoreFM&ignoreUserId=" + encodeURI(ignoreUserId);
    getData("/servers/profileserver.aspx", postData);
}

// create group ignore FS (From Search Groups box)
function createGroupIgnoreFS(ignoreUserId, keyword) {
    gCallingFunction = "createGroupIgnoreFS";
    postData = "action=create&dataElement=GroupIgnoreFS&ignoreUserId=" + encodeURI(ignoreUserId) + "&keyword=" + encodeURI(keyword);
    getData("/servers/profileserver.aspx", postData);
}

// FM (From My Groups box)
function getMyGroupsFM() {
    gCallingFunction = "getMyGroupsFM";
    postData = "action=get&dataElement=MyGroupsFM";
    getData("/servers/profileserver.aspx", postData);
}

function deleteUserIgnore(ignoreUserId) {
    gCallingFunction = "deleteUserIgnore";
    postData = "action=delete&dataElement=UserIgnore&ignoreUserId=" + encodeURI(ignoreUserId);
    getData("/servers/profileserver.aspx", postData);
}

function getForgotPasswordLink() {
    gCallingFunction = "getForgotPasswordLink";
    postData = "action=get&dataElement=forgotpasswordlink";
    getData("/servers/integration/marketamerica.aspx", postData);
}

function populateNavWhiteboards(whiteboardsHtml) {
    selectList = document.getElementById("leftNavControl_navlstWhiteboards");
    selectList.options.length = 0;
    if (whiteboardsHtml != "") {
        arrWhiteboards = whiteboardsHtml.split(':~:');
        for (i = 0; i < arrWhiteboards.length; i++) {
            arrWhiteboard = arrWhiteboards[i].split("*~*");
            addOption(selectList, arrWhiteboard[0], arrWhiteboard[1]);
        }
        arrWhiteboard = arrWhiteboards[0].split("*~*");
    }
    if (document.getElementById("lstWhiteboards")) {
        populateWhiteboards(whiteboardsHtml);
    }
}

function removeChannelSubscriber(channelId) {
    gChannelId = channelId;
    postData = "action=delete&dataElement=channelsubscriber&channelId=" + gChannelId;
    gCallingFunction = "removeChannelSubscriber";
    getData("/servers/channelserver.aspx", postData);
}

function requestInvite() {
    gCallingFunction = "requestInvite";
    postData = "action=send&dataElement=invite&email=" + document.getElementById("txtInviteEmail").value;
    getData("/servers/profileserver.aspx", postData);
}

function sendInvite() {
    if (document.getElementById("txtInviteEmail").value == "") {
        setStatus("Please enter an email to send this invite to.");
    }
    else {
        gCallingFunction = "sendInvite";
        postData = "action=send&dataElement=invite&fromUserId=" + gUserId + "&email=" + document.getElementById("txtInviteEmail").value;
        getData("/servers/profileserver.aspx", postData);
    }
}

function sendRoomMediaPlayer(mediaPlayerUserId) {
    if (gUserId == "") {
        document.getElementById("viewSendRoomMediaPlayer").style.display = "none";
        setStatus("Please login to send this media player.");
    }
    else if (document.getElementById("txtRoomMediaPlayerEmail").value == "") {
        setStatus("Please enter an email to send your media player to.");
    }
    else {
        gCallingFunction = "sendRoomMediaPlayer";
        postData = "action=send&dataElement=roommediaplayer&mediaPlayerUserId=" + mediaPlayerUserId + "&email=" + document.getElementById("txtRoomMediaPlayerEmail").value;
        getData("/servers/profileserver.aspx", postData);
    }
}

function showHideMenu(menuName) {
    oMenu = document.getElementById("menu" + menuName);
    if (oMenu.style.display == "none") {
        oMenu.style.display = "block";
        document.getElementById("imgCollapse" + menuName).src = "/Images/collapse_b.gif";
        setSessionNode("Session", "LeftNavMenu" + menuName, "Show");
    }
    else {
        oMenu.style.display = "none";
        document.getElementById("imgCollapse" + menuName).src = "/Images/collapse_a.gif";
        setSessionNode("Session", "LeftNavMenu" + menuName, "Hide");
    }
}

function setOpacity(obj, opacity) {
    if (obj) {
        isIE = window.Event ? false : true;
        opacity = (opacity == 100) ? 99.999 : opacity;
        if (isIE)
        { obj.style.filter = "alpha(opacity:" + opacity + ")"; }
        else
        { obj.style.opacity = opacity / 100; }
    }
}

function setSessionNode(parentXPath, nodeName, nodeValue) {
    gCallingFunction = "setSessionNode";
    postData = "action=set&dataElement=sessionnode&parentXPath=" + parentXPath +
		"&nodeName=" + nodeName + "&nodeValue=" + nodeValue;
    getData("/servers/sessionserver.aspx", postData);
}

function sendSurveyInvite() {
    gCallingFunction = "sendSurveyInvite";
    postData = "action=send&dataElement=invite&mobileProviderId=" + document.getElementById("lstMobileProvider").value +
		"&mobilePhone=" + document.getElementById("txtMobileNumber").value + "&email=" + document.getElementById("txtEmail").value;
    getData("/servers/surveyserver.aspx", postData);
}
function submitSurveyResponse() {
    if (document.getElementById("hdnSurveyItemValue") && document.getElementById("hdnSurveyItemValue").value != "") {
        gCallingFunction = "submitSurveyResponse";
        postData = "action=update&dataElement=ItemCount&surveyItemId=" + document.getElementById("hdnSurveyItemValue").value;
        getData("/servers/surveyserver.aspx", postData);
    }
    else {
        sendSurveyInvite();
    }
}

function setStatus(writeStatus, moveTop) {
    if (writeStatus.length > 140) {
        document.getElementById("viewStatus").style.fontSize = "12px";
    } else {
        document.getElementById("viewStatus").style.fontSize = "14px";
    }
    if (writeStatus == "")
    { document.getElementById("viewStatus").style.display = "none"; }
    else {
        document.getElementById("viewStatus").style.display = "block";
        document.getElementById("statusText").innerHTML = writeStatus;
        if ((moveTop == null) || (moveTop == true)) {
            document.location.href = "#pageTopAnchor";
        }
    }
}


function updateRoomPlayerMediaId(mediaId) {
}

function logout() {
    gCallingFunction = "logout";
    postData = "action=update&dataElement=endSession";
    getData("/servers/profileserver.aspx", postData);
}

function chatNowWindow(friendID) {
    document.getElementById("menuChat").style.display = "none";
    showHideMenu('Chat');
    showHideChat('participants');
    createChat();
    createChatParticipant(friendID);
    setTimeout("document.getElementById('chatMessageText').focus();", 1000);
}

// profile post

var microblogInputDivName = "microblogInput"
var microblogInputDefault = "What are you doing right now?";
var microblogInputDefaultIs = "is";
var microblogName = ""
var insideFocus = 0;

function trimMicroBlogInput(i) {
    var obj = document.getElementById(microblogInputDivName + i);
    if (obj) {
        var strO = obj.value;
        strO = strO.replace(/^\s+/, '');
        strO = strO.replace(/\s+$/, '');
        obj.value = strO;
    }
}

function microblogInitial() {
    var obj = document.getElementById("leftNavControl_spnUsername1");
    if (obj) {
        microblogName = obj.innerHTML;
    }
    for (var i = 1; i < 3; i++) {
        obj = document.getElementById(microblogInputDivName + i);
        if (obj) {
            obj.value = microblogInputDefault;
        }
    }
    var obj1 = document.getElementById("leftNavControl_spnTagline1");
    obj = document.getElementById("leftNavControl_spnTagline2");
    if ((obj) && (obj1)) {
        obj.innerHTML = obj1.innerHTML;
    }
}

function groupMicroblogInitial() {
    var obj = document.getElementById("leftNavGroupControl_spnUsername1");
    if (obj) {
        microblogName = obj.innerHTML;
    }
    for (var i = 1; i < 3; i++) {
        obj = document.getElementById(microblogInputDivName + i);
        if (obj) {
            obj.value = microblogInputDefault;
        }
    }
    var obj1 = document.getElementById("leftNavGroupControl_spnTagline1");
    obj = document.getElementById("leftNavGroupControl_spnTagline2");
    if ((obj) && (obj1)) {
        obj.innerHTML = obj1.innerHTML;
    }
}

function microblogPost(i) {
    trimMicroBlogInput(i);
    var obj1 = document.getElementById(microblogInputDivName + i);
    if ((obj1) && (obj1.value.length > 0) && (obj1.value != microblogInputDefault)) {
        gCallingFunction = "createMicroBlog";
        postData = "action=create&dataElement=microblog&entry=" + decodeURI(obj1.value);
        getData("/servers/blogserver.aspx", postData);
        microblogUpdate(".........");
        obj1.value = microblogInputDefault;
    }
}

function microblogPostUser(i, t) {
    trimMicroBlogInput(i);
    var obj1 = document.getElementById(microblogInputDivName + i);
    if ((obj1) && (obj1.value.length > 0) && (obj1.value != microblogInputDefault)) {
        gCallingFunction = "createMicroBlog";
        postData = "action=create&dataElement=microblog&entry=" + decodeURI(obj1.value) + "&updateTwitter=" + t;
        getData("/servers/blogserver.aspx", postData);
        microblogUpdate(".........");
        obj1.value = microblogInputDefault;
    }
}

function groupMicroblogPost(i, id) {
    trimMicroBlogInput(i);
    var obj1 = document.getElementById(microblogInputDivName + i);
    if ((obj1) && (obj1.value.length > 0) && (obj1.value != microblogInputDefault)) {
        gCallingFunction = "createGroupMicroBlog";
        postData = "action=create&dataElement=microblog&entry=" + decodeURI(obj1.value) + "&userId=" + id;
        getData("/servers/blogserver.aspx", postData);
        groupMicroblogUpdate(".........");
        obj1.value = microblogInputDefault;
    }
}

function microblogUpdate(s) {
    var obj2;
    for (var i = 1; i < 3; i++) {
        obj2 = document.getElementById("leftNavControl_spnTagline" + i);
        if (obj2) {
            obj2.innerHTML = s;
            obj2.title = s;
            obj2.focus();
        }
    }
}
function groupMicroblogUpdate(s) {
    var obj2;
    for (var i = 1; i < 3; i++) {
        obj2 = document.getElementById("leftNavGroupControl_spnTagline" + i);
        if (obj2) {
            obj2.innerHTML = s;
            obj2.title = s;
            obj2.focus();
        }
    }
}

function microblogInputFocus(i) {
    trimMicroBlogInput(i)
    var obj = document.getElementById(microblogInputDivName + i);
    if (obj) {
        if (insideFocus == 0) {
            setTimeout("microblogInputSetFocus(" + i + ");", 500);
        }
    }
}


function microblogInputLostFocus(i) {
    trimMicroBlogInput(i)
    var obj = document.getElementById(microblogInputDivName + i);
    if (obj) {
        if ((obj.value == "") || (obj.value == microblogName + " " + microblogInputDefaultIs)) {
            obj.value = microblogInputDefault;
        }
    }
}

function microblogInputSetFocus(i) {
    insideFocus = 1;
    var obj = document.getElementById(microblogInputDivName + i);
    if (obj) {
        if ((obj.value == microblogInputDefault) || (obj.value == microblogName)) {
            obj.value = microblogName + " " + microblogInputDefaultIs + " ";
        }
        obj.focus();
        obj.value = obj.value;
    }
    insideFocus = 0;
}

function microblogKey(e, i) {
    var key = e.keyCode || e.which;
    if (key == 13) {
        microblogPost(i);
        var obj = document.getElementById("microblogdummy");
        try {
            if (obj) obj.focus();
        } catch (e) { }
        return false;
    }
}

function microblogKeyUser(e, i, t) {
    var key = e.keyCode || e.which;
    if (key == 13) {
        microblogPostUser(i, t);
        var obj = document.getElementById("microblogdummy");
        try {
            if (obj) obj.focus();
        } catch (e) { }
        return false;
    }
}
function deleteGroupMember(UserFriendId) {
    if (confirm("Are you sure you want to leave this group?")) {
        gCallingFunction = "deleteGroupMember";
        postData = "action=delete&dataElement=groupByUserFriendId&UserFriendId=" + UserFriendId;
        getData("servers/friendserver.aspx", postData);
    }
}

function deleteGroupMemberByIds(groupUserId, userId) {
    if (confirm("Are you sure you want to leave this group?")) {
        gCallingFunction = "deleteGroupMember";
        postData = "action=delete&dataElement=groupByGroupUserId&groupUserId=" + groupUserId + "&userId=" + userId;
        getData("servers/groupserver.aspx", postData);
    }
}

function requestGroupMember(groupUserId, userId) {
    gCallingFunction = "acceptGroupInvite";
    //    postData = "action=request&dataElement=groupMember&groupUserId=" + groupUserId + "&userId=" + userId;
    postData = "action=accept&dataElement=groupinvite2&userID=" + userId + "&groupID=" + groupUserId + "&admin=0";
    getData("servers/groupserver.aspx", postData);
}

function requestGroupMemberLN(groupUserId, userId) {
    if (userId.length > 0) {
        gCallingFunction = "requestGroupMember";
        postData = "action=request&dataElement=groupMember&groupUserId=" + groupUserId + "&userId=" + userId;
        //    postData = "action=accept&dataElement=groupinvite2&userID=" + userId + "&groupID=" + groupUserId + "&admin=0";
        getData("servers/groupserver.aspx", postData);
    }
    else {
        setStatus("You must log in to join this group.");
    }
}


function createGroupMemberFF(userId, friendId, excludeIds, includeIds) {
    lastGroupRequested = friendId;
    gCallingFunction = "createGroupMemberFF";
    postData = "action=create&dataElement=GroupMemberFF&userId=" + encodeURI(userId) + "&friendId=" + encodeURI(friendId) + "&excludeIds=" + excludeIds + "&includeIds=" + includeIds;
    getData("/servers/friendserver.aspx", postData);
}

function createGroupMemberFS(userId, friendId, keyword) {
    lastGroupRequested = friendId;
    gCallingFunction = "createGroupMemberFS";
    postData = "action=create&dataElement=GroupMemberFS&userId=" + encodeURI(userId) + "&friendId=" + encodeURI(friendId) + "&keyword=" + encodeURI(keyword);
    getData("/servers/friendserver.aspx", postData);
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function switchGroupView() {
    var currVal = readCookie("AdminView");
    if (currVal != null && currVal == "true") {
        eraseCookie("AdminView");
        createCookie("AdminView", "false", 0);
    }
    else {
        eraseCookie("AdminView");
        createCookie("AdminView", 'true', 0);
    }
    currVal = readCookie("AdminView");
    location.reload(true);
}

function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

function textAreaCounter(field, cntfield, maxlimit) {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        cntfield.value = maxlimit - field.value.length;
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/, "");
}

