/**
 * Functions for the image listing, used by images.php only
 * @author $Author: Wei Zhuo $
 * @version $Id: images.js 26 2004-03-31 02:35:21Z Wei Zhuo $
 * @package ImageManager
 */
        function changeDir(newDir)
        {
                showMessage('Loading');
                location.href = "images.php?dir="+newDir;
        }

        function newFolder(dir, newDir)
        {
                location.href = "images.php?dir="+dir+"&newDir="+newDir;
        }

        //update the dir list in the parent window.
        function updateDir(newDir)
        {
                var selection = window.top.document.getElementById('dirPath');
                if(selection)
                {
                        for(var i = 0; i < selection.length; i++)
                        {
                                var thisDir = selection.options[i].text;
                                if(thisDir == newDir)
                                {
                                        selection.selectedIndex = i;
                                        showMessage('Loading');
                                        break;
                                }
                        }
                }
        }
        function selectImage(filename, alt, width, height, thumbSrc, thumbAlt, thumbWidth, thumbHeight)
        {
                var topDoc = window.top.document;

                if (topDoc.getElementById('main').checked)
                {
                    topDoc.getElementById('f_url').value = filename;
                    topDoc.getElementById('f_width').value = width;
                    topDoc.getElementById('f_height').value = height;
                    topDoc.getElementById('f_alt').value = alt;
                    topDoc.getElementById('original_width').value = width;
                    topDoc.getElementById('original_height').value = height;
                    if (topDoc.getElementById('onmouseout').disabled == false){
                        topDoc.getElementById('onmouseout').value = filename;
                    }
                }
                if (topDoc.getElementById('option').checked && topDoc.getElementById('popupenable').checked == true)
                {
                    if(thumbSrc != 'null'){
                        if(confirm('Use image\'s thumbnail?')){
                            topDoc.getElementById('f_url').value = thumbSrc;
                            topDoc.getElementById('f_width').value = thumbWidth;
                            topDoc.getElementById('f_height').value = thumbHeight;
                            topDoc.getElementById('f_alt').value = thumbAlt;
                            topDoc.getElementById('original_width').value = thumbWidth;
                            topDoc.getElementById('original_height').value = thumbHeight;
                        }
                    }
                    topDoc.getElementById('popupthumb').value = filename;
                    topDoc.getElementById('thumbWidth').value = width;
                    topDoc.getElementById('thumbHeight').value = height;
                    topDoc.getElementById('thumbname').value = alt;
                    topDoc.getElementById('original_width_thumb').value = width;
                    topDoc.getElementById('original_height_thumb').value = height;
                }
                if (topDoc.getElementById('option').checked && topDoc.getElementById('onmousemove').checked)
                {
                    topDoc.getElementById('onmouseover').value = filename;
                }
        }
        function showMessage(newMessage)
        {
                var topDoc = window.top.document;

                var message = topDoc.getElementById('message');
                var messages = topDoc.getElementById('messages');
                if(message && messages)
                {
                        if(message.firstChild)
                                message.removeChild(message.firstChild);

                        message.appendChild(topDoc.createTextNode(newMessage));

                        messages.style.display = "block";
                }
        }
        
        function confirmNewThumb(file)
        {
                if(confirm("Create Thumbnail "+file+"?"))
                        return true;

                return false;
        }

        function confirmDelThumb(file)
        {
                if(confirm("Delete Thumbnail "+file+"?"))
                        return true;

                return false;
        }

        function addEvent(obj, evType, fn)
        {
                if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; }
                else if (obj.attachEvent) {  var r = obj.attachEvent("on"+evType, fn);  return r;  }
                else {  return false; }
        }

        function confirmDeleteFile(file)
        {
                if(confirm("Delete file?"))
                        return true;

                return false;
        }

        function confirmDeleteDir(dir, count)
        {
                if(count > 0)
                {
                        alert("Please delete all files/folders inside the folder you wish to delete first.");
                        return;
                }

                if(confirm("Delete folder?"))
                        return true;

                return false;
        }

        addEvent(window, 'load', init);
