$(document).ready(function(){

       			 
// form validation for subscribe page
	// if there is a number in any birthdate field, then the associated birthname is required
	// if the date field is empty, is a string or has spaces, then the associate birthname is not required 
	// after form submit, if there are hidden error messages, show all hidden
	// custom error message for birthday rewards
	$("#mc-embedded-subscribe-form").validate({
		rules: 
		{
			RESTAURANT: 
			{
				required: true
			},
			EMAIL: 
			{
				required: true,
				email: true
			},
			SPOUSENAME:
			{
				required: function(element) 
				{
					if ( (isNaN( parseInt ( $("#mce-SPOUSEBDAY-month").val() ) )) && (isNaN( parseInt ( $("#mce-SPOUSEBDAY-day").val() ) )) && (isNaN( parseInt ( $("#mce-SPOUSEBDAY-year").val() ) )) )
					{
					 return "true";
					}
				}
			},
			CHILDNAME1:
			{
				required: function(element) 
				{
					if ( (isNaN( parseInt ( $("#mce-CHILDBDAY1-month").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY1-day").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY1-year").val() ) )) )
					{
					 return "true";
					}
				}
			},
			CHILDNAME2:
			{
				required: function(element) 
				{
					if ( (isNaN( parseInt ( $("#mce-CHILDBDAY2-month").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY2-day").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY2-year").val() ) )) )
					{
					 return "true";
					}
				}
			},
			CHILDNAME3:
			{
				required: function(element) 
				{
					if ( (isNaN( parseInt ( $("#mce-CHILDBDAY3-month").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY3-day").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY3-year").val() ) )) )
					{
					 return "true";
					}
				}
			},
			CHILDNAME4:
			{
				required: function(element) 
				{
					if ( (isNaN( parseInt ( $("#mce-CHILDBDAY4-month").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY4-day").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY4-year").val() ) )) )
					{
					 return "true";
					}
				}
			},
			CHILDNAME5:
			{
				required: function(element) 
				{
					if ( (isNaN( parseInt ( $("#mce-CHILDBDAY5-month").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY5-day").val() ) )) && (isNaN( parseInt ( $("#mce-CHILDBDAY5-year").val() ) )) )
					{
					 return "true";
					}
				}
			}			
		}, // end of rules
		messages: 
		{
			SPOUSENAME:	{ required: "Name is required for birthday rewards." },
			CHILDNAME1:	{ required: "Name is required for birthday rewards." },
			CHILDNAME2:	{ required: "Name is required for birthday rewards." },
			CHILDNAME3:	{ required: "Name is required for birthday rewards." },
			CHILDNAME4:	{ required: "Name is required for birthday rewards." },
			CHILDNAME5:	{ required: "Name is required for birthday rewards." }			
		}, // end of messages
		invalidHandler: function(form, validator) 
		{
			if ( $(".error:hidden") ) // if there is a hidden error, show all hidden
			{
				$("#mc-embedded-subscribe-form .form-toggle.active-toggle").trigger('click');
			}
		} // end of invalidHandler	   
	});	
				

// subscribe page: hide/show birthdays inputs and birthday 8 day message
	$("#bday-msg").hide();
	$("#mc-embedded-subscribe-form .form-toggle").each(function() {
		$(this).addClass("active-toggle");
		$(this).next('div.form-group').hide();
	}); 
	$("#mc-embedded-subscribe-form .form-toggle").hover(
      function () {
        $(this).addClass("active-toggle-hover");
      }, 
      function () {
        $(this).removeClass("active-toggle-hover");
      }
    );
    $("#mc-embedded-subscribe-form .form-toggle").toggle(
      function () {
		$(this).removeClass("active-toggle");
		$(this).addClass("inactive-toggle");
		$(this).next('div.form-group').show(400);
		$("#bday-msg").show(400);
      },
      function () {
		$(this).addClass("active-toggle");
		$(this).removeClass("inactive-toggle");
		$(this).next('div.form-group').hide(400);
      }
    );

// subscribe page: hide/show interest group descrip
	$('<span class="form-toggle-descrip">What\'s this?</span>').insertBefore("span.descrip");
	$("#mc-embedded-subscribe-form .checkbox-label span.descrip").hide();
	$("#mc-embedded-subscribe-form .form-toggle-descrip").hover(
      function (evt) {
        $(this).addClass("form-toggle-descrip-hover");
        evt.preventDefault();
      }, 
      function (evt) {
        $(this).removeClass("form-toggle-descrip-hover");
        evt.preventDefault();
      }
    );
	$("#mc-embedded-subscribe-form .form-toggle-descrip").toggle(
      function () {
        $(this).next().show(400);
      },
      function () {
        $(this).next().hide(400); 
      }
    );
	
});