function moveInputId(thisPtr,fromId,toId,memberId,tableId,cellLabel) {
	var rowLastRow,row,lastRow,fromPtr,toPtr,str;

	fromPtr = (fromId ? document.getElementById(fromId) : null);
	toPtr = (toId ? document.getElementById(toId) : null);
	rowLastRow = coachPlayerRowNumber(thisPtr);
	row = rowLastRow[0];
	if (row >= 0) {
		if (fromPtr) {
			str = fromPtr.value;
			str = (str == memberId ? '' : str.replace('|'+memberId+'|','|'));
			fromPtr.value = str;
		}
		if (toPtr) {
			str = toPtr.value;
			if (str.indexOf('|'+memberId+'|') < 0) {
				toPtr.value = str+memberId+'|';
			}
		}
		if (tableId) {
			setSpec = tableId+',tr:'+row+',td:1='+cellLabel;
			setInnerHtml(document,setSpec);
		}
	}
}

function guestLookup(idPath,namePath,emailPath,phonePath,cellPath,hideId,showId,hostOnly,fromId,toPath,toClass)
{
	this.id = idPath;
	this.name = namePath;
	this.email = emailPath;
	this.phone = phonePath;
	this.cell = cellPath;
	if ((hideId !== undefined) && (hideId !== '')) {
		this.hideId = hideId;
	}
	if ((showId !== undefined) && (showId !== '')) {
		this.showId = showId;
	}
	if ((hostOnly !== undefined) && (hostOnly !== '')) {
		this.hostOnly = hostOnly;
	}
	if ((fromId !== undefined) && (fromId !== '')) {
		this.fromId = fromId;
	}
	if ((toPath !== undefined) && (toPath !== '')) {
		this.toPath = toPath;
	}
	if ((toClass !== undefined) && (toClass !== '')) {
		this.toClass = toClass;
	}
}

function coachPlayerSearch(thisPtr,searchType,toClass) {
	var rowLastRow,row,lastRow,tableId,inputId,inputNo,hostOnly,fromId,toPath,toFillPath;

	rowLastRow = coachPlayerRowNumber(thisPtr);
	row = rowLastRow[0];
	lastRow = rowLastRow[1];
	if (row >= 0) {
		tableId = (searchType=='P' ? 'playerTable' :'coachTable');
		inputId = (searchType=='H' ? 'headId' :(searchType=='A' ? 'assistantId' : 'playerId'));
		ids = document.getElementById(inputId).value;
		ids = ids.split('|').length;
		inputNo = (searchType=='H' ? 0 : ids-1 );
		hostOnly = (searchType == 'H') || (searchType == 'A');
		fromId = (lastRow ? (searchType=='P' ? 'playerTemplate' :'coachTemplate') : '');
		toPath = (lastRow ? tableId+',tr:'+(row+1) : '');
		toFillPath = (lastRow && searchType=='P' ? 'td:0='+(row+1)+')' :'');
		guestSearch(new guestLookup(inputId+',::value['+inputNo+']',tableId+',tr:'+row+',td:0',tableId+',tr:'+row+',td:3',tableId+',tr:'+row+',td:5','','','',hostOnly,fromId,toPath,toClass));
	}
}

function coachPlayerDelete(thisPtr,searchType,memberId) {
	var rowLastRow,row,thisTrPtr,tableId,inputId,inputNo,setSpec;
	rowLastRow = coachPlayerRowNumber(thisPtr);
	row = rowLastRow[0];
	thisTrPtr = rowLastRow[2];
	if (row >= 0) {
		tableId = 'coachTable';
		inputId = (searchType=='H' ? 'headId' :(searchType=='A' ? 'assistantId' : 'playerId'));
		inputNo = (searchType=='H' ? 0 :(searchType=='A' ? row - 2 : row - 1));
		moveInputId(thisPtr,inputId,null,memberId,null,null);
		thisTrPtr.parentNode.removeChild(thisTrPtr);
		//setSpec = tableId+',tr:'+row+',td:0=|'+tableId+',tr:'+row+',td:2=|'+tableId+',tr:'+row+',td:3=|'+tableId+',tr:'+row+',td:4=';
		//setInnerHtml(document,setSpec);
	}
}

function coachPlayerRowNumber(thisPtr) {
	var trPtr,thisTrPtr,nextTrPtr,lastRow,row;
	// Find the <tr> parent
	trPtr = thisPtr.parentNode;
	while (trPtr && (trPtr.nodeName.toLowerCase() != 'tr')) {
		trPtr = trPtr.parentNode;
	}
	// Save a pointer to this row
	thisTrPtr = trPtr;
	// Check if the next row is the row template
	nextTrPtr = trPtr.nextSibling;
	while (nextTrPtr && (nextTrPtr.nodeName.toLowerCase() != 'tr')) {
		nextTrPtr = nextTrPtr.nextSibling;
	}
	lastRow = ((nextTrPtr!==null) && (nextTrPtr.className == 'noDisplay'));
	// Count which row number this is
	row = -1;
	while (trPtr) {
		if (trPtr.nodeName.toLowerCase() == 'tr') {
			row++;
		}
		trPtr = trPtr.previousSibling;
	}
	return Array(row,lastRow,thisTrPtr);
}

function hoCoDriverSearch(formNo,hostOnly) {
	var namePtr;
	guestSearch(new guestLookup('if_1_'+formNo+',p:0,input:0:value','if_1_'+formNo+'_P,a:0','','','','if_1_'+formNo+'_B','if_1_'+formNo+'_P',hostOnly));
}

function inlineSubmit(formNum,sForm) {
	var formPrefix,toFormPtr,fromFormPtr,elementName,valueSet,i;
	sForm = ((sForm !== undefined) && (sForm !== ''));
	formPrefix = 'if_'+parseInt(formNum)+'_';
	toFormPtr = document.getElementById(formPrefix+'S');
	formId = 0;
	fromFormPtr = document.getElementById(formPrefix+parseInt(formId));
	valueSet = '';
	while (toFormPtr && fromFormPtr) {
		for (i=0; i<fromFormPtr.elements.length; i++) {
			elementName = fromFormPtr.elements[i].name;
			if (toFormPtr.elements[elementName] !== undefined) {
				toFormPtr.elements[elementName].value=fromFormPtr.elements[i].value;
				valueSet += fromFormPtr.elements[i].value;
			}
		}
		formId++;
		fromFormPtr = document.getElementById(formPrefix+parseInt(formId));
	}
	if (!sForm && toFormPtr && (valueSet !== '')) {
		toFormPtr.submit();
	}
	return(sForm);
}

function submitCommit(thisPtr,agree) {
	if (thisPtr) {
		thisPtr.form.agree.value=agree;
	}
	return false;
}

