document.getElementById("loadingMessage").innerHTML = 'Loading crew...';

function AddCrewman(crewmanToAdd, shipPartToAddTo)
{
	var i;
	if (shipPartToAddTo.curCrew < shipPartToAddTo.maxCrew)
	{
		for (i=0; i<shipPartToAddTo.crew.length; i++)
		{
			if (shipPartToAddTo.crew[i] == null)
			{
				// add this crewman to this position.
				shipPartToAddTo.crew[i] = crewmanToAdd;
				shipPartToAddTo.curCrew++;
				calculateAdjustedValues(playerShip);
//				calculateAdjustedValues(encounterShip);
				return true;
			}
		}
//		alert("Gone through 'em all! " + shipPartToAddTo.crew.length);
	} else {
		// try to add this crewman to child containers
		if (shipPartToAddTo.attachments != null)
		{
			for (i=0; i<shipPartToAddTo.attachments.length; i++)
			{
				if (shipPartToAddTo.attachments[i] != null)
				{
					if (AddCrewman(crewmanToAdd, shipPartToAddTo.attachments[i]))
					{
					 return true;
					}
				}
			}
		}
		// if you get here, you can't add a crewman.  Return false.
//		alert("couldn't add crewman!");
		return false;
	}
}

function populateWithAutoPirate(curPart) {
	var i;
	while (AddCrewman(new Crewman("Auto-", "Pirate", 0, 0, 0, 0, 0, 0), curPart))
	{
		// just keep doing this until hell freezes over.
	}
	for (i = 0; i < curPart.attachments.length; i++) {
		if (curPart.attachments[i] != null) {
			populateWithAutoPirate(curPart.attachments[i]);
		}
	}
}

function RemoveCrewman(curPart, crewmanID)
{
	var i, returnValue;
	for (i=0; i<curPart.crew.length; i++)
	{
		if (curPart.crew[i] != null)
		{
			if (curPart.crew[i].ID == crewmanID)
			{
				// remove this crewman.
				curPart.crew[i] = null;
				curPart.curCrew--;
				calculateAdjustedValues(playerShip);
//				calculateAdjustedValues(encounterShip);
				return true;
			}
		}
	}
	for (i=0; i<curPart.attachments.length; i++)
	{
		if (curPart.attachments[i] != null)
		{
			returnValue = RemoveCrewman(curPart.attachments[i], crewmanID);
			if (returnValue == true)
			{
				return true;
			}
		}
	}
	return false;
}

function dropFirstAutoPirate(curPart) 
{
	var i;
	for (i=0; i<curPart.crew.length; i++)
	{
		if (curPart.crew[i] != null)
		{
			if (curPart.crew[i].firstName == "Auto-")
			{
//				alert("Dropped ID# " + curPart.crew[i].ID)
				RemoveCrewman(curPart, curPart.crew[i].ID);
				return true;
			}
		}
	}
	for (i=0; i<curPart.attachments.length; i++)
	{
		if (curPart.attachments[i] != null)
		{
//			alert('testing next attachment: ' + curPart.attachments[i].partName + ' (crew: ' + curPart.attachments[i].crew.length + ')');
			if (dropFirstAutoPirate(curPart.attachments[i]))
			{
				return true;
			}
		}
	}
	return false;
}


function GetCrewman(curPart, crewmanID)
{
	var i;
	var returnValue;
//	alert(curPart +", " + curPart.crew);
	for (i=0; i<curPart.crew.length; i++)
	{
		if (curPart.crew[i].ID == crewmanID)
		{
			// return this crewman.
			return curPart.crew[i];
		}
	}
	for (i=0; i<curPart.attachments.length; i++)
	{
		if (curPart.attachments[i] != null)
		{
			returnValue = GetCrewman(curPart.attachments[i], crewmanID);
			if (returnValue != null)
			{
				return returnValue;
			}
		}
	}
	return null;
}

