
var $j = jQuery.noConflict();

$j(function(){
	$j('.quoteform').hide();
	$j('#waiting').hide();
	$j('#thankyou').hide();
	$j('#thankyou_message').html('');

	$j('#nm_5 a').removeClass("selected");
	$j('#nm_6 a').removeClass("selected");
	$j('#nm_7 a').removeClass("selected");
	$j('#nm_8 a').removeClass("selected");
	
	$j('#validation_individual').html('');
	$j('#validation_individual').hide();
	$j('#validation_group').html('');
	$j('#validation_group').hide();
	$j('#validation_shortterm').html('');
	$j('#validation_shortterm').hide();
	$j('#validation_medicare').html('');
	$j('#validation_medicare').hide();
	
	$j('#generalinformation').hide();	
	$j('#generalinformationLink').click(function() {
		$j('#generalinformation').toggle();
		return false;
	});
	$j('#individualresources').hide();	
	$j('#individualresourcesLink').click(function() {
		$j('#individualresources').toggle();
		return false;
	});
	$j('#groupresources').hide();	
	$j('#groupresourcesLink').click(function() {
		$j('#groupresources').toggle();
		return false;
	});
	$j('#medicareresources').hide();	
	$j('#medicareresourcesLink').click(function() {
		$j('#medicareresources').toggle();
		return false;
	});
	
	//months
	for(var i = 1; i < 13; i++)
	{
		$j('.monthselect').append('<option>' + i + '</option>')
	} 
	//days
	for(var i = 1; i < 32; i++)
	{
		$j('.dayselect').append('<option>' + i + '</option>')
	} 
	//years
	var now = new Date();
	var yr = now.getFullYear();
	for(var i = yr; i >= 1930; i--)
	{
		$j('.yearselect').append('<option>' + i + '</option>')
	} 
	
	// setup menu and panels
	if($j('body').attr('id') == "individual-and-family") //individual
	{
		$j('#nm_5 a').addClass("selected");
		$j('#form_5').show();
		
	}
	else if($j('body').attr('id') == "group-plans")
	{
		$j('#nm_6 a').addClass("selected");
		$j('#form_6').show();
		
		 
	}
	else if($j('body').attr('id') == "short-term-medical")
	{
		$j('#nm_7 a').addClass("selected");
		$j('#form_7').show();
		
		
	}
		else if($j('body').attr('id') == "medicare-plans")
	{
		$j('#nm_8 a').addClass("selected");
		$j('#form_8').show();
		
		
	}

	else
	{
		$j('#nm_5 a').addClass("selected");
		$j('#form_5').show();
		
		
	}
	
	
	
	$j('#nm_5 a').click(function() {
		
		window.location = this.getAttribute('href');
		return false;
		
		/*
		$j('#nm_5 a').addClass("selected");
		$j('#nm_6 a').removeClass("selected");
		$j('#nm_7 a').removeClass("selected");
		$j('#nm_8 a').removeClass("selected");
		$j('#msg').html('');
		$j('#thankyou_message').html('');
		// hide all forms
		$j('.quoteform').hide();

		$j('#form_5').show();
		
		return false;
		*/
	});
	
	$j('#nm_6 a').click(function() {
		/*
		$j('#nm_5 a').removeClass("selected");
		$j('#nm_6 a').addClass("selected");
		$j('#nm_7 a').removeClass("selected");
		$j('#nm_8 a').removeClass("selected");
		$j('#msg').html('');
		$j('#thankyou_message').html('');
		
		// hide all forms
		$j('.quoteform').hide();

		$j('#form_6').show();
		return false;
		*/
		
		window.location = this.getAttribute('href');

		return false;
		
	});
	
	$j('#nm_7 a').click(function() {
		/*
		$j('#nm_5 a').removeClass("selected");
		$j('#nm_6 a').removeClass("selected");
		$j('#nm_7 a').addClass("selected");
		$j('#nm_8 a').removeClass("selected");
		$j('#msg').html('');
		$j('#thankyou_message').html('');
		
		// hide all forms
		$j('.quoteform').hide();

		$j('#form_7').show();
		return false;
		*/
		window.location = this.getAttribute('href');

		return false;
	});
	
	$j('#nm_8 a').click(function() {
		/*
		$j('#nm_5 a').removeClass("selected");
		$j('#nm_6 a').removeClass("selected");
		$j('#nm_7 a').removeClass("selected");
		$j('#nm_8 a').addClass("selected");
		$j('#msg').html('');
		$j('#thankyou_message').html('');
		
		// hide all forms
		$j('.quoteform').hide();

		$j('#form_8').show();
		return false;
		*/
		window.location = this.getAttribute('href');

		return false;
	});
	
	
	$j('#form_5 a.submit_individual').click(function() {
		
		$j('#waiting').show();
		$j('#form_5').hide();
		
		$j('#validation_individual').html('');
		$j('#validation_individual').hide();

		
		var validation_message = "";
		validation_message = validate_individual_form();
		if(validation_message != "")
		{
			$j('#validation_individual').html(validation_message);
			$j('#validation_individual').show();
			$j('#waiting').hide();
			$j('#form_5').show();
		
			return false;
		}
		
		$j.post("http://bluemoonbenefits.com/wp-content/themes/bluemoonbenefits/quotes.php", 
			$j("#individual_form").serialize(),
			function(data) {
					//alert("data.msg: " + data);
					$j('#waiting').hide();
					$j('#thankyou').show();
					$j('#thankyou_message').html(data);

				},
				"html"
			);
			return false;
		 
	});
	
	$j('#form_6 a.submit_group').click(function() {
		
		$j('#waiting').show();
		$j('#form_6').hide();
		
		$j('#validation_group').html('');
		$j('#validation_group').hide();

		
		var validation_message = "";
		validation_message = validate_group_form();
		if(validation_message != "")
		{
			$j('#validation_group').html(validation_message);
			$j('#validation_group').show();
			$j('#waiting').hide();
			$j('#form_6').show();
		
			return false;
		}
		
		$j.post("http://bluemoonbenefits.com/wp-content/themes/bluemoonbenefits/quotes.php", 
			$j("#group_form").serialize(),
			function(data) {
					//alert("data.msg: " + data);
					$j('#waiting').hide();
					$j('#thankyou').show();
					$j('#thankyou_message').html(data);

				},
				"html"
			);
			return false;
		
	});
	
	$j('#form_7 a.submit_shortterm').click(function() {
		
		$j('#waiting').show();
		$j('#form_7').hide();
		
		$j('#validation_shortterm').html('');
		$j('#validation_shortterm').hide();

		
		var validation_message = "";
		validation_message = validate_shortterm_form();
		if(validation_message != "")
		{
			$j('#validation_shortterm').html(validation_message);
			$j('#validation_shortterm').show();
			$j('#waiting').hide();
			$j('#form_7').show();
		
			return false;
		}
		
		
		$j.post("http://bluemoonbenefits.com/wp-content/themes/bluemoonbenefits/quotes.php", 
			$j("#shortterm_form").serialize(),
			function(data) {
					//alert("data.msg: " + data);
					$j('#waiting').hide();
					$j('#thankyou').show();
					$j('#thankyou_message').html(data);
					
					
				},
				"html"
			);
			
			window.open('http://stmdirector.eassuranthealth.com/STMConsumer/Default.aspx?linkid=34A55C1A88FF8B03');
			return false;
		
	});
	
	$j('#form_8 a.submit_medicare').click(function() {
		
		$j('#waiting').show();
		$j('#form_8').hide();
		
		$j('#validation_medicare').html('');
		$j('#validation_medicare').hide();

		
		var validation_message = "";
		validation_message = validate_medicare_form();
		if(validation_message != "")
		{
			$j('#validation_medicare').html(validation_message);
			$j('#validation_medicare').show();
			$j('#waiting').hide();
			$j('#form_8').show();
		
			return false;
		}
		
		
		$j.post("http://bluemoonbenefits.com/wp-content/themes/bluemoonbenefits/quotes.php", 
			$j("#medicare_form").serialize(),
			function(data) {
					//alert("data.msg: " + data);
					$j('#waiting').hide();
					$j('#thankyou').show();
					$j('#thankyou_message').html(data);

				},
				"html"
			);
			return false;
		
	});
	
	/*
	$j('#form_5').ajaxError(function(event, request, settings) {
  		$j(this).text('Error accessing ' . settings.url);
	});
	*/
	
	$j(document).ajaxError(function(e, xhr, settings, exception) {
		alert('error in: ' + settings.url + ' \\n error: ' + exception + ' \\n status: ' + xhr.status);

	}); 
	
	setupIndividualQuoteForm();

});

