// JavaScript Document

var target = null;
//
var setContent = function (content)
{
    target.innerHTML =  decodeURI(content);
}

var Ajax2 = function ()
{
    this.loader = null;
    this.target = null;
	
	this.stack = new Array();
	
	
	
    this.setLoader = function (obj)
    {
        this.loader = obj;


        //
        this.loader.show = function ()
        {
            this.style.display = "block";
        }
        //
        this.loader.hidden = function ()
        {
            this.style.display = "none";
        }
        //
    }

    //
    this.loadContent = function (url,tgt)
    {
        target = tgt;

        this.load(url, "setContent");
    }
    //
    this.loadResult = function (url,fc)
    {
        this.load(url,fc);
    }

    //
    this.load = function (url,fct)
    {
        var xmlhttp = getRequest();

        if(xmlhttp)
        {
			xmlhttp.abort();
            xmlhttp.open("GET",url,true);

            $this = this;
            
            if($this.loader)
            {
                $this.loader.show();
            }

            xmlhttp.onreadystatechange = function () {

                var state = xmlhttp.readyState;

                switch(state)
                {
                    case 4:
                    var status = xmlhttp.status;
                    // Se o carregamento foi correto
                    if(status == 200)
                    {
                        eval(""+fct+"(\""+encodeURI(xmlhttp.responseText)+"\")");
                    }
                    // Esconde o loader
                    if($this.loader)
                    {
                        $this.loader.hidden();
                    }
                    //
                    break;
                    default:
                    // Mostra o loader
                    if($this.loader)
                    {
                        $this.loader.show();
                    }

                    break;

                }

            }

            xmlhttp.send(null);

        }
    }
}