/**
 * Author: Olexandr Tarasiuk
 * Date: 02.04.2009
 * Version: 1.0.0
 * @Required /scripts/net/integrio/scripting/ajax/Form.js
 */
function FormField(id, required, requiredMessage, validationFunction) {
    this.id = id;
    this.required = required;
    this.requiredMessage = requiredMessage;
    this.validationFunction = validationFunction ? validationFunction : function(value) {
        return value.trim() != "";
    };
    this.tag = null;
    this.getValue = function() {
        return this.tag.value;
    };
    this.setValue = function(value) {
        this.tag.value = value;
    };
    this.validate = function() {
        if (!this.required) return true;
        if (this.tag.style.display == "none") return true;
        if (this.validationFunction(this.getValue())) return true;
        this.tag.scrollIntoView();
        if (FormField.REQUIRED_MESSAGE_MODE == "DIALOG")
            $createMessageDialog(this.requiredMessage).show();
        else if (FormField.REQUIRED_MESSAGE_MODE = "ALERT") {
            alert(this.requiredMessage);
            this.tag.focus();
        } else
            throw "Invalid REQUIRED_MESSAGE_MODE " + FormField.REQUIRED_MESSAGE_MODE;
        return false;
    };
    this.init = function() {
        this.tag = document.getElementById(this.id);
    };
}
FormField.REQUIRED_MESSAGE_MODE = "DIALOG";