function validate_medicare_form()
{
	var msg = new Array();
	var phone_pattern = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
	var email_pattern = /^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4})$/;

	if(($j('#medicare_form #medicarename').val()).length < 1)
	{
		msg.push("Name is a required Field");
		$j('#medicare_form #medicarename').addClass('highlight');
	}
	else
	{
		$j('#medicare_form #medicarename').removeClass('highlight');
	}
	
	if(($j('#medicare_form #medicarephone').val()).length < 1)
	{	
		msg.push("Phone is a required Field");
		$j('#medicare_form #medicarephone').addClass('highlight');
	}
	else if(!phone_pattern.test($j('#medicare_form #medicarephone').val()))
	{
		msg.push("Please enter a valid phone number");
		$j('#medicare_form #medicarephone').addClass('highlight');
	}	
	else
	{
		$j('#medicare_form #medicarephone').removeClass('highlight');
	}
	
	if(($j('#medicare_form #medicareemail').val()).length < 1)
	{	
		msg.push("Email is a required Field");
		$j('#medicare_form #medicareemail').addClass('highlight');
	}
	else if(!email_pattern.test($j('#medicare_form #medicareemail').val()))
	{
		msg.push("Please enter a valid email address");
		$j('#medicare_form #medicareemail').addClass('highlight');
	}	
	else
	{
		$j('#medicare_form #medicareemail').removeClass('highlight');
	}
	
