// This javascript is very tightly coupled to the PlayerProfile.asp page
// Not preferable, but time constraints dictated...

var ajaxTarget = "GolferLookup.asp";
var userSearchedBy = ""
var validationMessage = "";

var xmlHttp;

var tableRowRemove = "<A onclick='removeClub(this);return false;' href=''>Remove</A>";

var startTime
var callAjaxTime
var ajaxResponseTime
var completeTime

//Auto-complete control in search by club for adding memberships
var mySearch = nitobi.combo.List.prototype.Search;

// This needs to be moved to the GolferLookup.asp page
var searchResultsTableStructure = "<table id='SelectClubTable' border='0' cellpadding='3' cellspacing='0' width='85%' align='center'>\n <thead>\n <tr class='SearchResultsHeaderRow'>\n <td width='18%'>&nbsp;</td>\n<td style='display:none' width='1%'></td>\n<td width='18%'>IGN</td>\n<td width='26%'>Name</td>\n<td width='11%'>Index</td>\n<td width='15%'>Rev Date</td>\n</tr>\n</thead>";

function pageLoad(){
	parseClubArray();

	//Mozilla browsers can't handle synchronous Ajax
	// this triggers functionality to validate the username uniqueness server side
	document.getElementById("userNameVerified").value = 'F';
	
	var errorInfo = document.getElementById("errorInfo").value;
	if (errorInfo.length!=0) {alert(errorInfo);}
	
	var sReturnUrl = document.getElementById("returnUrl").value;
	var formMode = document.getElementById("formMode").value;
	if ('saved'==formMode&&0!=sReturnUrl.length){
		window.parent.location.replace(sReturnUrl);
	}
	
}

function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; 
  with (document){ if (getElementById) obj = getElementById(objId); }
  if (obj){
	if (theValue == true || theValue == false)
	  eval("obj.style."+theProp+"="+theValue);
	else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}

function scrollToBottom(){
	var height;
	height = 10000;
	window.scrollTo(0,height);
}

function showClubSearchControls(){
	deselectAllSearchOptions();
	MM_changeProp('AddDeleteClubButtons','','display','none','DIV');
	MM_changeProp('ClubSearchControls','','display','block','DIV');
	// DWagner - 10/24/2008
	// Business wants to default to the search by Club option
	document.getElementById("selectByClubRadio").checked = true;
	showSearchControls('Club');
	// end DWagner - 10/24/2008
	scrollToBottom();
}

function showSearchControls(type){
	hideAllSearchDivs();
	userSearchedBy = type;
	switch(type){
		case "IGN":
			MM_changeProp('SelectByIGNDiv','','display','block','DIV');
			break;
		case "GolferNumber":
			MM_changeProp('SelectByGolferNumberDiv','','display','block','DIV');
			break;
		case "Association":
			MM_changeProp('SelectByAssociationDiv','','display','block','DIV');
			break;
		case 'Club':
			MM_changeProp('SelectByClubDiv','','display','block','DIV');
			// Initialize the auto-complete control
			initializeClubAutoComplete();
			try
			{
				$("SelectByClub_ClubSearch").object.SetFocus();
			}
			catch(e)
			{}
			break;
		case 'NonMember':
			MM_changeProp('SelectByNonMemberDiv','','display','block','DIV');
			break;
	}
	scrollToBottom();
}

function initializeClubAutoComplete()
{
	nitobi.loadComponent('SelectByClub_ClubSearch');
	nitobi.combo.List.prototype.Search = ExtendedSearch;
}

//user must type at least three characters in the auto-complete before it will search
// to change the number of required characters, update the length comparison
function ExtendedSearch(SearchSubstring, SearchColumnIndex, SearchCallback, CacheOnly)
{
	
	if (SearchSubstring.length >= 3)
	{
		mySearch.call(this, SearchSubstring, SearchColumnIndex, SearchCallback, CacheOnly);
	}
}


