﻿$(document).ready
(
    function ()
    {
       
        //ETAPAS
        $("#DivEtapa1").show();
       
       
        //ALTERA MARCA
        $("#OpcMontadora").change
        (
            function ()
            {
                if ($(this).val() != "")
                {
                    FuncListaAplicacao($(this).val());
                }
            }
        )
        
    }
)



function FuncListaAplicacao(Valor)
{
    $.ajax({
       type: "GET",
       url: "/ajax/produtos.aspx",
       data: "tipo=ListaAplicacao&marca="+ Valor,
       beforeSend: function()
       {
            $("#DivShowAplicacao").html("Carregando... aguarde");
       },
       error: function()
       {
            $("#DivShowAplicacao").html("Não foi possível listar as aplicações.");
       },
       success: function(retorno)
       {
            $("#DivShowAplicacao").html(retorno);            
       }
    });
    
}



function FuncBuscar()
{
    $.ajax({
       type: "GET",
       url: "/ajax/produtos.aspx",
       data: "tipo=ListaProdutos"+
             "&TipoCodigo="+ $("#OpcCodigo").val() +
             "&Codigo="+ tratarLINK($("#TxtCodigo").val()) +
             "&Produto="+ $("#OpcProduto").val() +
             "&marca="+ $("#OpcMontadora").val() +
             "&Aplicacao="+ $("#HdAplicacao").val(),
       beforeSend: function()
       {
            $("#DivEtapa1").hide();
            $("#DivEtapa2").show();
            $("#DivEtapa3").hide();
            $("#DivListProdutos").html("<center><br><br>Carregando... aguarde</center>");
       },
       error: function()
       {
            $("#DivListProdutos").html("<center><br><br>Não foi possível listar as aplicações.</center>");
       },
       success: function(retorno)
       {
            $("#DivListProdutos").html(retorno);            
       }
    });
    
}



function FuncMudaAplicacao(valor)
{
    $("#HdAplicacao").val(valor);
}



function ShowProduto(ID)
{

    $.ajax({
       type: "GET",
       url: "/ajax/produtos.aspx",
       data: "tipo=MostrarProduto"+
             "&ID="+ ID,
       beforeSend: function()
       {
            $("#DivEtapa1").hide();
            $("#DivEtapa2").hide();
            $("#DivEtapa3").show();
            ClearProd();
       },
       error: function()
       {
            $("#DivListProdutos").html("<center><br><br>Não foi possível listar as aplicações.</center>");
       },
       success: function(retorno)
       {
            $("#ScriptsShowProd").html(retorno);
       }
    });

}




function ClearProd()
{
    
    $("#LblValCodigoBremse").html("");
    $("#LblValCodigoConv").html("");
    $("#LblValCodigoOrig").html("");
    $("#LblValProduto").html("");
    $("#LblValMontadora").html("");
    $("#LblValAplicacao").html("");
    $("#LblValCodigoBremse2").html("");
    $("#LblValFoto").html("Produto sem imagem");
}
