
$.support.cors = true;
jQuery.support.cors = true; ////


var colorArray = Array("#02A0E3", "#35C1FD", "#989701", "#CAC902", "#6C6CB7", "#660954", "#FB9804", "#663399", "#8B53C6", "#FF6600", "#CC3300", "#CCCC9A", "#8C9C9A", "#9DB2B1", "#BFCFCC", "#D6E4E1", "#CDBFAC", "#E1D4C0", "#F5EDE3", "#F1EFE2", "#F5FAFA", "#E7E4D3", "#F6F4DA", "#F4F3EE", "#ACD1E9", "#DF9496");
//var data1 = [ ['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14],  ['Out of home', 16],['Commuting', 7], ['Orientation', 9] ];
//var data1 = [["Due to Expiry today",1206],["Not Converted_Flag",306],["Converted_Flag",242]];

//var urlWS = window.location.protocol + '//' + window.location.host + '/FinIQWeb_webservice/Dashboard_WS/FinIQ_Dashboard_WS.asmx/';

var data1 = [];
var day = "";
var arrDayTemp = [];
var methodname = "";
var scenarioname;
var usertype;
var sequence = 0;
var scenariosequence;
var scenariotype;
var username;
var scenariousername;
var entityid;
var scenarioentity;
var count = 1;
var count1 = 1;
var count2 = 0;
var position;
var user;


jQuery.support.cors = true;


//From .aspx side Start

var getDataPoint = " ";
var linkname = "";
var panelArray = [];


//window.onbeforeunload = function () {
//    
//    if (panelArray.length > 0) {
//        for (var i = 0; panelArray.length - 1; i++) {
//            sessionStorage.removeItem(panelArray[i]);
//        }
//        return '';
//    }

//    else {
//        return '';

