function loadXMLDoc(url){
	var obj=this;
    var re = new RegExp("&","g");
	this.runFunctions="";
	
	function load(){
		obj.complete=0;
		if (window.XMLHttpRequest) obj.xmlhttp=new XMLHttpRequest();
		else if (window.ActiveXObject) obj.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(obj.xmlhttp){
			obj.xmlhttp.onreadystatechange=function(){
				if (obj.xmlhttp.readyState==4){
          if (obj.xmlhttp.status==200){
  					obj.complete=1;
            if(obj.runFunctions!=""){
          		
              /* Checa XML caso seja inválido  */
              if (window.XMLHttpRequest){
                returnError=new XMLSerializer().serializeToString(obj.xmlhttp.responseXML);
                if(returnError.indexOf("parsererror")>=0) returnError=true;
              }else if (window.ActiveXObject){
                returnError=obj.xmlhttp.responseXML.parseError.errorCode;
                if(returnError!=0) returnError=true;
              }

              if(returnError==true) eval("Error"+unescape((obj.runFunctions.replace(re,"; Error"))));
              else eval(unescape((obj.runFunctions.replace(re,";"))));

  					}
				  }else{
            eval("Error"+unescape((obj.runFunctions.replace(re,"; Error"))));
          }
				}
			};
            d=new Date();

			obj.xmlhttp.open("GET",url+((url.indexOf("?")>=0)?"&rtimestampobj="+d.getTime():"?rtimestampobj="+d.getTime()),true);
			obj.xmlhttp.send(null);
		}
	}
	
	/*Metodo para executar funções especificas do XML*/
	this.run=runF;
	function runF(x){
		if (obj.complete==1){
			eval(x.replace(re,";"));
		}
		obj.runFunctions+=((obj.runFunctions!="")?"&":"")+escape(x);
	}
	
	/*Metodo para reload do XML*/
	this.reload=load;
	this.reload();

    //Metodo para exibir loading de XML
    
    this.showLoadingXML=loading;
    function loading(ob,id){
        var H_DIV_load=document.createElement("div");
        H_DIV_load.appendChild(document.createTextNode("loading..."));
        H_DIV_load.id=ob+"h_loading";
        H_DIV_load.className="XMLload";
        if(eval(ob+".xmlhttp.readyState")<4) {
            //quando descomentado o loading pisca
            eval("setTimeout(\""+ob+".showLoadingXML('"+ob+"','"+id+"');\",300);");
            if(document.getElementById(H_DIV_load.id)) document.getElementById(id).removeChild(document.getElementById(H_DIV_load.id));
            else document.getElementById(id).appendChild(H_DIV_load);
        }else {
            if(document.getElementById(H_DIV_load.id)) document.getElementById(id).removeChild(document.getElementById(H_DIV_load.id));
        }
    }
}

///////////////////////////////////////
