(function ($) {
	
	var addCufon = false;
	// add cufon selector
	if ($.addCufonSelector) {
		try {
			$.addCufonSelector(['legend.header'], 'demibold');
			$.addCufonSelector(['legend.regular.header'], 'regular');
			addCufon = true;
		}
		catch (e) {
			console.error(e);
		}
	}
	
	if (window.console && !addCufon) {
		console.error("Can not add cufon selector. Make sure that the Headlines-Module was loaded before the Form-Module"); 
	}
	
	/**
	* Add datepicker onSelect event.
	* This one is needed to fire the in case you use a jQuery UI datepicker in your form
	* AND you using the validate plugin on your form. 
	*/
	var datepickerAdded = false;
	if ($.datepicker && $('div.hasGrid, form.hasGrid').length) {
		try {
			$.datepicker.setDefaults ({
				onSelect: function(dateText, inst) {
					$.smaValidateOptions.unhighlight($(this), 'error', 'valid');
				}
			});
			datepickerAdded = true;
		}
		catch (e) {
			console.log(e);
		}
	}
	
	if (window.console && !datepickerAdded) {
		console.warn('Can not add datepicker onSelect event.');
		console.info('Make sure that jQuery UI was loaded before the Form-Module in case you are using a jQuery UI datepicker in your form with the class "hasGrid"'); 
	}
	
	
	
	
	$(function () {

		/**
		 * Form Validation
		 * -----------------
		 *
		 * ASP.NET entwicker müssen als Selector den Container angeben, der die zu validierenden Elemente enthält.
		 * @example $('div.hasGrid').smaValidate(...);
		 *
		 * zusätzlich kann der zu validierende Bereich auch über die option "fieldset: SELECTOR/jQuery-Object"
		 * @example $('div.hasGrid').smaValidate({
		 *		fieldset: '.six-col.checkboxgroup'
		 * });
		 *
		 * @see: https://svn.sma.de/projects/html-dummies/wiki/SmaValidate
		 * 
		 * @to-do: http://jquery-ui.googlecode.com/svn/branches/labs/tooltip-callout/index.html
		 */
		var $form = $('div.hasGrid, form.hasGrid').smaValidate({
			debug		: true
			//fieldset	: '.six-col.checkboxgroup'
		});
	});
}(jQuery));
