/*
	OnChange_Country(): The state/Province and Zip/Postal Code fields vary with the selection
						of the country
*/
function OnChange_Country() {
	theForm = document.Form_Register;
	theForm.buttonClicked.value = "edit";
	theForm.submit();
	/*
	// Country is United States
	if (theForm.Country.options[theForm.Country.selectedIndex].value == "United States" ||
		theForm.Country.options[theForm.Country.selectedIndex].value == "US") {
		document.getElementById("ID_OtherCountry").style.display = "none";
		document.getElementById("ID_USStates").style.display = "block";
		document.getElementById("ID_CanadaProvince").style.display = "none";
		document.getElementById("ID_StateProvince").style.display = "none";
		document.getElementById("ID_ZipCode").style.display = "block";
		document.getElementById("ID_PostalCode").style.display = "none";
		document.getElementById("ID_ZipPostalCode").style.display = "none";
	}
	// Country is Canada
	else if (theForm.Country.options[theForm.Country.selectedIndex].value == "Canada" ||
			 theForm.Country.options[theForm.Country.selectedIndex].value == "CA") {
		document.getElementById("ID_OtherCountry").style.display = "none";
		document.getElementById("ID_USStates").style.display = "none";
		document.getElementById("ID_CanadaProvince").style.display = "block";
		document.getElementById("ID_StateProvince").style.display = "none";
		document.getElementById("ID_ZipCode").style.display = "none";
		document.getElementById("ID_PostalCode").style.display = "block";
		document.getElementById("ID_ZipPostalCode").style.display = "none";
	}
	// Country is not on the list
	else if (theForm.Country.options[theForm.Country.selectedIndex].value == "Other" ||
			 theForm.Country.options[theForm.Country.selectedIndex].value == "OT") {
		document.getElementById("ID_OtherCountry").style.display = "block";
		document.getElementById("ID_USStates").style.display = "none";
		document.getElementById("ID_CanadaProvince").style.display = "none";
		document.getElementById("ID_StateProvince").style.display = "block";
		document.getElementById("ID_ZipCode").style.display = "none";
		document.getElementById("ID_PostalCode").style.display = "none";
		document.getElementById("ID_ZipPostalCode").style.display = "block";
	}
	// All other countries
	else {
		document.getElementById("ID_OtherCountry").style.display = "none";
		document.getElementById("ID_USStates").style.display = "none";
		document.getElementById("ID_CanadaProvince").style.display = "none";
		document.getElementById("ID_StateProvince").style.display = "block";
		document.getElementById("ID_ZipCode").style.display = "none";
		document.getElementById("ID_PostalCode").style.display = "none";
		document.getElementById("ID_ZipPostalCode").style.display = "block";
	}
	*/
}


