﻿var orcamento = function() {
    return {
        validarCampos: function() {


            if ($("#FormNome").val() == "") { return false; }
            else if ($("#FormEmail").val() == "") { return false; }
            else if ($("#FormEmpresa").val() == "") { return false; }
            else if ($("#FormEndereco").val() == "") { return false; }
            else if ($("#FormCEP").val() == "") { return false; }
            else if ($("#FormCidade").val() == "") { return false; }
            else if ($("#FormFone").val() == "") { return false; }
            else {
//                alert("ae");
                $('#aguarde').dialog({
                    bgiframe: true,
                    height: 200,
                    width: 400,
                    modal: true,
                    resizable: false,
                    draggable: false,
                    title: "Solicitação de Orçamento",
                    zIndex: 1000,
                    beforeclose: function(event, ui) {
                        $('#aguarde').dialog('destroy');
                    }
                });

                $.post("../area/formPostOrcamento.ashx", $("#frmFormulario").serialize(),
                  function(data) {
                      if (data.sucesso) {
                          $('#aguarde').dialog('destroy');
                          $('#ok').dialog({
                              bgiframe: true,
                              height: 200,
                              width: 300,
                              modal: false,
                              resizable: false,
                              draggable: false,
                              title: "Solicitação de Orçamento",
                              zIndex: 1000,
                              buttons: {
                                  Ok: function() {
                                      $("#listProd").dialog('close');
                                      $(this).dialog('close');
                                  }
                              },
                              beforeclose: function(event, ui) {
                                  $('#ok').dialog('destroy');
                              }
                          });
                      } else {
                          $('#aguarde').dialog('destroy');
                          $('#erro').dialog({
                              bgiframe: true,
                              height: 200,
                              width: 300,
                              modal: false,
                              resizable: false,
                              draggable: false,
                              title: "Solicitação de Orçamento",
                              zIndex: 1000,
                              beforeclose: function(event, ui) {
                                  $('#erro').dialog('destroy');
                              }, buttons: {
                                  Ok: function() {
                                      $(this).dialog('close');
                                  }
                              }
                          });
                      }
                  }, "json");
                return false;
            }

        }
    };
} ();