function addSelectedClub(selectedClub){
	var clubMembershipTable = document.getElementById("ClubMembership");
	var searchResultsTable = document.getElementById("SelectClubTable");
	var row=selectedClub.parentNode.parentNode.rowIndex;
	var selectedClubRow = searchResultsTable.rows[row];

	var rowCount = clubMembershipTable.rows.length;
	var newClub = clubMembershipTable.insertRow(rowCount);

	//Remove button				
	newClub.insertCell(0).innerHTML = tableRowRemove;

	//Home
	if (rowCount == 1) {
		newClub.insertCell(1).innerHTML = "Yes";
	}else{
		newClub.insertCell(1).innerHTML = "No";
	}
	//Club Name
	newClub.insertCell(2).innerHTML = selectedClubRow.cells[1].innerHTML;
	// IGN
	newClub.insertCell(3).innerHTML = selectedClubRow.cells[2].innerHTML;
	//Golfer name
	newClub.insertCell(4).innerHTML = selectedClubRow.cells[3].innerHTML;
	// Index
	newClub.insertCell(5).innerHTML = selectedClubRow.cells[4].innerHTML;
	//Revision Date
	newClub.insertCell(6).innerHTML = selectedClubRow.cells[5].innerHTML;
	// first row is the header row
	document.getElementById("clubCount").value = clubMembershipTable.rows.length - 1;				

	//Creates a dependency on the Forms.js
	dirtyForm =true;

	resetClubSearchControls();
}

function removeClub(club){
	var clubTable = document.getElementById("ClubMembership");
	var row=club.parentNode.parentNode.rowIndex;

	// Cannot delete home club if there are no other clubs in the profile
	if(clubTable.rows.length==2&&clubTable.rows[row].cells[1].innerHTML=="Yes"){
		alert("There must be at least one other club in your profile before you can remove your home club.");
		return false;
	}

	clubTable.deleteRow(row);

	dirtyForm =true;

	// first row is the header row
	document.getElementById("clubCount").value = clubTable.rows.length - 1;
	//set zero row to HomeClube
	if(clubTable.rows.length > 1){clubTable.rows[1].cells[1].innerHTML = "Yes";}
}

function resetClubSearchControls(){

	// reset the ajax results for the next search
	document.getElementById("SelectClub").innerHTML = "<br><span class='message'>Please wait while your request is processed...</span>";

	deselectAllSearchOptions();
	resetAllSearchCriteria();
	hideAllSearchDivs();
	MM_changeProp('AddDeleteClubButtons','','display','block','DIV');
	MM_changeProp('ClubSearchControls','','display','none','DIV');
	scrollToBottom();
}

function deselectAllSearchOptions(){
	document.getElementById("selectByIGNRadio").checked = false;
	//document.getElementById("selectByGolferNumberRadio").checked = false;
	//document.getElementById("selectByAssociationRadio").checked = false;
	document.getElementById("selectByClubRadio").checked = false;
	document.getElementById("selectByNonMemberRadio").checked = false;
}

function searchAgain(){
	showSearchControls(userSearchedBy);
	document.getElementById("SelectClub").innerHTML = "<br><span class='message'>Please wait while your request is processed...</span>";
	MM_changeProp('ClubSearchControls','','display','block','DIV');
}

function resetAllSearchCriteria(){
	document.getElementById("SelectByIGNText").value = "";
	document.getElementById("SelectByGolferNumber_StateText").value = "";
	document.getElementById("SelectByGolferNumber_ClubNameText").value = "";
	document.getElementById("SelectByGolferNumber_NumberText").value = "";
	document.getElementById("SelectByGolferNumber_SuffixText").value = "0";
	document.getElementById("SelectByAssociation_ClubNameText").value = "";
	document.getElementById("SelectByAssociation_AssociationSelect").selectedIndex="0";
	//document.getElementById("SelectByClub_StateText").value = "";
	//document.getElementById("SelectByClub_ClubNameText").value = "";
	document.getElementById("SelectByNonMember_AssociationSelect").selectedIndex="0";
	$("SelectByClub_ClubSearch").jsObject.SetTextValue('');
	$("SelectByClub_ClubSearch").jsObject.GetList().GetXmlDataSource().Clear();
}

function hideAllSearchDivs(){
	MM_changeProp('SelectByIGNDiv','','display','none','DIV');
	MM_changeProp('SelectByGolferNumberDiv','','display','none','DIV');
	MM_changeProp('SelectByAssociationDiv','','display','none','DIV');
	MM_changeProp('SelectByClubDiv','','display','none','DIV');
	MM_changeProp('SelectByNonMemberDiv','','display','none','DIV');
	MM_changeProp('SelectClubResults','','display','none','DIV');
}

