/* checks login form for empty / incorrect fields -- borrowed from member_auth.jsp */
function lookover() {
	if (document.auth1.user_email.value == ""){
		alert("Please enter your Email Address");
		document.auth1.user_email.focus();
		return false;
   	} else {
      	var emailReg = "^[\\w-_\.\'\+]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
      	var regex = new RegExp(emailReg);
      	if (!regex.test(document.auth1.user_email.value)) {
        	alert("Please enter a valid E-mail address");
         	document.auth1.user_email.focus();
         	return false;
      	}
   	}
   	if (document.auth1.password.value == ""){
      	alert("Please enter your password");
      	document.auth1.password.focus();
      	return false;
   	}
   	return true;
}


/* self explanatory */
function findpassword() {
   	if (document.auth1.user_email.value != "") {
	open('https://secure.audience.nascar.com/services/nascar/pitpass/passHint.do?source=nascar&pid=nascar.default&user_email='+document.auth1.user_email.value+'&url=http%3A%2F%2Fwww.nascar.com%2Ftrackpass%2F');
   	} else {
      	alert("Please enter your Email Address");
      	document.auth1.user_email.focus();
   	}
}


/* detects error code and displays appropriate message */
function getError() {
	var parameter = location.search;							// Grabs "?" + "string" (error code from user's incorrect entry)
	if (parameter.indexOf('error=Bad%20email') > -1) {					// Unrecognized email address
		document.getElementById('badEmail').style.display='block';
	} else if (parameter.indexOf('error=Bad%20password') > -1) {		// Bad password
		document.getElementById('badPass').style.display='block';
	} else if (parameter.indexOf('error=2') > -1) {											// Not a subscriber
		document.getElementById('notSub').style.display='block';
	} else if (parameter.indexOf('error=3') > -1) {											// Expired subscription
		document.getElementById('expiredSub').style.display='block';
	} else if (parameter.indexOf('error=4') > -1) {											// Wrong subscription
		document.getElementById('wrongSub').style.display='block';
	} else if (parameter.indexOf('error=5') > -1) {											// Backend (LDAP) error
		document.getElementById('intError').style.display='block';
	} else if (parameter.indexOf('errorMsg=User%20not%20found') > -1) {						// Unrecognized email address (Member Services)
		document.getElementById('badEmail').style.display='block';
	} else if (parameter.indexOf('errorMsg=Password%20did%20not%20match') > -1) {			// Bad password (Member Services)
		document.getElementById('badPass').style.display='block';
	}
}