function ajaxClubList(field,updatediv) {
	
	//get search string
	var search = document.getElementById(field).value;
	
	search = search.replace("'","_");
		
		document.getElementById('clubSearch').style.display = "block";
		
		var params = "search=" + search;
		
		var myAjax = new Ajax.Updater(
	    			"clubSearch", 
	    			"ajaxSearch.htm?mode=club", 
	    			{method: "get", onFailure: notifyFailure, 
	    			parameters: "mode=club&search=" + search });
	    
}
function closeClubSearch() {

	document.getElementById('clubSearch').style.display = "none";
}

function notifyFailure(originalRequest)
{
  alert("Failed AJAX Request.")
    
}
function saveEntrantClub() {

	var dropdownIndex = document.getElementById('clubs_found').selectedIndex;
	var dropdownValue = document.getElementById('clubs_found')[dropdownIndex].value;
	var dropdownText = document.getElementById('clubs_found')[dropdownIndex].text;
	
	//hide drop down
	document.getElementById('clubSearch').style.display = "none";
	
	if(document.getElementById('clubLookup.id') == null) {
		
		document.getElementById('clubName').value = dropdownText;
		document.getElementById('entry.club.id').value = dropdownValue;
		
	} else {
		// update hidden field with id
		document.getElementById('clubLookup.id').value = dropdownValue;
		// put text in drop down
		document.getElementById('clubLookup.name').value = dropdownText
	}
}

function validate_form(form) {

	with (form) {
		
		/**
			Check for Blanks
		*/
		if (validate_required(fname,"Your First Name is Required") == false) {
			fname.focus();
			return false;
		}
		if (validate_required(fsname,"Your Surname is Required") == false) {
			fsname.focus();
			return false;
		}
		if (fcat.selectedIndex == 0) {
			alert("An age category must be specified");
			fcat.focus();
			return false;
		}
		if (validate_required(femail,"An email address must be supplied") == false) {
			femail.focus();
			return false;
		}
		if (validate_required(fcemail,"Please confirm your email address") == false) {
			fcemail.focus();
			return false;
		}

		// Check Email
		if (femail.value != fcemail.value) {
			alert("Please ensure both your email and confimation email address are the same and correct.");
			fcemail.focus();
			return false;
		}
		if (!isValidEmail(femail.value)) {
			alert("Your email address does not appear to be valid");
			femail.focus();
			return false;			
		}

		if (validate_required(faddr1,"Please supply an address") == false) {
			faddr1.focus();
			return false;
		}
		if (validate_required(fcity,"Please supply a city") == false) {
			fcity.focus();
			return false;
		}
		if (validate_required(fpcode,"Please supply a post code") == false) {
			fpcode.focus();
			return false;
		}

		if (fagree[0].checked==false ) {
			alert("You must agree to the terms and conditions");
			return false;
		}
	}

	// got here so success
	return true;
}

function validate_required(field,alerttxt) {
	var fieldvalue;
	fieldvalue = field.value.trim();
		
	if (fieldvalue==null||fieldvalue=="") {
		alert(alerttxt);
		return false;
		
	} else {
		return true
	}
}

function isValidEmail(str) {
   var dot;
   dot = str.indexOf(".");
   var at;
   at = str.indexOf("@");

   if ((dot > 0) && (at > 0)) {
		return true;
   } else {
		return false;
	}
 //  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
