var err_color = '#ffcccc';
var ok_color = '#ffffff';

function listserv_type_fix()
{
	document.listserv_form.listserv_type.style.backgroundColor = ok_color;
}

function password_new_fix()
{
	document.listserv_form.password_new.style.backgroundColor = ok_color;
}

function password_fix()
{
	document.listserv_form.password.style.backgroundColor = ok_color;
}

function password_old_fix()
{
	document.listserv_form.password_old.style.backgroundColor = ok_color;
}

function listserv_name_fix()
{
	document.listserv_form.listserv_name.style.backgroundColor = ok_color;
}

function email_fix()
{
	document.listserv_form.email.style.backgroundColor = ok_color;
}

function listserv_action_fix()
{
	document.listserv_form.listserv_action.style.backgroundColor = ok_color;
}

function check_form()
{


//var class_year = document.listserv_form.listserv_name.value;
if (document.listserv_form.listserv_action.value != "")
	{
	//alert("You picked an action");
	
	if (document.listserv_form.listserv_action.value == "subscribe" || document.listserv_form.listserv_action.value == "unsubscribe" || document.listserv_form.listserv_action.value == "options")
		{
		//alert(document.listserv_form.listserv_action.value);	
		
		if (document.listserv_form.listserv_type.value == "connection_city" || document.listserv_form.listserv_type.value == "class_year" || document.listserv_form.listserv_type.value == "interest_group")
			{
			//alert(document.listserv_form.listserv_type.value);
		
			if (document.listserv_form.listserv_name.value != "")
				{
				//alert("You picked a listserv name.");
				var check_val = (document.listserv_form.listserv_name.value)/(document.listserv_form.listserv_name.value);
				//alert(document.listserv_form.listserv_name.value.length);
				if ((document.listserv_form.listserv_type.value == "class_year") && (check_val == "1"))
					{
					if (document.listserv_form.listserv_name.value.length == "4")
						{
						//alert("You provided a valid class year.");
						}
					else
						{
						alert("Please provide a four digit class year.");
						document.listserv_form.listserv_name.focus();
       					document.listserv_form.listserv_name.style.backgroundColor = err_color;
						return false;
						}
					
						
					}
				else if ((document.listserv_form.listserv_type.value == "class_year") && (check_val != "1"))
					{
					alert("Please provide a valid class year.");
					document.listserv_form.listserv_name.focus();
       				document.listserv_form.listserv_name.style.backgroundColor = err_color;
					return false;
					}
				
				
				
				if ((document.listserv_form.email.value.indexOf(".") >= "1") && (document.listserv_form.email.value.indexOf("@") > "0"))
					{
					//alert("You provided a valid e-mail address");					
					}
				else
					{
					alert("Please provide a valid e-mail address.");
					document.listserv_form.email.focus();
       				document.listserv_form.email.style.backgroundColor = err_color;
					return false;
					}
					
				if (document.listserv_form.listserv_action.value == "options")
					{
					if (document.listserv_form.action.value == "dm")
						{
						//alert("digest mode");
						if(document.listserv_form.password.value != "")
							{
							//alert("You provided a password.");
							}
						else
							{
							alert("Please provide your listserv password.");
							document.listserv_form.password.focus();
       						document.listserv_form.password.style.backgroundColor = err_color;
							return false;
							}
							
						}
					else if (document.listserv_form.action.value == "rp")
						{
						//alert("request password");	
							
						}
					else if (document.listserv_form.action.value == "cp")
						{
						//alert("change password");	
						if(document.listserv_form.password_old.value != "")
							{
							//alert("You provided a password.");
							}
						else
							{
							alert("Please provide your listserv password.");
							document.listserv_form.password_old.focus();
       						document.listserv_form.password_old.style.backgroundColor = err_color;
							return false;
							}
						if(document.listserv_form.password_new.value != "")
							{
							//alert("You provided a new password.");
							}
						else
							{
							alert("Please provide a new password.");
							document.listserv_form.password_new.focus();
       						document.listserv_form.password_new.style.backgroundColor = err_color;
							return false;
							}
						}
					else
						{
						alert("You chose an invalid options action.");	
							
						}
					}
					
				}
			else
				{
				alert("Please choose a listserv.");
				document.listserv_form.listserv_name.focus();
       			document.listserv_form.listserv_name.style.backgroundColor = err_color;
				return false;
				}
			
			}
		
		else
			{
			alert("Please choose a listserv type.");
			document.listserv_form.listserv_type.focus();
       		document.listserv_form.listserv_type.style.backgroundColor = err_color;
			return false;
			}
			
			
		}

	else
		{
		alert("You chose an invalid action.  Please choose subscribe, unsubscribe, or options.");
		document.listserv_form.action.focus();
       	document.listserv_form.action.style.backgroundColor = err_color;
		return false;
		
		}
	
	
	
	
	
	
	
	return true;
	}
else
	{
	alert ("Please choose a listserv action.");
	document.listserv_form.listserv_action.focus();
    document.listserv_form.listserv_action.style.backgroundColor = err_color;
	return false;
	}
}
/* var check_val = class_year/class_year;
var check_length = class_year.length;
var date = new Date();
var year = date.getFullYear();
var first_two = class_year.substr(0,2);
var last_two = class_year.substr(2,2);
last_two = "Class" + last_two;
document.listserv_form.listserv_name.value = last_two;
if ((class_year > year) || (class_year < 1935) || (class_year >=1936 && class_year <=1939) ||  (class_year >=1942 && class_year <=1944))
	{
	document.listserv_form.listserv_name.value = "xxx1";
	}
if(check_val != 1)
	{
	document.listserv_form.listserv_name.value = "xxx2";
	}
if(check_length != 4)
	{
	document.listserv_form.listserv_name.value = "xxx3";
	}
}
*/
