// Sets specified URL as homepage in IE
function setHomepage(url,string) {
    if (document.all){
	document.write('<A HREF="#" onClick="this.style.behavior=\'url(#default#homepage)\';this.setHomePage(\'' + url + '\');">');
	document.write(string);
	document.write('</a>');
    }
}

// Opens new window with specified content
function openWindow(url, w, h) {
    var options = "width=" + w + ",height=" + h + ",";
    options += "resizable=yes,scrollbars=yes,status=yes,";
    options += "menubar=no,toolbar=no,location=no,directories=no";
    var newWin = window.open(url, 'newWin', options);
    newWin.focus();
}

// Loads content in existing window
function load(file, target) {
    if (target != '') target.window.location.href = file;
    else window.location.href = file;
}

// Checks item's checkbox when starting to drag item
function startDrag(item, type) {
    window.event.dataTransfer.effectAllowed = "move";
    if (type != '') document.getElementById(type + '_' + item).checked = true;
}

// Sets graphic and checks destination folder when dragging item over folder
function showDragCursor(to_folder) {
    window.event.returnValue = false;
    window.event.dataTransfer.dropEffect = "move";
    document.getElementById('radio_' + to_folder).checked = true;
}

// Sets graphic and hidden form value and submits form when dropping item on folder
function drop(action, to_folder) {
    window.event.returnValue = false;
    window.event.dataTransfer.dropEffect = "move";
    var drag_move = eval("document." + action + ".drag_move");
    drag_move.value = 1;
    var form = eval("document." + action);
    form.submit();
}

// Detects whether Enter key has been pressed in input fields
function detectEnter(action, evt, type) {
    evt = (evt) ? evt : event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode == 13) {
    	var execute = eval("document." + action + ".execute");
	execute.value = type;
	var form = eval("document." + action);
	form.submit();
    }
}

// Toggles main menu submenus on and off
function toggleSubMenu(element, action) {
    if (action == 'on') {
	document.getElementById(element).style.display = 'block';
    }
    else if (action == 'off') {
	document.getElementById(element).style.display = 'none';
    }
}