if((($j('#medicare_form #medicare_dob_month').val()).length < 1) || (($j('#medicare_form #medicare_dob_day').val()).length < 1) || (($j('#medicare_form #medicare_dob_year').val()).length < 1))
	{
		msg.push("Date of birth is a required Field");
		$j('#medicare_form #medicare_dob_month').addClass('highlight');
		$j('#medicare_form #medicare_dob_day').addClass('highlight');
		$j('#medicare_form #medicare_dob_year').addClass('highlight');
		
	}
	else
	{
		$j('#medicare_form #medicare_dob_month').removeClass('highlight');
		$j('#medicare_form #medicare_dob_day').removeClass('highlight');
		$j('#medicare_form #medicare_dob_year').removeClass('highlight');
		
	}


	return msg.join('<br />');
}
function validate_shortterm_form()
{
	var msg = new Array();
	var phone_pattern = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
	var email_pattern = /^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4})$/;
	
	if(($j('#shortterm_form #shorttermname').val()).length < 1)
	{
		msg.push("Name is a required Field");
		$j('#shortterm_form #shorttermname').addClass('highlight');
	}
	else
	{
		$j('#shortterm_form #shorttermname').removeClass('highlight');
	}
	
	if(($j('#shortterm_form #shorttermphone').val()).length < 1)
	{	
		msg.push("Phone is a required Field");
		$j('#shortterm_form #shorttermphone').addClass('highlight');
	}
	else if(!phone_pattern.test($j('#shortterm_form #shorttermphone').val()))
	{
		msg.push("Please enter a valid phone number");
		$j('#shortterm_form #shorttermphone').addClass('highlight');
	}	
	else
	{
		$j('#shortterm_form #shorttermphone').removeClass('highlight');
	}
	
	if(($j('#shortterm_form #shorttermemail').val()).length < 1)
	{	
		msg.push("Email is a required Field");
		$j('#shortterm_form #shorttermemail').addClass('highlight');
	}
	else if(!email_pattern.test($j('#shortterm_form #shorttermemail').val()))
	{
		msg.push("Please enter a valid email address");
		$j('#shortterm_form #shorttermemail').addClass('highlight');
	}	
	else
	{
		$j('#shortterm_form #shorttermemail').removeClass('highlight');
	}
	
	
	
	return msg.join('<br />');
}
function validate_group_form()
{
	var msg = new Array();
	var phone_pattern = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
	var email_pattern = /^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4})$/;
	var zip_pattern = /^\d{5}(-\d{4})?$/;
	var num_pattern = /^\d{1,5}$/;
	
	if(($j('#group_form #companyname').val()).length < 1)
	{
		msg.push("Company Name is a required Field");
		$j('#group_form #companyname').addClass('highlight');
	}
	else
	{
		$j('#group_form #companyname').removeClass('highlight');
	}
	
	if(($j('#group_form #companyzip').val()).length < 1)
	{	
		msg.push("Zip code is a required Field");
		$j('#group_form #companyzip').addClass('highlight');
	}
	else if(!zip_pattern.test($j('#group_form #companyzip').val()))
	{
		msg.push("Please enter a valid zip code");
		$j('#group_form #companyzip').addClass('highlight');
	}	
	else
	{
		$j('#group_form #companyzip').removeClass('highlight');
	}
	
	
	if(($j('#group_form #numemployees').val()).length < 1)
	{	
		msg.push("Number of Employees is a required Field");
		$j('#group_form #numemployees').addClass('highlight');
	}
	else if(!num_pattern.test($j('#group_form #numemployees').val()))
	{
		msg.push("Please enter a valid number");
		$j('#group_form #numemployees').addClass('highlight');
	}	
	else
	{
		$j('#group_form #numemployees').removeClass('highlight');
	}
	
	if(($j('#group_form #contactname').val()).length < 1)
	{
		msg.push("Contact Name is a required Field");
		$j('#group_form #contactname').addClass('highlight');
	}
	else
	{
		$j('#group_form #contactname').removeClass('highlight');
	}
	
	if(($j('#group_form #contactphone').val()).length < 1)
	{	
		msg.push("Contact Phone is a required Field");
		$j('#group_form #contactphone').addClass('highlight');
	}
	else if(!phone_pattern.test($j('#group_form #contactphone').val()))
	{
		msg.push("Please enter a valid phone number");
		$j('#group_form #contactphone').addClass('highlight');
	}	
	else
	{
		$j('#group_form #contactphone').removeClass('highlight');
	}
	
	if(($j('#group_form #contactemail').val()).length < 1)
	{	
		msg.push("Contact Email is a required Field");
		$j('#group_form #contactemail').addClass('highlight');
	}
	else if(!email_pattern.test($j('#group_form #contactemail').val()))
	{
		msg.push("Please enter a valid email address");
		$j('#group_form #contactemail').addClass('highlight');
	}	
	else
	{
		$j('#group_form #contactemail').removeClass('highlight');
	}
	
	
	return msg.join('<br />');
}

