

jQuery.fn.observe = function(time, callback, ignore) {
    return this.each(function() {
        var aForm = this;
        var aChange = false;

        jQuery("#" + aForm.id + " :input").livequery('change', function() {
            aChange = true;
        });

        jQuery.each(ignore, function(index, item) {
            jQuery(item).unbind('change');
        })

        window.setInterval(function() {
            if (aChange) {
                callback.call(aForm);
            }
            aChange = false;
        }, time * 1000);
    });
};

jQuery.fn.removeChildren = function() {
    this.each(function(index, item) {
        while (item.hasChildNodes()) {
            item.removeChild(item.lastChild);
        }
    });
}

jQuery.fn.buildStateOptions = function(callback) {
    var stateSelect = this;
    jQuery.getJSON("./State.action", {list: '', AUX_RQ_ID: buster() },
            function(stateData) {
                jQuery.each(stateData, function(index, item) {
                    stateSelect.append('<option value="' + item['stateAbbr'] + '">' + item['name'] + '</option>');
                });
                $(this).find('option:first').attr("selected","selected");
                if(callback != undefined) callback();
            });
}

function buster() {
    //yyyyMMddHHmmss
    var busterDate = new Date();
    return '' + busterDate.getFullYear() + '' + busterDate.getMonth() + '' + busterDate.getDate() + '' + busterDate.getHours() + '' + busterDate.getMinutes() + '' + busterDate.getMilliseconds();
}

function alternate(index) {
    if (index % 2 == 0) {
        return "even";
    } else {
        return "odd";
    }
}