function setAction(Action) {
	if (Action == "Print") {
		document.frmApplication.action = "ApplicationForm.asp?Action=Print&CompanyId=0&MemberId=0";
		return true;
	}
	else {
		FormAction = "App".concat(Action).concat(".asp");
		document.frmApplication.action = FormAction;
		document.frmApplication.Action.value = "Next";
		return true;
	}
}	
function validateForm(Action,MemberId) {
	//alert (Action);
	document.frmApplication.Action.value = Action;
	switch (Action) {
		case "Next":
			if (document.frmApplication.txtMemberNo.value == "") {
				alert ("Please Enter Membership Number for verification");
				document.frmApplication.txtMemberNo.select();
				document.frmApplication.txtMemberNo.focus();
				return false;
			}
		break;
		case "PayNow":
			//document.frmApplication.MemberId.value = MemberId;
			//document.frmApplication.target = "_blank";
			//document.frmApplication.action = "https://select.worldpay.com/wcc/purchase";
			//document.frmApplication.action = "https://secure-test.ims.worldpay.com/wcc/dispatcher";
			document.frmApplication.action = "GoToWorldPay.asp";
			document.frmApplication.submit();
		break;
		case "ReNew":
			document.frmApplication.MemberId.value = MemberId;
			document.frmApplication.custom.value = MemberId;
			document.frmApplication.chqPermission1.checked = true;
			document.frmApplication.chqPermission2.checked = true;

			return true;
		break;
		case "SectionA":
			if (document.frmApplication.txtFirstName.value == "" ) {
				alert ("Please Enter Members First Name or Initial");
				document.frmApplication.txtFirstName.select();
				document.frmApplication.txtFirstName.focus();
				return false;
			}
			if (document.frmApplication.txtSurname.value == "") {
				alert ("Please Enter Members Surname");
				document.frmApplication.txtSurname.select();
				document.frmApplication.txtSurname.focus();
				return false;
			}
		
			document.frmApplication.txtFirstName.value = ConvertString(document.frmApplication.txtFirstName.value, 3);
			document.frmApplication.txtSurname.value = ConvertString(document.frmApplication.txtSurname.value, 3);
			document.frmApplication.name.value = document.frmApplication.txtFirstName.value+" "+document.frmApplication.txtSurname.value; 
		break;
		case "SectionB":
			if (document.frmApplication.txtCompanyName.value == "") {
				alert ("Please Enter Company Name for Corporate Membership");
				document.frmApplication.txtCompanyName.select();
				document.frmApplication.txtCompanyName.focus();
				return false;
			}
			document.frmApplication.txtCompanyName.value = ConvertString(document.frmApplication.txtCompanyName.value, 5);
		break;
		case "Print":
			if (document.frmApplication.txtSurname != "" && document.frmApplication.txtAddress1.value != "" && document.frmApplication.txtCity.value != "" ) {
				document.frmApplication.Action.value = "SaveFirst";
				if (document.frmApplication.txtInitials.value == "" ) {
					alert ("Please Enter Member's Initials");
					document.frmApplication.txtInitials.select();
					document.frmApplication.txtInitials.focus();
					return false;
				}
				if (document.frmApplication.txtFirstName.value == "" ) {
					alert ("Please Enter Member's FirstName");
					document.frmApplication.txtFirstName.select();
					document.frmApplication.txtFirstName.focus();
					return false;
				}
				if (document.frmApplication.txtPostcode.value == "") {
					alert ("Please Enter the Postcode ")
					document.frmApplication.txtPostcode.select()
					document.frmApplication.txtPostcode.focus()
					return false;
				}
				if (document.frmApplication.txtHomePhone.value == "") {
					alert ("Please enter a contact phone number");
					document.frmApplication.txtHomePhone.select();
					document.frmApplication.txtHomePhone.focus();
					return false;
				}
			}
			else {
				document.frmApplication.Action.value = Action;
			}
			
		break;
	}
	if (Action != "SectionC" && Action != "Print" && Action != "ReNew" && Action != "PayNow" && Action != "Next") {
		if (document.frmApplication.txtAddress1.value == "") {
			alert ("Please Enter the first line of your Address ")
			document.frmApplication.txtAddress1.select()
			document.frmApplication.txtAddress1.focus()
			return false;
		}
		if (document.frmApplication.txtArea.value != "") {
			document.frmApplication.txtArea.value = ConvertString(document.frmApplication.txtArea.value, 3);
			}
		//if (document.frmApplication.txtCity.value == "") {
		//	alert ("Please Enter the City/Town ")
		//	document.frmApplication.txtCity.select()
		//	document.frmApplication.txtCity.focus()
		//	return false;
		//}
		if (document.frmApplication.txtPostcode.value == "") {
			alert ("Please Enter the Postcode ")
			document.frmApplication.txtPostcode.select()
			document.frmApplication.txtPostcode.focus()
			return false;
		}
		if (document.frmApplication.txtHomePhone.value == "" ) {
			alert ("Please enter a contact phone number")
			document.frmApplication.txtHomePhone.select()
			document.frmApplication.txtHomePhone.focus()
			return false;
		}
		if (document.frmApplication.MemberType.value == "") {
			alert ("Please Select Membership Type required");
			document.frmApplication.chqMType(0).select();
			document.frmApplication.chqMType(0).focus();
			return false;
		}
		if (document.frmApplication.MemberType.value != "1" && document.frmApplication.MemberType.value != "2") {
			if (document.frmApplication.txtFirstName2.value == "" && document.frmApplication.txtSurname2.value == "") {
				alert ("If you wish to apply for family membership please complete family member's details");
				document.frmApplication.txtFirstName2.select();
				document.frmApplication.txtFirstName2.focus();
				return false;
			}
		}
		if (MemberId == "") {
			if (document.frmApplication.chqPermission1.checked == false) {
				alert ("Application for membership can only be processed if you agree to observe the rules of the society");
				document.frmApplication.chqPermission1.select();
				document.frmApplication.chqPermission1.focus();
				return false;
			}
				if (document.frmApplication.chqPermission2.checked == false) {
				alert ("Application for membership can only be processed if give your permission to retain your details on the Membership Database");
				document.frmApplication.chqPermission2.select();
				document.frmApplication.chqPermission2.focus();
				return false;
			}
		}

}
	document.frmApplication.txtInitials.value = ConvertString(document.frmApplication.txtInitials.value, 1);
	document.frmApplication.txtTitle.value = ConvertString(document.frmApplication.txtTitle.value, 3);
	document.frmApplication.txtAddress1.value = ConvertString(document.frmApplication.txtAddress1.value, 3);
	document.frmApplication.txtArea.value = ConvertString(document.frmApplication.txtArea.value, 3);
	document.frmApplication.txtCity.value = ConvertString(document.frmApplication.txtCity.value, 3);
	document.frmApplication.address.value = document.frmApplication.txtAddress1.value+"\n"+document.frmApplication.txtArea.value+"\n"+document.frmApplication.txtCity.value+"\n"+document.frmApplication.txtCounty.value;
	document.frmApplication.txtCounty.value = ConvertString(document.frmApplication.txtCounty.value, 3);
	document.frmApplication.country.value = document.frmApplication.txtCountry.value;
	document.frmApplication.txtPostcode.value = ConvertString(document.frmApplication.txtPostcode.value, 1);
	document.frmApplication.postcode.value = ConvertString(document.frmApplication.txtPostcode.value, 1);
	document.frmApplication.txtHomeEmail.value = ConvertString(document.frmApplication.txtHomeEmail.value, 2);
	document.frmApplication.email.value = document.frmApplication.txtHomeEmail.value
	document.frmApplication.tel.value = document.frmApplication.txtHomePhone.value;
	document.frmApplication.txtWorkEmail.value = ConvertString(document.frmApplication.txtWorkEmail.value, 2);
	document.frmApplication.txtInterests.value = ConvertString(document.frmApplication.txtInterests.value,5);
	document.frmApplication.desc.value = "Membership Application - "+document.frmApplication.cartId.value;
	
	//alert (document.frmApplication.name.value);
if (Action != "Print") {
			//document.frmApplication.submit();
			//document.frmApplication.target = "_blank";
			//document.frmApplication.action = "https://select.worldpay.com/wcc/purchase";
			//document.frmApplication.action = "https://secure-test.ims.worldpay.com/wcc/dispatcher";
			document.frmApplication.action = "members/ConfirmApplication.asp";
} else {
	window.print();
}
	return true;
}