function displayResults(searchType){
	startTime = Date();
	if (HasSearchCriteria(searchType)){
		hideAllSearchDivs();
		MM_changeProp('SelectClubResults','','display','block','DIV');
		MM_changeProp('ClubSearchControls','','display','none','DIV');
	
		if (haveXmlHttp()==true){
			switch(searchType) {
				case "IGN":
					findClubsWithIGN();
					break;
				case "GolferNumber":
					findClubsWithGolferNumber();
					break
				case "Association":
					findClubsWithAssociation();
					break;
				case 'Club':
					findClubsWithClub();
					break;
				case 'NonMember':
					findNonMemberClubs();
					break;
			}
		}	
		// have to show this now in order to get the table structure
		MM_changeProp('SelectClubResults','','display','block','DIV');
		scrollToBottom();
		completeTime = Date();
		//showMetrics();
	}
}

function showMetrics()
{
	var metrics;
	metrics = 'Start Time: ' + startTime;
	metrics += '\nCall Ajax Time: ' + callAjaxTime;
	metrics += '\nAjax Response Time: ' + ajaxResponseTime;
	metrics += '\nComplete Time: ' + completeTime;
	alert(metrics);
	
}

function HasSearchCriteria(searchType){
	var msgText = '';
	var IGN;
	var State;
	var clubName;
	var golferNumber;
	var FirstName;
	var LastName;
	var AssociationID;
	var clubNumber;

	var retVal;
	retVal = true;
	
	if (haveXmlHttp()==true){
		switch(searchType) {
			case "IGN":
				IGN = document.getElementById("SelectByIGNText").value;							
				if (IGN==''||IGN.length==0) {
					alert('Please provide an IGN before searching');
					retVal = false;
				}else if(IGN.length<7){
					alert('The minimum length for an IGN is seven (7) characters. The criteria provided is ' + IGN.length + ' character(s)');
					retVal = false;
				}else{
					retVal = true;
				}
				break;

			case "GolferNumber":
				State = document.getElementById("SelectByGolferNumber_StateText").value;
				clubName = document.getElementById("SelectByGolferNumber_ClubNameText").value;
				golferNumber = document.getElementById("SelectByGolferNumber_NumberText").value;
				
				if (State==''||State.length==0) {msgText+='\tState\n';}
				if (clubName==''||clubName.length==0) {msgText+='\tClub Name\n';}
				if (golferNumber==''||golferNumber.length==0) {msgText+='\tGolfer Number\n';}
				
				if (msgText!=''&&msgText.length!=0) {
					msgText = 'Please provide values for the following fields before searching\n' + msgText;
					alert(msgText);
					retVal= false;
				}else{
					retVal = true;
				}
				break;

			case "Association":
				var assn = document.getElementById("SelectByAssociation_AssociationSelect");
				AssociationID = assn.options[assn.selectedIndex].value;

				clubName = document.getElementById("SelectByAssociation_ClubNameText").value;
				FirstName = document.getElementById("FirstName").value;
				LastName = document.getElementById("LastName").value;
				
				if (AssociationID==0) {msgText+='\tAssociation\n';}
				if (clubName==''||clubName.length==0) {msgText+='\tClub Name\n';}
				if (FirstName==''||FirstName.length==0) {msgText+='\tFirst Name\n';}
				if (LastName==''||LastName.length==0) {msgText+='\tLast Name\n';}
				
				if (msgText!=''&&msgText.length!=0) {
					msgText = 'Please provide values for the following fields before searching\n' + msgText;
					alert(msgText);
					retVal = false;
				}else{
					retVal = true;
				}
				break;

			case 'Club':
				//State = document.getElementById("SelectByClub_StateText").value;
				//clubName = document.getElementById("SelectByClub_ClubNameText").value;
				//FirstName = document.getElementById("FirstName").value;
				LastName = document.getElementById("LastName").value;
				clubNumber = $('SelectByClub_ClubSearch').jsObject.GetSelectedRowValues()[2];
				
				//if (State==''||State.length==0) {msgText+='\tState\n';}
				//if (clubName==''||clubName.length==0) {msgText+='\tClub Name\n';}
				//if (FirstName==''||FirstName.length==0) {msgText+='\tFirst Name\n';}
				if (LastName==''||LastName.length==0) {msgText+='\tLast Name\n';}
				if (clubNumber==''||clubNumber.length==0) {msgText+='\tSelect a club from the list\n';}
				
				if (msgText!=''&&msgText.length!=0) {
					msgText = 'Please provide values for the following fields before searching\n' + msgText;
					alert(msgText);
					retVal = false;
				}else{
					retVal = true;
				}
				break;
			case 'NonMember':
				var assn = document.getElementById("SelectByNonMember_AssociationSelect");
				AssociationID = assn.options[assn.selectedIndex].value;
				if (AssociationID==0) {
					msgText = 'Please select an association before searching.';
					alert(msgText);
					retVal = false;
				}else{
					retVal = true;
				}
				break;
		}
	}
	return retVal;
}

