<!--

getFormErrors = function (form) {
	var errors = new Array();
	for (var e = 0; e < form.elements.length; e++) {
		var elem = form.elements[e];
		// text and textarea types
		if (elem.type == "text" || elem.type == "textarea") {
			elem.value = trimWhitespace(elem.value)
			if (elem.required  && elem.value == '') {errors[errors.length] = elem.requiredError; setErrorStyle(elem,'#FFFFCC');} //switchErrorImg(elem.requiredImgError);}
			else if (elem.maxlength && isValidLen(elem.value, 0, elem.maxlength) == false) {errors[errors.length] = elem.maxlengthError; setErrorStyle(elem,'#FFFFCC'); }//switchErrorImg(elem.requiredImgError);}
			else if (elem.minlength && isValidLen(elem.value, elem.minlength, Number.MAX_VALUE) == false) {errors[errors.length] = elem.minlengthError; setErrorStyle(elem,'#FFFFCC');} //switchErrorImg(elem.requiredImgError);}
			// pattern (credit card number, email address, zip or postal code, alphanumeric, numeric)
			else if (elem.illegalChars && illegalChars(elem.value) == false) {errors[errors.length] = elem.illegalCharsError; setErrorStyle(elem,'#FFFFCC');} //switchErrorImg(elem.requiredImgError);}
			else if (elem.pat) {
				if ( (elem.pat.toLowerCase() == 'email' && isValidEmail(elem.value) == false) || (elem.pat.toLowerCase() == 'zip or postal code' && isValidZip(elem.value, form) == false && isValidPostal(elem.value, form) == false) || (elem.pat.toLowerCase() == 'alphanumeric' && isAlphanum(elem.value, true) == false) || (elem.pat.toLowerCase() == 'numeric' && isNum(elem.value, true) == false) || (elem.pat.toLowerCase() == 'alphabetic' && isAlpha(elem.value, true) == false) )  {
					errors[errors.length] = elem.patError; setErrorStyle(elem,'#FFFFCC');// switchErrorImg(elem.requiredImgError);
				}
				else if (elem.match && matchPat(elem.value, elem.matchComp) == false) {errors[errors.length] = elem.matchError; setErrorStyle(elem,'#FFFFCC');} //switchErrorImg(elem.requiredImgError);}
			}
		}
		else if (elem.type == "password") {
			if (elem.required  && elem.value == '') {errors[errors.length] = elem.requiredError; setErrorStyle(elem,'#FFFFCC');}
			else if (elem.max && isValidLen(elem.value, 0, elem.maxlength) == false) {errors[errors.length] = elem.maxLengthError; setErrorStyle(elem,'#FFFFCC');}// switchErrorImg(elem.requiredImgError);}
			else if (elem.min && isValidLen(elem.value, elem.minlength, Number.MAX_VALUE) == false) {errors[errors.length] = elem.minLengthError; setErrorStyle(elem,'#FFFFCC');} //switchErrorImg(elem.requiredImgError);}
		}
		else if (elem.type == "select-one" || elem.type == "select-multiple" || elem.type == "select") {
			if (elem.required && elem.selectedIndex == -1) {errors[errors.length] = elem.requiredError; setErrorStyle(elem,'#FFFFCC');}// switchErrorImg(elem.requiredImgError);}
			else if (elem.noEmptyVal && elem.options[elem.selectedIndex].value == '') {errors[errors.length] = elem.noEmptyValError; setErrorStyle(elem,'#FFFFCC');}// switchErrorImg(elem.requiredImgError);}
		}
		else if (elem.type == "radio") {
			var radiogroup = form.elements[elem.name];
			if (radiogroup.required && radiogroup.length) {
				var checkedRadioButton = -1;
				for (var radioIndex = 0; radioIndex < radiogroup.length; radioIndex++) {
					if (radiogroup[radioIndex].checked == true) {
						checkedRadioButton = radioIndex;
						break;
					}
				}
				if (checkedRadioButton == -1 && !radiogroup.tested) {
					errors[errors.length] = radiogroup.requiredError; setErrorStyle(elem,'#FFFFCC');// switchErrorImg(elem.requiredImgError);
					radiogroup.tested = true;
				}
			}
			radiogroup = null;
		}
	}
	return errors;
}; // close getFormErrors();

