$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $j(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};

$.fn.dialogButtons = function(name, state){
    var buttons = $(this).next('div').find('button');
    if(!name)return buttons;
    return buttons.each(function(){
        var text = $(this).text();
        if(text==name && state=='disabled') {$(this).attr('disabled',true).addClass('ui-state-disabled');return this;}
        if(text==name && state=='enabled') {$(this).attr('disabled',false).removeClass('ui-state-disabled');return this;}
        if(text==name){return this;}
        if(name=='disabled'){$(this).attr('disabled',true).addClass('ui-state-disabled');return buttons;}
        if(name=='enabled'){$(this).attr('disabled',false).removeClass('ui-state-disabled');return buttons;}
    });
};

