﻿/*-----------------------------------------------------------
function	: checkMaxLength
Parameters	: maxLength indicating the max length allowed for the field
Description : allows user to enter max characters specified by Maxlength parameter
modified on	:	
-----------------------------------------------------------*/
/*-----------------------------------------------------------
function	: checkMaxLength
Parameters	: maxLength indicating the max length allowed for the field
Description : allows user to enter max characters specified by Maxlength parameter
modified on	:	
-----------------------------------------------------------*/
function checkMaxLength(maxLength, numctlID, ctlID) {
    var str;

    var numctl = $get(numctlID);
    var ctl = $get(ctlID);

    var len = Number(ctl.value.length);
    str = "";
    if (numctl != null && ctl != null) {
        if (ctl.value.length == maxLength - 100)
        { alert("You have only 100 characters left to type"); }
        numctl.innerHTML = (maxLength + 1) - (Number(ctl.value.length) + 1);
        numctl.innerHTML = numctl.innerHTML - 1;
        if (numctl.innerHTML == (maxLength - 1) & ctl.value == "")
        { numctl.innerHTML = maxLength; }
        if (numctl.innerHTML <= -1)
        { numctl.innerHTML = 0; }

        if (len == maxLength) {
            for (var i = 0; i < maxLength - 1; i++)
            { str = str + ctl.value.charAt(i); }

            alert("You have exceeded the limit of " + maxLength + " characters. The characters in excess of " + maxLength + " have been deleted from the end of your statement.\n \n If you have cut and pasted your statement from Word, it is suggested that you delete your statement (highlight your statement in the box and press delete) and then edit your statement in Word to within the " + maxLength + " character limit before re-pasting it.");
            ctl.value = "";
            ctl.value = str;
        }
    }
}
function MaxLengthValidation(maxLength, obj) {
    var ctl = $get(obj);
    var rtn = false;
    if (ctl != null) {
        if (ctl.value.length > maxLength)
            alert("The number of characters entered: " + ctl.value.length + "exceeds the maximum length: " + maxLength + ". Please edit your text and re-submit");
        else
            rtn = true;
    }
    return rtn;
}