//
// Garis Graphics (2005) Function - Removes the last traveler on the traveler input table
//
function RemoveLastTraveler(TableID, QuantityID)
{
	var tableElement = document.getElementById(TableID);
	var quantityElement = document.getElementById(QuantityID);
	
	var numOfRows = tableElement.rows.length;
	
	if(numOfRows > 2)
	{
		//Before subtracting the row, we must first get rid of any optional services connections
		var textCell = tableElement.rows[numOfRows - 1].cells[0];
		var textNode = textCell.firstChild;
		if(textNode.data != null)
		{
			//Search string
			var searchString = /\./;
			
			//Replace any irregular characters with nothing
			var correctedName = textNode.data.replace(searchString, "");
			
			//Trim whitespace
			correctedName = 'Traveler ' + trim(correctedName);
			
			//Debug message
//					alert("correctedName : " + correctedName);
			
			//Detach the optional services link from the traveler
			detachOSLink(correctedName);
		}
		
		//Subtract the row and do the same to the amount of members
		tableElement.deleteRow(numOfRows - 1);
		
		//Decrease the number of travelers
		this.memberNumber--;
		
		//Set the quantity number box to the new amount of members
		quantityElement.value = this.memberNumber;
	}
}

//
// Garis Graphics (2005) Function - Adds a traveler input row to a form field area
//
function TravellerInput(TableID, Paid, QuantityID)
{
	if(document.getElementById('memberInputTable'))
	{
		var newMemberNumber = memberNumber + 1;
		
		//Note: (03/22/05) - Might have to put this into a separate file, so it can be used externally from this project
		// - Need to implement Netscape and IE compatibility & fix the html table output
		
		//Retrieve table to put in new Member input row
		var tableElement = document.getElementById(TableID);
		var quantityElement = document.getElementById(QuantityID);
		
		//Create a new row (at the end) to house the member input information
//				var newRow = tableElement.insertRow(tableElement.rows.length);
		var newRow = tableElement.insertRow(-1);
		
		//Create the first cell - the Number of the member row
		var memberNumberCell = newRow.insertCell(0);
		
			//Change the alignment of the cell
			memberNumberCell.setAttribute('align', 'right');
				
			//Create the actual member number text that will go into the cell
			var memberNumberText = document.createTextNode(newMemberNumber + ".");
			
			//Attach the text information to the cell
			memberNumberCell.appendChild(memberNumberText);
					
		//Create the second cell - the First name input cell
		var firstNameCell = newRow.insertCell(1);
				
			//Create the actual first name input element
			var firstNameInput = document.createElement('input');
		
			//Set the input attributes
			firstNameInput.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][First]');
			firstNameInput.setAttribute('type', 'text');
			firstNameInput.setAttribute('size', '14');
			firstNameInput.setAttribute('maxLength', '100');
			firstNameInput.setAttribute('value', '');
			firstNameInput.setAttribute('id', javaWord + javaId);
			
			javaId++;
		
		//Append the input field to the cell
		firstNameCell.appendChild(firstNameInput);
					
		//Create the third cell - the Middle initial input cell
//				var MICell = newRow.insertCell(2);
//				
//					//Create the actual middle initial input element
//					var MIInput = document.createElement('input');
//				
//					//Set the input attributes
//					MIInput.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][MI]');
//					MIInput.setAttribute('type', 'text');
//					MIInput.setAttribute('size', '1');
//					MIInput.setAttribute('maxLength', '1');
//					MIInput.setAttribute('value', '');
//				
//				//Append the input field to the cell
//				MICell.appendChild(MIInput);
			
		//Create the fourth cell - the Last name input cell
		var lastNameCell = newRow.insertCell(2);
		
			//Create the actual last name input element
			var lastNameInput = document.createElement('input');
			
			//Set the input attributes
			lastNameInput.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][Last]');
			lastNameInput.setAttribute('type', 'text');
			lastNameInput.setAttribute('size', '14');
			lastNameInput.setAttribute('maxLength', '100');
			lastNameInput.setAttribute('value', '');
			lastNameInput.setAttribute('id', javaWord + javaId);
			
			javaId++;
			
			//Append the input field to the cell
			lastNameCell.appendChild(lastNameInput);
			
		//Create the fifth cell - the Date of Birth input cell
		var DOBCell = newRow.insertCell(3);
		
			//Create the actual date of birth input element (including javascript function calls)
			var DOBInput = document.createElement('input');
			
			//Set the input attributes
			DOBInput.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][DOB]');
			DOBInput.setAttribute('type', 'text');
			DOBInput.setAttribute('size', '11');
			DOBInput.setAttribute('maxLength', '10');
			DOBInput.setAttribute('id', javaWord + javaId);
			
			javaId++;
			
			if(document.all)
			{
				//IE DOM Methods
				DOBInput.attachEvent('onkeyup', function () {DateFormat(DOBInput, DOBInput.value, event, false,"1");});
				DOBInput.attachEvent('onblur', function () {DateFormat(DOBInput, DOBInput.value, event, true,"1");});
			}
			else
			{
				//Mozilla DOM methods
				//DOBInput.addEventListener('keyup', function() {Reset('f_date_a','f_calcdate');}, false);
				//DOBInput.addEventListener('keyup', function() {DateFormat(DOBInput, DOBInput.value, this.event, true, "1");}, true);
				//DOBInput.addEventListener('keyup', function () {DateFormat(DOBInput, DOBInput.value,event,false,"1")}, false);
				//DOBInput.addEventListener('onblur', function () {DateFormat(DOBInput, DOBInput.value,event,true,"1"); }, false);
				//DOBInput.addEventListener('blur', function() {Reset();}, true);
			}
			
			//Append the input field to the cell
			DOBCell.appendChild(DOBInput);
			
		//Create the sixth cell - the Gender input cell
		var GenderCell = newRow.insertCell(4);
		
			//Create the actual gender input element
			var GenderInput = document.createElement('select');
			
			//Set the input attributes
			GenderInput.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][Gender]');
			GenderInput.setAttribute('size', '1');
			
				//Create the Male option element
				var MaleOption = new Option('M', 'Male');
				
				//Create the Female option element
				var FemaleOption = new Option('F', 'Female');
				
				//Append the options to the select field
				GenderInput.options[0] = MaleOption;
				GenderInput.options[1] = FemaleOption;
			
			//Append the select options input field to the cell
			GenderCell.appendChild(GenderInput);
			
		//Create the seventh cell - the Email input cell
		var EmailCell = newRow.insertCell(5);
		
			//Create the actual email input element
			var EmailInput = document.createElement('input');
			
			//Set the input attributes
			EmailInput.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][Email]');
			EmailInput.setAttribute('type', 'text');
			EmailInput.setAttribute('size', '14');
			EmailInput.setAttribute('maxLength', '100');
			EmailInput.setAttribute('value', '');
			
			//Append the email input field to the email cell
			EmailCell.appendChild(EmailInput);
		
		var MasterCopyOptionCell = newRow.insertCell(6);
			MasterCopyOptionCell.setAttribute('align', 'center');
			
			//Create the actual Master Copy option element
			var MasterCopyOption = document.createElement('input');
			
			//Set the option attributes
			MasterCopyOption.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][Send Master Subscription]');
			MasterCopyOption.setAttribute('type', 'checkbox');
			
			//Append the master copy option to the master copy cell
			MasterCopyOptionCell.appendChild(MasterCopyOption);
		
		var osCell = newRow.insertCell(7);
			osCell.setAttribute('align', 'center');
			
			//Create the actual Master Copy option element
			var osOption = document.createElement('input');
			
			var idCopy = javaId;
			checkedArray[idCopy] = false;
//					alert("javaID right now = " + javaId);
			//Set the option attributes
			osOption.setAttribute('name', 'oa_attributes[' + Paid + '][Traveler ' + newMemberNumber + '][Additional Services]');
			osOption.setAttribute('type', 'checkbox');
			osOption.setAttribute('id', javaWord + idCopy);
			if(document.all)
			{
				//IE DOM Methods
//						alert("checkedArray[" + idCopy + "] = " + checkedArray[idCopy]);
				osOption.attachEvent('onclick', function () {checkedArray[idCopy] = !checkedArray[idCopy]; attachOSLink('Traveler ' + newMemberNumber, Paid, idCopy)});
			}
			else
			{
//						alert("checkedArray[" + idCopy + "] = " + checkedArray[idCopy]);
				//Firefox DOM Methods
				osOption.addEventListener('click', function () {checkedArray[idCopy] = !checkedArray[idCopy]; attachOSLink('Traveler ' + newMemberNumber, Paid, idCopy)}, false);
			}
			
			javaId++;
			//Append the master copy option to the master copy cell
			osCell.appendChild(osOption);
			
		//Set the quantity to the new amount of members
		quantityElement.value = newMemberNumber;
		this.memberNumber = newMemberNumber;
	}
}