function GetCrewmanPart(curPart, crewmanID)
{
	var i, returnValue;
	for (i=0; i<curPart.crew.length; i++)
	{
		if (curPart.crew[i].ID == crewmanID)
		{
			// return this crewman.
			return curPart;
		}
	}
	for (i=0; i<curPart.attachments.length; i++)
	{
		if (curPart.attachments[i] != null)
		{
			returnValue = GetCrewmanPart(curPart.attachments[i], crewmanID);
			if (returnValue != null)
			{
				return returnValue;
			}
		}
	}
	return null;
}

function SwapCrewmen(firstCrewmanID, secondCrewmanID)
{
	var firstCrewman, secondCrewman, firstCrewmanPart, secondCrewmanPart;
	
	firstCrewman = GetCrewman(playerShip, firstCrewmanID);
	secondCrewman = GetCrewman(playerShip, secondCrewmanID);
	
	firstCrewmanPart = GetCrewmanPart(playerShip, firstCrewmanID);
	secondCrewmanPart = GetCrewmanPart(playerShip, secondCrewmanID);

	if (firstCrewmanPart == secondCrewmanPart)
	{
		showAlertWindow("Can ye not think?", "Thar's no point in swapping crewmen around in the same part of the ship.  It won't make any difference to how yer ship performs, and it's really, really mean to make 'em switch bunks fer no good reason.", "Arr, yeah, I knew that.");
		setTimeout(clearOutCrewmen, 10);
		crewmanIDToSwap = -1;
	} else {
//		alert('Trading stuff: ' + firstCrewman + ', ' + secondCrewman);
		RemoveCrewman(playerShip, firstCrewman.ID);
		RemoveCrewman(playerShip, secondCrewman.ID);
		AddCrewman(secondCrewman, firstCrewmanPart);
		AddCrewman(firstCrewman, secondCrewmanPart);
		calculateAdjustedValues(playerShip);
		crewmanIDToSwap = -1;
		populateShipPartCrewmen();

	}
}

function crewmanAction(curIndex)
{

	var partToCheck;

	if (document.getElementById("crewManagementShipComponents").value == -1)
	{
		partToCheck = playerShip;
	} else {
		partToCheck = playerShip.attachments[document.getElementById("crewManagementShipComponents").value];	
	}

	if (crewmanIDToSwap != -1 && partToCheck.crew[curIndex] != null)
	{
//		alert("Checking: " + partToCheck.crew[curIndex].ID);
		SwapCrewmen(crewmanIDToSwap, partToCheck.crew[curIndex].ID);
		populateShipPartCrewmen();
		return;		
	}

	if (partToCheck.crew[curIndex] == null)
	{
		return;
	} else {
//		alert("crewman: " + partToCheck.crew[curIndex].firstName + " " + partToCheck.crew[curIndex].lastName)
	currentlySelectedCrewman = partToCheck.crew[curIndex];
	document.getElementById("crewmanActionName").innerHTML = partToCheck.crew[curIndex].firstName + " " + partToCheck.crew[curIndex].lastName;
	SwitchWindows('crewManagementScreen', 'crewmanActionScreen');
	DrawCrewmanLarge(partToCheck.crew[curIndex], "crewmanActionLargeStats")
	}

}

function fireCrewman()
{
	document.getElementById("largeCrewmanSVG").style.left = '200px';
	showConfirmationWindow("Out the Airlock!", "<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;Be ye certain ye want te fire " + currentlySelectedCrewman.firstName + " " + currentlySelectedCrewman.lastName + "?  It's more than just a figure o' speech fer space pirates, y'know.", "Aye, and good riddance!", "Arr, maybe tomorrow.", "fireCrewman");
//	showConfirmationWindow("Title", "Message", "Yes", "No", "fireCrewman");
}

function swapCrewmanAction()
{
	crewmanIDToSwap = currentlySelectedCrewman.ID;
	SwitchWindows('crewmanActionScreen', 'crewManagementScreen');
	populateShipPartCrewmen();

}

