$(function()
{
	


	$('.mini').css({'opacity':'0.7'});
	
	

	
	$('.external').click(function()
	{
		$(this).attr('target', '_blank');
	});
	
	
	
	$('#copyAddressToDeliveryButton').click(function()
	{
		copyAddressToDelivery();
	});
	
	
	
	
	

	
	// 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').submit(function()
	{
		var ret = true;
		var f = $(this).parent();
		var errorText = '<strong>Please fix the following errors:</strong><br/>';

		errs = false;
		
		$('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();
				errs = true;
				errorText += '<p style="width:30%;float:left;">' + lf.replace(/_/g, ' ').replace('cust', '').replace('del', 'Delivery') + '</p>';

				ret = false;
			}
			else
			{
				$('#errorAlert').hide();
				e.removeClass('errorInput');
				// ret = true;
			}
		});

		if ( errs )
		{
			$('#errorWrapper').html(errorText + '<div class="clear"></div>');
		}
		
		return ret;

	});
	
	
	
	
	

		

		
	
	
	
	
	// ie7 fixes
	if ( $.browser.msie && $.browser.version <= 7 )
	{
		$('#builderLeft').css({'width': '520px'});
		$('#builderRight').css({'width': '382px', 'float':'right'});
		$('#navigationWrap').css({'background': 'black'});
		// $('#navigationWrap img').css({'display': 'none'});
	}
	
	
});