// Remove all commas from a string
removeCommas = function (str) {
	var newStr1 = '';
	for (var i = 0; i < str.length; i++) {
		if (str.charAt(i) != ',') newStr1 += str.charAt(i);
	}
	return newStr1;
};  //close removeSpaces();

// Returns a checksum digit for a number using mod 10
getMod10 = function (num) {
	// returns -1 for illegal input
	num = '' + num;
	num = removeSpaces(num);
	if (!isNum(num)) return -1;
	var checksum = 0;
	for (var i = num.length - 1; i >= 0; i--) {
		var isOdd = ((num.length - i) % 2 != 0) ? true : false;
		digit = number.charAt(i);
		if (isOdd) checksum += parseInt(digit);
		else {
			var evenDigit = parseInt(digit) * 2;
			if (evenDigit >= 10) checksum += 1 + (evenDigit - 10);
			else checksum += evenDigit;
		}
	}
	return (checksum % 10);
}; // close getMod10();

validate = function (form) {
	for (var e = 0; e < form.elements.length; e++) {
		var elem = form.elements[e];
		if (elem.type != "checkbox")
		{ 
			setErrorStyle(elem,'#FFFFFF');
		}
	}
	
	//form.combinedDate.value = document.signUp.bMonth.value+"/"+document.signUp.bYear.value;
	
	var req = new Array('req1','req2','req3','req4');
	for (var i = 0; i < req.length; i++) {
		var img = req[i];
		switchErrorImg(img,'reset');
	}
	
	form.email.pat = 'email';
	form.email.patError = 'Please enter a valid e-mail address\n';
	form.email.required = true;
	form.email.requiredError = 'Please enter an e-mail address\n';
	form.email.illegalChars = true;
	form.email.illegalCharsError = 'Please enter a valid e-mail address\n';
	form.email.match = true;
	form.email.matchComp = form.email2.value;
	form.email.matchError = 'Please enter identical e-mail addresses\n';
	form.email.requiredImgError = 'req1';
	
	form.email2.pat = 'email';
	form.email2.patError = 'Please confirm your e-mail with a correct address\n';
	form.email2.required = true;
	form.email2.requiredError = 'Please confirm your e-mail address\n';
	form.email2.illegalChars = true;
	form.email2.illegalCharsError = 'Please confirm your e-mail with an address containing standard characters only\n';
	form.email2.requiredImgError = 'req2';
	
	form.bMonth.required = true;
	form.bMonth.noEmptyVal = true;
	form.bMonth.requiredImgError = 'req3';
	
	form.bYear.required = true;
	form.bYear.noEmptyVal = true;
	form.bYear.requiredImgError = 'req4';
	
	var errors = getFormErrors(form);
	var chDt = CheckDate();
	
	if (errors.length > 0 || chDt !='')
	//if (errors.length > 0)
	{
		var errorMessage = '';
		errorMessage = '<br /><div class="ErrMsg"><div class="ErrListItem">Please correct or provide the following information:</div>';
		//for (var errorIndex = 0; errorIndex < errors.length; errorIndex++) {
		for (var errorIndex = 0; errorIndex < 2; errorIndex++) {
			if(errors[errorIndex] != null) {
				errorMessage += '<div class="ErrListItem">&bull;<span style="padding-left:10px">' + errors[errorIndex] + '</span></div>';
			}
		}
		
		if (chDt != '')
		{
			errorMessage += '<div class="ErrListItem">&bull;<span style="padding-left:10px">' + chDt + '</span></div><div class="ErrSpacer"><img src="//a248.e.akamai.net/a755bdded7308e72e7fac2eae90715fc.com/Images/signUpForEmail/trans_pixel.gif" width="1" height="1"></div></div><br />';
		}
		else
		{
			errorMessage += '<div class="ErrSpacer"><img src="//a248.e.akamai.net/a755bdded7308e72e7fac2eae90715fc.com/Images/signUpForEmail/trans_pixel.gif" width="1" height="1"></div></div><br />';
		}
		dispErr(errorMessage);
		return false;
	}
};//This closes validate function