function populateBarCrewmen(sourceSeed)
{
	var i;
	var tmpSeed = null;
	if (sourceSeed != null)
	{
//		alert("populate bar crewmen: " + sourceSeed);
		tmpSeed = randomNumberSeed;
		randomNumberSeed = sourceSeed;
	}
	ClearAllChildren('recruitableCrewmen');
	for (i=0; i<6; i++)
	{
		barCrewmen[i] = CreateRandomCrewman();
		DrawCrewmanCard(i, barCrewmen[i], "recruitableCrewmen", "addCrewmanToCrew");
	}
	if (tmpSeed != null) {
		randomNumberSeed = tmpSeed;
	}


}

function drawBarCrewmen() {
	var tmpX, tmpY, i;

	tmpX = 83;
	tmpY = 200;
//	alert("drawing bar crewmen!");
	for (i=0; i<barCrewmen.length; i++)
	{
		if (document.getElementById("smallCrewmanSVG"+i).getSVGDocument() != null) {
//			alert("drawing bar crewman " + i + ": " + tmpX + ", " + tmpY + ", " + document.getElementById("smallCrewmanSVG"+i).getSVGDocument());
			document.getElementById("smallCrewmanSVG"+i).style.left = tmpX + 'px';
			document.getElementById("smallCrewmanSVG"+i).style.top = tmpY + 'px';
			document.getElementById("smallCrewmanSVG"+i).getSVGDocument().drawFace(barCrewmen[i].face);
			document.getElementById("smallCrewmanSVG"+i).getSVGDocument().setIndex(i);
			document.getElementById("smallCrewmanSVG"+i).getSVGDocument().setScale(0.5, 0.5);
		}
		tmpX = tmpX + 200;
		if (tmpX > 600) {
			tmpX = 83;
			tmpY = tmpY + 200;
		}
	}
}

function clearOutCrewmen() {
	var i;
	for (i=0; i<8; i++) {
		document.getElementById("smallCrewmanSVG"+i).style.left = '-100px';
		document.getElementById("smallCrewmanSVG"+i).style.top = '-100px';
	}
	document.getElementById("largeCrewmanSVG").style.left = '-200px';
	document.getElementById("largeCrewmanSVG").style.top = '-200px';
}

function populateShipPartCrewmen() 
{
	var i;
	var partToCheck;
	var tmpY, tmpX;
	var curValue = document.getElementById('crewManagementShipComponents').options[document.getElementById('crewManagementShipComponents').selectedIndex].value;
	
	if (curValue == -1)
	{
		partToCheck = playerShip;
	} else {
		partToCheck = playerShip.attachments[curValue];	
	}
	
	if (crewmanIDToSwap == -1)
	{
		document.getElementById('crewManagementTitle').innerHTML = "Ship's Rosterrr";
	} else {
		document.getElementById('crewManagementTitle').innerHTML = "Swap with...";
	}
//	alert('Clear the decks!');
	ClearAllChildren('currentCrewmen');
	clearOutCrewmen();
	if (partToCheck != null)
	{
		tmpX = 83;
		tmpY = 267;
		for (i=0; i<partToCheck.maxCrew; i++)
		{
			if (document.getElementById("smallCrewmanSVG"+i).getSVGDocument() != null) {
				document.getElementById("smallCrewmanSVG"+i).style.left = tmpX + 'px';
				document.getElementById("smallCrewmanSVG"+i).style.top = tmpY + 'px';
		document.getElementById("smallCrewmanSVG"+i).getSVGDocument().drawFace(partToCheck.crew[i].face);
				document.getElementById("smallCrewmanSVG"+i).getSVGDocument().setIndex(i);
				document.getElementById("smallCrewmanSVG"+i).onClick = "crewmanAction(" + i + ");";
				document.getElementById("smallCrewmanSVG"+i).getSVGDocument().setScale(0.5, 0.5);
			}
			DrawCrewmanCard(i, partToCheck.crew[i], "currentCrewmen", "crewmanAction");
			tmpX = tmpX + 200;
			if (tmpX > 600) {
				tmpX = 83;
				tmpY = tmpY + 200;
			}
		}
	}
}

