$(function()
{
	
	
	
	
	
	
	// go through each form assigning a handler to save buttons
	// making sure that all labels 

	var errorAlert = '<div id="errorAlert">\
						<strong>Error</strong><br/>\
						Please fill in all required fields (marked with a <img src="/admin/img/icons/bullet_red.png" />) before submitting the form.\
						</div>';

	$('form input:submit').click(function()
	{
		var ret = true;
		var f = $(this).parent();
		$('label[class="required"]').each(function()
		{
			var lf = $(this).attr('for');
			var e = $('*[name="' + lf + '"]', f);
			var v = e.val();
			if ( v == '' )
			{
				e.addClass('errorInput').effect("pulsate", { times: 3 }, 150);
				$('#errorAlert').remove();
				$('p.adminDescription').after(errorAlert);
				$('#errorAlert').show();
				ret = false;
			}
			else
			{
				$('#errorAlert').hide();
				e.removeClass('errorInput');
			}
		});
		return ret;
	});
	
	
	
	
	// input[name="url"] = strip any http://'s they put in, and any other crap
	$('input[name="url"]').keyup(function()
	{
		$(this).attr('value', $(this).attr('value').replace('http://', '').replace(' ', '').replace(/[^0-9a-zA-Z\.\/\&\?\_\=\+\#\:-]/g, ''));
	});
	
	// telehone / fax - only allow 0-9
	$('#telephone').keyup(function()
	{
		$(this).attr('value', $(this).attr('value').replace('[^0-9]', ''));
	});
	
	
	
	// add rollover help tip 
	/*
	$('form label[class="required"]')
	.mouseover(function()
	{
		$(this).append('<div class="labelHelp">This field is required.</div>');
	})
	.mouseout(function()
	{
		$('.labelHelp').remove();
	});
	*/
	
	
	
	
	
	
});