/*
 * jQuery UI Contrib 0.1pre
 *
 * Copyright (c) 2009 AUTHORS.txt
 * (http://code.google.com/p/jqueryui-contrib/wiki/About)
 * Licensed under the MIT (MIT-LICENSE.txt)
 *
 * http://code.google.com/p/jqueryui-contrib/wiki/docbutton
 */
(function(a){a.widget("ui.button",{_init:function(){var b=this,c=this.options;this.element.addClass("ui-widget ui-widget-container ui-button ui-helper-clearfix");if(c.tooltip!=""){this.oldTitle=this.element.attr("title");this.element.attr("title",c.tooltip)}this.button=a("<a></a>").addClass("ui-state-default ui-corner-all").click(function(){b.click()}).hover(function(){a(this).addClass("ui-state-hover")},function(){a(this).removeClass("ui-state-hover")}).mousedown(function(){a(this).addClass("ui-state-active")}).mouseup(function(){a(this).removeClass("ui-state-active")}).html(c.text).appendTo(this.element);this.icon=a("<span></span>").addClass("ui-icon").prependTo(this.button);this._setIcon(c.icon)},destroy:function(){this.element.removeClass("ui-widget ui-widget-container ui-button ui-helper-clearfix").attr("title",this.oldTitle);this.button.remove()},click:function(){var b=this,c=this.options;c.click.apply(b.element[0],arguments)},_setIcon:function(b){if(b!=""){this.icon.addClass(b)}else{this.icon.hide()}},_setData:function(b,c){switch(b){case"icon":this.icon.removeClass(this.options.icon);this._setIcon(c);break;case"text":this.button.html(c);this.icon.prependTo(this.button);break;case"tooltip":this.element.attr("title",c);break}a.widget.prototype._setData.apply(this,arguments)}});a.extend(a.ui.button,{version:"0.1pre",defaults:{icon:"",text:"",tooltip:"",click:function(){}}})})(jQuery);(function(a){a.widget("ui.buttongroup",{_init:function(){var b=this,c=this.options;this.element.addClass("ui-buttongroup ui-helper-clearfix ui-widget-content");this._createButtons(c.buttons)},destroy:function(){this.element.removeClass("ui-buttongroup ui-helper-clearfix ui-widget-content").find(".ui-button").remove()},add:function(b,e){var c=a("<div></div").appendTo(this.element),d=this.options.scope||c.get(0);c.button({text:b,click:function(){e.apply(d,arguments)}})},remove:function(b){this.element.find(".ui-button").each(function(){if(a(this).button("option","text")==b){a(this).button("destroy")}})},_setData:function(b,c){switch(b){case"buttons":tihs.createButtons(c);break}a.widget.prototype._setData.apply(this,arguments)},_createButtons:function(e){var c=this,b=false,f=this.element,d=this.options.scope||this;this.element.find(".ui-button").remove();(typeof e=="object"&&e!==null&&a.each(e,function(){return !(b=true)}));if(b){a.each(e,function(g,h){c.add(g,h)})}}});a.extend(a.ui.buttongroup,{version:"0.1pre",defaults:{buttons:{}}})})(jQuery);(function(a){a.widget("ui.form",{_init:function(){var b=this,c=this.options;this.element.addClass("ui-widget");if(a.ui.notifier){this.notifier=a("<div></div>").prependTo(this.element).notifier()}this.method=this.element.attr("method").toUpperCase()||"GET";this.action=this.element.attr("action")||"#";this.inputs=this.element.find("input");a.extend(c.validators,a.ui.form.validators);this._createButtons(this.options.buttons);this.textInputs=this.element.find("input[type=text], input[type=password]")},destroy:function(){if(this.notifier){this.notifier.remove()}},submit:function(){var b=this,c={};if(!this._validate()){return}b.inputs.each(function(){c[a(this).attr("name")]=a(this).val()});a.ajax({cache:false,type:b.method,url:b.action,data:c,error:function(d,g,e){var f="An unknown error has occurred";if(d.responseText){f=d.responseText}else{if(g){f=g}else{if(e){f=e}}}b.notifier.notifier("option","text",f).notifier("option","style",a.ui.notifier.ERROR).show("bounce")},beforeSend:function(d){b.notifier.hide();b.inputs.removeClass("ui-state-error")},success:b.options.success})},reset:function(){this.element.each(function(){this.reset()});this.notifier.hide();this.inputs.removeClass("ui-state-error")},_setData:function(b,c){switch(b){case"buttons":this._createButtons(c);break;case"validators":a.extend(c,a.ui.form.validators);break}a.widget.prototype._setData.apply(this,arguments)},_keyPress:function(b,c){if(c.which==13){c.preventDefault();c.data.submit()}},_validate:function(){var b=this,c=this.options,d="";this.inputs.removeClass("ui-state-error");this.inputs.each(function(){var e=this;a.each(b.options.validators,function(f){if(a(e).hasClass(f)){ret=this.apply(e,arguments);if(typeof(ret)!="undefined"){d+=ret;a(e).addClass("ui-state-error")}}})});if(d!=""){this.notifier.notifier("option","text",d).notifier("option","style",a.ui.notifier.ERROR).show("bounce");return false}return true},_createButtons:function(b){this.element.find(".ui-buttongroup").remove();a("<div></div>").appendTo(this.element).buttongroup({buttons:b,scope:this.element[0]})}});a.extend(a.ui.form,{version:"0.1pre",validators:{required:function(){if(a(this).val()==""){return a(this).attr("name").toUpperCase()+" is required"}}},defaults:{buttons:{},success:function(){},validators:{}}})})(jQuery);(function(a){a.widget("ui.notifier",{_init:function(){var b=this,c=this.options;this.element.addClass("ui-corner-all ui-widget ui-notifier");this.container=a("<p></p>").addClass("ui-widget-container").appendTo(this.element);this.iconSpan=a('<span class="icon"></span>').appendTo(this.container);this.messageSpan=a('<span class="message"></span>').appendTo(this.container);this.messageSpan.text(c.text);this.iconSpan.addClass("ui-icon");this._updateStyle(c.style);this._updateVisible(c.visible);this._updateWidth(c.width)},destroy:function(){this.element.removeClass("ui-state-highlight ui-state-error").removeClass("ui-corner-all ui-widget ui-notifier");this.container.remove()},_setData:function(b,c){switch(b){case"text":this.messageSpan.text(c);this._updateWidth(this.options.width);break;case"style":this._updateStyle(c);break;case"width":this._updateWidth(c);break;case"visible":this._updateVisible(c);break}a.widget.prototype._setData.apply(this,arguments)},_updateWidth:function(c){var b=false;if(c==="auto"){if(this.element.is(":hidden")){b=true;this.element.show()}this.element.width("100%");this.element.width(this.iconSpan.width()+this.messageSpan.width());if(a.browser.msie){this.element.width(this.element.width()+46)}if(b){this.element.hide()}}else{this.element.width(c)}},_updateVisible:function(b){if(b){this.element.show()}else{this.element.hide()}},_updateStyle:function(b){this.element.toggleClass("ui-state-highlight",b==a.ui.notifier.WARNING);this.element.toggleClass("ui-state-error",b==a.ui.notifier.ERROR);this.iconSpan.toggleClass("ui-icon-info",b==a.ui.notifier.WARNING);this.iconSpan.toggleClass("ui-icon-alert",b==a.ui.notifier.ERROR)}});a.extend(a.ui.notifier,{version:"0.1pre",WARNING:1,ERROR:2,defaults:{style:1,visible:false,text:"&nbsp;",width:"auto"}})})(jQuery);