﻿function createSortable(ulId)
{
    Sortable.create(ulId,
    {
        handle:'handle',
        onUpdate: function()
        {
            var str  = Sortable.serialize(ulId);
            str = str.split(ulId + "[]=");
            var priority = 1;
            var allPriorityTextBoxs = document.getElementsByTagName("input");
            
            for (var i=0; i < allPriorityTextBoxs.length; i++) 
            {
                if (allPriorityTextBoxs[i].className == "priorityTextBox")
                {
                    allPriorityTextBoxs[i].value = priority++ * 2; //str[i].replace("&","");
                }
            }
        }
    });
}

function createSortableMenu(ulId,txtId)
{
            
    Sortable.create(ulId,
    {
        constraint: false,
        onUpdate: function()
        {
            var str  = Sortable.serialize(ulId);
            str = str.split(ulId + "[]=");
            document.getElementById(txtId).value= str;
            
        }
    });
}


function createSortableGallery(ulId,bottomUid,txtId)
{
            
    Sortable.create(ulId,
    {
    containment:[ulId,bottomUid],
        constraint: false,
        onUpdate: function()
        {
            var str  = Sortable.serialize(ulId);
            str = str.split(ulId + "[]=");
            document.getElementById(txtId).value= str;
            
        }
    });
}


function disableMenuLink(ulId,txtId)
{

    var allChilds = document.getElementById(ulId).childNodes;

    for (var i=0; i < allChilds.length; i++) 
    {
        if (allChilds[i].firstChild.href  != "")
        {
            if (allChilds[i].firstChild.name  != "")
            {
                Sortable.destroy( ulId );
                allChilds[i].firstChild.href=allChilds[i].firstChild.name;
            }
            else
            {
                createSortableMenu(ulId, txtId)
                allChilds[i].firstChild.name=allChilds[i].firstChild.href;
                allChilds[i].firstChild.href="javascript:void(0)";//priority++ * 2; //str[i].replace("&","");
            }
        }
        
       
    }
    
}
