// JavaScript Document

function form_check ()
{    
    var myFirst, myMI, myLast;
    myFirst=document.myform.txtFirstName.value;
    myMI=document.myform.txtMI.value;
    myLast=document.myform.txtLastName.value;

    //alert(j);
    var CO;
	CO=document.myform.txtCo.value;
	var Email, ConfirmEmail;
	Email=document.myform.txtEmail.value;
	ConfirmEmail=document.myform.txtConfirmEmail.value;
	var addr;
	addr=document.myform.txtAddr1.value;
	var phone;
	phone=document.myform.txtPhone.value;
	var state;
	state=document.myform.txtState.value;
	var city;
	city=document.myform.txtCity.value;
	
	if(myFirst == "")
	{
		alert("You Must Enter your First Name");
	    document.myform.txtFirstName.focus();
	    return false;	    
	}
	
	if(myLast == "")
	{
		alert("You Must Enter your Last Name");
	    document.myform.txtLastName.focus();
		return false;
	    
	}
	
	if(addr == "")
	{
		alert("Must enter an Address");

		document.myform.txtAddr1.focus();
		return false;		
	}
	
	if(city == "")
	{
		alert("Must enter a City");

		document.myform.txtCity.focus();
		return false;		
	}
    if(state == "")
	{
		alert("Must enter a State");
		document.myform.txtState.focus();
		return false;
		
	}
    
	if(event == "")
	{
		alert("Please pick an event.");
		document.myform.event.focus();
		return false;
		
	}
	
	if(phone == "")
	{
		alert("Must enter a Phone Number");
		document.myform.txtPhone.focus();
		return false;
		
	}
    
	if(Email == "")
	{
		alert("You Must Enter a Vaild Email");
	    document.myform.txtEmail.focus();
	    return false;
	    
	}
	
	if (ConfirmEmail == "")
	{
		alert("You Must Enter a Vaild Confirmed Email");
	    document.myform.txtConfirm.focus();
	    return false;
	    
	}
	
	if(!validEmail(document.myform.txtEmail.value))
	{	
		alert ("Your email address is not correctly formatted.");
		document.myform.txtEmail.focus();
		return false;
		
	}
	
	if (!(Email == ConfirmEmail))
	{
		alert("Your EMAIL and CONFIRM EMAIL must be the same.");
	    return false;
	    document.myform.txtEmail.focus();
	    return false;
	    
	}
	
	
	
}
function validEmail(email){
	var i;
	var invalidChars = new Array(":",":","/",",");
	var atPos;
	var periodPos;
	var SpaceLocation;		
	if(email=="")
	{
		alert("please enter email address");
		document.myform.txtEmail.focus();
		return false;
		document.myform.txtEmail.focus();
	}
		
	for (i=0; i<invalidChars.length; i++)
	{
		if(email.indexOf(invalidChars[i])!=-1)
		{
			alert("You cannot have a" +invalidChars[i]+ "in your email address.");
			return false;
		}
	}
	
	while(email.lastIndexOf(" ")== email.length-1)
	{
		email = email.substring(0,email.length-1);
	}	
	
	SpaceLocation=email.indexOf(" ");
	if (SpaceLocation!=-1)
	{
		alert("You cannont have a space in your email address");
	}	
	
	atPos=email.indexOf("@");
	if (atPos==-1)
	
	{
		alert("The email has no @ symbol.");
		return false;
	}
	
	periodPos=email.indexOf(".");
	if (periodPos==-1)
	
	{
		alert("no period symbol.");
		return false;
	}
	
	periodPos=email.lastIndexOf(".");
	if(atPos>periodPos)
	{
		alert("The @ should come before last perdiod in the email.");
		return false;
	}
	return true;
} 

		

