//variables for item selection and combination
var firstItem=0;
var secondItem=0;

function combine_items() {
	document.actions.item1.value=firstItem;
	if(secondItem==0)
	{
		document.actions.item2.value=firstItem;
	} else {
		document.actions.item2.value=secondItem;
	}
	document.actions.do_action.value="combine";
}

function break_item() {
	//need to ensure that if the first item isn't the one actively selected, we give the value of the item that IS selected
	if(firstItem==0)
		firstItem=secondItem;
	document.actions.item1.value=firstItem;
	document.actions.do_action.value="break";
}

function toggle_combine(toggle)
{
	combineButton=document.getElementById("combineItem");
	if(toggle==true)
	{
		//enable the combine button
		combineButton.className="button";
		combineButton.disabled=false;
	} else {
		//disable the combine button
		combineButton.className="disabled";
		combineButton.disabled=true;
	}
}

function toggle_break(toggle)
{
	breakButton=document.getElementById("breakItem");
	if(toggle==true)
	{
		//enable the break button
		breakButton.className="button";
		breakButton.disabled=false;
	} else {
		//disable the break button
		breakButton.className="disabled";
		breakButton.disabled=true;
	}
}

function select_item(item) {
	changeMe=document.getElementById("inv"+item);
	times=document.actions.times;
	max=document.actions.max;
	switch(item)
	{
		case firstItem: //if the item selected is the first item
			firstItem=0;
			changeMe.className="item";
			if(secondItem==0) { //if there's no other item selected
				//disable the break button
				toggle_break(false);
				//disable the combine button
				toggle_combine(false);
				times.className="disabled";
				times.disabled=true;
				max.className="disabled";
				max.disabled=true;
			} else { //if there is still a second item selected
				//enable the break button
				toggle_break(true);
			}
			break;
		case secondItem:  //if the item selected is the second item
			secondItem=0;
			changeMe.className="item";
			if(firstItem==0) {  //if there's no other item selected
				//disable the break button
				toggle_break(false);
				//disable the combine button
				toggle_combine(false);
				times.className="disabled";
				times.disabled=true;
				max.className="disabled";
				max.disabled=true;
			} else { //if there's still another item selected
				//enable the break button
				toggle_break(true);
			}
			break;
		default:
			if(firstItem==0) { //if the first item isn't selected
				firstItem=item;
				changeMe.className="selected";
				max.className="button";
				max.disabled=false;
				//enable the combine button
				toggle_combine(true);
				if(secondItem==0) { //if the second item isn't selected
					//enable the break button
					toggle_break(true);
					times.className="button";
					times.disabled=false;
				} else { //if there IS a second item selected, then
					//disable the break button
					toggle_break(false);
				}
			} else {  
				if(secondItem==0) { //if the second item isn't selected
					secondItem=item;
					changeMe.className="selected";
					//disable the break button
					toggle_break(false);
				} //otherwise, do nothing, to prevent 3 items from being selected
			}
			break;
	}
}
