// This function selects all text in a given form element to allow
// easier user correction of erroneous fields

function highlight(elem) {
	elem.blur();
	elem.focus();
	elem.select();
}

// are regular expressions supported? If so, we can do some better
// validation of email address formats
var reSupported = 0;
if (window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) reSupported = 1;
}

// Validate the format of an email address. NB: whether an email address
// actually exists or not cannot be validated here.

function validateEmail(str) {
  if (!reSupported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

