function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function is_zip(field,alerttxt)
{
var strValidChars = "0123456789";
var strChar;
with (field)
  {
	   if (value.length != 5)
	   { 
		   alert(alerttxt);
		   return false;
	   }
	   for (i = 0; i < value.length; i++)
	      {
	      strChar = value.charAt(i);
	      if (strValidChars.indexOf(strChar) == -1)
	         {
	    	 alert(alerttxt);return false;
	         }
	      }
	   	return true;

  }
}

function validate_email(field,alerttxt)
{
with (field)
  {
	  apos=value.indexOf("@");
	  dotpos=value.lastIndexOf(".");
	  if (apos<1||dotpos-apos<2)
	  {
		  alert(alerttxt);return false;
	  }
	  else 
	  {
		  return true;
	  }
  }
}

function is_areacode(field,alerttxt)
{
var strValidChars = "0123456789";
var strChar;
with (field)
  {
	   if (value.length != 3)
	   { 
		   alert(alerttxt);
		   return false;
	   }
	   for (i = 0; i < value.length; i++)
	      {
	      strChar = value.charAt(i);
	      if (strValidChars.indexOf(strChar) == -1)
	         {
	    	 alert(alerttxt);return false;
	         }
	      }
	   	return true;

  }
}

function is_phonenumber(field,alerttxt)
{
var strValidChars = "0123456789";
var strChar;
with (field)
  {
	   if (value.length != 7)
	   { 
		   alert(alerttxt);
		   return false;
	   }
	   for (i = 0; i < value.length; i++)
	      {
	      strChar = value.charAt(i);
	      if (strValidChars.indexOf(strChar) == -1)
	         {
	    	 alert(alerttxt);return false;
	         }
	      }
	   	return true;

  }
}

function is_match(field1, field2, alerttxt)
{
	if (field1.value != field2.value)
	{
		alert(alerttxt);return false;
	}
}


function validate_newsletter_form(thisform)
{
with (thisform)
  {
  if (newsoptin.checked==false){
	alert("Please check the box to opt into the newsletter.");
	newsoptin.focus();
	return false;
  }
  }
}

function validate_unsubscribe_newsletter_form(thisform)
{
with (thisform)
  {
  if (validate_required(email,"Please enter your Email.")==false)
  {email.focus();return false;}
  if (validate_email(email,"Invalid email format.")==false)
  {email.focus();return false;}
  if (validate_required(confirmemail,"Please confirm your email.")==false)
  {confirmemail.focus();return false;}
  if (is_match(email,confirmemail,"Your email and confirm email do not match.")==false)
  {email.focus();return false;}
  }
}



function validate_application_form(thisform)
{
with (thisform)
  {
  if (validate_required(email,"Please enter your Email.")==false)
  {email.focus();return false;}
  if (validate_email(email,"Invalid email format.")==false)
  {email.focus();return false;}
  if (validate_required(confirmemail,"Please confirm your email.")==false)
  {confirmemail.focus();return false;}
  if (is_match(email,confirmemail,"Your email and confirm email do not match.")==false)
  {email.focus();return false;}
  if (validate_required(firstname,"Please enter your First Name.")==false)
  {firstname.focus();return false;}
  if (validate_required(lastname,"Please enter your Last Name.")==false)
  {lastname.focus();return false;}
  if (validate_required(address1,"Please enter your Address.")==false)
  {address1.focus();return false;}
  if (validate_required(city,"Please enter your City.")==false)
  {city.focus();return false;}
  if (validate_required(state,"Please select your State.")==false)
  {state.focus();return false;}
  if (validate_required(zip,"Please enter your Zip.")==false)
  {zip.focus();return false;}
  if (is_zip(zip,"Invalid zip code.")==false)
  {zip.focus();return false;}
  
  if (validate_required(postitionofinterest,"Please select Position of Interest.")==false)
  {postitionofinterest.focus();return false;}
  if (validate_required(coverletter,"Please enter your cover letter.")==false)
  {coverletter.focus();return false;}
  if (validate_required(resume,"Please enter your Resumé.")==false)
  {resume.focus();return false;}
  }
}

function check_not_equal_to(field, alerttxt, term) {
	with (field) {
		if (value == term) {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}


function validate_search_form(thisform) {
	with (thisform) {
		if (validate_required(query, "Please enter your search criteria.") == false) {
			query.focus();
			return false;
		}
		if (check_not_equal_to(query, "Please enter your search criteria.", "Search Marzetti.com") == false) {
			query.focus();
			return false;
		}
	}
}

function validate_search_recipes_form(thisform) {
	with (thisform) {
		if (validate_required(keywords, "Please enter your search criteria.") == false) {
			keywords.focus();
			return false;
		}
		if (check_not_equal_to(keywords, "Please enter your search criteria.", "Search the Recipe Center") == false) {
			keywords.focus();
			return false;
		}
	}
}