function DoConfirm(message, url) {
        if(confirm(message)) location.href = url;
}

function WhichClicked(ww) {
        window.document.postmodify.waction.value = ww;
}

function submitonce(theform) {
        // if IE 4+ or NS 6+
        if (document.all || document.getElementById) {
                // hunt down "submit" and "reset"
                for (i=0;i<theform.length;i++) {
                        var tempobj=theform.elements[i];
                        if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
                                //disable it
                                tempobj.disabled=true;
                        }
                }
        }
}


// Change an anchor, by name.  Puts baseLink and value together.
function changeAnchor(elName, baseLink, value)
{
        // IE...
        if (typeof(document.all) != 'undefined')
                document.all[elName].href = baseLink + value;
        // Mozilla, etc.
        else if (typeof(document.getElementById) != 'undefined')
                document.getElementById(elName).href = baseLink + value;
        // Others...
        else
                for (var i = 0; i < document.anchors.length; i++)
                {
                        if (document.anchors[i].name == elName || document.anchors[i].id == elName)
                                document.anchors[i].href = baseLink + value;
                }
}
function storeCaret_old(text) {
        if (text.createTextRange) {
                text.caretPos = document.selection.createRange().duplicate();
        }
}

// Remember the current position.
function storeCaret(text)
{
        // Only bother if it will be useful.
        if (typeof(text.createTextRange) != 'undefined')
                text.caretPos = document.selection.createRange().duplicate();
}

function replaceText_old(text)
{
        if (document.postmodify.message.createTextRange && document.postmodify.message.caretPos) {
                var caretPos = document.postmodify.message.caretPos;
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
                text + ' ' : text;
        }
        else document.postmodify.message.value += text;
        document.postmodify.message.focus(caretPos)
}

// Replaces the currently selected text with the passed text.
function replaceText(text, textarea)
{
        // Attempt to create a text range (IE).
        if (textarea.createTextRange && textarea.caretPos)
        {
                var caretPos = textarea.caretPos;

                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
                caretPos.select();
        }
        // Mozilla text range replace.
        else if (textarea.selectionStart)
        {
                var begin = textarea.value.substr(0, textarea.selectionStart);
                var end = textarea.value.substr(textarea.selectionEnd);
                textarea.value = begin + text + end;
                if (textarea.setSelectionRange)
                {
                        textarea.focus();
                        textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
                }
        }
        // Just put it on the end.
        else
        {
                textarea.value += text;
                textarea.focus(textarea.value.length - 1);
        }
}

// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, textarea)
{
        // Can a text range be created?
        if (textarea.createTextRange && textarea.caretPos)
        {
                var caretPos = textarea.caretPos;

                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
                caretPos.select();
        }
        // Mozilla text range wrap.
        else if (textarea.selectionStart)
        {
                var begin = textarea.value.substr(0, textarea.selectionStart);
                var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
                var end = textarea.value.substr(textarea.selectionEnd);

                textarea.value = begin + text1 + selection + text2 + end;
                if (textarea.setSelectionRange)
                {
                        var newCursorPos = textarea.selectionEnd + text1.length + text2.length;
                        textarea.focus();
                        textarea.setSelectionRange(newCursorPos, newCursorPos);
                }
        }
        // Just put them on the end, then.
        else
        {
                textarea.value += text1 + text2;
                textarea.focus(textarea.value.length - 1);
        }
}

function surroundText_old(text1,text2)
{
        if (document.postmodify.message.createTextRange && document.postmodify.message.caretPos) {
                var caretPos = document.postmodify.message.caretPos;
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
                text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
        }
        else document.postmodify.message.value += text1 + text2;
        document.postmodify.message.focus(caretPos)
}

function isEmptyText(theField)
{
        while (theField.value.length > 0 && (theField.value.charAt(0)==' ' || theField.value.charAt(0)=='\t'))
                theField.value = theField.value.substring(1,theField.value.length);
        while (theField.value.length > 0 && (theField.value.charAt(theField.value.length-1)==' ' || theField.value.charAt(theField.value.length-1)=='\t'))
                theField.value = theField.value.substring(0,theField.value.length-1);

        if (theField.value=='')
                return true;
        else
                return false;
}
