Subversion Repositories SmartDukaan

Rev

Rev 20110 | Blame | Compare with Previous | Last modification | View Log | RSS feed

var CRMNameSpace = CRMNameSpace || {};

$(function() {
    $("a.show-order-details").live('click', function() {
        var orderId = $(this).attr('orderId');
        loadOrderInfo("bottom-infopane", orderId);
    });

    $("a.show-user-details").live('click', function() {
        var userId = $(this).attr('userId');
        loadUserPane("infopane", userId);
    });
    
    $("a.agent-ticket-count").live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?agentIds=" + $(this).attr('agentId') +"&status=OPEN");
    });
    
    $("a.show-recharge-orders").live('click', function() {
        var userId = $(this).attr('userId');
        loadRechargeOrderPane("infopane", userId, 0);
    });
    
    $("a.show-recharge-details").live('click', function() {
        var orderId = $(this).attr('orderId');
        loadRechargeOrderInfo("bottom-infopane", orderId);
    });

    $("a.show-orders").live('click', function() {
        var userId = $(this).attr('userId');
        loadOrderPane("infopane", userId, 0);
    });
    
    $("a.show-return-tickets").live('click', function(){
        var userId = $(this).attr('userId');
        loadReturnTxnPane("infopane", userId, 0);
    });

    $("a.show-cart").live('click', function() {
        var userId = $(this).attr('userId');
        var cartId = $(this).attr('cartId');
        loadCartPane("infopane", userId, cartId);
    });

    $("a.show-line-details").live('click', function() {
        var userId = $(this).attr('userId');
        var itemId = $(this).attr('itemId');
        loadLineInfo("bottom-infopane", userId, itemId);
    });

    $("a.show-tickets").live('click', function() {
        var userId = $(this).attr('userId');
        loadTickets('infopane', "/crm/tickets!searchTickets?userId=" + userId);
    });

    $("a.show-activity").live('click', function() {
        var userId = $(this).attr('userId');
        listActivities('infopane', "userId=" + userId);
    });

    $("a.show-ticket-details").live('click', function() {
        var ticketId = $(this).attr('ticketId');

        // will be set when ticket Id link is clicked from activity page
        var activityId = $(this).attr('activityId');
        loadTicketInfo("bottom-infopane", ticketId, null, activityId);
    });
    
    $("a.show-activity-description").live('click', function() {
        loadActivityDescription("activity-description-pane", this);
    });

    $("a.show-activity-details").live('click', function() {
        var activityId = $(this).attr('activityId');
        loadActivityInfo("bottom-infopane", activityId);
    });
    
    $("a.create-ticket").live('click', function() {
        var userId = $(this).attr('userId');

        var params = null;
        if (userId != null && userId != "") {
            params = "userId=" + userId;
        }

        loadTicketCreationForm("infopane", params);
    });

    $("a.create-activity").live('click', function() {
        var userId = $(this).attr('userId');

        var params = null;
        if (userId != null && userId != "") {
            params = "userId=" + userId;
        }

        loadActivityCreationForm("infopane", params);
    });

    $('#update-ticket-form').live('submit', function() {
        var ticketId = $(this).attr('ticketId');
        updateTicket("infopane", ticketId, $(this).serialize());
        return false;
    });

    $('form#mail-form').live(
            'submit',
            function() {
                var body = $('#mail-body').val().trim();
                if (body == null || body == '') {
                        alert('Please specify body of the mail');
                }
                else {
                    var ticketId = $('#update-ticket-form').attr('ticketId');
                    updateTicket("infopane", ticketId, $(this).serialize() + '&'
                            + $('#update-ticket-form').serialize());
                    $.colorbox.close();
                }

                return false;
            });

    $('form#escalation-form').live(
            'submit',
            function() {
                var ticketId = $('#update-ticket-form').attr('ticketId');
                updateTicket("infopane", ticketId, $(this).serialize() + '&'
                        + $('#update-ticket-form').serialize());
                $.colorbox.close();
                return false;
            });
    
    $('form#cancel-form').live('submit',
                function() {
        if( $('#cancelReasonBox').attr('style') && !($('#cancelReasonBox').attr('style').indexOf('none'))) {
        var body = $('#cancel-body').val().trim();
        if (body == null || body == '') {
                alert('Please specify description');
                return false;
        }
    }
    var clicked = CRMNameSpace.CancelObj;
    var canceltype = $("div#cancel-div").attr('cancelType');
    var ticketId = $(clicked).attr('ticketId');
    var orderStatus =  $(clicked).attr('orderStatus');
    var transactionId = $(clicked).attr('transactionId');
    var orderId = $(clicked).attr('orderId');
  //  if(canceltype=='txn'){
    if(orderId==undefined||orderId==''){
        cancelTxn("bottom-infopane", ticketId, transactionId, orderStatus, $(this).serialize());
    }
    else{
        
        cancelOrder("bottom-infopane", ticketId, orderId, orderStatus, $(this).serialize());
    }
    $.colorbox.close();
    return false;
        });
    
    $('#cancel-store-order-form').live('submit',
                function() {
        if( $('#cancelReasonBox').attr('style') && !($('#cancelReasonBox').attr('style').indexOf('none'))) {
        var body = $('#cancel-body').val().trim();
        if (body == null || body == '') {
                alert('Please specify description');
                return false;
        }
    }
    var ticketId = $('.display-cancel-store-order-popup').attr('ticketId');
    var orderId = $('.display-cancel-store-order-popup').attr('orderId');
    var orderStatus = $('.display-cancel-store-order-popup').attr('orderStatus');
    cancelStoreOrder("bottom-infopane", ticketId, orderId, orderStatus, $(this).serialize());
    $.colorbox.close();
    return false;
        });

    $('form#activity-mail-form').live(
            'submit',
            function() {
                createActivity("infopane", $(this).serialize() + '&' + $("#create-activity-form").serialize());
                $.colorbox.close();
                return false;
            });

    $('#create-activity-form').live('submit', function() {
        createActivity("infopane", $(this).serialize());
        return false;
    });

    $('#create-ticket-form').live('submit', function() {
        createTicket("infopane", $(this).serialize());
        return false;
    });

    $(".home-page").click(function() {
        goToHomePage();
    });

    $(".my-open-tickets").live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?agentIds=" + $(this).attr('agentIds') +"&status=OPEN");
    });

    $(".unassigned-tickets").live('click', function() {
        loadTickets('infopane', "/crm/tickets!getUnassignedTickets");
    });

    $("#spinner-div").ajaxSend(function(evt, request, settings) {
        if (settings.url != '/crm') {
            $(this).show();
        }
    });

    $("#spinner-div").ajaxComplete(function(evt, request, settings) {
        if (settings.url != '/crm') {
            $(this).hide();
        }
    });

    $("select#activity-type").live('change', function() {
        processActivityTypeChange($(this).val());
    });
    
    /*$("select#ticketCategory").live('change', function() {
        var categoryType = $(this).val();
        if(categoryType != "DOA_RECEIVED") {
                $('input#orderQty').hide();
                $('input#orderQty').removeClass('required digits');
        }else if(categoryType != "RETURN_FORM"){
                $('input#orderQty').hide();
                $('input#orderQty').removeClass('required digits');
        }else {
                $('input#orderQty').show();
                $('input#orderQty').addClass('required digits');
        }
    });*/
    
    $("select#common-activity-desc").live('change', function() {
        changeActivityFormValidCriteria($(this).val());
    });

    $(".list-my-activity").live('click', function() {
        listActivities('infopane', "");
    });

    $(".list-customer-activity").live('click', function() {
        listActivities('infopane', "creatorId=1&notShowPmTickets=yes");
    });

    $("#mark-as-read").live('click', function() {
        var activityId = $(this).attr('activityId');
        markAsRead(activityId);
    });
    
    $("#deny-doa").live('click', function() {
        var ticketId = $(this).attr('ticketId');
        var orderId = $(this).attr('orderId');
        denyDOA(orderId, ticketId);
    });
    
    $("#authorize-doa").live('click', function() {
        var ticketId = $(this).attr('ticketId');
        var orderId = $(this).attr('orderId');
        authorizeDOA(orderId, ticketId);
    });
    
    $("#deny-return").live('click', function() {
        var ticketId = $(this).attr('ticketId');
        var orderId = $(this).attr('orderId');
        denyReturn(orderId, ticketId);
    });
    
    $("#authorize-return").live('click', function() {
        var ticketId = $(this).attr('ticketId');
        var orderId = $(this).attr('orderId');
        authorizeReturn(orderId, ticketId);
    });
    
    $("#block-payment").live('click', function() {
        var transactionId = $(this).attr('transactionId');
        var ticketId = $(this).attr('ticketId');
        var paymentId = $(this).attr('paymentId');
        blockPayment(transactionId, ticketId, paymentId);
    });
    
    $("#allow-payment").live('click', function() {
        var transactionId = $(this).attr('transactionId');
        var ticketId = $(this).attr('ticketId');
        var paymentId = $(this).attr('paymentId');
        allowPayment(transactionId, ticketId, paymentId);
    });
    
    $("form#search").live('submit', function() {
        if ($('#searchEntity').val() == 'Tickets') {
            loadTickets('infopane', "/crm/tickets!searchTickets?" + $(this).serialize());
        }
        else {
            listActivities('infopane', $(this).serialize());
        }

        $.colorbox.close();
        return false;
    });
    
    $(".advanced-search").live('click', function() {
        loadAdvancedSearchBox();
        return false;
    });

    $("select#searchEntity").live('change', function() {
        var searchEntity = $(this).val();
        processSearchEntityChange(searchEntity);
    });
    
    $('.pending-cod-verification-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=COD_VERIFICATION&status=OPEN");        
        return false;
    });
    $('.delivery-attempt-failed-count').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=DELIVERY_ATTEMPT_FAILED&status=OPEN");        
        return false;
    });

    $('.open-failed-payments-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=FAILED_PAYMENTS&status=OPEN");        
        return false;
    });
    
    $('.open-flagged-payments-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=PAYMENT_FLAGGED&status=OPEN");        
        return false;
    });
    
    $('.doa-request-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=DOA_RECEIVED&status=OPEN");        
        return false;
    });
    
    $('.return-request-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=RETURN_FORM&status=OPEN");        
        return false;
    });
    
    $('.low-inventory-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=LOW_INVENTORY_CANCELLED_ORDERS&status=OPEN");        
        return false;
    });
    
    //Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
    $('.rto-refunds-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=RTO_REFUND&status=OPEN");        
        return false;
    });
    //End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
    
    $('.bulk-order-enquiry-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=Bulk_Order_ENQUIRY&status=OPEN");        
        return false;
    });
    
    $('.profit-mandi-tickets').live('click',function(){
        loadTickets('infopane', "/crm/tickets!loadProfitMandiTickets");        
        return false;
    });
    
    $('#order-cancellation-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=ORDER_CANCELLATION&status=OPEN");        
        return false;
    });

    $('.open-delayed-delivery-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=DELAYED_DELIVERY&status=OPEN");        
        return false;
    });
    
    $('#store-pickup-tickets').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=STORE_PICKUP&status=OPEN");        
        return false;
    });

    $('.trust-level-increase').live('click', function() {
        increaseTrustLevel('infopane', $('input#trust-level-increase').attr('userId'), $('input#trust-level-increase').val());
    });
    
    $('.add-to-private-deal').live('click', function() {
        addPrivateDealUser('infopane', $('.add-to-private-deal').attr('userId'));
    });
    
    $('.change-private-deal-user-status').live('click', function() {
        if (!(confirm('Are you sure about this action?'))){
                return false;
        }
        changePrivateDealUserStatus('infopane', $('.change-private-deal-user-status').attr('userId'),$('.change-private-deal-user-status').attr('active'));
    });
    
    $('.reset-private-deal-user-password').live('click', function() {
        if (!(confirm('Are you sure want to reset password?'))){
                return false;
        }
        resetPasswordForPrivateDealUser('infopane', $('.reset-private-deal-user-password').attr('userId'));
    });
    
    $('.update-order-status').live('click', function() {
        updateOrderStatus('bottom-infopane', $(this).attr('ticketId'), $(this).attr('orderId'), $(this).attr('orderStatus'));
    });
    
    $('.update-txn-status').live('click', function() {
        updateTxnStatus('bottom-infopane', $(this).attr('ticketId'), $(this).attr('transactionId'), $(this).attr('orderStatus'));
    });
    

    $('.list-my-unread-activity').live('click', function() {
        loadUnreadActivities('infopane');
    });

    $('form.change-address').live('submit', function() {
        changeAddress($(this).serialize());
    });
    

    
    
    $('.display-cancel-order-popup').live('click', function(){
        CRMNameSpace.CancelObj= this;
        var orderId = $(this).attr('orderid');
        if(orderId==undefined){
                displayCancelOrderPopUp("txn");
        }else{
                displayCancelOrderPopUp("order");
        }
    });
    
    $('.display-cancel-store-order-popup').live('click', function(){
        displayCancelStoreOrderPopUp();
    });
    
    $('input.cancelReason').live('change', function(){
        showHidecancelReasonDiv($(this).attr('id'));
    });
    
    $('a.manage-agents').live('click', function() {
        loadAgentsInfo("infopane");
    });
    
    /*$('a.process-returns').live('click', function() {
        loadReturnTxnsInfo("infopane");
    });*/
    
    $('a.open-tickets').live('click', function() {
        loadAllOpenTickets("infopane");
    });
    
    $('a.open-ticket-count').live('click', function() {
        loadTickets('infopane', "/crm/tickets!searchTickets?category=" + $(this).attr('category') + "&status=OPEN");
    });
    
    $('a#create-agent').live('click', function() {
        loadAgentCreationForm();
    });
    
    $('a#deactivate-agent').live('click', function() {
        deactivateAgentPopup();
    });
    
    $('a#change-password').live('click', function() {
        changeAgentPasswordPopup();
    });
    
    $('a#change-role').live('click', function() {
        changeAgentRolePopup();
    });
    
    $('input#deactivate-agent').live('click', function() {
        deactivateAgent($('#deactivate-agent-email').val(),$('#deactivate-agent-email').find(':selected')[0].id);
    });
    
    $('#create-agent-form').live('submit', function() {
        if(validateAgentCreationForm()){
                var managerId = $('#manager-email-id').find(':selected')[0].id;
                createAgent($(this).serialize(), managerId);
        }
    });
    
    $('#change-agent-role-form').live('submit', function() {
        if($('#changed-role')[0].value!=""||$('#changed-role')[0].value!=undefined){
                changeAgentRole($(this).serialize());
        } else {
                alert("Please choose roles before proceeding");
        }
    });
    
    $('#change-agent-password').live('click', function() {
        updateAgentPassword();
    });
    
    $('.extend-expiry').live('click', function() {
        var pickupExtension = $('#pickupExtension').val();
        extendExpiryDate('bottom-infopane', $(this).attr('ticketId'), $(this).attr('orderId'), pickupExtension);
    });
    
    $('#refund-recharge-order').live('click', function() {
        var orderId = $(this).attr('orderId');
        refundRechargeOrder(orderId, "bottom-infopane");
    });
    
    $('#changeShippingAddress').live('click', function() {
        $('#changeShippingAddress').hide();
        $('#shippingAddressFrm').slideDown(100);
    });
    
    $('#cancelAddressChange').live('click', function() {
        $('#shippingAddressFrm').slideUp(100, function(){
                $('#changeShippingAddress').show();
        });
    });
    
    $('#submitNewAddress').live('click', function(){
        var orderId = $(this).attr('orderId');
        changeShippingAddress(orderId);
    });
    
    $('#storeToNormal').live('click', function() {
        var orderId = $('#storeToNormal').attr('order_id');
        convertStoreToNormal(orderId);
    });
    
    $('#display-store-ret-auth-options').live('click', function() {
        $.colorbox({
            inline : true,
            width : "550px",
            height : "200px",
            href : "div#store-return-auth",
            onClosed : function() {
                $('#store-return-form input[name=orderId], #store-return-form input[name=id]').remove();
                $("#store-return-auth").hide();
            }
        });
        $("#store-return-form").append("<input type='hidden' name='orderId' value=" + $(this).attr('orderId') + "></input>");
        $("#store-return-form").append("<input type='hidden' name='id' value=" + $(this).attr('ticketId') + "></input>");
        $("#store-return-auth").show();
    });

    $('#display-store-doa-auth-options').live('click', function() {
        $.colorbox({
            inline : true,
            width : "550px",
            height : "200px",
            href : "div#store-doa-auth",
            onClosed : function() {
                $('#store-doa-form input[name=orderId], #store-doa-form input[name=id]').remove();
                $("#store-doa-auth").hide();
            }
        });
        $("#store-doa-form").append("<input type='hidden' name='orderId' value=" + $(this).attr('orderId') + "></input>");
        $("#store-doa-form").append("<input type='hidden' name='id' value=" + $(this).attr('ticketId') + "></input>");
        $("#store-doa-auth").show();
    });
                
    $('#auth-return-button').live('click', function() {
        $.ajax({
            type : "POST",
            url : "/crm/tickets!authorizeReturn",
            data : $('#store-return-form').serialize(),
            success : function(response) {
                $('#bottom-infopane').html(response);
            }
        });
        $.colorbox.close();
    });
    
    $('#auth-doa-button').live('click', function() {
        $.ajax({
            type : "POST",
            url : "/crm/tickets!authorizeDOA",
            data : $('#store-doa-form').serialize(),
            success : function(response) {
                $('#bottom-infopane').html(response);
            }
        });
        $.colorbox.close();
    });
    
        
    $('#refundPayment').live('click', function() {
        $('#refundPayment').hide();
        $('#refundDetailSubmit').attr('disabled', 'true');
        $('#refundPhysicalOrderForm').slideDown(100);
    });
    
    $('#cancelRefundRequest').live('click', function() {
        $('#refundPhysicalOrderForm').slideUp(100, function(){
                $("#rfdCheque").attr("checked", false);
            $("#rfdGateway").attr("checked", false);
            $("#rfdCoupon").attr("checked", false);
            $('div#refundByCoupon').hide();
            $('div#refundByCheque').hide();
            $('div#refundByGateway').hide();
            $('#refundPayment').show();
            $('#couponDetails').val('');
            $('#refundAmountCoupon').val('');
            $('#chequeDetails').val('');
            $('#refundAmountCheque').val('');
            $('#comments').val('');
            $('#refundAmountGateway').val('');
        });
    });
    
    $('#refundPhysicalOrderForm').live('submit', function(){
        var orderAmount = $("input[name='orderAmount']").val();
        var orderAmountFloat = parseFloat(orderAmount);
        var radioBtnValue = $("input[name='rfdRadio']:checked").val();
        if(radioBtnValue == 'rfdCoupon')
                {
                        var couponDeatils = $("input[name='couponDetails']").val();
                        var refundAmountCoupon = $("input[name='refundAmountCoupon']").val();
                        var refundAmountCouponFloat = parseFloat(refundAmountCoupon);
                        if(couponDeatils==null || couponDeatils=="")
                        {
                                alert("Coupon Details are Mandatory. Please fill the Details");
                                $('input[name=couponDetails]').focus();
                                return false;
                        }
                        if(refundAmountCoupon==null || refundAmountCoupon=="")
                        {
                                alert("Refund Amount is Mandatory. Please fill the Amount");
                                $('input[name=refundAmountCoupon]').focus();
                                return false;
                        }
                        if(refundAmountCouponFloat > orderAmountFloat){
                                var didConfirm = confirm("Refund Amount is Greater Than Order Total Amount.\nAre you still want to Proceed");
                                if(didConfirm==false){
                                        return false;
                                }
                        }
                }
                if(radioBtnValue == 'rfdCheque')
                {
                        var chequeDetails = $("input[name='chequeDetails']").val();
                        var refundAmountCheque = $("input[name='refundAmountCheque']").val();
                        if(chequeDetails==null || chequeDetails=="")
                        {
                                alert("Cheque Details are Mandatory. Please fill the Details");
                                $('input[name=chequeDetails]').focus();
                                return false;
                        }
                        if(refundAmountCheque==null || refundAmountCheque=="")
                        {
                                alert("Refund Amount is Mandatory. Please fill the Amount");
                                $('input[name=refundAmountCheque]').focus();
                                return false;
                        }
                }
                if(radioBtnValue == 'rfdGateway')
                {
                        var comments = $("input[name='comments']").val();
                        var refundAmountGateway = $("input[name='refundAmountGateway']").val();
                        var refundAmountGatewayFloat = parseFloat(refundAmountGateway);
                        if(comments==null || comments=="")
                        {
                                alert("Comments Mandatory. Please fill the Details");
                                $('input[name=comments]').focus();
                                return false;
                        }
                        if(refundAmountGateway==null || refundAmountGateway=="")
                        {
                                alert("Refund Amount is Mandatory. Please fill the Amount");
                                $('input[name=refundAmountGateway]').focus();
                                return false;
                        }
                        if(refundAmountGatewayFloat > orderAmountFloat){
                                var didConfirm = confirm("Refund Amount is Greater Than Order Total Amount.\nAre you still want to Proceed");
                                if(didConfirm==false){
                                        return false;
                                }
                        }
                }
        refundOrderPayment($(this).serialize());
        return false;
    });
    
    $('#rfdCoupon').live('click', function() {
        $('div#refundByCoupon').show();
        $('div#refundByCheque').hide();
        $('div#refundByGateway').hide();
        $('#refundDetailSubmit').removeAttr('disabled');
     
    });
    $('#rfdGateway').live('click', function() {
        $('div#refundByCoupon').hide();
        $('div#refundByCheque').hide();
        $('div#refundByGateway').show();
        $('#refundDetailSubmit').removeAttr('disabled');
        
    });
    $('#rfdCheque').live('click', function() {
        $('div#refundByCoupon').hide();
        $('div#refundByCheque').show();
        $('div#refundByGateway').hide();
        $('#refundDetailSubmit').removeAttr('disabled');
       
    });
    
    /*
    $('input#returnTxnRadio').live('click', function() {
        $('div#returnPkupInput').hide();
        $('div#returnTxnInput').show();
    });
    
    $('input#returnPkupRadio').live('click', function() {
        $('div#returnPkupInput').show();
        $('div#returnTxnInput').hide();
    });*/
    $("a.return-transactions-view").live('click', function() {
        var userId = $(this).attr('userId');

        var params = null;
        if (userId != null && userId != "") {
            params = "userId=" + userId;
        }

        loadReturnTransactionsView("infopane", params);
    });
    
    $(".return-transaction-option").live('click', function() {
        var userId = $(this).attr('userId');
        var returnType = $(this).attr('returnType')
        loadReturnTransactionsPane("infopane", userId, returnType);
    });
    
    $(".return-pickup-option").live('click', function() {
        var userId = $(this).attr('userId');
        loadReturnPickUpPane("infopane", userId);
    });
    
    $(".confirm-return-transaction").live('click', function() {
        var userId = $(this).attr('userId');
        var returnType = $(this).attr('returnType');
        var tableData;
        tableData = storeTblValues()
        tableData = JSON.stringify(tableData);
        validateReturn(tableData, userId, returnType,"infopane");
    });
    
    $('.confirm-address-return-order').live('click', function() {
        if (this.checked) {
            $('#user-addresses-return-order input[type=checkbox]').not($(this)).prop('checked', false);
        }
    });
    
    $('.create-new-address-for-return-transaction').live('click', function() {
        $('#add-new-address-return-transaction').toggle();
    });
    
    $('input.submit-address-return-transaction').live('click',function() {
        var userId = $(this).attr('userId');
        var returnType = $(this).attr('returnType');
        var name =  $("input[name='name']").val();
        var line1 = $("input[name='line1']").val();
        var line2 = $("input[name='line2']").val();
        var landmark = $("input[name='landmark']").val();
        var city = $("input[name='city']").val();
        var state = $("select[name='state']").val();
        var country = $("input[name='country']").val();
        var pincode = $("input[name='pincode']").val();
        var phone = $("input[name='phone']").val();
        var addressType = $("input[name='addressType']").val();
        var tableData;
        tableData = storeTblValues2()
        tableData = JSON.stringify(tableData);
        
        var params = "name=" + name + "&line1=" + line1 + "&line2=" +line2 + "&landmark=" +landmark + "&city=" + city +"&state=" +state +"&country=" +country+
        "&pincode=" + pincode + "&phone=" + phone + "&addressType=" + addressType + "&userId=" +userId;
        submitAddressForReturnOrder(params,userId,returnType,tableData,"infopane");
    });
    
    $(".create-return-transaction").live('click', function() {
        var userId = $(this).attr('userId');
        var returnType = $(this).attr('returnType');
        var tableData;
        var addressId = "0";
        tableData = storeTblValues2()
        tableData = JSON.stringify(tableData);
        $('#user-addresses-return-order tr').each(function(row, tr){
                if($(tr).find('td:eq(6)').find('input').is(":checked")){
                        addressId = $(tr).find('td:eq(6)').find('input').val();
                }   
        }); 
        
        if(addressId==0){
                alert("Please select address for pick up");
                return;
        }
        
        createReturnTransaction(tableData, userId, returnType, addressId, "infopane");
    });
    
    $(".change-return-transaction-status").live('click', function() {
        var returnTransactionId = $(this).attr('returnTransactionId');
        var newReturnTransactionStatus = $(this).attr('value');
        changeStatusForReturnTransaction(returnTransactionId, newReturnTransactionStatus, "infopane");
    });
    
    $(".show-return-order-details").live('click', function() {
        var returnOrderId = $(this).attr('returnOrderId');
        viewReturnOrderInfo(returnOrderId, "sub-bottom-infopane");
    });
    
    $(".show-return-transaction-details").live('click', function() {
        var returnTransactionId = $(this).attr('returnTransactionId');
        viewReturnTransaction(returnTransactionId, "bottom-infopane");
    });
    
    $(".confirm-return-pickup").live('click', function() {
        var userId = $(this).attr('userId');
        confirmPickup(userId, "infopane");
    });
    
    $(".update-return-pickup").live('click', function() {
        var pickupRequestNo =  $("input[name='pickupRequestNo']").val();
        var logisticProviderId = $("select[name='logisticProviderId']").val();
        var pickupStatus = $("select[name='pickupStatus']").val();
        var pickupRequestId = $(this).attr('value');
        var promised_pickup_timestamp = new Date($("input[name='promised_pickup_timestamp']").val()).valueOf();
        var pickedUpAt = new Date($("input[name='pickedUpAt']").val()).valueOf();
        changeRequestPickupStatus(pickupRequestId, pickupRequestNo, logisticProviderId, pickupStatus, promised_pickup_timestamp, pickedUpAt, "infopane");
    });
    
    $(".view-all-return-transactions").live('click', function() {
        var userId = $(this).attr('userId');
        showAllReturnTransactions(userId,"infopane")
    });
    
    $("#add-serial-number").live('click', function() {
        $('<br/><br/><label><span>Serial Numbers :</span></label><input type="text" value="" name="serialNumbers" id="serialNumbers"/>').appendTo('#serial-number-container');
    });
    
    $("#receiveItem").live('submit', function(){
        var formData = new FormData($(this)[0]);

        $.ajax({
            url: "/crm/return-transactions!receiveItem",
            type: 'POST',
            data: formData,
            async: false,
            success: function (data) {
                        alert(data);
                        $('#receiveItem')[0].reset();
                        location.reload();
            },
                 error : function() {
                        alert("OOPS!!!Failed to do changes.Try Again.");
                 },
            cache: false,
            contentType: false,
            processData: false
        });
        $("#spinner-div").hide();
        return false;
    });
    
    $('.split-return-order').live('click', function(){
        $('.split-return-order-div').toggle();
    });
    
    $('#submitSplitReturnOrder').live('click',function(){
        $("input[name='splitOrderQuantity']").attr('disabled','disabled');
        var returnOrderId = $(this).attr('returnOrderId');
        var splitOrderQuantity = $("input[name='splitOrderQuantity']").val();
        alert(returnOrderId + " " + splitOrderQuantity);
        var params = "returnOrderId=" +returnOrderId + "&splitOrderQuantity=" + splitOrderQuantity;
        splitReturnOrder(params);
        $("input[name='splitOrderQuantity']").removeAttr('disabled');
    });
    
    $("#refundNotPickedUpOrder").live('submit', function(){
        var formData = new FormData($(this)[0]);

        $.ajax({
            url: "/crm/return-transactions!markReturnNotPickedUp",
            type: 'POST',
            data: formData,
            async: false,
            success: function (data) {
                        alert(data);
                        $('#refundNotPickedUpOrder')[0].reset();
                        location.reload();
            },
                 error : function() {
                        alert("OOPS!!!Failed to do changes.Try Again.");
                 },
            cache: false,
            contentType: false,
            processData: false
        });
        $("#spinner-div").hide();
        return false;
    });
    
    $("select#refundType").live('change', function() {
        showHideRefundDiv($(this).val());
    });
    
    $("#refundRecievedOrder").live('submit', function(){
        var formData = new FormData($(this)[0]);

        $.ajax({
            url: "/crm/return-transactions!refundReceivedOrder",
            type: 'POST',
            data: formData,
            async: false,
            success: function (data) {
                        alert(data);
                        $('#refundRecievedOrder')[0].reset();
                        location.reload();
            },
                 error : function() {
                        alert("OOPS!!!Failed to do changes.Try Again.");
                 },
            cache: false,
            contentType: false,
            processData: false
        });
        $("#spinner-div").hide();
        return false;
    });
    
    //refundRecievedOrder
    
    
});