// an global variable to count the number of attachments
var autoAttachments = 0

// more global variables for the temp values
var tempFire = 0;
var tempWind = 0;
var tempThunder = 0;
var tempLight = 0;
var tempIce = 0;
var tempEarth = 0;
var tempWater = 0;
var tempDark = 0;

// calculates the maximum elemental attributes of a head and frame combination
function autoMax() {
	var maxFire = 0;
	var maxWind = 0;
	var maxThunder = 0;
	var maxLight = 0;
	var maxIce = 0;
	var maxEarth = 0;
	var maxWater = 0;
	var maxDark = 0;

	//this switch sets the max values for each attribute based upon the selected head
	switch(document.getElementById("autoHead").selectedIndex) {

		// stats of the harlequin head
		case 0: maxFire = 2;
			maxWind = 2;
			maxThunder = 2;
			maxLight = 0;
			maxIce = 2;
			maxEarth = 2;
			maxWater = 2;
			maxDark = 0;
		break;

		// stats of the sharpshot head
		case 1: maxFire = 3;
			maxWind = 3;
			maxThunder = 2;
			maxLight = 2;
			maxIce = 0;
			maxEarth = 0;
			maxWater = 2;
			maxDark = 0;
		break;
		
		// stats of the soulsoother head
		case 2: maxFire = 0;
			maxWind = 2;
			maxThunder = 0;
			maxLight = 3;
			maxIce = 3;
			maxEarth = 2;
			maxWater = 3;
			maxDark = 0;
		break;
		
		// stats of the spiritreaver head
		case 3: maxFire = 0;
			maxWind = 2;
			maxThunder = 0;
			maxLight = 0;
			maxIce = 3;
			maxEarth = 2;
			maxWater = 3;
			maxDark = 3;
		break;
		
		// stats of the stormwaker head
		case 4: maxFire = 0;
			maxWind = 2;
			maxThunder = 0;
			maxLight = 0;
			maxIce = 3;
			maxEarth = 2;
			maxWater = 3;
			maxDark = 2;
		break;
		
		// stats of the valoredge head
		case 5: maxFire = 3;
			maxWind = 2;
			maxThunder = 2;
			maxLight = 2;
			maxIce = 0;
			maxEarth = 3;
			maxWater = 0;
			maxDark = 0;
		break;
	}

	//this switch sets the max values for each attribute based upon the selected frame
	switch(document.getElementById("autoFrame").selectedIndex) {

		// stats of the harlequin frame
		case 0: maxFire += 2;
			maxWind += 2;
			maxThunder += 2;
			maxLight += 0;
			maxIce += 2;
			maxEarth += 2;
			maxWater += 2;
			maxDark += 0;
		break;

		// stats of the sharpshot frame
		case 1: maxFire += 3;
			maxWind += 3;
			maxThunder += 2;
			maxLight += 2;
			maxIce += 0;
			maxEarth += 0;
			maxWater += 2;
			maxDark += 0;
		break;
		
		// stats of the stormwaker frame
		case 2: maxFire += 0;
			maxWind += 2;
			maxThunder += 0;
			maxLight += 3;
			maxIce += 3;
			maxEarth += 2;
			maxWater += 3;
			maxDark += 0;
		break;
		
		// stats of the valoredge frame
		case 3: maxFire += 0;
			maxWind += 2;
			maxThunder += 0;
			maxLight += 0;
			maxIce += 3;
			maxEarth += 2;
			maxWater += 3;
			maxDark += 3;
		break;
	}

	// changes the form to display the maximum values
	document.getElementById("maxFire").value = maxFire;
	document.getElementById("maxWind").value = maxWind;
	document.getElementById("maxThunder").value = maxThunder;
	document.getElementById("maxLight").value = maxLight;
	document.getElementById("maxIce").value = maxIce;
	document.getElementById("maxEarth").value = maxEarth;
	document.getElementById("maxWater").value = maxWater;
	document.getElementById("maxDark").value = maxDark;
}

// calculates the total value of the fire attachments.
function autoFire(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempFire += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempFire > parseInt(document.getElementById("maxFire").value)){
			autoAttachments--;
			tempFire -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Fire capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempFire -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempFire -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempFire").value = tempFire;
}

// calculates the total value of the wind attachments.
function autoWind(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempWind += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempWind > parseInt(document.getElementById("maxWind").value)){
			autoAttachments--;
			tempWind -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Wind capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempWind -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempWind -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempWind").value = tempWind;
}

// calculates the total value of the thunder attachments.
function autoThunder(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempThunder += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempThunder > parseInt(document.getElementById("maxThunder").value)){
			autoAttachments--;
			tempThunder -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Thunder capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempThunder -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempThunder -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempThunder").value = tempThunder;
}

// calculates the total value of the light attachments.
function autoLight(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempLight += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempLight > parseInt(document.getElementById("maxLight").value)){
			autoAttachments--;
			tempLight -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Light capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempLight -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempLight -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempLight").value = tempLight;
}

// calculates the total value of the ice attachments.
function autoIce(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempIce += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempIce > parseInt(document.getElementById("maxIce").value)){
			autoAttachments--;
			tempIce -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Ice capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempIce -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempIce -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempIce").value = tempIce;
}

// calculates the total value of the earth attachments.
function autoEarth(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempEarth += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempEarth > parseInt(document.getElementById("maxEarth").value)){
			autoAttachments--;
			tempEarth -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Earth capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempEarth -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempEarth -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempEarth").value = tempEarth;
}

// calculates the total value of the water attachments.
function autoWater(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempWater += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempWater > parseInt(document.getElementById("maxWater").value)){
			autoAttachments--;
			tempWater -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Water capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempWater -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempWater -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempWater").value = tempWater;
}

// calculates the total value of the dark attachments.
function autoDark(tempAttachment) {

	// adjusts the temp value and the number of attachments
	if (tempAttachment.checked) {
		autoAttachments++;
		tempDark += parseInt(tempAttachment.value);
	// checks to see if the max capacity is exceeded, if it is then that selection is undone
		if (tempDark > parseInt(document.getElementById("maxDark").value)){
			autoAttachments--;
			tempDark -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("That attachment would exceed the Dark capacity of this head and frame combination.");
		}
	// checks the number of attachments (12 is the maximum)
		if (autoAttachments > 12) {
			autoAttachments--;
			tempDark -= parseInt(tempAttachment.value);
			tempAttachment.checked = false;
			alert("You may only equip 12 attachments.");
		}
	}
	else {
		autoAttachments--;
		tempDark -= parseInt(tempAttachment.value);
	}

	document.getElementById("tempDark").value = tempDark;
}
