﻿function createSortable(ulId,txtId,updatePnlId)
{            
    window.addEvent('domready', function(){
	    
	    var flag = false;
	    
	    new Sortables($(ulId), {
    	
		    revert: { duration: 500, transition: 'elastic:out' },
		    constrain: false,
            clone: true,
            onStart: function(){
                disableMenuLink(ulId,txtId);
            },
            onSort: function(){
                flag=true;
                return false;
            },
            onComplete: function(){
            
                if (flag)
                {
                    document.getElementById(txtId).value= this.serialize();
                    javascriptUpdate(updatePnlId);
    //              setTimeout("createSortableMenu('" + ulId + "','" + txtId + "','" + updatePnlId + "')",1000);
                }
                enableMenuLink(ulId,txtId)
                return false;
                
            }
	    });
    });
}


function javascriptUpdate(updatePnlId) 
{
    __doPostBack(updatePnlId,'');
}


function disableMenuLink(ulId,txtId)
{
    try
    {
        var allChilds = document.getElementById(ulId).childNodes;
        
        for (var i=0; i < allChilds.length; i++) 
        {
            if (allChilds[i].firstChild.href  != "")
            {
                allChilds[i].firstChild.name = allChilds[i].firstChild.href;
                allChilds[i].firstChild.href="javascript:void(0)";
                
            }  
        }
    }
    catch(e)
    {}
}

function enableMenuLink(ulId,txtId)
{
    try
    {
        var allChilds = document.getElementById(ulId).childNodes;
        
        for (var i=0; i < allChilds.length; i++) 
        {
            if (allChilds[i].firstChild.href  == "javascript:void(0)")
            {
                allChilds[i].firstChild.href = allChilds[i].firstChild.name;
                
            }  
        }
    }
    catch(e)
    {}
}