function valCancel()
{
	var checkit = confirm("Do you really want to cancel your membership?" + '\n' + "OK to continue; otherwise Cancel")
	return (checkit);
}

function chekMessage(theForm)
{
	if (theForm.Subject.value == "")
	{
		alert("Please enter the Subject");
		theForm.Subject.focus();
		return (false);
	}
	
	var myRegExpr = new RegExp("^([A-Z0-9]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Subject.value))
	{
	    alert("Please enter only letters, number, space, apostrophe or hyphen in the Subject field.");
	    theForm.Subject.focus();
	    return (false);
	}	
	
	if (theForm.Recipient.value == 0)
	{
		alert("Please select a Recipient");
		theForm.Recipient.focus();
		return (false);
	}
	
	if (theForm.Comment.value == "")
	{
		alert("Please enter the Message");
		theForm.Comment.focus();
		return (false);
	}
}

function valResponse(theForm)
{
	var anyChecked=false;
	var sMessage;
	if(theForm.OptType.value==1)
	{
		sMessage = "Please select an option";
		for (i=0;i<theForm.OptCount.value;i++)
		{
			if (theForm.Response[i].checked) anyChecked=true;
		}				
	}
	else
	{
		sMessage = "Please select at least one option";
		for (i=0;i<theForm.OptCount.value;i++)
		{
			if (document.getElementById('Response'+i).checked) anyChecked=true;
		}
	}

	if (!anyChecked) alert (sMessage)
	return (anyChecked);
}

function massMailVal(theForm)
{

  if (theForm.Message.value == "")
  {
  		alert("Please enter a message");
    	theForm.Message.focus();
    	return (false);
  }
  
  if (theForm.B1.value == "Send Email")
  {
  		var checkit = confirm("Do you really want to send an email to all members?" + '\n' + "OK to continue; otherwise Cancel")
  		if (!checkit)
  		{
  			return (checkit);
  		}
  }
}

function optionVal(theForm)
{
	if (theForm.EmailAddr.value == "")
	{
		alert("Please enter a value in the Email field.");
		theForm.EmailAddr.focus();
		return (false);
	}
  
	var myRegExpr = new RegExp("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$","gi");
	if (!myRegExpr.test(theForm.EmailAddr.value))
	{
		alert("This does not appear to be a valid email address.")
	    theForm.EmailAddr.focus();
	    return (false);
	}
}

function chekReply(theForm)
{
	if (theForm.Comment.value == "")
	{
		alert("Please enter your Comment");
		theForm.Comment.focus();
		return (false);
	}	
	return (true)
}

function chekSurvey(theForm)
{
	if (theForm.Subject.value == "")
	{
		alert("Please enter the Topic");
		theForm.Subject.focus();
		return (false);
	}
	
	var myRegExpr = new RegExp("^([A-Z0-9]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Subject.value))
	{
	    alert("Please enter only letters, number, space, apostrophe or hyphen in the Topic field.");
	    theForm.Subject.focus();
	    return (false);
	}	
	
	if (theForm.Comment.value == "")
	{
		alert("Please enter the Question");
		theForm.Comment.focus();
		return (false);
	}
		
	try{
	if (!theForm.Audience[0].checked && !theForm.Audience[1].checked)
		{
			alert("Please select the Audience for this discussion");
			return (false);
		}
	}catch(e){}
		
	if (!theForm.OptType[0].checked && !theForm.OptType[1].checked)
	{
		alert("Please select the Option Type for this survey");
		return (false);
	}
	
	var optEntered = 0;
	var x;
	
	for (i=0;i<10;i++)
	{
		x = document.getElementById('Option'+i).value;
		if(x!='') 
		{		
			myRegExpr.compile("^([A-Z0-9]+[ ]?|[-]?)+$","gi");
			if (!myRegExpr.test(x))
			{
			    alert("Please enter only letters, numbers, spaces, hyphens in the Option field.");
			    document.getElementById('Option'+i).focus();
			    return (false);
			}		
			optEntered++;				
		}		
	}
	
	if (optEntered<2)
	{
		alert("Please enter at least two options")
		return (false);
	}
	
	return (true)
}

function chekDisc(theForm)
{
	if (theForm.Subject.value == "")
	{
		alert("Please enter the Subject");
		theForm.Subject.focus();
		return (false);
	}
	
	var myRegExpr = new RegExp("^([A-Z0-9]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Subject.value))
	{
	    alert("Please enter only letters, number, space, apostrophe or hyphen in the Site Name field.");
	    theForm.Subject.focus();
	    return (false);
	}	
	
	if (theForm.Comment.value == "")
	{
		alert("Please enter the Initial Comment");
		theForm.Comment.focus();
		return (false);
	}
		
	try{
	if (!theForm.Audience[0].checked && !theForm.Audience[1].checked)
		{
			alert("Please select the Audience for this discussion");
			return (false);
		}
	}catch(e){}
		
	return (true)
}

function valNotice(theForm)
{
	if (theForm.Subject.value=="")
	{
		alert("Please enter Subject.");
		theForm.Subject.focus();
		return (false);
	}
	
	var myRegExpr = new RegExp("^([A-Z0-9]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Subject.value))
	{
	    alert("Please enter only letters, numbers, spaces, apostrophe or hyphen in the Subject field.");
	    theForm.Subject.focus();
	    return (false);
	}  
	
	if (theForm.Description.value=="")
	{
		alert("Please enter Text.");
		return (false);
	}
	
	try{
	if (!theForm.Audience[0].checked && !theForm.Audience[1].checked)
		{
			alert("Please select the audience for this link");
			return (false);
		}
	}catch(e){}
	
}

function mailVal(theForm)
{
	if (theForm.Name.value == "")
	{
	alert("Please enter your name.");
	theForm.Name.focus();
	return (false);
	}
	
	var myRegExpr = new RegExp("^([A-Z]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Name.value))
	{
	    alert("Please enter only letters, spaces, apostrophe or hyphen in the Name field.");
	    theForm.Name.focus();
	    return (false);
	}
  
	if (theForm.EmailAddr.value == "")
	{
		alert("Please enter a value in the Email field.");
		theForm.EmailAddr.focus();
		return (false);
	}
  
	myRegExpr.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$","gi");
	if (!myRegExpr.test(theForm.EmailAddr.value))
	{
		alert("This does not appear to be a valid email address.")
	    theForm.EmailAddr.focus();
	    return (false);
	}
  
	if (theForm.Subject.value == "")
	{
		alert("Please enter subject.");
		theForm.Subject.focus();
		return (false);
	}
	
	myRegExpr.compile("^([A-Z]+[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Subject.value))
	{
	    alert("Please enter only letters, spaces, hyphens in the Subject field.");
	    theForm.Subject.focus();
	    return (false);
	}
	
	if (theForm.Comment.value == "")
	{
		alert("Please enter your message.");
		theForm.Comment.focus();
		return (false);
	}
	return (true);
}

function chekLinks(theForm)
{
	if (theForm.LinkName.value == "")
	{
		alert("Please enter the Site Name");
		theForm.LinkName.focus();
		return (false);
	}
	
	var myRegExpr = new RegExp("^([A-Z0-9/()]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.LinkName.value))
	{
	    alert("Please enter only letters, number, space, apostrophe or hyphen in the Site Name field.");
	    theForm.LinkName.focus();
	    return (false);
	}	
	
	if (theForm.LinkURL.value == "")
	{
		alert("Please enter the URL");
		theForm.LinkURL.focus();
		return (false);
	}
	
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789/:?=.";
    var checkStr = theForm.LinkURL.value;
    var allValid = true;
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
        allValid = false;
        break;
      }
    }
    if (!allValid)
    {
      alert("The value entered contains an invalid character: "+ch);
      theForm.LinkURL.focus();
      return (false);
    }
	
	var myLink = theForm.LinkURL.value.toLowerCase();
	if (myLink.indexOf("http://") != 0 && myLink.indexOf("https://") != 0)
	{
		alert("The value entered appears to be invalid");
		theForm.LinkURL.focus();
		return (false);
	}
	
	try{
	if (!theForm.Audience[0].checked && !theForm.Audience[1].checked)
		{
			alert("Please select the audience for this link");
			return (false);
		}
	}catch(e){}
		
	return (true)
}

function logonVal(theForm)
{
  if (theForm.UserName.value == "")
  {
    alert("Please enter your User Name.");
    theForm.UserName.focus();
    return (false);
  }
   
  if (theForm.UserPassword.value == "")
  {
    alert("Please enter your Password.");
    theForm.UserPassword.focus();
    return (false);
  }
  
 return (true);
}

function valForgot(theForm)
{
	if (theForm.Email.value == "")
	{
	alert("Please enter a value in the \"Email Address\" field.");
	theForm.Email.focus();
	return (false);
	}
  
	var myRegExpr = new RegExp("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$","gi");
	if (!myRegExpr.test(theForm.Email.value))
	{
		alert("This does not appear to be a valid email address.")
	    theForm.Email.focus();
	    return (false);
	}
	
	return (true);
}

function registerVal(theForm)
{
	if (theForm.FirstName.value == "")
	{
	alert("Please enter First Name.");
	theForm.FirstName.focus();
	return (false);
	}
  
	var myRegExpr = new RegExp("^([A-Z]+[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.FirstName.value))
	{
	    alert("Please enter only letters, spaces or hyphens in the First Name field.");
	    theForm.FirstName.focus();
	    return (false);
	} 

	if (theForm.Surname.value == "")
	{
	alert("Please enter Surname.");
	theForm.Surname.focus();
	return (false);
	}
  
	myRegExpr.compile("^([A-Z]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Surname.value))
	{
	    alert("Please enter only letters, spaces, apostrophe or hyphen in the Surname field.");
	    theForm.Surname.focus();
	    return (false);
	}
	
	if (theForm.Email.value == "")
	{
		alert("Please enter a value in the Email field.");
		theForm.Email.focus();
		return (false);
	}
  
	myRegExpr.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$","gi");
	if (!myRegExpr.test(theForm.Email.value))
	{
		alert("This does not appear to be a valid email address.")
	    theForm.Email.focus();
	    return (false);
	}
	
	if (theForm.FlatNum.value == 0)
	{
		alert("Please select Flat Number.");
		theForm.FlatNum.focus();
		return (false);
	}
	
	if (!theForm.Status[0].checked && !theForm.Status[1].checked && !theForm.Status[2].checked)
	{
		alert("Please select your Status.");
		return (false);
	}

	if (theForm.Status[1].checked)
	{
		if (theForm.Address.value=="")
		{
			alert("Please enter Address.");
			theForm.Address.focus();
			return (false);
		}
		
		if (theForm.Postcode.value=="")
		{
			alert("Please enter Postcode.");
			theForm.Postcode.focus();
			return (false);
		}
		else
		{	
			myRegExpr.compile("^[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,1}[ ]{1,1}[0-9]{1,1}[A-Z]{1,2}$","gi");
			if (!myRegExpr.test(theForm.Postcode.value))
			{
				alert("This does not appear to be a valid postcode")
			    theForm.Postcode.focus();
			    return (false);
			}
		}
	}
	
	if (!theForm.Terms.checked)
	{
		alert("Please confirm that you have read and agree to Terms.");
		return (false);
	}	
		
	return (true);
}

function personalVal(theForm)
{
  
	if (theForm.FirstName.value == "")
	{
	alert("Please enter First Name.");
	theForm.FirstName.focus();
	return (false);
	}
  
	var myRegExpr = new RegExp("^([A-Z]+[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.FirstName.value))
	{
	    alert("Please enter only letters, spaces or hyphens in the First Name field.");
	    theForm.FirstName.focus();
	    return (false);
	}  
	
	if (theForm.Surname.value == "")
	{
	alert("Please enter Surname.");
	theForm.Surname.focus();
	return (false);
	}
  
	myRegExpr.compile("^([A-Z]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Surname.value))
	{
	    alert("Please enter only letters, spaces, apostrophe or hyphen in the Surname field.");
	    theForm.Surname.focus();
	    return (false);
	}
	
	if (theForm.Nickname.value != "")
	{
		myRegExpr.compile("^([A-Z0-9]+[&]?|[-]?)+$","gi");
		if (!myRegExpr.test(theForm.Nickname.value))
		{
		    alert("Please enter only letters, numbers, dash or ampersand in Alias field.");
		    theForm.Nickname.focus();
		    return (false);
		}
	}
	
	if (theForm.MemberType.value == "3")
	{
		if (theForm.Address.value=="")
		{
			alert("Please enter Address.");
			theForm.Address.focus();
			return (false);
		}
		
		if (theForm.Postcode.value=="")
		{
			alert("Please enter Postcode.");
			theForm.Postcode.focus();
			return (false);
		}
		else
		{	
			myRegExpr.compile("^[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,1}[ ]{1,1}[0-9]{1,1}[A-Z]{1,2}$","gi");
			if (!myRegExpr.test(theForm.Postcode.value))
			{
				alert("This does not appear to be a valid postcode")
			    theForm.Postcode.focus();
			    return (false);
			}
		}	
	}

	
	if (theForm.LogonName.value.length < 6)
	{
	    alert("Please enter a Logon Name (min 6 character).");
	    theForm.LogonName.focus();
	    return (false);
	}
		
	myRegExpr.compile("^([A-Z0-9]+[-]?)+$","gi");
	if (!myRegExpr.test(theForm.LogonName.value))
	{
	    alert("Please enter only letters, numbers or dashes in Logon Name field.");
	    theForm.LogonName.focus();
	    return (false);
	}
  
	if (theForm.Password.value.length < 6)
	{
		alert("Please enter at least 6 characters in the Password field.");
		theForm.Password.focus();
		return (false);
	}
	
	myRegExpr.compile("^([A-Z0-9]+[_]?)+$","gi");
	if (!myRegExpr.test(theForm.Password.value))
	{
	    alert("Please enter only letters, numbers or underscore in the Password field.");
	    theForm.Password.focus();
	    return (false);
	}

	if (theForm.Password.value != theForm.PasswordCheck.value)
	{
		alert("The two Password fields are not identical. Please re-enter");
		theForm.Password.value= "";
		theForm.PasswordCheck.value= "";
		theForm.Password.focus();
		return (false);
	}
	return (true)
 }

function chekArticleDel(theForm)
{
	if(theForm.ArticleID.value == 0)
	{
		alert("Please select an article if you wish to delete");
		theForm.ArticleID.focus();
		return false;
	}
	else
	{
		var doIt;
		doIt = confirm("Do you really want to delete this document?\nOK to proceed; otherwise cancel");
		if (!doIt)
		{
			return false;
		}
	}
	return true;
}

function chekArticleAdd(theForm)
{
	if (theForm.Article.value == "")
	{
		alert("Please select a file to upload");
		theForm.Article.focus();
		return false;
	}
	
    if (theForm.Article.value != "")
    {
      var str = theForm.Article.value.toLowerCase();
      var len = str.length;
      var pos = len - 4;
      if (str.substr(pos,4) != '.pdf' && str.substr(pos,4) != '.doc' 
      && str.substr(pos,4) != '.rtf' && str.substr(pos,4) != '.txt')
      {
        alert("Invalid file type chosen. PDF, DOC, RTF or TXT only.");
        theForm.Article.focus();
        return false;
      }
    }
    	
	if (theForm.Title.value == "")
	{
		alert("Please enter a title for the article");
		theForm.Title.focus();
		return false;
	}
	
	var myRegExpr = new RegExp("^([A-Z0-9]+[']?|[ ]?|[-]?)+$","gi");
	if (!myRegExpr.test(theForm.Title.value))
	{
	    alert("Please enter only alphanumeric, space, apostrophe or hyphen in the Title field.");
	    theForm.Title.focus();
	    return (false);
	}	
	
	try{
	if (!theForm.Audience[0].checked && !theForm.Audience[1].checked)
		{
			alert("Please select the audience for this document");
			return (false);
		}
	}catch(e){}
	  
    return true;
}
