var registroPostVenta = (function($) {

    var init = function() {
       	var urlLogin = loginPostVentaViewUrl;
       	if(loginPagoRecarga){
           urlLogin = loginRecargaPagoViewUrl;       		
       	}
        loginPostVentaView(urlLogin);
    };

    
    var loginPostVentaView = function(urlLogin) {    	
    	$('#loadingModal').modal('show');
        $.ajax({
            url: urlLogin,
            type: "POST",
            dataType: "html"
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorLoginView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    var seleccionRegistroView = function() {
        $('#loadingModal').modal('show');
        $.ajax({
            url: seleccionRegistroViewUrl,
            type: "POST",
            dataType: "html"
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
            $('.box').matchHeight();
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorSeleccionRegistroView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    var registroSMSView = function() {
        $('#loadingModal').modal('show');
        $.ajax({
            url: registroSMSViewUrl,
            type: "POST",
            dataType: "html"
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
            $('.box').matchHeight();
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorRegistroSMSView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    var registroICEClaveView = function() {
        $('#loadingModal').modal('show');
        $.ajax({
            url: registroICEClaveViewUrl,
            type: "POST",
            dataType: "html"
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorRegistroICEClaveView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    var solicitarICEClaveView = function() {
        $('#loadingModal').modal('show');

        $.ajax({
            url: solicitarICEClaveViewUrl,
            type: "POST",
            dataType: "html",
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorSolicitarICEClaveView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    var recordarICEClaveView = function() {
        $('#loadingModal').modal('show');

        $.ajax({
            url: recordarICEClaveViewUrl,
            type: "POST",
            dataType: "html",
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorRecordarICEClaveView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    var verificarSMSView = function(autoCodigo, nombre, primerApellido, segundoApellido, tipoCedula, cedula, telefono) {
        $('#loadingModal').modal('show');
        $.ajax({
            url: verificarSMSViewUrl,
            type: "POST",
            dataType: "html",
            data: {
                autoCodigo: autoCodigo,
                nombre: nombre,
                primerApellido: primerApellido,
                segundoApellido: segundoApellido,
                tipoCedula: tipoCedula,
                cedula: cedula,
                telefono: telefono
            }
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorVerificarSMSView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    var registroMiKolbiView = function(autoCodigo, nombre, primerApellido, segundoApellido, tipoCedula, cedula, telefono, tipoRegistro) {
        $('#loadingModal').modal('show');
        $.ajax({
            url: registroMiKolbiViewUrl,
            type: "POST",
            dataType: "html",
            data: {
                autoCodigo: autoCodigo,
                nombre: nombre,
                primerApellido: primerApellido,
                segundoApellido: segundoApellido,
                tipoCedula: tipoCedula,
                cedula: cedula,
                telefono: telefono,
                tipoRegistro: tipoRegistro
            }
        }).done(function(data) {
            $("#divRegistroPostVenta").html(data);
        }).fail(function() {
            $("#modalErrorView").modal("show");
            $("#modalErrorView #mensajeModalError").text(errorRegistroMiKolbiView);
        }).always(function() {
            $('#loadingModal').modal('hide');
        });
    };

    return {
        init: init,
        loginPostVentaView: loginPostVentaView,
        seleccionRegistroView: seleccionRegistroView,
        registroSMSView: registroSMSView,
        registroICEClaveView: registroICEClaveView,
        solicitarICEClaveView: solicitarICEClaveView,
        recordarICEClaveView: recordarICEClaveView,
        verificarSMSView: verificarSMSView,
        registroMiKolbiView: registroMiKolbiView
    };
    
})(jQuery);
$(document).ready(function() {
    registroPostVenta.init();
});