// JavaScript Document

$(function() {
	
	/*$(".feed_item .feed_preview_date").each(function() {
		var thisDay = parseInt($(this).children(".day").text(), 10);
		var thisMonth = parseInt($(this).children(".month").text(), 10) - 1;
		var thisYear = parseInt($(this).children(".year").text(), 10) + 2000;
		$(this).text($.datepicker.formatDate('M dd, yy', new Date(thisYear,thisMonth,thisDay)));
	});
	
	$(".upcoming-event .upcoming-event-date").each(function() {
		var thisDay = parseInt($(this).children(".ued-day").text(), 10);
		var thisMonth = parseInt($(this).children(".ued-month").text(), 10) - 1;
		var thisYear = parseInt($(this).children(".ued-year").text(), 10);
		$(this).text($.datepicker.formatDate('M dd, yy', new Date(thisYear,thisMonth,thisDay)));
	});*/
	
	/*$(".main-item-hdr").each(function() {
		var aryText = $(this).text().split(" ",2);
		$(this).html($(this).text().replace(aryText[1], "<span>"+aryText[1]+"</span>"));
	});
	
	$("#main-menu > div").each(function() {
		var linky = $(this).find(".feed_preview_title a").attr("href");
		$(this).find(".btn-learn").attr("href",linky);
	});*/

});

function isPhone(strValue) { return /^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?|\.?))[2-9]\d{2}[- \.]?\d{4}$/.test(strValue); } //^\d{3}-\d{3}-\d{4}$
function isEmail(strValue) { return /^[-!#\$%\*\+\/\?\|\^&{}`~\w]+(\.[-!#\$%\*\+\/\?\|\^&{}`~\w]+)*@[-\w]+(\.[-\w]+)+$/.test(strValue); } 
function isZIP(strValue) { return /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(strValue); } 

function validateContact(objForm)
{

	var strReqMsg = "";
	var strValidationMsg = "";
	
	if(objForm.name.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - 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"; }
	
	if(objForm.phone.value.replace(/\s+/g, "") == "")
	{ strReqMsg += "    - Phone\n"; }
	
	if(objForm.phone.value.length && !isPhone(objForm.phone.value))
	{ strValidationMsg += "    - Phone must be in the format xxx-xxx-xxxx\n"; }
	
	if(document.getElementById("interest8").checked)
	{
		if(objForm.interestOther.value.replace(/\s+/g, "") == "")
		{ strReqMsg += "    - What's driving your interest - Other\n"; }
	}
	
	if(document.getElementById("phase8").checked)
	{
		if(objForm.phaseOther.value.replace(/\s+/g, "") == "")
		{ strReqMsg += "    - Current phase of development - Other\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;
	}
}
