// validates that the field value string has one or more characters in it
function isNotEmpty(elem) 
{
	var str = elem.value;
	if(str == null || str.length == 0) 
	{
		// field is empty
		// alert("Please fill in the required field.");
		return false;
	} 
	else 
	{
		// not empty
		return true;
	}
}

// validates that the entry is a positive or negative number
function isnumber(elem) 
{
	var str = elem.value;
	var oneDecimal = false;
	var oneChar = 0;
	// make sure value hasn't cast to a number data type
	str = str.toString()
	for (var i = 0; i < str.length; i++) 
	{
		oneChar = str.charAt(i).charCodeAt(0);
		// OK for minus sign as first character
		if (oneChar == 45) 
		{
			if (i ==0) 
			{
				continue;
			} 
			else 
			{
				alert ("Only the first character may be a minus sign.");
				return false;
			}
		}
		// OK for one decimal point
		if (oneChar == 46) 
		{
			if (!oneDecimal) 
			{
				oneDecimal = true;
				continue;
			} 
			else 
			{
				alert("Only one decimal is allowed in a number.");
				return false;
			}
		}
		// characters outside of 0 through 9 not OK
		if (oneChar < 48 || oneChar > 57) 
		{
			alert("Enter only numbers into the field.");
			return false;
		}
	}
	return true;
}

// validates that the entry is formatted as an email address
function isEMailAddr(elem) 
{
	try
	{
		var str = elem.value;
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
		
		if (!str.match(re))
		{
			//alert("Verify the address format.");
			return false;
		}
		else
		{
			return true;
		}
	}
	catch (e)
	{
		alert("Caught exception:" + e.message);
		return false;
	}
}

function ValidatorCW(theForm)
{

  var checkOK = "0123456789-.,";
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";

  //.............................................................................................
  // added required field checks
	if (!isNotEmpty(theForm.ConsultName))
	{
		alert("Please enter the Name.");
		theForm.ConsultName.focus();
		return (false);
	}

	if (!isNotEmpty(theForm.ConsultPhone))
	{
		alert("Please enter a Phone Number that we may reach you at.");
		theForm.ConsultPhone.focus();
		return (false);
	}
	
	if (!isNotEmpty(theForm.ConsultEmail))
	{
		alert("Please enter an Email address.");
		theForm.ConsultEmail.focus();
		return (false);
	}
	
	if (!isEMailAddr(theForm.ConsultEmail))
	{
		alert("Please verify the format of the Email address.");
		theForm.ConsultEmail.focus();
		return (false);
	}
	
	if (theForm.top_dealstr.checked == false)
	{  //top_dealstr
	
	 if (theForm.top_dealneg.checked == false)
	    {  //top_dealneg
	    
	    if  (theForm.top_deal3f.checked == false)
	        { //top_deal3f

	        if (theForm.top_brain.checked == false)
	        	{ //top_brain
	        	
	        		if (theForm.top_creative.checked  == false) 
	        		   {  //top_creative
	        		   
	        		   if (theForm.top_other.checked  == false)
	        		   	  {  // top_other
							alert("Please select a topic to be discussed.");
							theForm.top_dealstr.focus();
							return (false);
						  }  // top_other
						  
					   }  // top_creative
					   
				}  // top_brain
				
			} //top_deal3f
			
		} //top_dealneg
		
	} //top_dealstr

	if (!isNotEmpty(theForm.ConsultWhen))
	{
		alert("Please enter when you would like to meet.");
		theForm.ConsultWhen.focus();
		return (false);
	}
	
	if (!isNotEmpty(theForm.ConsultWhere))
	{
		alert("Please enter where you would like to meet.");
		theForm.ConsultWhere.focus();
		return (false);
	}
	
	if (!isNotEmpty(theForm.ConsultTime))
	{
		alert("Please enter what time you would like to meet.");
		theForm.ConsultTime.focus();
		return (false);
	}

	
  // all required fields entered; ok to continue...
  
  //..............................................................................................
  //....data type validations for rest of form go here....
  // nothing else to check really
  
  // if at this point, should be valid; check captcha and return result;
  //return cap_valid(event);
  
  // using reCaptcha in calling form instead; return true at this point;
  return (true);  
  
}
