﻿/*
* HTML5-compliant watermark script.  Based on: http://www.cssnewbie.com/cross-browser-support-for-html5-placeholder-text-in-forms/
*/
(function() {
	var A1 = window.A1 || { };

	$.support.placeholder = $.support.placeholder || (function() {
		var i = document.createElement('input');
		return 'placeholder' in i;
	})();

	A1.Placeholder = {
		show: function() {
			$(".optional").attr("placeholder", "(Optional)");
			$(".typeAhead").attr("placeholder", "Start typing to see results");

			if (!$.support.placeholder) {
				var cssPlaceholderClass = "waterMark";
				
				$("[placeholder]").on("focus.a1watermark", function() {
					// remove placeholder and waterMark css class on focusing
					var ph = $(this).attr('placeholder');

					if (ph != '') {
						$(this).removeClass(cssPlaceholderClass);
						if ($(this).val() == ph)
							$(this).val('');
					}
				}).on("blur.a1watermark change.a1watermark",  function() {
					// reapply placeholder if necessary
					var ph = $(this).attr('placeholder');

					if (ph != '') {
						
						if ($(this).val() == '' || $(this).val() == ph) {
							$(this).val(ph).addClass(cssPlaceholderClass);
						} else {
							$(this).removeClass(cssPlaceholderClass);
						}
					}
				}).blur();
				
			}
		},
		hide: function() {
			if (!$.support.placeholder) {
				$("[placeholder]").off("focus.a1watermark blur.a1watermark change.a1watermark").each(function() {
					if ($(this).val() == $(this).attr("placeholder"))
						$(this).val('').change().blur();
				});
			}
		}
	};

	A1.ready(function() {
		A1.Placeholder.show();

	});
})();


