
function logit() { }

var XTREME = function()
{
    var initData;
    var rhsBox;

    function init( )
    { 
        rhsBox = document.getElementById('rhsBox');

        var IN_HTML_CMD = eval( '(' + document.getElementById('skate_js').innerHTML + ')' );

        initData = { "base": IN_HTML_CMD.b };

        if( IN_HTML_CMD.i == -1 )
        {
            ajax_get( IN_HTML_CMD.b + '_xco_/head_login_form.html', XTREME.gotPost, 'rhs' );
        }

        if( IN_HTML_CMD.LL == true )
        {
            ajax_get( IN_HTML_CMD.b + '_xco_/left_links.php', XTREME.gotPost, 'LL' );
        }
        
        try
        {
            preparePage();
        }
        catch( err )
        {
            
        } 
    }

    function checkLogin()
    {
        if(document.getElementById('username').value.length == 0 || document.getElementById('password').value.length == 0)
            return false;
        document.getElementById('loginButton').value = '';
        document.getElementById('loginButton').className = "buttonLoading";
        return true;
    }

    function gotPost( json, kind )
    {
        if( kind == 'rhs' )
        {
            rhsBox.innerHTML = json.supplant( initData );
        }
        else if( kind == 'LL' )
        {
            document.getElementById('left_links_stub').innerHTML = json.supplant( initData );
        }
    }

    return {
        init: init,
        checkLogin: checkLogin,
        gotPost: gotPost
    }
}();


String.prototype.supplant = function (o) {
    return this.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' ?
                r : a;
        }
    );
};


function ajax_get( url, _cb, _msg )
{
    var cb = _cb;
    var msg = _msg;
    var xmlhttp = null;
    if (window.XMLHttpRequest)  {  xmlhttp = new XMLHttpRequest();  }
    else if (window.ActiveXObject)  {   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    if (xmlhttp != null)
    {
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState == 4)
            {
                if (xmlhttp.status == 200)
                {
                    cb( xmlhttp.responseText, msg );
                }
            }
        }
        xmlhttp.open('GET', url, true );
        xmlhttp.send( null );
    }
    else  {  logit('Cannot continue, your browser does not support ajax!');  }
}

window.onload = function() { XTREME.init() };