
    /*$RCSfile: validateMinLength.js,v $ $Rev: 376673 $ $Date: 2007/12/04 14:15:01 $ */
    /**
    * A field is considered valid if greater than the specified minimum.
    * Fields are not checked if they are disabled.
    * <p>
    * <strong>Caution:</strong> Using <code>validateMinLength</code> on a password field in a 
    *  login page gives unnecessary information away to hackers. While it only slightly
    *  weakens security, we suggest using it only when modifying a password.</p>
    * @param form The form validation is taking place on.
    */
    function validateMinLength(form) {
        var isValid = true;
        var focusField = null;
        var i = 0;
        var fields = new Array();
        var oMinLength = eval('new ' + jcv_retrieveFormName(form) +  '_minlength()');
		
        for (var x in oMinLength) {
            if (!jcv_verifyArrayElement(x, oMinLength[x])) {
                continue;
            }
            var field = form[oMinLength[x][0]];
            if (!jcv_isFieldPresent(field)) {
              continue;
            }

            if ((field.type == 'hidden' ||
                field.type == 'text' ||
                field.type == 'password' ||
                field.type == 'textarea')) {

		        if (field.className.indexOf("_ERROR") > 0){
		        	lib_tmp = "lib_" + field.name;
		            if (document.getElementById(lib_tmp) != null){
		             	document.getElementById(lib_tmp).className = document.getElementById(lib_tmp).className.substr(0,document.getElementById(lib_tmp).className.indexOf("_ERROR"));
					}
					field.className = field.className.substr(0,field.className.indexOf("_ERROR"));
				}
               
				
                /* Adjust length for carriage returns - see Bug 37962 */
                var lineEndLength = oMinLength[x][2]("lineEndLength");
                var adjustAmount = 0;
                if (lineEndLength) {
                    var rCount = 0;
                    var nCount = 0;
                    var crPos = 0;
                    while (crPos < field.value.length) {
                        var currChar = field.value.charAt(crPos);
                        if (currChar == '\r') {
                            rCount++;
                        }
                        if (currChar == '\n') {
                            nCount++;
                        }
                        crPos++;
                    }
                    var endLength = parseInt(lineEndLength);
                    adjustAmount = (nCount * endLength) - (rCount + nCount);
                }

                var iMin = parseInt(oMinLength[x][2]("minlength"));
                if ((trim(field.value).length > 0) && ((field.value.length + adjustAmount) < iMin)) {
                    if (i == 0) {
                        focusField = field;
                    }
                    
                    lib_tmp = "lib_" + field.name;
                    if (document.getElementById(lib_tmp) != null){
                		document.getElementById(lib_tmp).className = document.getElementById(lib_tmp).className + '_ERROR';
					}
                    field.className = field.className + '_ERROR';
                    fields[i++] = oMinLength[x][1];
                    isValid = false;
                }
               
            }
        }
        if (fields.length > 0) {
           jcv_handleErrors(fields, focusField);
        }
        return isValid;
    }
