function validateEmail(theForm, theInput, theErrDiv, validateNotNull)
{
	if (theErrDiv != '') theErrDiv = document.getElementById(theErrDiv)
	if(theForm != '')
	{
		theInput =  eval('document.forms["'+theForm+'"].'+theInput)
	}else{
		theInput = eval("document.getElementById('"+theInput+"')")
	}
	
	//Validate not null
	if ((theInput.value == "")&&(validateNotNull == 1))
	{
		if (theErrDiv != '') theErrDiv.style.display = ""
		theInput.focus ()
		return false
	}
		
	//Check that there is only one @
	var validEmail = true
	var theAtIndex = theInput.value.indexOf('@')
	
	if (theAtIndex == -1 || theAtIndex == theInput.value.length - 1  || theAtIndex != theInput.value.lastIndexOf('@')) //There is no @ or it is at the end of the email or there is more than one @
	{
		validEmail = false
	}
	
	//Get the last dot index
	var theLastDotIndex = theInput.value.lastIndexOf('.')
	if (theLastDotIndex == -1 || theLastDotIndex == theInput.value.length - 1) //There is no . or it is at the end of the email
	{
		validEmail = false
	}
	
	//check that there is text between the @ and the last dot
	if(theAtIndex == theLastDotIndex -1)
	{
		validEmail = false
	}

	//check that there is text before the @
	if(theAtIndex == 0)
	{
		validEmail = false
	}


	if(!validEmail && theInput.value != '')
	{	
		if (theErrDiv != '') theErrDiv.style.display = ""
		theInput.focus()
		return false
	}

	return true
	
}