function validate_individual_form()
{
	var msg = new Array();
	var phone_pattern = /^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/;
	var email_pattern = /^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4})$/;
	var zip_pattern = /^\d{5}(-\d{4})?$/;
	
	if(($j('#individual_form #name').val()).length < 1)
	{
		msg.push("Name is a required Field");
		$j('#individual_form #name').addClass('highlight');
	}
	else
	{
		$j('#individual_form #name').removeClass('highlight');
	}
	
	
	if(($j('#individual_form #phone').val()).length < 1)
	{	
		msg.push("Phone is a required Field");
		$j('#individual_form #phone').addClass('highlight');
	}
	else if(!phone_pattern.test($j('#individual_form #phone').val()))
	{
		msg.push("Please enter a valid phone number");
		$j('#individual_form #phone').addClass('highlight');
	}	
	else
	{
		$j('#individual_form #phone').removeClass('highlight');
	}
	
	if(($j('#individual_form #email').val()).length < 1)
	{	
		msg.push("Email is a required Field");
		$j('#individual_form #email').addClass('highlight');
	}
	else if(!email_pattern.test($j('#individual_form #email').val()))
	{
		msg.push("Please enter a valid email address");
		$j('#individual_form #email').addClass('highlight');
	}	
	else
	{
		$j('#individual_form #email').removeClass('highlight');
	}
	
	if(($j('#individual_form #county').val()).length < 1)
	{
		msg.push("County is a required Field");
		$j('#individual_form #county').addClass('highlight');
	}
	else
	{
		$j('#individual_form #county').removeClass('highlight');
	}
	
	if(($j('#individual_form #zip').val()).length < 1)
	{	
		msg.push("Zip code is a required Field");
		$j('#individual_form #zip').addClass('highlight');
	}
	else if(!zip_pattern.test($j('#individual_form #zip').val()))
	{
		msg.push("Please enter a valid zip code");
		$j('#individual_form #zip').addClass('highlight');
	}	
	else
	{
		$j('#individual_form #zip').removeClass('highlight');
	}
	
	if((($j('#individual_form #dob_month').val()).length < 1) || (($j('#individual_form #dob_day').val()).length < 1) || (($j('#individual_form #dob_year').val()).length < 1))
	{
		msg.push("Date of birth is a required Field");
		$j('#individual_form #dob_month').addClass('highlight');
		$j('#individual_form #dob_day').addClass('highlight');
		$j('#individual_form #dob_year').addClass('highlight');
		
	}
	else
	{
		$j('#individual_form #dob_month').removeClass('highlight');
		$j('#individual_form #dob_day').removeClass('highlight');
		$j('#individual_form #dob_year').removeClass('highlight');
		
	}
	
	if(($j('#individual_form #sex').val()).length < 1)
	{
		msg.push("Sex is a required Field");
		$j('#individual_form #sex').addClass('highlight');
	}
	else
	{
		$j('#individual_form #sex').removeClass('highlight');
	}
	
	return msg.join('<br />');
}
function setupGroupQuoteFrom()
{
	
	
	
}

function setupIndividualQuoteForm()
{
	$j('.child1info').hide();
	$j('.child1link').click(function() {
		$j('.child2link').show();
		$j('.child1info').show();
		return false;
	});
	
	$j('.child2link').hide();
	$j('.child2info').hide();
	$j('.child2link').click(function() {
		$j('.child3link').show();
		$j('.child2info').show();
		return false;
	});
	
	$j('.child3link').hide();
	$j('.child3info').hide();
	$j('.child3link').click(function() {
		$j('.child4link').show();
		$j('.child3info').show();
		return false;
	});
	
	$j('.child4link').hide();
	$j('.child4info').hide();
	$j('.child4link').click(function() {
		$j('.child4info').show();
		return false;
	});
	
	
	$j('.spouseinfo').hide();
	
	$j('a.spouselink').click(function() {
		$j('.spouseinfo').toggle();		
		return false;
	});

    
	
}

