function checkEmail(email) {



  var str = new String(email);

  var isOK = true;

  rExp = /[!\"£$%\^&*()-+=<>,\'#?\\|¬`\/\[\]]/

  if( rExp.test(str) )

    isOK = false;

  if( str.indexOf('.') == -1 || str.indexOf('@') == -1 )

    isOK = false;

  if( str.slice(str.lastIndexOf('.')+1,str.length).length < 2 )

    isOK = false;

  if( str.slice(0,str.indexOf('@')).length < 1 )

    isOK = false;

  if( str.slice(str.indexOf('@')+1,str.lastIndexOf('.')).length < 1 )

    isOK = false;



  if( !isOK )

    alert( "Invalid email address" );



  return isOK;

}



function clear_form() {

	//document.form1.email.value="";

	//document.form1.password.value="";

	//document.form1.email.style.backgroundColor = "#FFFFFF";

	//document.form1.password.style.backgroundColor = "#FFFFFF";

}



function submit_form(form,target) {

	

	

	//emailMatches();

	var thisform=document.getElementById(form);

	if (allCellsFilledIn(thisform)==true) {

		if(emailMatches()==true)

		{

			if(passwordMatches()==true)

			{

				email1=document.getElementById("email1").value;

				if(checkEmail(email1))

				{

					thisform.action=target;

					thisform.submit();

				}

			}

		}

		

		

	}

	

}

function submit_form2(form,target) {

	

	

	//emailMatches();

	var thisform=document.getElementById(form);

	if (allCellsFilledIn(thisform)==true) {

		thisform.action=target;

		thisform.submit();

	}

	

}





function submit_form_nocheck(form,target) 

{

	var thisform=document.getElementById(form);

	thisform.action=target;

	thisform.submit();

}





function emailMatches()

{



	//document.getElementById("feedback").innerHTML="Got here";

	var bCheck;

	bCheck=false;

	email1=document.getElementById("email1").value;

	email2=document.getElementById("email2").value;



	if(!(email1==email2))

	{

		document.getElementById("feedback").innerHTML="The two email addresses must match!";

		document.getElementById("email1").style.backgroundColor="#FFCCCC";

		document.getElementById("email2").style.backgroundColor="#FFCCCC";

		return(false);

	} else

	{

		return(true);

		}



}



function passwordMatches()

{



	//document.getElementById("feedback").innerHTML="Got here";

	//alert("got here");

	var bCheck;

	bCheck=false;

	password1=document.getElementById("password1").value;

	password2=document.getElementById("password2").value;



	if(!(password1==password2))

	{

		document.getElementById("feedback").innerHTML="The two passwords must match!";

		document.getElementById("password1").style.backgroundColor="#FFCCCC";

		document.getElementById("password2").style.backgroundColor="#FFCCCC";

		return(false);

	} else

	{

		return(true);

		}



}





function allCellsFilledIn(form) {



var bCheck;

bCheck=false;

	for (var i=0; i < form.length; i++) {

		thisElement=form[i];

	if((form.elements[i].type == "text" || form.elements[i].type=="password") ) {

			thisElement.style.backgroundColor = "#FFFFFF";

		}

	} 



 	for (var i=0; i < form.length; i++) {

		thisElement=form[i];

		if((form.elements[i].type == "text" || form.elements[i].type=="password") && trimString(form.elements[i].value) == "") {

			name=thisElement.name;
			if(name.indexOf("nocheck")==-1)
			{
				thisElement.style.backgroundColor = "#FFCCCC";

				form.elements[i].focus();

				bCheck=true;
			}

		} //end if 

	} //end for 



	if (bCheck) {

		jErrorMessage="Please put in values for the elements highlighted ";

		document.getElementById("feedback").innerHTML=jErrorMessage;

		return (false);

	}

	else 

	{

		return (true);

	}

	

}





function trimString (str) {

  str = this != window? this : str;

  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');

}