function setCookie(name, value) {
	var now = new Date();
	var then = new Date(now.getTime() + 31536000000);
	document.cookie = name + "=" + escape(value) +
		"; expires=" + then.toGMTString() + "; path=/";
}

/* Get previous value of element. */
function getValue(element) {
	var value = getCookie(element.name);
	if (value != null) element.value = value;
}

/* Set new value for element. */
function setValue(element) {
	setCookie(element.name, element.value);
}

/* Function to efficiently fix elements that are not filled. */
function fixElement(element, message) {
	alert(message);
	element.focus();
}

/* Check a string to see if it is a proper email */
function checkEmail( eml ) {

    // if the eml string is empty, contains no "@" or contains no "." then return null
	if( eml == null || eml.length == 0 || eml.indexOf("@") == -1 || eml.indexOf(".") == -1) {
	    return null;
    }

	var charsToChomp = 0;
	var whitespace = " \t\r\n"; // characters to strip

	// count the number of white spaces at the beginning of the email field
	while( whitespace.indexOf( eml.charAt( charsToChomp ) ) != -1 ) charsToChomp++;

	// remove the leading white spaces
	eml = eml.substring( charsToChomp, eml.length );

	var charsToUse = eml.length-1; // the number of characters to use

	// find the number of characters before the trailing white space
	while( whitespace.indexOf( eml.charAt( charsToUse ) ) != -1 ) charsToUse--;

	// remove the trailing white spaces
	eml = eml.substring( 0, charsToUse+1 );

	// if any of the whitespace characters are in the email value, the email is not valid.
	for( var i=0; i<whitespace.length; i++ ) {
		if( eml.indexOf( whitespace.charAt( i ) ) != -1 ) {
			return null;
		}
	}

	return eml;
}

/*
	checks a field for commas.

	if a comma is present, fixElement is called and false is returned
 */
function checkFieldForCommas( field ) {
	if( field.value.indexOf(",") != -1 ) {
		fixElement( field, "Do not use commas in your entry. Please remove the comma(s) and proceed." );
		return false
	}
	return true;
}
