// Check for the completion of form fields
function IsFormComplete(FormName)
{
	var x       = 0
	var FormOk  = true
	
	while ((x < document.forms[FormName].elements.length) && (FormOk))
	   {
	     if (document.forms[FormName].elements[x].value == '')
	     { 
	        alert('Enter the '+document.forms[FormName].elements[x].name +' and try again.')
	        document.forms[FormName].elements[x].focus()
	        FormOk = false 
	     }
	     x ++
	   }
	return FormOk
	}

// Validate an email address
function IsEmailValid(formfield)
{
var Temp     = formfield
var AtSym    = Temp.value.indexOf('@')
var Period   = Temp.value.lastIndexOf('.')
var Space    = Temp.value.indexOf(' ')
var Length   = Temp.value.length - 1   // Array is from 0 to length-1

if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
      return false;
   }
return true;
}

// Validate a zip code
function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;
var fieldvalue = field.value;

if (fieldvalue.length != 5 && fieldvalue.length != 10) {
	alert("Please enter a 5 digit or 5 digit+4 zip code.");
	return false;
}
for (var i=0; i < fieldvalue.length; i++) {
	temp = "" + fieldvalue.substring(i, i+1);
	if (temp == "-") hyphencount++;
	if (valid.indexOf(temp) == "-1") {
		alert("Invalid characters in your zip code.  Please try again.");
		return false;
	}
	if ((hyphencount > 1) || ((fieldvalue.length==10) && ""+fieldvalue.charAt(5)!="-")) {
		alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
		return false;
   }
}
return true;
}

// Check contact form for completeness and valid entries
function checkContact() {
	if (document.frmContact.txtName.value == "") {
		 alert("Enter a name.");
	     document.frmContact.txtName.focus();
		 return false;
	}
	if (document.frmContact.txtEmail.value == "") {
		 alert("Enter an e-mail address.");
	     document.frmContact.txtEmail.focus();
		 return false;
	}
	if (!IsEmailValid(document.frmContact.txtEmail)) {
		alert("Enter a valid email address.");
     	document.frmContact.txtEmail.focus();
	 	return false;
	}
return true;
}

// Check username request form for completeness and valid entries
function checkUsernameReq() {
	if (document.frmReq.txtEmail.value == "") {
		 alert("Enter an e-mail address.");
	     document.frmReq.txtEmail.focus();
		 return false;
	}
	if (!IsEmailValid(document.frmReq.txtEmail)) {
		alert("Enter a valid email address.");
     	document.frmReq.txtEmail.focus();
	 	return false;
	}
return true;
}

// Check password request form for completeness
function checkPassReq() {
	if (document.frmReq.txtUserName.value == "") {
		 alert("Enter a username.");
	     document.frmReq.txtUserName.focus();
		 return false;
	}
return true;
}
