var accountid
var folderid
var authoringauthorization
var userauthorization
var editlinks
var editfolders

function SetAccountID(id)
{
	accountid = id
}

function SetFolderID(id)
{
	folderid = id
}

function SetAuthorization(authoring, user, links, folders)
{
	authoringauthorization = authoring
	userauthorization = user
	editlinks = links
	editfolders = folders
}

function GetAnchorHRef(target)
{
	while (target)
	{
		if (target.tagName == 'A')
		{
			return target.href
		}
		target = target.parentElement
	}

	return ''
}

function ParseUrl(url, isdest)
{
	var r = new Object
	var n

	if (url > '')
	{

		if (isdest || (authoringauthorization == 'True' || (userauthorization == 'True' && editlinks == 'True')))
		{
			n = url.indexOf('golink.asp')
			if (n >= 0)
			{
				n += 16
				r.type = 1
				var m = url.indexOf('&', n)
				r.val = url.substring(n, m)
				return r
			}
		}

		if (isdest || (authoringauthorization == 'True' || (userauthorization == 'True' && editfolders == 'True')))
		{
			n = url.indexOf('browse.asp')
			if (n >= 0)
			{
				n += 18
				r.type = 2
				r.val = url.substr(n)
				return r
			}

			n = url.indexOf('openfolder_action.asp')
			if (n >= 0)
			{
				n += 29
				r.type = 2
				var m = url.indexOf('&', n)
				r.val = url.substring(n, m)
				return r
			}
			n = url.indexOf('closefolder_action.asp')
			if (n >= 0)
			{
				n += 30
				r.type = 2
				var m = url.indexOf('&', n)
				r.val = url.substring(n, m)
				return r
			}
		}
	}

	r.type = 0
	return r
}

// This function is called by the target object in the ondrop event.

function HandleDrop()
{
	var oData = window.event.dataTransfer;

	if (oData.getData("URL") != null)
	{
		var src = ParseUrl(oData.getData("URL"), false)
		if (src.type > 0)
		{
			var dst = ParseUrl(GetAnchorHRef(window.event.srcElement), true)

			if ((dst.type == 2) && ((src.type != dst.type) || (src.val != dst.val)))
			{
				CancelDefault()
				if (src.type == 1)
				{
//alert('src.type=' + src.type + ' src.val=' + src.val + ' dst.type=' + dst.type + ' dst.val=' + dst.val)
					if (false && window.event.shiftKey)
					{
						if (window.event.ctrlKey || confirm("Are you sure you want to make a copy of this link in another folder?\n(to avoid this prompt in the future, hold down the ctrl key)"))
						{
							window.location.href = 'dragdrop_action.asp?op=copylink&linksrc=' + src.val + '&folderdst=' + dst.val + '&folderid=' + folderid + '&accountid=' + accountid
						}

					}
					else
					{
						if (window.event.ctrlKey || confirm("Are you sure you want to move this link into another folder?\n(to avoid this prompt in the future, hold down the ctrl key)"))
						{
							window.location.href = 'dragdrop_action.asp?op=movelink&linksrc=' + src.val + '&folderdst=' + dst.val + '&folderid=' + folderid + '&accountid=' + accountid
						}
					}
				}
				else if (src.type == 2)
				{
					if (false && window.event.shiftKey)
					{
						if (window.event.ctrlKey || confirm("Are you sure you want to make a copy of this folder in another folder?\n(to avoid this prompt in the future, hold down the ctrl key)"))
						{
							window.location.href = 'dragdrop_action.asp?op=copyfolder&foldersrc=' + src.val + '&folderdst=' + dst.val + '&folderid=' + folderid + '&accountid=' + accountid
						}
					}
					else
					{
						if (window.event.ctrlKey || confirm("Are you sure you want to move this folder into another folder?\n(to avoid this prompt in the future, hold down the ctrl key)"))
						{
							window.location.href = 'dragdrop_action.asp?op=movefolder&foldersrc=' + src.val + '&folderdst=' + dst.val + '&folderid=' + folderid + '&accountid=' + accountid
						}
					}
				}
			}
		}
	}
}