//    }
$(window).unload(function () {
    //Call here delete all filters for logged in user

    try {
        $.ajax({
            type: 'POST',
            url: 'web_DashboardData.aspx/Update_DD_Before_Unload',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({ "EntityID": entityid, "Usertype": usertype, "UserName": $("#ctl00_MainContent_Login").val().trim() }),
            crossDomain: true,
            async: false,
            success: function (data) {




            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });

    } catch (err) {
        console.log(err.message);
    }

})

function ddlAutocompleteControl(controlID, strArray) {
    try {

        var availableTags = [];
        availableTags = strArray.split("|");

        $("#ctl00_MainContent_" + controlID).autocomplete({
            source: availableTags,
            autoFocus: true,
            minLength: 0,
            select: function (event, ui) {
                var label = ui.item.label;
                var value = ui.item.value;
                //store in session
                $("#ctl00_MainContent_" + controlID).val(value.trim())
                __doPostBack("ctl00_MainContent_" + controlID, "TextChanged");

            }
        }).focus(function () {
            //  $(this).autocomplete("search");
            //  $(this).data("uiAutocomplete").search($(this).val());
            $(this).autocomplete("search", "");
        });

    } catch (err) {
        console.log(err.message)
    }
}
function OpenWindow(obj) {
    try {
        if (1) {
            return true
        } else {
            getDataPoint = $(obj).attr('title').replace(",", "");
            //    $("#mainDrag, #droppableContainer, .divFilter").addClass("parentDisable").attr("disabled", "disabled");

            $(".gridpanel").fadeIn("slow");
            linkname = $(obj).parent().parent().parent().find("input[type='hidden']").val();

            $("#ctl00_MainContent_linknameHiddenField").val(linkname);

            $("#ctl00_MainContent_dataHiddenField").val(getDataPoint);
            $("#gridPanelTitle").html(getDataPoint);

            $("#ctl00_MainContent_btn_getDataPointDetails").click();
        }
    } catch (error) {
        console.log(error.message);

    }

}


$(function () {
    $(".btnCancel").click(function () {

        $(this).parent().parent().parent().parent().parent().hide();

    });
    $(".ViewMoreBtn").each(function () {
        $(this).click(function () {

            $('.ViewGridDetailsPanel').show('fast');
            $("body").scrollTop(0);

        })
    })
});





window.onload = function () {



}

function removediv(btnObj) {
    try {
        $(btnObj).parent().parent().fadeOut("slow");
        //   $("#mainDrag, #droppableContainer, .divFilter").removeClass("parentDisable").removeAttr("disabled", "disabled");

    } catch (error) {
        console.log(error.message);

    }

}

function removeZoomedPanel(objNew) {
    try {

        $(objNew).parent().hide("slow");
        // $("#mainDrag, #droppableContainer, .divFilter").removeClass("parentDisable").removeAttr("disabled", "disabled");
    } catch (error) {
        console.log(error.message);

    }
}
function removeOpenedGridPanel(objGridPanel) {
    try {

        $(objGridPanel).parent().hide("slow");
        //   $("#mainDrag, #droppableContainer, .divFilter").removeClass("parentDisable").removeAttr("disabled", "disabled");

    } catch (error) {
        console.log(error.message);

    }
}



//End

$(function () {
    $(".datepicker").each(function () {

        $(this).datepicker({ dateFormat: 'dd-M-yy' });
    })

});


$(function () {

    // $('#mainDrag').hide();
    $(".TDDraggable").each(function () {
        $(this).slideToggle("fast");

    })




    $('#arrow').click(function () {

        if (count2 % 2 == 0) {
            $(this).css('background-image', 'url(images/arrow/arrow_right.png)');
            // $(".innerDroppableContainer").width(1850);
            //  $('#mainDrag').slideToggle("fast");
            $(".TDDraggable").each(function () {
                $(this).slideToggle("fast");

            })
        }
        else {

            $(this).css('background-image', 'url(images/arrow/arrow_left.png)');
            a = (1850);
            //   $(".innerDroppableContainer").width(a);
            //   $('#mainDrag').slideToggle("fast");
            $(".TDDraggable").each(function () {
                $(this).slideToggle("fast");

            })

        }
        count2++;


    });
});





$(document).click(function (event) {

    var e = event || window.event;
    var popup = $(".PanelFilter");

    if (e.target.localName == "span") {
        if ($(e.target).parent().parent().parent().find(".ui-datepicker")) {
            return false;
        }
    }
    else if (!$(".FilterSettings").is(e.target) && (!popup.is(e.target) && popup.has(e.target).length == 0)) {
        popup.hide(150);
    }

});

var parameter = Sys.WebForms.PageRequestManager.getInstance();

parameter.add_endRequest(function () {

    sessionStorage.setItem("recordsSaved", "FALSE");
    sessionStorage.setItem("recordsSavedFlag", "FALSE");
    $("#ctl00_MainContent_lblInfo").html("");

    $(".PanelFilter").each(function () {
        $(this).hide();
    });

    $(".btnCancel").click(function () {
        $(this).parent().parent().parent().parent().parent().hide();
        //   alert(2)
    })


    $(".FilterSettings").click(function () {
        try {
            $(this).parent().parent().parent().find(".PanelFilter").toggle();
            p = $(this).position();


            left1 = parseFloat(p.left) - ($(this).parent().parent().parent().find(".PanelFilter").width());
            top1 = ((parseFloat(p.top)) + 20) + "px";
            $(this).parent().parent().parent().find(".PanelFilter").css("left", left1);
            $(this).parent().parent().parent().find(".PanelFilter").css("top", top1);
        } catch (err) {
            console.log(err.message);
        }

    });

    $(function () {
        $(".datepicker").each(function () {

            $(this).datepicker({ dateFormat: 'dd-M-yy' });
        })

        $(".innerDroppableContainer").each(function (i, THIS) {
            //var title=    $(this).find("title here ")
            //     call LinkDisable(title,true);

        }) 
    });


    $(".resizeBtn").click(function () {
        
        $('.zoomChartDiv').show('fast');
        $("body").scrollTop(0);
        //  $("#mainDrag, #droppableContainer, .divFilter").addClass("parentDisable").attr("disabled", "disabled");
    });



    $(".ViewMoreBtn").each(function () {
        $(this).click(function () {
            $('.ViewGridDetailsPanel').show('fast');
            $("body").scrollTop(0);
        });
    });

});


function SetActiveFilterCSS(ScenarioNo, activeButton) {
    //$('input[type="submit"]').removeClass("ActiveFilter");
    //$(".PanelFilter").find('input[type="hidden"]').each(function () {

    //    if ($(this).val() == ScenarioNo) {

    //        $(this).parent().parent().find("." + activeButton).addClass("ActiveFilter");


    //    }
    //});
}

function createlist() {
    try {


        //    $(".lblError").html('');
        $("#draggableContainer").empty();
        var str = "";
        var UserType = "";
        var LoginID = "";
        var EntityID = "";

        LoginID = $("#ctl00_MainContent_Login").val();
        EntityID = $("#ctl00_MainContent_Entity").val();
        UserType = $("#ctl00_MainContent_UserType1").val();

        $.ajax({
            type: "POST",
            url: "web_DashboardData.aspx/Get_UserType",
            data: JSON.stringify({ "LoginID": LoginID, "EntityID": EntityID }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (dtUserType) {

                if (dtUserType.d != null) {

                    var obj = jQuery.parseJSON(dtUserType.d);

                    $(obj).each(function (i, strUserType) {
                        var h3 = $('<h3>').text(strUserType.Dashboard_Group);
                        $("#draggableContainer").append(h3);
                        var ul = $('<ul>');
                        $("#draggableContainer").append(ul);
                        EntityID = $("#ctl00_MainContent_Entity").val();
                        CreateScenarioList(strUserType.Dashboard_Group, EntityID, ul);
                    });
                    //$("#draggableContainer").append(obj);
                }
            }
        });

        $('#draggableContainer').accordion({
            header: "h3"
            , heightStyle: "content"
            , collapsible: true
        });
    }
    catch (er) {
        console.log(er.message);
    }
}


function CreateScenarioList(UserType, EntityID, panel) {

    $.ajax({
        type: "POST",
        url: "web_DashboardData.aspx/Get_Dashboard_Master_Json",
        data: JSON.stringify({ "UserType": UserType, "EntityID": EntityID }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,

        success: function (data) {
            var obj = jQuery.parseJSON(data.d);
            str = '';

            var ControlType = '';
            $(obj).each(function () {
                //str = str + '<div class="draggable" ><div class="LiTitle"><label class="LinkName" id="draggable' + count1 + '" onclick="clickaccordion(' + count1 + ')">' + $(this)[0].ScenarioHeader + '</label><span class="LinkID"  style="display:none">' + "Scenario " + $(this)[0].LinkName + '</span></div>';
                //str = str + '<div class="LiImage" id="LiImage' + count1 + '" style="background-image:url(images/' + $(this)[0].ControlType + '.png);background-repeat:no-repeat;display:none;"></div></div>';

                var li = $('<li class="draggable">');
                var label = $('<label>', { class: "LinkName", id: "draggable" + count1, text: $(this)[0].ScenarioHeader }).css({ "background-image": 'url("./images/icons/' + $(this)[0].ControlType + '.png")' }).on("click", function (index, elem) {
                    clickaccordion(this.id.replace('draggable', ''));
                });

                $(li).append($(label));

                $(li).append($('<span>', { class: "LinkID", css: { "display": "none" }, text: "Scenario " + $(this)[0].LinkName }));
                $(li).append($('<div>', { class: "LiImage", id: "LiImage" + count1 }).css({ "background-image": 'url("images/' + $(this)[0].ControlType + '.png")', "background-repeat": "no-repeat", "display": "none" }));

                $(panel).append(li);
                count1++;
                sort();
            });
            
            dragDrop();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("Error while creating list " + errorThrown);
        }
    });
}

function dragDrop() {

    try {
        var scenario = " ";
        var ScenarioHeader = " ";
        var $collaction = $('#draggableContainer li:not([disabled="disabled"])');
        var $trash = $('.innerDroppableContainer:not([disabled="disabled"])');

        $trash.droppable({
            accept: '#draggableContainer li:not([disabled="disabled"]), #draggableContainer .draggable:not([disabled="disabled"])',
            hoverClass: "highlight",

            drop: function (event, ui) {
                var $this = $(this);
                $(".highlight").removeClass("highlight");
                $this.addClass("highlight");

                scenario = ui.draggable.find(".LinkID").text();
                ScenarioHeader = ui.draggable.find(".LinkName").text();
                createPanel1(scenario, ScenarioHeader);

                LinkDisable(ScenarioHeader, true);
                $(".highlight").removeClass("highlight");
                $(this).addClass($(ui.draggable).attr('class'));

                count++;

            }

        });

        $collaction = $('#draggableContainer  .draggable:not([disabled="disabled"])');

        $collaction.draggable({
            revert: "invalid",
            containment: "window",
            helper: "clone",
            cursor: "move",
            drop: function (event, ui) {
                $(this).prop("disabled", true);
                $(this).prop("disabled", "disabled");
            }
        });
    } catch (err) {
        console.log(err.message());
    }
}


function clickaccordion(count1) {
    
    var count = count1;
    // $("#draggable"+count).click(function() {

    $("#LiImage" + count).slideToggle("slow");
    // });
}

function createPanel1(scenarioID, ScenarioHeader) {
    //  alert(scenarioID);
    var str = "";

    $(".mainContainer #ctl00_MainContent_updatePanel1").find(".panelDragable").each(function (i, element) {
        if ($(this).find(".PanelFilter").find('input[type="hidden"]').val() == scenarioID) {
            $(".innerDroppableContainer #ctl00_MainContent_updatePanel2").append($(this));
        }
    });

    $(".innerDroppableContainer .panelHeading").sortable({
        revert: true,
        cursor: "move",
        opacity: 0.5,
        handle: '.panelHeading',
        change: function (event, ui) {
            ui.placeholder.css({ visibility: 'visible' }).addClass('highlight');
        }
    }).disableSelection();




}


function fAccordion() {
    $('#draggableContainer').animate({ width: 'toggle' });
}


function removePanel(deleteBtnElement) {

    // $("#Loader").show();
    //$('body').addClass('opacity');
    var ScenarioHeader = "";
    ScenarioHeader = $(deleteBtnElement).parent().parent().find(".title").text().replace(':: ', '');
    $(deleteBtnElement).parent().parent().parent().prependTo($("#ctl00_MainContent_updatePanel1"));

    // alert(ScenarioHeader);
    LinkDisable(ScenarioHeader, false);
    var scenarioToDelete;
    scenarioToDelete = $(deleteBtnElement).parent().parent().next().find("input[type='hidden']").val().trim();

    deleteSinglePanel(scenarioToDelete);

    //  $(".lblError").html('Dashboard Updated Successfully!');


}
function deleteSinglePanel(scenarioToDelete) {
    try {
        var clearItemKey = [];
        clearItemKey = scenarioToDelete.split(" ");

        $.support.cors = true;

        var UserType = "";
        var LoginID = "";
        var EntityID = "";

        LoginID = $("#ctl00_MainContent_Login").val();
        EntityID = $("#ctl00_MainContent_Entity").val();
        UserType = $("#ctl00_MainContent_UserType1").val();

        return;
        $.ajax({
            type: 'POST',
            url: 'web_DashboardData.aspx/Delete_SinglePanel',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({ "scenarioToDelete": scenarioToDelete, "UserName": LoginID, "EntityID": EntityID, "UserType": UserType }),
            crossDomain: true,
            async: false,
            success: function (data) {

                sessionStorage.removeItem(clearItemKey[0] + "_" + clearItemKey[1] + "_" + UserType);
                console.log("Deleted :: " + clearItemKey[0] + "_" + clearItemKey[1] + "_" + UserType);

            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    } catch (err) {
        console.log(err.message);

    }
    finally {


    }
}

function LinkDisable(ScenarioHeader, disabled) {
    if (disabled == true) {
        $('#draggableContainer .draggable:contains(' + ScenarioHeader + ')').prop("disabled", "disabled");
        $('#draggableContainer .draggable:contains(' + ScenarioHeader + ')').attr('disabled', true);
    }
    else if (disabled == false) {
        $('#draggableContainer .draggable:contains(' + ScenarioHeader + ')').prop("disabled", false);
        $('#draggableContainer .draggable:contains(' + ScenarioHeader + ')').removeAttr('disabled');
    }
}





function fdelete() {
    try {

        $.support.cors = true;

        var UserType = "";
        var LoginID = "";
        var EntityID = "";
        LoginID = $("#ctl00_MainContent_Login").val();
        EntityID = $("#ctl00_MainContent_Entity").val();
        UserType = $("#ctl00_MainContent_UserType1").val();
        var layoutID = $("#ctl00_MainContent_txtLayout").val();
        $.ajax({
            type: 'POST',
            url: 'web_DashboardData.aspx/Delete_Dashboard_Data',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({ "UserName": LoginID, "EntityID": EntityID, "UserType": UserType, "LayoutID": layoutID }),
            crossDomain: true,
            async: false,
            success: function (data) {

            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });

    } catch (error) {
        console.log(error.message);
    }
}



function fsave() {
    try {
        var index = 0;

        $(".innerDroppableContainer ").find(".panelDragable").each(function (index, element) {
            var ScenarioID = " ";
            var UserType = "";
            var LoginID = "";
            var EntityID = "";
            ScenarioID = $(this).find('.PanelFilter').find('input[type="hidden"]').val();
            UserType = $("#ctl00_MainContent_UserType1").val();
            LoginID = $("#ctl00_MainContent_Login").val();
            EntityID = $("#ctl00_MainContent_Entity").val();
            layoutID = $("#ctl00_MainContent_txtLayout").val();

            if ($(this).css("display") == "block") {
                index = index + 1;
                SequenceNo = Number(index);
                InsertSequence(UserType, LoginID, EntityID, ScenarioID, SequenceNo, layoutID);

            }
        });
    } catch (err) {
        console.log(err.message);

    } finally {

        $("#Loader").hide();
        $('body').removeClass('opacity');
        sessionStorage.setItem("recordsSaved", "TRUE");
        sessionStorage.setItem("recordsSavedFlag", "TRUE");

        window.location.reload();

    }
}

//Add for overlay effect on ajax loading in progress by Shekhar 04-Feb-2019
$(document).ready(function () {
    try {
        $(document).ajaxStart(function () {
            $('#loader').hide();
        });
        $(document).ajaxStop(function () {
            $('#loader').hide();
        });
        $(document).ajaxError(function (e, xhr, opt) {
            $('#loader').hide();
        });


        $(document).find('.buttonsContainer button.closeButton').attr('title', 'Delete');

        $('.panelDragable .min').remove();
        $('.panelDragable .max').remove();
        $('.panelDragable .exit').remove();

        $('.panelDragable').append('<div class="after"><div class="s1" title="Shortcut-1" onclick="dialogMin(event, this);" ></div><div class="s2" title="Shortcut-2" onclick="javascript:dialogMax(event, this);"></div><div class="s3"  title="Shortcut-3" onclick="dialogClose(event, this);"></div><div class="s4"  title="Shortcut-4" onclick="dialogClose(event, this);"></div></div>');


    } catch (er) { console.log(er.message); }
});





function UpdateDashBoardDetails(ScenarioNo, EntityID, UserType, UserName, fromDate, toDate, DayRange, DateP, Year, Month) {
    try {
        //    panelArray.push(ScenarioNo.replace(" ", "_") + "_" + UserType);
        
        sessionStorage.setItem(ScenarioNo.replace(" ", "_") + "_" + UserType, EntityID + "|" + UserType + "|" + UserName + "|" + fromDate + "|" + toDate + "|" + DayRange + "|" + DateP + "|" + Year + "|" + Month);
        //  $(".lblError").html(ScenarioNo + ' :: Dashboard Updated Successfully!');
    } catch (err) {
        console.log(err.message());
    }

}


function InsertSequence(UserType, LoginID, EntityID, ScenarioID, SequenceNo, LayoutID) {
    try {

        $.support.cors = true;
        var getlocalStorageData = " ";

        if (sessionStorage.getItem(ScenarioID.replace(" ", "_") + "_" + UserType) != null) {
            getlocalStorageData = sessionStorage.getItem(ScenarioID.replace(" ", "_") + "_" + UserType);
        } else {
            getlocalStorageData = "";
        }


        dataTD = JSON.stringify({ "SequenceNo": SequenceNo, "EntityID": EntityID, "ScenarioID": ScenarioID, "UserName": LoginID, "UserType": UserType, "getlocalStorageData": getlocalStorageData, "LayoutID": LayoutID });
        $.ajax({
            type: 'POST',

            url: 'web_DashboardData.aspx/Insert_Dashboard_Data',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: dataTD,
            crossDomain: true,
            async: false,
            success: function (data) {
                $("#ctl00_MainContent_lblInfo").html("Layout Saved Successfully!");

            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
                $("#ctl00_MainContent_lblInfo").html("Layout not Saved!" + thrownError);
            }
        });
    } catch (er) {
        console.log(er.message);
    }
}

$(document).ready(function () {


    $(document).find(".PanelFilter").each(function (iPanelFilter, PanelFilter) {
        $(PanelFilter).hide();
    });
    //  $(".lblError").html('');
   // $("#ctl00_MainContent_lblInfo").html("");

    if (sessionStorage.getItem("recordsSaved") == "TRUE" && sessionStorage.getItem("recordsSavedFlag") == "TRUE") {
        
        $("#ctl00_MainContent_lblInfo").html("Layout Saved Successfully!");
        sessionStorage.setItem("recordsSaved", "FALSE");
        sessionStorage.setItem("recordsSavedFlag", "FALSE");
        setTimeout(function () {
            $("#ctl00_MainContent_lblInfo").html("")

        }, 5000);
    }
    else {
        sessionStorage.setItem("recordsSaved", "FALSE");
        sessionStorage.setItem("recordsSavedFlag", "FALSE");
        $("#ctl00_MainContent_lblInfo").html("");
    }


    sessionStorage.setItem("recordsSaved", "FALSE");
    sessionStorage.setItem("recordsSavedFlag", "FALSE");

    $(".PanelFilter").find(" table").find(" td").attr("nowrap", "nowrap"); 
    createlist();

    $("#ctl00_MainContent_updatePanel2").sortable({
        revert: true,
        cancel: ".disable-sort-item",
        handle: '.panelHeading',
        change: function (event, ui) {
            ui.placeholder.css({ visibility: 'visible' }).addClass('highlight');
        }
       
}).disableSelection();


    $(".saveLayout").each(function () {
        $(this).on('click', function () {
           
            $("#Loader").show();
            $('body').addClass('opacity');

            setTimeout(function () {
                fdelete();
                console.log("calling delete function")
            }, 3000)
            setTimeout(function () {
                fsave();
                console.log("calling save function")
            }, 3000)

        }
            )
    });





    $(".FilterSettings").click(function () {
        $(this).parent().parent().parent().closest('div').find(".PanelFilter").toggle();
        p = $(this).position();

        left1 = parseFloat(p.left) - ($(this).parent().parent().parent().find(".PanelFilter").width());
        top1 = ((parseFloat(p.top)) + 20) + "px";

        $(this).parent().parent().parent().find(".PanelFilter").css("left", left1);
        $(this).parent().parent().parent().find(".PanelFilter").css("top", top1);
    });

    $(".popupdiv").click(function () {
        $(this).fadeOut();
    });

    $(".zoomChartDiv").hide();

    $(".ViewGridDetailsPanel").hide();
    $(".resizeBtn").click(function () {
        
        $('.zoomChartDiv').show('fast');
        $("body").scrollTop(0);
        //  $("#mainDrag, #droppableContainer, .divFilter").addClass("parentDisable").attr("disabled", "disabled");
    });



    $(".gridpanel").draggable({
        containment: "window",
        helper: "original",
        cursor: "move",
        drop: function (event, ui) {

        }
    });

    var $trash2 = $("body");

    $trash2.droppable({
        hoverClass: "highlight",
        accept: ".gridpanel",
        drop: function (event, ui) {

        },
        change: function (event, ui) {
            ui.placeholder.css({ visibility: 'visible' }).addClass('highlight');
        }
    });

    $("#ctl00_MainContent_updatePanel2, #ctl00_MainContent_updatePanel1").sortable({
        revert: true,
        cursor: "move",
        opacity: 0.5,
        handle: '.panelHeading',
        change: function (event, ui) {
            ui.placeholder.css({ visibility: 'visible' }).addClass('highlight');
        }
          
    }).disableSelection();


    $("#ctl00_MainContent_updatePanel2>div.panelDragable").each(function (i, elem) {
        LinkDisable($(elem).find("div.title").text().trim(), true);
    });

});

function SearchScenario(that, event){
    try { 
        var filter = that.value.toUpperCase();
        
        $('#draggableContainer > UL li').each(function (index, li) {
           var txtValue =  $(li).find("label.LinkName").text();
            if (txtValue.toUpperCase().indexOf(filter) > -1) {
                li.style.display = "";
            } else {
                li.style.display = "none";
            }
        }); 
    } catch (er) { }
}

 

    function Ascending_sort(a, b) {
        return ($(b).text().toUpperCase()) <
            ($(a).text().toUpperCase()) ? 1 : -1;
    }
    

    function sort() {
        var selector = $('#draggableContainer > UL')[0];
        btnSort = $('#mainDrag > h3 .sort');
        if ($(btnSort).attr('title') == 'Asc') {
            $(selector).children("li").sort(function (a, b) {
                var A = $(a).find("label.LinkName").text().toUpperCase();
                var B = $(b).find("label.LinkName").text().toUpperCase();
                return (A < B) ? -1 : (A > B) ? 1 : 0;
            }).appendTo(selector);
            $(btnSort).attr('title', 'Desc');
        } else {
            $(selector).children("li").sort(function (a, b) {
                var A = $(a).find("label.LinkName").text().toUpperCase();
                var B = $(b).find("label.LinkName").text().toUpperCase();
                return (A < B) ? 1 : (A > B) ? -1 : 0;
            }).appendTo(selector);
            $(btnSort).attr('title', 'Asc');
        }
       
    }

   