// JavaScript Document

// Check Whole Form 

function checkWholeForm(eNewsletter) 
{    	var why = "";    
	why += checkEmail(eNewsletter.email.value);    
	why += checkname(eNewsletter.name.value);

//  use isEmpty to check for required fields that may have been left empty
//  isEmpty can be used more than once - just copy the why statement and change .notempty. to the name of field to check    
	
	if (why != "") 
		{    
		alert(why);    
		return false;    
		}
	return true;    
}

// email : USE

function checkEmail (strng) 
{	
	var error="";
	if (strng == "") 
	{   
		error = "You didn't enter an email address.\n";
	}    
	var emailFilter=/^.+@.+\..{2,3}$/;    
	if (!(emailFilter.test(strng))) 
	{        
		error = "Please enter a valid email address.\n";    
	}    
	else 
	{
	
	//test email for illegal characters     
  
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/         
		if (strng.match(illegalChars)) 
		{          
			error = "The email address contains illegal characters.\n";       
		}    
	}
	return error;    
}

function checkname (strng)
{	
	var error="";
	if (strng == "") 
	{   
		error = "You didn't enter a Name.\n";
	}    
	return error; 
}

function checkPhone (strng) 
{    
	var error = "";     
	// do not do anything if phone left blank - it is not required    
	if (strng == "") 
	{   
		 return error;     
	}    
	else 
	{
	// check phone number if there is one        
		if (strng == "") 
		{           
			error = "You didn't enter a phone number.\n";        
		}        
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); 
	
	//strip out acceptable non-numeric characters            
	
	if (isNaN(parseInt(stripped))) 
		{            
			error = "The phone number contains illegal characters.";            
		}            

	if (!(stripped.length == 10)) 
		{            
			error = "The phone number is the wrong length. Make sure you included an area code.\n";            
		}     
		return error;    
	}
}

// exactly one radio button is chosen

function checkRadio(checkvalue) 

{
	var error = "";   
	if (!(checkvalue)) 
	{       
	error = "Please check a radio button to tell us if you are a member.\n";    
	}
	return error;
	}

// valid selector from dropdown list

function checkDropdown(choice) 

{
	var error = "";    
	if (choice == 0) 
	{    
	error = "You didn't choose an option from the drop-down list.\n";    
	}    
	return error;
	} 

// non-empty textbox

function isEmpty(strng) 

{
	var error = "";  
	if (strng.length == 0) 
	{     
	error = "The Name field has not been filled in.\n"  
	}
	return error;     
}
