$(document).ready(function() {
	
	//
	// Put some niceness on the small subscribe form.
	//
	
	// Show the clear button if there is text in the input.
	if ( $("div.subscribe input[name=email]").val() == '' || $("div.subscribe input[name=email]").val() == 'Your Email' ) {
		$("div.subscribe .submit").css({opacity:0.2});
	} else {
		$("div.subscribe input[name=email]").addClass("active");
	}
	// Do stuff when selecting the input field.
	$("div.subscribe input[name=email]").focus(
		function()
		{
			if ( $(this).val() != '' ) {
				$(this).attr("rel", $(this).val())
					.val("")
					.addClass("active")
					.parent().parent().find(".submit").css({opacity:0.2});
			}
		}
	)
	.blur(
		function()
		{
			if ( $(this).val() == '' ) {
				var relValue = $(this).attr("rel");
				$(this).val($(this).attr("rel")).removeAttr("rel");
				if ( relValue == '' || relValue == 'Your Email' ) {
					$(this).removeClass("active")
					.parent().parent().find(".submit").css({opacity:0.2});
				} else {
					$(this).parent().parent().find(".submit").css({opacity:1});
				}
			}
		}
	).keyup(
		function()
		{
			if ( $(this).val() == '' ) {
				$(this).parent().parent().find(".submit").css({opacity:0.2});
			} else {
				$(this).parent().parent().find(".submit").css({opacity:1});
			}
		}
	);
});

function validateSubscribe( el )
{
	subscribeReturnFocus = 'div#subscribe input';
	if ( el.find("input.required").val() == '' || el.find("input").val() == 'Your Email' ) {
		return false;
	} else {
		if ( (el.find("input").val().match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/) == null) ) {
			// Show a lightbox error message.
			showLightbox( 'Please provide a valid email address.' );
			return false;
		}
	}
	return true;
}

function validateSubscribeLarge( el )
{
	subscribeReturnFocus = '';
	if ( el.find("input[name=cm-name]").val() == '' || el.find("input[name=cm-f-kdhtui]").val() == '' || el.find("input[name=cm-xvjjk-xvjjk]").val() == '' ) {
		// Show a lightbox error message.
		showLightbox( 'Please fill out all required fields.' );
		return false;
	} else {
		if ( el.find("input[name=cm-xvjjk-xvjjk]").val().match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/) == null ) {
			// Show a lightbox error message.
			showLightbox( 'Please provide a valid email address.' );
			return false;
		}
	}
	return true;
}
