// Form validation and submission functions
// REQUIRES: formHelper.js

// To set up validation for a for a form that detects ENTER keypresses
// within text (not textarea) and password input fields, add a SCRIPT
// block at the end of your HTML just inside the closing BODY tag similar to:
/*
	<script type="text/javascript">
	<!--
	// Set up event handlers for keypresses in text form fields
	//   formKeyCapture() is defined in formHelper.js
	//   validateForm() is defined in validation.js
	formKeyCapture('frmForm1', validateForm);
	formKeyCapture('frmForm2', validateForm);
	//-->
	</script>
*/
// Then add the "onsubmit" and "autocomplete" attributes to each form to be
// validated, configured as follows:
//    onsubmit="return validate(this)" autocomplete="off"
//
// You can set up as many forms as you like in this manner.
//
// Write one validation function for each form to be validated.
// The function signature must be: "validate_<FORMNAME>(frm, bShowErrors, bSubmit)"
// where <FORMNAME> is replaced by the value of the "name" attribute
// on the appropriate form.
//


// Constants
var ERROR_SUMMARY_HEADING = 'Please correct the following errors:';
var CONFIRM_PROGRAM_OPT_OUT = 'Are you sure you wish to cancel your enrollment in this program?\nYou cannot enroll again without talking to a Purina® administrator.';

// Set up event handler for when a key is pressed in a text form field.
// This function will attempt to execute a validation function with the
// signature: "validate_<FORMNAME>(object, bool, bool)"
// where <FORMNAME> is replaced by the value of the "name" attribute on
// the appropriate form.
function validateForm(evt) {
	var valid = true;

	// Set bShowErrors to true for IE since Gecko will do a form submit on enter
	// press automatically and invoke the onsubmit handler of the form.
	var bShowErrors = (window.event);
	var bSubmit = true;
	var src = (window.event) ? evt.srcElement : evt.target;

	if (checkEnterPressed(evt)) {
		var valid = eval('validate_' + src.form.name + '(src.form, bShowErrors, bSubmit)');
		src.focus();
	}

	return valid;
}

// Activates a form validation for the onsubmit handler of a form
function validate(frm) {
	return eval('validate_' + frm.name + '(frm, true, false)');
}

// Complete the validation process by:
//   - Printing an error summary (if desired)
//   - Submit the form automatically (if desired)
function completeValidation(frm, title, msg, bShowErrors, bSubmit) {
	var valid = (msg.length == 0);
	if (!valid) { if (bShowErrors) { alert(((title.length > 0) ? title + '\n\n' : '') + ERROR_SUMMARY_HEADING + '\n\n' + msg); } }
	if (bSubmit && valid) { frm.submit(); }
	return valid;
}


//---------------------------------------------------------------------------------------
//  CUSTOM VALIDATION FUNCTIONS
//---------------------------------------------------------------------------------------

function validate_frmInterest(frm, bShowErrors, bSubmit) {
	var blnInterest = frm.elements['chkInterest'].checked;
	var blnContract = frm.elements['chkFoodContract'].checked;
	var foodContract = frm.elements['drpFoodContract'].value;
	var msg = '';
	msg += (!blnInterest	? '  - Please select checkbox if you are interested in enrolling in the Pets for Seniors Program.\n'	: '');
	
	if (blnContract)
	{
	  	msg += (foodContract == -1	? '  - Please select which competitive food manufacturer your organization has a contract with.\n'	: '');  
	}
	
	// Complete the validation process
	return completeValidation(frm, 'I\'m Interested Form', msg, bShowErrors, bSubmit);
}
// Validation for Member Login Form
function validate_frmMemberLogin(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var username = frm.elements['txtLoginUsername'].value;
	var password = frm.elements['txtLoginPassword'].value;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(username)	? '  - Username is required.\n'	: '');
	msg += (!checkString(password)	? '  - Password is required.\n'	: '');
	
	if(checkString(username))
		msg += ( !IsValidUserName(username)	? '  - Username is not valid.\n'	: '');
	if (checkString(password))
	{
		if (TrimAll(password).length < 6) { msg += '  - Password must be at least six characters and contain no spaces.\n'; }
		//Leaving this commented out so we can maybe enable it in the future when we're sick of old dumb passwords
		if (!checkPassword(password)) { msg += '  - Password must include both letters and digits (a-z, A-Z, 0-9) without spaces.\n'; }
	}	
	
	// Complete the validation process
	return completeValidation(frm, 'Member Login Form', msg, bShowErrors, bSubmit);
}

