function echeck( str ) 
{
	var at   = "@"
	var dot  = "."
	var lat  = str.indexOf(at)
	var lstr = str.length
	var ldot = str.indexOf(dot)

	if ( str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr )
    {
	   return false
	}

	if ( str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr )
    {
		return false
	}
    
    if ( str.indexOf(at,(lat+1)) != -1 )
    {
		return false
	}

	if ( str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot )
    {
		return false
	}

	if ( str.indexOf(dot,(lat+2)) == -1 )
    {
		return false
	}
	
	if ( str.indexOf(" ") != -1 )
    {
		return false
	}

 	return true					
}

function ValidateVolunteerForm( givenname, familyname, emailaddress, homeaddress, phoneOne, phoneTwo )
{
    if ( givenname.value == null || givenname.value == "" )
    {
		alert("Please enter your given name (also known as first name)")
		givenname.focus()
		return false        
    }
    
    if ( familyname.value == null || familyname.value == "" )
    {
		alert("Please enter your family name (also known as last name)")
		familyname.focus()
		return false        
    }

    if ( emailaddress.value == null || emailaddress.value == "" )
    {   
        if ( homeaddress.value == null || homeaddress.value == "" )
        {
            if ( phoneOne.value == null || phoneOne.value == "" )
            {
                if ( phoneTwo.value == null || phoneTwo.value == "" )
                {
            		alert("Please ensure you have entered at least one way for Don's campaign to contact you")
		            emailaddress.focus()
		            return false        
                }
            }
        }
    }

    if ( emailaddress.value != null && emailaddress.value != "" )
    {
        if ( echeck( emailaddress.value ) == false )
        {
		    alert("Please enter a valid email address")
		    emailaddress.focus()
		    return false
	    }
    }

    return true;
}

function ValidateSignRequestForm( nameID, postalID, emailID, phoneID )
{
    if ( nameID.value == null || nameID.value == "" )
    {
		alert("Please enter your name")
		nameID.focus()
		return false        
    }

    if ( postalID.value == null || postalID.value == "" )
    {
		alert("Please enter your address, where we will deliver the sign")
		nameID.focus()
		return false        
    }

	if ( emailID.value == null || emailID.value == "" )
    {
        if ( phoneID.value == null || phoneID.value == "" )
        {
            alert("Please provide an email address or phone number so the sign team can get in contact with you if necessary")
	        phoneID.focus()
	        return false
        }
	}
    else
    {
        if ( echeck( emailID.value ) == false )
        {
		    alert("Please enter a valid email address")
		    emailID.focus()
		    return false
	    }
    }

	return true
}

function ValidateForm( nameID, emailID, phoneID, postalID, messageID )
{
    if ( nameID.value == null || nameID.value == "" )
    {
		alert("Please enter your name")
		nameID.focus()
		return false        
    }

    if ( messageID.value == null || messageID.value == "" )
    {
		alert("Please enter your message for Don")
		messageID.focus()
		return false        
    }

	if ( emailID.value == null || emailID.value == "" )
    {
        if ( phoneID.value == null || phoneID.value == "" )
        {
            if ( postalID.value == null || postalID.value == "" )
            {
		        alert("Please enter at least one way for Don to get in contact with you")
		        phoneID.focus()
		        return false
            }
        }
	}
    else
    {
        if ( echeck( emailID.value ) == false )
        {
		    alert("Please enter a valid email address")
		    emailID.focus()
		    return false
	    }
    }

	return true
}