function saveProfile(){
	if (validateForm()) {
		document.getElementById("formMode").value = "save";
		//put club data in form field
		persistClubArray();
		submitForm(0);
		return true;
	}else{
		alert(validationMessage);
		validationMessage="";
		return false;
	}
}

function persistClubArray(){
	// need the array of clubs server side...
	var membershipTable = document.getElementById("ClubMembership");
	var clubData = "";
	// all that is needed is the IGN...
	// first row (i=0) is the header row
	for (var i = 1; i < membershipTable.rows.length; i++){
		clubData += membershipTable.rows[i].cells[3].innerHTML + ';';
	}
	// don't want the trailing semicolon
	//clubData.length = clubData.length - 1;
	
	document.getElementById("clubArraySave").value = clubData;
	
}

function validateForm(){
	
	verifyPasswords();
	verifyEmail();

	var errorList;
	errorList = "";

	if(document.getElementById("ClubMembership").rows.length == 1){
		validationMessage += "\nYou must have at least one club in your profile.";
		}
	
	var requiredFields;
	var AssID = document.getElementById("AssnID").value;
	// do not require the user to provide a password when editing a profile
	//if (document.getElementById("formMode").value != "edit"){
		if (AssID == "4") {
			requiredFields = "FirstName;LastName;UserName;Password;EmailAddress;Mailing_Address1;Mailing_Zip;Mailing_City;Mailing_State;Gender";
		}else if (AssID == "7"){
			requiredFields = "FirstName;LastName;UserName;Password;EmailAddress;Mailing_Address1;Mailing_Zip;Mailing_City;Mailing_State;HomePhone;Gender";
		}else if (AssID == "9"){
			requiredFields = "FirstName;LastName;UserName;Password;EmailAddress;Mailing_Address1;Mailing_Zip;Mailing_City;Mailing_State;Gender";
		}else{
			requiredFields = "FirstName;LastName;UserName;Password;EmailAddress;Gender";
		}
	//}else{
	//	requiredFields = "FirstName;LastName;UserName;HomePhone;EmailAddress;Mailing_Address1;Mailing_Zip;Mailing_City;Mailing_State;DateOfBirth;Gender";
	//}

	var fieldArray = requiredFields.split(';');

	for (field in fieldArray){
		var ctrl = document.getElementById(fieldArray[field]);
		//if (ctrl.value){
			if (ctrl.value==undefined||ctrl.value.length==0){ errorList += '\n\t' + ctrl.name; }
		//}else{
		//	if (ctrl.selectedIndex == 0){ errorList +=  '\n\t' + ctrl.name };
		//}
	}

	// now that we know we have a username, make sure it is available
	verifyUserName()

	if (errorList.length != 0){
		if (validationMessage.length != 0) {validationMessage += '\n';}
		validationMessage += 'The following fields are required: ' + errorList;
	}
	
	if(validationMessage.length != 0){
		return false;
	}else{
		return true;
	}
}

function verifyPasswords(){
	var password = document.getElementById("Password").value;

	var confirmPassword = document.getElementById("ConfirmPassword").value;

	if (password != confirmPassword){
		validationMessage += 'The password and re-typed passwords do not match';
		return false;
	}else{
		return true;
	}
}

function verifyEmail(){
	var Email = document.getElementById("EmailAddress").value;

	var confirmEmail = document.getElementById("ConfirmEmailAddress").value;

	if (Email != confirmEmail){
		validationMessage += 'The Email address and re-typed Email Address do not match';
		return false;
	}else{
		return true;
	}
}

function verifyUserName(){
	var sUserName = document.getElementById("UserName").value;

	if (isFinite(sUserName)){
		validationMessage += "Your username must contain at least one alphabetic character.";
		return false;
	}

	var PlayerID = document.getElementById("playerID").value;
	if (PlayerID.length == 0) {PlayerID = 0;}

	var SearchBy = "UserName";
	var Output = "TF";
	
	var ajaxUrl = ajaxTarget + '?SearchBy=' + SearchBy + '&Output=' + Output + '&PlayerID=' + PlayerID + '&UserName=' + sUserName;
	if(haveXmlHttp()==true){
		// Some browsers do not support SJAX through readyStateChange
		//xmlHttp.onreadystatechange=processUserNameCheck;
		// Mozilla based browsers do not like synchronous calls
		// but this check must be synchronous for browsers that support it to avoid a postback
		// Mozilla based browsers will suffer a postback for this validation
		xmlHttp.open("GET", ajaxUrl, false);
		xmlHttp.send(null);
		

		// Some browsers do not support SJAX through readyStateChange
		var userNameIsUsed = xmlHttp.responseText;
		xmlHttp = null;

		if (userNameIsUsed=='true'){ 
			validationMessage += "The UserName provided is already used. Please select another username.";
			document.getElementById("userNameVerified").value = 'T';
		}else if(userNameIsUsed=='false'){
			document.getElementById("userNameVerified").value = 'T';
		}else{
			// tell the page to validate the userName server side...
			document.getElementById("userNameVerified").value = 'F';
		}
		
	}
}

