// Newsletter validation

var errorText = "";

// function is calledon submit
function validate()
{
errorText = "Please enter: \n\n";

// shortcut the document.input_form with x
x=document.request

// recieve all the data from the form
firstname=x.firstname.value;
lastname=x.lastname.value;
variety_id=x.variety_id.value;
at=x.email.value.indexOf("@");
country_id=x.country_id.value;

// default the submit action to true
submitOK="True"

  // firstname validation field.
if (firstname.length<1)
 {
  errorText = errorText + "- your first name" + "\n"
  x.firstname.focus()
  submitOK="False"
 }

 // lastname validation field.
if (lastname.length<1)
 {
  errorText = errorText + "- your last name" + "\n"
  x.lastname.focus()
  submitOK="False"
 }
 
// email validation field.
 if (at==-1) 
 {
 errorText = errorText + "- a valid eMail address" + "\n"
 submitOK="False"
 x.email.focus()
 }
 
 // country validation field.
  
 if (country_id==0)
 {
  errorText = errorText + "- your country" + "\n"
  x.country_id.focus()
  submitOK="False"
 }	
  
// Color/Size DropDown.
if (variety_id==0)
 {
  errorText = errorText + "- color/size request" + "\n"
  x.variety_id.focus()
  submitOK="False"
 }
 
if (variety_id==99)
 {
  errorText = errorText + "- THIS ITEM IS SOLD OUT" + "\n"
  x.variety_id.focus()
  submitOK="False"
 }
 
 // if any of the above validation sections have failed show the alert box with the errorText
if (submitOK=="False")
 {
 alert(errorText)
 // return false to stop the form submission
 return false
 }
 return true;
}

