/**
 * Main jQuery rules
 */
$(function() {


// Setup the search box message
	$('.clickreplace').each(function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});
//	if ($('.clickreplace').val() == '') {
//		$('#mapsUsSaddr').val($('#mapsUsSaddr').attr('title'));
//	}
	
	// Now handle what happens when focus is given to it or removed from it
	$('.clickreplace').focus(function() {
		// See if the input field is the default
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	})
	.blur(function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});


	// Setup the search box message
	if ($('#emailsignup').val() == '') {
		$('#emailsignup').val($('#emailsignup').attr('title'));
	}
	// Now handle what happens when focus is given to it or removed from it
	$('#emailsignup').focus(function() {
		// See if the input field is the default
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
			$(this).css({color:'#000'});
		}
	})
	.blur(function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
			$(this).css({color:'#999'});
		}
	});
	
	// Handle jax requests for quick signup
	$('#submitquicksignup').click(function() {
		var hearabout = $('#hearabout').val();
		var email = $('#emailsignup').val();
		
		// If we have values, use them
		if (hearabout != '' && email != '' && email != $('#emailsignup').attr('title')) {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if (reg.test(email) == false) {
				alert('You must supply a valid email address.');
				$('#emailsignup').focus();
				return false;
			}
			// Send it on and handle it
			$.post(
				'stayinformed.php',
				{emailaddress: email, hear_about: hearabout, ajax: 1},
				function(html) {
					//$('#quicksignupbox').html(html);
					//var reply = (html == 1) ? 'Thank you, your request has been submitted.' : 'We\'re sorry, but we have experienced a problem.';
					alert('Thank you, your request has been submitted.')
				}
			);
		} else {
			if (hearabout == '') {
				alert('Please tell us how you heard about us.');
			} else {
				alert('You must supply an email address.');
				$('#emailsignup').focus();
			}
		}
		
		return false;
	});
});
