/**
 * @author Julius
 */
	function abrePainelDedicado(parametro) {
		if (parametro == 0 || parametro == 1) {
			cTexto = "<input type='hidden' name='memoria' id='memoria' value='0' />";
		} else {
			cTexto = '<td colspan="4" align="center"><br />' +
					 '<b>Escolha a quantidade de memória:</b><br />' + 
					 '<select name="memoria" id="memoria" onchange="javascript:CalculaTotal()">' + 
						 '<option value="64" >Servidor dedicado com 64MB</option>' + 
						 '<option value="128">Servidor dedicado com 128MB</option>' +
						 '<option value="256">Servidor dedicado com 256MB</option>' + 
					 '</select>' +
					 '<br /><br /></td>';
		}
		document.getElementById("linhaDedicado").innerHTML = cTexto;
		CalculaTotal();
	}

	function CalculaTotal() {
		
		ind = document.getElementById("plano").value;
		cValor = 0;
		
		if (ind == 1) {
			cValor = 10;
		} else if (ind == 2) {
			cValor = 40;
		} else if (ind == 3) {
			cValor = 70;
		} else if (ind == 4) {
			cValor = 100;
		}
		if (document.getElementById("memoria").value != 0) {
			ind = document.getElementById("memoria").value;
			
			if (ind == 64) {
				cValor += 20;
			} else if (ind == 128) {
				cValor += 35;
			} else if (ind == 256) {
				cValor += 60;
			}
		}

		document.getElementById("valormensal").value = "R$ " + cValor + ",00";
	}
	
	function ValidaCPF() {
		retorno = true;
		texto = "<b>Erros encontrados:</b><br /><ul>";

		// Validando o cnpj/cpf -- Chamar função externa para isso
		if (!isCpfCnpj(document.getElementById("cpf").value)) {
			texto += "<li>Número de CPF/CNPJ inválido. Digite-o sem pontos ou espaços</li>";
			retorno = false;
		}

		texto += "</ul>";

		// Processa o retorno
		if (retorno) {
			document.getElementById("resultadoValidacao").innerHTML = "";
			document.getElementById("resultadoValidacao").style.display = "none";
		} else {
			document.getElementById("resultadoValidacao").innerHTML = texto;
			document.getElementById("resultadoValidacao").style.display = "block";
		}
	}
	
	function ValidaFormulario() {
		retorno = true;
		texto = "<b>Erros encontrados:</b><br /><ul>";
		
		// Validando o nome
		if (document.getElementById("NomeCompleto").value.length < 10) {
			texto += "<li>O nome está muito curto</li>";
			retorno = false;
		}
		
		// Validando o endereço
		if (document.getElementById("Endereco").value.length < 10) {
			texto += "<li>O endereço está muito curto</li>";
			retorno = false;
		}
		
		// Validando a cidade
		if (document.getElementById("cidade").value.length < 3) {
			texto += "<li>O nome da cidade está muito curto</li>";
			retorno = false;
		}
		
		// Validando o e-mail
		if (document.getElementById("email").value.length < 10) {
			texto += "<li>O e-mail está muito curto</li>";
			retorno = false;
		}
		if (document.getElementById("email").value.indexOf("@") == -1 || document.getElementById("email").value.indexOf(".") == -1) {
			texto += "<li>Endereço de e-mail inválido</li>";
			retorno = false;
		}
		
		// Validando o cnpj/cpf -- Chamar função externa para isso
		if (document.getElementById("cpf").value.length < 11) {
			texto += "<li>Número de CPF/CNPJ inválido. Digite-o sem pontos ou espaços</li>";
			retorno = false;
		}

		// Validando o plano
		if (document.getElementById("plano").value <= 0) {
			texto += "<li>Selecione um plano, mesmo que deseje customizá-lo.</li>";
			retorno = false;
		}

		// Validando o login
		if (document.getElementById("nomeusuario").value.length > 8 || document.getElementById("nomeusuario").value.length < 4) {
			texto += "<li>O nome do usuário deve ter entre 4 e 8 caracteres</li>";
			retorno = false;
		}

		// Validando a senha 
		//if (document.getElementById("senhausuario").value.length < 6 || document.getElementById("senhausuario").value.length > 32) {
		//	texto += "<li>A senha do usuário deve ter entre 6 e 32 caracteres</li>";
		//	retorno = false;
		//}
		//if (document.getElementById("re_senha").value.length < 6) {
		//	texto += "<li>As senhas não conferem, digite-as novamente</li>";
		//	retorno = false;
		//}
		//if (document.getElementById("re_senha").value != document.getElementById("senhausuario").value) {
		//	texto += "<li>As senhas não conferem, digite-as novamente</li>";
		//	retorno = false;
		//}

		texto += "</ul><br /><img src='images/cancel.png' alt='fechar erros' onclick='OcultaPainelErro()'>";

		// Processa o retorno
		if (retorno) {
			document.getElementById("resultadoValidacao").innerHTML = "";
			document.getElementById("resultadoValidacao").style.display = "none";
			document.forms[0].submit();
		} else {
			document.getElementById("resultadoValidacao").innerHTML = texto;
			document.getElementById("resultadoValidacao").style.display = "block";
		}
	}

	function OcultaPainelErro() {
		document.getElementById("resultadoValidacao").style.display = "none";
	}
