
function EMailAddressValidBLN(objField, strMessage) {   
// Validates e-mail address form inputs.
//	Apr 4, 2000 - Frank
	
	if (objField.value == "") {	// no value entered in field.
	
		// DISPLAY validation failure message.
		alert(strMessage);    
		
		// REDIRECT shopper's cursor to the offending field.
		objField.focus();      
		return false;       
	}
	
	if (objField.value.indexOf ('@', 0) == -1 || objField.value.indexOf ('.', 0) == -1) {	// address does not contain the "@" and "." characters.
	
		// DISPLAY validation failure message.
		alert(strMessage);    
		 
		// REDIRECT shopper's cursor to the offending field.
		objField.select();      
		objField.focus();      
		return false;      
	}
	
	else {	// the address is acceptable.
		return true;      
	}   
}

function ValidEmailExistsBLN(objField) {
// Validate email address if it already exists
// May 09, 2000 - Josh Pak

	if (EmailExistsBLN(objField.value))
	{
		alert("Email already exists!!")
		
		objField.focus();
		return false;
	}
	else
	{
		return true
	}
}

function IsNumericBLN(objField) {
// Validates numeric input.
//  May 7, 2000 - C. Wilson

	// INITIALIZE procedure-scope variables.
	var blnNumeric = true
	
	// SCAN string for non-numeric characters.
	for (var i = 0; i < objField.value.length; i++) {
	
		var strDigit = objField.value.charAt(i)
	
		if (strDigit < "0" || strDigit > "9") {	//non-numeric character has been found.
			blnNumeric = false
			break
		}
	}
	
	// ASSIGN return value.
	return blnNumeric
	
}


function PasswordValidBLN(objField, strMessage) {
// Validates new password form inputs.
//	Apr 4, 2000 - Frank

	if (objField.value == "") {	// no value entered in field
	
		// DISPLAY validation failure message.
		alert(strMessage);
		
		// REDIRECT shopper's cursor to the offending field.
		objField.focus();
		return false;
	}
	
	else {	// the password is acceptable.
		return true;
	}
	
}

function PasswordEqualBLN(objField1, objField2, strMessage) {
// Validates new password form inputs.
//	May 8, 2000 - Josh

	if (objField1.value == "") {	// no value entered in field
	
		// DISPLAY validation failure message.
		alert(strMessage);
		
		// REDIRECT shopper's cursor to the offending field.
		objField1.focus();
		return false;
	}
	
	if (objField2.value == "") {	// no value entered in field
	
		// DISPLAY validation failure message.
		alert(strMessage);
		
		// REDIRECT shopper's cursor to the offending field.
		objField2.focus();
		return false;
	}
	
	if	(objField1.value != objField2.value) { // check if they are same
	
		// DISPLAY validation failure message.
		alert("Your password did not match");
		
		// REDIRECT shopper's cursor to the offending field.
		objField2.focus();
		return false;
	}
	
	else { // the password is acceptable.
		return true;
	}
	
}

function TrimSTR(strValue) {
// Trims any leading and/or trailing spaces from the string argument.
//  May 7, 2000 - C. Wilson

	// REMOVE leading spaces.
	while (true) {
		if (strValue.indexOf(" ") == 0) {								// a leading space has been found so...
			strValue = strValue.substring(1, strValue.length)			// slice it off.
		} else {														// the first character in the string is no longer a space so...
			break														// exit the loop.
		}
	}
	
	// REMOVE trailing spaces.
	if (strValue.length > 0) {	// the string is not null.
		while (true) {
			if (strValue.lastIndexOf(" ") == strValue.length - 1) {			// a trailing space has been found so...
				strValue = strValue.substring(0, strValue.length - 1)	// slice it off.
			} else {													// the last character in the string is no longer a space so...
				break													// exit the loop.
			}
		}
	}

	// ASSIGN return value
	return strValue
}


			
			
			function ValidateEMailBLN(objForm) {
			// Validates only the e-mail field.
			//	May 3, 2000 - C. Wilson
			
				if (EMailAddressValidBLN(objForm.email, "Please enter a valid email address.")) {
					return true
				} else {
					return false
				}
				
			}
			
			
			function ValidateNewAccountBLN(objForm) {
			// Validates new account form.
			//	May 8, 2000 - Josh Pak
			
				if (ValidateAddressBLN(objForm) && EMailAddressValidBLN(objForm.email, "Please enter a valid email address.") && PasswordValidBLN(objForm.password, "Please enter your password.") && PasswordEqualBLN(objForm.password, objForm.retypePassword, "Please enter your password."))
				{
					return true
				} 
				else 
				{
					return false
				}
				
			}

			
			
			function ValidateAddressBLN(objForm) {
			// Validates address information (e.g., billing and shipping).
			//  May 7, 2000 - C. Wilson
	
				with (objForm) {
				
					// REMOVE trailing and leading spaces from input strings before proceeding with validation.
					
					firstname.value = TrimSTR(firstname.value)
					lastname.value = TrimSTR(lastname.value)
					company.value = TrimSTR(company.value)
					address1.value = TrimSTR(address1.value)
					address2.value = TrimSTR(address2.value)
					country.value = TrimSTR(country.value)
					city.value = TrimSTR(city.value)
					state.value = TrimSTR(state.value)
					zip.value = TrimSTR(zip.value)
					//Country.value = TrimSTR(Country.value)
					
					dayPhone1.value = TrimSTR(dayPhone1.value)
					eveningPhone1.value = TrimSTR(eveningPhone1.value)
				
			
					// VALIDATE first name.
					if ((firstname.value.length > 30) || (firstname.value.length < 1)) {
						alert("Please enter a valid First Name.");
						firstname.select()
						firstname.focus()
						return false
					}
			
					// VALIDATE last name.
					if ((lastname.value.length > 30) || (lastname.value.length < 1)) {
						alert("Please enter a valid Last Name.");
						lastname.select()
						lastname.focus()
						return false
					}
			
					// VALIDATE company.
					if (company.value.length > 50) {
						alert("Please enter a valid Company.");
						company.select()
						company.focus()
						return false
					}
			
					// VALIDATE address.
					if ((address1.value.length > 50) || (address1.value.length < 1) || (address2.value.length > 50)) {
						alert("Please enter a valid Address.");
						address1.focus()
						return false
					}

                   if (country.value.length < 1) {
						alert("Please select a Country.");
						country.focus()
						return false
					}
					
					
			
					// VALIDATE city.
					if ((city.value.length > 30) || (city.value.length < 1)) {
						alert("Please enter a valid City.");
						city.select()
						city.focus()
						return false
					}
			
					// VALIDATE state.
					if (state.value.length < 1) {
						alert("Please enter a valid State.");
						state.focus()
						return false
					}
			
					// VALIDATE zip code.
					if (zip.value.length < 1) {
						alert("Please enter a valid zip Code.");
						zip.focus()
						return false
					}


					
					// VALIDATE daytime phone number.
					if (dayPhone1.value.length < 1) {
						alert("Please enter a valid Daytime Phone.");
						dayPhone1.focus()
						return false
					}

			

					else 
						return true
				}
			
			}
			
