function validarContato() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("nome").value == "") {
	 passou = false; alerta += "- Nome preenchido incorretamente.\n";
  }
  if (document.form1.email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.form1.email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("empresa").value == "") {
	 passou = false; alerta += "- Empresa preenchido incorretamente.\n";
  }
  if (document.getElementById("telefone").value == "") {
	 passou = false; alerta += "- Telefone preenchido incorretamente. Utilize a forma: 00 0000.0000\n";
  }
  if (document.getElementById("mensagem").value == "") {
	 passou = false; alerta += "- Mensagem preenchido incorretamente.\n";
  }

  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}

function validarEmail(email)
{
	var s = email;
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
	return true;
	else
	return false;
}

function aparecerElemento(acao, id) {
		if (acao == "aparecer") {
			document.getElementById(id).className = "aparecer";
		}
		if (acao == "sumir") {
			document.getElementById(id).className = "sumir";
		}
}

function onOff(quem, tipo) {
	if (quem == "certificacao_tipo" && tipo == "habilitar") {
			document.getElementById("iso_9001_2008").disabled = false;
			document.getElementById("iso_ts_16949").disabled = false;
			document.getElementById("iso_14001").disabled = false;
			document.getElementById("ohsas").disabled = false;
			document.getElementById("outros").disabled = false;
			document.getElementById("outros_text").disabled = false;
	}
	if (quem == "certificacao_tipo" && tipo == "desabilitar") {
			document.getElementById("iso_9001_2008").disabled = true;
			document.getElementById("iso_ts_16949").disabled = true;
			document.getElementById("iso_14001").disabled = true;
			document.getElementById("ohsas").disabled = true;
			document.getElementById("outros").disabled = true;
			document.getElementById("outros_text").disabled = true;
	}
}

function testar(quem) {
	if(document.getElementById("outros").checked == true && quem == "checkbox") {
		document.getElementById("outros_text").focus();
	}
	else if(document.getElementById("outros").checked == false && quem == "text") {
		document.getElementById("outros").checked = true;	
	}
}

function validarSolicitacao() {
  var passou = true;
  var alerta = "O sistema encontrou os seguintes erros no preenchimento do formulário:\n\n";

  // validações dos campos gerais
  if (document.getElementById("empresa").value == "") {
	 passou = false; alerta += "- Empresa preenchido incorretamente.\n";
  }
  if (document.getElementById("cnpj").value == "") {
	 passou = false; alerta += "- CNPJ preenchido incorretamente.\n";
  }
  if (document.getElementById("ie").value == "") {
	 passou = false; alerta += "- I.E. preenchido incorretamente.\n";
  }
  if (document.getElementById("endereco").value == "") {
	 passou = false; alerta += "- Endereço preenchido incorretamente.\n";
  }
  if (document.getElementById("numero").value == "") {
	 passou = false; alerta += "- Número preenchido incorretamente.\n";
  }
  if (document.getElementById("bairro").value == "") {
	 passou = false; alerta += "- Bairro preenchido incorretamente.\n";
  }
  if (document.getElementById("cep").value == "") {
	 passou = false; alerta += "- CEP preenchido incorretamente.\n";
  }
  if (document.getElementById("estado").value == "") {
	 passou = false; alerta += "- Estado preenchido incorretamente.\n";
  }
  if (document.getElementById("cidade").value == "") {
	 passou = false; alerta += "- Cidade preenchido incorretamente.\n";
  }
  if (document.getElementById("pessoa").value == "") {
	 passou = false; alerta += "- Pessoa preenchido incorretamente.\n";
  }
  if (document.getElementById("cargo").value == "") {
	 passou = false; alerta += "- Cargo preenchido incorretamente.\n";
  }
  if (document.form2.email.value == "") {
     passou = false; alerta += "- E-mail preenchido incorretamente.\n";
  }else{
      if (!validarEmail(document.form2.email.value)) {
           passou = false; alerta += "- E-mail preenchido incorretamente.\n";
      }
  }
  if (document.getElementById("telefone").value == "") {
	 passou = false; alerta += "- Telefone preenchido incorretamente.\n";
  }
  if (document.getElementById("seu_software").value == "") {
	 passou = false; alerta += "- Descreva um resumo das características de seu software.\n";
  }

  if (passou == true) { return true; }
  else { alert(alerta); return false; }
}
