function validate () 
{
  var divCollection = document.OrderNow.getElementsByTagName("DIV"), 
      item, field, errCollection = new Array(), errMessage = new String, 
	  CRLF = String.fromCharCode(13) + String.fromCharCode(10), 
	  TAB = "\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0", error = 0, code, vFunc, i;
	  
  for (item=0; item<divCollection.length; item++) 
  {
	if (divCollection[item].className == "Required") 
	{
	  field = document.getElementsByName(divCollection[item].id.substr(9)).item(0);
	  code = field.onkeyup;
	  vFunc = code();
	  if (!vFunc(field.value)) 
	  { 
	    error = errCollection.push(divCollection[item].innerHTML); 
	  }
	}
  }
	
  if (errCollection.length) 
  {
    errMessage += "The following fields are required             " + CRLF + CRLF;
	for (item in errCollection) 
	{ 
	  errMessage += TAB + errCollection[item] + CRLF; 
	}
	
	errMessage += CRLF;
    errMessage += "Please fill and resubmit the form.            " + CRLF + CRLF;	
  }

  if (error) 
    alert(errMessage);
  else document.OrderNow.submit();
}

// The verification function
function vText (s) 
{
  return (s.length? true : false);
}


function vEMail (s) 
{
  var regexp = new RegExp, match;
  regexp = /(.+)@(.+)/;	// user@domain
  if (!regexp.test(s)) 
    return false;
  match = regexp.exec(s);
  //atom=[^\s\(\)<>@,;:\\\"\.\[\]]{2,3};
  //word=([^\s\(\)<>@,;:\\\"\.\[\]]+|"[^"]*");
  //user=/word(\.word)*$/;
  //domain=/atom(\.atom)+$/;
  regexp = /([^\s\(\)<>@,;:\\\"\.\[\]]+|"[^"]*")(\.([^\s\(\)<>@,;:\\\"\.\[\]]+|"[^"]*"))*$/; // user
  if (!regexp.test(match[1])) 
    return false; 
  regexp = /[^\s\(\)<>@,;:\\\"\.\[\]]{2,3}(\.[^\s\(\)<>@,;:\\\"\.\[\]]{2,3})+$/; // domain
  if (!regexp.test(match[2])) 
    return false; 
  
  return true;
}


function required (o, vFunc) 
{
  // if o=form then this means the function was called from validate() -return the handling function
  if (typeof(o.value) == "undefined") 
  { 
    return vFunc; 
  }
	
  // else, do the job
  var oDiv = document.getElementById("required_" + o.name), valid = vFunc(o.value);
  
  if (!oDiv) 
    return;
	
  oDiv.style.color = (valid? "black" : "");
  oDiv.style.fontWeight = (valid? "normal" : "");
}
