/*              The Moolidate validation library                 */
/*             http://code.google.com/p/moolidate/               */

/*    depends on the mootools libraries -Core -Class -Elements -All "Native" libraries  */
/*                                      http://mootools.net                             */

Element.extend({
    validName : function() {
        return this.findValue().isName();
    },
    validPhone : function() { 
        return this.findValue().isPhoneNumber();
    },
    validEmail : function() { 
        return this.findValue().isEmail();
    },
    validStreet : function() {
        return this.findValue().isStreet();
    },

    validZip : function() {
        return this.findValue().isZip();
    },
    isNotEmpty : function() {
        return this.findValue().isNotEmpty();
    },
    isEmpty : function() {
        return this.findValue().isEmpty();
    },
    validate : function(re) {
        return this.findValue().validate(re);
    },
    findValue : function() {
        if (this.getValue()) return this.getValue();
        else if (this.getText().isNotEmpty()) return this.getText();
        return "";
    }
});
String.extend({
    isName : function() {
        var re = /^[A-Za-z](['. -])?([A-Za-z](['. -])?)+$/;
        if (this.match(re)) {
            return true;
        }
        return false;
    },
    isPhoneNumber : function() {
        var re = /^\(?\d{3}(?:\)|[. -])[. -]?\d{3}[-. ]\d{4}$/  
        if (this.match(re)) {
            return true;
        }
        return false;
    },
    isEmail : function() {
        var re =/^[A-Za-z0-9]+[\w.-]*?[A-Za-z0-9]+@[A-Za-z0-9]+[\w.-]*?\.[A-Za-z0-9]{2,5}$/;
        if (this.match(re)) return true;
        return false;
    },

    isStreet : function() {
        var re = /^\d{2,}\s\b[A-Z][\w .]*[^\W]\.?$/i;
        if (this.match(re)) return true;
        return false;
    },

    isZip : function() {
        var re = /^\d{5}(?:[-._ ]\d{4})?$/;
        if (this.match(re)) return true;
        return false;
    },
    isNotEmpty : function() {
        var re = /\w+/
        if (this.match(re)) return true;
        return false;
    },
    isEmpty : function() {
        var re = /\w+/
        if (this.match(re)) return false;
        return true;
    },
    validate : function(re) {
        if (this.match(re)) return true;
        return false;
    }
});
