
function setPHPDebug(bValue)
{
    if(bValue == 1)
    {
        Communication.createCookie("DBGSESSID", "1");
        window.phpEdDebuggingOn = true;
    }
    else
    {
        Communication.eraseCookie("DBGSESSID");
        window.phpEdDebuggingOn = false;
    }
}
function setJSDebug(bValue)
{
    if(bValue == 1)
    {
        Communication.createCookie("debug", "true");
    }
    else
    {
        Communication.createCookie("debug", "false");
    }
    window.location.reload();
}

function doLogin()
{
    document.getElementById("tools_login_form").submit();
    return true;
}

function checkEnter(e)
{
    // e is event object passed from function invocation
    var characterCode;
    
    if(e && e.which)
    {
        // if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else if(typeof event != 'undefined')
    {
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }
    
    if(characterCode == 13)
    {
        // if generated character code is equal to ascii 13 (if enter key)
        if(document.all) window.event.returnValue = false;
        doLogin();
        return false
    }
    else
        return true
}

window.addEvent("domready" , function() {
    try {
        window.loginForm = new ExtendedForm({
            "form": "login"
            });
    }
    catch(e) { 
        // must have been a sys down message
    } 
    // remove the h1.logo.
    var aH1 = $$("h1.logo");
    if(aH1 && aH1.length > 0)
    	aH1[0].destroy();
});

window.addEvent("domready", function() {
	if($("navigation"))
	    new NavSlider($("navigation").getElement("ul"), $("navigation_slider"));
});

var NavSlider = new Class({
    initialize: function(menu, slider, options) {
        this.setOptions(this.getOptions(), options);
        
        this.menu = menu;
        this.slider = slider;
        this.current = this.menu.getElement('.current');
        this.menu.getElements('a').each(function(item){
            item.addEvent('mouseover', function() { this.moveBg(item); }.bind(this));
            item.addEvent('mouseout', function(){ this.moveBg(this.current); }.bind(this));
            item.addEvent("click", function() { this.updateCurrent(item); }.bind(this));
        }.bind(this));
                
        this.slider_marker = new Element('div').addClass('slider_marker').adopt(new Element('div')).injectInside(this.slider);
        this.moveBg(this.current);
    },
    
    setCurrent: function(el){
        this.current = el;
    },
    
    getOptions: function(){
        return {
            transition: Fx.Transitions.sineInOut,
            duration: 500, wait: false,
            onClick: Class.empty
        };
    },

    moveBg: function(to) {
        if(!this.current) return;
        var tweenTo = to.offsetLeft + to.offsetWidth;
        this.slider_marker.tween("width", tweenTo);
    },
    
    updateCurrent: function(oCurrent) {
        this.current = oCurrent;
        this.moveBg(oCurrent);
    }
});

NavSlider.implement(new Options);