/***********************************************
*
* This file contains JavaScript functions written by
* Rick Steele for use in the NuRide site.
* All functions begin with RS_ for easy identification.
* Some are placeholder functions for mock-ups.
*
***********************************************/



/***********************************************
*
*  This function checks if an email string is valid
*
*  input  = email strng
*  return = "true" if valid email string
*  return = "false" if email string is invalid
*
***********************************************/

function RS_checkValidEmailString(email) {						
	//var regex = /^[\w\.\-_\+]+@[\w-]+(\.\w{2,4})+$/;
	var regex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	//var regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if (regex.test(email.value)) {
		return true;
	}
	else {
		return false;
	}
}


/***********************************************
*
*  This function trims leading & trailing spaces
*  from an input field.  This even works on IE6!
*
*  input  = input field
*  return = trimmed field
*
***********************************************/

function RS_trimInput(userInput) {
	userInput.value = userInput.value.replace(/^\s+|\s+$/g,"");
}


/***********************************************
*
*  This function updates the "Saved changes" area
*  at the bottom of many of the user account page.
*
*  input  = "saved",  shows divs called saved text and graphics
*         = "unsaved" shows div with unsaved text (error message)
*         = "hide" hides all divs
*
***********************************************/

function RS_updateSaveStatus(status) {
	if (status == "saved") {
		// Display "Saved changes" message and hide others
		document.getElementById("unsavedText").style.display = 'none';
		document.getElementById("savedText").style.display = 'block';
		document.getElementById("savedGraphic").style.display = 'block';
	}
	else if (status == "unsaved") {
		// Display "Unsaved" message and hide others
		document.getElementById("unsavedText").style.display = 'block';
		document.getElementById("savedText").style.display = 'none';
		document.getElementById("savedGraphic").style.display = 'none';
	}
	else if (status == "hide") {
		// Hide all of the elements
		document.getElementById("unsavedText").style.display = 'none';
		document.getElementById("savedText").style.display = 'none';
		document.getElementById("savedGraphic").style.display = 'none';
	}
}

