searchCallbackFunction = null;

toggleTemporaryGolflinkNo = function(field)
{
	field.value = field.value == '9999999999' ? '' : '9999999999';
}

validateGolflinkNo = function(golflinkNoField, allowTemporary)
{
	var golflinkNo = golflinkNoField.value;

	if (golflinkNo == null)
	{
		return;
	}	
	if (golflinkNo.length > 0 && golflinkNo.length < 10)
	{
		alert('Warning - Golflink number must be 10 digits');
		return;
	}
	for (var i = 0; i < golflinkNo.length; i++) 
    {
        var ch = golflinkNo.charAt(i)
        if (i == 0 && ch == "-")
        {
            continue
        }
        if (ch < "0" || ch > "9")
        {
    		alert('Warning - Golflink number must only contain digits');
            return;
        }
    }
    if (!allowTemporary && golflinkNo.indexOf('99999') == 0)
    {
		alert('Error - Temporary Golflink number entered');
    }
}

searchGolflink = function(golflinkNo, callbackFunction, beforSearch)
{
	if (golflinkNo == null || golflinkNo == '')
	{
		alert('Error - Golflink number must be entered');
		return;
	}	
	
	if (beforSearch != null && beforSearch != null)
	{
		eval(beforSearch);
	}
	searchCallbackFunction = callbackFunction;
 	sendCommonUpdate('getVisitorDetails', 'golflinkNo=' + golflinkNo, onSuccess, null, {asynchronous: false});
}

visitorDetails = function(visitorXml)
{
	this.firstname=getTagContent(visitorXml, "FirstName");
	this.lastname=getTagContent(visitorXml, "Surname");
	this.exactHandicap=getTagContent(visitorXml, "ExactHandicap");
	this.genderCode=getTagContent(visitorXml, "GenderCode");
	this.golflinkNo=getTagContent(visitorXml, "GolflinkNo");
	this.homeClubId=getTagContent(visitorXml, "HomeClubId");
	this.isHomeClub=getTagContent(visitorXml, "IsHomeClub");
	this.membershipNumber = getTagContent(visitorXml, "MembershipNumber");

	this.getFullname = getFullname;

	function getFullname()
	{
		return this.firstname + ' ' + this.lastname;
	}
}


onSuccess = function(transport)
{
	var visitors = getFromTransport(transport,"VisitorDetail");

	for (var i = 0; i < visitors.length; i++) 
	{	
		var visitor = new visitorDetails(visitors[i]);
		
		if (searchCallbackFunction != 'null' && searchCallbackFunction != '')
		{
			searchCallbackFunction(visitor);
		}
	}
}
