var taxaserv = 6.90; //Multiplicador para o VALUE que vem do combo de tipo de servico

var GBTraf1 = 50;  
var GBTraf2 = 20; 
var txTraf1 = 0.800; 
var txTraf2 = 0.920; 
var txTraf3 = 1; 

var MBEspacoSite1  = 5000;  // A partir de 5GB
var MBEspacoSite2  = 1000;  // A partir de 1GB
var txEspacoSite1  = 0.010;
var txEspacoSite2  = 0.012; 
var txEspacoSite3  = 0.015;

var MBEspacoEmail1 = 5000;  // A partir de 20GB
var MBEspacoEmail2 = 10000; // A partir de 5GB
var txEspacoEmail1 = 0.010; 
var txEspacoEmail2 = 0.012;
var txEspacoEmail3 = 0.015;

var NumeroBase1 = 5;
var NumeroBase2 = 2;
var txNumeroBase1 = 1.5;
var txNumeroBase2 = 1.5;
var txNumeroBase3 = 0;

var NumeroContaFTP1 = 10; 
var NumeroContaFTP2 = 2;
var txNumeroContaFTP1 = 0.5;
var txNumeroContaFTP2 = 0.8;
var txNumeroContaFTP3 = 0; 

var NumeroSubDom1 = 10; 
var NumeroSubDom2 = 1;
var txNumeroSubDom1 = 0.088;
var txNumeroSubDom2 = 0.10;
var txNumeroSubDom3 = 0.30; 

var NumeroListas1 = 5; 
var NumeroListas2 = 1;
var txNumeroListas1 = 1;
var txNumeroListas2 = 1.8;
var txNumeroListas3 = 1.8; 

var NumeroDomAd1 = 5; 
var NumeroDomAd2 = 1;
var txNumeroDomAd1 = 2;
var txNumeroDomAd2 = 3;
var txNumeroDomAd3 = 1; 

