 
function setFocus(aField) {
document.forms[0][aField].focus();
}





function validateEmail(aTextField,man,db) {
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (document.forms[0][aTextField].value.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<document.forms[0][aTextField].value.length; i++) {
   if (document.forms[0][aTextField].value.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}
var atPos = document.forms[0][aTextField].value.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('Invalid email Address.\n Email address must contain an @');
   return false;
}
if (atPos == 0) {
   if (db) alert('Invalid email Address.\n Email address must not start with @');
   return false;
}
if (document.forms[0][aTextField].value.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('Invalid email Address.\n Email address must contain only one @');
   return false;
}
if (document.forms[0][aTextField].value.indexOf('.', atPos) == -1) {
   if (db) alert('Invalid email Address.\n Email address must contain a period in the domain name');
   return false;
}
if (document.forms[0][aTextField].value.indexOf('@.',0) != -1) {
   if (db) alert('Invalid email Address.\n period must not immediately follow @ in email address');
   return false;
}
if (document.forms[0][aTextField].value.indexOf('.@',0) != -1){
   if (db) alert('Invalid email Address.\n  period must not immediately precede @ in email address');
   return false;
}
if (document.forms[0][aTextField].value.indexOf('..',0) != -1) {
   if (db) alert('Invalid email Address.\n two periods must not be adjacent in email address');
   return false;
}
var suffix = document.forms[0][aTextField].value.substring(document.forms[0][aTextField].value.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('Invalid email Address.\n  invalid primary domain in email address');
   return false;
}
return true;
}





function isAnEmailAddress(aTextField) {
// 1+@3+ [or x@x.x] is as close as we will test

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.forms[0][aTextField].value.length -
 document.forms[0][aTextField].value.indexOf("@") < 4) {
return false;
}else if (document.forms[0][aTextField].value.lastindexOf(".") < document.forms[0][aTextField].value.indexOf("@")) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) ||
 (document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}

function validate() {
// will return true or false
// Step 1: check that required fields are
// filled in, alert and exit without
// submitting if not

// check that the name field is valued
if (isEmpty("feedback_subject")) {
	alert("Please enter subject.");
	setFocus("feedback_subject");
	return false;
}

// check that the name field is valued
if (isEmpty("fullname")) {
	alert("Please enter your name.");
	setFocus("fullname");
	return false;
}

// check that the enclavename field is valued
/*if (isEmpty("enclavename")) {
	alert("Please enter your Enclave name.");
	setFocus("enclavename");
	return false;
}*/

// check that the enclaveuserid field is valued
/*if (isEmpty("enclaveuserid")) {
	alert("Please enter your Enclave login name.");
	setFocus("enclaveuserid");
	return false;
}*/

// check that the email field is valued
if (isEmpty("emailaddress")) {
	alert("Please enter email address.");
	setFocus("emailaddress");
	return false;
}

// Step 2: check that the email address is
// even close, alert and exit without
// submitting if not
if (!validateEmail("emailaddress",1,1)) {
	
	setFocus("emailaddress");
	return false;
}



// check that the feedback_desc field is valued
if (isEmpty("feedback_desc")) {
	alert("Please enter feedback description.");
	setFocus("feedback_desc");
	return false;
}
// Step 2: check that the email address is
// even close, alert and exit without
// submitting if not
if (!validateEmail("emailaddress")) {	
	alert("Please enter valid email address.");
	setFocus("emailaddress");
	return false;
}


// if we get this far everthing is ok, so
// let the form submit
return true;

}
  

