
// Added By Neeral For AutoScroll Functionality
function AutoScroll(e) {
    x = e.clientX;
    y = e.clientY;

    // Desired offset, in pixels
    var offset = 2000;
    // Desired time to scroll, in milliseconds
    var scrollTime = 30;

    var iTopScroll = 100;
    var iBottomMarginArea = 100;
    var iTopMarginArea = 100;


    var iLeftScroll = 200;
    var eVerticalElement = document.getElementsByTagName("body");
    var eHorizontalElement = $("#divGridLayout");

    //


    if (x > 1325) {
        var iScroll = ($(eHorizontalElement).scrollLeft() + iLeftScroll)
        eHorizontalElement.animate({
            scrollLeft: iScroll
        }, scrollTime);

    }

    if (x < 330) {
        var iScroll = ($(eHorizontalElement).scrollLeft() - iLeftScroll)
        eHorizontalElement.animate({
            scrollLeft: iScroll
        }, scrollTime);

    }

    if ($(eVerticalElement).isOverflowHeight()) {
        if ((window.innerHeight - (e.pageY - ($(eVerticalElement).scrollTop()))) < iBottomMarginArea) {
            var iScroll = (($(eVerticalElement).scrollTop() + iTopScroll));
            ($(eVerticalElement)).animate({
                scrollTop: iScroll
            }, scrollTime);

        }

        if ((window.innerHeight - (e.pageY - ($(eVerticalElement).scrollTop()))) > (window.innerHeight - iTopMarginArea)) {
            var iScroll = (($(eVerticalElement).scrollTop() - iTopScroll));
            ($(eVerticalElement)).animate({
                scrollTop: iScroll
            }, scrollTime);

        }
    }

}


(function ($) {
    $.fn.isOverflowHeight = function () {
        return this.each(function () {
            var el = $(this);
            if (el.css("overflow") == "hidden") {
                var text = el.html();
                var t = $(this.cloneNode(true)).hide().css('position', 'absolute').css('overflow', 'visible').height('auto').width(el.width());
                el.after(t);

                function height() {
                    return t.height() > el.height();
                };

            }
        });
    };
})(jQuery);

//END  Added By Neeral For AutoScroll Functionality



function dragdropFunction() {


    var minX = 0; // farthest to left it can go
    var maxX = 1300; // farthest to right it can go
    var yPosition = 0; // set to your y position
    var yMax = 5000; //Updated by SwatiP on 21-4-2022 <BBVAORINT-202>
    //ctl00_MainContent_oUCPLayout_GridFindUDFColumn
    //"#ctl00_MainContent_Tabs_TabLayoutDesign_


    $(document).ready(function () {

        $(".GridLayout, .Grid").find(".GridItem").find("td").sortable({
            revert: true
        });

        $(".GridLayout, .Grid").find(".GridItem").find("td").draggable(
       {
           cursor: "move", helper: ZoomDrag, containment: [minX, yPosition, maxX, yMax]

       })

        $("#ctl00_MainContent_oUCPLayout_GridFindUDFColumn").find("td:first-child").draggable(
            {
                cursor: "move", helper: ZoomDrag, containment: [minX, yPosition, maxX, yMax]


            });


    });

    function ZoomDrag() {

        var helper = $(this).clone();
        helper.addClass("ui-draggable-helper Zoom");
        return helper;
    }
    var parameter = Sys.WebForms.PageRequestManager.getInstance();

    parameter.add_endRequest(function () {

        $(".GridLayout, .Grid").find(".GridItem").find("td").sortable({
            revert: true
        });

        $(".GridLayout, .Grid").find(".GridItem").find("td").draggable(
       {
           cursor: "move", helper: ZoomDrag, containment: [minX, yPosition, maxX, yMax]

       });

        $("#ctl00_MainContent_oUCPLayout_GridFindUDFColumn").find("td:first-child").draggable(
            {
                cursor: "move", helper: ZoomDrag, containment: [minX, yPosition, maxX, yMax]

            });


    });



    $("td").disableSelection();

    $(".GridLayout, .UCP_GridLayoutGrid").find(".GridItem").find("td").droppable({
        drop: function (event, ui) {
            txtdraggable = $(ui.draggable).html();
            clearDuplicate($(ui.draggable).html())
            $(this).html(txtdraggable);
            // ui.droppable.droppable('disable');
            reorder();
        }
    });

    function clearDuplicate(txt) {
        // alert(txt);
        $(".GridLayout").find(".GridItem").find("td").each(function () {
            if ($(this).html() == txt) {
                //  alert(txt + " is duplicate field.");
                $(this).html('');
            }
        });
    }
}

function reorder() {

    // var Grid_Table = document.getElementById('<%= GridLayout.ClientID %>');

    /* for (var row = 0; row < Grid_Table.rows.length; row++) {
         for (var col = 0; col < Grid_Table.rows[row].cells.length; col++) {
 
             if (col == 0)
                 if (document.all)
                     DraggedString = DraggedString + Grid_Table.rows[row].cells[col].innerText;
                 else
                     DraggedString = DraggedString + Grid_Table.rows[row].cells[col].textContent;
             else
                 if (document.all)
                     DraggedString = DraggedString + '|' + Grid_Table.rows[row].cells[col].innerText;
                 else
                     DraggedString = DraggedString + '|' + Grid_Table.rows[row].cells[col].textContent;
         }        
         DraggedString = DraggedString + '~#';
     }*/
    DraggedString = '';
    var Grid_Table = document.getElementById("ctl00_MainContent_oUCPLayout_GridLayout");
    var colcount = document.getElementById("ctl00_MainContent_oUCPLayout_ddlUCPColumns");
    var application = document.getElementById("ctl00_MainContent_oUCPLayout_ddlApplication");
    var rowcount = document.getElementById("ctl00_MainContent_oUCPLayout_ddlUCPRows");
    var i = 0

    if (application.value == 'MULFIX') {
        for (var col = 0; col < colcount.value; col++) {
            for (var row = 0; row < rowcount.value; row++) {

                if (DraggedString != '') {
                    DraggedString = DraggedString + "|";
                }

                if (Grid_Table.rows[row].cells[col] != null) {
                    DraggedString = DraggedString + (i + ":" + Grid_Table.rows[row].cells[col].textContent);
                }
                else
                    DraggedString = DraggedString + (i + ":" + "");

                i = i + 1;
            }
        }
    }
    else {
        for (var col = 0; col < Grid_Table.rows[0].cells.length; col++) {
            for (var row = 0; row < Grid_Table.rows.length; row++) {

                if (DraggedString != '') {
                    DraggedString = DraggedString + "|";
                }

                if (Grid_Table.rows[row].cells[col] != null) {
                    DraggedString = DraggedString + (i + ":" + Grid_Table.rows[row].cells[col].textContent);
                }
                else
                    DraggedString = DraggedString + (i + ":" + "");

                i = i + 1;
            }
        }
    }
    $("#ctl00_MainContent_oUCPLayout_hdnDraggedValue").val(DraggedString);
    // document.getElementById("<%=hdnDraggedValue.ClientID%>").value = DraggedString
    return false;
}

var confo
function Confirm() {

    confo = $("#dialog_Confirm").dialog({
        title: 'Gird/Tab Display Name',
        modal: true,
        autoOpen: true,
        width: 250,
        height: 740,
        Overflow: auto,
        close: function () {
        }
    });
    $("#iFrame_Reconfirm").prop("src", "FrmAllTabNameList.aspx");
    confo.dialog('open');
}