<!--- hiding

function validateConsumer( TheForm ) 
{
	
	
	var blnRetVal = true;
	var consumer = new UnileverConsumer( TheForm );
	
	consumer.unMark();
	
	
	if( !consumer.isFormBlank() )
	{
		alert("Fields marked in red are required. Please fill.");
		return !blnRetVal;
	}
	
	consumer.fixDataFields( TheForm );
	
	if( !consumer.validateFields() )
	{
		return !blnRetVal;
	}
	return blnRetVal;    
}



function UnileverConsumer(frmName)
{	

	this.defaultFontWeight = 'normal'; 
	this.defaultColor = '#333333';
	this.errorFontWeight = 'bold';
	this.errorColor = '#FF0000';
		
	this.email = eval('document.' + frmName + '.email');
	this.firstname = eval('document.' + frmName + '.firstname');
	this.lastname = eval('document.' + frmName + '.lastname');
	this.address1 = eval('document.' + frmName + '.address1');
	this.addr2 = eval('document.' + frmName + '.addr2');
	this.city = eval('document.' + frmName + '.city');
	this.state = eval('document.' + frmName + '.state');
	this.zip = eval('document.' + frmName + '.zip');
	this.phonedayarea = eval('document.' + frmName + '.phonedayarea');
	this.phoneday1 = eval('document.' + frmName + '.phoneday1');
	this.phoneday2 = eval('document.' + frmName + '.phoneday2');
	this.dayext = eval('document.' + frmName + '.dayext');
	this.phoneevearea = eval('document.' + frmName + '.phoneevearea');
	this.phoneeve1 = eval('document.' + frmName + '.phoneeve1');
	this.phoneeve2 = eval('document.' + frmName + '.phoneeve2');
	this.eveext = eval('document.' + frmName + '.eveext');
	this.month = eval('document.' + frmName + '.month');
	this.day = eval('document.' + frmName + '.day');
	this.year = eval('document.' + frmName + '.year');
	this.upc = eval('document.' + frmName + '.upc');
	this.manufcode = eval('document.' + frmName + '.manufcode');
	this.comment = eval('document.' + frmName + '.comment');
	this.blnFormBlank = false;
	this.isFormBlank = isFormBlank;
	//For address2, phone, etc...
	this.fixDataFields = fixDataFields;
	this.validateFields = validateFields;
	this.checkTextField = checkTextField;
	this.checkDropDownField = checkDropDownField;
	this.unMark = unMark;
	this.mark = mark;
}

function fixDataFields(frmName)
{
	if( Trim( this.addr2.value ) == "" )
		eval('document.' + frmName + '.address2').value = "";
	else
		eval('document.' + frmName + '.address2').value = this.addr2.value;
	
	eval('document.' + frmName + '.dateofbirth').value = this.month[this.month.selectedIndex].value + "/" + this.day[this.day.selectedIndex].value + "/" + this.year[this.year.selectedIndex].value;
	
	eval('document.' + frmName + '.phoneday').value = this.phonedayarea.value.toString() + this.phoneday1.value.toString() + this.phoneday2.value.toString();
	
	eval('document.' + frmName + '.phoneeve').value = this.phoneevearea.value.toString() + this.phoneeve1.value.toString() + this.phoneeve2.value.toString();
}

function mark(elementName)
{
	document.getElementById(elementName).style.fontWeight = this.errorFontWeight;
	document.getElementById(elementName).style.color = this.errorColor;
}

function unMark()
{
	document.getElementById('divemail').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divemail').style.color = this.defaultColor;
	document.getElementById('divfirstname').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divfirstname').style.color = this.defaultColor;
	document.getElementById('divlastname').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divlastname').style.color = this.defaultColor;
	document.getElementById('divaddress').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divaddress').style.color = this.defaultColor;
	document.getElementById('divcity').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divcity').style.color = this.defaultColor;
	document.getElementById('divstate').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divstate').style.color = this.defaultColor;
	document.getElementById('divzip').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divzip').style.color = this.defaultColor;
	document.getElementById('divphone').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divphone').style.color = this.defaultColor;
	document.getElementById('divevephone').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divevephone').style.color = this.defaultColor;
	document.getElementById('divdob').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divdob').style.color = this.defaultColor;
	document.getElementById('divcomment').style.fontWeight = this.defaultFontWeight;
	document.getElementById('divcomment').style.color = this.defaultColor;
	
}