function FormValidation_Register() {
	theForm = document.Form_Register;

	// for the user registered as an employer
	if (theForm.Seeker.value == 0) {
		// validate an employer type
		theForm.EmployerType.required = true;
		theForm.EmployerType.requiredError = 'An Employer Type must be selected.';
		theForm.EmployerType.disallowEmptyValue = true;
		theForm.EmployerType.disallowEmptyValueError = 'An Employer Type must be selected.';
		
		// validate a company name
		theForm.Company.required = true;
		theForm.Company.requiredError = 'The Company Name field must be filled in.';
	}
	
	// validate a first name
	theForm.FirstName.required = true;
	theForm.FirstName.requiredError = 'The First Name field must be filled in.';
	
	// validate a last name
	theForm.LastName.required = true;
	theForm.LastName.requiredError = 'The Last Name field must be filled in.';
	
	// validate an address
//	theForm.Address1.required = true;
//	theForm.Address1.requiredError = 'The Address field must be filled in.';
	
	// validate a city
//	theForm.City.required = true;
//	theForm.City.requiredError = 'The City field must be filled in.';
	
/*	else if (theForm.Country.options[theForm.Country.selectedIndex].value == "Canada" ||
			 theForm.Country.options[theForm.Country.selectedIndex].value == "CA") {
		theForm.Province.required = true;
		theForm.Province.requiredError = 'A Province must be selected.';
		theForm.Province.disallowEmptyValue = true;
		theForm.Province.disallowEmptyValueError = 'A Province must be selected.';
	}
	else {
		theForm.StateProvince.required = true;
		theForm.StateProvince.requiredError = 'The State/Province field must be filled in.';
	}
*/
	if (theForm.Country.options[theForm.Country.selectedIndex].value == "United States" ||
		theForm.Country.options[theForm.Country.selectedIndex].value == "US") {
		theForm.ZipCode.required = true;
		theForm.ZipCode.requiredError = 'A Zip Code must be filled in.';
		theForm.ZipCode.pattern = 'zipcode';
		theForm.ZipCode.patternError = 'The US Zip Code entered is not valid (must be exactly 5 numeric digits).';
	}
	// validate a state/province

	if (theForm.Country.options[theForm.Country.selectedIndex].value == "United States" ||
		theForm.Country.options[theForm.Country.selectedIndex].value == "US") {
		if (theForm.City.value == ''){
			theForm.City.required = true;
			theForm.City.requiredError = 'City is required. A Zip Code not found.';
			theForm.City.pattern = 'hidden';
			theForm.City.patternError = 'City is required. A Zip Code not found.';
		}
		if (theForm.state.value == ''){
			theForm.state.required = true;
			theForm.state.requiredError = 'State is required. A Zip Code not found.';
			theForm.state.pattern = 'hidden';
			theForm.state.patternError = 'State is required. A Zip Code not found.';
		}
	}
/*
	else if (theForm.Country.options[theForm.Country.selectedIndex].value == "Canada" ||
			 theForm.Country.options[theForm.Country.selectedIndex].value == "CA") {
		theForm.PostalCode.required = true;
		theForm.PostalCode.requiredError = 'A Postal Code must be filled in.';
		theForm.PostalCode.pattern = 'postal code';
		theForm.PostalCode.patternError = 'The Canadian Postal Code entered is not valid (use ANA NAN or ANA-NAN format).';
	}
	else {
		theForm.ZipPostalCode.required = true;
		theForm.ZipPostalCode.requiredError = 'The Zip/Postal Code field must be filled in.';
		theForm.ZipPostalCode.pattern = 'zip or postal code';
		theForm.ZipPostalCode.patternError = 'The Zip/Postal Code entered is not valid.';
	}
*/
	
	if (theForm.Country.options[theForm.Country.selectedIndex].value == "Other" ||
		theForm.Country.options[theForm.Country.selectedIndex].value == "OT") {
		if (theForm.OtherCountry.value == '(type a country name)') {
			theForm.OtherCountry.value = '';
		}
		theForm.OtherCountry.required = true;
		theForm.OtherCountry.requiredError = 'The Country field must be filled in.';
	}
	
	// validate a phone number
	if (theForm.Country.options[theForm.Country.selectedIndex].value == "United States" ||
		theForm.Country.options[theForm.Country.selectedIndex].value == "US" ||
		theForm.Country.options[theForm.Country.selectedIndex].value == "Canada" ||
		theForm.Country.options[theForm.Country.selectedIndex].value == "CA") {
		if (theForm.Seeker.value == 0) {
			theForm.PhoneWork.required = true;
			theForm.PhoneWork.requiredError = 'The Work Phone field must be filled in (xxx-xxx-xxxx).';
			theForm.PhoneWork.pattern = 'us phone number';
			theForm.PhoneWork.patternError = 'The Work Phone number is not valid.';
			
//			theForm.PhoneFax.required = true;
//			theForm.PhoneFax.requiredError = 'The Fax field must be filled in (xxx-xxx-xxxx).';
//			theForm.PhoneFax.pattern = 'us phone number';
//			theForm.PhoneFax.patternError = 'The Fax number is not valid.';
		}
		else {
			theForm.PhoneHome.required = true;
			theForm.PhoneHome.requiredError = 'The Home Phone field must be filled in (xxx-xxx-xxxx).';
			theForm.PhoneHome.pattern = 'us phone number';
			theForm.PhoneHome.patternError = 'The Home Phone number is not valid (xxx-xxx-xxxx).';
		}
	}
	else {
		if (theForm.Seeker.value == 0) {
			theForm.PhoneWork.required = true;
			theForm.PhoneWork.requiredError = 'The Work Phone field must be filled in.';
			
//			theForm.PhoneFax.required = true;
//			theForm.PhoneFax.requiredError = 'The Fax field must be filled in.';
		}
		else {
			theForm.PhoneHome.required = true;
			theForm.PhoneHome.requiredError = 'The Home Phone field must be filled in.';
		}
	}
	
	// validate an email address
	theForm.EmailAddress.required = true;
	theForm.EmailAddress.requiredError = 'The Email Address field must be filled in.';
	theForm.EmailAddress.pattern = 'email';
	theForm.EmailAddress.patternError = 'The Email Address entered is not valid.';
	theForm.EmailAddress.maxLength = 50;
	theForm.EmailAddress.maxLengthError = 'Your EmailAddress with ' + trimWhitespace(theForm.EmailAddress.value).length + ' charater(s) is too long (max: 50 characters).';
	
	// validate an email address
	theForm.ConfirmEmailAddress.required = true;
	theForm.ConfirmEmailAddress.requiredError = 'The Retype Email Address field must be filled in.';
	theForm.ConfirmEmailAddress.pattern = 'email';
	theForm.ConfirmEmailAddress.patternError = 'The Retype Email Address entered is not valid.';
	
	// validate an address
	theForm.Address.maxLength = 50;
	theForm.Address.maxLengthError = 'Your Address with ' + trimWhitespace(theForm.Address.value).length + ' charater(s) is too long (max: 50 characters).';

/*	
	if (theForm.EmailAddress.value != theForm.ConfirmEmailAddress.value) {
		alert("Retype Email Address does not match Email Address.");
		return false;
	}
*/	
	// validate how to hear about us
/*
	theForm.ReferredBy.required = true;
	theForm.ReferredBy.requiredError = 'How Did You Hear About Us must be selected.';
	theForm.ReferredBy.disallowEmptyValue = true;
	theForm.ReferredBy.disallowEmptyValueError = 'How Did You Hear About Us must be selected.';
*/
	// validate a username
	theForm.LoginID.required = true;
	theForm.LoginID.requiredError = 'The Username field must be filled in (5 to 50 characters).';
	theForm.LoginID.minLength = 5;
	theForm.LoginID.minLengthError = 'Your Username with ' + trimWhitespace(theForm.LoginID.value).length + ' charater(s) is too short (min: 5 characters).';
	theForm.LoginID.maxLength = 50;
	theForm.LoginID.maxLengthError = 'Your Username with ' + trimWhitespace(theForm.LoginID.value).length + ' charater(s) is too long (max: 50 characters).';
	
	// validate a password
	theForm.Password.required = true;
	theForm.Password.requiredError = 'The Password field must be filled in (6 to 12 characters)).';
	theForm.Password.pattern = 'password';
	theForm.Password.patternError = 'The Password entered is not valid.';
	theForm.Password.minLength = 6;
	theForm.Password.minLengthError = 'Your password with ' + trimWhitespace(theForm.Password.value).length + ' charater(s) is too short (min: 6 characters).';
	theForm.Password.maxLength = 12;
	theForm.Password.maxLengthError = 'Your password with ' + trimWhitespace(theForm.Password.value).length + ' charater(s) is too long (max: 12 characters).';
	
	theForm.ConfirmPassword.required = true;
	theForm.ConfirmPassword.requiredError = 'The Confirm Password field must be filled in (6 to 12 characters).';
/*
	// validate if the password and confirm password match
	if (trimWhitespace(theForm.Password.value) != trimWhitespace(theForm.ConfirmPassword.value)) {
		alert("Your password and confirm password do not match.");
		theForm.Password.value = '';
		theForm.ConfirmPassword.value = '';
		theForm.Password.focus();
		return false;
	}
*/	
	var errors = getFormErrors(theForm);
	// validate if email address match retype email address
	if (theForm.EmailAddress.value != theForm.ConfirmEmailAddress.value) {
		errors[errors.length] = "Retype Email Address does not match Email Address.";
	}
	
	// validate if the password and confirm password match
	if (trimWhitespace(theForm.Password.value) != trimWhitespace(theForm.ConfirmPassword.value)) {
		errors[errors.length] = "Password and Confirm Password do not match.";
	}
	
	// validate if password does not have 
/*	if (isValidNumAlp(trimWhitespace(theForm.Password.value)) == false){
		errors[errors.length] = "Password should be with at least one digit and at least one Alphabet.";
	}*/
	
	// validate if the user accepts the term and privacy 
	if (!theForm.Accept.checked) {
		errors[errors.length] = "You must accept the terms and conditions of the site privacy statement to complete your registration.";
	}
	
	if (errors.length > 0) {
		var errorMessage = 'The form was not submitted due to the following problem' + ((errors.length > 1) ? 's' : '') + ':\n\n';
		for (var errorIndex = 0; errorIndex < errors.length; errorIndex++) {
			errorMessage += '* ' + errors[errorIndex] + '\n';
		}
		errorMessage += '\nPlease fix ' + ((errors.length > 1) ? 'these' : 'this') + ' problem' + ((errors.length > 1) ? 's' : '') + ' and resubmit the form.';
		alert(errorMessage);
		return false;
	}
	
/*
	if (!theForm.Accept.checked) {
		alert("Your registration can not be processed if you don't accept the terms and conditions of the site privacy statement.");
		return false;
	}
*/	
	// disable all buttons to avoid multi-submit
	disableButtons(theForm);
	
	// alert to avoid multiple-submit
	submitAlert();
	
	/* submit the form once all validation is complete */
	//theForm.submit();
//	alert('Form WOULD successfully submit!');
//	return false;
	
	// no errors, so submit the form
	return true;
}




