		function myTrim(theString)
		{
			var trimStr = "";
			for (i = 0; i <= theString.length; ++i)
				{
					if (theString.charAt(i) != " ")
						{
							trimStr += theString.substring(i, i+1);
						}
				}
			return trimStr;
		}	

function myTel(TrimmedTel) 
{
				var cheTel = "";
				for (i = 0; i <= TrimmedTel.length; ++i)
					{
						if (TrimmedTel.charAt(i) != "+")
							{
								cheTel += TrimmedTel.substring(i, i+1);
							}
					}
			return cheTel;

}
		function ValidateForm()
		{
						
			if (myTrim(document.theForm.title.value).length == 0)
			{
				alert("The field 'Title' is required");
				document.theForm.title.value = "";
				document.theForm.title.focus();
				return false;
			}
			if (myTrim(document.theForm.name.value).length == 0)
			{
				alert("The field 'Name' is required");
				document.theForm.name.value = "";
				document.theForm.name.focus();
				return false;
			}
			if (myTrim(document.theForm.surname.value).length == 0)
			{
				alert("The field 'Surname' is required");
				document.theForm.surname.value = "";
				document.theForm.surname.focus();
				return false;
			}
			
			if (myTrim(document.theForm.gg[document.theForm.gg.selectedIndex].value).length == 0)
			{
				alert("Insert a valid birth's date");
				document.theForm.gg.focus();
				return false;
			}
			
			if (myTrim(document.theForm.mm[document.theForm.mm.selectedIndex].value).length == 0)
			{
				alert("Insert a valid birth's date");
				document.theForm.mm.focus();
				return false;
			}
		
			if (myTrim(document.theForm.aaaa.value).length == 0)
			{
				alert("Insert a valid birth's date");
				document.theForm.aaaa.value = "";
				document.theForm.aaaa.focus();
				return false;
			}
			else if (isNaN(document.theForm.aaaa.value) || (document.theForm.aaaa.value.length > 4))
			{
				alert("Insert a valid birth's date");
				document.theForm.aaaa.value = "";
				document.theForm.aaaa.focus();
				return false;
			}

			if (document.theForm.gg.value!='' && document.theForm.mm.value!='' && !isNaN(document.theForm.aaaa.value) && !isValidDate(document.theForm.gg.value+"/"+document.theForm.mm.value+"/"+document.theForm.aaaa.value))
			{
				alert("Insert a valid birth's date");
				document.theForm.gg.focus();
				return false;
			}

			if (myTrim(document.theForm.nationality.value).length == 0)
			{
				alert("The field 'Nationality' is required");
				document.theForm.nationality.value = "";
				document.theForm.nationality.focus();
				return false;
			}
			
			if (myTrim(document.theForm.positionheld.value).length == 0)
			{
				alert("The field 'Position held' is required");
				document.theForm.positionheld.value = "";
				document.theForm.positionheld.focus();
				return false;
			}
	
			if (myTrim(document.theForm.institution.value).length == 0)
			{
				alert("The field 'Institution' is required");
				document.theForm.institution.value = "";
				document.theForm.institution.focus();
				return false;
			}
			
			if (myTrim(document.theForm.mail.value).length == 0)
			{
				alert("The field 'Mailing address' is required");
				document.theForm.mail.value = "";
				document.theForm.mail.focus();
				return false;
			}
			
			if (myTrim(document.theForm.city.value).length == 0)
			{
				alert("The field 'City' is required");
				document.theForm.city.value = "";
				document.theForm.city.focus();
				return false;
			}
	
			if (myTrim(document.theForm.zipcode.value).length == 0)
			{
				alert("Insert a Zip code");
				document.theForm.zipcode.value = "";
				document.theForm.zipcode.focus();
				return false;
			}
			else if (/*isNaN(document.theForm.zipcode.value) || */(document.theForm.zipcode.value.length < 2))
			{
				//alert("Insert a valid Zip code");
				alert("Zip code must be at least 5 chars");
				document.theForm.zipcode.value = "";
				document.theForm.zipcode.focus();
				return false;
			}
	
			if (myTrim(document.theForm.country[document.theForm.country.selectedIndex].value).length == 0)
			{
				alert("Select a country");
				document.theForm.country.focus();
				return false;
			}
			
			if (myTrim(document.theForm.telephone.value).length == 0)
			{
				alert("Insert a telephone number");
				document.theForm.telephone.value = "";
				document.theForm.telephone.focus();
				return false;
			}
			else 
			{
				document.theForm.telephone.value=myTrim(document.theForm.telephone.value);
				
				cheTel = myTel (document.theForm.telephone.value);

				if (isNaN(cheTel))
				{
					alert("Insert a valid telephone number\n(country code+area code+telephone number)");
					document.theForm.telephone.value = "";
					document.theForm.telephone.focus();
					return false;
				}
			}
			
			if (myTrim(document.theForm.fax.value).length == 0)
			{
				alert("Insert a fax number");
				document.theForm.fax.value = "";
				document.theForm.fax.focus();
				return false;
			}
			else 
			{
				document.theForm.fax.value=myTrim(document.theForm.fax.value);
				
				cheFax = myTel (document.theForm.fax.value);

				if (isNaN(cheFax))
				{
					alert("Insert a valid fax number");
					document.theForm.fax.value = "";
					document.theForm.fax.focus();
					return false;
				}
			}
			
			if (myTrim(document.theForm.email.value).length == 0)
			{
				alert("Insert an email address");
				document.theForm.email.focus();
				return false;
			}
			else if (document.theForm.email.value.indexOf(".") == -1 || document.theForm.email.value.indexOf("@") == -1)
			{
				alert("Insert a valid email address");
				document.theForm.email.focus();
				return false;
			}
			
			var ifIschecked = false;
			
			for (i=0;i<document.theForm.member.length;i++)
			{
				if (document.theForm.member[i].checked == true) ifIschecked = true;			
			}
			
			if (!ifIschecked)
			{
				alert("Select a type member");
				//document.theForm.member.focus();
				return false;
			}


					if ((document.theForm.member[0].checked == true ) && (myTrim(document.theForm.membersince.value).length == 0))
					{
						alert("Insert an year");
						//document.theForm.membersince.focus();
						return false;
					}
					else if (isNaN(document.theForm.membersince.value))
					{
						alert("Insert a valid year");
						document.theForm.membersince.value = "";
						document.theForm.membersince.focus();
						return false;
					}
					
					
					var ifIschecked2 = false;
					
					for (i=0;i<document.theForm.membershipcategory.length;i++)
					{
						if (document.theForm.membershipcategory[i].checked == true) ifIschecked2 = true;			
					}
					
					if (!ifIschecked2)
					{
						alert("Select a category member'");
						document.theForm.membershipcategory.focus();
						return false;
					}

			return true;
		}	

function isValidDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
var matchArray = dateStr.match(datePat); 
	
	if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
	}
	
day = matchArray[1]; 
month = matchArray[3];
year = matchArray[4];

	if (month < 1 || month > 12) {
		alert("Month must be between 1 and 12.");
		return false;
	}
	
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false
	}
	
	if (month == 2) { 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
		}
	}
	
	return true; 
}

	function ValidateForm3()
		{
						
			if (myTrim(document.theForm.org.value).length == 0)
			{
				alert("The field 'Name of Applying Organisation' is required");
				document.theForm.org.value = "";
				document.theForm.org.focus();
				return false;
			}
			if (myTrim(document.theForm.name.value).length == 0)
			{
				alert("The field 'Name of Contact Person' is required");
				document.theForm.name.value = "";
				document.theForm.name.focus();
				return false;
			}
			if (myTrim(document.theForm.address.value).length == 0)
			{
				alert("The field 'Address for communications' is required");
				document.theForm.address.value = "";
				document.theForm.address.focus();
				return false;
			}
		
			if (myTrim(document.theForm.telephone.value).length == 0)
			{
				alert("Insert a telephone number");
				document.theForm.telephone.value = "";
				document.theForm.telephone.focus();
				return false;
			}
			else if (isNaN(document.theForm.telephone.value))
			{
				alert("Insert a valid telephone number");
				document.theForm.telephone.value = "";
				document.theForm.telephone.focus();
				return false;
			}
			
			if (myTrim(document.theForm.fax.value).length == 0)
			{
				alert("Insert a fax number");
				document.theForm.fax.value = "";
				document.theForm.fax.focus();
				return false;
			}
			else if (isNaN(document.theForm.fax.value))
			{
				alert("Insert a valid fax number");
				document.theForm.fax.value = "";
				document.theForm.fax.focus();
				return false;
			}
			
			if (myTrim(document.theForm.email.value).length == 0)
			{
				alert("Insert an email address");
				document.theForm.email.focus();
				return false;
			}
			else if (document.theForm.email.value.indexOf(".") == -1 || document.theForm.email.value.indexOf("@") == -1)
			{
				alert("Insert a valid email address");
				document.theForm.email.focus();
				return false;
			}
			
			if (myTrim(document.theForm.website.value).length == 0)
			{
				alert("The field 'Website' is required");
				document.theForm.website.value = "";
				document.theForm.website.focus();
				return false;
			}
			
			if (myTrim(document.theForm.regaddr.value).length == 0)
			{
				alert("The field 'Registered address' is required");
				document.theForm.regaddr.value = "";
				document.theForm.regaddr.focus();
				return false;
			}
			
			if (myTrim(document.theForm.typeorg.value).length == 0)
			{
				alert("The field 'Type of Organisation' is required");
				document.theForm.typeorg.value = "";
				document.theForm.typeorg.focus();
				return false;
			}
			
			if (myTrim(document.theForm.aims.value).length == 0)
			{
				alert("The field 'Aims' is required");
				document.theForm.aims.value = "";
				document.theForm.aims.focus();
				return false;
			}
			
			if (myTrim(document.theForm.members.value).length == 0)
			{
				alert("The field 'Names and titles of Board members' is required");
				document.theForm.members.value = "";
				document.theForm.members.focus();
				return false;
			}
			
			if (myTrim(document.theForm.formed.value).length == 0)
			{
				alert("The field 'Year in which organisation was formed' is required");
				document.theForm.formed.value = "";
				document.theForm.formed.focus();
				return false;
			}
			else if (isNaN(document.theForm.formed.value))
			{
				alert("Insert a valid year");
				document.theForm.formed.value = "";
				document.theForm.formed.focus();
				return false;
			}
			
			if (myTrim(document.theForm.registered.value).length == 0)
			{
				alert("The field 'Year in which organisation was registered' is required");
				document.theForm.registered.value = "";
				document.theForm.registered.focus();
				return false;
			}
			else if (isNaN(document.theForm.registered.value))
			{
				alert("Insert a valid year");
				document.theForm.registered.value = "";
				document.theForm.registered.focus();
				return false;
			}
			
			if (myTrim(document.theForm.affiliations.value).length == 0)
			{
				alert("The field 'Other affiliations/memberships' is required");
				document.theForm.affiliations.value = "";
				document.theForm.affiliations.focus();
				return false;
			}
			
			return true;
		}	