//--   JAVASCRIPT FOR AUCTION TICKET ORDER FORM  +++  SECTION 1  +++    ---------------------------------------------------------------------


//-- set focus when page loads  -------------------------------------------------------
document.editor.sentbyname.focus();

//-- error messages  -------------------------------------------------------
var namemsg = "Contact Name  has not been given"; 
var locationmsg = "City / State has not been given"; 

var emailmsg0 = "No email address has been given";
var emailmsg = "Invalid email address has been given";

var subjectmsg = "Subject of letter has not been given";
var contentmsg = "No content has been written";


//-- validate form on submission  -------------------------------------------------------
function validateMe()
{	 
	//--  get values from form
	var sendername = document.editor.sentbyname.value;
	var senderlocation = document.editor.sentbylocation.value;
	
	var emailOK = true;
	var email = document.editor.sentbyemail.value;
	
	var subject = document.editor.commentssubject.value;
	var comments = document.editor.comments.value;

		
//-- clear previous error markers
	for ( var i = 0; i < document.editor.elements.length-2; i++ )
		{  document.editor.elements[ i ].style.backgroundColor = "";		}


//-- verify that name field is completed  ------------------------
	if ( !sendername ) 
		{ 	document.editor.sentbyname.style.backgroundColor = errcolor;
			document.editor.sentbyname.focus();
			anon_pop( namemsg, 'sentbyname' );
			return false;
		}

//-- validate email field  -------------------------------------------------------	
	//-- if email address is given, check to see if it is valid
	if ( !email )
		{   emailOK = false;		}
		
	if ( !emailOK ) 
		{  	document.editor.sentbyemail.style.backgroundColor = errcolor;
		   anon_pop( emailmsg0, 'sentbyemail' );
		   return false;
		 }   //-- end if block  [ emailOK ]

	
	//-- if email address is given, check to see if it is valid
	if ( email != "" )
		{   emailOK = validateEmail( email );		}
		
	if ( !emailOK ) 
		{  	document.editor.sentbyemail.style.backgroundColor = errcolor;
			document.editor.sentbyemail.select();
		   anon_pop( emailmsg, 'sendbyemail' );
		   return false;
		 }   //-- end if block  [ emailOK ]


//-- verify that location field is completed  ------------------------
	if ( !senderlocation ) 
		{ 	document.editor.sentbylocation.style.backgroundColor = errcolor;
			document.editor.sentbylocation.focus();
			anon_pop( locationmsg, 'sentbylocation' );
			return false;
		}

//-- verify that subject field is completed  ------------------------
	if ( !subject ) 
		{ 	document.editor.commentssubject.style.backgroundColor = errcolor;
			document.editor.commentssubject.focus();
			anon_pop( subjectmsg, 'commentssubject' );
			return false;
		}

//-- verify that letter content field is completed  ------------------------
	if ( !comments ) 
		{ 	document.editor.comments.style.backgroundColor = errcolor;
			document.editor.comments.focus();
			anon_pop( contentmsg, 'comments' );
			return false;
		}

	return true;

}	//-- end function  [ validateMe ]



//-- validate email address  -------------------------------------------------------
//--  min req. for email is 6 chars, which are:  4 - alpha/numeric, 1 - at  '@' sign, and 1 - period
function validateEmail ( address )
{
	var toggle = true;

	if ( address == "" ) 
		{ return toggle;	}
	
  if ( ( address.indexOf("@") == -1 ) || ( address.indexOf(".") == -1 ) || ( address.length <6 ) )
	{	toggle = false;	}

	return toggle;

}	//-- end function  [ validateEmail ]


