
    // TREE FUNCTIONS - FRAME
    // These functions affect the tree frame and any items that may be pointing to the tree.
    var currentFrameState = 'open';
    var defaultFrameWidth = '260,*';
    var userDefinedFrameWidth = '260,*';

    var workText;
    var buildText;
    
    // Create the AJAX mail update object before requesting it
    var updateMailerAjx = new Ajax('index.php', {method:'post', postBody:'updateMsgCount=true', onComplete:showResponse});
    function updateMail(now) {
    	try {
    	  // if 'now' is set, runs immediate ajax request (avoids problem on initial loading where periodical waits for time period before making first request)
    	  if (now)
		  updateMailerAjx.request();
		  return false;
    	} catch(oException) {
		// Delay first run until we're ready...
		xx=updateMail.delay(1000,'',true);
    	}
    }

	function showResponse(request) {
		var counts = request.split(',');
		var elm = $('msgCounter');
          if (elm) elm.innerHTML ='(' + counts[0] + ' / ' + counts[1] + ')';
        var elm = $('newMail');
		  if (elm) elm.style.display = counts[0] >0 ? 'inline' :  'none';
	}
	
	window.addEvent('load', function() {
        updateMail(true); // First run update
	updateMail.periodical(60000, '', true); // Periodical Updater
        if(top.__hideTree) {
            // display toc icon
            var elm = $('tocText');
            if(elm) elm.innerHTML = "<a href='#' onclick='defaultTreeFrame();'><img src='media/style/MODxLight/images/icons/application_side_expand.png' alt='Show tree' width='16' height='16' /></a>";
        }
    });

    function hideTreeFrame() {
        userDefinedFrameWidth = parent.document.getElementsByTagName("FRAMESET").item(1).cols;
        currentFrameState = 'closed';
        try {
            var elm = $('tocText');
            if(elm) elm.innerHTML = "<a href='#' onclick='defaultTreeFrame();'><img src='media/style/MODxLight/images/icons/application_side_expand.png' alt='Show tree' width='16' height='16' /></a>";
            parent.document.getElementsByTagName("FRAMESET").item(1).cols = '0,*';
            top.__hideTree = true;
        } catch(oException) {
            x=window.setTimeout('hideTreeFrame()', 1000);
        }
    }

    function defaultTreeFrame() {
        userDefinedFrameWidth = defaultFrameWidth;
        currentFrameState = 'open';
        try {
            var elm = $('tocText')
            if(elm)elm.innerHTML = "";
            parent.document.getElementsByTagName("FRAMESET").item(1).cols = defaultFrameWidth;
            top.__hideTree = false;
        } catch(oException) {
            z=window.setTimeout('defaultTreeFrame()', 1000);
        }
    }

    // TREE FUNCTIONS - Expand/ Collapse
    // These functions affect the expanded/collapsed state of the tree and any items that may be pointing to it
    function expandTree() {
        try {
            parent.tree.d.openAll();  // dtree
        } catch(oException) {
            zz=window.setTimeout('expandTree()', 1000);
        }
    }

    function collapseTree() {
        try {
            parent.tree.d.closeAll();  // dtree
        } catch(oException) {
            yy=window.setTimeout('collapseTree()', 1000);
        }
    }

    // GENERAL FUNCTIONS - Refresh
    // These functions are used for refreshing the tree or menu
    function reloadtree() {
        var elm = $('buildText');
        if (elm) {
            elm.innerHTML = "&nbsp;&nbsp;<img src='media/style/MODxLight/images/icons/information.png' width='16' height='16' />&nbsp;Loading document tree...";
            elm.style.display = 'block';
        }
        top.tree.saveFolderState(); // save folder state
        setTimeout('top.tree.restoreTree()',200);
    }

    function reloadmenu() {
        }

    function startrefresh(rFrame){
        if(rFrame==1){
            x=window.setTimeout('reloadtree()',500);
        }
        if(rFrame==2) {
            x=window.setTimeout('reloadmenu()',500);
        }
        if(rFrame==9) {
            x=window.setTimeout('reloadmenu()',500);
            y=window.setTimeout('reloadtree()',500);
        }
    }

    // GENERAL FUNCTIONS - Work
    // These functions are used for showing the user the system is working
    function work() {
        var elm = $('workText');
        if (elm) elm.innerHTML = "&nbsp;<img src='media/style/MODxLight/images/icons/exclamation.png' width='16' height='16' />&nbsp;Working...";
        else w=window.setTimeout('work()', 50);
    }

    function stopWork() {
        var elm = $('workText');
        if (elm) elm.innerHTML = "";
        else  ww=window.setTimeout('stopWork()', 50);
    }

    // GENERAL FUNCTIONS - Remove locks
    // This function removes locks on documents, templates, parsers, and snippets
    function removeLocks() {
        if(confirm("Κλείνοντας το παράθυρο υπάρχει πιθανότητα να μίνει περιεχόμενο χωρίς να καταχωριθεί .\n\n Θέλετε να προχορίσετε;")==true) {
            top.main.document.location.href="index.php?a=67";
        }
    }

    function showWin() {
        window.open('../');
    }

    function stopIt() {
        top.mainMenu.stopWork();
    }

    function openCredits() {
        parent.main.document.location.href = "index.php?a=18";
        xwwd = window.setTimeout('stopIt()', 2000);
    }

    function NavToggle(element) {
        // This gives the active tab its look
        var navid = document.getElementById('nav');
        var navs = navid.getElementsByTagName('li');
        var navsCount = navs.length;
        for(j = 0; j < navsCount; j++) {
            active = (navs[j].id == element.parentNode.id) ? "active" : "";
            navs[j].className = active;
        }

        // remove focus from top nav
        if(element) element.blur();
    }
	
