/* AJSE v0.1 - paulo@f1 */
 
/* AjsePrimitiveAjax - Resgata Objeto XMLHTTPRequest */
function AjsePrimitiveAjax() {
	
   var xml;
   var erro = "ERRO: Seu navegador é incompatível com algumas funções do website!";
   
   /*@cc_on
        @if (@_jscript_version >= 5)
         try {
           xml = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
           try {
             xml = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {
             xml = false;
             alert(erro);
           }
         }
         @else
         xml = false;
         alert(erro);
   @end @*/
   
   if (!xml && typeof XMLHttpRequest != 'undefined') {
       try {
           xml = new XMLHttpRequest();
       } catch (e) {
           xml = false;
           alert(erro);
       }
   }
   
   return xml;
}

/* Ajse - Objeto ajax */
function Ajse(serve, func, charse) {  
	
	var here = this;  
		      
	here.server = serve;   
	here.busy = false;
	here.charset = charse==undefined || charse==null || charse==false? "UTF-8" : charse ;
	here.cbf = func==undefined || func==null || func==false? function(non){ } : func ; 
	here.httpObject = null;
	
	this.cancel = function() {    
		if (here.busy) {       
			here.httpObject.abort();      
			here.httpObject = null;
			here.busy = false;
			return true;         
		}  
		return false;
	}  	    
	
	this.query = function( dat, metho, sinc, force) {   
		  
		if (here.busy && (force==undefined || force==null)) { 
			return false; 
		}else if(here.busy){
			here.httpObject.abort();
		}    
		
		here.busy = true;
		here.httpObject = null; 
		here.httpObject = AjsePrimitiveAjax(); 
		 
		var data = dat==undefined || dat==null || dat==false ? "" : dat ;
		var sync = sinc!=undefined && sinc!=null ? false : true;	 
				   
		here.httpObject.onreadystatechange = function() {          
			if (here.httpObject.readyState == 4) {                       
				here.busy = false;                          
				here.cbf(here.httpObject);                  
				here.httpObject = null;                                                 
			}                                                            
		}    
		                                              
		if (metho=="POST") {               
			here.httpObject.open("POST", here.server+'?nochache='+Math.random(), sync);   
    		here.httpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset="+here.charset);
    		here.httpObject.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
    		here.httpObject.setRequestHeader("Pragma", "no-cache");          
			here.httpObject.setRequestHeader("Content-Length", data.length);        
			here.httpObject.send(data);      
		} else {                 
			here.httpObject.open("GET", here.server+'?nocache='+Math.random()+'&'+data, sync);                                     
			here.httpObject.send(null);                                               
		}                
		return true;                                                 
	}
}

/* LoadIntoHTML - Carrega arquivo "fil" para dentro da tag "id" */
function LoadIntoHTML(id,fil,substitute){
	
	var here = this;
	here.httpObject = AjsePrimitiveAjax();
	here.httpObject.open("GET", fil, true);	
	if(substitute!=false && substitute!=undefined && substitute!=null){
	    document.getElementById(id).innerHTML = substitute;
	}	
	here.httpObject.onreadystatechange = function (){
		if (here.httpObject.readyState == "4") {
			document.getElementById(id).innerHTML = here.httpObject.responseText;
		}
	};
	here.httpObject.send(null);
}
/* Obs! */
var AJSE_loaded = true;