// Validation for Register AWO Form
function validate_frmRegisterAwo(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	//Organization Information
	var awoname = frm.elements['txtAwoName'].value;
	var tax1 = frm.elements['txtTaxId1'].value;
	var tax2 = frm.elements['txtTaxId2'].value;
	var street1 = frm.elements['txtStreet1'].value;
	var street2 = frm.elements['txtStreet2'].value;
	var city = frm.elements['txtCity'].value;
	var state = frm.elements['cboState'].value;
	var zip = frm.elements['txtZip'].value;
	var phone1 = frm.elements['txtPhone1'].value;
	var phone2 = frm.elements['txtPhone2'].value;
	var phone3 = frm.elements['txtPhone3'].value;
	var ShippingAddressFalse = frm.elements['chkShipSame'].checked;

	//Organization Leader Information
	var leaderfirstName = frm.elements['txtLeaderFirstName'].value;
	var leaderlastName = frm.elements['txtLeaderLastName'].value;
	var leaderemail = frm.elements['txtLeaderEmail'].value;
	var leaderphone1 = frm.elements['txtLeaderPhone1'].value;
	var leaderphone2 = frm.elements['txtLeaderPhone2'].value;
	var leaderphone3 = frm.elements['txtLeaderPhone3'].value;
	var leadertitle = frm.elements['cboLeaderTitle'].value;
	var otherleadertitle = frm.elements['txtLeaderTitle'].value;
	
	//Username and Password Information
	var username = TrimAll(frm.elements['txtLeaderUsername'].value);
	var password = frm.elements['txtLeaderPassword'].value;
	var passwordConfirm = frm.elements['txtLeaderConfirmPassword'].value;
	var passwordHint = frm.elements['txtLeaderPasswordHint'].value;
	
	var LeaderIsPrimaryFalse = frm.elements['rdoLeaderIsPrimaryFalse'].checked;


	// Validate and create an error summary string
	var msg = '';
	//Organization Information validation
	msg += (!checkString(awoname)	? '  - Organization Name is required.\n'	: '');
	if(checkString(awoname))
	{
		msg += ( !checkSpecialCharacter(awoname)	? '  - Angle brackets are not allowed in organization name.\n'	: '');
		msg += ( !checkDoubleQuotes(awoname)	? '  - Quotation marks are not allowed in organization name.\n'	: '');
		msg += ( IsCharacterFound(awoname,':')	? '  - Colon is not allowed in organization name.\n'	: '');
		msg += ( IsCharacterFound(awoname,'\\')	? '  - Backslash is not allowed in organization name.\n'	: '');
	}
	
	msg += ( (!checkString(tax1) || !checkString(tax2))	? '  - Tax ID or EIN is required.\n'	: '');
	if (checkString(tax1) && checkString(tax2))
		msg += ( !IsValidTaxID(tax1,tax2)	? '  - Enter a valid Tax ID.\n'	: '');
	msg += (!checkString(street1)	? '  - Address is required.\n'	: '');
	if(checkString(street1))
			msg += ( !checkSpecialCharacter(street1)	? '  - Angle brackets are not allowed in street1.\n'	: '');
		
	if(checkString(street2))
		msg += ( !checkSpecialCharacter(street2)	? '  - Angle brackets are not allowed in street2.\n'	: '');	
			
	msg += (!checkString(city)	? '  - City is required.\n'	: '');
	if(checkString(city))
		msg += ( !checkSpecialCharacter(city)	? '  - Angle brackets are not allowed in city.\n'	: '');
	
	msg += (!checkString(state)	? '  - State is required.\n'	: '');
	msg += (!checkString(zip)	? '  - Zip Code is required.\n'	: '');
	if (checkString(zip))
		msg += (!IsZipcode(zip)	? '  - Enter five digit Zip Code.\n'	: '');
	msg += ( !checkPhone(phone1,phone2,phone3)	? '  - Complete phone number of organization is required in the format (###) ###-####.\n'	: '');

    //If the shipping address is not checked, then we go for this too
	if (!ShippingAddressFalse)
	{
	    var shipstreet1 = frm.elements['txtShipStreet1'].value;
	    var shipstreet2 = frm.elements['txtShipStreet2'].value;
	    var shipcity = frm.elements['txtShipCity'].value;
	    var shipstate = frm.elements['cboShipState'].value;
	    var shipzip = frm.elements['txtShipZip'].value;
	    
 	    msg += (!checkString(shipstreet1)	? '  - Shipping Address is required.\n'	: '');
	    if(checkString(shipstreet1))
			    msg += ( !checkSpecialCharacter(shipstreet1)	? '  - Angle brackets are not allowed in the Shipping Address.\n'	: '');
    		
	    if(checkString(shipstreet2))
		    msg += ( !checkSpecialCharacter(shipstreet2)	? '  - Angle brackets are not allowed in the Shipping Address.\n'	: '');	
    			
	    msg += (!checkString(shipcity)	? '  - Shipping Address City is required.\n'	: '');
	    if(checkString(shipcity))
		    msg += ( !checkSpecialCharacter(shipcity)	? '  - Angle brackets are not allowed in city.\n'	: '');
    	
	    msg += (!checkString(shipstate)	? '  - Shipping Address State is required.\n'	: '');
	    msg += (!checkString(shipzip)	? '  - Shipping Address Zip Code is required.\n'	: '');
	    if (checkString(shipzip))
		    msg += (!IsZipcode(shipzip)	? '  - Enter five digit Zip Code for the Shipping Address.\n'	: '');
   }
	
	//Organization Leader Information validation
	msg += (!checkString(leaderfirstName)	? '  - First name is required.\n'	: '');
	if(checkString(leaderfirstName))
	{
		msg += ( !checkSpecialCharacter(leaderfirstName)	? '  - Angle brackets are not allowed in first name.\n'	: '');
		msg += ( !checkDoubleQuotes(leaderfirstName)	? '  - Quotation marks are not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(leaderfirstName,':')	? '  - Colon is not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(leaderfirstName,'\\')	? '  - Backslash is not allowed in first name.\n'	: '');
	}
	
	msg += (!checkString(leaderlastName)	? '  - Last name is required.\n'	: '');
	if(checkString(leaderlastName))
	{
		msg += ( !checkSpecialCharacter(leaderlastName)	? '  - Angle brackets are not allowed in last name.\n'	: '');
		msg += ( !checkDoubleQuotes(leaderlastName)	? '  - Quotation marks are not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(leaderlastName,':')	? '  - Colon is not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(leaderlastName,'\\')	? '  - Backslash is not allowed in last name.\n'	: '');
	}
	
	msg += (!checkString(leaderemail)	? '  - E-Mail is required.\n'	: '');
	if (checkString(leaderemail))
		msg += (!checkEmail(leaderemail)	? '  - Correct e-mail address (username@domain.com).\n'	: '');
	msg += ( !checkPhone(leaderphone1,leaderphone2,leaderphone3)	? '  - Complete phone number of Contact is required in the format (###) ###-####.\n'	: '');
	msg += (checkTitle(leadertitle,otherleadertitle)	? '  - Title is required.\n'	: '');
	if(checkString(otherleadertitle))
		msg += ( !checkSpecialCharacter(otherleadertitle)	? '  - Angle brackets are not allowed in title.\n'	: '');
	
	//msg += (!checkString(leadertitle) || (compareStrings(leadertitle,"Other",true) && !checkString(otherleadertitle))	? '  - Title is required.\n'	: '');

	//Username and Password Information validation
	msg += (!checkString(username)	? '  - Username is required.\n'	: '');
	if (checkString(username))
	{
		msg += ( !checkSpecialCharacter(username)	? '  - Angle brackets are not allowed in username.\n'	: '');
		if (!IsValidUserName(username))
			msg += '  - Username is not valid.\n';
	}
	msg += (!checkString(password)	? '  - Password is required.\n'	: '');

	if (checkString(password))
	{
		if (TrimAll(password).length < 6) { msg += '  - Password must be at least six characters and contain no spaces.\n'; }
		if (!checkPassword(password)) { msg += '  - Password must include both letters and digits (a-z, A-Z, 0-9) without spaces.\n'; }
	}
	msg += (!checkString(passwordConfirm)	? '  - Confirm Password is required.\n'	: '');
	if (checkString(password) && checkString(passwordConfirm))
		msg += (!compareStrings(password,passwordConfirm,false)	? '  - Both passwords must match.\n'	: '');
	msg += (!checkString(passwordHint)	? '  - Password Hint is required.\n'	: '');
	if(checkString(passwordHint))
	{
		msg += ( !checkSpecialCharacter(passwordHint)	? '  - Angle brackets are not allowed in password hint.\n'	: '');
		msg += ( !checkDoubleQuotes(passwordHint)	? '  - Quotation marks are not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,':')	? '  - Colon is not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,'\\')	? '  - Backslash is not allowed in password hint.\n'	: '');
	}	
	

	//if the primary contact is other than organization leader
	if (LeaderIsPrimaryFalse)
	{
		var primaryfirstname = frm.elements['txtPrimaryFirstName'].value;
		var primarylastname = frm.elements['txtPrimaryLastName'].value;
		var primaryemail = frm.elements['txtPrimaryEmail'].value;
		var primaryphone1 = frm.elements['txtPrimaryPhone1'].value;
		var primaryphone2 = frm.elements['txtPrimaryPhone2'].value;
		var primaryphone3 = frm.elements['txtPrimaryPhone3'].value;
		var primarytitle = frm.elements['cboPrimaryTitle'].value;
		var otherprimarytitle = frm.elements['txtPrimaryTitle'].value;
		
		var primaryusername = TrimAll(frm.elements['txtPrimaryUsername'].value);
		var primarypassword = frm.elements['txtPrimaryPassword'].value;
		var primaryconfirmpassword = frm.elements['txtPrimaryConfirmPassword'].value;
		var primarypasswordhint = frm.elements['txtPrimaryPasswordHint'].value;
		
		msg += (!checkString(primaryfirstname)	? '  - First name of Primary Contact is required.\n'	: '');
		if(checkString(primaryfirstname))
		{
			msg += ( !checkSpecialCharacter(primaryfirstname)	? '  - Angle brackets are not allowed in first name of Primary Contact.\n'	: '');
			msg += ( !checkDoubleQuotes(primaryfirstname)	? '  - Quotation marks are not allowed in first name of Primary Contact.\n'	: '');
			msg += ( IsCharacterFound(primaryfirstname,':')	? '  - Colon is not allowed in first name of Primary Contact.\n'	: '');
			msg += ( IsCharacterFound(primaryfirstname,'\\')	? '  - Backslash is not allowed in first name of Primary Contact.\n'	: '');
			
		}
		
		msg += (!checkString(primarylastname)	? '  - Last name of Primary Contact is required.\n'	: '');
		if(checkString(primarylastname))
		{
			msg += ( !checkSpecialCharacter(primarylastname)	? '  - Angle brackets are not allowed in last name of Primary Contact.\n'	: '');
			msg += ( !checkDoubleQuotes(primarylastname)	? '  - Quotation marks are not allowed in last name of Primary Contact.\n'	: '');
			msg += ( IsCharacterFound(primarylastname,':')	? '  - Colon is not allowed in last name of Primary Contact.\n'	: '');
			msg += ( IsCharacterFound(primarylastname,'\\')	? '  - Backslash is not allowed in last name of Primary Contact.\n'	: '');
		}
		
		msg += (!checkString(primaryemail)	? '  - E-Mail of Primary Contact is required.\n'	: '');
		if (checkString(primaryemail))
			msg += (!checkEmail(primaryemail)	? '  - Correct e-mail address of Primary Contact (username@domain.com).\n'	: '');
		msg += ( !checkPhone(primaryphone1,primaryphone2,primaryphone3)	? '  - Complete phone number of Primary Contact is required in the format (###) ###-####.\n'	: '');
		msg += (checkTitle(primarytitle,otherprimarytitle)	? '  - Title of Primary Contact is required.\n'	: '');
		if(checkString(otherprimarytitle))
			msg += ( !checkSpecialCharacter(otherprimarytitle)	? '  - Angle brackets are not allowed in title of Primary Contact.\n'	: '');
		
		//Username and Password Information validation

		msg += (!checkString(primaryusername)	? '  - Username of Primary Contact is required.\n'	: '');
		if (checkString(primaryusername))
		{
			msg += ( !checkSpecialCharacter(primaryusername)	? '  - Angle brackets are not allowed in username of Primary Contact.\n'	: '');
			if (!IsValidUserName(primaryusername))
				msg += '  - Username of Primary Contact is not valid.\n';
		}
		msg += (!checkString(primarypassword)	? '  - Password of Primary Contact is required.\n'	: '');

		if (checkString(primarypassword))
		{
			if (TrimAll(primarypassword).length < 6) { msg += '  - Password of Primary Contact must be at least six characters.\n'; }
			if (!checkPassword(primarypassword)) { msg += '  - Password of Primary Contact must include both letters and digits (a-z, A-Z, 0-9) without spaces.\n'; }
		}
		msg += (!checkString(primaryconfirmpassword)	? '  - Confirm Password of Primary Contact is required.\n'	: '');
		if (checkString(primarypassword) && checkString(primaryconfirmpassword))
			msg += (!compareStrings(primarypassword,primaryconfirmpassword,false)	? '  - Both passwords of Primary Contact must match.\n'	: '');
		msg += (!checkString(primarypasswordhint)	? '  - Password Hint of Primary Contact is required.\n'	: '');
		if(checkString(primarypasswordhint))
		{
			msg += ( !checkSpecialCharacter(primarypasswordhint)	? '  - Angle brackets are not allowed in password hint of Primary Contact.\n'	: '');
			msg += ( !checkDoubleQuotes(primarypasswordhint)	? '  - Quotation marks are not allowed in password hint of Primary Contact.\n'	: '');
			msg += ( IsCharacterFound(primarypasswordhint,':')	? '  - Colon is not allowed in password hint of Primary Contact.\n'	: '');
			msg += ( IsCharacterFound(primarypasswordhint,'\\')	? '  - Backslash is not allowed in password hint of Primary Contact.\n'	: '');
			
		}	
		if (checkString(username) && checkString(primaryusername))
			msg += (compareStrings(username,primaryusername,true)	? '  - Organization Leader and Primary Contact username should not be same.\n'	: '');
	}

	// Complete the validation process
	return completeValidation(frm, 'Register Your AWO Form', msg, bShowErrors, bSubmit);
}

