		
	function troca_plano(plano, cupom) {
		/* Passo 1: Muda as informações ao lado da imagem */
		var assine_fundo_imagem = document.getElementById('assine-fundo-imagem');
		document.getElementById('assine-info-ed').innerHTML = dados[((plano - 1) * 4) + 0];
		document.getElementById('assine-info-tm').innerHTML = dados[((plano - 1) * 4) + 1];
		document.getElementById('assine-info-tx').innerHTML = dados[((plano - 1) * 4) + 2];
		document.getElementById('assine-info-vl').innerHTML = dados[((plano - 1) * 4) + 3];
		assine_fundo_imagem.style.background = 'url("' + caminho + '/imagens/' + imgs[plano - 1] + '")';
		
		/* Passo 2: Recria a tabela de preços */
		/* 2.1: Exclui todas as linhas (menos o título) */
		var table = document.getElementById('assine-pagamento-tabela');
		while (table.rows.length > 1) {
			table.deleteRow(table.rows.length - 1);
		}
		/* 2.2: Adiciona as novas linhas */
		var plano_id;
		for (i = 0; i < qt_linhas; i++) {
			plano_id = linhas[i * 6];
			if (plano_id == plano) {
				var chave = table.rows.length -1;
				
				/* Periodicidade */
				var tr = table.insertRow(table.rows.length);
				tr.setAttribute('id', 'tr_' + chave);
				tr.setAttribute('onMouseOver', 'tr_over(this);');
				tr.setAttribute('onMouseOut', 'tr_out(this);');
				
				var td = tr.insertCell(0);
				if (chave == 1 && !cupom) {
					td.style.borderColor = '#fffbe2 #fadcc2 #fffbe2 #fffbe2';
				}
				td.innerHTML = 
					'<span style="float: left; margin-left: 30px;">' + 
						'<input onclick="ver_pagamento(this);" class="input-radio" type="radio" name="plano_pagamento_id" id="plano_pagamento_id_' + chave + '" value="' + linhas[(i * 6) + 1] + '" />' +
						'</span>' +
					'<span style="float: right;  padding-right: 10px;"><label for="plano_pagamento_id_' + chave + '">' + linhas[(i * 6) + 2] + '</label></span>';
				
				/* Valor */
				var td = tr.insertCell(1);
				if (chave == 1 && !cupom) {
					td.style.borderColor = '#fffbe2 #fadcc2 #fffbe2 #fffbe2';
				}
				td.innerHTML = 'R$ ' + nbf(linhas[(i * 6) + 3]);
				
				/* Desconto */
				var td = tr.insertCell(2);
				if (chave == 1 && !cupom) {
					td.style.borderColor = '#fffbe2 #fadcc2 #fffbe2 #fffbe2';
				}
				td.innerHTML = linhas[(i * 6) + 4];
				
				/* Próxima Fatura em */
				var td = tr.insertCell(3);
				td.style.borderColor = '#fffbe2 #fffbe2 ' + ((chave == 1 && !cupom) ? '#fffbe2' : '#fadcc2') + ' #fffbe2';
				td.innerHTML = linhas[(i * 6) + 5];
			}
		}
		
		atualiza_pagamento_tabela_tam();

		esconde('dom');
		esconde('vlr');
		
		ds_plano = get('plano').options[get('plano').selectedIndex].text;
	
		calcula_valor_fatura();

	}
	
	function seta_cupom(cupom_id, desconto_nr_meses, periodicidade, vlr_total, prox_fatura, plano_pagamento_id) {	
		/* Recria a tabela (limpa de cupom, se existir) */
		troca_plano(get('plano').value, true);
		
		/* Cria uma nova linha */
		var table = document.getElementById('assine-pagamento-tabela');
		var chave = table.rows.length -1;
		
		/* Periodicidade */
		var tr = table.insertRow(table.rows.length);
		tr.setAttribute('id', 'tr_' + chave);
		tr.setAttribute('onMouseOver', 'tr_over(this);');
		tr.setAttribute('onMouseOut', 'tr_out(this);');

		var td = tr.insertCell(0);
		td.style.borderColor = '#fffbe2 #fadcc2 #fffbe2 #fffbe2';
		td.innerHTML = 
			'<span style="float: left; margin-left: 30px;">' + 
				'<input checked="true" onclick="ver_pagamento(this);" class="input-radio" type="radio" name="plano_pagamento_id" id="plano_pagamento_id_' + chave + '" value="' + plano_pagamento_id + '" />' +
				'</span>' +
			'<span style="float: right;  padding-right: 10px;"><label for="plano_pagamento_id_' + chave + '">' + periodicidade + '</label></span>';
		
		get('plano_pagamento_id_cupom').value = plano_pagamento_id;
		get('vlr_plano_pagamento_id_cupom').value = vlr_total;
		get('periodicidade_plano_pagamento_id_cupom').value = periodicidade;
		
		/* Valor */
		var td = tr.insertCell(1);
		td.innerHTML = 'R$ ' + nbf(vlr_total);
		td.style.borderColor = '#fffbe2 #fadcc2 #fffbe2 #fffbe2';
		
		/* Desconto */
		var td = tr.insertCell(2);
		td.innerHTML = desconto_nr_meses;
		td.style.borderColor = '#fffbe2 #fadcc2 #fffbe2 #fffbe2';
		
		/* Próxima Fatura em */
		var td = tr.insertCell(3);
		td.innerHTML = prox_fatura;
		td.style.borderColor = '#fffbe2 #fffbe2 #fffbe2 #fffbe2';	
		
		atualiza_pagamento_tabela_tam();

		expande('dom');
		esconde('vlr');
		
		ver_pagamento('plano_pagamento_id_' + chave);
		calcula_valor_fatura();
	
	}
	
	/* Altera o tamanho dos divs de acordo com o número de registros */
	function atualiza_pagamento_tabela_tam() {
		var table = document.getElementById('assine-pagamento-tabela');
		var div = document.getElementById('assine-pagamento-div-tab');
		var borda = document.getElementById('assine-pagamento-borda');
		var div_hg_antigo = div.style.height;
		div.style.height = (58 + (32 * (table.rows.length - 1))) + 'px';
		borda.style.height = (51 + (33 * (table.rows.length - 1))) + 'px';
		/* Variação para tamanho geral do documento */
		var variacao = parseInt(div.style.height) - parseInt(div_hg_antigo);
		set_principal_height(get_principal_height() + variacao);
		
	}
	
	
	/* Mouse over das opções de pagamento */
	function tr_over(tr) {
		var i = 0;
		var el;
		while (el = document.getElementById('plano_pagamento_id_' + i)) {
			document.getElementById('tr_' + i).style.backgroundColor = '#fffbe2';
			i++;
		}
		tr.style.backgroundColor = '#fff4be';
	}
	function tr_out(tr) {
		var el;
		tr.style.backgroundColor = '#fffbe2';
		var i = 0;
		while (el = document.getElementById('plano_pagamento_id_' + i)) {
			document.getElementById('tr_' + i).style.backgroundColor = (el.checked) ? '#fff4be' : '#fffbe2';
			i++;
		}
	}
	/* Para acertar o tamanho geral, ao expandir divs */
	function get_principal_height() {
		var hg = document.getElementById('principal').style.height;
		if (!hg) {
			hg = height;
		}
		return(parseInt(hg));
	}
	/* Para acertar o tamanho geral, ao expandir divs */
	function set_principal_height(hg) {
		hg = parseInt(hg);
		document.getElementById('principal').style.height = hg + 'px';
		document.getElementById('noticias-principal').style.height = (hg - 272) + 'px';
		document.getElementById('noticias-rodape-novo').style.marginTop = (hg - 415) + 'px';
	}
	var exp_dom = false;
	var exp_vlr = false;
	function expande(bloco) {
		if ((bloco == 'dom') && (!exp_dom)) {
			document.getElementById('assine-configuracao').style.display = 'block';
			set_principal_height(get_principal_height() + 300);
			exp_dom = true;
		}
		if ((bloco == 'vlr') && (!exp_vlr)) {
			document.getElementById('assine-vlr').style.display = 'block';
			set_principal_height(get_principal_height() + 150);
			exp_vlr = true;
		}
	}
	function esconde(bloco) {
		if ((bloco == 'dom') && (exp_dom)) {
			document.getElementById('assine-configuracao').style.display = 'none';
			set_principal_height(get_principal_height() - 300);
			exp_dom = false;
		}
		if ((bloco == 'vlr') && (exp_vlr)) {
			document.getElementById('assine-vlr').style.display = 'none';
			set_principal_height(get_principal_height() - 150);
			exp_vlr = false;
		}
	}
	function ver_pagamento(radio) {
		expande('dom');
		if (get('plano_pagamento_id_cupom').value) {
			ds_periodicidade = get('periodicidade_plano_pagamento_id_cupom').value;
			vlr_hospedagem = get('vlr_plano_pagamento_id_cupom').value;
		} else {
			for (i = 0; i < qt_linhas; i++) {
				if ((linhas[i * 6] == get('plano').value) && (linhas[(i * 6) + 1]) == radio.value) {
					ds_periodicidade = linhas[(i * 6) + 2];
					vlr_hospedagem = linhas[(i * 6) + 3];
				}
			}
		}
		linhas[(i * 6) + 2];
		calcula_valor_fatura();
	}
	function ver_dominio_existente() {
		var end_existente = get('end_existente');
		var end_configurar = get('end_configurar');
		var dominio_p = get('dominio_p');
		end_configurar.value = '';
		dominio_p.checked = true;
		esconde_erro('erro-end_configurar');
		var end_existente = get('end_existente');
		if (end_existente.value == '') {
			mostra_erro('erro-end_existente', 'Favor preencher o endereço!');
			esconde('vlr');
		} else {
			if (!valida_url(end_existente.value)) {
				mostra_erro('erro-end_existente', 'Favor preencher corretamente o endereço!');
				esconde('vlr');
			} else {
				/* Se o cupom for específico para um domínio. */
				if (end_existente.value.toUpperCase().indexOf(get('url_cupom').value.toUpperCase()) == -1) {
					mostra_erro('erro-end_existente', 'O domínio digitado não pode ser utilizado para o cupom informado!');
					esconde('vlr');
				} else {
					dominio_id = get('dominio_id').value = '';
					vlr_dominio = 0;
					esconde_erro('erro-end_existente');
					expande('vlr');
					calcula_valor_fatura();
				}
			}
		}
	}
	function limpa_dominios() {
		esconde_erro('erro-end_existente');
		esconde_erro('erro-end_configurar');
		get('end_existente').value = '';
		get('end_configurar').value = '';
	}
	
	function ver_dominio_novo() {
		var end_existente = get('end_existente');
		var end_configurar = get('end_configurar');
		var dominio_w = get('dominio_w');
		end_existente.value = '';
		dominio_w.checked = true;
		
		esconde_erro('erro-end_existente');
		var end_configurar = get('end_configurar');
		if (end_configurar.value == '') {
			mostra_erro('erro-end_configurar', 'Favor preencher o endereço!');
			esconde('vlr');
		} else {
			if (!valida_url(end_configurar.value)) {
				mostra_erro('erro-end_configurar', 'Favor preencher corretamente o endereço!');
				esconde('vlr');
			} else {
				var dominio_id = get('dominio_id');
				dominio_id.value = '';
				for (var i = 0; i < dominios.length; i += 4) {
					var url = end_configurar.value;
					sufixo = dominios[i + 1];
					sufixo = sufixo.toUpperCase();
					url = url.toUpperCase();
					var ix = url.indexOf(sufixo);
					if (url.length == ix + sufixo.length) {
						dominio_id.value = dominios[i];
						vlr_dominio = dominios[i + 2];
						nac_int = dominios[i + 3];
					}
				}
				if (!dominio_id.value) {
					mostra_erro('erro-end_configurar', 'O domínio digitado é inválido ou não é registrável pela WeWeb.');
					esconde('vlr');
				} else {
					/* Se o cupom for específico para um domínio. */
					if (end_configurar.value.toUpperCase().indexOf(get('url_cupom').value.toUpperCase()) == -1) {
						mostra_erro('erro-end_configurar', 'O domínio digitado não pode ser utilizado para o cupom informado!');
						esconde('vlr');
					} else {
						esconde_erro('erro-end_configurar');
						expande('vlr');
						calcula_valor_fatura();
					}
				}
			}
		}
	}
	/* Para calcular o valor total */
	function calcula_valor_fatura() {
		
		var vlr_boleto = vlr_tarifa;
		var nac_int;
		
		var vlr_total;
		vlr_hospedagem = (vlr_hospedagem) ? vlr_hospedagem : 0;
		vlr_hospedagem = parseFloat(vlr_hospedagem);
		vlr_dominio = parseFloat(vlr_dominio);
		vlr_boleto = parseFloat(vlr_boleto);
		if (vlr_hospedagem + vlr_dominio == 0) {
			vlr_total = 0;
			vlr_boleto = 0;
		} else {
			vlr_total = vlr_hospedagem + vlr_dominio + vlr_boleto;
		}

		var linha1 = get('assine-valor-linha1');
		var linha2 = get('assine-valor-linha2');
		var linha3 = get('assine-valor-linha3');
		var total_fatura = get('total_fatura');
		if (nac_int) {
			nac_int = ' ' + nac_int;
		} else {
			nac_int = '';
		}
		if (!ds_periodicidade) {
			ds_periodicidade = 'Indefinido';
		}
		linha1.innerHTML = 'Plano de Hospedagem ' + ds_plano + ' - Pagamento ' + ds_periodicidade + ': <span class="texto_rosa f11 negrito">R$ ' + nbf(vlr_hospedagem) + '</span>';
		linha2.innerHTML = 'Configuração do Domínio' + nac_int + ' - Pagamento Anual: <span class="texto_rosa f11 negrito">R$ ' + nbf(vlr_dominio) + '</span>';
		linha3.innerHTML = 'Taxa Bancária do Boleto: <span class="texto_rosa f11 negrito">R$ ' + nbf(vlr_boleto) + '</span>';
		
		total_fatura.innerHTML = 'R$ ' + nbf(vlr_total);
	
	}
	
	function mostra_erro(id, msg) {
		var div = get(id);
		var div_main = get(id + '-main');
		var erro_msg  = '<h2>' + textos_contato_titulo_erro + '</h2>';
		erro_msg += '<ul>';
		erro_msg += 	'<li>- ' + msg + '</li>';
		erro_msg += '</ul>';
		div.innerHTML = erro_msg;
		if (div_main.style.display == 'none') {
			set_principal_height(get_principal_height() + 106);
		}
		div_main.style.display = '';
	}
	
	function esconde_erro(id) {
		if (get(id + '-main').style.display == '') {
			set_principal_height(get_principal_height() - 106);
		}
		get(id + '-main').style.display = 'none';
	}
	
	function valida_cupom() {
		cupom = get('cupom');
		var ajax = criar_ajax();
		if (ajax != null){
			ajax.onreadystatechange = function() {
				if (ajax.readyState == 4) {
					res = ajax.responseText;
					res = res.split('|');
					if (res[0] == 'ok') {
					
						var cupom_id = res[1];
						var desconto_nr_meses = res[2];
						var periodicidade = res[3];
						var prox_fatura = res[4];
						var plano_pagamento_id = res[5];
						var vlr_total = res[6];
						get('url_cupom').value = res[7];

						seta_cupom(cupom_id, desconto_nr_meses, periodicidade, vlr_total, prox_fatura, plano_pagamento_id);
						esconde_erro('erro-cupom');
					} else {
						mostra_erro('erro-cupom', res);
					}
				}
			}
			ajax.open('GET', caminho + '/assine/cupom/' + cupom.value + '|' + get('plano').value, true);
			ajax.send(null);
		} else {
			mostra_erro('erro-cupom', 'Seu navegador não suporta Ajax!');
		}
	}
	
	function prosseguir() {
		if (get('dominio_p').checked) {
			ver_dominio_existente();
		} else {
			ver_dominio_novo();
		}
		if (get('erro-end_existente-main').style.display == 'none' && get('erro-end_configurar-main').style.display == 'none') {
			document.getElementById('form-assine').submit();
		}
	}
