

// *********************************************************** //
// © 2010 Brad Greenwald @ greenwaldweb.com
// Please preserve copyright notice when using this script.
//
// Plan to make this a plugin.... work in cases for select, textrea, radio
//
// *********************************************************** //

$(function(){
		
		// Default Form Behavior: 
		// 1) Clear default values on focus
		// 2) Restore default values when blank
		// 3) Prevent default values from being submitted, omit input names provided in array.

		$('.search, .product-search').find('input[type="text"]').each(function(){
				var el = $(this);
				
				// Store initial value in jquery data object
				el.data('value', $(this).val() );
				
				// Clear value if it's the default
				el.focus(function(e){
						var t = $(this);
						if( t.val() == t.data('value') ) { t.val('');	}
				});
				
				// Restore value if input is left blank
				el.blur(function(e){
						var t = $(this);
						if( t.val() == '' ) { t.val( t.data('value') ); }	
				});
		
		// Return to form collection & apply sumbmit behavior
		}).end().submit(function(){
				
				// If we want to omit certain input names from our default behavior for submission, add them to the submitException object.
				// Correctly iterate key/value pairs with an object, not an array
				var submitException = {
						//0 : 'quantity'
				};
				
				// Remove any defauly input vals prior to submit
				$(this).find('input[type="text"]').each(function(){																			
						var t = $(this);
						
						// End this loop is this input namae ass bee added to the exceptions array
						if ( submitException ) {
								for ( i in submitException ) {
										if( submitException[i] == t.attr('name') ) {
												return;
										}
								}
						}
						
						if( t.val() == t.data('value') ) { t.val(''); }
				});
				
				return true;
		});
		
		// Default Anchor Behavor:
		
		
		
});