// Validation for Update AWO Details Form
function validate_frmUpdateAwo(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var awoname = frm.elements['txtAwoName'].value;
	var tax1 = frm.elements['txtTaxId1'].value;
	var tax2 = frm.elements['txtTaxId2'].value;
	var street1 = frm.elements['txtStreet1'].value;
	var street2 = frm.elements['txtStreet2'].value;
	var city = frm.elements['txtCity'].value;
	var state = frm.elements['cboState'].value;
	var zip = frm.elements['txtZip'].value;
	var shipstreet1 = frm.elements['txtShipStreet1'].value;
	var shipstreet2 = frm.elements['txtShipStreet2'].value;
	var shipcity = frm.elements['txtShipCity'].value;
	var shipstate = frm.elements['cboShipState'].value;
	var shipzip = frm.elements['txtShipZip'].value;

	var phone1 = frm.elements['txtPhone1'].value;
	var phone2 = frm.elements['txtPhone2'].value;
	var phone3 = frm.elements['txtPhone3'].value;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(awoname)	? '  - Organization Name is required.\n'	: '');
	if(checkString(awoname))
	{
		msg += ( !checkSpecialCharacter(awoname)	? '  - Angle brackets are not allowed in organization name.\n'	: '');
		msg += ( !checkDoubleQuotes(awoname)	? '  - Quotation marks are not allowed in organization name.\n'	: '');
		msg += ( IsCharacterFound(awoname,':')	? '  - Colon is not allowed in organization name.\n'	: '');
		msg += ( IsCharacterFound(awoname,'\\')	? '  - Backslash is not allowed in organization name.\n'	: '');
	}
		
	msg += ( (!checkString(tax1) || !checkString(tax2))	? '  - Tax ID or EIN is required.\n'	: '');
	if (checkString(tax1) && checkString(tax2))
		msg += ( !IsValidTaxID(tax1,tax2)	? '  - Enter a valid Tax ID.\n'	: '');
	
	msg += (!checkString(street1)	? '  - Address is required.\n'	: '');
	if(checkString(street1))
		msg += ( !checkSpecialCharacter(street1)	? '  - Angle brackets are not allowed in street1.\n'	: '');
	
	if(checkString(street2))
		msg += ( !checkSpecialCharacter(street2)	? '  - Angle brackets are not allowed in street2.\n'	: '');
	
	msg += (!checkString(city)	? '  - City is required.\n'	: '');
	if(checkString(city))
		msg += ( !checkSpecialCharacter(city)	? '  - Angle brackets are not allowed in city.\n'	: '');
	
	msg += (!checkString(state)	? '  - State is required.\n'	: '');
	msg += (!checkString(zip)	? '  - Zip Code is required.\n'	: '');
	if (checkString(zip))
		msg += (!IsZipcode(zip)	? '  - Enter five digit Zip Code.\n'	: '');

	msg += ( !checkPhone(phone1,phone2,phone3)	? '  - Complete phone number is required in the format (###) ###-####.\n'	: '');

    //Shipping Address
	msg += (!checkString(shipstreet1)	? '  - Shipping Address is required.\n'	: '');
	if(checkString(shipstreet1))
		msg += ( !checkSpecialCharacter(shipstreet1)	? '  - Angle brackets are not allowed in Shipping Address.\n'	: '');
	
	if(checkString(shipstreet2))
		msg += ( !checkSpecialCharacter(shipstreet2)	? '  - Angle brackets are not allowed in Shipping Address.\n'	: '');

	msg += (!checkString(shipcity)	? '  - Shipping Address city is required.\n'	: '');
	if(checkString(shipcity))
		msg += ( !checkSpecialCharacter(shipcity)	? '  - Angle brackets are not allowed in Shipping Address city.\n'	: '');
	
	msg += (!checkString(shipstate)	? '  - Shipping Address State is required.\n'	: '');
	msg += (!checkString(shipzip)	? '  - Shipping Address Zip Code is required.\n'	: '');
	if (checkString(shipzip))
		msg += (!IsZipcode(shipzip)	? '  - Enter five digit Shipping Address Zip Code.\n'	: '');

	// Complete the validation process
	return completeValidation(frm, 'Update AWO Details Form', msg, bShowErrors, bSubmit);
}