function CreateRandomCrewman(bonusModifier)
{

	var newCrewman;
	var tmpNav, tmpGun, tmpEng, tmpMkt, tmpCost;
	
	if (bonusModifier == null) {
		bonusModifier = 0;
	}
	
	tmpNav = Math.floor(rnd() * 15) - 5;
	tmpGun = Math.floor(rnd() * 15) - 5;
	tmpEng = Math.floor(rnd() * 15) - 5;
	tmpMkt = Math.floor(rnd() * 15) - 5;
	tmpCost = (tmpNav + tmpGun + tmpEng + tmpMkt);
	if (tmpCost <= 0) 
	{
		tmpCost = 1;
	}
	tmpCost = 100 * ((tmpCost * tmpCost) / 300);
	
	if (tmpCost < 10)
	{
		tmpCost = 10;
	}

	tmpCost = Math.floor((((rnd() * .5) - .25) * tmpCost)  + tmpCost);
	
	tmpNav = tmpNav + bonusModifier;
	tmpGun = tmpGun + bonusModifier;
	tmpEng = tmpEng + bonusModifier;
	tmpMkt = tmpMkt + bonusModifier;
	
	if (tmpNav > 9) {
		tmpNav = 9;
	} else if (tmpNav < -5) {
		tmpNav = -5;
	}
	
	if (tmpGun > 9) {
		tmpGun = 9;
	} else if (tmpGun < -5) {
		tmpGun = -5;
	}
	
	if (tmpEng > 9) {
		tmpEng = 9;
	} else if (tmpEng < -5) {
		tmpEng = -5;
	}
	
	if (tmpMkt > 9) {
		tmpMkt = 9;
	} else if (tmpMkt < -5) {
		tmpMkt = -5;
	}
	
	newCrewman = new Crewman(SelectRandomItemFromArray(firstNames), SelectRandomItemFromArray(lastNames), tmpNav, tmpGun, tmpEng, tmpMkt, tmpCost, randomInteger(2000000000));
	
	return newCrewman;

}


function addCrewmanToCrew(indexToAdd)
{
	clearOutCrewmen();
	if (GetAdjustedStatistic(playerShip, "maxCrew") <= GetAdjustedStatistic(playerShip, "curCrew") ) 
	{
		showAlertWindow("Can Ye Not Count?", "Ye can't fit any more men aboard yer ship.  If ye don't give one of yer current crew the boot, yer gonna need a bigger boat.", "Fine, whatever you say."); 
	} else {
		if (playerCash < Math.floor(barCrewmen[indexToAdd].cost)) 
		{
		showAlertWindow("Check yer wallet", "Seems ye lack the funds necessary te recruit this fine individual.  Frankly, ye barely seem te have enough money for lunch.", "Spare credit, sir?  Bus fare?"); 
		} else {

		showConfirmationWindow(barCrewmen[indexToAdd].firstName + " " + barCrewmen[indexToAdd].lastName, "Be ye certain ye want te hire " + barCrewmen[indexToAdd].firstName + " " + barCrewmen[indexToAdd].lastName + "?", "Welcome aboard, matey!", "On second thought, no.", "hireCrewman", indexToAdd);

		}
	}
}

function addCrewmanFromVictory(indexToAdd)
{
	if (indexToAdd >= encounterShip.crew.length) {
//		alert("no more crew to check!");
		endCombat();
		return;
	}

//	alert("add crewman test: " + (indexToAdd+1) + " / " + encounterShip.crew.length + "; cost=" + (encounterShip.crew[indexToAdd].cost));

	
	
	encounterShip.crew[indexToAdd].cost = Math.floor((encounterShip.crew[indexToAdd].cost)/3);
	
	if (GetAdjustedStatistic(playerShip, "maxCrew") <= GetAdjustedStatistic(playerShip, "curCrew") ) 
	{
//		alert("no more space!");
		endCombat();
		return;
	} else {
		if (playerCash < Math.floor(encounterShip.crew[indexToAdd].cost)) 
		{
			addCrewmanFromVictory(indexToAdd+1);
		} else {

			if (Math.random() < 0.333) {
//				alert("hiring opportunity!");
				showConfirmationWindow(encounterShip.crew[indexToAdd].firstName + " " + encounterShip.crew[indexToAdd].lastName, "A swabbie by the name of " + encounterShip.crew[indexToAdd].firstName + " " + encounterShip.crew[indexToAdd].lastName + " wishes to join yer crew.  What say ye?", "Aye, why not?", "Not bloody likey, matey.", "hireCrewmanVictory", indexToAdd);
				return;
			} else {
				addCrewmanFromVictory(indexToAdd+1);
				return;
			}
		}
	}
}

