/************************************************************

  MAVEN CREATIVE | www.wearemaven.com | copyright 2009 

  written/adapted by: Michael Sevilla | michael@wearemaven.com 

  This script requires jQuery and the jQuery Color plugin
  adapted from http://trevordavis.net

  I am sure there is a better way to write this.

***********************************************************/

$(document).ready(function(){
						   
	//clear fields
		$('#emailF').val("");
		
		//set fields
		$('#emailF').example(function() { return $(this).attr('title')});
		
						   
	var startColor = "#2a2a2a";
	var errorColor = "#00a4d3";
	var animateSpeed = 200;
	
	
	var nrf=1; // number of required fields
	
	//set indiv. color vars in required fields array
	var rf=new Array();
	var i=0;
	for (i=0;i<=nrf-1;i++)
	{
		rf[i] =	startColor;
	} 
	
	//reset borders
	function rB(mVar, cc)
	{
		var cVar = rf[cc];
		$(mVar).css("border-color",cVar);
		$(mVar).animate({ borderColor: startColor }, animateSpeed);
		rf[cc] = startColor;
	};
	//set error borders
	function sB(sVar, sc)
	{
		var tVar = rf[sc];
		$(sVar).css("border-color",tVar);
		$(sVar).animate({ borderColor: errorColor }, animateSpeed);
		rf[sc] = errorColor;
	};
	
	$("#join").click(function(){
		
		//required fields
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailVal = $("#email").val();
		if(emailVal == 'Email' || emailVal == '') 
		{
			sB("#nlEmailAd", 0);
			hasError = true;
		} else if(!emailReg.test(emailVal)) {
			sB("#nlEmailAd", 0);
			hasError = true;
		}else{
			rB("#nlEmailAd",0);
		}
		
		
		if(hasError == false) 
		{
			return true;
		}				
		return false;
	});
});