function verifyRebateForm(f)
{
	var good = true;
	$('.required').removeClass('required');
	
	$('.rebate-form:visible .req-text input, .rebate-form:visible .req-text select').each(function(){
		if ($(this).val() == '')
		{
			$(this).addClass('required');
			$(this).parent().addClass('required');
			good = false;
		}
	});
	
	if (!good)
	{
		document.location = '#top';
		alert('Please fill out the fields hilighted in red');
		return false;
	}
	
	return true;
}

function copyPropAddress(flag)
{
	var f = document.rebateForm;
	if (flag)
	{
		$('[name^=appl]').each(function(){
			var name = $(this).attr('name');
			var propName = name.replace(/appl/, 'prop');
			var e = f.elements[propName];
			$(e).val($(this).val());
		});
	}
}

function toggleSecondToilet(flag)
{
	if (flag)
		$('#second-toilet').show();
	else
		$('#second-toilet').hide();
}

function updateFlowRating(val, num)
{
	if (val == 'Other')
		$('#other-flowrating'+num).show();
	else		
		$('#other-flowrating'+num).hide();
}

$(function(){
	// preload hover images
	$('img.hover').each(function(){
		var src = $(this).attr('src');
		var ext = src.slice(-4);
		var hoverSrc = src.slice(0,-4)+'-hover'+ext;
		var img = new Image();
		img.src = hoverSrc;
		$(this).data('hover', hoverSrc);
		$(this).data('org', src);
	});
	
	// hover handlers
	$('img.hover').hover(
		function() { $(this).attr('src', $(this).data('hover')); },
		function() { $(this).attr('src', $(this).data('org')); }
	);
});