// This function sets the dropEffect when the user moves the mouse over the target object.

function HandleDragEnter()
{
	var oData = window.event.dataTransfer;

	if (oData.getData("URL") != null)
	{
		var src = ParseUrl(oData.getData("URL"), false)
		if (src.type > 0)
		{
			var dst = ParseUrl(GetAnchorHRef(window.event.srcElement), true)
			if ((dst.type == 2) && ((src.type != dst.type) || (src.val != dst.val)))
			{
				CancelDefault()
				if (false && window.event.shiftKey)
					oData.dropEffect = "copy";
				else
					oData.dropEffect = "move";
			}
		}
	}
}

function HandleDragOver()
{
	var oData = window.event.dataTransfer;

	if (oData.getData("URL") != null)
	{
		var src = ParseUrl(oData.getData("URL"), false)
		if (src.type > 0)
		{
			var dst = ParseUrl(GetAnchorHRef(window.event.srcElement), true)
			if ((dst.type == 2) && ((src.type != dst.type) || (src.val != dst.val)))
			{
				CancelDefault()
			}
		}
	}
}

function CancelDefault()
{
	window.event.returnValue = false;
}




// This function is called when the user initiates a drag-and-drop operation.

function HandleDragStart()
{                                      
	var oData = window.event.dataTransfer;

	if (false && window.event.shiftKey)
		oData.effectAllowed = "copy";
	else
		oData.effectAllowed = "move";
}


function getObject(obj)
{
	if (typeof obj == "string") 
	{		
		if (document.getElementById)	// Browser check: DOM compliant browser
		{
			return document.getElementById(obj).style
		}
		else if (document.all)			// Browser check: IE DHTML compliant browser
		{
			return document.all[obj].style
		}
		else if (document.layers)		// Browser check: NS (4.x) DHTML compliant browser
		{
			return document[obj]
		}

		return null;
	}

	return obj
}


<!-- This function is responsible for showing and hiding the DHTML object -->
function setVisibility(obj, flag)
{
	var isNav = (navigator.appName == "Netscape")
	var theObj = getObject(obj)
	if (theObj)
	{
		if (flag)
			theObj.visibility = 'visible'
		else
			theObj.visibility = 'hidden'
	}
}

function shiftTo(obj, x, y)
{
	var isNav = (navigator.appName == "Netscape")
	var theObj = getObject(obj)
	if (theObj)
	{
		if (isNav) 
		{
			if (document.getElementById)
			{
				theObj.style.left = x;			// doesn't work in netscape 6
				theObj.style.top = y;
			}
			else
				theObj.moveTo(x, y);
		}
		else 
		{
			theObj.pixelLeft = x;
			theObj.pixelTop = y;
		}
	}
}

function shiftBy(obj, deltaX, deltaY)
{
	var isNav = (navigator.appName == "Netscape")
	var theObj = getObject(obj)
	if (theObj)
	{
		if (isNav)
		{
			if (document.getElementById)
			{
				theObj.style.left += deltaX;	// doesn't work in netscape 6
				theObj.style.top += deltaY;
			}
			else
				theObj.moveBy(deltaX, deltaY);
		}
		else
		{
			theObj.pixelLeft += deltaX;
			theObj.pixelTop += deltaY;
		}
	}
}

function CheckAll(thisform, str, box)
{
	var strlen = str.length

	var numelements = document.thisform.elements.length;

	var elements = document.thisform.elements;

	for (var i=0;i<numelements;i++)
	{ 
		var e = elements[i];

		if (e.type == 'checkbox')
		{
			if (e.name.substring(0, strlen) == str)
			{
				e.checked = box.checked;
			}
		}
	}
}
