
var emailRequired = "<li>Email Address is missing.</li>";
var emailInvalid = "<li>Email Address is invalid.</li>";
var passRequired = "<li>Password is missing.</li>";
var passLength = "<li>Password is invalid.</li>";
var errorStr="<span class='txt_error'>Sorry! It looks like you\'ve missed one or more of our required fields. Please fill in the fields highlighted below.</span>";
var invalidStr="<span class='txt_error'>Sorry! The information you\'ve entered in the following fields (highlighted) does not match our requirements. Please try again.</span>";


function validateLogin() {
	var errorMessage = validateForm();
	if (errorMessage == '') {
	  submitTo('loginform', '/en_US/loginsubmit.do');
	} else {		
		document.getElementById('njs_errors').innerHTML ="";
		getElement('show_errors').innerHTML =errorMessage;
		getElement('show_errors').className='txt_errors';
		getElement('show_help').style.display='block';
		scroll(0,130);
	}
	return false; 
}

function validateForm() {
	  var result = true;
	  var errorMsg = '';
	  var reqdErrorMsg = '';
	  var invalidErrorMsg = '';
		document.getElementById('loginform').email.value=trim(document.getElementById('loginform').email.value);
	  var email = document.getElementById('loginform').email;
	   if ( !validRequired(email)) {
		  reqdErrorMsg = reqdErrorMsg + emailRequired;
		  result = false;
	  }else if (!isvalidEmail(email.value)){

		 invalidErrorMsg = invalidErrorMsg + emailInvalid;
		  result = false;
		}

	  var pass = document.getElementById('loginform').password;
	  if (!validRequired( pass)) {
		  reqdErrorMsg = reqdErrorMsg + passRequired;
		  result = false;
	  }
	  if (pass.value != '') {
		if (pass.value.length < 6 || pass.value.length > 12) {
		  invalidErrorMsg = invalidErrorMsg + passLength;
		  result = false;
		}
	  }
	  if (reqdErrorMsg != '') {
		  errorMsg = errorStr + reqdErrorMsg;
	  }
	  if (invalidErrorMsg != '') {
		  errorMsg = errorMsg + invalidStr + invalidErrorMsg;
	  }
	  return errorMsg;
}
function isvalidEmail(email){
	var reg="^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$"; 
	var reg1 = new RegExp(reg);
	return reg1.test(trim(email))
}
function submitTo(formName, url) {
	var form = getElement(formName);
	form.action = url;
	form.submit();
}
function MM_openBrWindow(theURL,winName,features) { 
	var popWin = window.open(theURL,winName,features);

}
function setfocus(){
	document.getElementById('loginform').email.focus();
}
function setValue(){
	document.getElementById('loginform').nextpage.value="updatepage";
}