function validatePricematch(theForm)
{
  var reason = "";
  
  reason += validateEmpty(theForm.name);
  reason += validateEmail(theForm.email);
  reason += validateEmpty(theForm.manufacturer);
  reason += validateEmpty(theForm.part_number);
  reason += validateEmpty(theForm.product_description);
  reason += validateEmpty(theForm.competitor_price);
  reason += validateEmpty(theForm.competitor_url);
  reason += validateEmpty(theForm.our_price);

  if (reason != "")
  {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

//NO ENTER KEY SUBMIT
function stopRKey(evt)
{
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))
  {
    return false;
  }
}

document.onkeypress = stopRKey; 

//EMPTY FIELDS
function validateEmpty(fld)
{
  var error = "";

  if (fld.value.length == 0)
  {
    if (fld.name == "name")
    {
      fld.style.background = '#fffdd9'; 
      error = "Name is invalid or missing.\n"
    }
    if (fld.name == "manufacturer")
    {
      fld.style.background = '#fffdd9'; 
      error = "Manufacturer is invalid or missing.\n"
    }
    if (fld.name == "part_number")
    {
      fld.style.background = '#fffdd9'; 
      error = "Part Number is invalid or missing.\n"
    }
    if (fld.name == "product_description")
    {
      fld.style.background = '#fffdd9'; 
      error = "Product Description is invalid or missing.\n"
    }
    if (fld.name == "competitor_price")
    {
      fld.style.background = '#fffdd9'; 
      error = "Competitor's Delivered Price is invalid or missing.\n"
    }
    if (fld.name == "competitor_url")
    {
      fld.style.background = '#fffdd9'; 
      error = "Competitor's URL of Product is invalid or missing.\n"
    }
    if (fld.name == "our_price")
    {
      fld.style.background = '#fffdd9'; 
      error = "SuperCarCovers.com's Price is invalid or missing.\n"
    }
  }
  else
  {
    fld.style.background = 'White';
  }
  return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

//EMAIL
function validateEmail(fld)                        // value of field with whitespace trimmed off
{
  var error="";
  var tfld = trim(fld.value);
  var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
  var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

  if (fld.value == "")
  {
    fld.style.background = '#fffdd9';
    error = "Email is invalid or missing.\n"
  }
  else if (!emailFilter.test(tfld))              //test email for illegal characters
  {
    fld.style.background = '#fffdd9';
    error = "Email is invalid or missing.\n"
    fld.focus();
  }
  else if (fld.value.match(illegalChars))
  {
    fld.style.background = '#fffdd9';
    error = "Email contains illegal characters.\n"
    fld.focus();
  }
  else
  {
    fld.style.background = 'White';
  }
  return error;
}