function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
 if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function check_email(field1,field2,alertxt)
{
	var email = field1;
	var email2 = field2;
	
	if(email.value != email2.value) {
		alert(alertxt);return false;}
		else {return true;}
}

function check_rules(field,alerttxt)
{
with (field)
  {
	if(field.checked == false) {
		alert(alerttxt); return false;}
		else { return true;}
  }
}

function validate_form(thisform)
{
with (thisform)
{
//delegate number check
  //if (validate_required(txtDelNo,"Please provide your Strictly Woodturning Delegate No (ie. STR123456")==false)
  //{txtDelNo.focus();return false}
//title check
  if (validate_required(title,"Please select a title")==false)
  {title.focus();return false} 
//firstname check
  if (validate_required(txtName,"Please enter your firstname")==false)
  {txtName.focus();return false} 
//surname check 
  if (validate_required(txtSurname,"Please enter your surname")==false)
  {txtSurname.focus();return false} 
//address check 
  if (validate_required(txtAddress,"Please enter your address")==false)
  {txtAddress.focus();return false} 
//post code check  
  if (validate_required(txtPostCode,"Please enter your post code")==false)
  {txtPostCode.focus();return false} 
//phone number check  
  if (validate_required(txtPhone,"Please provide a contact number")==false)
  {txtPhone.focus();return false} 
//e-mail check  
  if (validate_email(txtEmail,"Please provide a valid email address")==false)
  {txtEmail.focus();return false} 
//confirmation e-mail check    
  if (validate_email(valEmail,"Please confirm your email address") == false)
  {valEmail.focus();return false}
//check both e-mails
  if (check_email(txtEmail, valEmail,"Confirm email must match email")==false)
  {valEmail.focus();return false}
//check entry description 
  if (validate_required(txtEntryDesc,"Please provide a description of your entry") == false)
  {txtEntryDesc.focus();return false}
//check entry dimensions
  if (validate_required(txtEntryDim,"Please provide the dimensions of your entry") == false)
  {txtEntryDim.focus();return false}
//check both terms
  if (check_rules(chkRules, "Please confirm you have read and understand the rules of entry")==false)
  {chkRules.focus(); return false}
}
}