// Validation for Forgot Username/Password Form
function validate_frmForgotUsernamePassword(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var email = frm.elements['txtEmail'].value;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(email)	? '  - E-mail is required.\n'	: '');
	if (checkString(email))
		msg += (!checkEmail(email)	? '  - Correct e-mail address (username@domain.com).\n'	: '');

	// Complete the validation process
	return completeValidation(frm, 'Forgot Username/Password Form', msg, bShowErrors, bSubmit);
}

// Validation for Contact Purina Form
function validate_frmContactPurina(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var email = frm.elements['txtEmail'].value;
	var firstName = frm.elements['txtFirstName'].value;
	var lastName = frm.elements['txtLastName'].value;
	var organizationName = frm.elements['txtOrganizationName'].value;
	var comments = frm.elements['txtComments'].value;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(email)	? '  - E-Mail is required.\n'	: '');
	if (checkString(email))
		msg += (!checkEmail(email)	? '  - Correct e-mail address (username@domain.com).\n'	: '');
	msg += (!checkString(firstName)	? '  - First name is required.\n'	: '');
	if(checkString(firstName))
	{
		msg += ( !checkSpecialCharacter(firstName)	? '  - Angle brackets are not allowed in first name.\n'	: '');
		msg += ( !checkDoubleQuotes(firstName)	? '  - Quotation marks are not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstName,':')	? '  - Colon is not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstName,'\\')	? '  - Backslash is not allowed in first name.\n'	: '');
	}
	
	msg += (!checkString(lastName)	? '  - Last name is required.\n'	: '');
	if(checkString(lastName))
	{
		msg += ( !checkSpecialCharacter(lastName)	? '  - Angle brackets are not allowed in last name.\n'	: '');
		msg += ( !checkDoubleQuotes(lastName)	? '  - Quotation marks are not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastName,':')	? '  - Colon is not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastName,'\\')	? '  - Backslash is not allowed in last name.\n'	: '');
	}
	
	if(checkString(organizationName))
	{
		msg += ( !checkSpecialCharacter(organizationName)	? '  - Angle brackets are not allowed in organization name.\n'	: '');
		msg += ( !checkDoubleQuotes(organizationName)	? '  - Quotation marks are not allowed in organization name.\n'	: '');
		msg += ( IsCharacterFound(organizationName,':')	? '  - Colon is not allowed in organization name.\n'	: '');
		msg += ( IsCharacterFound(organizationName,'\\')	? '  - Backslash is not allowed in organization name.\n'	: '');
	}
		
	msg += (!checkString(comments)	? '  - Comments are required.\n'	: '');
	if (comments.length > 5000)
		msg += '  - Please limit your comments to 5000 or fewer characters.';
	if(checkString(comments))
		msg += ( !checkSpecialCharacter(comments)	? '  - Angle brackets are not allowed in comments.\n'	: '');
		
	// Complete the validation process
	return completeValidation(frm, 'Contact Purina Form', msg, bShowErrors, bSubmit);
}

