//--------------------------------------------------------------------
// Module Name: validate.js
// Created by:  G. Ajamian
// Copywrite of G. Ajamian and the Arabic Baptist Church.
//--------------------------------------------------------------------
//
// This script is called when the Submit button is clicked to validate
// the form before p sending emails
//
//--------------------------------------------------------------------


//---------------------------------------------------------------
// private members
//---------------------------------------------------------------
// var tbl = document.getElementById('tblReg');
// var elementI = tbl.rows.length;

//---------------------------------------------------------------
// Validate the entire form.  Return false if something is wrong.
// Main Function
//---------------------------------------------------------------
function validateForm(frm) 
{
	var theElement;
	var bStatus = true;
	var bReceipientSelected = false;
	
	// Now make sure that all the fields in the frm contain a value
	// last field is the send button, so we don't need to validate it either.
	for (var i = 0; i < frm.elements.length - 1; i++) 
	{
		theElement = frm.elements[i];
		
//		alert (theElement.name);
		
		// first look for at least one checkboxe selected
		if (theElement.type.toLowerCase()=="checkbox")
		{
			if ( theElement.checked )
				bReceipientSelected = true;
		}
		
		// look for email address for validation
		else if (frm.elements[i].id == "EmailAddress")
		{
			if (!emailCheck(frm.EmailAddress.value)) 
				{ alertUser ("lbl_EmailAddressAlert"); bStatus = false; }
			else
				{ clearAlert ("lbl_EmailAddressAlert"); } 
		}
	
		// look for everything else
		else
		{
			if (theElement.value.length == 0)
				{ alertUser ("lbl_" + theElement.name + "Alert"); bStatus = false; }
			else
				{ clearAlert ("lbl_" + theElement.name + "Alert"); }
		}
	}
	
	if (bReceipientSelected)
		{ clearAlert ("lbl_SendMsgToAlert"); } 
	else
		{ alertUser ("lbl_SendMsgToAlert"); bStatus = false; }
	
	
	return bStatus;
}

//---------------------------------------------------------------
// Make sure that a required field is filled in.
//---------------------------------------------------------------
function alertUser(NameOfField) 
{
	document.getElementById(NameOfField).style.visibility = "visible";
}


//---------------------------------------------------------------
// Clear Alert if field is filled in.
//---------------------------------------------------------------
function clearAlert(NameOfField) 
{
	document.getElementById(NameOfField).style.visibility = "hidden";
}


//---------------------------------------------------------------
// PrintAck
//---------------------------------------------------------------
function PrintAck(frm)
{
	alert ("Thank you " + frm.Title.options[frm.Title.selectedIndex].value + 
			" " + frm.FirstName.value + " " + frm.LastName.value +
			"\n You will receive confirmation by e-mail." +
			"\n Please print a copy and bring with you to registration." );
}