function setStatColor(statToSet)
{
	switch (statToSet)
	{
		case -5:
		case -4:
			return "color:#FF0000;";
			break;
		case -3:
		case -2:
		case -1:
			return "color:#FF9999;";
			break;
		case 0:
		case 1:
		case 2:
		case 3:
			return "color:#C0C0C0;";
			break;
		case 4:
		case 5:
		case 6:
		case 7:
			return "color:#99FF99;";
			break;
		case 8:
		case 9:
		case 10:
			return "color:#00FF00;";
			break;
	}
}

function drawCrewmanFace(scale) {

	var workingImage;
	var workingColor;
	var crewmanImage;
	
//	crewmanImage = document.createElement("embed");
//	crewmanImage = document.getElementById("baseCrewmanSVG");

//	crewmanImage = document.getElementById("baseCrewmanSVG").cloneNode(true);
//	alert(crewmanImage);

	if (crewmanImage != null) {
		crewmanImage.width=scale;
		crewmanImage.height=scale;
	}

	return crewmanImage;

}

function drawCrewmanFaceOnLoad(currentID) {
//	alert("loaded: " + currentID);
	var workingImage;
	
	workingImage = document.getElementById(currentID);
	workingImage.width = 100;
	workingImage.height = 100;
	alert(workingImage);
}

function DrawCrewmanCard(index, crewmanToDraw, targetDiv, onClickFunction)
{
	var tmpDiv;
	var tmpDiv2;
	var tmpSpan;
	var tmpCrewmanFace;

	tmpDiv = document.createElement("div");
	tmpDiv.setAttribute('id', ('playerCard' + index));
	tmpDiv.setAttribute('class', 'crewmanContainer');
	tmpDiv.setAttribute('onClick', onClickFunction + '(' + index + ');');
		tmpDiv.setAttribute('style', 'position:absolute;top:' + ((Math.floor(index/3) * 200)) + 'px;left:' + ((index % 3) * 200) + 'px;');
	
	if (crewmanToDraw != null)
	{
		
		if (crewmanToDraw.ID == crewmanIDToSwap)
		{
			tmpDiv.setAttribute('style', 'position:absolute;top:' + ((Math.floor(index/3) * 200)) + 'px;left:' + ((index % 3) * 200) + 'px;border-color:#FF0000;');
		}

/*
		tmpDiv2 = document.createElement("div");
		tmpDiv2.setAttribute('class', 'crewmanPicture');
		tmpDiv2.setAttribute('style', 'position:absolute;top:76px;left:76px;');
		
		// at this point, draw and adjust the crewman's face.
		
		

		tmpCrewmanFace = drawCrewmanFace(100);
		if (tmpCrewmanFace != null) {
			tmpDiv2.appendChild(tmpCrewmanFace);
		}
		
		
		tmpDiv.appendChild(tmpDiv2);	
*/		
		tmpDiv2 = document.createElement("div");
		tmpDiv2.setAttribute('class', 'crewmanName');
		tmpDiv2.setAttribute('style', 'position:absolute;top:2px;left:2px;');
		tmpDiv2.appendChild(document.createTextNode(crewmanToDraw.firstName));
		tmpDiv2.appendChild(document.createElement("br"));
		tmpDiv2.appendChild(document.createTextNode(crewmanToDraw.lastName));
		tmpDiv.appendChild(tmpDiv2);	

		tmpDiv2 = document.createElement("div");
		tmpDiv2.setAttribute('class', 'crewmanStatLabels');
		tmpDiv2.setAttribute('style', 'position:absolute;top:78px;left:2px;');
		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("NAV: " + crewmanToDraw.navigation));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.navigation));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));

		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("GUN: " + crewmanToDraw.gunnery));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.gunnery));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));

		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("ENG: " + crewmanToDraw.engineering));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.engineering));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));

		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("MKT: " + crewmanToDraw.haggling));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.haggling));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));		tmpDiv2.appendChild(document.createTextNode("$" + crewmanToDraw.cost));
		tmpDiv.appendChild(tmpDiv2);	
	}	
	
	
	document.getElementById(targetDiv).appendChild(tmpDiv);
}

