﻿function change_background(id)
{
	document.getElementById(id).style.background="#C0EAA6";
}

function reset_background(id)
{
	document.getElementById(id).style.background="#FBFAE9";
}

function over_submit(id)
{
	document.getElementById(id).style.border="2px inset";
}

function out_submit(id)
{
	document.getElementById(id).style.border="2px outset";
}


function check_email ()
{
	var email = document.forms['form1'].email.value;
	var length = email.length;
	var result = true;
	var at_first_position = email.indexOf("@") + 1;
	var at_last_position = email.lastIndexOf("@") + 1;
	var dot_first_position = email.indexOf(".") + 1;
	var dot_last_position = email.lastIndexOf(".") + 1;
	if ((at_first_position == at_last_position)					/* Only one "@" */
			&& (at_first_position != 1)							/* "@" is not the first character */
			&& (dot_first_position != 1)						/* "." is not the first character  */
			&& (dot_last_position < length)						/* "." is not the last character  */
			&& ((at_first_position - dot_first_position) != 1)
					/* If there is a "." before the "@", there is an other character between both*/
			&& ((at_first_position + 1) < dot_last_position)
					/* There is a "." after the "@" and a charcater between both*/
			&& (length >= 7))									/*The email adress is 7 char. long or more*/
	{
		/*alert("Your email is correct.");*/
		null;
	}
	else
	{
		
		text = (text + "Please enter a valid mail adress. \n" );
		correct = "Error";
		return false;
	}
}



function check_filled (id)
{
	/*var element_value = document.forms['form1'].element.value;
	alert("AAAAAAA15/06/2007");
	var element_length = element_value.length;
	alert("Re");*/
	var element = document.getElementById(id);
	if ((element.value != "") && (element.value != " "))
	{
		null;
	}
	else
	{
		text = (text + "Please fill in the following field: " + id + ". \n" );
		correct = "Error";
		return false;
	}
}

	var text = "";
	var correct = "Correct";


function oldboys() {
	check_filled("name");
	check_filled("tel");
	check_filled("years");
	check_email();

	if (correct == "Correct") {
		return true;
	}
	else {
		alert(text);
		text = "";
		correct = "Correct";
		return false;
	}
}

function checkPasswords() {
	if (document.getElementById("password1").value == document.getElementById("password2").value && document.getElementById("password1").value != "") {
		return true;
	}
	alert("Please ensure both passwords are the same");
	return false;
}

function checkLogin() {
	check_filled("name");
	check_filled("postcode");

	if (correct == "Correct")
	{
		return true;
	}
	else
	{
		alert(text);
		text = "";
		correct = "Correct";
		return false;
	}

}

function check_submit ()
{
	check_filled("name");
	check_filled("email");
	check_filled("comment");
	check_email();
	if (correct == "Correct")
	{
		return true;
	}
	else
	{
		alert(text);
		text = "";
		correct = "Correct";
		return false;
	}
}