function MontaPlano(){
	 var form = document.getElementById("frmassinatura");

   if (form != null) {
		var CodTipoServico   = (document.getElementById("tipo_servico").value * 1);
		var FatorTipoServico = 0;

		switch (CodTipoServico)	{
			case 1 : 
				FatorTipoServico = 1.16;  /// Email = R$ 7,00 mes
			break;
 		  case 2 : 
				FatorTipoServico = 1.666;   /// Park = R$ 2,50 mes
			break;
			case 3 : 
				FatorTipoServico = 1.6; ////////4.365;
			break;
			case 4 : 
				FatorTipoServico = 3.406;  /// Linux - Bronze basico R$ 27,00 
											//// T 5gb , Site 300mb , email 200mb - banco 1, ftp 1
			break;
			case 5 : 
				FatorTipoServico = 4.0;  // Windows - Bronze basico R$ 
			break;
			case 6 : 
				FatorTipoServico = 3;
			break;
			case 7 : 
				FatorTipoServico = 2.3;
			break;
			case 8 : 
				FatorTipoServico = 2.8;
			break;
			case 9 : 
				FatorTipoServico = 3;
			break;
		}

    switch (CodTipoServico)	{
			case 1:
				document.getElementById("espaco_site").value = 0;  
				if (document.getElementById("espaco_email").value == 0)  
					document.getElementById("espaco_email").value = 200;  
				if (document.getElementById("trafego_mensal").value == 0)  
					document.getElementById("trafego_mensal").value = 10;  
					document.getElementById("base_bd").value = 0;  
					document.getElementById("conta_ftp").value = 0;  
					document.getElementById("subdom").value = 0;  
					document.getElementById("listas").value = 0;  
					document.getElementById("dom_ad").value = 0;  
			break;
			case 2:
				  document.getElementById("espaco_site").value  = 0;  
					document.getElementById("espaco_email").value = 0;  
					document.getElementById("trafego_mensal").value = 0;  
					document.getElementById("base_bd").value = 0;  
					document.getElementById("conta_ftp").value = 0;  
					document.getElementById("subdom").value = 0;  
					document.getElementById("listas").value = 0;  
					document.getElementById("dom_ad").value = 0;  
			break;
			case 3:
				  document.getElementById("espaco_site").value  = 0;
					document.getElementById("espaco_email").value = 0;
					document.getElementById("trafego_mensal").value = 0;
					document.getElementById("base_bd").value = 0;  
					document.getElementById("conta_ftp").value = 1;  
					document.getElementById("subdom").value = 0;  
					document.getElementById("listas").value = 0;  
					document.getElementById("dom_ad").value = 0;  
			break;
			default:
				if (document.getElementById("espaco_site").value == 0)  
				  document.getElementById("espaco_site").value  = 200;  
				if (document.getElementById("espaco_email").value == 0)  
					document.getElementById("espaco_email").value = 200;  
				if (document.getElementById("trafego_mensal").value == 0)  
					document.getElementById("trafego_mensal").value = 10;  
				if (document.getElementById("base_bd").value == 0)  
					document.getElementById("base_bd").value = 1;
				if (document.getElementById("conta_ftp").value == 0)  
					document.getElementById("conta_ftp").value = 1;  
				if (document.getElementById("subdom").value == 0)  
					document.getElementById("subdom").value = 0;  
				if (document.getElementById("listas").value == 0)  
					document.getElementById("listas").value = 0;  
				if (document.getElementById("dom_ad").value == 0)  
					document.getElementById("dom_ad").value = 0;  
			break;			
		}
		
		var trafego     = document.getElementById("trafego_mensal").value;  
		var espacosite  = document.getElementById("espaco_site").value;  
		var espacoemail = document.getElementById("espaco_email").value;  
		var basebd      = document.getElementById("base_bd").value;  
		var contaftp    = document.getElementById("conta_ftp").value;  
		var subdom      = document.getElementById("subdom").value;  
		var listas      = document.getElementById("listas").value;  
		var dom_ad      = document.getElementById("dom_ad").value;  
		var valor       = document.getElementById("valor");
		  
		txGBTraf         = 0;
		txMBEspacoSite   = 0;
		txMBEspacoEmail  = 0;
		txNumeroBase     = 0;
		txNumeroContaFTP = 0;
		txNumeroSubDom   = 0;
		txNumeroListas   = 0;
		txNumeroDomAd    = 0;
		calcValor        = 0;
					
		if (trafego >= GBTraf1)
			txGBTraf = txTraf1;
		else if (trafego >= GBTraf2)
			txGBTraf = txTraf2;
		else 
		  txGBTraf = txTraf3;
		
		if (espacosite >= MBEspacoSite1)
			txMBEspacoSite = txEspacoSite1;
		else	if (espacosite >= MBEspacoSite2)
			txMBEspacoSite = txEspacoSite2;
		else 
		  txMBEspacoSite = txEspacoSite3;
			
		if (espacoemail >= MBEspacoEmail1)
			txMBEspacoEmail = txEspacoEmail1;
		else if (espacoemail >= MBEspacoEmail2)
			txMBEspacoEmail = txEspacoEmail2;
		else 
		  txMBEspacoEmail = txEspacoEmail3;

    if (basebd >= NumeroBase1)
			txNumeroBase = txNumeroBase1;
		else if (basebd >= NumeroBase2)
			txNumeroBase = txNumeroBase2;
		else 
		  txNumeroBase = txNumeroBase3;

		if (contaftp >= NumeroContaFTP1)
			txNumeroContaFTP = txNumeroContaFTP1;
		else if (contaftp >= NumeroContaFTP2)
			txNumeroContaFTP = txNumeroContaFTP2;
		else 
		  txNumeroContaFTP = txNumeroContaFTP3;

		if (subdom >= NumeroSubDom1)
			txNumeroSubDom = txNumeroSubDom1;
		else if (subdom >= NumeroSubDom2)
			txNumeroSubDom = txNumeroSubDom2;
		else 
		  txNumeroSubDom = txNumeroSubDom3;

		if (listas >= NumeroListas1)
			txNumeroListas = txNumeroListas1;
		else if (listas >= NumeroListas2)
			txNumeroListas = txNumeroListas2;
		else 
		  txNumeroListas = txNumeroListas3;
    
		if (dom_ad >= NumeroDomAd1)
			txNumeroDomAd = txNumeroDomAd1;
		else if (dom_ad >= NumeroDomAd2)
			txNumeroDomAd = txNumeroDomAd2;
		else 
		  txNumeroDomAd = txNumeroDomAd3;

		calcValor = (taxaserv * FatorTipoServico);
		calcValor += parseFloat((trafego - 9) * txGBTraf);
		calcValor += parseFloat(espacosite * txMBEspacoSite);
		calcValor += parseFloat(espacoemail * txMBEspacoEmail);
		calcValor += parseFloat(basebd * txNumeroBase);
		calcValor += parseFloat(contaftp * txNumeroContaFTP);
		calcValor += parseFloat(subdom * txNumeroSubDom);
		calcValor += parseFloat(listas * txNumeroListas);
		calcValor += parseFloat(dom_ad * txNumeroDomAd);

    calcValor = calcValor.toFixed(2).toString().replace(".",",");
		if (document.getElementById("valor") != null){
		    document.getElementById("valor").innerHTML = calcValor.toString();
		}
	}	  
}
