function submitForm(val)
{
    if((val == "Cancel") || (val == "Delete")) {
            document.forms.messageForm.submit();
    } else {
           if (checkFields()) {
              document.forms.messageForm.submit();
           }
    }
}

function confirmAction(val,loc)
{
    if (confirm(val)) {
        location = loc
    }
}


function checkFields()
{
    if (document.forms.messageForm.body!=null) {
        var body     = document.forms.messageForm.body.value;
        var subject = document.forms.messageForm.subject.value;

        if (subject  == "" ) {
            alert("Please enter a subject for this post.");
            document.forms.messageForm.subject.focus();
            return false;
        }

        if (subject.length > 54) {
            alert("Post subjects can be up to 50 characters in length.\nThe post subject entered is " + subject.length + " characters long.");
            document.forms.messageForm.subject.focus();
            return false;
        }

        if (body == "" ) {
            alert("Please enter a message for this post.");
            document.forms.messageForm.body.focus();
            return false;
        }
        
    }
    return true;
}

function textCounter(theField,theCharCounter,maxChars) {
    if( theField.value.length > maxChars) {
        alert("Maxmiun message length reached, Your message has been truncated at maxmimun.");
        theField.value = theField.value.substring(0, maxChars);
        theCharCounter.value = maxChars - theField.value.length;
        return false;
    }
    theCharCounter.value = maxChars - theField.value.length;
    return true;
}