// Validation for Edit User Information Form
function validate_frmUserProfileEdit(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	//var username = frm.elements['txtLoginUsername'].value;

	// Validate and create an error summary string
	var msg = '';
	//msg += (!checkString(username)	? '  - Username is required.\n'	: '');

	// Complete the validation process
	return completeValidation(frm, 'Edit User Information Form', msg, bShowErrors, bSubmit);
}
// Validation for AWO Admin Add/Edit User Information Form
function validate_frmUserAddEdit(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var firstName = frm.elements['txtLeaderFirstName'].value;
	var lastName = frm.elements['txtLeaderLastName'].value;
	var email = frm.elements['txtLeaderEmail'].value;
	var phone1 = frm.elements['txtLeaderPhone1'].value;
	var phone2 = frm.elements['txtLeaderPhone2'].value;
	var phone3 = frm.elements['txtLeaderPhone3'].value;
	var username = frm.elements['txtLeaderUsername'].value;
	var password = frm.elements['txtLeaderPassword'].value;
	var passwordConfirm = frm.elements['txtLeaderConfirmPassword'].value;
	var passwordHint = frm.elements['txtLeaderPasswordHint'].value;

	// Validate and create an error summary string
	
	var msg = '';
	msg += (!checkString(firstName)	? '  - First name is required.\n'	: '');
	if(checkString(firstName))
	{
		msg += ( !checkSpecialCharacter(firstName)	? '  - Angle brackets are not allowed in first name.\n'	: '');
		msg += ( !checkDoubleQuotes(firstName)	? '  - Quotation marks are not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstName,':')	? '  - Colon is not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstName,'\\')	? '  - Backslash is not allowed in first name.\n'	: '');
	}
	
	msg += (!checkString(lastName)	? '  - Last name is required.\n'	: '');
	if(checkString(lastName))
	{
		msg += ( !checkSpecialCharacter(lastName)	? '  - Angle brackets are not allowed in last name.\n'	: '');
		msg += ( !checkDoubleQuotes(lastName)	? '  - Quotation marks are not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastName,':')	? '  - Colon is not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastName,'\\')	? '  - Backslash is not allowed in last name.\n'	: '');
	}
	
	msg += (!checkString(email)	? '  - E-Mail is required.\n'	: '');
	if (checkString(email))
		msg += (!checkEmail(email)	? '  - Correct e-mail address (username@domain.com).\n'	: '');
	msg += ( !checkPhone(phone1,phone2,phone3)	? '  - Complete phone number is required in the format (###) ###-####.\n'	: '');

	msg += (!checkString(username)	? '  - Username is required.\n'	: '');
	if (checkString(username))
	{
		msg += ( !checkSpecialCharacter(username)	? '  - Angle brackets are not allowed in username.\n'	: '');
		
		if (!IsValidUserName(username))
			msg += '  - Username is not valid.\n';
	}
	msg += (!checkString(password)	? '  - Password is required.\n'	: '');

	if (checkString(password))
	{
		if (TrimAll(password).length < 6) { msg += '  - Password must be at least six characters and contain no spaces.\n'; }
		if (!checkPassword(password)) { msg += '  - Password must include both letters and digits (a-z, A-Z, 0-9) without spaces.\n'; }
	}
	msg += (!checkString(passwordConfirm)	? '  - Confirm Password is required.\n'	: '');
	if (checkString(password) && checkString(passwordConfirm))
		msg += (!compareStrings(password,passwordConfirm,false)	? '  - Both passwords must match.\n'	: '');
	msg += (!checkString(passwordHint)	? '  - Password Hint is required.\n'	: '');
	if(checkString(passwordHint))
	{
		msg += ( !checkSpecialCharacter(passwordHint)	? '  - Angle brackets are not allowed in password hint.\n'	: '');
		msg += ( !checkDoubleQuotes(passwordHint)	? '  - Quotation marks are not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,':')	? '  - Colon is not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,'\\')	? '  - Backslash is not allowed in password hint.\n'	: '');
	}	
	

	// Complete the validation process
	return completeValidation(frm, 'Add/Edit User Information Form', msg, bShowErrors, bSubmit);
}

