

Evonux.Page = {};

Evonux.Page.get = function (/* data, container, onComplete */) 
{
    var		p_data = null;
    var		p_container = null;
    var		p_complete = function () {};

    // Get arguments
    if (arguments.length > 0)
    p_data = arguments[0] + "&dyn=1";
    if (arguments.length > 1)
    p_container = $(arguments[1]);
    else
    p_container = $("content");
    if (arguments.length > 2)
    p_complete = arguments[2];

    // Show message box
    if (arguments[1] == "msg")
    $('msgbox').style.display = "block";

    // Load ajax
    //    document.body.style.cursor = 'wait';
    // document.body.style.cursor = 'auto'; 
    new Request.HTML ({url: U_ROOT + "/index.php", data: p_data, update: p_container, onComplete: p_complete, evalScripts: true}).get ();
}

Evonux.Page.post = function (/* data, container, onComplete, prefix */)
{
    var         p_data = null;
    var         p_container = null;
    var         p_complete = function () {};

    // Get arguments
    if (arguments.length > 0)
    p_data = $(arguments[0]);
    if (arguments.length > 1)
    p_container = $(arguments[1]);
    if (arguments.length > 2)
    p_complete = arguments[2];

    // Save Wysiwyg if needed
    $$("textarea.wysiwyg").each (function (el) {
	tinyMCE.triggerSave (); //getEditorId ('textareaname');
    });

    // Post form
    new Request.HTML ({url: U_ROOT + "/index.php?dyn=1", data: p_data, update: p_container, onComplete: p_complete, evalScripts: true}).post ();
}

Evonux.Page.submit = function ()
{    
    var		box;
    var		msg;
    var		frm;
    var		prefix;

    box = "msg-box" + (arguments.length > 0 ? "-" + arguments[0] : '');
    msg = "msg" + (arguments.length > 0 ? "-" + arguments[0] : '');
    frm = "frm" + (arguments.length > 0 ? "-" + arguments[0] : '');
    Evonux.Page.post ($(frm), $(msg), function () { $(box).style.display = "block"; });
}

Evonux.Page.reset = function ()
{    
    $('frm').reset ();
}

Evonux.Page.load = function (/* data, container, onComplete */)
{   
    var         p_data = null;
    var         p_container = null;
    var         p_complete = function () {};
    
    // Default args
    p_data = arguments[0];
    p_container = (arguments.length < 2 ? "main-content" : arguments[1]);
    p_complete = (arguments.length < 3 ? p_complete : arguments[2]);
    Evonux.Page.get (p_date, p_container, function () { p_complete (); });
}

Evonux.Page.loadRef = function (ref)
{   
    Evonux.Page.get ("module=webpage&state=show&ref=ref", "content");
}


Evonux.Page.loadUrl = function (/* url, container, oncomplete*/)
{   
    var		url = null;
    var         p_data = null;
    var         p_container = $("content");
    var         p_complete = null;

    url = arguments[0];
    if (arguments.length > 1)
    p_container = $(arguments[1]);
    if (arguments.length > 2)
    p_complete = arguments[2];

    // Clear existing timers
    //    clearTimeout (timer_1);

    new Request.HTML ({url: U_ROOT + "/" + url, data: "dyn=1", update: p_container, onComplete: p_complete, evalScripts: true}).get ();
}


Evonux.Page.refresh = function ()
{    
    document.location = document.location;
}

/*Evonux.Page.back = function (state, ref)
{    
    var		frm = $('frm');

    if (frm.back.value)
    {
	Evonux.Page.loadUrl (unescape (unescape (frm.back.value)));
    }
    else
    {
	Evonux.Page.loadUrl ("?module=webpage&state=show&ref=" + ref);
    }
}    
*/

Evonux.Page.changeState = function (state, oid, type)
{
    var		frm = $('frm');

    Evonux.Page.get ('module=' + frm.module.value + '&state=' + state + (oid ? '&oid=' + oid : '') + (type ? '&type=' + type : '') + '&back=' + frm.url.value, 'main-content');
}

Evonux.Page.relocate = function (url)
{
    Evonux.Page.load (url);
}

Evonux.Page.goTo = function (url)
{
    document.location = url;
}


Evonux.Page.goBack = function (ref)
{
    var		frm = $('frm');

    if (frm.back.value)
	Evonux.Page.loadUrl ('?' + unescape (unescape (frm.back.value)));
    else
        Evonux.Page.loadUrl ('?module=webpage&state=show&ref=' + ref);
}