//Function changes Country field based on the state selected.
function changeCountry() { 
	var SelectedState = document.signUp.state.value;
	if((SelectedState == "AB")||(SelectedState == "BC")||(SelectedState == "NB")||(SelectedState == "LB")||(SelectedState == "MB")||(SelectedState == "NF")||(SelectedState == "NT")||(SelectedState == "NS")||(SelectedState == "ON")||(SelectedState == "PE")||(SelectedState == "QC")||(SelectedState == "SK")||(SelectedState == "YT"))
	{ document.signUp.country.value = "Canada"; }
	else
	{ document.signUp.country.value = "United States"; }
}

//Function resets the state field when Country field is changed.
function changeState() {
	document.signUp.state.value = "";
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		//input.form[(getIndex(input)+1) % input.form.length].focus();
		//NOTE:-When ATG form get submitted it will create another form element for each form element same name with prepending _D: 
		//and it looks like _D:<original_form_element_name> So, instead of incrementing the index by 1 to get focus on next element 
		//it's been incremented by 2, it will happen only with ATG forms.
		input.form[(getIndex(input)+2) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;
	}
	function getIndex(input) {
		var index = 1, i = 0, found = false;
		while (i < input.form.length && index == 1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}

function CheckDate()
// This function returns true if the date provided is valid.
// Dates are assumed to be in mm/dd/yyyy format.
{	var txtDate = document.signUp.bMonth.value+"/"+document.signUp.bYear.value+"/";		  
	var strDateDiv= "/";
	var intMinYear=1900;
	var intMaxYear=2100;
	var pos1=txtDate.indexOf(strDateDiv);
	var pos2=txtDate.lastIndexOf(strDateDiv);
	var strMonth=txtDate.substring(0,pos1);
	var strYear=txtDate.substring(pos1+1,pos2);
	strYr=strYear;
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth);
	year=parseInt(strYr);
	
	if (strMonth.length<1 || month<1 || month>12)
	{
		dtStr = "Please fill in the valid month of your birthday to verify that you are old enough to receive AE promotions.";
	}
	else if (strYear.length != 4 || year==0 || year<intMinYear || year>intMaxYear)
	{
		dtStr = "Please fill in the valid year of your birthday to verify that you are old enough to receive AE promotions.";
	}
	else
	{
		dtStr = '';
	}
	return dtStr;
}

function isInteger(strTemp)
// Returns true if all the characters in strTemp are numbers.
// Called from CheckDate
{
	var i;
	for (i = 0; i < strTemp.length; i++)
	{
		// Check that current character is number.
		var c = strTemp.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function StripChars(strTemp, strToStrip)
// This function strips strToStrip from strTemp
// Search through strTemp characters one by one, if character is not strToStrip, append to returnString.
// It is called from CheckDate.
{
	var i;
	var returnString = "";
	
	for (i = 0; i < strTemp.length; i++)
	{
		var strChar = strTemp.charAt(i);
		if (strToStrip.indexOf(strChar) == -1) returnString += strChar;
	}
	return returnString;
}

//Privacy Policy Link - from AE checkout
function PrivacyPolicyPopup()
{
	var LeftPosition = (screen.width) ? (screen.width-508)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-368)/2 : 0;
	var popupURL = 'http://www.ae.com/'+jsContextRoot+'/help/privacy_policy.html';
	var popup = window.open(popupURL,"Estimate_Ship",'toolbar=0,top='+TopPosition+',left='+LeftPosition+',location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=508,height=368');
	if(navigator.appName.substring(0,8)=="Netscape")
	{
		popup.location=popupURL;
		popup.opener=self;
	}
	popup.focus();
}

//Birthday Link - from AE checkout
function BirthdayPopup()
{
	var LeftPosition = (screen.width) ? (screen.width-508)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-368)/2 : 0;
	var popupURL = 'http://www.ae.com/'+jsContextRoot+'/popups/birthday.html';
	var popup = window.open(popupURL,"Estimate_Ship",'toolbar=0,top='+TopPosition+',left='+LeftPosition+',location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=200');
	if(navigator.appName.substring(0,8)=="Netscape")
	{
		popup.location=popupURL;
		popup.opener=self;
	}
	popup.focus();
}

//-->