function showForm(form_id)
{
	var show_the_form = 
		window.document.getElementById(form_id);
	show_the_form.style.display = "block";
}

function checkSubscriptionFields(u, n, j)
{
	var u_ok = false;
	var n_ok = false;

	var chkstr = 
		"*abcdefghijklmnopqrstuvwxyz" + 
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "_";

//check name
	if (chkstr.indexOf(n.charAt(0)) > 0)
	{
		n_ok = true;
	}
	else
	{
		if (n.length > 0)
		{
			alert("Please enter a valid name.");
		}
		else
		{
			alert("Please enter your name.");
		}
	}

// check user
	if ((u.indexOf("@") > 0) && (u.indexOf(".") > 2) && (u.length > 4) && (chkstr.indexOf(u.charAt(0)) > 0))
	{
		u_ok = true;
	}
	else
	{
		alert("Please enter a valid e-mail address.");
	}

//join or leave
	if (u_ok && n_ok)
	{
		var form1 = window.document.getElementById("subscription");
		form1._browser_out.value =
			"/Students/Biomedical_Engineering_Society/submitted.html";
		if (j)
		{
			//SEND SUBSCRIBE E-MAIL
			form1._send_email1.value = 
				"/Students/Biomedical_Engineering_Society/mail/subscribe.dat";
			form1.outtext.value =
				"Your subscribe request has been submitted successfully.";
		}
		else
		{
			//SEND UNSUBSCRIBE E-MAIL
			form1._send_email1.value = 
				"/Students/Biomedical_Engineering_Society/mail/unsubscribe.dat";
			form1.outtext.value = 
				"Your unsubscribe request has been submitted successfully.";
		}
		return true;
	}
	else
	{
		return false;
	}

}

function checkCommentsFields(n, e, c, f)
{
	var n_ok = false;
	var e_ok = false;
	var c_ok = false;

	var chkstr = 
		"*abcdefghijklmnopqrstuvwxyz" + 
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "_";

//check name
	if (chkstr.indexOf(n.charAt(0)) > 0)
	{
		n_ok = true;
	}
	else
	{
		if (n.length > 0)
		{
			alert("Please enter a valid name.");
		}
		else
		{
			alert("Please enter your name.");
		}
	}

// check email
	if ((e.indexOf("@") > 0) && (e.indexOf(".") > 2) && (e.length > 4) && (chkstr.indexOf(e.charAt(0)) > 0))
	{
		e_ok = true;
	}
	else
	{
		alert("Please enter a valid e-mail address.");
	}

//check comments
	for (var i=1; i<chkstr.length-1 ; i++)
	{
		if (c.indexOf(chkstr.charAt(i)) >= 0)
		{
			c_ok = true;
			break;
		}
	}
	if (!c_ok)
	{
		if (c.length > 0)
		{
			alert("Please enter valid comments.");
		}
		else
		{
			alert("Please enter some comments.");
		}
	}

//join or leave
	if (n_ok && c_ok && e_ok)
	{
		var form2 = window.document.getElementById("contactform");
		form2._browser_out.value =
			"/Students/Biomedical_Engineering_Society/submitted.html";
		form2.outtext.value =
			"Your comments have been submitted successfully.";
		form2._send_email1.value =
			"/Students/Biomedical_Engineering_Society/mail/" + f;

		return true;
	}
	else
	{
		return false;
	}
}


function checkPresetRecip()
{
	var uri = window.document.location.href;
	var end_clipping;
	
	if (uri.indexOf("#") == -1)
	{
		end_clipping = uri.length;
	}
	else
	{
		end_clipping = uri.indexOf("#");
	}

	var clipped_uri = uri.substring(0, end_clipping);
	var split_uri = clipped_uri.split("?");
	var sel_obj = window.document.getElementById("recipient");

	if (split_uri.length == 2)
	{
		var param_str = split_uri[1];
		var split_param_str = param_str.split("=");
		
		if (split_param_str.length == 2);
		{
			var attr = split_param_str[0];
			var val = split_param_str[1];

			if ((attr == "recip") && ((val == "pres") || (val == "vp") || (val == "treas") || (val == "pchair") || (val == "mchair") || (val == "sophrep")))
			{
				var found = false;
				var counter = 1;							// start at 1 to avoid 'Unknown'

				while (!found)
				{
					if (sel_obj.options[counter].value == 
						val)
					{
						found = true;
						sel_obj.options[counter].selected = true;
					}
					else
					{
						counter++;
					}
				}
			}
		}
	}
}

function submitMailingListForm()
{
	var user_obj = window.document.getElementById("user");

	var name_obj = 
		window.document.getElementById("nm");

	var sub_radio = 
			window.document.getElementById("subscribe");
	var unsub_radio =
		window.document.getElementById("unsubscribe");

	var is_joining;

	if (sub_radio.checked)
	{	
		is_joining = true;
	}
	else if (unsub_radio.checked)
	{
		is_joining = false;
	}

	var go_nogo = false;
	go_nogo = 
		checkSubscriptionFields(user_obj.value, name_obj.value, is_joining);
	
	return go_nogo;
}

function submitContactForm()
{
	var commenter_obj = window.document.getElementById("commenter");
	var sender_obj = window.document.getElementById("sender");
	var checkbox_obj = window.document.getElementById("copy");
	var comments_obj = window.document.getElementById("comments");

	var selector = window.document.getElementById("recipient");

	var data_str = 
		selector.options[selector.selectedIndex].value;

	if (checkbox_obj.checked)
	{
		data_str += "-c";
	}

	data_str += ".dat";

	var confirmed = false;
	confirmed = 
		checkCommentsFields(commenter_obj.value, sender_obj.value, comments_obj.value, data_str);

	return confirmed;
}