
function validateCode()
{
	// Make sure the browser supports DOM
	if(!document.getElementById)
	{
		alert("We're sorry, but your browser doesn't support the technology required for this.  If you can, please try again using a current version of either Internet Explorer or Firefox.");
		return;
	}
	
	var objFirstName = document.getElementById("CFirstName");
	var objLastName = document.getElementById("CLastName");
	var objEmailAddress = document.getElementById("CEmail");
	var objValidate = document.getElementById("vCode");
	
	if(objFirstName.value.length == 0)
	{
		alert("Please enter your first name.");
		objFirstName.focus();
		return(false);
	}
	
	if(objLastName.value.length == 0)
	{
		alert("Please enter your Last name.");
		objLastName.focus();
		return(false);
	}
	
	// Validate the users email
	if(objEmailAddress.value.length == 0)
	{
		alert("Please enter your email address.");
		objEmailAddress.focus();
		return(false);
	}
	else if(!CheckEmail(objEmailAddress))
	{
		alert("The email address you entered is invalid.  Please try again.");
		objEmailAddress.focus();
		return(false);
	}
	
	
	
	if(objValidate.value.length == 0)
	{
		alert("Please enter the Valdiation Code.");
		objValidate.focus();
		return(false);
	}
	
	
	// Make the AJAX call.
	var callback = 
	{
		success:Validate_HandleAJAXResponse_Success,
		failure:Validate_HandleAJAXResponse_Failure,
		timeout:10000
	}
	
	
	//AJAXEngine_ReturnText("http://www.therabreath.com/ajax/EmailList_Subscribe.aspx", "ActionDefID=" + intActionDefID + "&FollowUpID=" + intFollowUpID + "&FirstName=" + objFirstName.value + "&Email=" + objEmailAddress.value + "&CustomerType=" + strCustomerType + "&AffiliateID=" + strAffiliateID + "&ContainerDivName=" + strContainerDivName + "&WriteCookie=" + bolWriteCookie + "&ButtonName=" + strButtonName, "GET", EmailList_Subscribe_HandleAJAXResponse);
	var objAjax = YAHOO.util.Connect.asyncRequest("GET", "http://www.therabreath.com/ajax/BreathTest_Validate.aspx?VCode=" + objValidate.value, callback);
	//var objAjax = YAHOO.util.Connect.asyncRequest("GET", "ajax_proxy.asp?method=GET&content_type=text&url=" + strAjaxServer + "/ajax/EmailList_Subscribe.aspx&data=ActionDefID=" + intActionDefID + "*FollowUpID=" + intFollowUpID + "*FirstName=" + objFirstName.value + "*Email=" + objEmailAddress.value + "*CustomerType=" + strCustomerType + "*AffiliateID=" + strAffiliateID + "*ContainerDivName=" + strContainerDivName + "*WriteCookie=" + bolWriteCookie + "*ButtonName=" + strButtonName, callback);

//var objValidate = document.getElementById("vCode");
//alert(objValidate.value);

//return(true);
}


var Validate_HandleAJAXResponse_Success = function(obj)
{
    if (obj.responseText == "Passed")
	  {
	    document.getElementById("breathtest").submit();
	  }
	 else
	  { 
	    alert("You did not enter the correct validation Code, Please Try Again.");
	    return(false);
	  }
	        
}


var Validate_HandleAJAXResponse_Failure = function(obj)
{
	alert("We're sorry, but something went wrong and we did not receive your Breath Test.  Please Try Again.");

	return(false);
}


function CheckEmail(e)
{
	var pattern = /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/;
	
	if(pattern.exec(e.value) != null)
		return true;
	else
		return false;
}











 