function isFormBlank()
{
	var blnFlag = false;
	var oRegExp = new RegExp(/\S/);
	if( !oRegExp.test(this.email.value) )
	{	
		this.blnFormBlank = true;
		this.mark('divemail');
	}
	if( !oRegExp.test(this.firstname.value) )
	{	
		this.blnFormBlank = true;
		this.mark('divfirstname');
	}
	if( !oRegExp.test(this.lastname.value) )
	{	
		this.blnFormBlank = true;
		this.mark('divlastname');
	}
	if( !oRegExp.test(this.address1.value) )
	{	
		this.blnFormBlank = true;	
		this.mark('divaddress');
	}
	if( !oRegExp.test(this.city.value) )
	{	
		this.blnFormBlank = true;
		this.mark('divcity');
	}
	if( this.state.selectedIndex == 0 )
	{	
		this.blnFormBlank = true;
		this.mark('divstate');
	}
	if( !oRegExp.test(this.zip.value) )
	{	
		this.blnFormBlank = true;
		this.mark('divzip');
	}
	if( (this.day.selectedIndex == 0 ) 
	|| (this.month.selectedIndex == 0 )  
	|| (this.year.selectedIndex == 0 ) )
	{	
		this.blnFormBlank = true;
		this.mark('divdob');
	}
	if( !oRegExp.test(this.comment.value) )
	{	
		this.blnFormBlank = true;
		this.mark('divcomment');
	}
	return !this.blnFormBlank;
}
function checkTextField(sMarkField, sAlert, sField)
{
	this.mark( sMarkField )
	alert( sAlert );
	eval('this.' + sField + '.focus()');
	eval('this.' + sField + '.select()');
	return false;
}
function checkDropDownField(sMarkField, sAlert, sField)
{
	this.mark( sMarkField );
	alert( sAlert );
	eval('this.' + sField + '.focus()');
	return false;
}
function validateFields()
{	
	//validate the email address
	if( !validateEmail( this.email.value ) )
		return this.checkTextField('divemail', 'Enter a valid Email Address', 'email');
	
	//validate the firstname
	if( !validateAlpha( this.firstname.value ) )
		return this.checkTextField('divfirstname', 'Enter First Name with only alpha characters', 'firstname');
	
	//validate the lastname
	if( !validateAlpha( this.lastname.value ) )
		return this.checkTextField('divlastname', 'Enter Last Name with only alpha characters', 'lastname');
	
	//validate the address
	if( !validateAddress1( this.address1.value ) )
		return this.checkTextField('divaddress', 'The following special characters are not allowed for Address < > \" \' % ; ) ( & + - ', 'address1');
	
      if( !validateAddress2( this.addr2.value ) )
		return this.checkTextField('divaddress', 'The following special characters are not allowed for Address < > \" \' % ; ) ( & + - ', 'addr2');
		
	//validate the city
	if( !isValid( this.city.value ) )
		return this.checkTextField('divcity', 'Enter City with only alpha characters', 'city');
	
	//validate the zip code
	if( !validateZip( this.zip.value ) )
		return this.checkTextField('divzip', 'Enter Zipcode with only numerics \nand either 5 or 9 digits', 'zip');
	
	//validate the area code
	if( isNaN( this.phonedayarea.value ) )
		return this.checkTextField('divphone', 'Enter phone number with only numerics', 'phonedayarea');
	
	//validate the phone1
	if( isNaN( this.phoneday1.value ) )
		return this.checkTextField('divphone', 'Enter phone number with only numerics', 'phoneday1');
	
	//validate the phone2
	if( isNaN( this.phoneday2.value ) )
		return this.checkTextField('divphone', 'Enter phone number with only numerics', 'phoneday2');

	//validate the dayext
	if( isNaN( this.dayext.value ) )
		return this.checkTextField('divphone', 'Enter phone ext. with only numerics', 'dayext');

	//validate the Eve area code
	if( isNaN( this.phoneevearea.value ) )
		return this.checkTextField('divevephone', 'Enter evening phone number with only numerics', 'phoneevearea');
	
	//validate the phone1
	if( isNaN( this.phoneeve1.value ) )
		return this.checkTextField('divevephone', 'Enter evening phone number with only numerics', 'phoneeve1');
	
	//validate the phone2
	if( isNaN( this.phoneeve2.value ) )
		return this.checkTextField('divevephone', 'Enter evening phone number with only numerics', 'phoneeve2');

	//validate the eveext
	if( isNaN( this.eveext.value ) )
		return this.checkTextField('divevephone', 'Enter phone ext. with only numerics', 'eveext');			
	
	var iday = this.day[this.day.selectedIndex].value;
	var imonth = this.month[this.month.selectedIndex].value;
	var iyear = this.year[this.year.selectedIndex].value;
	//validate Date Of Birth
	if( !validateDateOfBirth( imonth, iday, iyear ) )
		return this.checkDropDownField('divdob', 'Please enter a valid date of birth', 'day');
	
	//validate Age
	if( !validateAgebyRules( imonth, iday, iyear, 13 ) )
		return this.checkDropDownField('divdob', 'Must be 13 years or old to register', 'day');

	//validate the comment

	if( !validateComment( this.comment.value ) )
		return this.checkTextField('divcomment', 'The following special characters are not allowed for Comment < > \" \' % ; ) ( & + - ', 'comment');


	return true;
}
function validateAlpha(strValue) {
	var blnRetVal = true;
	var strTest = new String(strValue);
	var pattern = new RegExp(/[^a-zA-Z^\-^`^ ^']/);
	var result = strTest.match(pattern);
	if (result)
		blnRetVal = false;
						
	return blnRetVal;
						
}
function validateAddress1(strValue) {
	var blnRetVal = true;
	var strTest = new String(strValue);
	var pattern = new RegExp(/[^a-zA-Z0-9^\-^ ^.]/);
	var result = strTest.match(pattern);
	if (result)
		blnRetVal = false;
						
	return blnRetVal;
						
}
function validateAddress2(strValue) {
	var blnRetVal = true;
	var strTest = new String(strValue);
	var pattern = new RegExp(/[^a-zA-Z0-9^\-^ ^.]/);
	var result = strTest.match(pattern);
	if (result)
		blnRetVal = false;
						
	return blnRetVal;
						
}
function validateComment(strValue) {
	var blnRetVal = true;
	var strTest = new String(strValue);
	var pattern = new RegExp(/\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-/g);
	var result = strTest.match(pattern);
	if (result)
		var blnRetVal = false;

	return blnRetVal;
}						

function validateZip(strValue) {
	var blnRetVal = true;
				
	var strTest = new String(strValue);
	var pattern = new RegExp(/[^0-9^\-]/);
	var result = strTest.match(pattern);
	if (result) 
		blnRetVal = false;
					
	//Check the length of the zip code
	if (blnRetVal == true) {
		if (strTest.length != 0 && strTest.length !=5 && strTest.length !=9) 
		   	blnRetVal = false;
	}
						
	return blnRetVal;
						
}

function validateEmail(strValue)
{

	var oRegExp = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
//	if (oRegExp.test(strValue))
//	{	
//	//proper email address
//	 	return true;
//	}
//	else
//	{	
//	//improper email address
//	 	return false;
//	}

return oRegExp.test(strValue);

//var b=false;
//alert(strValue);
	
}
			
function isValid(strValue) {
	var blnRetVal = true;
	var strTest = new String(strValue);
	var pattern = new RegExp(/[^a-zA-Z^ ^.]/);
	var result = strTest.match(pattern);
	if (result)
		var blnRetVal = false;

	return blnRetVal;
}

function validateAgebyRules(imonth, iday, iyear, iage)
{
	var isValid = true;
	var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var enteredDOB = new Date(iyear.toString() + " " + m_names[imonth - 1].toString() + " " + iday.toString());
	var currentDate = new Date();
	var currentYear = currentDate.getFullYear();
	var currentMonth = currentDate.getMonth();
	var currentDay = currentDate.getDate();
	
	if( ( currentYear - iyear ) < parseInt( iage ) )
		isValid = false;
	if( ( currentYear - iyear ) > parseInt( iage ) )
		isValid = true;
	if( ( currentYear - iyear ) == parseInt( iage ) )
	{	
		if( parseInt( currentMonth  + 1 ) < parseInt( imonth ) )
			isValid = false;
		if( parseInt( currentMonth  + 1 ) > parseInt( imonth ) )
			isValid = true;
		if( parseInt( currentMonth  + 1 ) == parseInt( imonth ) )
		{
			if( parseInt( currentDay  ) < parseInt( iday ) )
				isValid = false;
			if( parseInt( currentDay  ) >= parseInt( iday ) )
				isValid = true;
		}
	}
	return isValid;
}

function validateDateOfBirth(imonth, iday, iyear)
{
  var isValid = true;
  var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
  var enteredDate = new Date(iyear.toString() + " " + m_names[imonth - 1].toString() + " " + iday.toString());
  
  if (enteredDate.getDate() != iday)
  {
    isValid = false;
  }
  return isValid;
}

function Trim(strText)
{
	while(strText.length != 0 && strText.charAt(0) == " ")
	{
		strText=strText.substring(1,strText.length);
	}
	while(strText.length != 0 && strText.charAt(strText.length-1) == " ")
	{
		strText=strText.substring(0,strText.length-1);
	}
	return(strText)
}

// end hiding --->