/**
* CustomGolAjax - classe para criação e manipulação de objeto XMLHttp
* @author Ricardo Machado Poffo
* @date 07/06/2006
*/
/**
* Classe de manipulção de XMLHttp
* @package Ajax
* @author Ricardo Machado Poffo
* @date 07/06/2006
*/
var CustomGolAjax = function(){
  var Self = this;
  /**
  * Nome do arquivo chamado pelo Ajax
  * @var string
  */
	 this.File   = null;
	 /**
	 * Funcão de Retorno
	 * @var string
	 */
 	this.Ret    = null;
 	/**
 	* Parâmetros passados do Ajax para o arquivo de processamento
 	* @var string
  	*/
 	this.Param    = '';
 	/**
 	* XML gerado pelo arquivo de processamento
 	* @var XML
 	*/
 	this.XmlDoc = null;
 	/**
 	* Protocolo utilizado na chamada do Ajax
 	* @var string GET ou POST
 	*/
 	this.Transf = 'POST';
 	/**
 	* Opção de depuração
 	* @var boolean
 	*/
 	this.Debug = false;
 	/**
 	* Tipo de retorno
 	* @var string
 	*/
 	this.ReturnType = 'xml';
 	/**
 	* Objeto manipulador do XMLHttp
  * @var XMLHttp manipulador
 	*/
 	this.Handler = null;
 	/**
 	* Construtor
 	*/
 	this.Construct = _Construct;
 	/**
 	* Função que abre o objeto XMLHttp
  */
  this.Open = _Open;
 	/**
 	* Declaração do construtor
 	*/
 	function _Construct(){
    //verifica se o browser tem suporte a ajax
    try {
       Self.Handler = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(e) {
       try {
          Self.Handler = new ActiveXObject("Msxml2.XMLHTTP");
       }catch(ex) {
          try {
             Self.Handler = new XMLHttpRequest();
          }catch(exc) {
             alert("Esse browser não tem recursos para uso do Ajax");
             Self.Handler = null;
          }
       }
    }
    if(Self.Handler != null){
      Self.Handler.onreadystatechange = _TestReadyStateSend;
    }
  }
  /**
  * Abre o objeto XMLHttp para uso
  * Faz chamada para arquivo de processamento
  * Passa parametros para arquivo de processamento
  * Seta header no caso de tipo POST setado na comunicação
  * @param string Param parâmetros
  */
  function _Open(Param){
    Self.Construct();
    Self.Handler.open(Self.Transf,Self.File,true);
				if (this.Transf == 'POST'){
					Self.Handler.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				}
				Self.Handler.send(Param);
	  			parent.LoadChange();
  }
  /**
  * Função que testa o estado do objeto XMLHttp
  * Chamada no evento onreadystatechange do objeto XMLHttp
  * Chama função de interna de retorno no caso de status igual a 200
  */
  function _TestReadyStateSend() {
  		if (Self.Handler.readyState == 4) {//se estado for = processamento completo
			parent.LoadChange();
  			if (Self.Handler.status == '200') {//se estado for retorno bem sucedido
  				_EvalInternalGet();               //Chamada da função interna de retorno
  			} else {
  				alert('Página não encontrada');
  				return false;
  			}
  		}
 	}
  /**
  * Função de retorno do objeto XMLHttp
  */
  function _EvalReturn() {
  		var retFunc = '';
  		if (typeof(Self.Ret) == 'function') {
  			eval('new Self.Ret');
  		}
 	}
	 /**
	 * Testa o tipo setado para retorno
	 * Se depuração está ativa exibe dados de retorno
	 * Chama função de retorno
	 */
	 function _EvalInternalGet() {
  		Self.XmlDoc = (Self.ReturnType == 'xml' ? Self.Handler.responseXML : Self.Handler.responseText);
  		if (Self.Debug){
  			var container = document.getElementsByTagName("BODY");
  			if (container.length > 0){
  				var newDiv = document.createElement("DIV");
  				newDiv.setAttribute("style", "position:absolute; width:640; left:30; top:100; background: #FFFFFF; border: 2px solid #000000");
  				var txt = document.createTextNode(Self.Handler.responseText);
  				newDiv.appendChild(txt);
  				container[0].appendChild(newDiv);
  			}
  		}
  		_EvalReturn();
 	}

  //final da classe CustomGolAjax
}