function scroll(id, ieId, howfarLeft)
{
    var IE = false;
    if(document.all)
    {
        IE = true;
    }
    var obj;
    if(IE)
    {
        obj = document.getElementById(ieId);
    }
    else
    {
        obj = document.getElementById(id);
    }
    
    var startPos = obj.scrollLeft;
    var endPos = startPos + howfarLeft;
    
    var pos;
    var speed = 5;
    
    if(howfarLeft > 0)
    {
        for(pos = startPos; pos < endPos; pos = pos + speed)
        {
            obj.scrollLeft = pos;
        }
    }
    else
    {
        pos = pos - speed;
        for(pos = startPos; pos > endPos; pos = pos - speed)
        {
            obj.scrollLeft = pos;
        }
    } 
}


function nextSticky(idStem, i)
{
    var showElement = document.getElementById(idStem);
    var nexti = i + 1;
    var hiddenElement = document.getElementById(idStem + nexti);
    showElement.innerHTML = hiddenElement.innerHTML;
    
    var mgrLinksStem = idStem.replace("Slide", "Manager");
    hiddenElement = document.getElementById(mgrLinksStem + nexti);
    showElement = document.getElementById(mgrLinksStem);
    showElement.innerHTML = hiddenElement.innerHTML;
    
}

function backASticky(idStem, i)
{
    var showElement = document.getElementById(idStem);
    var previ = i - 1;
    var hiddenElement = document.getElementById(idStem + previ);
    var txt = hiddenElement.innerHTML;
    showElement.innerHTML = txt;
    
    var mgrLinksStem = idStem.replace("Slide", "Manager");
    hiddenElement = document.getElementById(mgrLinksStem + previ);
    showElement = document.getElementById(mgrLinksStem);
    showElement.innerHTML = hiddenElement.innerHTML;
    
}

function changeElementClass(id, newClass)
{
    var objElement
    objElement = document.getElementById(id);
    objElement.className = newClass;
}


function updateKeyStrokes( objTextArea,counterDiv, maxLength, btnId)
{
    var txt = objTextArea.value;
    var length = txt.length;

    var countDown = maxLength - length;
    
    var objButton = document.getElementById(btnId);
    if(countDown < 0)
    {   
        objButton.disabled = true;
        objTextArea.value = txt.substring(0,maxLength);
    }
    else
    {
        objButton.disabled = false;
    }
    counterDiv = document.getElementById("textLengthCounter");
    counterDiv.innerHTML = countDown + " characters left";
}


function loadImages(stem,strImageList)
{
    if(document.images)
    {
        var strImage = strImageList.split(";");
        var i = 0;
        var img = new Image();
        for(i=0; i<strImage.length; i++)
        {
            img.src = stem + strImage[i];
        }
    }
}




function deleteContent(contentId, val, boardId)
{
    if(confirm('You are about to delete this content.  Do you want to continue?'))
    {
        var url = "createContent.aspx?action=delete&contentId=" + contentId + "&val=" + val + "&id=" + boardId;
        window.location=url
     }
}


function hideNotice(noticeId, val, url)
{
    if(confirm('You are about to take this notice down from the notice board.  Do you want to continue?'))
    {
        var url = "deleteNotice.aspx?action=hide&noticeId=" + noticeId + "&val=" + val + "&rdr=" + url;
        window.location=url;
        
     }
}
function deletePage(boardId, userId, url)
{
    if(confirm('You are about to delete this web page permanently.  Do you want to continue?'))
    {
    //alert("test");
        var url = "/deletePage.aspx?boardid=" + boardId + "&userid=" + userId + "&rdr=" +url;
        window.location=url;
    }
}
function deleteNotice(noticeId, val, url)
{
    if(confirm('You are about to delete this notice permanently.  Do you want to continue?'))
    {
        var url = "deleteNotice.aspx?action=delete&noticeId=" + noticeId + "&val=" + val + "&rdr=" + url;
        window.location=url;
        
     }
}

function deleteSticky(noticeId, val, url)
{
    if(confirm('You are about to remove this sticky permanently.  Do you want to continue?'))
    {
        var url = "deleteNotice.aspx?action=deleteSticky&noticeId=" + noticeId + "&val=" + val + "&rdr=" + url;
        window.location=url;
        
     }
}

function hidePublicConversation(ConversationId, UserId, noticeId, val, url)
{
    if(confirm('You are about to take this sticky and all of the replies down from the notice board. Do you want to continue?'))
    {
        var url = "deleteNotice.aspx?action=hidePublicConversation&conversationId=" + ConversationId + "&userId=" + UserId + "&noticeId=" + noticeId + "&val=" + val + "&rdr=" + url;
        window.location=url;
    }
}