// Validation for Change Password Form
function validate_frmChangePassword(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var password = frm.elements['txtPassword'].value;
	var passwordConfirm = frm.elements['txtPasswordConfirm'].value;
	var passwordHint = frm.elements['txtPasswordHint'].value;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(password)	? '  - New Password is required.\n'	: '');
	if (checkString(password))
	{
		if (TrimAll(password).length < 6) { msg += '  - New Password must be at least six characters and contain no spaces.\n'; }
		if (!checkPassword(password)) { msg += '  - New Password must include both letters and digits (a-z, A-Z, 0-9) without spaces.\n'; }
	}
	msg += (!checkString(passwordConfirm)	? '  - New Password Confirmation is required.\n'	: '');
	if (checkString(password) && checkString(passwordConfirm))
		msg += (!compareStrings(password,passwordConfirm,false)	? '  - Both passwords must match.\n'	: '');
	msg += (!checkString(passwordHint)	? '  - Password Hint is required.\n'	: '');
	if(checkString(passwordHint))
	{
		msg += ( !checkSpecialCharacter(passwordHint)	? '  - Angle brackets are not allowed in password hint.\n'	: '');
		msg += ( !checkDoubleQuotes(passwordHint)	? '  - Quotation marks are not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,':')	? '  - Colon is not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,'\\')	? '  - Backslash is not allowed in password hint.\n'	: '');
	}	
	

	// Complete the validation process
	return completeValidation(frm, 'Change Password Form', msg, bShowErrors, bSubmit);
}

// Validation for AWO Search Form
function validate_frmSearchAwo(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var zip = frm.elements['txtZip'].value;
	var range = frm.elements['cboRange'].value;
	frm.elements['newsearch'].value = 1;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(zip)	? '  - Zip Code is required.\n'	: '');
	if (checkString(zip))
		msg += (!IsZipcode(zip)	? '  - Enter five digit Zip Code.\n'	: '');
	msg += (!checkString(range)	? '  - Select the range within which to search.\n'	: '');


	// Complete the validation process
	var bRetVal =  completeValidation(frm, 'AWO Search Form', msg, bShowErrors, bSubmit);
	
	if(!bRetVal)
	{
		frm.elements['newsearch'].value = 0;
	}
	return bRetVal;
}

//Validation for Admin Profile Edit Form
function validate_frmProfileEdit(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var username = frm.elements['txtUsername'].value;
	var email = frm.elements['txtEmail'].value;
	var phone1 = frm.elements['txtPhone1'].value;
	var phone2 = frm.elements['txtPhone2'].value;
	var phone3 = frm.elements['txtPhone3'].value;
	var firstname = frm.elements['txtFirstName'].value;
	var lastname = frm.elements['txtLastName'].value;
	

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(email)	? '  - E-Mail is required.\n'	: '');
	if (checkString(email))
		msg += (!checkEmail(email)	? '  - Correct e-mail address (username@domain.com).\n'	: '');
		
	msg += ( !checkPhone(phone1,phone2,phone3)	? '  - Complete phone number is required in the format (###) ###-####.\n'	: '');
	
	msg += (!checkString(firstname)	? '  - First Name is required.\n'	: '');
	if(checkString(firstname))
	{
		msg += ( !checkSpecialCharacter(firstname)	? '  - Angle brackets are not allowed in first name.\n'	: '');
		msg += ( !checkDoubleQuotes(firstname)	? '  - Quotation marks are not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstname,':')	? '  - Colon is not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstname,'\\')	? '  - Backslash is not allowed in first name.\n'	: '');
	}
	
	msg += (!checkString(lastname)	? '  - Last Name is required.\n'	: '');
	if(checkString(lastname))
	{
		msg += ( !checkSpecialCharacter(lastname)	? '  - Angle brackets are not allowed in last name.\n'	: '');
		msg += ( !checkDoubleQuotes(lastname)	? '  - Quotation marks are not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastname,':')	? '  - Colon is not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastname,'\\')	? '  - Backslash is not allowed in last name.\n'	: '');
	}
	
	msg += (!checkString(username)	? '  - Username is required.\n'	: '');
	if (checkString(username))
	{
		msg += ( !checkSpecialCharacter(username)	? '  - Angle brackets are not allowed in username.\n'	: '');
		if (!IsValidUserName(username))
			msg += '  - Username is not valid.\n';
	}

	// Complete the validation process
	return completeValidation(frm, 'Edit User Information Form', msg, bShowErrors, bSubmit);
}

// Confirmation for wanting to opt out of a program
function confirmProgramOptOut(chk, enrolled) {
	if (!chk.checked && checkBoolean(enrolled)) { return confirm(CONFIRM_PROGRAM_OPT_OUT); }
	return true;
}

