// JavaScript Document

function mostraId(id)
{
	$("#"+id).show("fast");
}

function escondeId(id)
{
	$("#"+id).hide("fast");
}

function getId(s) {
  return document.getElementById(s);
}


function salvaOrcamento()
{
	var tipoF = getId('tipoF');
	var tipoJ = getId('tipoJ');
	
	var nome = getId('nome');
	var email = getId('email');
	var empresa = getId('empresa');
	var cidade = getId('cidade');
	var estado = getId('estado');
	var mensagem = getId('mensagem');
	var produto = getId('produto');
	var tipo = '';
	
	if( (tipoF.checked==false) && (tipoJ.checked==false) )
	{
		alert("Marque 'Pessoa Fisica' ou 'Pessoa Juridica'");
		return false;
	}
	
	if(tipoF.checked)
	{
		tipo = 'F';
	}
	else
	{
		if(tipoJ.checked)
			tipo = 'J';
	}
	
	if(tipo=='J')
	{
		cnpj = getId('cnpj');
		if(cnpj.value.length < 14)
		{
			alert("Preencha o campo 'CNPJ' corretamente");
			cnpj.focus();
			return false;
		}
	}
	
	/*
	var produtos = document.getElementsByName('produto');
  var arrProdutos = new Array() 
  var i = 0;
  var j = 0;
  while(i < produtos.length)
  {
    if(produtos[i].checked)
    {
      arrProdutos[j] = produtos[i].value;
      j++;
    }
    i++;
  }
	if(j==0)
	{
		alert('Selecione pelo menos 1 produto!');
		return false;
	}
	*/
	
	if ( nome.value == "" ) {
    alert("Favor, informe seu nome!");
    nome.focus();
    return false;
  }
	
	if ( email.value == "" ) {
    alert("Favor, informe seu email!");
    email.focus();
    return false;
  }
	
	if ( cidade.value == "" ) {
    alert("Favor, informe sua cidade!");
    cidade.focus();
    return false;
  }
	
	xajax_salvaOrcamento(nome.value, email.value, empresa.value, cidade.value, estado.value, mensagem.value, produto.value, tipo, cnpj.value);
	
}

function enviaContato()
{
	var nome = getId('nome');
	var email = getId('email');
	var empresa = getId('empresa');
	var cidade = getId('cidade');
	var estado = getId('estado');
	var assunto = getId('assunto');
	var texto = getId('texto');
	
	if(nome.value=='')
	{
		alert("Favor, informe seu nome");
		nome.focus();
		return false;
	}
	if(email.value=='')
	{
		alert("Favor, informe seu email");
		email.focus();
		return false;
	}
	if(cidade.value=='')
	{
		alert("Favor, informe sua cidade");
		cidade.focus();
		return false;
	}
	if(texto.value=='')
	{
		alert("Favor, preencha o campo 'Mensagem'");
		texto.focus();
		return false;
	}
	
	var corEnviando = '#EEEEEE';
	
	nome.style.background = corEnviando;
	email.style.background = corEnviando;
	empresa.style.background = corEnviando;
	cidade.style.background = corEnviando;
	estado.style.background = corEnviando;
	assunto.style.background = corEnviando;
	texto.style.background = corEnviando;
	
	xajax_enviaContato(nome.value, email.value, empresa.value, cidade.value, estado.value, assunto.value, texto.value);
}