
CustomForm = function (form)
{
    this.form = form;
    this.init();
};

CustomForm.prototype = {
    init : function()
    {
        this.elements = [];
        for(var i=0;i<this.form.elements.length;i++){
            this.elements.push(new CustomForm.Element(this.form.elements[i]),this);
        }
    }
};

CustomForm.Element = function(element,form)
{
    this.element = element;
    this.form = form;
    this.init();
};

CustomForm.Element.prototype = {
    init : function()
    {
        this._initRow();
        this._initShowField();
        this.showIf();
    },

    showIf : function()
    {
        if(false!=this.showField){
            if(this.showField.value == this.showFieldValue){
                this.tr.style.display = '';
            }
            else{
                this.tr.style.display = 'none';
            }
        }
    },

    _initRow : function()
    {
        var tr = this.element.parentNode;
        while (tr && typeof tr.tagName!='undefined' && tr.tagName.toLowerCase()!='tr') {
            tr = tr.parentNode;
        }
        if (tr && typeof tr.tagName!='undefined' && tr.tagName.toLowerCase()=='tr') {
            this.tr = tr;
        }
        else {
            this.tr = false;
        }
    },

    _initShowField : function()
    {
        if(this.tr && this.tr.getAttribute('showField')){
            this.showField = document.getElementById(this.tr.getAttribute('showField'));
            this.showFieldValue = this.tr.getAttribute('showFieldValue');
            YAHOO.util.Event.addListener(this.showField,'change',this.showIf,this,true);
        }
        else {
            this.showField = false;
            this.showFieldValue = false;
        }
    }
};