﻿var lamina = function() {
    return {
        Abre: function(elem, title, url, lamCod, prodCod) {

            $(elem).dialog({
                bgiframe: true,
                height: 480,
                width: 700,
                modal: true,
                resizable: false,
                draggable: false,
                title: title,
                zIndex: 500,
                open: function(event, ui) {
                    $.ajax({
                        url: url,
                        data: { "lamCod": lamCod, "prodCod": prodCod },
                        cache: false,
                        success: function(html) {
                            $("#viewProd").html(html);
                            $("#aguarde").hide();
                            $("#ok").hide();
                            $("#erro").hide();
                        }
                    });
                },
                beforeclose: function(event, ui) {
                    $(elem).dialog('destroy');
                }
            });
        },
        Ver: function(url, lamCod, liCodSelected) {
            $.ajax({
                url: url,
                data: { "lamCod": lamCod, "liCodSelected": liCodSelected },
                cache: false,
                success: function(html) {
                    $("#viewProd").html("");
                    $("#viewProd").html(html);
                }
            });
        },
        validarCampos: function() {


            if ($("#FormNome").val() == "") { return false; }
            else if ($("#FormEmail").val() == "") { return false; }
            else if ($("#FormFone").val() == "") { return false; }
            else {
                $('#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("../lamina/formPost.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;
            }


            //            if ($("#FormNome").val() != "" || $("#FormEmail").val() != "" || ($("#FormDDD").val() != "" && $("#FormFone").val() != "")) {
            //                $.post("../lamina/formPost.ashx", $("#frmFormulario").serialize(),
            //                  function(data) {

            //                  }, "json");
            //            } else {
            //                return false;
            //            }


        }
    };
} ();