/***************************************
 *File:						ct_validation.js
 *Purpose:				Generic ONLY form validation scripts.
 *Programmer:			Carl Mudryk
 *History:
 *24 Mar 2005			Initial Release - cmm
 *18 Jan 2006			Copied for PDNet20. - cmm
 *18 Feb 2011			Added VerifyData() for email checking. - cmm
'**************************************
*/

/* verify user password before bothering to send */
function checkEmail(theForm) {
if (document.getElementById('Contact0Email').value != document.getElementById('Contact0_VerifyEmail').value)
	{
	alert('Your email addresses do not match!');
	return false;
	}
	else {
	return true;
	}
}

function VerifyEmail()
	{
	if (document.infusion_xid.Contact0Email.value != document.infusion_xid.Contact0_VerifyEmail.value)
		{
		alert ("Your email addresses do not match - please try again.");
		return false;
		}
	else
		{
		alert ("Your email addresses do not match - please try again.");
		return false;
		}
	}
	
// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {
	var str = elem.value;
	if (str == null || str.length == 0) {
		alert("Please verify that all required fields are filled in.");
		return false;
	} else 	{
		return true;
	}
}

// validates that the entry is formatted as an email address
function isEmailAddr(elem) {
	var str = elem.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (!str.match(re)) {
		alert("Please verify the email address format.");
		elem.focus();
		return false;
	} else {
	}
}

// validates entire form
function validateTrial(form) {
	if (isNotEmpty(form.txtFName)) {
		if (isNotEmpty(form.txtLName)) {
				return true;
		}
	} else {
		return false;
	}
}

// validates entire form
function validateTS(form) {
	if (isNotEmpty(form.txtFName)) {
		if (isNotEmpty(form.txtLName)) {
			if (isNotEmpty(form.txtCompany)) {
				if (isNotEmpty(form.txtEmail)) {
					if (isEmailAddr(form.txtEmail)) {
						return true;
					}
				}
			}
		}
	} else {
		return false;
	}
}

