
function isAdult(number) {
	if (number.value>17) { return true; } else { return false; }
}


function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

   
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function TooShort(aTextField){
   if ((aTextField.value.length!=12) ||  (aTextField.value==null)) 
   
   {
      return true;
   }
   else { return false; }
 }



function ValidateForm(form)
{

   if (IsEmpty(form.customername)) 
   { 
      alert('Please enter your name') 
      form.customername.focus(); 
      return false; 
   } 
   
   if (IsEmpty(form.phonenumber)) 
   { 
      alert('Please enter a valid phone number with the correct area code\n\nExample: 888-986-5839') 
      form.phonenumber.focus(); 
      return false; 
   }  
   

   if (TooShort(form.phonenumber)) {
   		alert('The phone number has to be entered exactly like this:\nxxx-xxx-xxxx\n\nIn other words:\n[3 digits] [hyphen] [3 digits] [hyphen] [4 digits]');
		form.phonenumber.focus();
		return false;
   }

   if(IsEmpty(form.age)) 
   { 
      alert('Please enter your age') 
      form.age.focus(); 
      return false; 
   }   
   

   if (!isAdult(form.age)) {
      alert('Message to Minors:\n\nWe are very sorry, but we cannot help you ourselves if you are not of age to give permission for your own counseling.  If you can talk to a parent or family member, let them know you are having difficulty and need to speak to someone.  There are mental health centers in nearly any town.  If you go to a church or temple, you can ask your clergyman.  It can also be very helpful to tell a teacher whom you trust, who should then put you in touch with your school counselor.  Sometimes you have to be brave enough just to choose the safest adult you can think of and let them know you need help.  We all need to reach out to someone at various points in our lives.\n\nBest wishes,\nToltex, Inc.'); 
      form.age.focus(); 
      return false; 
   }     
    
	if (!isValidEmail(form.emailaddress.value)) 
   { 
      alert('Please enter a valid e-mail address') 
      form.emailaddress.focus(); 
      return false; 
      }             
      
       
     if(IsEmpty(form.country)) 
   { 
      alert('Please enter what country you are from'); 
      form.country.focus(); 
      return false; 
   }       
      
 
return true;
 
} 
