var size;
var current;

function initLoad() {
	document.getElementById('boxSize').value = 0;
	document.getElementById('location').value = '00';
	ten = new Array();
		ten[0] = 'item';
		ten[1] = 'item1';
		ten[2] = 'item2';
		ten[3] = 'item3';
		ten[4] = 'item4';
		ten[5] = 'item5';
		ten[6] = 'item6';
		ten[7] = 'item7';
		ten[8] = 'item8';
		ten[9] = 'item9';
		ten[10] = 'item10';
		ten[11] = 'item11';
		ten[12] = 'item12';
		ten[13] = 'item13';
		ten[14] = 'item14';
		ten[15] = 'item15';
		ten[16] = 'item16';
		ten[17] = 'item17';
	twenty = new Array();
		twenty[0] = 'item';
		twenty[1] = 'item18';
		twenty[2] = 'item19';
		twenty[3] = 'item20';
		twenty[4] = 'item21';
		twenty[5] = 'item22';
		twenty[6] = 'item23';
	thirty = new Array();
		thirty[0] = 'item';
		thirty[1] = 'item24';
		thirty[2] = 'item25';
		thirty[3] = 'item26';
		thirty[4] = 'item27';
		thirty[5] = 'item28';
		thirty[6] = 'item29';
		thirty[7] = 'item30';
		thirty[8] = 'item31';
		thirty[9] = 'item32';
		thirty[10] = 'item33';
		thirty[11] = 'item34';
		thirty[12] = 'item35';
		thirty[13] = 'item36';
		thirty[14] = 'item37';
		thirty[15] = 'item38';
		thirty[16] = 'item39';
		thirty[17] = 'item40';
		thirty[18] = 'item41';
		thirty[19] = 'item42';
	weight = new Array();
		weight[0] = 0;
		weight[1] = 10;
		weight[2] = 10;
		weight[3] = 5;
		weight[4] = 5;
		weight[5] = 5;
		weight[6] = 5;
		weight[7] = 5;
		weight[8] = 5;
		weight[9] = 5;
		weight[10] = 5;
		weight[11] = 5;
		weight[12] = 5;
		weight[13] = 5;
		weight[14] = 5;
		weight[15] = 10;
		weight[16] = 10;
		weight[17] = 5;
		weight[18] = 15;
		weight[19] = 15;
		weight[20] = 12;
		weight[21] = 7;
		weight[22] = 7;
		weight[23] = 7;
		weight[24] = 15;
		weight[25] = 11;
		weight[26] = 15;
		weight[27] = 20;
		weight[28] = 20;
		weight[29] = 11;
		weight[30] = 11;
		weight[31] = 11;
		weight[32] = 11;
		weight[33] = 11;
		weight[34] = 11;
		weight[35] = 11;
		weight[36] = 15;
		weight[37] = 15;
		weight[38] = 15;
		weight[39] = 11;
		weight[40] = 15;
		weight[41] = 15;
		weight[42] = 15;
}

function box() {
	size = document.getElementById('boxSize').value;
	document.getElementById('temp').innerHTML = 'Weight: '+'0'+'/'+size;
	document.form.reset();
	total = 0;
	count = 1;
	while (ten[count]) {
		document.getElementById(ten[count]).style.visibility = 'hidden';
		count++;
	}
	count = 1;
	while (twenty[count]) {
		document.getElementById(twenty[count]).style.visibility = 'hidden';
		count++;
	}
	count = 1;
	while (thirty[count]) {
		document.getElementById(thirty[count]).style.visibility = 'hidden';
		count++;
	}
	count = 1;
	
	if (size == '10') {
		while (ten[count]) {
			document.getElementById(ten[count]).style.visibility = 'visible';
			count++;
		}
	} else if (size == '21') {
		while (twenty[count]) {
			document.getElementById(twenty[count]).style.visibility = 'visible';
			count++;
		}
		document.getElementById(ten[1]).style.visibility = 'visible';
		document.getElementById(ten[2]).style.visibility = 'visible';
	} else if (size == '30') {
		while (thirty[count]) {
			document.getElementById(thirty[count]).style.visibility = 'visible';
			count++;
		}
		document.getElementById(twenty[1]).style.visibility = 'visible';
		document.getElementById(twenty[2]).style.visibility = 'visible';
	} else if (size == '45') {
		while (thirty[count]) {
			document.getElementById(thirty[count]).style.visibility = 'visible';
			count++;
		}
		document.getElementById(twenty[1]).style.visibility = 'visible';
		document.getElementById(twenty[2]).style.visibility = 'visible';
	} else if (size == '60') {
		while (thirty[count]) {
			document.getElementById(thirty[count]).style.visibility = 'visible';
			count++;
		}
		document.getElementById(twenty[1]).style.visibility = 'visible';
		document.getElementById(twenty[2]).style.visibility = 'visible';
	}
}

function update(item) {
	total = total - (current * weight[item]);
	add = document.getElementById('item'+item).value * weight[item];
	if ((total + add) > size) {
		document.getElementById('item'+item).value = current;
		total = total + (current * weight[item]);
		document.getElementById('temp').innerHTML = 'Weight: '+total+'/'+size;
	} else {
		total = total + add;
		document.getElementById('temp').innerHTML = 'Weight: '+total+'/'+size;
	}
	document.getElementById('location').focus();
}

function getCurrent(item) {
	current = document.getElementById('item'+item).value;
}