function randomize(id) {
	buildDeck();
	thisOne=document.getElementById(id);
	for (i=0; i<deck.length; i++) {
		free=true;
		for (j=0; j<selects.length; j++)
			if (selects[j]!=thisOne) {
				if (deck[i]==getValue(selects[j])) {
					free=false;
					break;
				}
			}
		if (free) {
			//validate card here
			thisOne.selectedIndex=deck[i]+1;
			break;
		}
	}
	setCurrentChoices();
	populateDifferencesList();
}

function clearBoxes() {
	for (i=0; i<selects.length; i++)
		selects[i].selectedIndex=0;
}

function randomizeAll() {
	setCurrentChoices();
	oldChoices=currentChoices;
	buildDeck();
	currentChoices=new Array();
		
	if (document.getElementById("reqAttack").checked) {
		index=getA("Attack");
		if (index==-1)
			alert("All attack cards have been excluded from the card pool. Please select some.");
		else {
			currentChoices[currentChoices.length]=deck[index];
			deck.splice(index,1);
		}
	}
	
	if (document.getElementById("reqReaction").checked && !document.getElementById("reqReaction").disabled) {
		index=getA("Reaction");
		if (index==-1)
			alert("All reaction cards have been excluded from the card pool. Please select some.");
		else {
			currentChoices[currentChoices.length]=deck[index];
			deck.splice(index,1);
		}
	}
	
	if (document.getElementById("reqBuy").checked) {
		index=getA("Buy");
		if (index==-1)
			alert("All extra gain cards have been excluded from the card pool. Please select some.");
		else {
			currentChoices[currentChoices.length]=deck[index];
			deck.splice(index,1);
		}
	}
	
	if (document.getElementById("reqCombo").checked) {
		index=getA("Combo");
		if (index==-1)
			alert("All combo cards have been excluded from the card pool. Please select some.");
		else {
			currentChoices[currentChoices.length]=deck[index];
			deck.splice(index,1);
		}
	}
	
	i=0;
	minPotions=3;
	noPotionsYet=true;
	skipPotions=false;
	while (currentChoices.length<10 && i<deck.length) {
		//Checking for smart potions. The first time a potion is found, if smart potions is enabled it takes the first 3 potions if room is available; otherwise it excludes potions completely
		while (cards[deck[i]].is("Potion")) {
			if (skipPotions)
				i++;
			else if (noPotionsYet) {
				noPotionsYet=false;
				if (document.getElementById("smartPotions").checked) {
					if (currentChoices.length+minPotions>10) {
						skipPotions=true;
						i++;
					} else {
						potions=0;
						while (potions<minPotions) {
							index=getA("Potion");
							if (index==-1) {
								alert("Too many potion-using cards have been excluded from the card pool. Please select some.");
								potions=minPotions;
							} else {
								currentChoices[currentChoices.length]=deck[index];
								deck.splice(index,1);
								potions++;
							}
						}
					}
				}
			} else
				break;
		}
		currentChoices[currentChoices.length]=deck[i];
		i++;
	}
	
	sortCurrentChoices();
	populateCurrentChoices();
	populateDifferencesList();
}



function populateCurrentChoices() {
	clearBoxes();
	for (i=0; i<currentChoices.length; i++)
		selects[i].selectedIndex=currentChoices[i]+1;
}