function processUserNameCheck(){
	if(xmlHttp.readyState==4){
		var userNameIsUsed = xmlHttp.responseText;
		xmlHttp = null;
	
		// Mozilla browsers can't handle synchronous Ajax
		// this disables functionality to validate the username uniqueness server side
		document.getElementById("userNameVerified").value = 'T';
		if (userNameIsUsed=='true'){ validationMessage += "The UserName provided is already used. Please select another username."; }
	}
}

function haveXmlHttp(){
	try
		{ // Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();
		return true;
		}
	catch (e)
		{ // Internet Explorer
		try
			{ 
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
			return true;
			}
		catch (e)
			{
			try
				{ 
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return true;
				}
			catch (e)
				{ 
				return false;
				}
		}
	}
}

function findClubsWithIGN(){
	var PlayerID = document.getElementById("playerID").value;
	var IGN = document.getElementById("SelectByIGNText").value;
	if (PlayerID.length == 0) {PlayerID = 0;}
	var SearchBy = "IGN";
	var Output = "TableData";
	
	var ajaxUrl = ajaxTarget + '?SearchBy=' + SearchBy + '&Output=' + Output + '&PlayerID=' + PlayerID + '&IGN=' + IGN;

	xmlHttp.open("GET", ajaxUrl, false);
	xmlHttp.send(null);
		
	document.getElementById("SelectClub").innerHTML = searchResultsTableStructure + xmlHttp.responseText
}

function findClubsWithGolferNumber(){
	var PlayerID = document.getElementById("playerID").value;
	if (PlayerID.length == 0) {PlayerID = 0;}

	var State = document.getElementById("SelectByGolferNumber_StateText").value;
	var clubName = document.getElementById("SelectByGolferNumber_ClubNameText").value;
	var golferNumber = document.getElementById("SelectByGolferNumber_NumberText").value;
	var golferSuffix = document.getElementById("SelectByGolferNumber_SuffixText").value;
	if (golferSuffix.length == 0) {golferSuffix = 0;}

	var SearchBy = "GolferNumber";
	var Output = "TableData";
	var ajaxUrl = ajaxTarget+'?SearchBy='+SearchBy+'&Output='+Output+'&PlayerID='+PlayerID+'&State='+State+'&ClubName='+clubName+'&GolferNumber='+golferNumber+'&GolferSuffix='+golferSuffix;

	xmlHttp.onreadystatechange=processAjaxResults;
	// Mozilla based browsers do not like synchronous calls
	xmlHttp.open("GET", ajaxUrl, true);
	xmlHttp.send(null);
}

function findClubsWithAssociation(){
	var PlayerID = document.getElementById("playerID").value;
	if (PlayerID.length == 0) {PlayerID = 0;}

	var assn = document.getElementById("SelectByAssociation_AssociationSelect");
	var AssociationID = assn.options[assn.selectedIndex].value;

	var clubName = document.getElementById("SelectByAssociation_ClubNameText").value;
	var FirstName = document.getElementById("FirstName").value;
	var LastName = document.getElementById("LastName").value;

	// 9/17/08 - use only full last name to search
	//FirstName = FirstName.substring(0,1);
	FirstName = '';
	//LastName = LastName.substring(0,4);

	var SearchBy = "Association";
	var Output = "TableData";
	var ajaxUrl = ajaxTarget+'?SearchBy='+SearchBy+'&Output='+Output+'&PlayerID='+PlayerID+'&AssociationID='+AssociationID+'&ClubName='+clubName+'&FirstName='+FirstName+'&LastName='+LastName;

	//alert(ajaxUrl);

	xmlHttp.onreadystatechange=processAjaxResults;
	// Mozilla based browsers do not like synchronous calls
	xmlHttp.open("GET", ajaxUrl, true);
	xmlHttp.send(null);
}

