/**
 * @fileOverview Enhancements for Forms
 * @version 0.1
 * @author Michael Schieben <michael@twoantennas.com> 
 */

/*jslint nomen: true, debug: true, evil: false, onevar: false, browser: true, plusplus: false, undef: true */
/*global window: true, KfW: true, jQuery: true */

(function ($) {
	
	function Forms() {
		
		// jQuery UI based input elements
		// @mm: needed to stop eui-wide for testing:
		
		/*
		$('.eui-select select').not('.eui-wide').selectmenu({'style': 'dropdown'});
		$('.eui-select select.eui-wide').selectmenu({'style': 'dropdown', 'menuWidth': 'auto'});
		*/
		$('.eui-select select').selectmenu({'style': 'dropdown'});
		
		$('.eui-checkbox input[type=checkbox]').customInput();
		
		$('.eui-submitter').submitter();
		
	}
	
	$.fn.submitter = function (options) {
		var defaultSettings = {
		};
		options = $.extend(defaultSettings, options);
		
		return this.each(function () {
			
			var select = $(this);
			if ($(this)[0].nodeName === "DIV") {
				select = $(this).find('select');
				$(this).find('input[type=submit]').hide();
			}
			select.change(function () {
				if ($(this).val() === 0) {
					return;
				}
				$(this).parents('form').submit();
			});
		});
	};
	
	KfW.addInitializer(Forms);
	
}(jQuery));
