function onLoadScript()
{
	document.onkeyup = checkFields;
}
		
function checkAddressRegex()
{
	var validRegex = /^[-a-zA-Z0-9][-a-zA-Z0-9\._]*[-a-zA-Z0-9]@[-a-zA-Z0-9][-a-zA-Z0-9]*[-a-zA-Z0-9\._]*\.[a-zA-Z0-9][a-zA-Z0-9]*$/
	var testString = new String;
	testString = document.getElementById("RegistrationForm").emaila.value;
	return !(testString.match(validRegex) == null);
}

function checkFields()
{
	var valid = true;
	var errortext = "";
	
	//firstname	
	if(document.getElementById("RegistrationForm").firstname.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_firstname").style.background = "#ffefe0";
		errortext += "Enter your first name<br />";
	}
	else
	{
		document.getElementById("row_firstname").style.background = "#ffffff"; 
	}
	
	//lastname
	if(document.getElementById("RegistrationForm").lastname.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_lastname").style.background = "#ffefe0";
		errortext += "Enter your last name<br />";
	}
	else
	{
		document.getElementById("row_lastname").style.background = "#ffffff"; 
	}
	
	
	//company
	if(document.getElementById("RegistrationForm").company.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_company").style.background = "#ffefe0";
		errortext += "Enter your company<br />";
	}
	else
	{
		document.getElementById("row_company").style.background = "#ffffff"; 
	}

	//addressline1
	if(document.getElementById("RegistrationForm").addressline1.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_addressline1").style.background = "#ffefe0";
		document.getElementById("row_addressline2").style.background = "#ffefe0";
		errortext += "Enter your address name<br />";
	}
	else
	{
		document.getElementById("row_addressline1").style.background = "#ffffff"; 
		document.getElementById("row_addressline2").style.background = "#ffffff"; 
	}

	//city
	if(document.getElementById("RegistrationForm").city.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_city").style.background = "#ffefe0";
		errortext += "Enter your city<br />";
	}
	else
	{
		document.getElementById("row_city").style.background = "#ffffff"; 
	}
	
	
	//state
	if(document.getElementById("RegistrationForm").state.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_state").style.background = "#ffefe0";
		errortext += "Enter your state or province<br />";
	}
	else
	{
		document.getElementById("row_state").style.background = "#ffffff"; 
	}
	
	//country
	if(document.getElementById("RegistrationForm").state.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_country").style.background = "#ffefe0";
		errortext += "Enter your country<br />";
	}
	else
	{
		document.getElementById("row_country").style.background = "#ffffff"; 
	}
	
	//zip
	if(document.getElementById("RegistrationForm").postalcode.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_postalcode").style.background = "#ffefe0";
		errortext += "Enter your ZIP/Postal Code<br />";
	}
	else
	{
		document.getElementById("row_postalcode").style.background = "#ffffff"; 
	}
	
	//email	
	if (document.getElementById("RegistrationForm").emaila.value.length > 0)
	{
		if (!checkAddressRegex())
		{
			valid = false;
			document.getElementById("emailblock").innerHTML = "Invalid e-mail address";
			
			document.getElementById("row_emaila").style.background = "#ffefe0";
			document.getElementById("row_emailb").style.background = "#ffffff";
		}
		else
		{
			if (document.getElementById("RegistrationForm").emaila.value == document.getElementById("RegistrationForm").emailb.value)
			{
				document.getElementById("emailblock").innerHTML = "Addresses match";
				document.getElementById("row_emaila").style.background = "#ffffff";
				document.getElementById("row_emailb").style.background = "#ffffff";				
			}
			else
			{
				valid = false;
				
				document.getElementById("emailblock").innerHTML = "Addresses do not match";
				document.getElementById("row_emaila").style.background = "#ffffff";
				document.getElementById("row_emailb").style.background = "#ffefe0";
			}
		}
	}
	else
	{
		valid = false;
		document.getElementById("emailblock").innerHTML = "Enter e-mail address twice";
		document.getElementById("row_emaila").style.background = "#ffefe0";
		document.getElementById("row_emailb").style.background = "#ffefe0";
	}
	
	// source
	if(document.getElementById("RegistrationForm").source.value.length < 2) 
	{ 
		valid = false;
		document.getElementById("row_source").style.background = "#ffefe0";
		errortext += "Enter the source where you learned of the RetroKit<br />";
	}
	else
	{
		document.getElementById("row_source").style.background = "#ffffff"; 
	}

	
	document.getElementById("errorblock").innerHTML = errortext;
	
	return valid;
}