// Yellow Wood Writers Group javascript file
function activateArrow(elemid) {
    o = document.getElementById(elemid);
    o.style.visibility = "visible";
}

function deactivateArrow(elemid) {
    o = document.getElementById(elemid);
    o.style.visibility = "hidden";
}

function popPhotoWin(path) {
    if( path == null ) {
        alert('Invalid Entry.');
        return;
    }
    var features = 'height=550,width=650,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no';
    photoWin     = window.open(path,'photoWin',features);
    photoWin.focus();
    return;
}

function openCloseDiv(name) {
    o = document.getElementById(name);
    if( o.style.display == 'none' ) {
        o.style.display = 'block';
    } else {
        o.style.display = 'none';
    }
}

function popPhotoWin(u) {
    // pop up the new photo window with the photo in it
    if( u == null ) {
        return;
    }
    photowin = window.open(u,'PhotoWin','height=650,width=650,directories=no,location=no,menubar=no,resizeable=yes,scrollbars=yes,status=no,toolbar=no');
    photowin.focus();
}

function openClose(id) {
    var o = document.getElementById(id);
    if( o.style.display == 'none' ) {
        o.style.display  = 'block';
    } else {
        o.style.display  = 'none';
    }
    switchShowHide(id);
}

function switchShowHide(id) {
    o = document.getElementById(id+'text');
    if( o.innerHTML == 'show' ) {
        o.innerHTML  = 'hide';
    } else {
        o.innerHTML = 'show';
    }
}

var editTools = 0;
var textItems = new Array();
function showHideEditTools(show) {
    // if variable passed, use that;
    // otherwise, toggle based on the editTools variable

    if( show != null ) {
        if( show ) {
            // SHOWING THE EDIT TOOLS
            editTools = 1;
            for( i = 0; i < textItems.length; i++ ) {
                // set style and onClick
                var o = document.getElementById(textItems[i]);
                o.style.background   = '#CCCCCC';
            }
            // SHOW FOLDER AND UPLOAD TOOLS
            var o = document.getElementById('addfolder');
            o.style.display   = 'block';
            var o = document.getElementById('addfile');
            o.style.display   = 'block';
        } else {
            // HIDING THE EDIT TOOLS
            editTools = 0;
            for( i = 0; i < textItems.length; i++ ) {
                 // set style and onClick
                 var o = document.getElementById(textItems[i]);
                 o.style.background   = '#FFFFFF';
            }
            // HIDE FOLDER AND UPLOAD TOOLS
            var o = document.getElementById('addfolder');
            o.style.display   = 'none';
            var o = document.getElementById('addfile');
            o.style.display   = 'none';
        }
        return;
    }

    if( editTools ) {
        // HIDING THE EDIT TOOLS
        editTools = 0;
        for( i = 0; i < textItems.length; i++ ) {
             // set style and onClick
             var o = document.getElementById(textItems[i]);
             o.style.background   = '#FFFFFF';
        }
        // HIDE FOLDER AND UPLOAD TOOLS
        var o = document.getElementById('addfolder');
        o.style.display   = 'none';
        var o = document.getElementById('addfile');
        o.style.display   = 'none';
    } else {
        // SHOWING THE EDIT TOOLS
        editTools = 1;
        for( i = 0; i < textItems.length; i++ ) {
            // set style and onClick
            var o = document.getElementById(textItems[i]);
            o.style.background   = '#CCCCCC';
        }
        // SHOW FOLDER AND UPLOAD TOOLS
        var o = document.getElementById('addfolder');
        o.style.display   = 'block';
        var o = document.getElementById('addfile');
        o.style.display   = 'block';
    }
}

function popEditWin(name,folder) {
    // show an edit window for the textitem being edited
    if( !editTools ) {
        // edit tools are not turned on; disallow the edit acton
        return false;
    }
    var url = '/edit.php?cwd='+folder+'&ti=' + name;
    editwin = window.open(url,'EditWin','height=550,width=750,directories=no,location=no,menubar=no,resizeable=yes,scrollbars=yes,status=no,toolbar=no');
    editwin.focus();
}

function closeEditWin() {
    var url = new String( window.opener.location );
    if( url.indexOf('?') > 0 ) {
        if( url.indexOf('tools=1') == -1 ) {
            url += '&tools=1';
        }
    } else {
        if( url.indexOf('tools=1') == -1 ) {
            url += '?tools=1';
        }
    }
    window.opener.location = url;
    window.close();
}


