$(document).ready(function() {
	
	$.fn.maxHeight = function() {		
		var maxHt = 0;

		this.each(function() {
			maxHt = Math.max( maxHt, $(this).height() );
		});

		this.each(function() {
			$(this).height(maxHt);
		});
	};

	$(window).load(function() {
		$(".box-row").each(function() {
			$(this).find(".box-con > article").maxHeight();
		});
	});

	
	$(window).resize(function() {
		
		$(".box-row .box-con > article").css("height", "auto");
		
		$(".box-row").each(function() {
			$(this).find(".box-con > article").maxHeight();
		});
		
	});
	
	
	$('.box-con h1, .box-con h2, .box-con h3, .box-con h4, .box-con h5, .box-con h6').fitText(.8);
});

function validateContact(objForm)
{

	var strReqMsg = "";
	var strValidationMsg = "";
	
	if(objForm.name.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - First and Last Name\n"; }
	
	if(objForm.phone.value.length && !isPhone(objForm.phone.value))
	{ strValidationMsg += "    - Phone must be in the format 000-000-0000\n"; }
	
	if(objForm.email.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Email\n"; }
	
	if(objForm.email.value.length && !isEmail(objForm.email.value))
	{ strValidationMsg += "    - Email must be in the format username@domain.com\n"; }
	
	if(objForm.state.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - State\n"; }
		
	// Assemble all of the error messates together to display to the user
	if(strReqMsg.length || strValidationMsg.length)
	{
		var strDisplay = "";
		if(strReqMsg.length)
		{ strDisplay += "The following fields are required to be completed:\n\n" + strReqMsg; }

		if(strValidationMsg.length)
		{ strDisplay += "The following fields are not filled in correctly:\n\n" + strValidationMsg; }

		alert(strDisplay);
		return false;
	}
	else
	{
		return true;
	}
}

function validateFeedback(objForm)
{

	var strReqMsg = "";
	var strValidationMsg = "";
	
	if(objForm.name.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - First and Last Name\n"; }
	
	if(objForm.email.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Email\n"; }
	
	if(objForm.email.value.length && !isEmail(objForm.email.value))
	{ strValidationMsg += "    - Email must be in the format username@domain.com\n"; }
	
	
	// Assemble all of the error messates together to display to the user
	if(strReqMsg.length || strValidationMsg.length)
	{
		var strDisplay = "";
		if(strReqMsg.length)
		{ strDisplay += "The following fields are required to be completed:\n\n" + strReqMsg; }

		if(strValidationMsg.length)
		{ strDisplay += "The following fields are not filled in correctly:\n\n" + strValidationMsg; }

		alert(strDisplay);
		return false;
	}
	else
	{
		return true;
	}
}



function isPhone(strValue) { return /^(?:\([0-9]\d{2}\)\ ?|[0-9]\d{2}(?:\-?|\ ?|\.?))[0-9]\d{2}[- \.]?\d{4}$/.test(strValue); }
function isEmail(strValue) { return /^[-!#\$%\*\+\/\?\|\^&{}`~\w]+(\.[-!#\$%\*\+\/\?\|\^&{}`~\w]+)*@[-\w]+(\.[-\w]+)+$/.test(strValue); } 
function isZIP(strValue) { return /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(strValue); } 
