///////////////////////////////////////////////////////////////////////////////////////////////
//Delete Confirmation
///////////////////////////////////////////////////////////////////////////////////////////////

function DeleteConfirm(PageID,Type,TypeID){

	if (confirm("Are you sure you want to delete?")) {
		if (Type == "News") {
			location = '/cms/submit.asp?PageID='+PageID+'&NewsID='+TypeID+'&SubmitType=DeleteNews'
		} else if (Type == "Meeting") {
			location = '/cms/submit.asp?PageID='+PageID+'&MeetingID='+TypeID+'&SubmitType=DeleteMeeting'
			} else if (Type == "Section") {
			location = '/cms/cmshome.asp?cmsarea=sections&SectionID='+TypeID+'&SubmitType2=DeleteSection'
		} else {
			location = 'cms/submit.asp?PageID='+PageID+'&SubmitType=DeletePage'
		}
	} else {
		return false
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Delete Confirmation
///////////////////////////////////////////////////////////////////////////////////////////////

function DeleteAlert() {
	alert("Please make sure all child pages are deleted before deleting this page.")
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Form validation
///////////////////////////////////////////////////////////////////////////////////////////////

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validDate(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var elems = formField.value.split("/");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var day = parseInt(elems[0],10);
			var month = parseInt(elems[1],10);
 			var year = parseInt(elems[2],10);
			result =  allDigits(elems[0]) && (day > 0) && (day < 32) &&
					 allDigits(elems[1]) && (month > 0) && (month < 13) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Please enter a date in the format DD/MM/YYYY for the "' + fieldLabel +'" field.');
			formField.focus();		
		}
	} 
	
	return result;
}


	function checkpassword(theForm) {
		
		if (theForm.Name.value == "") {
			alert("You need to enter a Name")
			theForm.Name.focus()
			return false
		}
				
		if (theForm.Telephone.value == "") {
			alert("You need to enter a Telephone Number")
			theForm.Telephone.focus()
			return false
		}
		
		if (theForm.Birth.value == "") {
			alert("You need to enter a Birth Place")
			theForm.Birth.focus()
			return false
		}
		
		if (theForm.Email.value == "") {
			alert("You need to enter an Email Address")
			theForm.Email.focus()
			return false
		}
		
		if (theForm.Username.value == "") {
			alert("You need to enter a Username")
			theForm.Username.focus()
			return false
		}
	
		if (theForm.Password.value.length < 6) {
			alert("Your passwords needs to be greater than 6 characters")
			theForm.Password.focus()
			return false
		}
	
		if (theForm.Password.value != theForm.VerifyPassword.value) {
			alert("Your passwords don't match")
			return false
		}
		
		if (theForm.Password.value != theForm.VerifyPassword.value) {
			alert("Your passwords don't match")
			return false
		}
		
		if (theForm.Password.value != theForm.VerifyPassword.value) {
			alert("Your passwords don't match")
			return false
		}
		
		if (theForm.HintQuestion.value == "") {
			alert("You need to enter a Hint Question")
			theForm.HintQuestion.focus()
			return false
		}
		
		if (theForm.HintAnswer.value == "") {
			alert("You need to enter a Hint Answer")
			theForm.HintAnswer.focus()
			return false
		}
		
	}
	
	function checkpassword2(theForm) {
		
		if (theForm.Name.value == "") {
			alert("You need to enter a Name")
			theForm.Name.focus()
			return false
		}
				
		if (theForm.Telephone.value == "") {
			alert("You need to enter a Telephone Number")
			theForm.Telephone.focus()
			return false
		}
		
		if (theForm.Birth.value == "") {
			alert("You need to enter a Birth Place")
			theForm.Birth.focus()
			return false
		}
		
		if (theForm.Email.value == "") {
			alert("You need to enter an Email Address")
			theForm.Email.focus()
			return false
		}
		
		if (theForm.Username.value == "") {
			alert("You need to enter a Username")
			theForm.Username.focus()
			return false
		}
	
		if (theForm.Password.value.length < 6) {
			alert("Your passwords needs to be greater than 6 characters")
			theForm.Password.focus()
			return false
		}
	
		if (theForm.Password.value != theForm.VerifyPassword.value) {
			alert("Your passwords don't match")
			return false
		}
		
		if (theForm.Password.value != theForm.VerifyPassword.value) {
			alert("Your passwords don't match")
			return false
		}
		
		if (theForm.Password.value != theForm.VerifyPassword.value) {
			alert("Your passwords don't match")
			return false
		}
		
		if (theForm.HintQuestion.value == "") {
			alert("You need to enter a Hint Question")
			theForm.HintQuestion.focus()
			return false
		}
		
		if (theForm.HintAnswer.value == "") {
			alert("You need to enter a Hint Answer")
			theForm.HintAnswer.focus()
			return false
		}
		
		if (document.Users.frmBotDetectConfirm.value == "") {
			alert("Please enter the characters displayed in the image")
			return false
		}
		
	}
	
	function checkmemnumber() {
		if (document.Users.Name.value == "") {
			alert("You need to enter a Name")
			return false
		}
		if (document.Users.Birth.value == "") {
			alert("You need to enter a Birth Place")
			return false
		}
		if (document.Users.Email.value == "") {
			alert("You need to enter an Email Address")
			return false
		}
		return true
	}
	
	function checkenqform(theForm) {
		if (theForm.name.value == "") {
			alert("You need to enter a name")
			theForm.name.focus()
			return false
		}
		if (theForm.email.value == "") {
			alert("You need to enter an email")
			theForm.email.focus()
			return false
		}
		if (theForm.query.value == "" || theForm.query.value == "Type your query here...") {
			alert("You need to enter a query")
			theForm.query.focus()
			return false
		}
	}
	
	function checkemail(){
	
	if (document.emailform.subject.value == 0){
	
	alert("Please select a value in the subject dropdown");
	
	}else if (document.emailform.name.value == ""){
	
	alert("Please complete the name field");
	
	}else if (document.emailform.email.value == ""){
	
	alert("Please complete the email field");
	
	}else{
	
	document.emailform.submit()
	
	}
	
	}