// JavaScript Document
function openGeneric(path, w, h) {
  window.open(path, '_blank', 'top=100,left=100,location=0,menubar=0,resizable=0,toolbar=0,personalbar=0,status=0,scrollbars=1,width=' + w + ',height= ' + h + '');
}

function aprovaCategoria() {
  if (document.form.nomeCategoria.value == '')  {
    alert("Erro: Preencha corretamente o campo 'Nome da Categoria'."); 
	return false;
  }
}

function menuDinamico(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
	var i, j;
	var prompt;
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
	prompt = (itemArray != null) ? goodPrompt : badPrompt;
	if (prompt == null) {
		j = 0;
	}
	else {
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}
	if (itemArray != null) {
		// add new items
		for (i = 0; i < itemArray.length; i++) {
			selectCtrl.options[j] = new Option(itemArray[i][0]);
			if (itemArray[i][1] != null) {
				selectCtrl.options[j].value = itemArray[i][1]; 
			}
			j++;
		}
		// select first item (prompt) for sub list
		selectCtrl.options[0].selected = true;
   }
}

function abilitarPessoaCadastroAnuncio (abilitar, desabilitar) {
  abilitar.name = "codPessoa";
  abilitar.disabled = false;
  desabilitar.name = "xxx";
  desabilitar.disabled = true;
}

function aprovaAnuncio (PJ, PF) {
  if ((document.form.oportunidade.value == "") || (document.form.contato.value == "") || 
	 (document.form.telefone.value == "") ||
	 ((PJ.disabled == true) && (PF.disabled == true)) || //garante que uma pessoa deve estar selecionada
	 ((PJ.options[PJ.selectedIndex].value == 0) && (PJ.disabled == false)) || //somente o abilitado deve ter o value diferente de 0 (zero)
	 ((PF.options[PF.selectedIndex].value == 0) && (PF.disabled == false)) || //somente o abilitado deve ter o value diferente de 0 (zero) 
     (document.form.codCategoria.options[document.form.codCategoria.selectedIndex].value == 0)) {    
	alert("Erro: Preencha corretamente os campos,\nselecione uma PJ/PF e uma categoria."); 
	return false;
  }
}

function aprovaAlteracaoAnuncio () {
  if ((document.form.oportunidade.value == "") || (document.form.contato.value == "") || 
	 (document.form.telefone.value == "") ||
     (document.form.codCategoria.options[document.form.codCategoria.selectedIndex].value == 0)) {    
	alert("Erro: Preencha corretamente os campos e\nselecione uma categoria."); 
	return false;
  }
}

function aprovaEmpresa () {
  //(document.form.cnpj.value == "") || 
  //(document.form.produtos.value == "") ||
  if ((document.form.razaoSocial.value == "") || (document.form.fantasia.value == "") ||
  	  (document.form.codCidade.options[document.form.codCidade.selectedIndex].value == 0) ||
	  //(document.form.regiaoAtuacao.value == "") || 
	  (document.form.endereco.value == "") || (document.form.bairro.value == "") ||
	  (document.form.cep.value == "") || (document.form.telefone.value == "") ||
	  (document.form.codCategoria.options[document.form.codCategoria.selectedIndex].value == 0)) {
	alert("Erro: Preencha corretamente os campos e\nselecione uma categoria da empresa."); 
	return false;	  
  }
}

function confirmaExclusao (nomeItem) {
  if (confirm("Deseja realmente excluir este(a) " + nomeItem)) {
    return true;
  }
  else {
    return false;
  }
}

function aprovaCidade () {
    if (document.form.nome.value == "") {
	  alert("Erro: Preencha corretamente o campo 'Nome da Cidade'.");
	  return false;
	}
	else {
	  return true;
	}
}

function carregarCidade (idUf, cidade, componente) {
  naoAchou = true;
  n = 0;
  while (naoAchou) {
    if (subcateg[idUf][n][0] == cidade) {
	  componente.options[n].selected = true;
	  naoAchou = false;
	}
	else {
	  n++;
	}
  }
}

function aprovaChar() { //nao permite colocar aspas duplas
  if (event.keyCode == 34) {
    alert("Erro: Não digite " + "\"" + " (aspas duplas).\nSubstitua por outro caracter.");
    event.returnValue = false;
  }
  else {
    event.returnValue = true;
  }
}

function aprovaPFisica () {
  //(document.form.rg.value == "") ||
  //(document.form.cpf.value == "") || 
  //(document.form.produtos.value == "") ||
  if ((document.form.nome.value == "") || 
  	  (document.form.codCidade.options[document.form.codCidade.selectedIndex].value == 0) ||
	  (document.form.regiaoAtuacao.value == "") || 
	  (document.form.endereco.value == "") || (document.form.bairro.value == "") ||
	  (document.form.cep.value == "") || (document.form.telefone.value == "") ||
	  (document.form.codCategoria.options[document.form.codCategoria.selectedIndex].value == 0)) {
	alert("Erro: Preencha corretamente os campos e\nselecione uma categoria da Pessoa Física."); 
	return false;	  
  }
}

/*
function carregaCategoriaDinamica (codCategoria, balcao, class) {
  if (balcao.checked) {
    menuDinamico(codCategoria, subcateg[1]);
  }
  else {
	menuDinamico(codCategoria, subcateg[0])  
  }
}
*/