function $id() {
var elements = new Array();
var totArgs = arguments.length;
for (var i = 0; i < totArgs; i++) {
if (typeof arguments[i] == 'string') arguments[i] =
document.getElementById(arguments[i]);
if (arguments.length == 1) return arguments[i];
elements.push(arguments[i]);
}
return elements;
}

function ajax(url, div, info, method, formID, script, func){
        this.url = url; // content url
        this.method = (method) ? method : 'GET'; // method GET or POST, by standard  "GET"
        this.div = div; // content destination
        this.info = (info) ? info : 'loading'; // while loading
        this.formID = formID; // form ID is required for post requests only
        this.script = (script==0 || script==1) ? script : 1;
        this.func = func;
}

ajax.prototype = {
    connect: function(){
                if(!this.url) return;
        this.xmlHttp = null;
                if( window.XMLHttpRequest ) this.xmlHttp = new XMLHttpRequest(); // All browsers
                else if( window.ActiveXObject){ // IE
                        try{
                                this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (e){
                                try{
                                        this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e) {}
                        }
                }
                if(this.xmlHttp != null && this.xmlHttp != undefined ){
                        var object = this;
                        this.xmlHttp.onreadystatechange = function(){ object.getState.call(object); }

                        if(this.method=="GET") this.executeGET(); // get request
                        else this.executePOST() // post request        
                }
        },
        getState: function(){
                if(this.xmlHttp.readyState == 4 ){
                        this.result(this.xmlHttp.responseText);
                        if(this.script) this.executeScripts(this.xmlHttp.responseText);
                        if(this.func!=null) eval(this.func);
                } else this.loading();
        },
        executeGET: function(){
                this.xmlHttp.open(this.method,this.url, true);
                this.xmlHttp.send(null);

        },
        executePOST: function(){
                var fields = "";
                if(!this.formID) alert("Erro: falta indicar FORM")
                for(i=0;i<$id(this.formID).length;i++){
                        fields+=$id(this.formID)[i].name+"="+$id(this.formID)[i].value+"&";
                }
                this.xmlHttp.open(this.method,this.url, true);
                this.xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                this.xmlHttp.setRequestHeader('Content-Type',"application/x-www-form-urlencoded;charset=iso-8859-1");
                this.xmlHttp.send(fields);              
        },      
        executeScripts: function(text){
                var ini = 0;
                while (ini!=-1){
                        ini = text.indexOf('<script', ini);
                        if (ini >=0){
                                ini = text.indexOf('>', ini) + 1;
                                var fim = text.indexOf('</script>', ini);
                                text = text.substring(ini,fim);
                                eval(text);
                        }
                }
        },
    loading: function(){ this.result(this.info) },
        result: function(r){ $id(this.div).innerHTML= r; }
}

function fsAjax(url, div, info, method, formID, script,func){
        var requestContent = new ajax(url, div, info, method, formID, script,func);
        requestContent.connect();
}

/* END OF AJAX */ 
