    // Array to hold error messages
    var errors = new Array();
    
    // Function to add an error message to the array
    function addError(msg)
    {
        if ( (msg != null) && (msg.length > 0) )
            errors.push(msg);
    }

    // Function to validate whether all form fields are filled
    // Parameter notRequired contains an array of fieldnames not to be checked
    // Parameter identifier contains initial characters of the fields to be checked
    // Returns the names of the fields that failed the verification, separated by commas.
    function validate(myForm, notRequired, identifier)
    {               
        var strCompulsory = '';          
                
        for (var i=0;i< myForm.elements.length;i++)
        { // for all of the elements on the form..
            // except those excluded
            var exclude = false;
            if (notRequired != null)
              for (var j=0; j < notRequired.length; j++)
                if (myForm.elements[i].name == notRequired[j])
                    exclude = true;
                    
            if ( ((myForm.elements[i].name.indexOf(identifier) == 0) || (identifier == null)) &&
                 (!exclude) ) 
            { // if the element's name starts with the identifier or no identifier is required..
                if (myForm.elements[i].type == 'select-one' || myForm.elements[i].type == 'select-multiple') 
                {
                    // if it's a list element(for Nav)..
                    if (!myForm.elements[i].options[myForm.elements[i].selectedIndex].value)
                    {
                        // and if the element is empty give a warning
                        strCompulsory = strCompulsory + ' ' + myForm.elements[i].name + ',';
                    }
                }
                else
                    if (!myForm.elements[i].value) 
                    {
                        strCompulsory = strCompulsory + ' ' + myForm.elements[i].name + ',';
                    }               
            } 
        }
        return strCompulsory;
    } 

    // Function to assess whether a specified string has a predefined HTTP URL format.
    // Returns true ou false.    
    function isSite(siteURL) 
    {   
        var siteok=/^(http:\/\/)?[A-Za-z0-9-_]+\.([a-zA-Z]{2,3}|[0-9]{1,3})[A-Za-z0-9-_%&\?\/.=]+$/;        
        return checkRegEx(siteURL, siteok);
    }
    
    // Function to assess whether a specified string has a predefined e-mail format.
    // Returns true ou false.
    function isEmail(mailAddress) 
    {   
        var mailok=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;       
        return checkRegEx(mailAddress, mailok);
    }
    
    // Function to assess whether a specified string matches a given regular expression
    // Returns true ou false.
    function checkRegEx(str, regextrue) 
    {      
        var reg = regextrue; // valid
        if (reg.test(str)) // if syntax is valid
            return true;
        else return false; // if syntax is not valid
    }

    // Function to generate a password, all capitals, with a specific size, and a specific prefix
    function genPassword(size, prefix)
    {
           var chars = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','Z','0','1','2','3','4','5','6','7','8','9');
                         
           var passSize = size;
           var pass = prefix;
           for (var i = 0; i < passSize; i++)
           {
                var pos = Math.floor(Math.random()* chars.length);
                pass = pass + chars[pos];
           }
           return pass;
    }