function findClubsWithClub(){
	var PlayerID = document.getElementById("playerID").value;
	if (PlayerID.length == 0) {PlayerID = 0;}

	//var State = document.getElementById("SelectByClub_StateText").value;
	//var clubName = document.getElementById("SelectByClub_ClubNameText").value;
	//var FirstName = document.getElementById("FirstName").value;
	var LastName = document.getElementById("LastName").value;

	var clubNumber = $('SelectByClub_ClubSearch').jsObject.GetSelectedRowValues()[2];

	FirstName = '';
	LastName = LastName.substring(0,4);

	var SearchBy = "Club";
	var Output = "TableData";
	//var ajaxUrl = ajaxTarget+'?SearchBy='+SearchBy+'&Output='+Output+'&PlayerID='+PlayerID+'&State='+State+'&ClubName='+clubName+'&FirstName='+FirstName+'&LastName='+LastName;
	var ajaxUrl = ajaxTarget+'?SearchBy='+SearchBy+'&Output='+Output+'&PlayerID='+PlayerID+'&ClubNumber='+clubNumber+'&FirstName='+FirstName+'&LastName='+LastName;

	//xmlHttp.onreadystatechange=processAjaxResults;

	callAjaxTime = Date();
	xmlHttp.open("GET", ajaxUrl, false);
	xmlHttp.send(null);
	
	document.getElementById("SelectClub").innerHTML = searchResultsTableStructure + xmlHttp.responseText
	ajaxResponseTime = Date();

	xmlHttp = null;
	
}



function processAjaxResults(){
		if(xmlHttp.readyState==4){
			document.getElementById("SelectClub").innerHTML = searchResultsTableStructure + xmlHttp.responseText;
			xmlHttp = null;
		}
}

function parseClubArray(){
	//need to split the clubArray and write it to the club membership table
	// format of clubArray: <clubName>;<IGN>;<golferName>;<Index>;<revDate>|
	//
	// build the HTML then push it into the table

	var clubArray = document.getElementById("clubArray").value;
	
	if (clubArray.length == 0) {return true;}

	var clubs = clubArray.split("|");
	if(clubs.length > 0) { 
		var memberTable = document.getElementById("ClubMembership"); 
		var rowCount = memberTable.rows.length;
	}
	
	for (var club in clubs){
		if(clubs[club].length!=0){
			var clubCols = clubs[club].split(';');
			
			if(clubCols.length > 0) {

				var newClub = memberTable.insertRow(rowCount);

				//Remove button				
				newClub.insertCell(0).innerHTML = tableRowRemove;
	
				//Home
				if (rowCount == 1) {
					newClub.insertCell(1).innerHTML = "Yes";
				}else{
					newClub.insertCell(1).innerHTML = "No";
				}// if rowCount == 1


				for(var i=0;i<clubCols.length;i++){
					newClub.insertCell(i+2).innerHTML = clubCols[i];
	
				} // for club in clubCols
			
			rowCount++;

			}// if clubCols.length
		}// if club.length
	}//for

	document.getElementById("clubCount").value = memberTable.rows.length - 1;
	//document.getElementById("clubArray").value = "";

}// function parseClubArray

function findNonMemberClubs(){
	var PlayerID = document.getElementById("playerID").value;
	if (PlayerID.length == 0) {PlayerID = 0;}

	var FirstName = document.getElementById("FirstName").value;
	var LastName = document.getElementById("LastName").value;

	FirstName = FirstName.substring(0,1);
	LastName = LastName.substring(0,4);

	var assn = document.getElementById("SelectByNonMember_AssociationSelect");
	var AssociationID = assn.options[assn.selectedIndex].value;

	var SearchBy = "NonMember";
	var Output = "TableData";

	var ajaxUrl = ajaxTarget+'?SearchBy='+SearchBy+'&Output='+Output+'&PlayerID='+PlayerID+'&FirstName='+FirstName+'&LastName='+LastName+'&AssociationID='+AssociationID;

	//alert(ajaxUrl);

	xmlHttp.onreadystatechange=processAjaxResults;
	// Mozilla based browsers do not like synchronous calls
	xmlHttp.open("GET", ajaxUrl, true);
	xmlHttp.send(null);
	
}// function findNonMemberClubs


function showOnProfileExplanation()
{
	alert('This membership is already associated with a profile and cannot be added to this profile.');
}

function showInactiveExplanation()
{
	alert('This membership is inactive and cannot be added to profiles.\nPlease contact the club to activate this membership.');
}
