var objGetClubs = {
	handleClubSuccess:function(o) {
		elmReturn = this.getElement(this.strReturnField);
		
		if (o.responseText != 0) {
			elmReturn.innerHTML = o.responseText;
		}
		else {
			alert('Association not found.');
		}		
	},
	
	handleClubFailure:function(o) {
		alert(o.statusText);		
	},
	
	startClubRequest:function(strField, strReturnField, intSec, bolAllClubs, strName) {
		if (intSec == null) {
			intSec = 1;
		}
		if (bolAllClubs == null) {
			bolAllClubs = 0;
		}
		if (strName == null) {
			strName = '';
		}
		this.strReturnField = strReturnField;
		strValue = this.getClubFormValue(strField);
		
		this.clearClubResponse();
		getHost();
		YAHOO.util.Connect.asyncRequest('POST', 'http://www.britishorienteering.org.uk/getClubs.php', varClubCallback, 'id='+strValue+'&useSec='+intSec+'&allclub='+bolAllClubs+'&name='+strName);
	},
	
	getClubFormValue:function(strField) {
		elmField = this.getElement(strField);
		
		return elmField[elmField.selectedIndex].value;		
	},
	
	getElement:function(strField) {
		return document.getElementById(strField);
	},
	
	clearClubResponse:function() {
		this.getElement(this.strReturnField).innerHTML = '';
	}
};

var varClubCallback = {
	success:objGetClubs.handleClubSuccess,
	failure:objGetClubs.handleClubFailure,
	scope:objGetClubs
};

function getClubs(strField, strReturnField, intSec, bolAllClubs, strName) {
	objGetClubs.startClubRequest(strField, strReturnField, intSec, bolAllClubs, strName);
}
function getHost() {
	var url = window.location.href;
	var arrParts = url.split('/');
	arrParts[(arrParts.length-1)]='';
	return arrParts.join('/');
}

