﻿//dragdrop.js

var dropInfo;
var dropCandidate;
var dropTarget;
var isDragging = false;
var isTreeMouseDown = false;
var dragObject = null;

function SetDropInfo ( droppedInfo )
{
    dropInfo = droppedInfo;
    dropTarget = dropCandidate;
    dropCandidate = "";
    
    var dropTarget = document.getElementById ( dropTarget );
    
    if(  !IsNullOrEmpty(dropTarget  ))
    {
        dropTarget.innerHTML = dropInfo;
    }
}

function SetDropCandidate( dragCellInfo )
{
    dropCandidate = dragCellInfo;
}

function CancelEvent( evtObj ) 
{
    evtObj.returnValue = false;
}

function UnsetDropCandidate( )
{
    dropCandidate = "";
}

function dragDrop( value )
{
}

function enterDrag(evtObj  )
{
}

function overDrag(evtObj  )
{
}

function startDrag(   evtObj  )
{
     isDragging = true;
}

function endDrag( evtObj  )
{
    isDragging = false;
    src = evtObj.srcElement;
    if(  !IsNullOrEmpty(src  ))
    {
         SetDropInfo ( src.id );
    }
}

//function dragMouseMove( evtObj )
//{
//    if( isDragging )
//    {
//         var src = evtObj.srcElement;
//         if(  !IsNullOrEmpty(src  ))
//         {
//    //        var objStyle = src.getAttribute("style");
//    //        if (! isIE) 
//    //        {
//    //            objStyle = ReplaceStringAttribute( objStyle, "cursor", "move" );
//    //        }
//    //        else
//    //        {
//    //	        objStyle.setAttribute("cursor", "move");
//    //	    }
//    //        src.setAttribute("style", objStyle);
//         }
//     }
//}

//function NonIEBeginDrag( evtObj )
//{
//    if (! isIE) 
//    {
//        if( !isDragging )
//        {
//            evtObj.returnValue = false;
//            var src = evtObj.srcElement;
//            if(  !IsNullOrEmpty(src  ))
//            {
//                isCapture = true;
//                isDragging = true;
//                src.setCapture();
//            }
//        }
//     }
//}

//function NonIEEndDrag( evtObj )
//{
//    if (! isIE) 
//    {
//        if( isDragging )
//        {
//            
//            evtObj.returnValue = false;
//            var src = evtObj.srcElement;
//            if(  !IsNullOrEmpty(src  ))
//            {
//                src.releaseCapture();
//                isCapture = false;
//                isDragging = false;
//                isTreeMouseDown = false;
//                SetDropInfo ( src.id );
//                
//            }
//        }
//     }
//}

function treeOnMouseDown( evtObj )
{
    if (!isIE) 
    {
        var src = evtObj.srcElement;
        if(  !IsNullOrEmpty(src  ))
        {
            isCapture = true;
            dragObject = src;
            dragObject.setCapture();
        }
    }
}

function treeOnMouseUp( evtObj )
{
    if (!isIE) 
    {
        if( isCapture &&  !IsNullOrEmpty(dragObject ))
        {
//            var src = evtObj.srcElement;
//            if(  !IsNullOrEmpty(src  ))
//            {
                dragObject.releaseCapture();
                isCapture = false;
                dragObject = null;
//            }
        }
    }
}

function DropOnMouseUp( evtObj, value )
{
    if (!isIE) 
    {
        if( isDragging )
        {
            var src = evtObj.srcElement;
            if(  !IsNullOrEmpty(src  ))
            {
                src.releaseCapture();
                isCapture = false;
                isDragging = false;
                isTreeMouseDown = false;
                SetDropCandidate ( value );
                SetDropInfo ( dropInfo );
            }
        }
    }
}

function treeOnMouseMove( evtObj )
{
    if (!isIE) 
    {
        if( isTreeMouseDown )
        {
            if( !isDragging )
            {
            var src = evtObj.srcElement;
                if(  !IsNullOrEmpty(src  ))
                {
                    dropInfo = src.id;
                    isCapture = true;
                    isDragging = true;
                    src.setCapture();
                }
            }
        }
    }
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();