function DrawCrewmanLarge(crewmanToDraw, targetDiv, extraMessage)
{
	var tmpDiv;
	var tmpDiv2;
	var tmpSpan;

	tmpDiv = document.createElement("div");
	tmpDiv.setAttribute('id', ('playerInfoStats'));
	tmpDiv.setAttribute('class', 'crewmanContainerLarge');
	tmpDiv.setAttribute('style', 'position:absolute;top:2px;left:40px;');

	if (crewmanToDraw != null)
	{
		
//		tmpDiv2 = document.createElement("div");
//		tmpDiv2.setAttribute('class', 'crewmanPictureLarge');
//		tmpDiv2.setAttribute('style', 'position:absolute;top:2px;left:2px;');
//		tmpDiv.appendChild(tmpDiv2);	
		
		tmpDiv2 = document.createElement("div");
		tmpDiv2.setAttribute('class', 'crewmanStatLabelsLarge');
		tmpDiv2.setAttribute('style', 'position:absolute;top:2px;left:210px;');

		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("Navigation: " + crewmanToDraw.navigation));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.navigation));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));

		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("Gunnery: " + crewmanToDraw.gunnery));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.gunnery));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));

		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("Engineering: " + crewmanToDraw.engineering));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.engineering));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));

		tmpSpan = document.createElement("span");
		tmpSpan.appendChild(document.createTextNode("Marketing: " + crewmanToDraw.haggling));
		tmpSpan.setAttribute('style', setStatColor(crewmanToDraw.haggling));
		tmpDiv2.appendChild(tmpSpan);
		tmpDiv2.appendChild(document.createElement("br"));
		tmpDiv2.appendChild(document.createTextNode("Salary: $" + crewmanToDraw.cost));
		tmpDiv.appendChild(tmpDiv2);	
	}	
		
	document.getElementById(targetDiv).appendChild(tmpDiv);
	
	if (extraMessage != null)
	{
		tmpDiv = document.createElement("div");
		tmpDiv.setAttribute('id', ('playerInfoStatsMessage'));
		tmpDiv.setAttribute('style', 'position:absolute;top:230px;left:0px;width:600px;');
		tmpDiv.appendChild(document.createTextNode(extraMessage));
		document.getElementById(targetDiv).appendChild(tmpDiv);
	}
	
	if (document.getElementById("largeCrewmanSVG").getSVGDocument() != null) {	
		if (targetDiv == "crewmanActionLargeStats") {
			document.getElementById("largeCrewmanSVG").style.left = '46px';
			document.getElementById("largeCrewmanSVG").style.top = '130px';
		} else {
			document.getElementById("largeCrewmanSVG").style.left = '46px';
			document.getElementById("largeCrewmanSVG").style.top = '160px';
		}
		document.getElementById("largeCrewmanSVG").getSVGDocument().drawFace(crewmanToDraw.face);
	}	
}

function smallCrewmanImageClicked(pageIndex)
{
//	alert("crew image click: " + pageIndex);
	if (document.getElementById("crewManagementScreen").style.display != "none") {
		crewmanAction(pageIndex);
	} else {
		addCrewmanToCrew(pageIndex);
	}
}

jsFilesLoaded = jsFilesLoaded + 1;