function deletePublicConversation(ConversationId, UserId, noticeId, val, url)
{
    if(confirm('You are about to permanently delete this conversation and all of the replies. Do you want to continue?'))
    {
        var url = "deleteNotice.aspx?action=deletePublicConversation&conversationId=" + ConversationId + "&userId=" + UserId + "&noticeId=" + noticeId + "&val=" + val + "&rdr=" + url;
        window.location=url;
    }
}

function deleteConversation(noticeId, val, url, conversationId, userId)
{
    if(confirm('You are about to delete this conversation permanently.  Do you want to continue?'))
    {
        var url = "deleteNotice.aspx?action=deleteConv&conversationId=" + conversationId + "&noticeId=" + noticeId + "&val=" + val + "&rdr=" + url;
        window.location=url;
        
     }
}

function makeConversationPrivate(noticeId, val, conversationId, url)
{
    if(confirm('You are about to make this conversation private only people involved in the conversation will be able to see it.  Do you want to continue?'))
    {
        var url = "deleteNotice.aspx?action=makeConvPrivate&conversationId=" + conversationId + "&noticeId=" + noticeId + "&val=" + val + "&rdr=" + url;
        window.location=url;
        
     }
}

function addToTextBox( strTextBoxId, strValue )
{
    var tb = document.getElementById(strTextBoxId);
    var strExistingTagList = tb.value.split(" ");
    var bAlreadyInTextBox = false;
    var i;
    for(i=0; i < strExistingTagList.length; i++)
    {
        if( strExistingTagList[i] == strValue )
        {
            bAlreadyInTextBox = true;
            i = strExistingTagList.length;
        }
    }
    if(!bAlreadyInTextBox)
    {
        if(tb.value.length > 0)
        {
            tb.value = tb.value + " " + strValue;
        }
        else
        {
            tb.value = strValue;
        }
    }
}



function replaceTextBoxContent( strTextBoxId, strValue )
{
    var tb = document.getElementById(strTextBoxId);

    tb.value = strValue;
   
}

function addRegularDateToList(strRegularityId, strDayOfWeekId, strHourId, strMinuteId, strDisplayElementId, strHiddenElementId)
{
    var displayEl = document.getElementById(strDisplayElementId);
    var hiddenEl = document.getElementById(strHiddenElementId);
    var regularityEl = document.getElementById(strRegularityId);
    var DayOfWeekEl = document.getElementById(strDayOfWeekId);
    var hourEl = document.getElementById(strHourId);
    var minuteEl = document.getElementById(strMinuteId);
    
    //if updating then if the hidden field has no content then reset the 
    //display field to show nothin before adding the new date
    if(hiddenEl.value.length == 0)
    {
        displayEl.innerHTML ="";
    }
    
    var strExistingDateList = displayEl.innerHTML.toUpperCase().split("<BR>");
    var bAlreadySelected = false;
    var i;
    var selectedRegularity = GetSelectedItem(regularityEl);
    var selectedDay = GetSelectedItem(DayOfWeekEl);
    var selectedHour = GetSelectedItem(hourEl);
    var selectedMinute = GetSelectedItem(minuteEl);
    
    
    strValue = selectedRegularity.text + " on " + selectedDay.text + " at "  + selectedHour.text + ":" + selectedMinute.text;
    
    for(i=0; i < strExistingDateList.length; i++)
    {
        if( strExistingDateList[i] == strValue.toUpperCase() )
        {
            bAlreadySelected = true;
            i = strExistingDateList.length;
        }
    }
    if(!bAlreadySelected)
    {
        if(displayEl.innerHTML.length > 0)
        {
            displayEl.innerHTML += "<BR>" + strValue;
            hiddenEl.value += "<EventDescription><Day>" + selectedDay.value + "</Day><WeekOfMonth>" + selectedRegularity.value + "</WeekOfMonth><Time>" + + selectedHour.text + ":" + selectedMinute.text + "</Time></EventDescription>";
        }
        else
        {
            displayEl.innerHTML = strValue;
            hiddenEl.value = "<EventDescription><Day>" + selectedDay.value + "</Day><WeekOfMonth>" + selectedRegularity.value + "</WeekOfMonth><Time>" + + selectedHour.text + ":" + selectedMinute.text + "</Time></EventDescription>";

        }
    }
}