// Validation for Assign Affiliates form
function validate_frmAddWalMart(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var StoreId = frm.elements['txtWalMartId'].value;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(StoreId)	? '  - Wal-Mart® store id is required.\n'	: '');
	msg += (!IsNumericOnly(StoreId) ? '  - Wal-Mart® store id should be numeric.\n'	: '');
	// Complete the validation process
	return completeValidation(frm, 'Assign Affiliates Form', msg, bShowErrors, bSubmit);
}
//frmAddCap
// Validation for Assign cap form
function validate_frmAddCap(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var StoreId = frm.elements['txtWalMartId'].value;

	// Validate and create an error summary string
	var msg = '';
	msg += (!checkString(StoreId)	? '  - Cap value is required.\n'	: '');
	msg += (!IsNumeric(StoreId) ? '  - Cap value should be numeric.\n'	: '');
	// Complete the validation process
	return completeValidation(frm, 'Assign Affiliates Form', msg, bShowErrors, bSubmit);
}

// Validation for AWO Admin Edit User Information Form
function validate_frmUserEdit(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var firstName = frm.elements['txtLeaderFirstName'].value;
	var lastName = frm.elements['txtLeaderLastName'].value;
	var email = frm.elements['txtLeaderEmail'].value;
	var phone1 = frm.elements['txtLeaderPhone1'].value;
	var phone2 = frm.elements['txtLeaderPhone2'].value;
	var phone3 = frm.elements['txtLeaderPhone3'].value;
	var username = frm.elements['txtLeaderUsername'].value;
	var password = frm.elements['txtLeaderPassword'].value;
	var passwordConfirm = frm.elements['txtLeaderConfirmPassword'].value;
	var passwordHint = frm.elements['txtLeaderPasswordHint'].value;

	// Validate and create an error summary string
	
	var msg = '';
	msg += (!checkString(firstName)	? '  - First name is required.\n'	: '');
	if(checkString(firstName))
	{
		msg += ( !checkSpecialCharacter(firstName)	? '  - Angle brackets are not allowed in first name.\n'	: '');
		msg += ( !checkDoubleQuotes(firstName)	? '  - Quotation marks are not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstName,':')	? '  - Colon is not allowed in first name.\n'	: '');
		msg += ( IsCharacterFound(firstName,'\\')	? '  - Backslash is not allowed in first name.\n'	: '');
	}
	
	msg += (!checkString(lastName)	? '  - Last name is required.\n'	: '');
	if(checkString(lastName))
	{
		msg += ( !checkSpecialCharacter(lastName)	? '  - Angle brackets are not allowed in last name.\n'	: '');
		msg += ( !checkDoubleQuotes(lastName)	? '  - Quotation marks are not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastName,':')	? '  - Colon is not allowed in last name.\n'	: '');
		msg += ( IsCharacterFound(lastName,'\\')	? '  - Backslash is not allowed in last name.\n'	: '');
	}
	
	
	msg += (!checkString(email)	? '  - E-Mail is required.\n'	: '');
	if (checkString(email))
		msg += (!checkEmail(email)	? '  - Correct e-mail address (username@domain.com).\n'	: '');
	msg += ( !checkPhone(phone1,phone2,phone3)	? '  - Complete phone number is required in the format (###) ###-####.\n'	: '');

	msg += (!checkString(username)	? '  - Username is required.\n'	: '');
	if (checkString(username))
	{
		msg += ( !checkSpecialCharacter(username)	? '  - Angle brackets are not allowed in username.\n'	: '');
		if (!IsValidUserName(username))
			msg += '  - Username is not valid.\n';
	}

	//msg += (!checkString(password)	? '  - Password is required.\n'	: '');
		
	if(checkString(password))
	{
		if (TrimAll(password).length < 6) { msg += '  - Password must be at least six characters and contain no spaces.\n'; }
		if (!checkPassword(password)) { msg += '  - Password must include both letters and digits (a-z, A-Z, 0-9) without spaces.\n'; }
		msg += (!checkString(passwordConfirm)	? '  - Confirm Password is required.\n'	: '');
	}
	if(checkString(passwordConfirm) && !checkString(password))
	{
		msg += (!checkString(password)	? '  - Password is required.\n'	: '');
	}
	if (checkString(password) && checkString(passwordConfirm))
	{
		msg += (!compareStrings(password,passwordConfirm,false)	? '  - Both passwords must match.\n'	: '');
	}
	
	msg += (!checkString(passwordHint)	? '  - Password Hint is required.\n'	: '');
	
	if(checkString(passwordHint))
	{
		msg += ( !checkSpecialCharacter(passwordHint)	? '  - Angle brackets are not allowed in password hint.\n'	: '');
		msg += ( !checkDoubleQuotes(passwordHint)	? '  - Quotation marks are not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,':')	? '  - Colon is not allowed in password hint.\n'	: '');
		msg += ( IsCharacterFound(passwordHint,'\\')	? '  - Backslash is not allowed in password hint.\n'	: '');
	}	

	// Complete the validation process
	return completeValidation(frm, 'Edit User Information Form', msg, bShowErrors, bSubmit);
}
// Validation for Adoption Survey Information Form
function validate_frmAdoptSurvey(frm, bShowErrors, bSubmit) {
	// Get the values to validate
	var adname = frm.elements['txtAdName'].value;
	var street1 = frm.elements['txtStreet1'].value;
	var city = frm.elements['txtCity'].value;
	var state = frm.elements['cboState'].value;
	var zip = frm.elements['txtZip'].value;
	var phone1 = frm.elements['txtPhone1'].value;
	var phone2 = frm.elements['txtPhone2'].value;
	var phone3 = frm.elements['txtPhone3'].value;
	var adopterage = frm.elements['txtAge'].value;

	var dateday = frm.elements['cboAdoptionDateDay'].value;
	var datemonth = frm.elements['cboAdoptionDateMonth'].value;
	var dateyear = frm.elements['cboAdoptionDateYear'].value;
	
	var discount = frm.elements['rdoDiscount50True'].checked ^ frm.elements['rdoDiscount50TrueFalse'].checked;
	
    /* Not Required Fields */
	var numberdogs = frm.elements['txtCurrentPetDog'].value;
	var numbercats = frm.elements['txtCurrentPetCat'].value;
	var numberother = frm.elements['txtCurrentPets'].value;

	var helpername = frm.elements['txtHelperName'].value;
	var helperstreet = frm.elements['txtHelperStreet1'].value;
	var helpercity = frm.elements['txtHelperCity'].value;
	var helperzip = frm.elements['txtHelperZip'].value;
	var helperphone1 = frm.elements['txtHelperPhone1'].value;
	var helperphone2 = frm.elements['txtHelperPhone2'].value;
	var helperphone3 = frm.elements['txtHelperPhone3'].value;
	
	var originalprice = frm.elements['txtOrgPrice'].value;

	// Validate and create an error summary string
	var msg = '';
	
	//Adoption Application Survey Information validation
	msg += (!checkString(adname)	? '  - Adopter Name is required.\n'	: '');
	if(checkString(adname))
	{
		msg += ( !checkSpecialCharacter(adname)	? '  - Angle brackets are not allowed in Adopter name.\n'	: '');
		msg += ( !checkDoubleQuotes(adname)	? '  - Quotation marks are not allowed in Adopter name.\n'	: '');
		msg += ( IsCharacterFound(adname,':')	? '  - Colon is not allowed in Adopter name.\n'	: '');
		msg += ( IsCharacterFound(adname,'\\')	? '  - Backslash is not allowed in Adopter name.\n'	: '');
	}
	
	msg += (!checkString(street1)	? '  - Address is required.\n'	: '');
	if(checkString(street1))
			msg += ( !checkSpecialCharacter(street1)	? '  - Angle brackets are not allowed in Adopter Street Address.\n'	: '');
	
	msg += (!checkString(city)	? '  - City is required.\n'	: '');
	if(checkString(city))
		msg += ( !checkSpecialCharacter(city)	? '  - Angle brackets are not allowed in city.\n'	: '');

	msg += (!checkString(state)	? '  - State is required.\n'	: '');	
	msg += (!checkString(zip)	? '  - Zip Code is required.\n'	: '');
	if (checkString(zip))
		msg += (!IsZipcode(zip)	? '  - Enter five digit Zip Code.\n'	: '');
	
	msg += ( !checkPhone(phone1,phone2,phone3)	? '  - Complete phone number is required in the format (###) ###-####.\n'	: '');

	if (checkString(adopterage))
	{
	    if (IsNumeric(adopterage))
	        { msg += (adopterage < 1 ? '  - Adopter Age must be greater than 0.\n' : ''); }
	    else
	        { msg +=                   '  - Adopter Age should be numeric.\n'; }
	    
	}
    else
        { msg += '  - Adopter age is required.\n'; }

	if(checkString(numberdogs))
			msg += ( !IsNumeric(numberdogs)	? '  - Number of dogs must be numeric.\n'	: '');
	if(checkString(numbercats))
			msg += ( !IsNumeric(numbercats)	? '  - Number of cats must be numeric.\n'	: '');
	if(checkString(numberother))
			msg += ( !IsNumeric(numberother) ? '  - Number of other pets must be numeric.\n'	: '');

	if(checkString(helpername))
	{
		msg += ( !checkSpecialCharacter(helpername)	? '  - Angle brackets are not allowed in Helper name.\n'	: '');
		msg += ( !checkDoubleQuotes(helpername)	? '  - Quotation marks are not allowed in Helper name.\n'	: '');
		msg += ( IsCharacterFound(helpername,':')	? '  - Colon is not allowed in Helper name.\n'	: '');
		msg += ( IsCharacterFound(helpername,'\\')	? '  - Backslash is not allowed in Helper name.\n'	: '');
	}

	if(checkString(helperstreet))
			msg += ( !checkSpecialCharacter(helperstreet)	? '  - Angle brackets are not allowed in Helper Street Address.\n'	: '');
	
	if(checkString(helpercity))
		msg += ( !checkSpecialCharacter(helpercity)	? '  - Angle brackets are not allowed in Helper Address city.\n'	: '');

	if (checkString(helperzip))
		msg += (!IsZipcode(helperzip)	? '  - Enter five digit Helper Address Zip Code.\n'	: '');

	if(checkString(helperphone1))
			msg += ( !IsNumeric(helperphone1)	? '  - Helper phone number area code must be numeric.\n'	: '');
	if(checkString(helperphone2))
			msg += ( !IsNumeric(helperphone2)	? '  - Helper phone number prefix must be numeric.\n'	: '');
	if(checkString(helperphone3))
			msg += ( !IsNumeric(helperphone3)	? '  - Helper phone number suffix code must be numeric.\n'	: '');

	msg += (datemonth == '-1'	    ? '  - Month of adoption date is required.\n'	: '');
	msg += (dateday == '-1'	        ? '  - Day of adoption date is required.\n'	: '');
	msg += (dateyear == '-1'	    ? '  - Year of adoption date is required.\n'	: '');
	
	if (datemonth != '-1' && dateday != '-1' && dateyear != '-1')
	    msg += (!IsValidDate(dateday,datemonth,dateyear) ? '  - Please select a valid date.\n' : '');

	if (checkString(originalprice))
	    msg += (!IsNumeric(originalprice) ? '  - Organization Adoption Price must be numeric.\n' : '');

	msg += (!discount ? '  - Please choose Yes or No for whether the $50 Discount was given.\n'	: '');

	// Complete the validation process
	return completeValidation(frm, 'Adoption Survey Information Form', msg, bShowErrors, bSubmit);
}

