function validateEmailAddress (inEmail) {
	var okEmail;
	var locAt = inEmail.indexOf("@");
	var emailsize=inEmail.length;
	var locPeriod = inEmail.lastIndexOf(".");
	var firstdot=inEmail.indexOf(".");

	if ( ( firstdot == -1) || (firstdot == locAt-1) || (firstdot == locAt+1) || (firstdot == 0)) {
 		return false;
	}

  	var prevdot = firstdot;
	for (var i=(firstdot+1);i < (inEmail.length -1);i++) {
		var curchar =inEmail.charAt(i);
		if ( (curchar == ".") && (i == prevdot+1) ) {
			return false;
		}

		if ( curchar == "." ) {
			prevdot = i;
		}
	}

	// there cannot be more than one @ sign and it cannot be the first letter and
	// last letter in the email address. Also, there has to be an @ sign in email.
	// there should be atleast two letters after the dot and there should be a dot
	// after the @ sign but should have text between @ and dot sign also.]

	okEmail = ((locAt != -1) && (locAt != 0) && (locAt != (inEmail.length - 1)) &&
             (inEmail.indexOf("@", (locAt + 1)) == -1) &&
             ( (locPeriod == (inEmail.length - 3)) ||
			 (locPeriod == (inEmail.length - 4))) &&
             (locPeriod > locAt)
	);

	return okEmail;
}


// This validates email form. All the fields on the form are required.
// If there are errors then the fields are focus and highlighted for the browsers
// that have javascript enabled and versions greater than 3.
// Once the data passes the validation, target window is open and the email is
// and a Thank you message is displayed to the user.

function validateStandardEmailForm (emailForm) {
	if (!validateEmailAddress(emailForm.email.value)) {
		alert("You must enter a valid email address.");
		emailForm.email.focus();
		emailForm.email.select();
		return false;
        }

	return true;
}


// This validates email form. Any fields listed in a form
// field named "required" are required.

function validateEmailForm (emailForm) {
	if (emailForm.required && emailForm.required.value != "") {
		var reqFields = emailForm.required.value.split(",");

		for (var i=0; i<reqFields.length; i++) {
			var fname = reqFields[i];

			// Strip whitespace
			while (fname.length > 0 && fname.charAt(0) == " ") {
				fname = fname.substring(1);
			}
			while (fname.length > 0 && fname.charAt(fname.length - 1) == " ") {
				fname = fname.substring(0, fname.length - 1);
			}

			if (emailForm[fname]) {
				var f = emailForm[fname];
				var isEmpty = false;

				if (f.type == 'text' || f.type == 'textarea' || f.type == 'password') {
					if (f.value == '') {
						isEmpty = true;
					}
				} else if (f.type == 'checkbox') {
					if (!f.checked) {
						isEmpty = true;
					}
				} else if (f.type == 'select-multiple') {
					if (f.selectedIndex < 0) {
						isEmpty = true;
					}
				} else if (f.type == 'select' || f.type == 'select-one') {
					if (f.selectedIndex < 0 || f.options[f.selectedIndex].value ==  '') {
						isEmpty = true;
					}
				} else if (!f.type) {
					// Assume the object is an array of radio buttons
					isEmpty = true;
					for (var j=0; j<f.length; j++) {
						if (f[j].checked) {
							isEmpty = false;
							break;
						}
					}

					// radio buttons cannot be focused.
					f = null;
				}

				if (isEmpty) {
					alert("You must provide a value for " + fname + ".");
					if (f != null) {
						if (f.focus) {
							f.focus();
						}
						if (f.select) {
							f.select();
						}
					}
					return false;
				}
			}
		}
	}

	var retval = true;
	if (emailForm.validate && emailForm.validate.value != '') {
		retval = eval(emailForm.validate.value + '(emailForm)');
	}

	if (retval == true && !(emailForm.redirect && emailForm.redirect.value != "")) {
		msgWindow = window.open("", "SendEmailWindoid","height=300,width=326,resizable=1");
		emailForm.target = "SendEmailWindoid";

		// Copy fields to hidden fields.
		for (var i=0; i<emailForm.length; i++) {
			var f = emailForm.elements[i];
			if (f.type == 'hidden' && f.name.substring(0, 2) == 'i_') {
				var nonHidden = emailForm.elements[f.name.substring(2)];
				if (nonHidden != null) {
					f.value = nonHidden.value;
					nonHidden.value = '';
				}
			}
		}
	}

	return retval;
}