function addOneOffDateToList(strDateDisplayId, strDateId, strHourId, strMinuteId, strDisplayElementId, strHiddenElementId)
{

    var dateEl = document.getElementById(strDateId);
    var strDate = dateEl.value;
    dateEl.value = "";
    if( strDate.length > 0)
    {

        var dateDisplayEl = document.getElementById(strDateDisplayId);
        var displayEl = document.getElementById(strDisplayElementId);
        var hiddenEl = document.getElementById(strHiddenElementId);       
        var hourEl = document.getElementById(strHourId);
        var minuteEl = document.getElementById(strMinuteId);
        
        //if updating then if the hidden field has no content then reset the 
        //display field to show nothin before adding the new date
        if(hiddenEl.value.length == 0)
        {
            displayEl.innerHTML ="";
        }
        var strExistingDateList = displayEl.innerHTML.toUpperCase().split("<BR>");

        var bAlreadySelected = false;
        var i;
        
        var strDisplaydate = dateDisplayEl.innerHTML;
        
        var selectedHour = GetSelectedItem(hourEl);
        var selectedMinute = GetSelectedItem(minuteEl);
        var strTime = selectedHour.value + ":" + selectedMinute.value;
        strValue = strDisplaydate + " at "  + strTime;
       
        for(i=0; i < strExistingDateList.length; i++)
        {
            if( strExistingDateList[i] == strValue.toUpperCase() )
            {
                bAlreadySelected = true;
                i = strExistingDateList.length;
            }
        }
        if(!bAlreadySelected)
        {       
            if(displayEl.innerHTML.length > 0)
            {
                displayEl.innerHTML += "<BR>" + strValue;
                //strDate already includes Day and date and xml tags
                hiddenEl.value += "<EventDescription>" + strDate + "<Time>" + strTime + "</Time></EventDescription>";            
            }
            else
            {
                displayEl.innerHTML = strValue;
                hiddenEl.value = "<EventDescription>" + strDate + "<Time>" + strTime + "</Time></EventDescription>";

            }
        }
        //alert(hiddenEl.value);
    }
}

function clearLastEntry(strDisplayElementId, strHiddenElementId)
{
    var displayEl = document.getElementById(strDisplayElementId);
    var hiddenEl = document.getElementById(strHiddenElementId);
    var strDisplay = displayEl.innerHTML.toLowerCase();
    
    displayEl.innerHTML = strDisplay.substring(0,strDisplay.lastIndexOf("<img"));
    
    var strHidden = hiddenEl.value;
    hiddenEl.value = strHidden.substring(0, strHidden.lastIndexOf(";", strHidden.length-3)+1);
}

function clearDateList(strDisplayElementId, strHiddenElementId)
{
    var displayEl = document.getElementById(strDisplayElementId);
    var hiddenEl = document.getElementById(strHiddenElementId);
    displayEl.innerHTML = "";
    hiddenEl.value = "";
}

function GetSelectedItem(selectElement) 
{

    var len = selectElement.length;
    i = 0;
    chosen = "none";

    for (i = 0; i < len; i++) 
    {
        if (selectElement[i].selected) 
        {
            chosen = selectElement[i];
        } 
    }

    return chosen;
}
function addIdToHiddenAndNameToDisplay(strName, Id, DisplayElementId, HiddenStorageElementId, src, delimiter)
{
    var displayEl = document.getElementById(DisplayElementId);
    var hiddenStorageEl = document.getElementById(HiddenStorageElementId);
    var strExistingList = hiddenStorageEl.value.split(delimiter);
    var bAlreadySelected = false;
    if(9 < strExistingList.length)
    {
        alert("Warning. Do not use chit-chat for spamming other members.  Failure to comply will result in the suspension of your account and the permanent removal of your profile.");
    }
    for(i=0; i < strExistingList.length; i++)
    {
        if( strExistingList[i] == Id )
        {
            bAlreadySelected = true;
            i = strExistingList.length;
        }
    }
    if(!bAlreadySelected)
    {
        var strDisplay = displayEl.innerHTML;
        //strDisplay += strName + displaydelimiter;
        strDisplay += "<img title='" + strName + "' height='40' width='40' src='" + src + "' />";
        displayEl.innerHTML = strDisplay;
        
        var strHiddenStorage = hiddenStorageEl.value;
        strHiddenStorage +=  Id + delimiter;
        hiddenStorageEl.value = strHiddenStorage;
     }
}
function addValueToList(ValueContainingElementId, DisplayElementId, HiddenStorageElementId, delimiter)
{

    var valueEl = document.getElementById(ValueContainingElementId);
    var displayEl = document.getElementById(DisplayElementId);
    var hiddenStorageEl = document.getElementById(HiddenStorageElementId);
    var strValue = valueEl.value;
    
    var strExistingList = displayEl.innerHTML.toUpperCase().split("<BR>");
    var bAlreadySelected = false;
    for(i=0; i < strExistingList.length; i++)
    {
        if( strExistingList[i] == strValue.toUpperCase() )
        {
            bAlreadySelected = true;
            i = strExistingList.length;
        }
    }
    if(!bAlreadySelected)
    {
        var strDisplay = displayEl.innerHTML;
        strDisplay += strValue + "<br />";
        displayEl.innerHTML = strDisplay;

        var strHiddenStorage = hiddenStorageEl.value;
        strHiddenStorage +=  strValue + delimiter;
        hiddenStorageEl.value = strHiddenStorage;
    }
    valueEl.value = "";
}

function ismaxlength(obj)/*not used in this app*/
{
    var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
    if (obj.getAttribute && obj.value.length>mlength)
    {
        obj.value=obj.value.substring(0,mlength)
    }
}