function fncValidateForm(aryArgs, lngLCID) {
    // v3.0 browsers
    // This function validates forms
    // The input is an array of arguments with 3 arguments per form field
    // The array must have this syntax: 'Form field name', 'Text to alert in case of error', 'Type of validation'
    // Example: 'companyName', 'Company name', 'R', 'email', 'Email', 'RisEmail'
    // Requires the function fncFindObj()
    // Version 1.0, dec 2000, by Søren Larsen
    var objField; // The form field object matching the given field name
    var strFieldAlertText; // The given text that represent the form field in the alert box
    var strTypeOfValidation; // The given validation string
    // Possible values: 
    // - R - input is required
    // - RisEmail - input is required, must be an email address (one or more characters + @ + 3 or more characters and at least one dot after the first lette after the @)
    // - NisEmail - input is NOT required, but if input is given it must be an email address
    // - RisChecked2:3 - input is required, between 2 and 3 of the checkboxes must checked
    // - NisChecked0:3 - input is not required, no more that 3 of the checkboxes can be checked
    // - RisNum - input is required, must be a number
    // - NisNum - input is NOT required, but if input is given it must be a number
    // - RinRange10:400 - input is required, must be a number in this case in the range 10 to 400
    // - NinRange1:5 - input is NOT required, but if input is given it must be a number in this case in the range 1 to 5
    var i; // Counter for iterations
    var pAt; // Pointer for email '@'
    var pDot; // Pointer for email '.'
    var lngCheckedFields; // Count number of checked checkboxes
    var n; // Counter for array of checkboxes / radio buttons
    var pColon; // Pointer for ':' in numeric ranges
    var lngMin; // Minimum value for numeric ranges
    var lngMax; // Maximum value for numeric ranges
    var strErrors = ''; // Used to build string for alert box

    if (lngLCID == 1030) {
        var strMsgGeneral1 = 'Du mangler at udfylde nogle felter.';
        var strMsgGeneral2 = 'Udfyld venligst:';
        var strMsgGeneral3 = 'og send formularen igen.';
        var strMsgIsEmail = 'skal indeholde en gyldig email-adresse';
        var strMsgIsChecked1 = ' (du må ikke markere flere end ';
        var strMsgIsChecked2 = ' (du skal markere mindst ';
        var strMsgIsChecked3 = ' (du skal markere ';
        var strMsgIsChecked4 = ' (du skal markere mellem ';
        var strMsgIsChecked5 = ' af checkboksene';
        var strMsgIsNum = 'skal være et tal';
        var strMsgInRange1 = ' (skal være et tal mellem ';
        var strMsgAnd = ' og ';
    }
    else {
        var strMsgGeneral1 = 'You need to specify aditional information.';
        var strMsgGeneral2 = 'Please fill in:';
        var strMsgGeneral3 = 'and submit again.';
        var strMsgIsEmail = 'must contain a valid e-mail address';
        var strMsgIsChecked1 = ' (you must check no more than ';
        var strMsgIsChecked2 = ' (you must check at least ';
        var strMsgIsChecked3 = ' (you must check ';
        var strMsgIsChecked4 = ' (you must check between ';
        var strMsgIsChecked5 = ' of the checkboxes';
        var strMsgIsNum = 'must contain a number';
        var strMsgInRange1 = ' (must contain a number between ';
        var strMsgAnd = ' and ';
    }

    for (i = 0; i < (aryArgs.length - 2); i += 3) {
        objField = fncFindObj(aryArgs[i]);
        if (objField) {
            valField = objField.value;
            strFieldAlertText = aryArgs[i + 1];
            strTypeOfValidation = aryArgs[i + 2];

            // save status of array of checkboxes or radio buttons in variable.
            lngCheckedFields = 0
            if (objField.type == "checkbox" || objField.type == "radio" || (isArray(objField) && (objField[1].type == "checkbox" || objField[1].type == "radio")))
                if (objField.checked) // Mark if only one checkbox exists i.e. there is no array (possible in dynamic arrays)
                lngCheckedFields = 1;
            else
                for (n = 0; n < objField.length; n++)
                if (objField[n].checked)
                lngCheckedFields++;

            if ((valField == '') || (valField == null && lngCheckedFields == 0) || ((objField.type == "checkbox" || objField.type == "radio") && objField.checked == false)) { // If no input was given
                if (strTypeOfValidation.charAt(0) == 'R') { // and input is required
                    strErrors += '- ' + strFieldAlertText + '\n'; //build error string
                }
            }
            else { // Input was given
                if (strTypeOfValidation.indexOf('isEmail') != -1) {
                    pAt = valField.indexOf('@')
                    pDot = valField.indexOf('.', pAt)
                    if (pAt < 1 || pAt == (valField.length - 3) || pDot < 1 || pDot == (valField.length - 1))
                        strErrors += '- ' + strFieldAlertText + ' (' + strMsgIsEmail + ')\n';
                }
                else if (strTypeOfValidation.indexOf('isChecked') != -1) {
                    pColon = strTypeOfValidation.indexOf(':');
                    lngMin = strTypeOfValidation.substring(10, pColon);
                    lngMax = strTypeOfValidation.substring(pColon + 1);
                    if (lngCheckedFields < lngMin || lngMax < lngCheckedFields) {
                        if (lngMin == 0)
                            strErrors += '- ' + strFieldAlertText + strMsgIsChecked1 + lngMax + strMsgIsChecked5 + ')\n';
                        else if ((lngMax == 9999) && (lngCheckedFields > 9998)) //9999 means unlimited
                            strErrors += '- ' + strFieldAlertText + strMsgIsChecked2 + lngMin + strMsgIsChecked5 + ')\n';
                        else if (lngMin == lngMax)
                            strErrors += '- ' + strFieldAlertText + strMsgIsChecked3 + lngMin + strMsgIsChecked5 + ')\n';
                        else
                            strErrors += '- ' + strFieldAlertText + strMsgIsChecked4 + lngMin + strMsgAnd + lngMax + strMsgIsChecked5 + ')\n';
                    }
                }
                else if (strTypeOfValidation != 'R') { // The rest of the validation types are numeric
                    if (valField != '' + parseFloat(valField))
                        strErrors += '- ' + strFieldAlertText + ' (' + strMsgIsNum + ')\n';
                    else { // Value is a number
                        if (strTypeOfValidation.indexOf('inRange') != -1) {
                            pColon = strTypeOfValidation.indexOf(':');
                            lngMin = strTypeOfValidation.substring(8, pColon);
                            lngMax = strTypeOfValidation.substring(pColon + 1);
                            if (lngMin * 1 > valField * 1 || valField * 1 > lngMax * 1)
                                strErrors += '- ' + strFieldAlertText + strMsgInRange1 + lngMin + strMsgAnd + lngMax + ')\n';
                        }
                    }
                }
            }
        } // Field not found
    } // End of loop
    if (strErrors) {
        alert(strMsgGeneral1 + '\n\n' + strMsgGeneral2 + '\n' + strErrors + '\n' + strMsgGeneral3 + '\n\n');
    }
    document.blnReturnValue = (strErrors == '');
    return (strErrors == '');
}

function fncFindObj(strFormFieldName, d) { //v3.0
    var p, i, x;

    if (!d)
        d = document;
    if ((p = strFormFieldName.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[strFormFieldName.substring(p + 1)].document;
        strFormFieldName = strFormFieldName.substring(0, p);
    }
    if (!(x = d[strFormFieldName]) && d.all)
        x = d.all[strFormFieldName];
    for (i = 0; !x && i < d.forms.length; i++)
        x = d.forms[i][strFormFieldName];
    for (i = 0; !x && d.layers && i < d.layers.length; i++)
        x = fncFindObj(strFormFieldName, d.layers[i].document);
    return x;
}

function isArray(obj) {
    return (typeof (obj.length) == "undefined") ? false : true;
}

function fncGetRadioValue(aryName) {
    var aryFields;
    var objValue = '';
    aryFields = fncFindObj(aryName);
    if (aryFields) {
        if (aryFields.checked) // Mark if only one radiobutton exists i.e. there is no array (possible in dynamic arrays)
            objValue = aryFields.value;
        else
            for (n = 0; n < aryFields.length; n++)
            if (aryFields[n].checked)
            objValue = aryFields[n].value;
        return objValue;
    }
}

