// Subtotal for pedido form.

var acctTypes = ['lite','standard','professional'];
var typeToId = {'lite':'m3fbrp__98','standard':'m3fbrp__99','professional':'m3fbrp__100'};


function subTotal () {
	var nLite = totalAccounts('lite');
	var nStandard = totalAccounts('standard');
	var nProfessional = totalAccounts('professional');
	
	// Calculate values
	var subTotal = nLite * 3.50 + nStandard * 6.50 + nProfessional * 8.50;
	
	return subTotal;
}


function totalAccounts (type){
	var total = 0;

	// loop array getting values
	for (var i in typeToId) {
		if ( ! type || (type && type == i) ) {
			var elemId = typeToId[i];
			var elem = document.getElementById(elemId);
			var value = parseInt(elem.options[elem.selectedIndex].text);
			total += value;
		}
	}
	
	return total;
}


function showTotal() {
	document.getElementById('subTotal').innerHTML = '<h4>Valor mensal: R$' + subTotal() + '</h4>';
}

function validatePedido () {
	var accounts = totalAccounts();
	var total = subTotal();
	var baseMsg = "Pedido minimo: ";
	var msg = "";
	
//	if ( accounts < 20 ) {
//		msg = "20 contas ";
//	}

// TEMPORARY DEACTIVATION OF MINIMUM REQUIREMENT
return true;

	if ( total < 50 ) {
		msg += "R$50. ";
	}

	if (msg) {
		alert(baseMsg + msg);
		return false;	
	}
	
	return true;
}


