//
// $Id: Validate.js,v 1.1 2010/07/10 16:48:00 steve Exp $
//
var Validate = function() {

    this.checkValid = function(elem) {
    
        if ($(elem).val()) {
            $(elem).removeClass('invalid')
        }
    }

    this.checkValue = function(elems) {
        
        var valid = 1
        $(elems).each(
            function() {
                if (! $(this).val()) {
                    $(this).addClass('invalid')
                    valid = 0
                }
            })
        if (! valid) {
            alert('Please complete all mandatory fields')
        }                 
        return valid
    }

    this.checkMatch = function(elem1, elem2) {

        if ($(elem1).val() != $(elem2).val() ) {
            $(elem1).addClass('invalid') 
            $(elem2).addClass('invalid')
            alert('Fields do not match')
            return 0
        }           
        return 1      
    }

    this.checkLength = function(elem, l) {

        if ($(elem).val().length < l) {
            $(elem).addClass('invalid') 
            alert('Field must be at least ' + l + ' characters')
            return 0
        }   
        return 1
    }

    this.checkHourMinute = function(elem) {

        if ($(elem).val().match(/^[0-9]*$/) || $(elem).val().match(/^[0-9]*:[0-9]*$/)) {
            return 1
        } else {
            return 0
        } 
    }
}
