﻿
// Used to clear Email Text Box on Contact Page
function clearEmail()
{
  if (document.getElementById("txtEmail").value == "Please Enter Valid Email Address")
  {
    document.getElementById("txtEmail").value = "";
  }
}

// Validate Contact Form in Contact Topic
function form_validate(theForm)
{
  
  if (theForm.txtFirstName.value == "")
  {
    theForm.txtFirstName.focus();
    theForm.txtFirstName.className = "error";
    return (false);
  }
  else
  {
    theForm.txtFirstName.className = "";
  }
  
  
  if (theForm.txtLastName.value == "")
  {
    theForm.txtLastName.focus();
    theForm.txtLastName.className = "error";
    return (false);
  }
  else
  {
    theForm.txtLastName.className = "";
  }

  if (theForm.txtStreet.value == "") {
    theForm.txtStreet.focus();
    theForm.txtStreet.className = "error";
    return (false);
  }
  else {
    theForm.txtStreet.className = "";
  }

  if (theForm.txtCity.value == "") {
    theForm.txtCity.focus();
    theForm.txtCity.className = "CityTBError";
    return (false);
  }
  else {
    theForm.txtCity.className = "CityTB";
  }

  if (theForm.txtState.value == "") {
    theForm.txtState.focus();
    theForm.txtState.className = "StateTBError";
    return (false);
  }
  else {
    theForm.txtState.className = "StateTB";
  }

  if (theForm.txtZip.value == "") {
    theForm.txtZip.focus();
    theForm.txtZip.className = "error";
    return (false);
  }
  else {
    theForm.txtZip.className = "";
  }

  if (theForm.txtPhone.value == "") {
    theForm.txtPhone.focus();
    theForm.txtPhone.className = "error";
    return (false);
  }
  else {
    theForm.txtPhone.className = "";
  }
  
  if (theForm.txtEmail.value == "")
  {
    theForm.txtEmail.focus();
    theForm.txtEmail.className = "error";
    return (false);
  } 
  else
  {
    theForm.txtEmail.className = "";
  }
  
  if (theForm.txtEmail.value.length <= 3)
  {
    theForm.txtEmail.focus();
    theForm.txtEmail.className = "error";
    theForm.txtEmail.value = "Please Enter Valid Email Address";
    return (false);
  } 
  else
  {
    theForm.txtEmail.className = "";
  }
  
  if (theForm.txtEmail.value.length > 3)
  {
  	if(!email_validate(theForm.txtEmail.value))
  	{
   		theForm.txtEmail.focus();
    	theForm.txtEmail.className = "error";
    	theForm.txtEmail.value = "Please Enter Valid Email Address";
    	return (false);
    }
    else
    {
      theForm.txtEmail.className = "";
    }
  } 
  
  return (true);
  
}

// Validate Email Address
function email_validate(e)
{
	accept = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++)
	{
		if(accept.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}       
	} 

	if (document.images)
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two))
		{
			return (-1);            
		} 
	}
}


