
function toggleEditProfileTabs(tabIndex, tabCount) {
	for (var i = 0; i < tabCount; i++) {
		deactivateTab(i, tabCount);
	}
	activateTab(parseInt(tabIndex), tabCount);
}
function checkNonUS(cBox, zipFieldId) {
	var zipField = document.getElementById(zipFieldId);
	if (cBox.checked) {
		zipField.maxLength = 6;
		zipField.value = "non-us";
		zipField.disabled = true;
	} else {
		zipField.maxLength = 5;
		zipField.value = "";
		zipField.disabled = false;
	}
}
function populateUserName(formName, linkObj) {
	var errorMsg = document.getElementById(formName + ":errorMsg");
	var userNameObj = document.getElementById(formName + ":username");
	var emailAddressErrorDiv = document.getElementById("emailAddressErrorDiv");
	if (userNameObj.value.length == 0) {
		emailAddressErrorDiv.className = "ErrorStyle";
		errorMsg.style.display = "inline";
		linkObj.href = "#";
	} else {
		linkObj.href = "/nemoves-pws/userMaintenance/displayPasswordHint.nem?userName=" + userNameObj.value;
		emailAddressErrorDiv.className = "nonErrorStyle";
		errorMsg.style.display = "none";
	}
}
function isValidEmail(fieldId) {
	// These comments use the following terms from RFC2822:
	// local-part, domain, domain-literal and dot-atom.
	// Does the address contain a local-part followed an @ followed by a domain?
	// Note the use of lastIndexOf to find the last @ in the address
	// since a valid email address may have a quoted @ in the local-part.
	// Does the domain name have at least two parts, i.e. at least one dot,
	// after the @? If not, is it a domain-literal?
	// This will accept some invalid email addresses
	// BUT it doesn't reject valid ones.
	return true;
	var email = document.getElementById(fieldId).value;
	alert(email);
	var atSym = email.lastIndexOf("@");
	if (atSym < 1) {
		alert('invalid');
		return false;
	} // no local-part
	if (atSym == email.length - 1) {
		alert('invalid');
		return false;
	} // no domain
	if (atSym > 64) {
		alert('invalid');
		return false;
	} // there may only be 64 octets in the local-part
	if (email.length - atSym > 255) {
		alert('invalid');
		return false;
	} // there may only be 255 octets in the domain

  // Is the domain plausible?
	var lastDot = email.lastIndexOf(".");
  // Check if it is a dot-atom such as example.com
	if (lastDot > atSym + 1 && lastDot < email.length - 1) {
		alert('VALID1');
		return true;
	}
  //  Check if could be a domain-literal.
	if (email.charAt(atSym + 1) == "[" && email.charAt(email.length - 1) == "]") {
		alert('VALID2');
		return true;
	}
		alert('invalid');
	return false;
}

function validatePasswordHint(){
	var passwordHintErrorMsg = document.getElementById("myPageForm:passwordHintErrorMsg");
	var passwordHintErrorDiv = document.getElementById("emailAddressErrorDiv");
	var userNameObj = document.getElementById("myPageForm:username");
	var valid = true;
	passwordHintErrorDiv.className = "nonErrorStyle";
	passwordHintErrorMsg.style.display = "none";

	if (userNameObj.value.length == 0) {
		passwordHintErrorMsg.style.display = "inline";
		valid = false;
	} else {
		passwordHintErrorMsg.style.display = "none";
	}
	if(valid) {
		var passHintHdnObj = document.getElementById('myPageForm:passwordHintHidden');
		if(passHintHdnObj != null) {
			passHintHdnObj.value = userNameObj.value;
		}
		
		var linkObj = document.getElementById("myPageForm:passwordHint");
		if(linkObj != null) {
			var target = linkObj.href;
			var startIndex = target.indexOf('userName=');
			var restOfTheURL = "";
			var firstPart = target.substring(0,startIndex);
			var endIndex = 0;
			if(startIndex > 0) {
				restOfTheURL = target.substring((startIndex + "userName=".length),target.length);
				endIndex = restOfTheURL.indexOf("&");
				restOfTheURL = restOfTheURL.substring(endIndex);
				//linkObj.href = firstPart + '&userName=' + passHintHdnObj.value + restOfTheURL;
			} else {
				//linkObj.href += '&userName=' + passHintHdnObj.value;
			}
		}
	}
	return valid;
}