function switchDisplay(num) {
	for (x = 1; x < 7; x++) {
		if (x == num) {
			document.getElementById("table" + x).style.visibility = "visible";
			document.getElementById("table" + x).style.display = "block";
			document.getElementById("sb_" + x).style.backgroundColor = "gray";
			}
		else {
			document.getElementById("table" + x).style.visibility = "hidden";
			document.getElementById("table" + x).style.display = "none";
			document.getElementById("sb_" + x).style.backgroundColor = "black";
			}
		}
	for (d = 1; d < 7; d++) {
		for (i = 1; i < 7; i++) {
			if (document.getElementById("pos_" + d + "_" + i)) document.getElementById("pos_" + d + "_" + i).selectedIndex = 0;
			if (document.getElementById("sell" + i)) document.getElementById("sell" + i).selectedIndex = 0;
			}
		}
	document.getElementById("cashback").innerHTML = formatCurrency(0)
	}

function calcSC(i) {

	//SET THE LEVEL RANKS
	var aPos = new Array()
	nFR = 0;
	for (x = 1; x <= i; x++) {
		aPos[x] = document.getElementById("pos_" + x + "_" + i).selectedIndex;
		}

	licNum = parseInt(document.getElementById("licnum" + i).value)
	licSold = document.getElementById("lictype" + i).selectedIndex;
	if (isNaN(licNum)) licNum = 0;
	myComm = new Array(0,0,0,0,0,0,0)
	minStatus = 0;
	if (aPos[1] > 0 && licSold > 0 && licNum > 0) {
		switch (licSold) {
			case 1:
				//MD Sold
				totComm = 0;
				for (d = i; d > 0; d--) {
					if (document.getElementById("pos_" + d + "_" + i).selectedIndex == 1 && minStatus < 1) { myComm[d] = 100 - totComm; totComm += myComm[d]; minStatus = 2; }
					if (document.getElementById("pos_" + d + "_" + i).selectedIndex == 2 && minStatus < 2) { myComm[d] = 50 - totComm; if (totComm > 0) { totComm += myComm[d] } else { totComm = 50 }; minStatus = 2; }
					if (document.getElementById("pos_" + d + "_" + i).selectedIndex == 3 && minStatus < 3) { myComm[d] = 200 - totComm; if (totComm > 0) { totComm += myComm[d] } else { totComm = 200 }; minStatus = 3; }
					if (document.getElementById("pos_" + d + "_" + i).selectedIndex == 4 && minStatus < 4) { myComm[d] = 250 - totComm; if (totComm > 0) { totComm += myComm[d] } else { totComm = 300 }; minStatus = 4; }
					}
				break;
			case 2:
				//RMD Sold
				totComm = 0;
				for (d = i; d > 0; d--) {
					if (document.getElementById("pos_" + d + "_" + i).selectedIndex == 3 & minStatus < 3) { myComm[d] = 1000 - totComm; totComm += myComm[d]; minStatus = 3; }
					if (document.getElementById("pos_" + d + "_" + i).selectedIndex == 4 & minStatus < 4) { myComm[d] = 1000 - totComm; totComm += myComm[d]; minStatus = 4; }
					}
				break;
			}
		}
	
		//BONUSES
		var curBonusAmount = 0;
		if (licSold == 2 && aPos[1] == 4 && licNum > 1) {
			blnOnlyNMD = true;
			for (r = 2; r < aPos.length; r++) {
				if (aPos[r] == 4) {
					blnOnlyNMD = false;
					break;
					}
				}
			if (blnOnlyNMD == true) {
				var curBonusPer = (licNum - 1) * 100;
				if (curBonusPer > 1000) curBonusPer = 1000;
				curBonusAmount = licNum * curBonusPer;
				document.getElementById("bonus").innerHTML = formatCurrency(curBonusAmount)
				}
			else document.getElementById("bonus").innerHTML = "$0.00";
			}
		else if (document.getElementById("bonus")) document.getElementById("bonus").innerHTML = "$0.00";
	
	curLicenseCommission = (myComm[1] * licNum);
	document.getElementById("cashback").innerHTML = formatCurrency(curLicenseCommission);
	}