function checkrequired(which) {

var pass = true;
var num_chars = 9;

if (document.images) {

	for (i = 0; i < which.length; i ++) {
	var tempobj = which.elements[i];

		if (tempobj.name.substring(0,num_chars) == "required_") {
			if (((tempobj.type == "text" || tempobj.type == "textarea") &&
				tempobj.value == '') || (tempobj.type.toString().charAt(0) == "s" &&
				tempobj.selectedIndex == 0)) {
				pass = false;
				break;
      }
    }
  }
}

if (!pass) {
	shortFieldName = tempobj.name.substring(num_chars,30).toUpperCase();
	alert("Please enter a value in the " + shortFieldName + " field.");
	return false;
}
else
	return true;
}// end function


function validate_form(theForm)
{
	var i = 0;
	var t = "";
	var n = "";
	var num_chars = 9;


	// Validate release
	if( theForm.Release.value != "I Accept" )
	{
		alert("You must accept the release by typing \"I Accept\" without the quotes in the text box provided.\n\nIf you do not accept the agreement you may not sign up.");
		theForm.Release.focus();
		return false;
	}

	for( i = 0; i < theForm.length; i++ )
	{
		t = theForm.elements[i].value;
		n = theForm.elements[i].name;

		if( t == "" && n.substring(0,num_chars) == "required_")
		{
			alert("You must fill in your " + Replace(n.substring(num_chars), "_", " ") + "!");
			theForm.elements[i].focus();
			return false;
		}
	}

	// validate email address
	var addr = theForm.required_Email_Address;

	var arr = addr.value.split('@');

	if( arr.length != 2 )
	{
		alert("You have not entered at valid email address. (format)");
		addr.focus();
		return false;
	}

	if( !valid_email_name( arr[0] ) )
	{
		alert("You have not entered at valid email address. (username)");
		addr.focus();
		return false;
	}

	if( !valid_domain( arr[1] ) )
	{
		alert("You have not entered at valid email address. (domain)");
		addr.focus();
		return false;
	}



	return true;
}

function valid_domain(strDomain)
{
	// These the only valid characters allowed in a domain name...
	// besides periods...
	var i = 0;
	//strDomain = strDomaun.toLowerCase();
	var arr = strDomain.split(".");

	if( arr.length < 2 )
	{
		return false;
	}

	for( i = 0; i < arr.length; i++ )
	{
		if( !valid_domain_field( arr[i] ) )
		{
			return false;
		}
	}

	return true;
}

function valid_domain_field(strField)
{
	var valid = "abcdefghijklmnopqrstuvwxyx0124567890-";
	var i = 0, m = 0;
	var isValid = false;

	strField = strField.toLowerCase();

	if( strField == "" )
		return false; // if periods are together at end or beginning, there will be blanks

	for( i = 0; i < strField.length; i++ )
	{
		isValid = false;
		for( m = 0; m < valid.length; m++ )
		{
			if( strField.charAt(i) == valid.charAt(m) )
			{
				isValid = true;
				break;
			}
		}
		if( !isValid )
			return false;
	}

	return true;
}

function valid_email_name(strName)
{
	var valid = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
	var isValid = false;
	var i = 0;
	var m = 0;
	var c;

	strName = strName.toLowerCase();

	if( strName == "" )
		return false; // Bad @ placement...

	for( i = 0; i < strName.length; i++ )
	{

		c = strName.charAt(i);
		isValid = false
		for( m = 0; m < valid.length; m++ )
		{
			if( c == valid.charAt(m) )
			{
				isValid = true;
				break;
			}
		}

		if( !isValid )
			return false;

	}
	return true;
}

function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;

	while( ( a = temp.indexOf(Find) ) > -1 )
	{
		temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}
