var isHomePage = true;

function validateInformed()
{
	if($('informedAddress1'))
	{
		isHomePage = false;
	}else
	{
		isHomePage = true;
	}

	var f = document.informed;
	var hasErrors = false;
	
	hideInformedErrors();
	
	if(f.informedFirstName.value == '')
	{
		hasErrors = true;
		
		$('informedFirstNameError').style.fontWeight = 700;
		$('informedFirstNameError').style.color = 'red';
	}
	
	if(f.informedLastName.value == '')
	{
		hasErrors = true;
		
		$('informedLastNameError').style.fontWeight = 700;
		$('informedLastNameError').style.color = 'red';
	}	
	
	if(!validateEmail(f.informedEmail.value))
	{
		hasErrors = true;
		
		$('informedEmailError').style.fontWeight = 700;
		$('informedEmailError').style.color = 'red';
	}
	
	if(!isHomePage)
	{
		//if(f.informedAddress1.value == '')
		//{
		//	hasErrors = true;
		//	
		//	$('informedAddress1Error').style.fontWeight = 700;
		//	$('informedAddress1Error').style.color = 'red';
		//}
		
		//if(f.informedCity.value == '')
		//{
		//	hasErrors = true;
		//	
		//	$('informedCityError').style.fontWeight = 700;
		//	$('informedCityError').style.color = 'red';
		//}
		
		//if(f.informedState.selectedIndex == 0)
		//{
		//	hasErrors = true;
		//	
		//	$('informedStateError').style.fontWeight = 700;
		//	$('informedStateError').style.color = 'red';
		//}
		
		if(f.informedZip.value.length < 5)
		{
			hasErrors = true;
			
			$('informedZipError').style.fontWeight = 700;
			$('informedZipError').style.color = 'red';
		}
	}
	
	if(hasErrors)
	{
		/* DO NOTHING */
	}else
	{
		$('informedSubmitDisp').update('Sending...');
		f.submit();
	}
}

function hideInformedErrors()
{
	try
	{
		$('informedFirstNameError').style.fontWeight = 400;
		$('informedFirstNameError').style.color = '#0b283d';
		$('informedLastNameError').style.fontWeight = 400;
		$('informedLastNameError').style.color = '#0b283d';
		$('informedEmailError').style.fontWeight = 400;
		$('informedEmailError').style.color = '#0b283d';
		
		if(!isHomePage)
		{
			//$('informedAddress1Error').style.fontWeight = 400;
			//$('informedAddress1Error').style.color = '#0b283d';
			//$('informedCityError').style.fontWeight = 400;
			//$('informedCityError').style.color = '#0b283d';
			//$('informedStateError').style.fontWeight = 400;
			//$('informedStateError').style.color = '#0b283d';
			$('informedZipError').style.fontWeight = 400;
			$('informedZipError').style.color = '#0b283d';
		}
	}catch(e)
	{
		alert(e.message);
	}
}

function validateEmail(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	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					
}